| 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 network::f5::bigip::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); |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'global', type => 0, message_separator => ' - ' }, |
| 34 |
]; |
| 35 |
|
| 36 |
$self->{maps_counters}->{global} = [ |
| 37 |
{ label => 'sync-status', threshold => 0, set => { |
| 38 |
key_values => [ { name => 'syncstatus' } ], |
| 39 |
closure_custom_calc => \&custom_syncstatus_calc, |
| 40 |
closure_custom_output => \&custom_syncstatus_output, |
| 41 |
closure_custom_perfdata => sub { return 0; }, |
| 42 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'failover-status', threshold => 0, set => { |
| 46 |
key_values => [ { name => 'failoverstatus' } ], |
| 47 |
closure_custom_calc => \&custom_failoverstatus_calc, |
| 48 |
closure_custom_output => \&custom_failoverstatus_output, |
| 49 |
closure_custom_perfdata => sub { return 0; }, |
| 50 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 51 |
} |
| 52 |
}, |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
sub custom_syncstatus_output { |
| 57 |
my ($self, %options) = @_; |
| 58 |
my $msg = "Sync status is '" . $self->{result_values}->{syncstatus} . "'"; |
| 59 |
|
| 60 |
return $msg; |
| 61 |
} |
| 62 |
|
| 63 |
sub custom_syncstatus_calc { |
| 64 |
my ($self, %options) = @_; |
| 65 |
|
| 66 |
$self->{result_values}->{syncstatus} = $options{new_datas}->{$self->{instance} . '_syncstatus'}; |
| 67 |
return 0; |
| 68 |
} |
| 69 |
|
| 70 |
sub custom_failoverstatus_output { |
| 71 |
my ($self, %options) = @_; |
| 72 |
my $msg = "Failover status is '" . $self->{result_values}->{failoverstatus} . "'"; |
| 73 |
|
| 74 |
return $msg; |
| 75 |
} |
| 76 |
|
| 77 |
sub custom_failoverstatus_calc { |
| 78 |
my ($self, %options) = @_; |
| 79 |
|
| 80 |
$self->{result_values}->{failoverstatus} = $options{new_datas}->{$self->{instance} . '_failoverstatus'}; |
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
sub new { |
| 85 |
my ($class, %options) = @_; |
| 86 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 87 |
bless $self, $class; |
| 88 |
|
| 89 |
$options{options}->add_options(arguments => { |
| 90 |
'warning-sync-status:s' => { name => 'warning_sync_status', default => '' }, |
| 91 |
'critical-sync-status:s' => { name => 'critical_sync_status', default => '%{syncstatus} =~ /unknown|syncFailed|syncDisconnected|incompatibleVersion/' }, |
| 92 |
'warning-failover-status:s' => { name => 'warning_failover_status', default => '' }, |
| 93 |
'critical-failover-status:s' => { name => 'critical_failover_status', default => '%{failoverstatus} =~ /unknown/' }, |
| 94 |
}); |
| 95 |
|
| 96 |
return $self; |
| 97 |
} |
| 98 |
|
| 99 |
sub check_options { |
| 100 |
my ($self, %options) = @_; |
| 101 |
$self->SUPER::check_options(%options); |
| 102 |
|
| 103 |
$self->change_macros(macros => ['warning_sync_status', 'critical_sync_status', 'warning_failover_status', 'critical_failover_status']); |
| 104 |
} |
| 105 |
|
| 106 |
my %map_boolean = ( |
| 107 |
0 => 'false', |
| 108 |
1 => 'true', |
| 109 |
); |
| 110 |
my %map_sync_status = ( |
| 111 |
0 => 'unknown', |
| 112 |
1 => 'syncing', |
| 113 |
2 => 'needManualSync', |
| 114 |
3 => 'inSync', |
| 115 |
4 => 'syncFailed', |
| 116 |
5 => 'syncDisconnected', |
| 117 |
6 => 'standalone', |
| 118 |
7 => 'awaitingInitialSync', |
| 119 |
8 => 'incompatibleVersion', |
| 120 |
9 => 'partialSync', |
| 121 |
); |
| 122 |
my %map_failover_status = ( |
| 123 |
0 => 'unknown', |
| 124 |
1 => 'offline', |
| 125 |
2 => 'forcedOffline', |
| 126 |
3 => 'standby', |
| 127 |
4 => 'active', |
| 128 |
); |
| 129 |
|
| 130 |
my $mapping = { |
| 131 |
sysAttrFailoverIsRedundant => { oid => '.1.3.6.1.4.1.3375.2.1.1.1.1.13', map => \%map_boolean }, |
| 132 |
sysAttrModeMaint => { oid => '.1.3.6.1.4.1.3375.2.1.1.1.1.21', map => \%map_boolean }, |
| 133 |
sysCmSyncStatusId => { oid => '.1.3.6.1.4.1.3375.2.1.14.1.1', map => \%map_sync_status }, |
| 134 |
sysCmFailoverStatusId => { oid => '.1.3.6.1.4.1.3375.2.1.14.3.1', map => \%map_failover_status }, |
| 135 |
}; |
| 136 |
|
| 137 |
sub manage_selection { |
| 138 |
my ($self, %options) = @_; |
| 139 |
|
| 140 |
my $snmp_result = $options{snmp}->get_leef( |
| 141 |
oids => [ |
| 142 |
$mapping->{sysAttrFailoverIsRedundant}->{oid} . '.0', |
| 143 |
$mapping->{sysAttrModeMaint}->{oid} . '.0', |
| 144 |
$mapping->{sysCmSyncStatusId}->{oid} . '.0', |
| 145 |
$mapping->{sysCmFailoverStatusId}->{oid} . '.0' |
| 146 |
], |
| 147 |
nothing_quit => 1 |
| 148 |
); |
| 149 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); |
| 150 |
|
| 151 |
if ($result->{sysAttrModeMaint} eq 'true') { |
| 152 |
$self->{output}->output_add( |
| 153 |
severity => 'OK', |
| 154 |
short_msg => 'maintenance mode is active' |
| 155 |
); |
| 156 |
$self->{output}->display(); |
| 157 |
$self->{output}->exit(); |
| 158 |
} |
| 159 |
if ($result->{sysAttrFailoverIsRedundant} eq 'false') { |
| 160 |
$self->{output}->output_add( |
| 161 |
severity => 'OK', |
| 162 |
short_msg => 'failover mode is disable' |
| 163 |
); |
| 164 |
$self->{output}->display(); |
| 165 |
$self->{output}->exit(); |
| 166 |
} |
| 167 |
|
| 168 |
$self->{global} = { |
| 169 |
syncstatus => $result->{sysCmSyncStatusId}, |
| 170 |
failoverstatus => $result->{sysCmFailoverStatusId}, |
| 171 |
}; |
| 172 |
} |
| 173 |
|
| 174 |
1; |
| 175 |
|
| 176 |
__END__ |
| 177 |
|
| 178 |
=head1 MODE |
| 179 |
|
| 180 |
Check failover status. |
| 181 |
|
| 182 |
=over 8 |
| 183 |
|
| 184 |
=item B<--filter-counters> |
| 185 |
|
| 186 |
Only display some counters (regexp can be used). |
| 187 |
|
| 188 |
=item B<--warning-sync-status> |
| 189 |
|
| 190 |
Set warning threshold for sync status |
| 191 |
You can use the following variables: %{syncstatus} |
| 192 |
|
| 193 |
=item B<--critical-sync-status> |
| 194 |
|
| 195 |
Set critical threshold for sync status (default: '%{syncstatus} =~ /unknown|syncFailed|syncDisconnected|incompatibleVersion/'). |
| 196 |
You can use the following variables: %{syncstatus} |
| 197 |
|
| 198 |
=item B<--warning-failover-status> |
| 199 |
|
| 200 |
Set warning threshold for failover status |
| 201 |
You can use the following variables: %{failoverstatus} |
| 202 |
|
| 203 |
=item B<--critical-failover-status> |
| 204 |
|
| 205 |
Set critical threshold for failover status (default: '%{failoverstatus} =~ /unknown/'). |
| 206 |
You can use the following variables: %{failoverstatus} |
| 207 |
|
| 208 |
=back |
| 209 |
|
| 210 |
=cut |