| 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::dlink::dgs3100::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 |
{ |
| 35 |
"warning:s" => { name => 'warning', default => '' }, |
| 36 |
"critical:s" => { name => 'critical', default => '' }, |
| 37 |
}); |
| 38 |
|
| 39 |
return $self; |
| 40 |
} |
| 41 |
|
| 42 |
sub check_options { |
| 43 |
my ($self, %options) = @_; |
| 44 |
$self->SUPER::init(%options); |
| 45 |
|
| 46 |
($self->{warn1s}, $self->{warn1m}, $self->{warn5m}) = split /,/, $self->{option_results}->{warning}; |
| 47 |
($self->{crit1s}, $self->{crit1m}, $self->{crit5m}) = split /,/, $self->{option_results}->{critical}; |
| 48 |
|
| 49 |
if (($self->{perfdata}->threshold_validate(label => 'warn1s', value => $self->{warn1s})) == 0) { |
| 50 |
$self->{output}->add_option_msg(short_msg => "Wrong warning (1sec) threshold '" . $self->{warn1s} . "'."); |
| 51 |
$self->{output}->option_exit(); |
| 52 |
} |
| 53 |
if (($self->{perfdata}->threshold_validate(label => 'warn1m', value => $self->{warn1m})) == 0) { |
| 54 |
$self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1m} . "'."); |
| 55 |
$self->{output}->option_exit(); |
| 56 |
} |
| 57 |
if (($self->{perfdata}->threshold_validate(label => 'warn5m', value => $self->{warn5m})) == 0) { |
| 58 |
$self->{output}->add_option_msg(short_msg => "Wrong warning (5min) threshold '" . $self->{warn5m} . "'."); |
| 59 |
$self->{output}->option_exit(); |
| 60 |
} |
| 61 |
if (($self->{perfdata}->threshold_validate(label => 'crit1s', value => $self->{crit1s})) == 0) { |
| 62 |
$self->{output}->add_option_msg(short_msg => "Wrong critical (1sec) threshold '" . $self->{crit1s} . "'."); |
| 63 |
$self->{output}->option_exit(); |
| 64 |
} |
| 65 |
if (($self->{perfdata}->threshold_validate(label => 'crit1m', value => $self->{crit1m})) == 0) { |
| 66 |
$self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1m} . "'."); |
| 67 |
$self->{output}->option_exit(); |
| 68 |
} |
| 69 |
if (($self->{perfdata}->threshold_validate(label => 'crit5m', value => $self->{crit5})) == 0) { |
| 70 |
$self->{output}->add_option_msg(short_msg => "Wrong critical (5min) threshold '" . $self->{crit5m} . "'."); |
| 71 |
$self->{output}->option_exit(); |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
sub run { |
| 76 |
my ($self, %options) = @_; |
| 77 |
$self->{snmp} = $options{snmp}; |
| 78 |
|
| 79 |
my $oid_rlCpuUtilEnable = '.1.3.6.1.4.1.171.10.94.89.89.1.6.0'; |
| 80 |
my $oid_rlCpuUtilDuringLastSecond = '.1.3.6.1.4.1.171.10.94.89.89.1.7.0'; |
| 81 |
my $oid_rlCpuUtilDuringLastMinute = '.1.3.6.1.4.1.171.10.94.89.89.1.8.0'; |
| 82 |
my $oid_rlCpuUtilDuringLast5Minutes = '.1.3.6.1.4.1.171.10.94.89.89.1.9.0'; |
| 83 |
|
| 84 |
$self->{result} = $self->{snmp}->get_leef(oids => [ $oid_rlCpuUtilEnable, $oid_rlCpuUtilDuringLastSecond, $oid_rlCpuUtilDuringLastMinute, $oid_rlCpuUtilDuringLast5Minutes ], |
| 85 |
nothing_quit => 1); |
| 86 |
|
| 87 |
if (defined($self->{result}->{$oid_rlCpuUtilEnable}) && $self->{result}->{$oid_rlCpuUtilEnable} == 1) { |
| 88 |
my $cpu1sec = $self->{result}->{$oid_rlCpuUtilDuringLastSecond}; |
| 89 |
my $cpu1min = $self->{result}->{$oid_rlCpuUtilDuringLastMinute}; |
| 90 |
my $cpu5min = $self->{result}->{$oid_rlCpuUtilDuringLast5Minutes}; |
| 91 |
|
| 92 |
my $exit1 = $self->{perfdata}->threshold_check(value => $cpu1sec, |
| 93 |
threshold => [ { label => 'crit1s', exit_litteral => 'critical' }, { label => 'warn1s', exit_litteral => 'warning' } ]); |
| 94 |
my $exit2 = $self->{perfdata}->threshold_check(value => $cpu1min, |
| 95 |
threshold => [ { label => 'crit1m', exit_litteral => 'critical' }, { label => 'warn1m', exit_litteral => 'warning' } ]); |
| 96 |
my $exit3 = $self->{perfdata}->threshold_check(value => $cpu5min, |
| 97 |
threshold => [ { label => 'crit5m', exit_litteral => 'critical' }, { label => 'warn5m', exit_litteral => 'warning' } ]); |
| 98 |
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); |
| 99 |
|
| 100 |
$self->{output}->output_add(severity => $exit, |
| 101 |
short_msg => sprintf("CPU Usage: %.2f%% (1sec), %.2f%% (1min), %.2f%% (5min)", |
| 102 |
$cpu1sec, $cpu1min, $cpu5min)); |
| 103 |
|
| 104 |
$self->{output}->perfdata_add(label => "cpu_1s", unit => '%', |
| 105 |
value => $cpu1sec, |
| 106 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1s'), |
| 107 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1s'), |
| 108 |
min => 0, max => 100); |
| 109 |
$self->{output}->perfdata_add(label => "cpu_1m", unit => '%', |
| 110 |
value => $cpu1min, |
| 111 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1m'), |
| 112 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1m'), |
| 113 |
min => 0, max => 100); |
| 114 |
$self->{output}->perfdata_add(label => "cpu_5m", unit => '%', |
| 115 |
value => $cpu5min, |
| 116 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5m'), |
| 117 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5m'), |
| 118 |
min => 0, max => 100); |
| 119 |
} else { |
| 120 |
$self->{output}->output_add(severity => 'UNKNOWN', |
| 121 |
short_msg => sprintf("CPU measurement is not enabled.")); |
| 122 |
} |
| 123 |
|
| 124 |
$self->{output}->display(); |
| 125 |
$self->{output}->exit(); |
| 126 |
} |
| 127 |
|
| 128 |
1; |
| 129 |
|
| 130 |
__END__ |
| 131 |
|
| 132 |
=head1 MODE |
| 133 |
|
| 134 |
Check CPU usage (env_mib.mib). |
| 135 |
|
| 136 |
=over 8 |
| 137 |
|
| 138 |
=item B<--warning> |
| 139 |
|
| 140 |
Warning threshold in percent (1s,1min,5min). |
| 141 |
|
| 142 |
=item B<--critical> |
| 143 |
|
| 144 |
Critical threshold in percent (1s,1min,5min). |
| 145 |
|
| 146 |
=back |
| 147 |
|
| 148 |
=cut |