| 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::cyberoam::snmp::mode::hastatus; |
| 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_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = "HA is '" . $self->{result_values}->{hastatus} . "' - "; |
| 33 |
$msg .= "Current HA State: '" . $self->{result_values}->{hastate} . "' - "; |
| 34 |
$msg .= "Peer HA State: '" . $self->{result_values}->{peer_hastate} . "' - "; |
| 35 |
$msg .= "HA Port: '" . $self->{result_values}->{ha_port} . "' - "; |
| 36 |
$msg .= "HA IP: '" . $self->{result_values}->{ha_ip} . "' - "; |
| 37 |
$msg .= "Peer IP: '" . $self->{result_values}->{ha_peer_ip} . "'"; |
| 38 |
return $msg; |
| 39 |
} |
| 40 |
|
| 41 |
sub set_counters { |
| 42 |
my ($self, %options) = @_; |
| 43 |
|
| 44 |
$self->{maps_counters_type} = [ |
| 45 |
{ name => 'ha', type => 0 }, |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{ha} = [ |
| 49 |
{ |
| 50 |
label => 'status', |
| 51 |
type => 2, |
| 52 |
set => { |
| 53 |
key_values => [ |
| 54 |
{ name => 'hastate' }, |
| 55 |
{ name => 'hastatus' }, |
| 56 |
{ name => 'peer_hastate' }, |
| 57 |
{ name => 'ha_port' }, |
| 58 |
{ name => 'ha_ip' }, |
| 59 |
{ name => 'ha_peer_ip' } |
| 60 |
], |
| 61 |
default_critical => '%{hastatus} =~ /^enabled$/ && %{hastate} =~ /^faulty$/', |
| 62 |
closure_custom_output => $self->can('custom_status_output'), |
| 63 |
closure_custom_perfdata => sub {return 0;}, |
| 64 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 65 |
} |
| 66 |
} |
| 67 |
]; |
| 68 |
} |
| 69 |
|
| 70 |
sub new { |
| 71 |
my ($class, %options) = @_; |
| 72 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 73 |
bless $self, $class; |
| 74 |
|
| 75 |
$options{options}->add_options(arguments => { |
| 76 |
'no-ha-status:s' => { name => 'no_ha_status', default => 'UNKNOWN' } |
| 77 |
}); |
| 78 |
|
| 79 |
return $self; |
| 80 |
} |
| 81 |
|
| 82 |
sub check_options { |
| 83 |
my ($self, %options) = @_; |
| 84 |
$self->SUPER::check_options(%options); |
| 85 |
|
| 86 |
$self->change_macros(macros => [ 'warning_status', 'critical_status' ]); |
| 87 |
} |
| 88 |
# snmptranslate -Td .1.3.6.1.4.1.2604.5.1.4.1.0 |
| 89 |
# SFOS-FIREWALL-MIB::sfosHAStatus.0 |
| 90 |
# sfosHAStatus OBJECT-TYPE |
| 91 |
# -- FROM SFOS-FIREWALL-MIB |
| 92 |
# -- TEXTUAL CONVENTION HaStatusType |
| 93 |
# SYNTAX INTEGER {disabled(0), enabled(1)} |
| 94 |
# MAX-ACCESS read-only |
| 95 |
# STATUS current |
| 96 |
# DESCRIPTION " " |
| 97 |
# ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) sophosMIB(2604) sfosXGMIB(5) sfosXGMIBObjects(1) sfosXGHAStats(4) sfosHAStatus(1) 0 } |
| 98 |
|
| 99 |
my %map_status = ( |
| 100 |
0 => 'disabled', |
| 101 |
1 => 'enabled' |
| 102 |
); |
| 103 |
|
| 104 |
# snmptranslate -Td .1.3.6.1.4.1.2604.5.1.4.4.0 |
| 105 |
# SFOS-FIREWALL-MIB::sfosDeviceCurrentHAState.0 |
| 106 |
# sfosDeviceCurrentHAState OBJECT-TYPE |
| 107 |
# -- FROM SFOS-FIREWALL-MIB |
| 108 |
# -- TEXTUAL CONVENTION HaState |
| 109 |
# SYNTAX INTEGER {notapplicable(0), auxiliary(1), standAlone(2), primary(3), faulty(4), ready(5)} |
| 110 |
# MAX-ACCESS read-only |
| 111 |
# STATUS current |
| 112 |
# DESCRIPTION "HA State of current Device" |
| 113 |
# ::= { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) sophosMIB(2604) sfosXGMIB(5) sfosXGMIBObjects(1) sfosXGHAStats(4) sfosDeviceCurrentHAState(4) 0 } |
| 114 |
|
| 115 |
my %map_state = ( |
| 116 |
0 => 'notapplicable', |
| 117 |
1 => 'auxiliary', |
| 118 |
2 => 'standAlone', |
| 119 |
3 => 'primary', |
| 120 |
4 => 'faulty', |
| 121 |
5 => 'ready' |
| 122 |
); |
| 123 |
|
| 124 |
sub manage_selection { |
| 125 |
my ($self, %options) = @_; |
| 126 |
|
| 127 |
my $oid_ha_status = '.1.3.6.1.4.1.2604.5.1.4.1.0'; |
| 128 |
my $oid_ha_state = '.1.3.6.1.4.1.2604.5.1.4.4.0'; |
| 129 |
my $oid_peer_ha_state = '.1.3.6.1.4.1.2604.5.1.4.5.0'; |
| 130 |
my $oid_ha_port = '.1.3.6.1.4.1.2604.5.1.4.8.0'; |
| 131 |
my $oid_ha_ip = '.1.3.6.1.4.1.2604.5.1.4.9.0'; |
| 132 |
my $oid_ha_peer_ip = '.1.3.6.1.4.1.2604.5.1.4.10.0'; |
| 133 |
|
| 134 |
$self->{ha} = {}; |
| 135 |
|
| 136 |
my $result = $options{snmp}->get_leef( |
| 137 |
oids => |
| 138 |
[ $oid_ha_status, $oid_ha_state, $oid_peer_ha_state, $oid_ha_port, $oid_ha_ip, $oid_ha_peer_ip ], |
| 139 |
nothing_quit => |
| 140 |
1 |
| 141 |
); |
| 142 |
|
| 143 |
if ($result->{$oid_ha_status} == 0 or $result->{$oid_ha_state} == 0) { |
| 144 |
$self->{output}->output_add( |
| 145 |
severity => $self->{option_results}->{no_ha_status}, |
| 146 |
short_msg => sprintf("Looks like HA is not enabled, or not applicable .."), |
| 147 |
long_msg => sprintf( |
| 148 |
"HA Enabled : '%u' HA Status : '%s'", |
| 149 |
$map_status{$result->{$oid_ha_status}}, $map_status{$result->{$oid_ha_state}} |
| 150 |
), |
| 151 |
); |
| 152 |
$self->{output}->display(); |
| 153 |
$self->{output}->exit(); |
| 154 |
} |
| 155 |
$self->{ha} = { |
| 156 |
hastatus => $map_status{$result->{$oid_ha_status}}, |
| 157 |
hastate => $map_state{$result->{$oid_ha_state}}, |
| 158 |
peer_hastate => $map_state{$result->{$oid_peer_ha_state}}, |
| 159 |
ha_port => $result->{$oid_ha_port}, |
| 160 |
ha_ip => $result->{$oid_ha_ip}, |
| 161 |
ha_peer_ip => $result->{$oid_ha_peer_ip} |
| 162 |
}; |
| 163 |
} |
| 164 |
|
| 165 |
1; |
| 166 |
|
| 167 |
__END__ |
| 168 |
|
| 169 |
=head1 MODE |
| 170 |
|
| 171 |
Check current HA-State. |
| 172 |
HA-States: notapplicable, auxiliary, standAlone, primary, faulty, ready |
| 173 |
|
| 174 |
=over 8 |
| 175 |
|
| 176 |
=item B<--warning-status> |
| 177 |
|
| 178 |
Trigger warning on %{hastatus} or %{hastate} or %{peer_hastate} values. |
| 179 |
|
| 180 |
=item B<--critical-status> |
| 181 |
|
| 182 |
Trigger critical on %{hastatus} or %{hastate} or %{peer_hastate} values. |
| 183 |
(default: '%{hastatus} =~ /^enabled$/ && %{hastate} =~ /^faulty$/'). |
| 184 |
|
| 185 |
=item B<--no-ha-status> |
| 186 |
|
| 187 |
Status to return when HA not running or not installed (default: 'UNKNOWN'). |
| 188 |
|
| 189 |
=back |
| 190 |
|
| 191 |
=cut |