Debian Codegraph @

src/network/f5/bigip/snmp/mode/poolstatus.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::f5::bigip::snmp::mode::poolstatus;
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_status_output {
30 my ($self, %options) = @_;
31
32 return sprintf(
33 'status: %s [state: %s] [reason: %s]',
34 $self->{result_values}->{status},
35 $self->{result_values}->{state},
36 $self->{result_values}->{reason}
37 );
38 }
39
40 sub pool_long_output {
41 my ($self, %options) = @_;
42
43 return "checking pool '" . $options{instance_value}->{display} . "'";
44 }
45
46 sub prefix_pool_output {
47 my ($self, %options) = @_;
48
49 return "Pool '" . $options{instance_value}->{display} . "' ";
50 }
51
52 sub prefix_member_output {
53 my ($self, %options) = @_;
54
55 return sprintf(
56 "member node '%s' [port: %s] ",
57 $options{instance_value}->{nodeName},
58 $options{instance_value}->{port}
59 );
60 }
61
62 sub set_counters {
63 my ($self, %options) = @_;
64
65 $self->{maps_counters_type} = [
66 { name => 'pools', type => 3, cb_prefix_output => 'prefix_pool_output', cb_long_output => 'pool_long_output', indent_long_output => ' ', message_multiple => 'All pools are ok',
67 group => [
68 { name => 'pool_status', type => 0, skipped_code => { -10 => 1 } },
69 { name => 'pool_connections', type => 0, skipped_code => { -10 => 1 } },
70 { name => 'members', display_long => 1, cb_prefix_output => 'prefix_member_output', message_multiple => 'members are ok', type => 1, skipped_code => { -10 => 1 } },
71 ]
72 }
73 ];
74
75 $self->{maps_counters}->{pool_status} = [
76 {
77 label => 'status',
78 type => 2,
79 warning_default => '%{membersAllDisabled} eq "no" and %{state} eq "enabled" and %{status} eq "yellow"',
80 critical_default => '%{membersAllDisabled} eq "no" and %{state} eq "enabled" and %{status} eq "red"',
81 set => {
82 key_values => [
83 { name => 'state' }, { name => 'status' }, { name => 'membersAllDisabled' },
84 { name => 'reason' }, { name => 'display' }
85 ],
86 closure_custom_output => $self->can('custom_status_output'),
87 closure_custom_perfdata => sub { return 0; },
88 closure_custom_threshold_check => \&catalog_status_threshold_ng
89 }
90 }
91 ];
92
93 $self->{maps_counters}->{pool_connections} = [
94 { label => 'current-server-connections', nlabel => 'pool.connections.server.count', set => {
95 key_values => [ { name => 'ltmPoolStatServerCurConns' }, { name => 'display' } ],
96 output_template => 'current server connections: %s',
97 perfdatas => [
98 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
99 ]
100 }
101 },
102 { label => 'current-active-members', nlabel => 'pool.members.active.count', set => {
103 key_values => [ { name => 'ltmPoolActiveMemberCnt' }, { name => 'display' } ],
104 output_template => 'current active members: %s',
105 perfdatas => [
106 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
107 ]
108 }
109 },
110 { label => 'current-total-members', display_ok => 0, nlabel => 'pool.members.total.count', set => {
111 key_values => [ { name => 'ltmPoolMemberCnt' }, { name => 'display' } ],
112 output_template => 'current total members: %s',
113 perfdatas => [
114 { template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
115 ]
116 }
117 }
118 ];
119
120 $self->{maps_counters}->{members} = [
121 {
122 label => 'member-status',
123 type => 2,
124 set => {
125 key_values => [
126 { name => 'state' }, { name => 'status' }, { name => 'reason' },
127 { name => 'poolName' }, { name => 'nodeName' }
128 ],
129 closure_custom_output => $self->can('custom_status_output'),
130 closure_custom_perfdata => sub { return 0; },
131 closure_custom_threshold_check => \&catalog_status_threshold_ng
132 }
133 }
134 ];
135 }
136
137 sub new {
138 my ($class, %options) = @_;
139 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
140 bless $self, $class;
141
142 $options{options}->add_options(arguments => {
143 'filter-name:s' => { name => 'filter_name' }
144 });
145
146 return $self;
147 }
148
149 my $map_pool_status = {
150 0 => 'none', 1 => 'green',
151 2 => 'yellow', 3 => 'red',
152 4 => 'blue', 5 => 'gray',
153 };
154 my $map_pool_enabled = {
155 0 => 'none', 1 => 'enabled', 2 => 'disabled', 3 => 'disabledbyparent',
156 };
157
158 # New OIDS
159 my $mapping = {
160 new => {
161 status => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.2', map => $map_pool_status }, # AvailState
162 state => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.3', map => $map_pool_enabled }, # EnabledState
163 reason => { oid => '.1.3.6.1.4.1.3375.2.2.5.5.2.1.5' } # StatusReason
164 },
165 old => {
166 status => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.18', map => $map_pool_status }, # AvailState
167 state => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.19', map => $map_pool_enabled }, # EnabledState
168 reason => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.21' } # StatusReason
169 }
170 };
171 my $mapping_members = {
172 new => {
173 state => { oid => '.1.3.6.1.4.1.3375.2.2.5.6.2.1.6', map => $map_pool_enabled }, # ltmPoolMbrStatusEnabledState
174 reason => { oid => '.1.3.6.1.4.1.3375.2.2.5.6.2.1.8' } # ltmPoolMbrStatusDetailReason
175 },
176 old => {
177 state => { oid => '.1.3.6.1.4.1.3375.2.2.5.3.2.1.16', map => $map_pool_enabled }, # ltmPoolMemberEnabledState
178 reason => { oid => '.1.3.6.1.4.1.3375.2.2.5.3.2.1.18' } # ltmPoolMemberStatusReason
179 }
180 };
181 my $mapping2 = {
182 ltmPoolStatServerCurConns => { oid => '.1.3.6.1.4.1.3375.2.2.5.2.3.1.8' },
183 ltmPoolActiveMemberCnt => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.8' },
184 ltmPoolMemberCnt => { oid => '.1.3.6.1.4.1.3375.2.2.5.1.2.1.23' }
185 };
186
187 sub add_members {
188 my ($self, %options) = @_;
189
190 my $oid_status = $options{map} eq 'new' ? '.1.3.6.1.4.1.3375.2.2.5.6.2.1.5' : '.1.3.6.1.4.1.3375.2.2.5.3.2.1.15';
191 my $snmp_result = $options{snmp}->get_table(oid => $oid_status);
192
193 my $loaded = 0;
194 foreach my $oid (keys %$snmp_result) {
195 $oid =~ /^$oid_status\.(.*)$/;
196 my $instance = $1;
197 my @indexes = split(/\./, $1);
198
199 my $num = shift(@indexes);
200 my $poolInstance = $num . '.' . join('.', splice(@indexes, 0, $num));
201 my $nodeName = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
202 my $port = $indexes[0];
203
204 next if (!defined($self->{pools}->{$poolInstance}));
205
206 $loaded = 1;
207 $options{snmp}->load(
208 oids => [ map($_->{oid}, values(%{$mapping_members->{ $options{map} }})) ],
209 instances => [$instance],
210 instance_regexp => '^(.*)$'
211 );
212
213 $self->{pools}->{$poolInstance}->{members}->{$instance} = {
214 poolName => $self->{pools}->{$poolInstance}->{display},
215 nodeName => $nodeName,
216 port => $port,
217 status => $map_pool_status->{ $snmp_result->{$oid} }
218 };
219 }
220
221 return if ($loaded == 0);
222
223 $snmp_result = $options{snmp}->get_leef();
224 foreach (keys %$snmp_result) {
225 next if (! /^$mapping_members->{ $options{map} }->{state}->{oid}\.(.*)$/);
226 my $instance = $1;
227 my @indexes = split(/\./, $1);
228
229 my $num = shift(@indexes);
230 my $poolInstance = $num . '.' . join('.', splice(@indexes, 0, $num));
231
232 my $result = $options{snmp}->map_instance(mapping => $mapping_members->{ $options{map} }, results => $snmp_result, instance => $instance);
233 $result->{reason} = '-' if (!defined($result->{reason}) || $result->{reason} eq '');
234
235 if ($result->{state} !~ /disabled/) {
236 $self->{pools}->{$poolInstance}->{pool_status}->{membersAllDisabled} = 'no';
237 }
238
239 $self->{pools}->{$poolInstance}->{members}->{$instance}->{state} = $result->{state};
240 $self->{pools}->{$poolInstance}->{members}->{$instance}->{reason} = $result->{reason};
241 }
242 }
243
244 sub manage_selection {
245 my ($self, %options) = @_;
246
247 my ($branch_name, $map) = ($mapping->{new}->{status}->{oid}, 'new');
248 my $snmp_result = $options{snmp}->get_table(oid => $mapping->{new}->{status}->{oid} );
249
250 if (scalar(keys %$snmp_result) == 0) {
251 ($branch_name, $map) = ($mapping->{old}->{status}->{oid}, 'old');
252 $snmp_result = $options{snmp}->get_table(
253 oid => $mapping->{old}->{status}->{oid},
254 nothing_quit => 1
255 );
256 }
257
258 $self->{pools} = {};
259 foreach my $oid (keys %$snmp_result) {
260 $oid =~ /^$branch_name\.(.*?)\.(.*)$/;
261 my ($num, $index) = ($1, $2);
262
263 my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result, instance => $num . '.' . $index);
264 my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $index))));
265
266 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
267 $name !~ /$self->{option_results}->{filter_name}/) {
268 $self->{output}->output_add(long_msg => "skipping pool '" . $name . "'.", debug => 1);
269 next;
270 }
271
272 $self->{pools}->{$num . '.' . $index} = {
273 display => $name,
274 pool_status => {
275 display => $name,
276 status => $result->{status},
277 membersAllDisabled => 'yes'
278 },
279 members => {}
280 };
281 }
282
283 if (scalar(keys %{$self->{pools}}) <= 0) {
284 $self->{output}->add_option_msg(short_msg => 'No pool found');
285 $self->{output}->option_exit();
286 }
287
288 $options{snmp}->load(
289 oids => [
290 $mapping->{$map}->{state}->{oid},
291 $mapping->{$map}->{reason}->{oid},
292 $mapping2->{ltmPoolStatServerCurConns}->{oid},
293 $mapping2->{ltmPoolActiveMemberCnt}->{oid},
294 $mapping2->{ltmPoolMemberCnt}->{oid},
295 ],
296 instances => [keys %{$self->{pools}}],
297 instance_regexp => '^(.*)$'
298 );
299 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
300
301 foreach (keys %{$self->{pools}}) {
302 my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result, instance => $_);
303 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_);
304
305 $result->{reason} = '-' if (!defined($result->{reason}) || $result->{reason} eq '');
306 $self->{pools}->{$_}->{pool_status}->{reason} = $result->{reason};
307 $self->{pools}->{$_}->{pool_status}->{state} = $result->{state};
308 $self->{pools}->{$_}->{pool_connections} = {
309 display => $self->{pools}->{$_}->{display},
310 ltmPoolStatServerCurConns => $result2->{ltmPoolStatServerCurConns},
311 ltmPoolActiveMemberCnt => $result2->{ltmPoolActiveMemberCnt},
312 ltmPoolMemberCnt => $result2->{ltmPoolMemberCnt}
313 };
314 }
315
316 $self->add_members(snmp => $options{snmp}, map => $map);
317 }
318
319 1;
320
321 __END__
322
323 =head1 MODE
324
325 Check pools.
326
327 =over 8
328
329 =item B<--filter-name>
330
331 Filter by name (regexp can be used).
332
333 =item B<--unknown-status>
334
335 Define the conditions to match for the status to be UNKNOWN.
336 You can use the following variables: %{state}, %{status}, %{membersAllDisabled}, %{display}
337
338 =item B<--warning-status>
339
340 Define the conditions to match for the status to be WARNING (default: '%{membersAllDisabled} eq "no" and %{state} eq "enabled" and %{status} eq "yellow"').
341 You can use the following variables: %{state}, %{status}, %{membersAllDisabled}, %{display}
342
343 =item B<--critical-status>
344
345 Define the conditions to match for the status to be CRITICAL (default: '%{membersAllDisabled} eq "no" and %{state} eq "enabled" and %{status} eq "red"').
346 You can use the following variables: %{state}, %{status}, %{membersAllDisabled}, %{display}
347
348 =item B<--unknown-member-status>
349
350 Define the conditions to match for the status to be UNKNOWN.
351 You can use the following variables: %{state}, %{status}, %{poolName}, %{nodeName}
352
353 =item B<--warning-member-status>
354
355 Define the conditions to match for the status to be WARNING.
356 You can use the following variables: %{state}, %{status}, %{poolName}, %{nodeName}
357
358 =item B<--critical-member-status>
359
360 Define the conditions to match for the status to be CRITICAL.
361 You can use the following variables: %{state}, %{status}, %{poolName}, %{nodeName}
362
363 =item B<--warning-*> B<--critical-*>
364
365 Thresholds.
366 Can be: 'current-server-connections', 'current-active-members', 'current-total-members'.
367
368 =back
369
370 =cut