| 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::failover; |
| 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 catalog_status_calc); |
| 28 |
|
| 29 |
sub custom_cluster_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
"cluster status is '%s' [partner status: %s][reason cannot takeover: %s]", |
| 34 |
$self->{result_values}->{cluster_status}, |
| 35 |
$self->{result_values}->{partner_status}, |
| 36 |
$self->{result_values}->{reason_cannot_takeover} |
| 37 |
); |
| 38 |
} |
| 39 |
|
| 40 |
sub custom_node_output { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
return sprintf( |
| 44 |
"status is '%s' [partner status: %s][reason cannot takeover: %s]", |
| 45 |
$self->{result_values}->{status}, |
| 46 |
$self->{result_values}->{partner_status}, |
| 47 |
$self->{result_values}->{reason_cannot_takeover} |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
sub set_counters { |
| 52 |
my ($self, %options) = @_; |
| 53 |
|
| 54 |
$self->{maps_counters_type} = [ |
| 55 |
{ name => 'global', type => 0, skipped_code => { -10 => 1 } }, |
| 56 |
{ name => 'nodes', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All high-availability nodes are OK' }, |
| 57 |
]; |
| 58 |
|
| 59 |
$self->{maps_counters}->{global} = [ |
| 60 |
{ label => 'cluster-status', set => { |
| 61 |
key_values => [ { name => 'cluster_status' }, { name => 'reason_cannot_takeover' }, { name => 'partner_status' } ], |
| 62 |
closure_custom_calc => \&catalog_status_calc, |
| 63 |
closure_custom_output => $self->can('custom_cluster_output'), |
| 64 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 65 |
closure_custom_perfdata => sub { return 0; }, |
| 66 |
} |
| 67 |
} |
| 68 |
]; |
| 69 |
|
| 70 |
$self->{maps_counters}->{nodes} = [ |
| 71 |
{ label => 'node-status', threshold => 0, set => { |
| 72 |
key_values => [ { name => 'status' }, { name => 'reason_cannot_takeover' }, { name => 'partner_status' }, { name => 'display' } ], |
| 73 |
closure_custom_calc => \&catalog_status_calc, |
| 74 |
closure_custom_output => $self->can('custom_node_output'), |
| 75 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 76 |
closure_custom_perfdata => sub { return 0; }, |
| 77 |
} |
| 78 |
} |
| 79 |
]; |
| 80 |
} |
| 81 |
|
| 82 |
sub prefix_node_output { |
| 83 |
my ($self, %options) = @_; |
| 84 |
|
| 85 |
return "Node '" . $options{instance_value}->{display} . "' "; |
| 86 |
} |
| 87 |
|
| 88 |
sub new { |
| 89 |
my ($class, %options) = @_; |
| 90 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 91 |
bless $self, $class; |
| 92 |
|
| 93 |
$options{options}->add_options(arguments => { |
| 94 |
'filter-node:s' => { name => 'filter_node' }, |
| 95 |
'unknown-cluster-status:s' => { name => 'unknown_cluster_status', default => '' }, |
| 96 |
'warning-cluster-status:s' => { name => 'warning_cluster_status', default => '%{cluster_status} =~ /^takeover|partialGiveback/i' }, |
| 97 |
'critical-cluster-status:s' => { name => 'critical_cluster_status', default => '%{cluster_status} =~ /dead|cannotTakeover/i' }, |
| 98 |
'unknown-node-status:s' => { name => 'unknown_node_status', default => '' }, |
| 99 |
'warning-node-status:s' => { name => 'warning_node_status', default => '%{status} =~ /^takeover|partialGiveback/i' }, |
| 100 |
'critical-node-status:s' => { name => 'critical_node_status', default => '%{status} =~ /dead|cannotTakeover/i' }, |
| 101 |
}); |
| 102 |
|
| 103 |
return $self; |
| 104 |
} |
| 105 |
|
| 106 |
sub check_options { |
| 107 |
my ($self, %options) = @_; |
| 108 |
$self->SUPER::check_options(%options); |
| 109 |
|
| 110 |
$self->change_macros(macros => [ |
| 111 |
'unknown_cluster_status', 'warning_cluster_status', 'critical_cluster_status', |
| 112 |
'unknown_node_status', 'warning_node_status', 'critical_node_status' |
| 113 |
]); |
| 114 |
} |
| 115 |
|
| 116 |
my $map_cannot_takeover = { |
| 117 |
1 => 'ok', 2 => 'unknownReason', |
| 118 |
3 => 'disabledByOperator', 4 => 'interconnectOffline', |
| 119 |
5 => 'disabledByPartner', 6 => 'takeoverFailed', |
| 120 |
7 => 'mailboxIsInDegradedState', 8 => 'partnermailboxIsInUninitialisedState', |
| 121 |
9 => 'mailboxVersionMismatch', 10 => 'nvramSizeMismatch', |
| 122 |
11 => 'kernelVersionMismatch', 12 => 'partnerIsInBootingStage', |
| 123 |
13 => 'diskshelfIsTooHot', 14 => 'partnerIsPerformingRevert', |
| 124 |
15 => 'nodeIsPerformingRevert', 16 => 'sametimePartnerIsAlsoTryingToTakeUsOver', |
| 125 |
17 => 'alreadyInTakenoverMode', 18 => 'nvramLogUnsynchronized', |
| 126 |
19 => 'stateofBackupMailboxIsDoubtful', 19 => 'stateofBackupMailboxIsDoubtful' |
| 127 |
}; |
| 128 |
my $map_state = { |
| 129 |
1 => 'dead', 2 => 'canTakeover', |
| 130 |
3 => 'cannotTakeover', 4 => 'takeover', |
| 131 |
5 => 'partialGiveback' |
| 132 |
}; |
| 133 |
my $map_partner_status = { |
| 134 |
1 => 'maybeDown', 2 => 'ok', 3 => 'dead' |
| 135 |
}; |
| 136 |
|
| 137 |
my $mapping_cf = { |
| 138 |
cfState => { oid => '.1.3.6.1.4.1.789.1.2.3.2', map => $map_state }, |
| 139 |
cfCannotTakeoverCause => { oid => '.1.3.6.1.4.1.789.1.2.3.3', map => $map_cannot_takeover }, |
| 140 |
cfPartnerStatus => { oid => '.1.3.6.1.4.1.789.1.2.3.4', map => $map_partner_status }, |
| 141 |
}; |
| 142 |
my $mapping_ha = { |
| 143 |
haState => { oid => '.1.3.6.1.4.1.789.1.21.2.1.4', map => $map_state }, |
| 144 |
haCannotTakeoverCause => { oid => '.1.3.6.1.4.1.789.1.21.2.1.5', map => $map_cannot_takeover }, |
| 145 |
haPartnerStatus => { oid => '.1.3.6.1.4.1.789.1.21.2.1.6', map => $map_partner_status }, |
| 146 |
}; |
| 147 |
my $oid_cf = '.1.3.6.1.4.1.789.1.2.3'; |
| 148 |
my $oid_haEntry = '.1.3.6.1.4.1.789.1.21.2.1'; |
| 149 |
|
| 150 |
sub manage_selection { |
| 151 |
my ($self, %options) = @_; |
| 152 |
|
| 153 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 154 |
oids => [ |
| 155 |
{ oid => $oid_cf, start => $mapping_cf->{cfState}->{oid}, end => $mapping_cf->{cfPartnerStatus}->{oid} }, |
| 156 |
{ oid => $oid_haEntry, start => $mapping_ha->{haState}->{oid}, end => $mapping_ha->{haPartnerStatus}->{oid} }, |
| 157 |
], |
| 158 |
nothing_quit => 1 |
| 159 |
); |
| 160 |
my $result = $options{snmp}->map_instance(mapping => $mapping_cf, results => $snmp_result->{$oid_cf}, instance => '0'); |
| 161 |
$self->{global} = { |
| 162 |
cluster_status => $result->{cfState}, |
| 163 |
reason_cannot_takeover => $result->{cfCannotTakeoverCause}, |
| 164 |
partner_status => $result->{cfPartnerStatus} |
| 165 |
}; |
| 166 |
|
| 167 |
$self->{nodes} = {}; |
| 168 |
foreach my $oid (keys %{$snmp_result->{$oid_haEntry}}) { |
| 169 |
next if ($oid !~ /^$mapping_ha->{haState}->{oid}\.(.*)$/); |
| 170 |
my $instance = $1; |
| 171 |
|
| 172 |
$result = $options{snmp}->map_instance(mapping => $mapping_ha, results => $snmp_result->{$oid_haEntry}, instance => $instance); |
| 173 |
my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $instance)))); |
| 174 |
if (defined($self->{option_results}->{filter_node}) && $self->{option_results}->{filter_node} ne '' && |
| 175 |
$name !~ /$self->{option_results}->{filter_node}/) { |
| 176 |
$self->{output}->output_add(long_msg => "skipping node '" . $name . "'.", debug => 1); |
| 177 |
next; |
| 178 |
} |
| 179 |
|
| 180 |
$self->{nodes}->{$instance} = { |
| 181 |
display => $name, |
| 182 |
status => $result->{haState}, |
| 183 |
reason_cannot_takeover => $result->{haCannotTakeoverCause}, |
| 184 |
partner_status => $result->{haPartnerStatus} |
| 185 |
}; |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
1; |
| 190 |
|
| 191 |
__END__ |
| 192 |
|
| 193 |
=head1 MODE |
| 194 |
|
| 195 |
Check failover status. |
| 196 |
|
| 197 |
=over 8 |
| 198 |
|
| 199 |
=item B<--filter-node> |
| 200 |
|
| 201 |
Filter name with regexp (based on serial) |
| 202 |
|
| 203 |
=item B<--unknown-cluster-status> |
| 204 |
|
| 205 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 206 |
You can use the following variables: %{cluster_status}, %{reason_cannot_takeover}, %{partner_status} |
| 207 |
|
| 208 |
=item B<--warning-cluster-status> |
| 209 |
|
| 210 |
Define the conditions to match for the status to be WARNING (default: '%{cluster_status} =~ /^takeover|partialGiveback/i'). |
| 211 |
You can use the following variables: %{cluster_status}, %{reason_cannot_takeover}, %{partner_status} |
| 212 |
|
| 213 |
=item B<--critical-cluster-status> |
| 214 |
|
| 215 |
Define the conditions to match for the status to be CRITICAL (default: '%{cluster_status} =~ /dead|cannotTakeover/i'). |
| 216 |
You can use the following variables: %{cluster_status}, %{reason_cannot_takeover}, %{partner_status} |
| 217 |
|
| 218 |
=item B<--unknown-node-status> |
| 219 |
|
| 220 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 221 |
You can use the following variables: %{status}, %{reason_cannot_takeover}, %{partner_status}, %{display} |
| 222 |
|
| 223 |
=item B<--warning-node-status> |
| 224 |
|
| 225 |
Define the conditions to match for the status to be WARNING (default: '%{status} =~ /^takeover|partialGiveback/i'). |
| 226 |
You can use the following variables: %{status}, %{reason_cannot_takeover}, %{partner_status}, %{display} |
| 227 |
|
| 228 |
=item B<--critical-node-status> |
| 229 |
|
| 230 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /dead|cannotTakeover/i'). |
| 231 |
You can use the following variables: %{status}, %{reason_cannot_takeover}, %{partner_status}, %{display} |
| 232 |
|
| 233 |
=back |
| 234 |
|
| 235 |
=cut |