Debian Codegraph @

src/network/alcatel/omniswitch/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::alcatel::omniswitch::snmp::mode::cpu;
22
23 use base qw(centreon::plugins::mode);
24
25 use strict;
26 use warnings;
27
28 sub new {
29 my ($class, %options) = @_;
30 my $self = $class->SUPER::new(package => __PACKAGE__, %options);
31 bless $self, $class;
32
33 $options{options}->add_options(arguments => {
34 "warning:s" => { name => 'warning', default => '' },
35 "critical:s" => { name => 'critical', default => '' },
36 });
37
38 return $self;
39 }
40
41 sub check_options {
42 my ($self, %options) = @_;
43 $self->SUPER::init(%options);
44
45 ($self->{warn1m}, $self->{warn1h}) = split /,/, $self->{option_results}->{warning};
46 ($self->{crit1m}, $self->{crit1h}) = split /,/, $self->{option_results}->{critical};
47
48 if (($self->{perfdata}->threshold_validate(label => 'warn1m', value => $self->{warn1m})) == 0) {
49 $self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1m} . "'.");
50 $self->{output}->option_exit();
51 }
52 if (($self->{perfdata}->threshold_validate(label => 'warn1h', value => $self->{warn1h})) == 0) {
53 $self->{output}->add_option_msg(short_msg => "Wrong warning (1hour) threshold '" . $self->{warn1h} . "'.");
54 $self->{output}->option_exit();
55 }
56 if (($self->{perfdata}->threshold_validate(label => 'crit1m', value => $self->{crit1m})) == 0) {
57 $self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1m} . "'.");
58 $self->{output}->option_exit();
59 }
60 if (($self->{perfdata}->threshold_validate(label => 'crit1h', value => $self->{crit1h})) == 0) {
61 $self->{output}->add_option_msg(short_msg => "Wrong critical (1hour) threshold '" . $self->{crit1h} . "'.");
62 $self->{output}->option_exit();
63 }
64 }
65
66 sub check_cpu {
67 my ($self, %options) = @_;
68
69 my $exit1 = $self->{perfdata}->threshold_check(
70 value => $options{'1min'},
71 threshold => [
72 { label => 'crit1m', exit_litteral => 'critical' },
73 { label => 'warn1m', exit_litteral => 'warning' },
74 ]
75 );
76 my $exit2 = $self->{perfdata}->threshold_check(
77 value => $options{'1hour'},
78 threshold => [
79 { label => 'crit1h', exit_litteral => 'critical' },
80 { label => 'warn1h', exit_litteral => 'warning' },
81 ]
82 );
83
84 my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
85
86 $self->{output}->output_add(
87 severity => $exit,
88 short_msg => sprintf("%s: %.2f%% (1min), %.2f%% (1hour)", $options{name}, $options{'1min'}, $options{'1hour'})
89 );
90
91 $self->{output}->perfdata_add(
92 label => "cpu1m" . $options{perf_label} , unit => '%',
93 value => $options{'1min'},
94 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1m'),
95 critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1m'),
96 min => 0, max => 100
97 );
98 $self->{output}->perfdata_add(
99 label => "cpu1h" . $options{perf_label} , unit => '%',
100 value => $options{'1hour'},
101 warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1h'),
102 critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1h'),
103 min => 0, max => 100
104 );
105 }
106
107 sub run {
108 my ($self, %options) = @_;
109
110 my $mapping = {
111 aos6 => {
112 entry_device => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1',
113 entry_module => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1',
114 device => {
115 healthDeviceCpu1MinAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.14' },
116 healthDeviceCpu1HrAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.1.15' }
117 },
118 module => {
119 healthModuleCpu1MinAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1.15' },
120 healthModuleCpu1HrAvg => { oid => '.1.3.6.1.4.1.6486.800.1.2.1.16.1.1.2.1.1.16' }
121 }
122 },
123 aos7 => {
124 entry_module => '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1',
125 module => {
126 healthModuleCpu1MinAvg => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1.11' },
127 healthModuleCpu1HrAvg => { oid => '.1.3.6.1.4.1.6486.801.1.2.1.16.1.1.1.1.1.12' }
128 }
129 }
130 };
131
132 my $snmp_result = $options{snmp}->get_multiple_table(oids => [
133 { oid => $mapping->{aos6}->{entry_device}, start => $mapping->{aos6}->{device}->{healthDeviceCpu1MinAvg}->{oid}, end => $mapping->{aos6}->{device}->{healthDeviceCpu1HrAvg}->{oid} },
134 { oid => $mapping->{aos6}->{entry_module}, start => $mapping->{aos6}->{module}->{healthModuleCpu1MinAvg}->{oid}, end => $mapping->{aos6}->{module}->{healthModuleCpu1HrAvg}->{oid} },
135 { oid => $mapping->{aos7}->{entry_module}, start => $mapping->{aos7}->{module}->{healthModuleCpu1MinAvg}->{oid}, end => $mapping->{aos7}->{module}->{healthModuleCpu1HrAvg}->{oid} },
136 ], nothing_quit => 1);
137
138 my $type = 'aos6';
139 if (scalar(keys %{$snmp_result->{ $mapping->{aos7}->{entry_module} }}) > 0) {
140 $type = 'aos7';
141 }
142
143 if (defined($mapping->{$type}->{device})) {
144 my $result = $options{snmp}->map_instance(mapping => $mapping->{$type}->{device}, results => $snmp_result->{ $mapping->{$type}->{entry_device} }, instance => '0');
145 $self->check_cpu(
146 name => 'Device cpu',
147 perf_label => '_device',
148 '1min' => $result->{healthDeviceCpu1MinAvg},
149 '1hour' => $result->{healthDeviceCpu1HrAvg}
150 );
151 }
152
153 foreach my $oid ($options{snmp}->oid_lex_sort(keys %{$snmp_result->{ $mapping->{$type}->{entry_module} }})) {
154 next if ($oid !~ /^$mapping->{$type}->{module}->{healthModuleCpu1MinAvg}->{oid}\.(.*)$/);
155 my $result = $options{snmp}->map_instance(mapping => $mapping->{$type}->{module}, results => $snmp_result->{ $mapping->{$type}->{entry_module} }, instance => $1);
156
157 $self->check_cpu(
158 name => "Module cpu '$1'",
159 perf_label => "_module_$1",
160 '1min' => $result->{healthModuleCpu1MinAvg},
161 '1hour' => $result->{healthModuleCpu1HrAvg}
162 );
163 }
164
165 $self->{output}->display();
166 $self->{output}->exit();
167 }
168
169 1;
170
171 __END__
172
173 =head1 MODE
174
175 Check CPU usage (AlcatelIND1Health.mib).
176
177 =over 8
178
179 =item B<--warning>
180
181 Warning threshold in percent (1m,1h).
182
183 =item B<--critical>
184
185 Critical threshold in percent (1m,1h).
186
187 =back
188
189 =cut
190