| 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::citrix::netscaler::snmp::mode::hastate; |
| 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_peer_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = sprintf("Peer status is '%s'", $self->{result_values}->{peer_status}); |
| 33 |
return $msg; |
| 34 |
} |
| 35 |
|
| 36 |
sub custom_ha_status_output { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
my $msg = sprintf( |
| 40 |
"High availibility status is '%s', mode is '%s'", |
| 41 |
$self->{result_values}->{ha_status}, |
| 42 |
$self->{result_values}->{ha_mode}, |
| 43 |
); |
| 44 |
return $msg; |
| 45 |
} |
| 46 |
|
| 47 |
sub set_counters { |
| 48 |
my ($self, %options) = @_; |
| 49 |
|
| 50 |
$self->{maps_counters_type} = [ |
| 51 |
{ name => 'global', type => 0, message_separator => ' - ' }, |
| 52 |
]; |
| 53 |
|
| 54 |
$self->{maps_counters}->{global} = [ |
| 55 |
{ label => 'ha-status', set => { |
| 56 |
key_values => [ { name => 'ha_status' }, { name => 'ha_mode' } ], |
| 57 |
closure_custom_calc => \&catalog_status_calc, |
| 58 |
closure_custom_output => $self->can('custom_ha_status_output'), |
| 59 |
closure_custom_perfdata => sub { return 0; }, |
| 60 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 61 |
} |
| 62 |
}, |
| 63 |
{ label => 'peer-status', set => { |
| 64 |
key_values => [ { name => 'peer_status' } ], |
| 65 |
closure_custom_calc => \&catalog_status_calc, |
| 66 |
closure_custom_output => $self->can('custom_peer_status_output'), |
| 67 |
closure_custom_perfdata => sub { return 0; }, |
| 68 |
closure_custom_threshold_check => \&catalog_status_threshold, |
| 69 |
} |
| 70 |
}, |
| 71 |
]; |
| 72 |
} |
| 73 |
|
| 74 |
sub new { |
| 75 |
my ($class, %options) = @_; |
| 76 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 77 |
bless $self, $class; |
| 78 |
|
| 79 |
$options{options}->add_options(arguments => { |
| 80 |
'unknown-ha-status:s' => { name => 'unknown_ha_status', default => '%{ha_status} =~ /unknown/i' }, |
| 81 |
'warning-ha-status:s' => { name => 'warning_ha_status', default => '' }, |
| 82 |
'critical-ha-status:s' => { name => 'critical_ha_status', default => '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i' }, |
| 83 |
'unknown-peer-status:s' => { name => 'unknown_peer_status', default => '%{peer_status} =~ /unknown/i' }, |
| 84 |
'warning-peer-status:s' => { name => 'warning_peer_status', default => '' }, |
| 85 |
'critical-peer-status:s' => { name => 'critical_peer_status', default => '' }, |
| 86 |
}); |
| 87 |
|
| 88 |
return $self; |
| 89 |
} |
| 90 |
|
| 91 |
sub check_options { |
| 92 |
my ($self, %options) = @_; |
| 93 |
$self->SUPER::check_options(%options); |
| 94 |
|
| 95 |
$self->change_macros(macros => [ |
| 96 |
'unknown_peer_status', 'warning_peer_status', 'critical_peer_status', |
| 97 |
'unknown_ha_status', 'warning_ha_status', 'critical_ha_status', |
| 98 |
]); |
| 99 |
} |
| 100 |
|
| 101 |
my $map_ha_status = { |
| 102 |
0 => 'unknown', 1 => 'init', |
| 103 |
2 => 'down', 3 => 'up', |
| 104 |
4 => 'partialFail', 5 => 'monitorFail', |
| 105 |
6 => 'monitorOk', 7 => 'completeFail', |
| 106 |
8 => 'dumb', 9 => 'disabled', |
| 107 |
10 => 'partialFailSsl', 11 => 'routemonitorFail', |
| 108 |
}; |
| 109 |
|
| 110 |
my $map_peer_status = { |
| 111 |
0 => 'standalone', 1 => 'primary', |
| 112 |
2 => 'secondary', 3 => 'unknown', |
| 113 |
}; |
| 114 |
|
| 115 |
sub manage_selection { |
| 116 |
my ($self, %options) = @_; |
| 117 |
|
| 118 |
my $oid_sysHighAvailabilityMode = '.1.3.6.1.4.1.5951.4.1.1.6.0'; |
| 119 |
my $oid_haPeerState = '.1.3.6.1.4.1.5951.4.1.1.23.3.0'; |
| 120 |
my $oid_haCurState = '.1.3.6.1.4.1.5951.4.1.1.23.24.0'; |
| 121 |
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_sysHighAvailabilityMode, $oid_haPeerState, $oid_haCurState], nothing_quit => 1); |
| 122 |
|
| 123 |
$self->{global} = { |
| 124 |
peer_status => $map_peer_status->{$snmp_result->{$oid_haPeerState}}, |
| 125 |
ha_mode => $map_peer_status->{$snmp_result->{$oid_sysHighAvailabilityMode}}, |
| 126 |
ha_status => $map_ha_status->{$snmp_result->{$oid_haCurState}}, |
| 127 |
}; |
| 128 |
} |
| 129 |
|
| 130 |
1; |
| 131 |
|
| 132 |
__END__ |
| 133 |
|
| 134 |
=head1 MODE |
| 135 |
|
| 136 |
Check high availability status. |
| 137 |
|
| 138 |
=over 8 |
| 139 |
|
| 140 |
=item B<--unknown-ha-status> |
| 141 |
|
| 142 |
Define the conditions to match for the status to be UNKNOWN. (default: '%{ha_status} =~ /unknown/i'). |
| 143 |
Can use special variables like: %{ha_status} |
| 144 |
|
| 145 |
=item B<--warning-ha-status> |
| 146 |
|
| 147 |
Define the conditions to match for the status to be WARNING. (default: ''). |
| 148 |
Can use special variables like: %{ha_status}, %{ha_mode} |
| 149 |
|
| 150 |
=item B<--critical-ha-status> |
| 151 |
|
| 152 |
Define the conditions to match for the status to be CRITICAL. (default: '%{ha_status} =~ /down|partialFail|monitorFail|completeFail|partialFailSsl|routemonitorFail/i'). |
| 153 |
Can use special variables like: %{ha_status}, %{ha_mode} |
| 154 |
|
| 155 |
=item B<--unknown-peer-status> |
| 156 |
|
| 157 |
Define the conditions to match for the status to be UNKNOWN. (default: '%{peer_status} =~ /unknown/i'). |
| 158 |
Can use special variables like: %{peer_status}, %{ha_mode} |
| 159 |
|
| 160 |
=item B<--warning-peer-status> |
| 161 |
|
| 162 |
Define the conditions to match for the status to be WARNING. (default: ''). |
| 163 |
Can use special variables like: %{peer_status} |
| 164 |
|
| 165 |
=item B<--critical-peer-status> |
| 166 |
|
| 167 |
Define the conditions to match for the status to be CRITICAL. (default: ''). |
| 168 |
Can use special variables like: %{peer_status} |
| 169 |
|
| 170 |
=back |
| 171 |
|
| 172 |
=cut |
| 173 |
|