Debian Codegraph @

src/network/raisecom/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::raisecom::snmp::mode::cpu;
22
23 use base qw(centreon::plugins::templates::counter);
24
25 use strict;
26 use warnings;
27
28 sub prefix_cpu_output {
29 my ($self, %options) = @_;
30
31 return "CPU '" . $options{instance} . "' usage ";
32 }
33
34 sub set_counters {
35 my ($self, %options) = @_;
36
37 $self->{maps_counters_type} = [
38 { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usage for every period are OK.', skipped_code => { -10 => 1 } }
39 ];
40
41 $self->{maps_counters}->{cpu} = [
42 { label => '1s', nlabel => 'cpu.utilization.1s.percentage', set => {
43 key_values => [ { name => 'oneSec' } ],
44 output_template => '%.2f%% (1sec)',
45 perfdatas => [
46 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
47 ]
48 }
49 },
50 { label => '5s', nlabel => 'cpu.utilization.5s.percentage', set => {
51 key_values => [ { name => 'fiveSec' } ],
52 output_template => '%.2f%% (5sec)',
53 perfdatas => [
54 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
55 ]
56 }
57 },
58 { label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => {
59 key_values => [ { name => 'oneMin' } ],
60 output_template => '%.2f%% (1min)',
61 perfdatas => [
62 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
63 ]
64 }
65 },
66 { label => '10m', nlabel => 'cpu.utilization.10m.percentage', set => {
67 key_values => [ { name => 'tenMin' } ],
68 output_template => '%.2f%% (10min)',
69 perfdatas => [
70 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
71 ]
72 }
73 },
74 { label => '2h', nlabel => 'cpu.utilization.2h.percentage', set => {
75 key_values => [ { name => 'twoHour' } ],
76 output_template => '%.2f%% (2h)',
77 perfdatas => [
78 { template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
79 ]
80 }
81 }
82 ];
83 }
84
85 sub new {
86 my ($class, %options) = @_;
87 my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
88 bless $self, $class;
89
90 $options{options}->add_options(arguments => {});
91
92 return $self;
93 }
94
95 my %mapping_period = (1 => 'oneSec', 2 => 'fiveSec', 3 => 'oneMin', 4 => 'tenMin', 5 => 'twoHour');
96
97 my $mapping = {
98 raisecomCPUUtilizationPeriod => { oid => '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.2', map => \%mapping_period },
99 raisecomCPUUtilization => { oid => '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1.3' }
100 };
101 my $mapping_pon = {
102 rcCpuUsage1Second => { oid => '.1.3.6.1.4.1.8886.18.1.7.1.1.1.3' },
103 rcCpuUsage10Minutes => { oid => '.1.3.6.1.4.1.8886.18.1.7.1.1.1.4' },
104 rcCpuUsage2Hours => { oid => '.1.3.6.1.4.1.8886.18.1.7.1.1.1.5' }
105 };
106
107 my $oid_raisecomCPUUtilizationEntry = '.1.3.6.1.4.1.8886.1.1.1.5.1.1.1';
108 my $oid_pon_raisecomCPUUtilizationEntry = '.1.3.6.1.4.1.8886.18.1.7.1.1.1';
109
110 sub manage_selection {
111 my ($self, %options) = @_;
112
113 my $snmp_result = $options{snmp}->get_table(oid => $oid_raisecomCPUUtilizationEntry, nothing_quit => 0);
114
115 $self->{cpu} = {};
116 if (scalar(keys %{$snmp_result}) <= 0) {
117 my $result = $options{snmp}->get_table(oid => $oid_pon_raisecomCPUUtilizationEntry, nothing_quit => 1);
118 foreach my $oid (keys %{$result}) {
119 next if ($oid !~ /^$mapping_pon->{rcCpuUsage1Second}->{oid}\.(.*)\.(.*)$/);
120 my $instance = $1;
121 my $mapping_result = $options{snmp}->map_instance(mapping => $mapping_pon, results => $result, instance => $instance . '.' . 0);
122 $self->{cpu}->{$instance} = {
123 oneSec => $mapping_result->{rcCpuUsage1Second},
124 tenMin => $mapping_result->{rcCpuUsage10Minutes},
125 twoHour => $mapping_result->{rcCpuUsage2Hours}
126 };
127 }
128 } else {
129 $self->{cpu} = { 0 => {} };
130
131 foreach my $oid (keys %{$snmp_result}) {
132 next if ($oid !~ /^$mapping->{raisecomCPUUtilization}->{oid}\.(.*)$/);
133 my $instance = $1;
134 my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
135
136 $self->{cpu}->{0}->{ $result->{raisecomCPUUtilizationPeriod} } = $result->{raisecomCPUUtilization};
137 }
138 };
139 }
140
141 1;
142
143 __END__
144
145 =head1 MODE
146
147 Check CPU usage.
148
149 =over 8
150
151 =item B<--filter-counters>
152
153 Only display some counters (regexp can be used).
154 Example: --filter-counters='^(1s|1m)$'
155
156 =item B<--warning-*>
157
158 Warning threshold.
159 Can be: '1s', '5s', '1m', '10m', '2h' for standard Raisecom devices.
160
161 Can be: '1s', '10m', '2h' for xPON Raisecom devices.
162
163 =item B<--critical-*>
164
165 Critical threshold.
166 Can be: '1s', '5s', '1m', '10m', '2h'.
167
168 Can be: '1s', '10m', '2h' for xPON Raisecom devices.
169
170 =back
171
172 =cut