| 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::partnerstatus; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
my %mapping_partner_status = ( |
| 29 |
1 => 'maybeDown', |
| 30 |
2 => 'ok', |
| 31 |
3 => 'dead', |
| 32 |
); |
| 33 |
my %mapping_interconnect_status = ( |
| 34 |
1 => 'notPresent', |
| 35 |
2 => 'down', |
| 36 |
3 => 'partialFailure', |
| 37 |
4 => 'up', |
| 38 |
); |
| 39 |
my $thresholds = { |
| 40 |
partner => [ |
| 41 |
['maybeDown', 'WARNING'], |
| 42 |
['ok', 'OK'], |
| 43 |
['dead', 'CRITICAL'], |
| 44 |
], |
| 45 |
interconnect => [ |
| 46 |
['notPresent', 'CRITICAL'], |
| 47 |
['down', 'CRITICAL'], |
| 48 |
['partialFailure', 'WARNING'], |
| 49 |
['up', 'OK'], |
| 50 |
], |
| 51 |
}; |
| 52 |
|
| 53 |
sub new { |
| 54 |
my ($class, %options) = @_; |
| 55 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 56 |
bless $self, $class; |
| 57 |
|
| 58 |
$options{options}->add_options(arguments => { |
| 59 |
'threshold-overload:s@' => { name => 'threshold_overload' }, |
| 60 |
}); |
| 61 |
|
| 62 |
return $self; |
| 63 |
} |
| 64 |
|
| 65 |
sub check_options { |
| 66 |
my ($self, %options) = @_; |
| 67 |
$self->SUPER::init(%options); |
| 68 |
|
| 69 |
$self->{overload_th} = {}; |
| 70 |
foreach my $val (@{$self->{option_results}->{threshold_overload}}) { |
| 71 |
if ($val !~ /^(.*?),(.*?),(.*)$/) { |
| 72 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); |
| 73 |
$self->{output}->option_exit(); |
| 74 |
} |
| 75 |
my ($section, $status, $filter) = ($1, $2, $3); |
| 76 |
if ($self->{output}->is_litteral_status(status => $status) == 0) { |
| 77 |
$self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); |
| 78 |
$self->{output}->option_exit(); |
| 79 |
} |
| 80 |
$self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); |
| 81 |
push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
my $mapping = { |
| 86 |
cfPartnerStatus => { oid => '.1.3.6.1.4.1.789.1.2.3.4', map => \%mapping_partner_status }, |
| 87 |
}; |
| 88 |
my $mapping2 = { |
| 89 |
cfInterconnectStatus => { oid => '.1.3.6.1.4.1.789.1.2.3.8', map => \%mapping_interconnect_status }, |
| 90 |
}; |
| 91 |
my $mapping3 = { |
| 92 |
haPartnerStatus => { oid => '.1.3.6.1.4.1.789.1.21.2.1.6', map => \%mapping_partner_status }, |
| 93 |
}; |
| 94 |
my $mapping4 = { |
| 95 |
haInterconnectStatus => { oid => '.1.3.6.1.4.1.789.1.21.2.1.10', map => \%mapping_interconnect_status }, |
| 96 |
}; |
| 97 |
|
| 98 |
sub run { |
| 99 |
my ($self, %options) = @_; |
| 100 |
$self->{snmp} = $options{snmp}; |
| 101 |
|
| 102 |
my $oid_cfPartnerName = '.1.3.6.1.4.1.789.1.2.3.6'; |
| 103 |
my $oid_haNodeName = '.1.3.6.1.4.1.789.1.21.2.1.1'; |
| 104 |
my $results = $self->{snmp}->get_multiple_table(oids => [ |
| 105 |
{ oid => $oid_cfPartnerName }, |
| 106 |
{ oid => $mapping->{cfPartnerStatus}->{oid} }, |
| 107 |
{ oid => $mapping2->{cfInterconnectStatus}->{oid} }, |
| 108 |
{ oid => $oid_haNodeName }, |
| 109 |
{ oid => $mapping3->{haPartnerStatus}->{oid} }, |
| 110 |
{ oid => $mapping4->{haInterconnectStatus}->{oid} }, |
| 111 |
], nothing_quit => 1); |
| 112 |
|
| 113 |
if (defined($results->{$mapping->{cfPartnerStatus}->{oid}}->{$mapping->{cfPartnerStatus}->{oid} . '.0'})) { |
| 114 |
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $results->{$mapping->{cfPartnerStatus}->{oid}}, instance => '0'); |
| 115 |
my $exit = $self->get_severity(section => 'partner', value => $result->{cfPartnerStatus}); |
| 116 |
$self->{output}->output_add(severity => $exit, |
| 117 |
short_msg => sprintf("Partner '%s' status is '%s'", $results->{$oid_cfPartnerName}->{$oid_cfPartnerName . '.0'}, $result->{cfPartnerStatus})); |
| 118 |
$result = $self->{snmp}->map_instance(mapping => $mapping2, results => $results->{$mapping2->{cfInterconnectStatus}->{oid}}, instance => '0'); |
| 119 |
$exit = $self->get_severity(section => 'interconnect', value => $result->{cfInterconnectStatus}); |
| 120 |
$self->{output}->output_add(severity => $exit, |
| 121 |
short_msg => sprintf("Interconnect status is '%s'", $result->{cfInterconnectStatus})); |
| 122 |
} else { |
| 123 |
$self->{output}->output_add(severity => 'OK', |
| 124 |
short_msg => 'HA status are ok on all nodes'); |
| 125 |
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$results->{$mapping3->{haPartnerStatus}->{oid}}})) { |
| 126 |
$oid =~ /^$mapping3->{haPartnerStatus}->{oid}\.(.*)$/; |
| 127 |
my $instance = $1; |
| 128 |
my $name = $results->{$oid_haNodeName}->{$oid_haNodeName . '.' . $instance}; |
| 129 |
my $result = $self->{snmp}->map_instance(mapping => $mapping3, results => $results->{$mapping3->{haPartnerStatus}->{oid}}, instance => $instance); |
| 130 |
|
| 131 |
my $exit = $self->get_severity(section => 'partner', value => $result->{haPartnerStatus}); |
| 132 |
$self->{output}->output_add(long_msg => sprintf("Partner status of node '%s' is '%s'", |
| 133 |
$name, $result->{haPartnerStatus})); |
| 134 |
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { |
| 135 |
$self->{output}->output_add(severity => $exit, |
| 136 |
short_msg => sprintf("Partner status of node '%s' is '%s'", |
| 137 |
$name, $result->{haPartnerStatus})); |
| 138 |
} |
| 139 |
|
| 140 |
$result = $self->{snmp}->map_instance(mapping => $mapping4, results => $results->{$mapping4->{haInterconnectStatus}->{oid}}, instance => $instance); |
| 141 |
$exit = $self->get_severity(section => 'interconnect', value => $result->{haInterconnectStatus}); |
| 142 |
$self->{output}->output_add(long_msg => sprintf("Interconnect status on node '%s' is '%s'", |
| 143 |
$name, $result->{haInterconnectStatus})); |
| 144 |
if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { |
| 145 |
$self->{output}->output_add(severity => $exit, |
| 146 |
short_msg => sprintf("Interconnect status on node '%s' is '%s'", |
| 147 |
$name, $result->{haInterconnectStatus})); |
| 148 |
} |
| 149 |
} |
| 150 |
} |
| 151 |
|
| 152 |
$self->{output}->display(); |
| 153 |
$self->{output}->exit(); |
| 154 |
} |
| 155 |
|
| 156 |
sub get_severity { |
| 157 |
my ($self, %options) = @_; |
| 158 |
my $status = 'UNKNOWN'; # default |
| 159 |
|
| 160 |
if (defined($self->{overload_th}->{$options{section}})) { |
| 161 |
foreach (@{$self->{overload_th}->{$options{section}}}) { |
| 162 |
if ($options{value} =~ /$_->{filter}/i) { |
| 163 |
$status = $_->{status}; |
| 164 |
return $status; |
| 165 |
} |
| 166 |
} |
| 167 |
} |
| 168 |
foreach (@{$thresholds->{$options{section}}}) { |
| 169 |
if ($options{value} =~ /$$_[0]/i) { |
| 170 |
$status = $$_[1]; |
| 171 |
return $status; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
return $status; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
1; |
| 180 |
|
| 181 |
__END__ |
| 182 |
|
| 183 |
=head1 MODE |
| 184 |
|
| 185 |
Check status of clustered failover partner. |
| 186 |
|
| 187 |
=over 8 |
| 188 |
|
| 189 |
=item B<--threshold-overload> |
| 190 |
|
| 191 |
Use this option to override the status returned by the plugin when the status label matches a regular expression (syntax: section,status,regexp). |
| 192 |
Example: --threshold-overload='partner,CRITICAL,^(?!(ok)$)' |
| 193 |
|
| 194 |
=back |
| 195 |
|
| 196 |
=cut |
| 197 |
|