Debian Codegraph @

src/network/f5/bigip/snmp/mode/nodestatus.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::nodestatus;
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 my $msg = 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 return $msg;
39 }
40
41 sub prefix_node_output {
42 my ($self, %options) = @_;
43
44 return "Node '" . $options{instance_value}->{display} . "' ";
45 }
46
47 sub set_counters {
48 my ($self, %options) = @_;
49
50 $self->{maps_counters_type} = [
51 { name => 'node', type => 1, cb_prefix_output => 'prefix_node_output', message_multiple => 'All nodes are ok', skipped_code => { -10 => 1 } }
52 ];
53
54 $self->{maps_counters}->{node} = [
55 {
56 label => 'status',
57 type => 2,
58 warning_default => '%{state} eq "enabled" and %{status} eq "yellow"',
59 critical_default => '%{state} eq "enabled" and %{status} eq "red"',
60 set => {
61 key_values => [ { name => 'state' }, { name => 'status' }, { name => 'reason' },{ name => 'display' } ],
62 closure_custom_output => $self->can('custom_status_output'),
63 closure_custom_perfdata => sub { return 0; },
64 closure_custom_threshold_check => \&catalog_status_threshold_ng
65 }
66 },
67 { label => 'current-server-connections', set => {
68 key_values => [ { name => 'ltmNodeAddrStatServerCurConns' }, { name => 'display' } ],
69 output_template => 'current server connections : %s',
70 perfdatas => [
71 { label => 'current_server_connections', template => '%s',
72 min => 0, label_extra_instance => 1, instance_use => 'display' }
73 ]
74 }
75 }
76 ];
77 }
78
79 sub new {
80 my ($class, %options) = @_;
81 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
82 bless $self, $class;
83
84 $options{options}->add_options(arguments => {
85 'filter-name:s' => { name => 'filter_name' }
86 });
87
88 return $self;
89 }
90
91 my $map_node_status = {
92 0 => 'none', 1 => 'green',
93 2 => 'yellow', 3 => 'red',
94 4 => 'blue', 5 => 'gray'
95 };
96 my $map_node_enabled = {
97 0 => 'none', 1 => 'enabled',
98 2 => 'disabled', 3 => 'disabledbyparent'
99 };
100
101 # New OIDS
102 my $mapping = {
103 new => {
104 AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.3', map => $map_node_status },
105 EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.4', map => $map_node_enabled },
106 StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.4.3.2.1.6' }
107 },
108 old => {
109 AvailState => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.13', map => $map_node_status },
110 EnabledState => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.14', map => $map_node_enabled },
111 StatusReason => { oid => '.1.3.6.1.4.1.3375.2.2.4.1.2.1.16' }
112 }
113 };
114 my $mapping2 = {
115 ltmNodeAddrStatServerCurConns => { oid => '.1.3.6.1.4.1.3375.2.2.4.2.3.1.9' }
116 };
117
118 sub manage_selection {
119 my ($self, %options) = @_;
120
121 my $snmp_result = $options{snmp}->get_multiple_table(
122 oids => [
123 { oid => $mapping->{new}->{AvailState}->{oid} },
124 { oid => $mapping->{old}->{AvailState}->{oid} },
125 ],
126 nothing_quit => 1
127 );
128
129 my ($branch_name, $map) = ($mapping->{new}->{AvailState}->{oid}, 'new');
130 if (!defined($snmp_result->{$mapping->{new}->{AvailState}->{oid}}) || scalar(keys %{$snmp_result->{$mapping->{new}->{AvailState}->{oid}}}) == 0) {
131 ($branch_name, $map) = ($mapping->{old}->{AvailState}->{oid}, 'old');
132 }
133
134 $self->{node} = {};
135 foreach my $oid (keys %{$snmp_result->{$branch_name}}) {
136 $oid =~ /^$branch_name\.(.*?)\.(.*)$/;
137 my ($num, $index) = ($1, $2);
138
139 my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result->{$branch_name}, instance => $num . '.' . $index);
140 my $name = $self->{output}->decode(join('', map(chr($_), split(/\./, $index))));
141
142 if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
143 $name !~ /$self->{option_results}->{filter_name}/) {
144 $self->{output}->output_add(long_msg => "skipping node '" . $name . "'.", debug => 1);
145 next;
146 }
147
148 $self->{node}->{$num . '.' . $index} = {
149 display => $name,
150 status => $result->{AvailState}
151 };
152 }
153
154 if (scalar(keys %{$self->{node}}) <= 0) {
155 $self->{output}->add_option_msg(short_msg => "No entry found.");
156 $self->{output}->option_exit();
157 }
158
159 $options{snmp}->load(
160 oids => [
161 $mapping->{$map}->{EnabledState}->{oid},
162 $mapping->{$map}->{StatusReason}->{oid},
163 $mapping2->{ltmNodeAddrStatServerCurConns}->{oid}
164 ],
165 instances => [keys %{$self->{node}}],
166 instance_regexp => '^(.*)$'
167 );
168 $snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
169
170 foreach (keys %{$self->{node}}) {
171 my $result = $options{snmp}->map_instance(mapping => $mapping->{$map}, results => $snmp_result, instance => $_);
172 my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_);
173
174 $result->{StatusReason} = '-' if (!defined($result->{StatusReason}) || $result->{StatusReason} eq '');
175 $self->{node}->{$_}->{reason} = $result->{StatusReason};
176 $self->{node}->{$_}->{state} = $result->{EnabledState};
177 $self->{node}->{$_}->{ltmNodeAddrStatServerCurConns} = $result2->{ltmNodeAddrStatServerCurConns};
178 }
179 }
180
181 1;
182
183 __END__
184
185 =head1 MODE
186
187 Check Nodes status.
188
189 =over 8
190
191 =item B<--filter-name>
192
193 Filter by name (regexp can be used).
194
195 =item B<--unknown-status>
196
197 Define the conditions to match for the status to be UNKNOWN (default: '').
198 You can use the following variables: %{state}, %{status}, %{display}
199
200 =item B<--warning-status>
201
202 Define the conditions to match for the status to be WARNING (default: '%{state} eq "enabled" and %{status} eq "yellow"').
203 You can use the following variables: %{state}, %{status}, %{display}
204
205 =item B<--critical-status>
206
207 Define the conditions to match for the status to be CRITICAL (default: '%{state} eq "enabled" and %{status} eq "red"').
208 You can use the following variables: %{state}, %{status}, %{display}
209
210 =item B<--warning-*> B<--critical-*>
211
212 Thresholds.
213 Can be: 'current-server-connections'.
214
215 =back
216
217 =cut