Debian Codegraph @

src/network/paloalto/snmp/mode/clusterstatus.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::paloalto::snmp::mode::clusterstatus;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 my $oid_panSysHAState = '.1.3.6.1.4.1.25461.2.1.2.1.11.0'; # '.0' to have the mode
29 my $oid_panSysHAPeerState = '.1.3.6.1.4.1.25461.2.1.2.1.12.0';
30 my $oid_panSysHAMode = '.1.3.6.1.4.1.25461.2.1.2.1.13.0';
31
32 my $thresholds = {
33 peer => [
34 ],
35 current => [
36 ],
37 };
38
39 sub new {
40 my ($class, %options) = @_;
41 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
42 bless $self, $class;
43
44 $options{options}->add_options(arguments =>
45 {
46 "threshold-overload:s@" => { name => 'threshold_overload' },
47 });
48
49 return $self;
50 }
51
52 sub check_threshold_overload {
53 my ($self, %options) = @_;
54
55 $self->{overload_th} = {};
56 foreach my $val (@{$self->{option_results}->{threshold_overload}}) {
57 if ($val !~ /^(.*?),(.*?),(.*)$/) {
58 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'.");
59 $self->{output}->option_exit();
60 }
61 my ($section, $status, $filter) = ($1, $2, $3);
62 if ($self->{output}->is_litteral_status(status => $status) == 0) {
63 $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'.");
64 $self->{output}->option_exit();
65 }
66 $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section}));
67 push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status};
68 }
69 }
70
71 sub check_options {
72 my ($self, %options) = @_;
73 $self->SUPER::init(%options);
74 $self->check_threshold_overload();
75 }
76
77 sub get_severity {
78 my ($self, %options) = @_;
79 my $status = 'OK'; # default
80
81 if (defined($self->{overload_th}->{$options{section}})) {
82 foreach (@{$self->{overload_th}->{$options{section}}}) {
83 if ($options{value} =~ /$_->{filter}/i) {
84 $status = $_->{status};
85 return $status;
86 }
87 }
88 }
89 foreach (@{$thresholds->{$options{section}}}) {
90 if ($options{value} =~ /$$_[0]/i) {
91 $status = $$_[1];
92 return $status;
93 }
94 }
95
96 return $status;
97 }
98
99 sub run {
100 my ($self, %options) = @_;
101 $self->{snmp} = $options{snmp};
102
103 $self->{result} = $self->{snmp}->get_leef(oids => [ $oid_panSysHAState, $oid_panSysHAPeerState, $oid_panSysHAMode ],
104 nothing_quit => 1);
105
106 # Check if mode cluster
107 my $ha_mode = $self->{result}->{$oid_panSysHAMode};
108 $self->{output}->output_add(long_msg => 'High availabily mode is ' . $ha_mode . '.');
109 if ($ha_mode =~ /disabled/i) {
110 $self->{output}->output_add(severity => 'OK',
111 short_msg => sprintf("No cluster configuration (standalone mode)."));
112 } else {
113 if ($ha_mode =~ /active-active/i) {
114 $thresholds = {
115 peer => [
116 ['^active$', 'OK'],
117 ['^passive$', 'CRITICAL'],
118 ],
119 current => [
120 ['^active$', 'OK'],
121 ['^passive$', 'CRITICAL'],
122 ],
123 };
124 }
125
126 $self->{output}->output_add(severity => 'OK',
127 short_msg => sprintf("Cluster status is ok [member: %s] [peer: %s]",
128 $self->{result}->{$oid_panSysHAState},
129 $self->{result}->{$oid_panSysHAPeerState}));
130
131 $self->{output}->output_add(long_msg => sprintf("current high-availability state is %s",
132 $self->{result}->{$oid_panSysHAState}));
133 my $exit = $self->get_severity(section => 'current', value => $self->{result}->{$oid_panSysHAState});
134 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
135 $self->{output}->output_add(severity => $exit,
136 short_msg => sprintf("current high-availability state is %s",
137 $self->{result}->{$oid_panSysHAState}));
138 }
139
140 $self->{output}->output_add(long_msg => sprintf("peer high-availability state is %s",
141 $self->{result}->{$oid_panSysHAPeerState}));
142 $exit = $self->get_severity(section => 'peer', value => $self->{result}->{$oid_panSysHAPeerState});
143 if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
144 $self->{output}->output_add(severity => $exit,
145 short_msg => sprintf("peer high-availability state is %s",
146 $self->{result}->{$oid_panSysHAPeerState}));
147 }
148 }
149
150 $self->{output}->display();
151 $self->{output}->exit();
152 }
153
154 1;
155
156 __END__
157
158 =head1 MODE
159
160 Check cluster status.
161
162 =over 8
163
164 =item B<--threshold-overload>
165
166 Set to overload default threshold value.
167 Example: --threshold-overload='peer,critical,active' --threshold-overload='current,critical,passive'
168
169 =back
170
171 =cut