Debian Codegraph @

src/network/watchguard/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::watchguard::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_prefix_output => 'prefix_cpu_output' }
33 ];
34
35 $self->{maps_counters}->{global} = [
36 { label => '1min', nlabel => 'cpu.utilization.1m.percentage', set => {
37 key_values => [ { name => '1min' } ],
38 output_template => '1 minute: %.2f %%',
39 perfdatas => [
40 { label => 'cpu_1min', template => '%.2f', min => 0, max => 100, unit => '%' }
41 ]
42 }
43 },
44 { label => '5min', nlabel => 'cpu.utilization.5m.percentage', set => {
45 key_values => [ { name => '5min' } ],
46 output_template => '5 minutes: %.2f %%',
47 perfdatas => [
48 { label => 'cpu_5min', template => '%.2f', min => 0, max => 100, unit => '%' }
49 ]
50 }
51 },
52 { label => '15min', nlabel => 'cpu.utilization.15m.percentage', set => {
53 key_values => [ { name => '15min' } ],
54 output_template => '15 minutes: %.2f %%',
55 perfdatas => [
56 { label => 'cpu_15min', template => '%.2f', min => 0, max => 100, unit => '%' }
57 ]
58 }
59 }
60 ];
61 }
62
63 sub prefix_cpu_output {
64 my ($self, %options) = @_;
65
66 return "CPU ";
67 }
68
69 sub new {
70 my ($class, %options) = @_;
71 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
72 bless $self, $class;
73
74 $options{options}->add_options(arguments => {
75 });
76
77 return $self;
78 }
79
80 sub manage_selection {
81 my ($self, %options) = @_;
82
83 if ($options{snmp}->is_snmpv1()) {
84 $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
85 $self->{output}->option_exit();
86 }
87
88 my $oid_wgSystemCpuUtil1 = '.1.3.6.1.4.1.3097.6.3.77.0';
89 my $oid_wgSystemCpuUtil5 = '.1.3.6.1.4.1.3097.6.3.78.0';
90 my $oid_wgSystemCpuUtil15 = '.1.3.6.1.4.1.3097.6.3.79.0';
91 my $snmp_result = $options{snmp}->get_leef(
92 oids => [
93 $oid_wgSystemCpuUtil1, $oid_wgSystemCpuUtil5, $oid_wgSystemCpuUtil15
94 ],
95 nothing_quit => 1
96 );
97
98 $self->{global} = {
99 '1min' => $snmp_result->{$oid_wgSystemCpuUtil1} / 100,
100 '5min' => $snmp_result->{$oid_wgSystemCpuUtil5} / 100,
101 '15min' => $snmp_result->{$oid_wgSystemCpuUtil15} / 100
102 };
103 }
104
105 1;
106
107 __END__
108
109 =head1 MODE
110
111 Check CPU usages.
112
113 =over 8
114
115 =item B<--filter-counters>
116
117 Only display some counters (regexp can be used).
118 Example: --filter-counters='^1min|5min$'
119
120 =item B<--warning-*> B<--critical-*>
121
122 Warning threshold.
123 Can be: '1min', '5min', '15min'.
124
125 =back
126
127 =cut