Debian Codegraph @

src/network/fortinet/fortimail/snmp/mode/ha.pm

raw
1 #
2 # Copyright 2022 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::fortinet::fortimail::snmp::mode::ha;
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 use Digest::MD5 qw(md5_hex);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf("high-availability status is '%s'", $self->{result_values}->{ha_status});
34 }
35
36 sub custom_status_calc {
37 my ($self, %options) = @_;
38
39 if (!defined($options{old_datas}->{$self->{instance} . '_ha_status'})) {
40 $self->{error_msg} = 'buffer creation';
41 return -2;
42 }
43 $self->{result_values}->{ha_status_last} = $options{old_datas}->{$self->{instance} . '_ha_status'};
44 $self->{result_values}->{ha_status} = $options{new_datas}->{$self->{instance} . '_ha_status'};
45
46 return 0;
47 }
48
49 sub set_counters {
50 my ($self, %options) = @_;
51
52 $self->{maps_counters_type} = [
53 { name => 'global', type => 0 }
54 ];
55
56 $self->{maps_counters}->{global} = [
57 { label => 'ha-status', type => 2, critical_default => '%{ha_status} ne %{ha_status_last}', set => {
58 key_values => [ { name => 'ha_status' } ],
59 closure_custom_calc => \&custom_status_calc,
60 closure_custom_output => $self->can('custom_status_output'),
61 closure_custom_perfdata => sub {return 0;},
62 closure_custom_threshold_check => \&catalog_status_threshold_ng
63 }
64 }
65 ];
66 }
67
68 sub new {
69 my ($class, %options) = @_;
70 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
71 bless $self, $class;
72
73 $options{options}->add_options(arguments => {});
74
75 return $self;
76 }
77
78 my $map_ha_status = {
79 0 => 'off', 1 => 'master', 2 => 'slave', 3 => 'configMaster', 4 => 'configSlave'
80 };
81
82 sub manage_selection {
83 my ($self, %options) = @_;
84
85 my $oid_facHaCurrentStatus = '.1.3.6.1.4.1.12356.105.1.200.2.0';
86 my $result = $options{snmp}->get_leef(oids => [ $oid_facHaCurrentStatus ], nothing_quit => 1);
87
88 $self->{global} = {
89 ha_status => $map_ha_status->{ $result->{$oid_facHaCurrentStatus} }
90 };
91
92 $self->{cache_name} = 'fortinet_fortimail_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
93 (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
94 }
95
96 1;
97
98 __END__
99
100 =head1 MODE
101
102 Check high-availability status.
103
104 =over 8
105
106 =item B<--warning-ha-status>
107
108 Define the conditions to match for the status to be WARNING.
109 You can use the following variables: %{ha_status}, %{ha_status_last}
110
111 =item B<--critical-ha-status>
112
113 Define the conditions to match for the status to be CRITICAL (default: '%{ha_status} ne %{ha_status_last}').
114 You can use the following variables: %{ha_status}, %{ha_status_last}
115
116 =back
117
118 =cut