Debian Codegraph @

src/network/hp/procurve/snmp/mode/virtualchassis.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::hp::procurve::snmp::mode::virtualchassis;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27 use Digest::MD5 qw(md5_hex);
28 use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
29
30 sub custom_status_output {
31 my ($self, %options) = @_;
32
33 return sprintf(
34 'virtual chassis operational status: %s',
35 $self->{result_values}->{status}
36 );
37 }
38
39 sub custom_member_status_output {
40 my ($self, %options) = @_;
41
42 return sprintf(
43 'state: %s',
44 $self->{result_values}->{state}
45 );
46 }
47
48 sub custom_member_status_calc {
49 my ($self, %options) = @_;
50
51 $self->{result_values}->{stateLast} = $options{old_datas}->{$self->{instance} . '_state'};
52 $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
53 if (!defined($options{old_datas}->{$self->{instance} . '_state'})) {
54 $self->{error_msg} = "buffer creation";
55 return -2;
56 }
57
58 return 0;
59 }
60
61 sub custom_link_status_output {
62 my ($self, %options) = @_;
63
64 return sprintf(
65 'operational status: %s',
66 $self->{result_values}->{link_status}
67 );
68 }
69
70 sub custom_memory_usage_output {
71 my ($self, %options) = @_;
72
73 my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
74 my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
75 my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
76 return sprintf(
77 "memory usage total: %s used: %s (%.2f%%) free: %s (%.2f%%)",
78 $total_size_value . " " . $total_size_unit,
79 $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
80 $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
81 );
82 }
83
84 sub member_long_output {
85 my ($self, %options) = @_;
86
87 return "checking stack member '" . $options{instance_value}->{display} . "'";
88 }
89
90 sub prefix_member_output {
91 my ($self, %options) = @_;
92
93 return "Stack member '" . $options{instance_value}->{display} . "' ";
94 }
95
96 sub prefix_link_output {
97 my ($self, %options) = @_;
98
99 return "link '" . $options{instance_value}->{display} . "' ";
100 }
101
102 sub set_counters {
103 my ($self, %options) = @_;
104
105 $self->{maps_counters_type} = [
106 { name => 'global', type => 0, skipped_code => { -10 => 1 } },
107 { name => 'member', type => 3, cb_prefix_output => 'prefix_member_output', cb_long_output => 'member_long_output', indent_long_output => ' ', message_multiple => 'All stack members are ok',
108 group => [
109 { name => 'member_global', type => 0, skipped_code => { -10 => 1 } },
110 { name => 'link', display_long => 1, cb_prefix_output => 'prefix_link_output', message_multiple => 'All links are ok', type => 1, skipped_code => { -10 => 1 } }
111 ]
112 }
113 ];
114
115 $self->{maps_counters}->{global} = [
116 { label => 'status', type => 2, critical_default => '%{status} !~ /active/i', set => {
117 key_values => [ { name => 'status' } ],
118 closure_custom_output => $self->can('custom_status_output'),
119 closure_custom_perfdata => sub { return 0; },
120 closure_custom_threshold_check => \&catalog_status_threshold_ng
121 }
122 },
123 { label => 'members-total', nlabel => 'stack.members.total.count', set => {
124 key_values => [ { name => 'members' } ],
125 output_template => 'total members: %s',
126 perfdatas => [
127 { template => '%s', min => 0 }
128 ]
129 }
130 }
131 ];
132
133 $self->{maps_counters}->{member_global} = [
134 { label => 'member-status', type => 2, critical_default => '%{state} ne %{stateLast} || %{state} =~ /communicationFailure|incompatibleOS/i', set => {
135 key_values => [ { name => 'state' }, { name => 'display' } ],
136 closure_custom_calc => $self->can('custom_member_status_calc'),
137 closure_custom_output => $self->can('custom_member_status_output'),
138 closure_custom_perfdata => sub { return 0; },
139 closure_custom_threshold_check => \&catalog_status_threshold_ng
140 }
141 },
142 { label => 'cpu-utilization', nlabel => 'member.cpu.utilization.percentage', set => {
143 key_values => [ { name => 'cpu' }, { name => 'display'} ],
144 output_template => 'cpu usage: %.2f%%',
145 perfdatas => [
146 { template => '%.2f', unit => '%', min => 0, max => 100,
147 label_extra_instance => 1 }
148 ]
149 }
150 },
151 { label => 'memory-usage', nlabel => 'member.memory.usage.bytes', set => {
152 key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
153 closure_custom_output => $self->can('custom_memory_usage_output'),
154 perfdatas => [
155 { template => '%d', min => 0, max => 'total',
156 unit => 'B', cast_int => 1, label_extra_instance => 1 }
157 ]
158 }
159 },
160 { label => 'memory-usage-free', display_ok => 0, nlabel => 'member.memory.free.bytes', set => {
161 key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' }, { name => 'display' } ],
162 closure_custom_output => $self->can('custom_memory_usage_output'),
163 perfdatas => [
164 { template => '%d', min => 0, max => 'total',
165 unit => 'B', cast_int => 1, label_extra_instance => 1 }
166 ]
167 }
168 },
169 { label => 'memory-usage-prct', display_ok => 0, nlabel => 'member.memory.usage.percentage', set => {
170 key_values => [ { name => 'prct_used' }, { name => 'display' } ],
171 output_template => 'memory used : %.2f %%',
172 perfdatas => [
173 { template => '%.2f', min => 0, max => 100,
174 unit => '%', label_extra_instance => 1 }
175 ]
176 }
177 }
178 ];
179
180 $self->{maps_counters}->{link} = [
181 { label => 'link-status', type => 2, critical_default => '%{link_status} eq "down"', set => {
182 key_values => [ { name => 'link_status' }, { name => 'display' }, { name => 'member_serial' } ],
183 closure_custom_output => $self->can('custom_link_status_output'),
184 closure_custom_perfdata => sub { return 0; },
185 closure_custom_threshold_check => \&catalog_status_threshold_ng
186 }
187 }
188 ];
189 }
190
191 sub new {
192 my ($class, %options) = @_;
193 my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
194 bless $self, $class;
195
196 $options{options}->add_options(arguments => {
197 "filter-member-serial:s" => { name => 'filter_member_serial' }
198 });
199
200 return $self;
201 }
202
203 my $mapping_oper_status = {
204 0 => 'unAvailable', 1 => 'disabled', 2 => 'active',
205 3 => 'fragmentInactive', 4 => 'fragmentActive'
206 };
207 my $mapping_admin_status = {
208 1 => 'enable', 2 => 'disabled'
209 };
210 my $mapping_member_state = {
211 0 => 'unusedId', 1 => 'missing',
212 2 => 'provision', 3 => 'commander',
213 4 => 'standby', 5 => 'member',
214 6 => 'shutdown', 7 => 'booting',
215 8 => 'communicationFailure', 9 => 'incompatibleOS',
216 10 => 'unknownState', 11 => 'standbyBooting',
217 };
218 my $mapping_link_status = {
219 1 => 'up', 2 => 'down', 3 => 'disabled',
220 };
221
222 my $mapping = {
223 hpicfVsfVCOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.2', map => $mapping_oper_status },
224 hpicfVsfVCAdminStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1.3', map => $mapping_admin_status }
225 };
226 my $mapping2 = {
227 hpicfVsfVCMemberState => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.9', map => $mapping_member_state },
228 hpicfVsfVCMemberSerialNum => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.14' },
229 hpicfVsfVCMemberCpuUtil => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.19' },
230 hpicfVsfVCMemberTotalMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.20' },
231 hpicfVsfVCMemberFreeMemory => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1.21' }
232 };
233 my $mapping3 = {
234 hpicfVsfVCLinkName => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.3' },
235 hpicfVsfVCLinkOperStatus => { oid => '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1.4', map => $mapping_link_status }
236 };
237 my $oid_hpicfVsfVCConfig = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.1';
238 my $oid_hpicfVsfVCMemberEntry = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.3.1';
239 my $oid_hpicfVsfVCLinkEntry = '.1.3.6.1.4.1.11.2.14.11.5.1.116.1.4.1';
240
241 sub manage_selection {
242 my ($self, %options) = @_;
243
244 my $snmp_result = $options{snmp}->get_multiple_table(
245 oids => [
246 { oid => $oid_hpicfVsfVCConfig, start => $mapping->{hpicfVsfVCOperStatus}->{oid}, end => $mapping->{hpicfVsfVCAdminStatus}->{oid} },
247 { oid => $oid_hpicfVsfVCMemberEntry, start => $mapping2->{hpicfVsfVCMemberState}->{oid} },
248 { oid => $oid_hpicfVsfVCLinkEntry, start => $mapping3->{hpicfVsfVCLinkName}->{oid}, end => $mapping3->{hpicfVsfVCLinkOperStatus}->{oid} }
249 ],
250 nothing_quit => 1
251 );
252
253 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_hpicfVsfVCConfig}, instance => '0');
254 if ($result->{hpicfVsfVCAdminStatus} eq 'disable') {
255 $self->{output}->output_add(
256 severity => 'OK',
257 short_msg => 'vsf virtual chassis is disabled'
258 );
259 $self->{output}->display();
260 $self->{output}->exit();
261 }
262
263 $self->{global} = { status => $result->{hpicfVsfVCOperStatus} };
264 $self->{member} = {};
265 foreach my $oid (keys %{$snmp_result->{$oid_hpicfVsfVCMemberEntry}}) {
266 next if ($oid !~ /^$mapping2->{hpicfVsfVCMemberState}->{oid}\.(.*)$/);
267 my $member_id = $1;
268 $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_hpicfVsfVCMemberEntry}, instance => $member_id);
269
270 my $member_name = $result->{hpicfVsfVCMemberSerialNum};
271 next if (defined($self->{option_results}->{filter_member_serial}) && $self->{option_results}->{filter_member_serial} ne '' &&
272 $member_name !~ /$self->{option_results}->{filter_member_serial}/);
273
274 $self->{member}->{$member_name} = {
275 display => $member_name,
276 member_global => {
277 display => $member_name,
278 state => $result->{hpicfVsfVCMemberState},
279 cpu => $result->{hpicfVsfVCMemberCpuUtil},
280 total => $result->{hpicfVsfVCMemberTotalMemory},
281 free => $result->{hpicfVsfVCMemberFreeMemory},
282 used => $result->{hpicfVsfVCMemberTotalMemory} - $result->{hpicfVsfVCMemberFreeMemory},
283 prct_used => ($result->{hpicfVsfVCMemberTotalMemory} - $result->{hpicfVsfVCMemberFreeMemory}) * 100 / $result->{hpicfVsfVCMemberTotalMemory},
284 prct_free => $result->{hpicfVsfVCMemberFreeMemory} * 100 / $result->{hpicfVsfVCMemberTotalMemory}
285 },
286 link => {}
287 };
288
289 foreach (keys %{$snmp_result->{$oid_hpicfVsfVCLinkEntry}}) {
290 next if (!/^$mapping3->{hpicfVsfVCLinkName}->{oid}\.$member_id\.(.*)$/);
291 $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{$oid_hpicfVsfVCLinkEntry}, instance => $member_id . '.' . $1);
292
293 $self->{member}->{$member_name}->{link}->{$result->{hpicfVsfVCLinkName}} = {
294 member_serial => $member_name,
295 display => $result->{hpicfVsfVCLinkName},
296 link_status => $result->{hpicfVsfVCLinkOperStatus}
297 };
298 }
299 }
300
301 $self->{global}->{members} = scalar(keys %{$self->{member}});
302
303 $self->{cache_name} = 'hp_procurve_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
304 md5_hex(
305 (defined($self->{option_results}->{filter_counters}) ? $self->{option_results}->{filter_counters} : 'all') . '_' .
306 (defined($self->{option_results}->{filter_member_serial}) ? $self->{option_results}->{filter_member_serial} : 'all')
307 );
308 }
309
310 1;
311
312 __END__
313
314 =head1 MODE
315
316 Check vsf virtual chassis.
317
318 =over 8
319
320 =item B<--filter-member-serial>
321
322 Filter members by serial (can be a regexp).
323
324 =item B<--unknown-status>
325
326 Define the conditions to match for the status to be UNKNOWN.
327 You can use the following variables: %{status}
328
329 =item B<--warning-status>
330
331 Define the conditions to match for the status to be WARNING.
332 You can use the following variables: %{status}
333
334 =item B<--critical-status>
335
336 Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /active/i').
337 You can use the following variables: %{status}
338
339 =item B<--unknown-member-status>
340
341 Define the conditions to match for the status to be UNKNOWN.
342 You can use the following variables: %{state}, %{stateLast}
343
344 =item B<--warning-member-status>
345
346 Define the conditions to match for the status to be WARNING.
347 You can use the following variables: %{state}, %{stateLast}
348
349 =item B<--critical-member-status>
350
351 Define the conditions to match for the status to be CRITICAL (default: '%{state} ne %{stateLast} || %{state} =~ /communicationFailure|incompatibleOS/i').
352 You can use the following variables: %{state}, %{stateLast}
353
354 =item B<--unknown-link-status>
355
356 Define the conditions to match for the status to be UNKNOWN.
357 You can use the following variables: %{link_status}, %{display}
358
359 =item B<--warning-link-status>
360
361 Define the conditions to match for the status to be WARNING.
362 You can use the following variables: %{link_status}, %{display}
363
364 =item B<--critical-link-status>
365
366 Define the conditions to match for the status to be CRITICAL (default: '%{link_status} eq "down"').
367 You can use the following variables: %{link_status}, %{display}
368
369 =item B<--warning-*> B<--critical-*>
370
371 Thresholds.
372 Can be: 'members-total', 'memory-usage-prct', 'memory-usage', 'memory-usage-free',
373 'cpu-utilization'.
374
375 =back
376
377 =cut