Debian Codegraph @

src/network/kemp/snmp/mode/hastatus.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::kemp::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);
28
29 sub custom_hastatus_output {
30 my ($self, %options) = @_;
31
32 my $msg = 'HA status : ' . $self->{result_values}->{status};
33 return $msg;
34 }
35
36 sub custom_syncstatus_output {
37 my ($self, %options) = @_;
38
39 my $msg = 'Synchronization l4 status : ' . $self->{result_values}->{status};
40 return $msg;
41 }
42
43 sub custom_hastatus_calc {
44 my ($self, %options) = @_;
45
46 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_hAstate'};
47 $self->{result_values}->{label} = 'ha_status';
48 return 0;
49 }
50
51 sub custom_syncstatus_calc {
52 my ($self, %options) = @_;
53
54 $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_daemonState'};
55 $self->{result_values}->{label} = 'sync_status';
56 return 0;
57 }
58
59 sub set_counters {
60 my ($self, %options) = @_;
61
62 $self->{maps_counters_type} = [
63 { name => 'global', type => 0, message_separator => ' - ' }
64 ];
65
66 $self->{maps_counters}->{global} = [
67 { label => 'ha-status', threshold => 0, set => {
68 key_values => [ { name => 'hAstate' } ],
69 closure_custom_calc => $self->can('custom_hastatus_calc'),
70 closure_custom_output => $self->can('custom_hastatus_output'),
71 closure_custom_perfdata => sub { return 0; },
72 closure_custom_threshold_check => \&catalog_status_threshold,
73 }
74 },
75 { label => 'sync-status', threshold => 0, set => {
76 key_values => [ { name => 'daemonState' } ],
77 closure_custom_calc => $self->can('custom_syncstatus_calc'),
78 closure_custom_output => $self->can('custom_syncstatus_output'),
79 closure_custom_perfdata => sub { return 0; },
80 closure_custom_threshold_check => \&catalog_status_threshold,
81 }
82 },
83 ];
84 }
85
86 sub new {
87 my ($class, %options) = @_;
88 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
89 bless $self, $class;
90
91 $options{options}->add_options(arguments =>
92 {
93 "warning-ha-status:s" => { name => 'warning_ha_status', default => '' },
94 "critical-ha-status:s" => { name => 'critical_ha_status', default => '' },
95 "warning-sync-status:s" => { name => 'warning_sync_status', default => '' },
96 "critical-sync-status:s" => { name => 'critical_sync_status', default => '' },
97 });
98
99 return $self;
100 }
101
102 sub check_options {
103 my ($self, %options) = @_;
104 $self->SUPER::check_options(%options);
105
106 $self->change_macros(macros => ['warning_ha_status', 'critical_ha_status', 'warning_sync_status', 'critical_sync_status']);
107 }
108
109 my %map_daemon_state = (
110 0 => 'none',
111 1 => 'master',
112 2 => 'backup',
113 );
114 my %map_ha_state = (
115 0 => 'none',
116 1 => 'master',
117 2 => 'standby',
118 3 => 'passive',
119 );
120 my $mapping = {
121 daemonState => { oid => '.1.3.6.1.4.1.12196.13.0.7', map => \%map_daemon_state },
122 hAstate => { oid => '.1.3.6.1.4.1.12196.13.0.9', map => \%map_ha_state },
123 };
124
125 sub manage_selection {
126 my ($self, %options) = @_;
127
128 $self->{vs} = {};
129 my $snmp_result = $options{snmp}->get_leef(oids => [ $mapping->{daemonState}->{oid} . '.0', $mapping->{hAstate}->{oid} . '.0' ],
130 nothing_quit => 1);
131 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0');
132
133 $self->{global} = { %$result };
134 }
135
136 1;
137
138 __END__
139
140 =head1 MODE
141
142 Check ha status.
143
144 =over 8
145
146 =item B<--filter-counters>
147
148 Only display some counters (regexp can be used).
149 Example: --filter-counters='^ha-status$'
150
151 =item B<--warning-ha-status>
152
153 Define the conditions to match for the status to be WARNING (default: none).
154 You can use the following variables: %{status}, %{display}
155
156 =item B<--critical-ha-status>
157
158 Define the conditions to match for the status to be CRITICAL (default: none).
159 You can use the following variables: %{status}, %{display}
160
161 =item B<--warning-sync-status>
162
163 Define the conditions to match for the status to be WARNING (default: none).
164 You can use the following variables: %{status}, %{display}
165
166 =item B<--critical-sync-status>
167
168 Define the conditions to match for the status to be CRITICAL (default: none).
169 You can use the following variables: %{status}, %{display}
170
171 =back
172
173 =cut