| 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 centreon::common::huawei::standard::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 => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' } |
| 33 |
]; |
| 34 |
|
| 35 |
$self->{maps_counters}->{cpu} = [ |
| 36 |
{ label => 'usage', set => { |
| 37 |
key_values => [ { name => 'cpu' }, { name => 'num' }, ], |
| 38 |
output_template => 'Usage : %.2f %%', |
| 39 |
perfdatas => [ |
| 40 |
{ label => 'cpu', value => 'cpu', template => '%.2f', |
| 41 |
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'num' }, |
| 42 |
], |
| 43 |
} |
| 44 |
}, |
| 45 |
]; |
| 46 |
} |
| 47 |
|
| 48 |
sub prefix_cpu_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return "CPU '" . $options{instance_value}->{num} . "' "; |
| 52 |
} |
| 53 |
|
| 54 |
sub new { |
| 55 |
my ($class, %options) = @_; |
| 56 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 57 |
bless $self, $class; |
| 58 |
|
| 59 |
$options{options}->add_options(arguments => {}); |
| 60 |
|
| 61 |
return $self; |
| 62 |
} |
| 63 |
|
| 64 |
my $oid_hwEntityCpuUsage = '.1.3.6.1.4.1.2011.5.25.31.1.1.1.1.5'; |
| 65 |
my $oid_hwAvgDuty5min = '.1.3.6.1.4.1.2011.6.3.4.1.4'; |
| 66 |
my $oid_hwResOccupancy = '.1.3.6.1.4.1.2011.6.3.17.1.1.3'; |
| 67 |
my $map_type = { 1 => 'memory', 2 => 'messageUnits', 3 => 'cpu' }; |
| 68 |
|
| 69 |
sub manage_selection { |
| 70 |
my ($self, %options) = @_; |
| 71 |
|
| 72 |
my $results = $options{snmp}->get_multiple_table(oids => [ |
| 73 |
{ oid => $oid_hwEntityCpuUsage }, |
| 74 |
{ oid => $oid_hwAvgDuty5min }, |
| 75 |
{ oid => $oid_hwResOccupancy }, |
| 76 |
], nothing_quit => 1); |
| 77 |
|
| 78 |
$self->{cpu} = {}; |
| 79 |
my $num = 1; |
| 80 |
if (defined($results->{$oid_hwAvgDuty5min}) && scalar(keys %{$results->{$oid_hwAvgDuty5min}}) > 0) { |
| 81 |
foreach (sort keys %{$results->{$oid_hwAvgDuty5min}}) { |
| 82 |
$self->{cpu}->{$num} = { num => $num, cpu => $results->{$oid_hwAvgDuty5min}->{$_} }; |
| 83 |
$num++; |
| 84 |
} |
| 85 |
} elsif (defined($results->{$oid_hwEntityCpuUsage}) && scalar(keys %{$results->{$oid_hwEntityCpuUsage}}) > 0) { |
| 86 |
foreach (sort keys %{$results->{$oid_hwEntityCpuUsage}}) { |
| 87 |
$self->{cpu}->{$num} = { num => $num, cpu => $results->{$oid_hwEntityCpuUsage}->{$_} }; |
| 88 |
$num++; |
| 89 |
} |
| 90 |
} else { |
| 91 |
foreach (sort keys %{$results->{$oid_hwResOccupancy}}) { |
| 92 |
/\.([0-9]*?)$/; |
| 93 |
next if (!defined($map_type->{$1}) || $map_type->{$1} ne 'cpu'); |
| 94 |
$self->{cpu}->{$num} = { num => $num, cpu => $results->{$oid_hwResOccupancy}->{$_} }; |
| 95 |
$num++; |
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
1; |
| 101 |
|
| 102 |
__END__ |
| 103 |
|
| 104 |
=head1 MODE |
| 105 |
|
| 106 |
Check CPU usages. |
| 107 |
|
| 108 |
=over 8 |
| 109 |
|
| 110 |
=item B<--warning-usage> |
| 111 |
|
| 112 |
Warning threshold. |
| 113 |
|
| 114 |
=item B<--critical-usage> |
| 115 |
|
| 116 |
Critical threshold. |
| 117 |
|
| 118 |
=back |
| 119 |
|
| 120 |
=cut |