(plugin) storage::netapp::ontap::snmp - mode global-status harden code check (#4341)

This commit is contained in:
qgarnier 2023-04-12 11:56:23 +02:00 committed by David Boucher
parent de4ef3eb51
commit 1b799785cb
1 changed files with 40 additions and 30 deletions

View File

@ -32,7 +32,7 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, skipped_code => { -10 => 1 } } { name => 'global', type => 0, skipped_code => { -10 => 1 } }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'read', nlabel => 'storage.io.read.usage.bytespersecond', set => { { label => 'read', nlabel => 'storage.io.read.usage.bytespersecond', set => {
key_values => [ { name => 'read', per_second => 1 } ], key_values => [ { name => 'read', per_second => 1 } ],
@ -60,8 +60,7 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {});
});
return $self; return $self;
} }
@ -72,12 +71,12 @@ my %states = (
3 => ['ok', 'OK'], 3 => ['ok', 'OK'],
4 => ['non critical', 'WARNING'], 4 => ['non critical', 'WARNING'],
5 => ['critical', 'CRITICAL'], 5 => ['critical', 'CRITICAL'],
6 => ['nonRecoverable', 'WARNING'], 6 => ['nonRecoverable', 'WARNING']
); );
my %fs_states = ( my %fs_states = (
1 => ['ok', 'OK'], 1 => ['ok', 'OK'],
2 => ['nearly full', 'WARNING'], 2 => ['nearly full', 'WARNING'],
3 => ['full', 'CRITICAL'], 3 => ['full', 'CRITICAL']
); );
my $oid_fsOverallStatus = '.1.3.6.1.4.1.789.1.5.7.1.0'; my $oid_fsOverallStatus = '.1.3.6.1.4.1.789.1.5.7.1.0';
@ -103,25 +102,42 @@ sub manage_selection {
if (!$options{snmp}->is_snmpv1()) { if (!$options{snmp}->is_snmpv1()) {
push @{$request}, ($oid_misc64DiskReadBytes, $oid_misc64DiskWriteBytes); push @{$request}, ($oid_misc64DiskReadBytes, $oid_misc64DiskWriteBytes);
} }
my $snmp_result = $options{snmp}->get_leef(oids => $request, nothing_quit => 1); my $snmp_result = $options{snmp}->get_leef(oids => $request, nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
$self->{global}->{read} = defined($snmp_result->{$oid_misc64DiskReadBytes}) ?
$snmp_result->{$oid_misc64DiskReadBytes} : if (defined($snmp_result->{$oid_misc64DiskReadBytes})) {
($snmp_result->{$oid_miscHighDiskReadBytes} << 32) + $snmp_result->{$oid_miscLowDiskReadBytes}; $self->{global}->{read} = $snmp_result->{$oid_misc64DiskReadBytes};
$self->{global}->{write} = defined($snmp_result->{$oid_misc64DiskWriteBytes}) ? } elsif (defined($snmp_result->{$oid_miscLowDiskReadBytes})) {
$snmp_result->{$oid_misc64DiskWriteBytes} : $self->{global}->{read} = ($snmp_result->{$oid_miscHighDiskReadBytes} << 32) + $snmp_result->{$oid_miscLowDiskReadBytes};
($snmp_result->{$oid_miscHighDiskWriteBytes} << 32) + $snmp_result->{$oid_miscLowDiskWriteBytes}; }
if (defined($snmp_result->{$oid_misc64DiskWriteBytes})) {
$self->{global}->{write} = $snmp_result->{$oid_misc64DiskWriteBytes};
} elsif (defined($snmp_result->{$oid_miscLowDiskWriteBytes})) {
$self->{global}->{write} = ($snmp_result->{$oid_miscHighDiskWriteBytes} << 32) + $snmp_result->{$oid_miscLowDiskWriteBytes};
}
$snmp_result->{$oid_miscGlobalStatusMessage} =~ s/\n//g; $snmp_result->{$oid_miscGlobalStatusMessage} =~ s/\n//g;
$self->{output}->output_add(severity => ${$states{$snmp_result->{$oid_miscGlobalStatus}}}[1], $self->{output}->output_add(
short_msg => sprintf("Overall global status is '%s' [message: '%s']", severity => ${$states{$snmp_result->{$oid_miscGlobalStatus}}}[1],
${$states{$snmp_result->{$oid_miscGlobalStatus}}}[0], $snmp_result->{$oid_miscGlobalStatusMessage})); short_msg => sprintf(
$snmp_result->{$oid_fsStatusMessage} =~ s/\n//g; "Overall global status is '%s' [message: '%s']",
$self->{output}->output_add(severity => ${$fs_states{$snmp_result->{$oid_fsOverallStatus}}}[1], $states{ $snmp_result->{$oid_miscGlobalStatus} }->[0], $snmp_result->{$oid_miscGlobalStatusMessage}
short_msg => sprintf("Overall file system status is '%s' [message: '%s']", )
${$fs_states{$snmp_result->{$oid_fsOverallStatus}}}[0], $snmp_result->{$oid_fsStatusMessage})); );
if (defined($snmp_result->{$oid_fsStatusMessage})) {
$snmp_result->{$oid_fsStatusMessage} =~ s/\n//g;
$self->{output}->output_add(
severity => ${$fs_states{$snmp_result->{$oid_fsOverallStatus}}}[1],
short_msg => sprintf(
"Overall file system status is '%s' [message: '%s']",
$fs_states{ $snmp_result->{$oid_fsOverallStatus} }->[0], $snmp_result->{$oid_fsStatusMessage}
)
);
}
$self->{cache_name} = "cache_netapp_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . $self->{cache_name} = "cache_netapp_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
@ -138,17 +154,11 @@ If you are in cluster mode, the following mode doesn't work. Ask to netapp to ad
=over 8 =over 8
=item B<--warning-*> =item B<--warning-*> B<--critical-*>
Threshold warning. Thresholds.
Can be: 'read', 'write'.
=item B<--critical-*>
Threshold critical.
Can be: 'read', 'write'. Can be: 'read', 'write'.
=back =back
=cut =cut