| 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::netapp::ontap::snmp::mode::clusternodes; |
| 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 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_node_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
"node status: %s", |
| 35 |
$self->{result_values}->{node_status} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub custom_bbu_status_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
"nvram battery status: %s", |
| 44 |
$self->{result_values}->{bbu_status} |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
sub custom_cpu_calc { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
my $diff_uptime = $options{new_datas}->{$self->{instance} . '_cpuUptime'} - $options{old_datas}->{$self->{instance} . '_cpuUptime'}; |
| 52 |
my $diff_busy = $options{new_datas}->{$self->{instance} . '_cpuBusyTime'} - $options{old_datas}->{$self->{instance} . '_cpuBusyTime'}; |
| 53 |
|
| 54 |
if ($diff_uptime == 0) { |
| 55 |
$self->{result_values}->{cpu_used} = 0; |
| 56 |
} else { |
| 57 |
$self->{result_values}->{cpu_used} = $diff_busy * 100 / $diff_uptime; |
| 58 |
} |
| 59 |
|
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
sub custom_port_link_status_output { |
| 64 |
my ($self, %options) = @_; |
| 65 |
|
| 66 |
return sprintf( |
| 67 |
"operational status: %s [admin: %s]", |
| 68 |
$self->{result_values}->{opstatus}, |
| 69 |
$self->{result_values}->{admstatus} |
| 70 |
); |
| 71 |
} |
| 72 |
|
| 73 |
sub custom_port_health_output { |
| 74 |
my ($self, %options) = @_; |
| 75 |
|
| 76 |
return sprintf( |
| 77 |
"health: %s", |
| 78 |
$self->{result_values}->{health} |
| 79 |
); |
| 80 |
} |
| 81 |
|
| 82 |
sub node_long_output { |
| 83 |
my ($self, %options) = @_; |
| 84 |
|
| 85 |
return sprintf( |
| 86 |
"checking node '%s'", |
| 87 |
$options{instance_value}->{name} |
| 88 |
); |
| 89 |
} |
| 90 |
|
| 91 |
sub prefix_node_output { |
| 92 |
my ($self, %options) = @_; |
| 93 |
|
| 94 |
return sprintf( |
| 95 |
"node '%s' ", |
| 96 |
$options{instance_value}->{name} |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
sub prefix_port_output { |
| 101 |
my ($self, %options) = @_; |
| 102 |
|
| 103 |
return sprintf( |
| 104 |
"port '%s' [role: %s] ", |
| 105 |
$options{instance_value}->{port_id}, |
| 106 |
$options{instance_value}->{role} |
| 107 |
); |
| 108 |
} |
| 109 |
|
| 110 |
sub set_counters { |
| 111 |
my ($self, %options) = @_; |
| 112 |
|
| 113 |
$self->{maps_counters_type} = [ |
| 114 |
{ name => 'nodes', type => 3, cb_prefix_output => 'prefix_node_output', cb_long_output => 'node_long_output', |
| 115 |
indent_long_output => ' ', message_multiple => 'All nodes are ok', |
| 116 |
group => [ |
| 117 |
{ name => 'status', type => 0, skipped_code => { -10 => 1 } }, |
| 118 |
{ name => 'cpu', type => 0, skipped_code => { -10 => 1 } }, |
| 119 |
{ name => 'env', type => 0, skipped_code => { -10 => 1 } }, |
| 120 |
{ name => 'ports', type => 1, cb_prefix_output => 'prefix_port_output', message_multiple => 'ports are ok', display_long => 1, skipped_code => { -10 => 1 } } |
| 121 |
] |
| 122 |
} |
| 123 |
]; |
| 124 |
|
| 125 |
$self->{maps_counters}->{status} = [ |
| 126 |
{ label => 'node-status', type => 2, critical_default => '%{node_status} eq "clusterComLost"', set => { |
| 127 |
key_values => [ |
| 128 |
{ name => 'node_status' }, { name => 'node_name' } |
| 129 |
], |
| 130 |
closure_custom_output => $self->can('custom_node_status_output'), |
| 131 |
closure_custom_perfdata => sub { return 0; }, |
| 132 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 133 |
} |
| 134 |
}, |
| 135 |
{ label => 'bbu-status', type => 2, critical_default => '%{bbu_status} !~ /fullyCharged|ok/i', set => { |
| 136 |
key_values => [ |
| 137 |
{ name => 'bbu_status' }, { name => 'node_name' } |
| 138 |
], |
| 139 |
closure_custom_output => $self->can('custom_bbu_status_output'), |
| 140 |
closure_custom_perfdata => sub { return 0; }, |
| 141 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 142 |
} |
| 143 |
} |
| 144 |
]; |
| 145 |
|
| 146 |
$self->{maps_counters}->{cpu} = [ |
| 147 |
{ label => 'cpu-utilization', nlabel => 'node.cpu.utilization.percentage', set => { |
| 148 |
key_values => [ { name => 'cpuUptime', diff => 1 }, { name => 'cpuBusyTime', diff => 1 } ], |
| 149 |
closure_custom_calc => $self->can('custom_cpu_calc'), |
| 150 |
output_template => 'cpu utilization: %.2f%%', |
| 151 |
output_use => 'cpu_used', threshold_use => 'cpu_used', |
| 152 |
perfdatas => [ |
| 153 |
{ value => 'cpu_used', template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 154 |
] |
| 155 |
} |
| 156 |
} |
| 157 |
]; |
| 158 |
|
| 159 |
$self->{maps_counters}->{env} = [ |
| 160 |
{ label => 'fan-failed', nlabel => 'node.hardware.fans.failed.count', set => { |
| 161 |
key_values => [ { name => 'envFailedFanCount' } ], |
| 162 |
output_template => 'number of fans failed: %s', |
| 163 |
perfdatas => [ |
| 164 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 165 |
] |
| 166 |
} |
| 167 |
}, |
| 168 |
{ label => 'psu-failed', nlabel => 'node.hardware.power_supplies.failed.count', set => { |
| 169 |
key_values => [ { name => 'envFailedPSUCount' } ], |
| 170 |
output_template => 'number of power supplies failed: %s', |
| 171 |
perfdatas => [ |
| 172 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 173 |
] |
| 174 |
} |
| 175 |
}, |
| 176 |
{ label => 'temperature-overrange', nlabel => 'node.hardware.temperatures.over_range.count', set => { |
| 177 |
key_values => [ { name => 'envOverTemp' } ], |
| 178 |
output_template => 'number of temperatures over range: %s', |
| 179 |
perfdatas => [ |
| 180 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 181 |
] |
| 182 |
} |
| 183 |
} |
| 184 |
]; |
| 185 |
|
| 186 |
$self->{maps_counters}->{ports} = [ |
| 187 |
{ label => 'port-link-status', type => 2, critical_default => '%{admstatus} eq "up" and %{opstatus} ne "up"', set => { |
| 188 |
key_values => [ |
| 189 |
{ name => 'admstatus' }, { name => 'opstatus' }, { name => 'port_id' }, { name => 'node_name' } |
| 190 |
], |
| 191 |
closure_custom_output => $self->can('custom_port_link_status_output'), |
| 192 |
closure_custom_perfdata => sub { return 0; }, |
| 193 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 194 |
} |
| 195 |
}, |
| 196 |
{ label => 'port-health', type => 2, warning_default => '%{health} eq "degraded"', set => { |
| 197 |
key_values => [ |
| 198 |
{ name => 'health' }, { name => 'port_id' }, { name => 'node_name' } |
| 199 |
], |
| 200 |
closure_custom_output => $self->can('custom_port_health_output'), |
| 201 |
closure_custom_perfdata => sub { return 0; }, |
| 202 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 203 |
} |
| 204 |
}, |
| 205 |
]; |
| 206 |
} |
| 207 |
|
| 208 |
sub new { |
| 209 |
my ($class, %options) = @_; |
| 210 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); |
| 211 |
bless $self, $class; |
| 212 |
|
| 213 |
$options{options}->add_options(arguments => { |
| 214 |
'filter-node-name:s' => { name => 'filter_node_name' }, |
| 215 |
'filter-port-id:s' => { name => 'filter_port_id' }, |
| 216 |
'filter-port-role:s' => { name => 'filter_port_role' } |
| 217 |
}); |
| 218 |
|
| 219 |
return $self; |
| 220 |
} |
| 221 |
|
| 222 |
my $map_node_health = { |
| 223 |
0 => 'clusterComLost', 1 => 'clusterComOk' |
| 224 |
}; |
| 225 |
my $map_nvram_status = { |
| 226 |
1 => 'ok', 2 => 'partiallyDischarged', |
| 227 |
3 => 'fullyDischarged', 4 => 'notPresent', |
| 228 |
5 => 'nearEndOfLife', 6 => 'atEndOfLife', |
| 229 |
7 => 'unknown', 8 => 'overCharged', 9 => 'fullyCharged' |
| 230 |
}; |
| 231 |
my $map_port_admin = { |
| 232 |
0 => 'down', 1 => 'up' |
| 233 |
}; |
| 234 |
my $map_port_state = { |
| 235 |
0 => 'undef', 1 => 'off', 2 => 'up', 3 => 'down' |
| 236 |
}; |
| 237 |
my $map_port_health = { |
| 238 |
-1 => 'unknown', 0 => 'healthy', 1 => 'degraded' |
| 239 |
}; |
| 240 |
my $map_port_role = { |
| 241 |
0 => 'undef', 1 => 'cluster', 2 => 'data', |
| 242 |
3 => 'node-mgmt', 4 => 'intercluster', 5 => 'cluster-mgmt' |
| 243 |
}; |
| 244 |
|
| 245 |
my $mapping = { |
| 246 |
health => { oid => '.1.3.6.1.4.1.789.1.25.2.1.11', map => $map_node_health }, # nodeHealth |
| 247 |
cpuUptime => { oid => '.1.3.6.1.4.1.789.1.25.2.1.15' }, # nodeCpuUptime |
| 248 |
cpuBusyTime => { oid => '.1.3.6.1.4.1.789.1.25.2.1.16' }, # nodeCpuBusyTime |
| 249 |
bbuStatus => { oid => '.1.3.6.1.4.1.789.1.25.2.1.17', map => $map_nvram_status }, # nodeNvramBatteryStatus |
| 250 |
envOverTemp => { oid => '.1.3.6.1.4.1.789.1.25.2.1.18' }, # nodeEnvOverTemperature |
| 251 |
envFailedFanCount => { oid => '.1.3.6.1.4.1.789.1.25.2.1.19' }, # nodeEnvFailedFanCount |
| 252 |
envFailedPSUCount => { oid => '.1.3.6.1.4.1.789.1.25.2.1.21' } # nodeEnvFailedPowerSupplyCount |
| 253 |
}; |
| 254 |
my $mapping_port = { |
| 255 |
port_id => { oid => '.1.3.6.1.4.1.789.1.22.2.1.2' }, # netportPort |
| 256 |
role => { oid => '.1.3.6.1.4.1.789.1.22.2.1.3', map => $map_port_role }, # netportRole |
| 257 |
opstatus => { oid => '.1.3.6.1.4.1.789.1.22.2.1.4', map => $map_port_state }, # netportLinkState |
| 258 |
admstatus => { oid => '.1.3.6.1.4.1.789.1.22.2.1.14', map => $map_port_admin }, # netportUpAdmin |
| 259 |
health => { oid => '.1.3.6.1.4.1.789.1.22.2.1.30', map => $map_port_health } # netportHealthStatus |
| 260 |
}; |
| 261 |
|
| 262 |
sub add_ports { |
| 263 |
my ($self, %options) = @_; |
| 264 |
|
| 265 |
my $oid_netportNode = '.1.3.6.1.4.1.789.1.22.2.1.1'; |
| 266 |
my $snmp_result = $options{snmp}->get_table( |
| 267 |
oid => $oid_netportNode |
| 268 |
); |
| 269 |
my $instances = {}; |
| 270 |
foreach (keys %$snmp_result) { |
| 271 |
next if (!defined($self->{nodes}->{ $snmp_result->{$_} })); |
| 272 |
|
| 273 |
/^$oid_netportNode\.(.*)$/; |
| 274 |
$instances->{$1} = $snmp_result->{$_}; |
| 275 |
} |
| 276 |
|
| 277 |
return if (scalar(keys %$instances) <= 0); |
| 278 |
|
| 279 |
$options{snmp}->load( |
| 280 |
oids => [ map($_->{oid}, values(%$mapping_port)) ], |
| 281 |
instances => [ keys %$instances ], |
| 282 |
instance_regexp => '^(.*)$' |
| 283 |
); |
| 284 |
$snmp_result = $options{snmp}->get_leef(); |
| 285 |
foreach (keys %$instances) { |
| 286 |
my $result = $options{snmp}->map_instance(mapping => $mapping_port, results => $snmp_result, instance => $_); |
| 287 |
|
| 288 |
if (defined($self->{option_results}->{filter_port_id}) && $self->{option_results}->{filter_port_id} ne '' && |
| 289 |
$result->{port_id} !~ /$self->{option_results}->{filter_port_id}/) { |
| 290 |
$self->{output}->output_add(long_msg => "skipping port '" . $result->{port_id} . "'.", debug => 1); |
| 291 |
next; |
| 292 |
} |
| 293 |
if (defined($self->{option_results}->{filter_port_role}) && $self->{option_results}->{filter_port_role} ne '' && |
| 294 |
$result->{role} !~ /$self->{option_results}->{filter_port_role}/) { |
| 295 |
$self->{output}->output_add(long_msg => "skipping port '" . $result->{port_id} . "'.", debug => 1); |
| 296 |
next; |
| 297 |
} |
| 298 |
|
| 299 |
$self->{nodes}->{ $instances->{$_} }->{ports}->{ $result->{port_id} } = $result; |
| 300 |
$self->{nodes}->{ $instances->{$_} }->{ports}->{ $result->{port_id} }->{node_name} = $instances->{$_}; |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
sub manage_selection { |
| 305 |
my ($self, %options) = @_; |
| 306 |
|
| 307 |
my $oid_nodeName = '.1.3.6.1.4.1.789.1.25.2.1.1'; |
| 308 |
my $snmp_result = $options{snmp}->get_table( |
| 309 |
oid => $oid_nodeName, |
| 310 |
nothing_quit => 1 |
| 311 |
); |
| 312 |
|
| 313 |
$self->{nodes} = {}; |
| 314 |
foreach (keys %$snmp_result) { |
| 315 |
/$oid_nodeName\.(.*)$/; |
| 316 |
|
| 317 |
my $instance = $1; |
| 318 |
my $name = $snmp_result->{$_}; |
| 319 |
if (defined($self->{option_results}->{filter_node_name}) && $self->{option_results}->{filter_node_name} ne '' && |
| 320 |
$name !~ /$self->{option_results}->{filter_node_name}/) { |
| 321 |
$self->{output}->output_add(long_msg => "skipping node '" . $name . "'.", debug => 1); |
| 322 |
next; |
| 323 |
} |
| 324 |
|
| 325 |
$self->{nodes}->{$name} = { |
| 326 |
instance => $instance, |
| 327 |
name => $name, |
| 328 |
status => { name => $name }, |
| 329 |
ports => {} |
| 330 |
}; |
| 331 |
} |
| 332 |
|
| 333 |
return if (scalar(keys %{$self->{nodes}}) <= 0); |
| 334 |
|
| 335 |
$options{snmp}->load( |
| 336 |
oids => [ map($_->{oid}, values(%$mapping)) ], |
| 337 |
instances => [ map($_->{instance}, values(%{$self->{nodes}})) ], |
| 338 |
instance_regexp => '^(.*)$' |
| 339 |
); |
| 340 |
$snmp_result = $options{snmp}->get_leef(); |
| 341 |
foreach (keys %{$self->{nodes}}) { |
| 342 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{nodes}->{$_}->{instance}); |
| 343 |
|
| 344 |
$self->{nodes}->{$_}->{status}->{node_status} = $result->{node_status}; |
| 345 |
$self->{nodes}->{$_}->{status}->{bbu_status} = $result->{bbu_status}; |
| 346 |
|
| 347 |
$self->{nodes}->{$_}->{cpu} = { |
| 348 |
cpuUptime => $result->{cpuUptime}, |
| 349 |
cpuBusyTime => $result->{cpuBusyTime} |
| 350 |
}; |
| 351 |
$self->{nodes}->{$_}->{env} = { |
| 352 |
envOverTemp => $result->{envOverTemp}, |
| 353 |
envFailedFanCount => $result->{envFailedFanCount}, |
| 354 |
envFailedPSUCount => $result->{envFailedPSUCount} |
| 355 |
}; |
| 356 |
} |
| 357 |
|
| 358 |
$self->add_ports(snmp => $options{snmp}); |
| 359 |
|
| 360 |
$self->{cache_name} = 'netapp_ontap_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 361 |
md5_hex( |
| 362 |
(defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : 'all') . '_' . |
| 363 |
(defined($self->{option_results}->{filter_node_name}) ? $self->{option_results}->{filter_node_name} : 'all') . '_' . |
| 364 |
(defined($self->{option_results}->{filter_port_id}) ? $self->{option_results}->{filter_port_id} : 'all') . '_' . |
| 365 |
(defined($self->{option_results}->{filter_port_role}) ? $self->{option_results}->{filter_port_role} : 'all') |
| 366 |
); |
| 367 |
} |
| 368 |
|
| 369 |
1; |
| 370 |
|
| 371 |
__END__ |
| 372 |
|
| 373 |
=head1 MODE |
| 374 |
|
| 375 |
Check cluster nodes. |
| 376 |
|
| 377 |
=over 8 |
| 378 |
|
| 379 |
=item B<--filter-node-name> |
| 380 |
|
| 381 |
Filter nodes by name (can be a regexp). |
| 382 |
|
| 383 |
=item B<--filter-port-id> |
| 384 |
|
| 385 |
Filter ports by ID (can be a regexp). |
| 386 |
|
| 387 |
=item B<--filter-port-role> |
| 388 |
|
| 389 |
Filter ports by role (can be a regexp). |
| 390 |
|
| 391 |
=item B<--unknown-node-status> |
| 392 |
|
| 393 |
Define the conditions to match for the status to be UNKNOWN. |
| 394 |
You can use the following variables: %{node_status}, %{node_name} |
| 395 |
|
| 396 |
=item B<--warning-node-status> |
| 397 |
|
| 398 |
Define the conditions to match for the status to be WARNING. |
| 399 |
You can use the following variables: %{node_status}, %{node_name} |
| 400 |
|
| 401 |
=item B<--critical-node-status> |
| 402 |
|
| 403 |
Define the conditions to match for the status to be CRITICAL (default: '%{node_status} eq "clusterComLost"'). |
| 404 |
You can use the following variables: %{node_status}, %{node_name} |
| 405 |
|
| 406 |
=item B<--unknown-bbu-status> |
| 407 |
|
| 408 |
Define the conditions to match for the status to be UNKNOWN. |
| 409 |
You can use the following variables: %{bbu_status}, %{node_name} |
| 410 |
|
| 411 |
=item B<--warning-bbu-status> |
| 412 |
|
| 413 |
Define the conditions to match for the status to be WARNING. |
| 414 |
You can use the following variables: %{bbu_status}, %{node_name} |
| 415 |
|
| 416 |
=item B<--critical-bbu-status> |
| 417 |
|
| 418 |
Define the conditions to match for the status to be CRITICAL (default: '%{bbu_status} !~ /fullyCharged|ok/i'). |
| 419 |
You can use the following variables: %{bbu_status}, %{node_name} |
| 420 |
|
| 421 |
=item B<--unknown-port-link-status> |
| 422 |
|
| 423 |
Define the conditions to match for the status to be UNKNOWN. |
| 424 |
You can use the following variables: %{admstatus}, %{opstatus}, %{port_id}, %{node_name} |
| 425 |
|
| 426 |
=item B<--warning-port-link-status> |
| 427 |
|
| 428 |
Define the conditions to match for the status to be WARNING. |
| 429 |
You can use the following variables: %{admstatus}, %{opstatus}, %{port_id}, %{node_name} |
| 430 |
|
| 431 |
=item B<--critical-port-link-status> |
| 432 |
|
| 433 |
Define the conditions to match for the status to be CRITICAL (default: '%{admstatus} eq "up" and %{opstatus} ne "up"'). |
| 434 |
You can use the following variables: %{admstatus}, %{opstatus}, %{port_id}, %{node_name} |
| 435 |
|
| 436 |
=item B<--unknown-port-health> |
| 437 |
|
| 438 |
Define the conditions to match for the status to be UNKNOWN. |
| 439 |
You can use the following variables: %{health}, %{port_id}, %{node_name} |
| 440 |
|
| 441 |
=item B<--warning-port-health> |
| 442 |
|
| 443 |
Define the conditions to match for the status to be WARNING (default: '%{health} eq "degraded"'). |
| 444 |
You can use the following variables: %{health}, %{port_id}, %{node_name} |
| 445 |
|
| 446 |
=item B<--critical-port-health> |
| 447 |
|
| 448 |
Define the conditions to match for the status to be CRITICAL. |
| 449 |
You can use the following variables: %{health}, %{port_id}, %{node_name} |
| 450 |
|
| 451 |
=item B<--warning-*> B<--critical-*> |
| 452 |
|
| 453 |
Thresholds. |
| 454 |
Can be: 'cpu-utilization', 'temperature-overrange', 'fan-failed', 'psu-failed'. |
| 455 |
|
| 456 |
=back |
| 457 |
|
| 458 |
=cut |