Debian Codegraph @

src/network/extreme/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::extreme::snmp::mode::cpu;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub set_counters {
29 my ($self, %options) = @_;
30
31 $self->{maps_counters_type} = [
32 { name => 'global', type => 0, cb_init => 'skip_global', },
33 { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' }
34 ];
35 $self->{maps_counters}->{global} = [
36 { label => 'total', set => {
37 key_values => [ { name => 'total' } ],
38 output_template => 'Total CPU Usage : %.2f %%',
39 perfdatas => [
40 { label => 'cpu_total', template => '%.2f', min => 0, max => 100, unit => '%' }
41 ]
42 }
43 }
44 ];
45
46 $self->{maps_counters}->{cpu} = [
47 { label => '5secs', set => {
48 key_values => [ { name => 'extremeCpuMonitorSystemUtilization5secs' }, { name => 'num' }, ],
49 output_template => '5 seconds : %.2f %%',
50 perfdatas => [
51 { label => 'cpu_5secs', template => '%.2f',
52 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num' }
53 ]
54 }
55 },
56 { label => '10secs', set => {
57 key_values => [ { name => 'extremeCpuMonitorSystemUtilization10secs' }, { name => 'num' }, ],
58 output_template => '10 seconds : %.2f %%',
59 perfdatas => [
60 { label => 'cpu_10secs', template => '%.2f',
61 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num' }
62 ]
63 }
64 },
65 { label => '30secs', set => {
66 key_values => [ { name => 'extremeCpuMonitorSystemUtilization30secs' }, { name => 'num' }, ],
67 output_template => '30 seconds : %.2f %%',
68 perfdatas => [
69 { label => 'cpu_30secs', template => '%.2f',
70 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num' }
71 ]
72 }
73 },
74 { label => '1min', set => {
75 key_values => [ { name => 'extremeCpuMonitorSystemUtilization1min' }, { name => 'num' }, ],
76 output_template => '1 minute : %.2f %%',
77 perfdatas => [
78 { label => 'cpu_1min', template => '%.2f',
79 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num' }
80 ]
81 }
82 },
83 { label => '5min', set => {
84 key_values => [ { name => 'extremeCpuMonitorSystemUtilization5mins' }, { name => 'num' }, ],
85 output_template => '5 minutes : %.2f %%',
86 perfdatas => [
87 { label => 'cpu_5min', template => '%.2f',
88 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num' }
89 ]
90 }
91 }
92 ];
93 }
94
95 sub skip_global {
96 my ($self, %options) = @_;
97
98 scalar(keys %{$self->{cpu}}) > 1 ? return(0) : return(1);
99 }
100
101 sub prefix_cpu_output {
102 my ($self, %options) = @_;
103
104 return "CPU '" . $options{instance_value}->{num} . "' ";
105 }
106
107 sub new {
108 my ($class, %options) = @_;
109 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
110 bless $self, $class;
111
112 $options{options}->add_options(arguments => {
113 });
114
115 return $self;
116 }
117
118 my $mapping = {
119 extremeCpuMonitorSystemUtilization5secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.5' },
120 extremeCpuMonitorSystemUtilization10secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.6' },
121 extremeCpuMonitorSystemUtilization30secs => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.7' },
122 extremeCpuMonitorSystemUtilization1min => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.8' },
123 extremeCpuMonitorSystemUtilization5mins => { oid => '.1.3.6.1.4.1.1916.1.32.1.4.1.9' },
124 };
125
126 sub manage_selection {
127 my ($self, %options) = @_;
128
129 my $oid_extremeCpuMonitorSystemEntry = '.1.3.6.1.4.1.1916.1.32.1.4.1';
130 my $oid_extremeCpuMonitorTotalUtilization = '.1.3.6.1.4.1.1916.1.32.1.2'; # without .0
131 my $snmp_result = $options{snmp}->get_multiple_table(
132 oids => [
133 { oid => $oid_extremeCpuMonitorTotalUtilization },
134 { oid => $oid_extremeCpuMonitorSystemEntry, start => $mapping->{extremeCpuMonitorSystemUtilization5secs}->{oid}, end => $mapping->{extremeCpuMonitorSystemUtilization5mins}->{oid} },
135 ],
136 nothing_quit => 1
137 );
138
139 $self->{cpu} = {};
140 foreach my $oid (keys %{$snmp_result->{$oid_extremeCpuMonitorSystemEntry}}) {
141 next if ($oid !~ /^$mapping->{extremeCpuMonitorSystemUtilization1min}->{oid}\.(.*)$/);
142 my $instance = $1;
143 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_extremeCpuMonitorSystemEntry}, instance => $instance);
144
145 foreach (keys %{$mapping}) {
146 $result->{$_} = undef if (defined($result->{$_}) && $result->{$_} =~ /n\/a/i);
147 }
148
149 $self->{cpu}->{$instance} = { num => $instance, %$result };
150 }
151
152 $self->{global} = { total => $snmp_result->{$oid_extremeCpuMonitorTotalUtilization}->{$oid_extremeCpuMonitorTotalUtilization . '.0'} };
153 }
154
155 1;
156
157 __END__
158
159 =head1 MODE
160
161 Check CPU usages.
162
163 =over 8
164
165 =item B<--filter-counters>
166
167 Only display some counters (regexp can be used).
168 Example: --filter-counters='^(1min|5min)$'
169
170 =item B<--warning-*>
171
172 Warning threshold.
173 Can be: 'total', '5secs', '10secs', '30secs', '1min', '5min'.
174
175 =item B<--critical-*>
176
177 Critical threshold.
178 Can be: 'total', '5secs', '10secs', '30secs', '1min', '5min'.
179
180 =back
181
182 =cut