Debian Codegraph @

src/network/colubris/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::colubris::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 => 'current', set => {
37 key_values => [ { name => 'usage_now' } ],
38 output_template => '%.2f %% (current)',
39 perfdatas => [
40 { label => 'cpu_current', value => 'usage_now', template => '%.2f',
41 unit => '%', min => 0, max => 100 },
42 ],
43 }
44 },
45 { label => '5s', set => {
46 key_values => [ { name => 'usage_5s' } ],
47 output_template => '%.2f %% (5sec)',
48 perfdatas => [
49 { label => 'cpu_5s', value => 'usage_5s', template => '%.2f',
50 unit => '%', min => 0, max => 100 },
51 ],
52 }
53 },
54 { label => '10s', set => {
55 key_values => [ { name => 'usage_10s' } ],
56 output_template => '%.2f %% (10sec)',
57 perfdatas => [
58 { label => 'cpu_10s', value => 'usage_10s', template => '%.2f',
59 unit => '%', min => 0, max => 100 },
60 ],
61 }
62 },
63 { label => '20s', set => {
64 key_values => [ { name => 'usage_20s' } ],
65 output_template => '%.2f %% (5sec)',
66 perfdatas => [
67 { label => 'cpu_20s', value => 'usage_20s', template => '%.2f',
68 unit => '%', min => 0, max => 100 },
69 ],
70 }
71 },
72 ];
73 }
74
75 sub prefix_cpu_output {
76 my ($self, %options) = @_;
77
78 return "CPU ";
79 }
80
81 sub new {
82 my ($class, %options) = @_;
83 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
84 bless $self, $class;
85
86 $options{options}->add_options(arguments => {
87 });
88
89 return $self;
90 }
91
92 sub manage_selection {
93 my ($self, %options) = @_;
94
95 my $oid_coUsInfoCpuUseNow = '.1.3.6.1.4.1.8744.5.21.1.1.5.0';
96 my $oid_coUsInfoCpuUse5Sec = '.1.3.6.1.4.1.8744.5.21.1.1.6.0';
97 my $oid_coUsInfoCpuUse10Sec = '.1.3.6.1.4.1.8744.5.21.1.1.7.0';
98 my $oid_coUsInfoCpuUse20Sec = '.1.3.6.1.4.1.8744.5.21.1.1.8.0';
99 my $snmp_result = $options{snmp}->get_leef(
100 oids => [
101 $oid_coUsInfoCpuUseNow, $oid_coUsInfoCpuUse5Sec,
102 $oid_coUsInfoCpuUse10Sec, $oid_coUsInfoCpuUse20Sec
103 ],
104 nothing_quit => 1
105 );
106
107 $self->{global} = {
108 usage_now => $snmp_result->{$oid_coUsInfoCpuUseNow},
109 usage_5s => $snmp_result->{$oid_coUsInfoCpuUse5Sec},
110 usage_10s => $snmp_result->{$oid_coUsInfoCpuUse10Sec},
111 usage_20s => $snmp_result->{$oid_coUsInfoCpuUse20Sec},
112 };
113 }
114
115 1;
116
117 __END__
118
119 =head1 MODE
120
121 Check CPU usage.
122
123 =over 8
124
125 =item B<--filter-counters>
126
127 Only display some counters (regexp can be used).
128 Example: --filter-counters='20s'
129
130 =item B<--warning-*>
131
132 Warning threshold.
133 Can be: 'current', '5s', '10s', '20s'.
134
135 =item B<--critical-*>
136
137 Critical threshold.
138 Can be: 'current', '5s', '10s', '20s'.
139
140 =back
141
142 =cut