Debian Codegraph @

src/network/aruba/aoscx/snmp/mode/cpu.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::aruba::aoscx::snmp::mode::cpu;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub prefix_module_output {
29 my ($self, %options) = @_;
30
31 return sprintf(
32 "module '%s' [type: %s] ",
33 $options{instance_value}->{name},
34 $options{instance_value}->{type}
35 );
36 }
37
38 sub set_counters {
39 my ($self, %options) = @_;
40
41 $self->{maps_counters_type} = [
42 { name => 'modules', type => 1, cb_prefix_output => 'prefix_module_output', message_multiple => 'All cpu usages are ok' }
43 ];
44
45 $self->{maps_counters}->{modules} = [
46 { label => 'cpu-utilization', nlabel => 'cpu.utilization.percentage', set => {
47 key_values => [ { name => 'cpu_util' } ],
48 output_template => 'cpu utilization: %.2f%%',
49 perfdatas => [
50 { template => '%s', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
51 ]
52 }
53 }
54 ];
55 }
56
57 sub new {
58 my ($class, %options) = @_;
59 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
60 bless $self, $class;
61
62 $options{options}->add_options(arguments => {
63 'filter-module-name:s' => { name => 'filter_module_name' }
64 });
65
66 return $self;
67 }
68
69 sub manage_selection {
70 my ($self, %options) = @_;
71
72 my $oid_cpu = '.1.3.6.1.4.1.47196.4.1.1.3.22.1.0.1.1.3'; # arubaWiredSystemInfoCpu
73 my $snmp_result = $options{snmp}->get_table(
74 oid => $oid_cpu,
75 nothing_quit => 1
76 );
77
78 $self->{modules} = {};
79 foreach (keys %$snmp_result) {
80 /^$oid_cpu\.(.*)$/;
81 my @indexes = split(/\./, $1);
82
83 my $type = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
84 my $name = $self->{output}->decode(join('', map(chr($_), splice(@indexes, 0, shift(@indexes)) )));
85
86 next if (defined($self->{option_results}->{filter_module_name}) && $self->{option_results}->{filter_module_name} ne '' &&
87 $name !~ /$self->{option_results}->{filter_module_name}/);
88
89 $self->{modules}->{$name} = {
90 name => $name,
91 type => $type,
92 cpu_util => $snmp_result->{$_}
93 };
94 }
95 }
96
97 1;
98
99 __END__
100
101 =head1 MODE
102
103 Check CPU (worked since firmware 10.10).
104
105 =over 8
106
107 =item B<--filter-module-name>
108
109 Filter modules by name (can be a regexp).
110
111 =item B<--warning-*> B<--critical-*>
112
113 Thresholds.
114 Can be: 'cpu-utilization' (%).
115
116 =back
117
118 =cut