Debian Codegraph @

src/centreon/common/cisco/standard/snmp/mode/stack.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 centreon::common::cisco::standard::snmp::mode::stack;
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_stack_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf("Stack status is '%s'", $self->{result_values}->{stack_status});
33 }
34
35 sub custom_status_output {
36 my ($self, %options) = @_;
37
38 return sprintf("state is '%s', role is '%s'", $self->{result_values}->{state}, $self->{result_values}->{role});
39 }
40
41 sub prefix_global_output {
42 my ($self, %options) = @_;
43
44 return "Number of members ";
45 }
46
47 sub prefix_status_output {
48 my ($self, %options) = @_;
49
50 return "Member '" . $options{instance_value}->{name} . "' ";
51 }
52
53 sub set_counters {
54 my ($self, %options) = @_;
55
56 $self->{maps_counters_type} = [
57 { name => 'stack', type => 0 },
58 { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
59 { name => 'members', type => 1, cb_prefix_output => 'prefix_status_output', message_multiple => 'All stack members status are ok' }
60 ];
61
62 $self->{maps_counters}->{stack} = [
63 { label => 'stack-status', type => 2, critical_default => '%{stack_status} =~ /notredundant/', set => {
64 key_values => [ { name => 'stack_status' } ],
65 closure_custom_output => $self->can('custom_stack_status_output'),
66 closure_custom_perfdata => sub { return 0; },
67 closure_custom_threshold_check => \&catalog_status_threshold_ng
68 }
69 }
70 ];
71
72 $self->{maps_counters}->{global} = [
73 { label => 'waiting', set => {
74 key_values => [ { name => 'waiting' } ],
75 output_template => 'waiting: %d',
76 perfdatas => [
77 { label => 'waiting', template => '%d', min => 0 }
78 ]
79 }
80 },
81 { label => 'progressing', set => {
82 key_values => [ { name => 'progressing' } ],
83 output_template => 'progressing: %d',
84 perfdatas => [
85 { label => 'progressing', template => '%d', min => 0 }
86 ]
87 }
88 },
89 { label => 'added', set => {
90 key_values => [ { name => 'added' } ],
91 output_template => 'added: %d',
92 perfdatas => [
93 { label => 'added', template => '%d', min => 0 }
94 ]
95 }
96 },
97 { label => 'ready', set => {
98 key_values => [ { name => 'ready' } ],
99 output_template => 'ready: %d',
100 perfdatas => [
101 { label => 'ready', template => '%d', min => 0 }
102 ]
103 }
104 },
105 { label => 'sdm-mismatch', set => {
106 key_values => [ { name => 'sdmMismatch' } ],
107 output_template => 'SDM mismatch: %d',
108 perfdatas => [
109 { label => 'sdm_mismatch', template => '%d', min => 0 }
110 ]
111 }
112 },
113 { label => 'version-mismatch', set => {
114 key_values => [ { name => 'verMismatch' } ],
115 output_template => 'version mismatch: %d',
116 perfdatas => [
117 { label => 'version_mismatch', template => '%d', min => 0 }
118 ]
119 }
120 },
121 { label => 'feature-mismatch', set => {
122 key_values => [ { name => 'featureMismatch' } ],
123 output_template => 'feature mismatch: %d',
124 perfdatas => [
125 { label => 'feature_mismatch', template => '%d', min => 0 }
126 ]
127 }
128 },
129 { label => 'new-master-init', set => {
130 key_values => [ { name => 'newMasterInit' } ],
131 output_template => 'new master init: %d',
132 perfdatas => [
133 { label => 'new_master_init', template => '%d', min => 0 }
134 ]
135 }
136 },
137 { label => 'provisioned', set => {
138 key_values => [ { name => 'provisioned' } ],
139 output_template => 'provisioned: %d',
140 perfdatas => [
141 { label => 'provisioned', template => '%d', min => 0 }
142 ]
143 }
144 },
145 { label => 'invalid', set => {
146 key_values => [ { name => 'invalid' } ],
147 output_template => 'invalid: %d',
148 perfdatas => [
149 { label => 'invalid', template => '%d', min => 0 }
150 ]
151 }
152 },
153 { label => 'removed', set => {
154 key_values => [ { name => 'removed' } ],
155 output_template => 'removed: %d',
156 perfdatas => [
157 { label => 'removed', template => '%d', min => 0 }
158 ]
159 }
160 }
161 ];
162
163 $self->{maps_counters}->{members} = [
164 { label => 'status', type => 2, critical_default => '%{state} !~ /ready/ && %{state} !~ /provisioned/', set => {
165 key_values => [ { name => 'name' }, { name => 'role' }, { name => 'state' } ],
166 closure_custom_output => $self->can('custom_status_output'),
167 closure_custom_perfdata => sub { return 0; },
168 closure_custom_threshold_check => \&catalog_status_threshold_ng
169 }
170 }
171 ];
172 }
173
174 sub new {
175 my ($class, %options) = @_;
176 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
177 bless $self, $class;
178
179 $options{options}->add_options(arguments => {});
180
181 return $self;
182 }
183
184 my %map_role = (
185 1 => 'master',
186 2 => 'member',
187 3 => 'notMember',
188 4 => 'standby'
189 );
190 my %map_state = (
191 1 => 'waiting',
192 2 => 'progressing',
193 3 => 'added',
194 4 => 'ready',
195 5 => 'sdmMismatch',
196 6 => 'verMismatch',
197 7 => 'featureMismatch',
198 8 => 'newMasterInit',
199 9 => 'provisioned',
200 10 => 'invalid',
201 11 => 'removed',
202 );
203
204 my $mapping = {
205 cswSwitchRole => { oid => '.1.3.6.1.4.1.9.9.500.1.2.1.1.3', map => \%map_role },
206 cswSwitchState => { oid => '.1.3.6.1.4.1.9.9.500.1.2.1.1.6', map => \%map_state },
207 };
208 my $oid_cswSwitchInfoEntry = '.1.3.6.1.4.1.9.9.500.1.2.1.1';
209
210 my $oid_cswRingRedundant = '.1.3.6.1.4.1.9.9.500.1.1.3.0';
211 my $oid_entPhysicalName = '.1.3.6.1.2.1.47.1.1.1.1.7';
212
213 sub manage_selection {
214 my ($self, %options) = @_;
215
216 $self->{global} = {
217 waiting => 0, progressing => 0, added => 0, ready => 0, sdmMismatch => 0,
218 verMismatch => 0, featureMismatch => 0, newMasterInit => 0, provisioned => 0,
219 invalid => 0, removed => 0
220 };
221 $self->{members} = {};
222
223 my $snmp_result = $options{snmp}->get_leef(oids => [ $oid_cswRingRedundant ], nothing_quit => 1);
224 $self->{stack} = {
225 stack_status => ($snmp_result->{$oid_cswRingRedundant} != 1) ? 'notredundant' : 'redundant',
226 };
227
228 $snmp_result = $options{snmp}->get_table(
229 oid => $oid_cswSwitchInfoEntry,
230 start => $mapping->{cswSwitchRole}->{oid},
231 end => $mapping->{cswSwitchState}->{oid},
232 nothing_quit => 1
233 );
234
235 foreach my $oid (keys %$snmp_result) {
236 next if($oid !~ /^$mapping->{cswSwitchRole}->{oid}\.(.*)$/);
237 my $instance = $1;
238
239 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
240
241 $self->{members}->{$instance} = {
242 name => $instance,
243 role => $result->{cswSwitchRole},
244 state => $result->{cswSwitchState},
245 };
246 $self->{global}->{ $result->{cswSwitchState} }++;
247 }
248
249 return if (scalar(keys %{$self->{members}}) <= 0);
250
251 $options{snmp}->load(
252 oids => [ $oid_entPhysicalName ],
253 instances => [ keys %{$self->{members}} ],
254 instance_regexp => '^(.*)$'
255 );
256 $snmp_result = $options{snmp}->get_leef();
257 foreach (keys %{$self->{members}}) {
258 if (defined($snmp_result->{ $oid_entPhysicalName . '.' . $_ }) && $snmp_result->{ $oid_entPhysicalName . '.' . $_ } ne '') {
259 $self->{members}->{$_}->{name} = $snmp_result->{ $oid_entPhysicalName . '.' . $_ };
260 }
261 }
262 }
263
264 1;
265
266 __END__
267
268 =head1 MODE
269
270 Check Cisco Stack (CISCO-STACKWISE-MIB).
271
272 =over 8
273
274 =item B<--warning-*> B<--critical-*>
275
276 Set thresholds for members count for each states.
277 (can be: 'waiting', 'progressing', 'added', 'ready', 'sdm-mismatch', 'version-mismatch',
278 'feature-mismatch', 'new-master-init', 'provisioned', 'invalid', 'removed')
279
280 =item B<--warning-stack-status>
281
282 Set warning threshold for stack status (default: '').
283 You can use the following variables: %{stack_status}
284
285 =item B<--critical-stack-status>
286
287 Set critical threshold for stack status (default: '%{stack_status} =~ /notredundant/').
288 You can use the following variables: %{stack_status}
289
290 =item B<--warning-status>
291
292 Set warning threshold for members status (default: '').
293 You can use the following variables: %{name}, %{role}, %{state}
294
295 =item B<--critical-status>
296
297 Set critical threshold for member status (default: '%{state} !~ /ready/ && %{state} !~ /provisioned/').
298 You can use the following variables: %{name}, %{role}, %{state}
299
300 Role can be: 'master', 'member', 'notMember', 'standby'.
301
302 State can be: 'waiting', 'progressing', 'added',
303 'ready', 'sdmMismatch', 'verMismatch', 'featureMismatch',
304 'newMasterInit', 'provisioned', 'invalid', 'removed'.
305
306 =back
307
308 =cut