| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package storage::hp::storeonce::3::restapi::mode::nasusage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_nas_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'status: %s [replication health: %s]', |
| 34 |
$self->{result_values}->{health}, |
| 35 |
$self->{result_values}->{replication_health} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub custom_share_status_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf('status: %s', $self->{result_values}->{health}); |
| 43 |
} |
| 44 |
|
| 45 |
sub prefix_nas_output { |
| 46 |
my ($self, %options) = @_; |
| 47 |
|
| 48 |
return "NAS '" . $options{instance_value}->{display} . "' "; |
| 49 |
} |
| 50 |
|
| 51 |
sub prefix_share_output { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
return "Share '" . $options{instance_value}->{display} . "' "; |
| 55 |
} |
| 56 |
|
| 57 |
sub set_counters { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
$self->{maps_counters_type} = [ |
| 61 |
{ name => 'nas', type => 1, cb_prefix_output => 'prefix_nas_output', message_multiple => 'All nas are ok' }, |
| 62 |
{ name => 'share', type => 1, cb_prefix_output => 'prefix_share_output', message_multiple => 'All shares are ok' } |
| 63 |
]; |
| 64 |
|
| 65 |
$self->{maps_counters}->{nas} = [ |
| 66 |
{ |
| 67 |
label => 'nas-status', |
| 68 |
type => 2, |
| 69 |
warning_default => '%{health} =~ /warning/i', |
| 70 |
critical_default => '%{health} =~ /critical/i', |
| 71 |
set => { |
| 72 |
key_values => [ { name => 'replication_health' }, { name => 'health' }, { name => 'display' } ], |
| 73 |
closure_custom_output => $self->can('custom_nas_status_output'), |
| 74 |
closure_custom_perfdata => sub { return 0; }, |
| 75 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 76 |
} |
| 77 |
} |
| 78 |
]; |
| 79 |
|
| 80 |
$self->{maps_counters}->{share} = [ |
| 81 |
{ |
| 82 |
label => 'share-status', |
| 83 |
type => 2, |
| 84 |
type => 2, |
| 85 |
warning_default => '%{health} =~ /warning/i', |
| 86 |
critical_default => '%{health} =~ /critical/i', |
| 87 |
set => { |
| 88 |
key_values => [ { name => 'health' }, { name => 'display' } ], |
| 89 |
closure_custom_output => $self->can('custom_share_status_output'), |
| 90 |
closure_custom_perfdata => sub { return 0; }, |
| 91 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 92 |
} |
| 93 |
} |
| 94 |
]; |
| 95 |
} |
| 96 |
|
| 97 |
sub new { |
| 98 |
my ($class, %options) = @_; |
| 99 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 100 |
bless $self, $class; |
| 101 |
|
| 102 |
$options{options}->add_options(arguments => { |
| 103 |
'filter-name:s' => { name => 'filter_name' } |
| 104 |
}); |
| 105 |
|
| 106 |
return $self; |
| 107 |
} |
| 108 |
|
| 109 |
my %mapping_health_level = ( |
| 110 |
0 => 'unknown', |
| 111 |
1 => 'ok', |
| 112 |
2 => 'information', |
| 113 |
3 => 'warning', |
| 114 |
4 => 'critical', |
| 115 |
); |
| 116 |
|
| 117 |
sub manage_selection { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
$self->{nas} = {}; |
| 121 |
$self->{share} = {}; |
| 122 |
my $result = $options{custom}->get(path => '/cluster/servicesets/*all*/services/nas', ForceArray => ['service', 'item']); |
| 123 |
if (defined($result->{services}->{service})) { |
| 124 |
foreach my $entry (@{$result->{services}->{service}}) { |
| 125 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 126 |
$entry->{properties}->{ssid} !~ /$self->{option_results}->{filter_name}/) { |
| 127 |
$self->{output}->output_add(long_msg => "skipping '" . $entry->{properties}->{ssid} . "': no matching filter.", debug => 1); |
| 128 |
next; |
| 129 |
} |
| 130 |
|
| 131 |
$self->{nas}->{$entry->{properties}->{ssid}} = { |
| 132 |
display => $entry->{properties}->{ssid}, |
| 133 |
health => $mapping_health_level{$entry->{properties}->{nasHealthLevel}}, |
| 134 |
replication_health => $mapping_health_level{$entry->{properties}->{repHealthLevel}}, |
| 135 |
}; |
| 136 |
|
| 137 |
foreach my $item (@{$entry->{shares}->{item}}) { |
| 138 |
$self->{share}->{$entry->{properties}->{ssid} . '.' . $item->{id}} = { |
| 139 |
display => $entry->{properties}->{ssid} . '.' . $item->{id}, |
| 140 |
health => $mapping_health_level{$item->{summaryHealthLevel}}, |
| 141 |
}; |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
if (scalar(keys %{$self->{nas}}) <= 0) { |
| 147 |
$self->{output}->add_option_msg(short_msg => "No nas found."); |
| 148 |
$self->{output}->option_exit(); |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
1; |
| 153 |
|
| 154 |
__END__ |
| 155 |
|
| 156 |
=head1 MODE |
| 157 |
|
| 158 |
Check NAS status. |
| 159 |
|
| 160 |
=over 8 |
| 161 |
|
| 162 |
=item B<--filter-counters> |
| 163 |
|
| 164 |
Only display some counters (regexp can be used). |
| 165 |
Example: --filter-counters='^nas-status$' |
| 166 |
|
| 167 |
=item B<--filter-name> |
| 168 |
|
| 169 |
Filter nas name (can be a regexp). |
| 170 |
|
| 171 |
=item B<--warning-nas-status> |
| 172 |
|
| 173 |
Define the conditions to match for the status to be WARNING (default: '%{health} =~ /warning/i'). |
| 174 |
You can use the following variables: %{health}, %{replication_health}, %{display} |
| 175 |
|
| 176 |
=item B<--critical-nas-status> |
| 177 |
|
| 178 |
Define the conditions to match for the status to be CRITICAL (default: '%{health} =~ /critical/i'). |
| 179 |
You can use the following variables: %{health}, %{replication_health}, %{display} |
| 180 |
|
| 181 |
=item B<--warning-share-status> |
| 182 |
|
| 183 |
Define the conditions to match for the status to be WARNING (default: '%{health} =~ /warning/i'). |
| 184 |
You can use the following variables: %{health}, %{replication_health}, %{display} |
| 185 |
|
| 186 |
=item B<--critical-share-status> |
| 187 |
|
| 188 |
Define the conditions to match for the status to be CRITICAL (default: '%{health} =~ /critical/i'). |
| 189 |
You can use the following variables: %{health}, %{replication_health}, %{display} |
| 190 |
|
| 191 |
=back |
| 192 |
|
| 193 |
=cut |