Debian Codegraph @

src/network/radware/alteon/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::radware::alteon::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 => 'mp_cpu', type => 0, cb_prefix_output => 'prefix_mp_cpu_output', skipped_code => { -10 => 1 } },
33 { name => 'sp_ga_avg', type => 0, skipped_code => { -10 => 1 } },
34 { name => 'sp_ga', type => 1, cb_init => 'skip_sp_ga', cb_prefix_output => 'prefix_sp_ga_output', message_multiple => 'All SP GA CPU are ok' },
35 ];
36
37 $self->{maps_counters}->{mp_cpu} = [
38 { label => 'mp-1s', set => {
39 key_values => [ { name => 'mp_1s' } ],
40 output_template => '%.2f%% (1sec)',
41 perfdatas => [
42 { label => 'mp_cpu_1s', value => 'mp_1s', template => '%.2f',
43 min => 0, max => 100, unit => '%' },
44 ],
45 }
46 },
47 { label => 'mp-4s', set => {
48 key_values => [ { name => 'mp_4s' } ],
49 output_template => '%.2f%% (4sec)',
50 perfdatas => [
51 { label => 'mp_cpu_4s', value => 'mp_4s', template => '%.2f',
52 min => 0, max => 100, unit => '%' },
53 ],
54 }
55 },
56 { label => 'mp-64s', set => {
57 key_values => [ { name => 'mp_64s' } ],
58 output_template => '%.2f%% (64sec)',
59 perfdatas => [
60 { label => 'mp_cpu_64s', value => 'mp_64s', template => '%.2f',
61 min => 0, max => 100, unit => '%' },
62 ],
63 }
64 },
65 ];
66
67 $self->{maps_counters}->{sp_ga_avg} = [
68 { label => 'sp-ga-avg-1s', set => {
69 key_values => [ { name => 'sp_1s' } ],
70 output_template => 'SP GA Average CPU Usage: %.2f%% (1sec)',
71 perfdatas => [
72 { label => 'avg_spga_cpu_1s', value => 'sp_1s', template => '%.2f',
73 min => 0, max => 100, unit => '%' },
74 ],
75 }
76 },
77 { label => 'sp-ga-avg-4s', set => {
78 key_values => [ { name => 'sp_4s' } ],
79 output_template => '%.2f%% (4sec)',
80 perfdatas => [
81 { label => 'avg_spga_cpu_4s', value => 'sp_4s', template => '%.2f',
82 min => 0, max => 100, unit => '%' },
83 ],
84 }
85 },
86 { label => 'sp-ga-avg-64s', set => {
87 key_values => [ { name => 'sp_64s' } ],
88 output_template => '%.2f%% (64sec)',
89 perfdatas => [
90 { label => 'avg_spga_cpu_64s', value => 'sp_64s', template => '%.2f',
91 min => 0, max => 100, unit => '%' },
92 ],
93 }
94 },
95 ];
96
97 $self->{maps_counters}->{sp_ga} = [
98 { label => 'sp-ga-1s', set => {
99 key_values => [ { name => 'sp_1s' }, { name => 'display' } ],
100 output_template => '%.2f%% (1sec)',
101 perfdatas => [
102 { label => 'spga_cpu_1s', value => 'sp_1s', template => '%.2f',
103 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
104 ],
105 }
106 },
107 { label => 'sp-ga-4s', set => {
108 key_values => [ { name => 'sp_4s' }, { name => 'display' } ],
109 output_template => '%.2f%% (4sec)',
110 perfdatas => [
111 { label => 'spga_cpu_4s', value => 'sp_4s', template => '%.2f',
112 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
113 ],
114 }
115 },
116 { label => 'sp-ga-64s', set => {
117 key_values => [ { name => 'sp_64s' }, { name => 'display' } ],
118 output_template => '%.2f%% (64sec)',
119 perfdatas => [
120 { label => 'spga_cpu_64s', value => 'sp_64s', template => '%.2f',
121 min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' },
122 ],
123 }
124 },
125 ];
126 }
127
128 sub prefix_mp_cpu_output {
129 my ($self, %options) = @_;
130
131 return "MP CPU Usage: ";
132 }
133
134 sub prefix_sp_ga_output {
135 my ($self, %options) = @_;
136
137 return "SP GA CPU '" . $options{instance_value}->{display} . "' Usage: ";
138 }
139
140 sub skip_sp_ga {
141 my ($self, %options) = @_;
142
143 scalar(keys %{$self->{sp_ga}}) <= 0 ? return(1) : return(0);
144 }
145
146 sub new {
147 my ($class, %options) = @_;
148 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
149 bless $self, $class;
150
151 $options{options}->add_options(arguments =>
152 {
153 });
154
155 return $self;
156 }
157
158 my $mapping = {
159 mpCpuStatsUtil1Second => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.2.1' },
160 mpCpuStatsUtil4Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.2.2' },
161 mpCpuStatsUtil64Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.2.3' },
162 };
163 my $mapping2 = {
164 spGAStatsCpuUtil1Second => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1.3' },
165 spGAStatsCpuUtil4Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1.4' },
166 spGAStatsCpuUtil64Seconds => { oid => '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1.5' },
167 };
168 my $oid_mpCpuStats = '.1.3.6.1.4.1.1872.2.5.1.2.2';
169 my $oid_spGAStatsCpuUtilTableEntry = '.1.3.6.1.4.1.1872.2.5.1.2.13.1.1';
170
171 sub manage_selection {
172 my ($self, %options) = @_;
173
174 my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_mpCpuStats }, { oid => $oid_spGAStatsCpuUtilTableEntry } ],
175 return_type => 1, nothing_quit => 1);
176 $self->{sp_ga} = {};
177 my ($avg_sp_1s, $avg_sp_4s, $avg_sp_64s) = (0, 0, 0);
178 foreach my $oid (keys %{$snmp_result}) {
179 next if ($oid !~ /^$mapping2->{spGAStatsCpuUtil64Seconds}->{oid}\.(.*)$/);
180 my $instance = $1;
181 my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $instance);
182
183 $self->{sp_ga}->{$instance} = {
184 display => $instance,
185 sp_1s => $result->{spGAStatsCpuUtil1Second},
186 sp_4s => $result->{spGAStatsCpuUtil4Seconds},
187 sp_64s => $result->{spGAStatsCpuUtil64Seconds},
188 };
189 $avg_sp_1s += $result->{spGAStatsCpuUtil1Second};
190 $avg_sp_4s += $result->{spGAStatsCpuUtil4Seconds};
191 $avg_sp_64s += $result->{spGAStatsCpuUtil64Seconds};
192 }
193
194 $self->{sp_ga_avg} = {};
195 if (scalar(keys %{$self->{sp_ga}}) > 1) {
196 $self->{sp_ga_avg} = {
197 sp_1s => $avg_sp_1s / scalar(keys %{$self->{sp_ga}}),
198 sp_4s => $avg_sp_4s / scalar(keys %{$self->{sp_ga}}),
199 sp_64s => $avg_sp_64s / scalar(keys %{$self->{sp_ga}}),
200 };
201 }
202
203 $self->{mp_cpu} = {
204 mp_1s => $snmp_result->{$mapping->{mpCpuStatsUtil1Second}->{oid} . '.0'},
205 mp_4s => $snmp_result->{$mapping->{mpCpuStatsUtil4Seconds}->{oid} . '.0'},
206 mp_64s => $snmp_result->{$mapping->{mpCpuStatsUtil64Seconds}->{oid} . '.0'},
207 };
208 }
209
210 1;
211
212 __END__
213
214 =head1 MODE
215
216 Check MP CPU usage (ALTEON-CHEETAH-SWITCH-MIB).
217
218 =over 8
219
220 =item B<--filter-counters>
221
222 Only display some counters (regexp can be used).
223 Example: --filter-counters='^(64s)$'
224
225 =item B<--warning-*>
226
227 Warning threshold.
228 Can be: 'mp-1s', 'mp-4s', 'mp-64s',
229 'sp-ga-1s', 'sp-ga-4s', 'sp-ga-64s',
230 'sp-ga-avg-1s', 'sp-ga-avg-4s', 'sp-ga-avg-64s'.
231
232 =item B<--critical-*>
233
234 Critical threshold.
235 Can be: 'mp-1s', 'mp-4s', 'mp-64s',
236 'sp-ga-1s', 'sp-ga-4s', 'sp-ga-64s',
237 'sp-ga-avg-1s', 'sp-ga-avg-4s', 'sp-ga-avg-64s'.
238
239 =back
240
241 =cut
242