Debian Codegraph @

src/network/cisco/asa/snmp/mode/failover.pm

raw
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::cisco::asa::snmp::mode::failover;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 my $msg = sprintf("Primary unit is '%s' [details: '%s'], Secondary unit is '%s' [details : '%s']",
34 $self->{result_values}->{primaryState}, $self->{result_values}->{primaryDetails},
35 $self->{result_values}->{secondaryState}, $self->{result_values}->{secondaryDetails});
36 return $msg;
37 }
38
39 sub custom_status_calc {
40 my ($self, %options) = @_;
41
42 $self->{result_values}->{primaryStateLast} = $options{old_datas}->{$self->{instance} . '_primary_state'};
43 $self->{result_values}->{primaryState} = $options{new_datas}->{$self->{instance} . '_primary_state'};
44 $self->{result_values}->{secondaryStateLast} = $options{old_datas}->{$self->{instance} . '_secondary_state'};
45 $self->{result_values}->{secondaryState} = $options{new_datas}->{$self->{instance} . '_secondary_state'};
46 $self->{result_values}->{primaryDetails} = $options{new_datas}->{$self->{instance} . '_primary_details'};
47 $self->{result_values}->{secondaryDetails} = $options{new_datas}->{$self->{instance} . '_secondary_details'};
48 return 0;
49 }
50
51 sub set_counters {
52 my ($self, %options) = @_;
53
54 $self->{maps_counters_type} = [
55 { name => 'global', type => 0, message_separator => ' - ' },
56 ];
57
58 $self->{maps_counters}->{global} = [
59 { label => 'active-units', set => {
60 key_values => [ { name => 'active_units' } ],
61 output_template => 'Active units : %s',
62 perfdatas => [
63 { label => 'active_units', value => 'active_units', template => '%s',
64 min => 0, max => 2 },
65 ],
66 }
67 },
68 { label => 'status', threshold => 0, set => {
69 key_values => [ { name => 'primary_state' }, { name => 'secondary_state' }, { name => 'primary_details' }, { name => 'secondary_details' } ],
70 closure_custom_calc => $self->can('custom_status_calc'),
71 closure_custom_output => $self->can('custom_status_output'),
72 closure_custom_perfdata => sub { return 0; },
73 closure_custom_threshold_check => \&catalog_status_threshold,
74 }
75 },
76 ];
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments =>
85 {
86 "warning-status:s" => { name => 'warning_status', default => '' },
87 "critical-status:s" => { name => 'critical_status', default => '' },
88 });
89
90 return $self;
91 }
92
93 sub check_options {
94 my ($self, %options) = @_;
95 $self->SUPER::check_options(%options);
96
97 $self->change_macros(macros => ['warning_status', 'critical_status']);
98 }
99
100 my %map_failover = (
101 1 => 'other',
102 2 => 'up', # for '.4' index
103 3 => 'down', # can be
104 4 => 'error', # maybe
105 5 => 'overTemp',
106 6 => 'busy',
107 7 => 'noMedia',
108 8 => 'backup',
109 9 => 'active', # can be
110 10 => 'standby' # can be
111 );
112
113 sub manage_selection {
114 my ($self, %options) = @_;
115
116 $self->{global} = {};
117
118 # primary is '.6' index and secondary is '.7' index (it's like that. '.4' is the global interface)
119 my $oid_cfwHardwareStatusValue_primary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.6';
120 my $oid_cfwHardwareStatusValue_secondary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.3.7';
121 my $oid_cfwHardwareStatusDetail_primary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.4.6';
122 my $oid_cfwHardwareStatusDetail_secondary = '.1.3.6.1.4.1.9.9.147.1.2.1.1.1.4.7';
123 my $result = $options{snmp}->get_leef(oids => [$oid_cfwHardwareStatusValue_primary, $oid_cfwHardwareStatusValue_secondary,
124 $oid_cfwHardwareStatusDetail_primary, $oid_cfwHardwareStatusDetail_secondary], nothing_quit => 1);
125
126 $self->{global}->{primary_state} = $map_failover{$result->{$oid_cfwHardwareStatusValue_primary}};
127 $self->{global}->{primary_details} = $result->{$oid_cfwHardwareStatusDetail_primary};
128 $self->{global}->{secondary_state} = $map_failover{$result->{$oid_cfwHardwareStatusValue_secondary}};
129 $self->{global}->{secondary_details} = $result->{$oid_cfwHardwareStatusDetail_secondary};
130 my $active_units = 0;
131 $active_units++ if ($result->{$oid_cfwHardwareStatusValue_primary} == 9 || $result->{$oid_cfwHardwareStatusValue_primary} == 10);
132 $active_units++ if ($result->{$oid_cfwHardwareStatusValue_secondary} == 9 || $result->{$oid_cfwHardwareStatusValue_secondary} == 10);
133 $self->{global}->{active_units} = $active_units;
134
135 $self->{cache_name} = "cisco_asa_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
136 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
137 }
138
139 1;
140
141 __END__
142
143 =head1 MODE
144
145 Check failover status on Cisco ASA (CISCO-UNIFIED-FIREWALL-MIB).
146
147 =over 8
148
149 =item B<--filter-counters>
150
151 Only display some counters (regexp can be used).
152 Example: --filter-counters='^status$'
153
154 =item B<--warning-status>
155
156 Define the conditions to match for the status to be WARNING.
157 You can use the following variables: %{primaryStateLast}, %{secondaryStateLast}, %{primaryState}, %{secondaryState}
158
159 =item B<--critical-status>
160
161 Define the conditions to match for the status to be CRITICAL.
162 You can use the following variables: %{primaryStateLast}, %{secondaryStateLast}, %{primaryState}, %{secondaryState}
163
164 =item B<--warning-*>
165
166 Warning threshold.
167 Can be: 'active-units'.
168
169 =item B<--critical-*>
170
171 Critical threshold.
172 Can be: 'active-units'.
173
174 =back
175
176 =cut
177