| 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::nortel::standard::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_value}->{num} . "' 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 usages are ok', skipped_code => { -10 => 1 } } |
| 39 |
]; |
| 40 |
|
| 41 |
$self->{maps_counters}->{cpu} = [ |
| 42 |
{ label => 'total', nlabel => 'cpu.utilization.total.percentage', set => { |
| 43 |
key_values => [ { name => 'total' }, { name => 'num' } ], |
| 44 |
output_template => '%.2f %% (total)', |
| 45 |
perfdatas => [ |
| 46 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 47 |
] |
| 48 |
} |
| 49 |
}, |
| 50 |
{ label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => { |
| 51 |
key_values => [ { name => '1m' }, { name => 'num' } ], |
| 52 |
output_template => '%.2f %% (1min)', |
| 53 |
perfdatas => [ |
| 54 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 55 |
] |
| 56 |
} |
| 57 |
}, |
| 58 |
{ label => '5m', nlabel => 'cpu.utilization.5m.percentage', set => { |
| 59 |
key_values => [ { name => '5m' }, { name => 'num' } ], |
| 60 |
output_template => '%.2f %% (5min)', |
| 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 => '10m' }, { name => 'num' } ], |
| 68 |
output_template => '%.2f %% (10min)', |
| 69 |
perfdatas => [ |
| 70 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 } |
| 71 |
] |
| 72 |
} |
| 73 |
}, |
| 74 |
{ label => '1h', nlabel => 'cpu.utilization.1h.percentage', set => { |
| 75 |
key_values => [ { name => '1h' }, { name => 'num' } ], |
| 76 |
output_template => '%.2f %% (1h)', |
| 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 |
|
| 93 |
return $self; |
| 94 |
} |
| 95 |
|
| 96 |
my $mapping = { |
| 97 |
s5ChasUtilTotalCPUUsage => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.4' }, |
| 98 |
s5ChasUtilCPUUsageLast1Minute => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.5' }, |
| 99 |
s5ChasUtilCPUUsageLast10Minutes => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.6' }, |
| 100 |
s5ChasUtilCPUUsageLast1Hour => { oid => '.1.3.6.1.4.1.45.1.6.3.8.1.1.7' } |
| 101 |
}; |
| 102 |
|
| 103 |
my $oid_rcSysCpuUtil = '.1.3.6.1.4.1.2272.1.1.20'; # without .0 |
| 104 |
my $oid_s5ChasUtilEntry = '.1.3.6.1.4.1.45.1.6.3.8.1.1'; |
| 105 |
|
| 106 |
sub check_khi { |
| 107 |
my ($self, %options) = @_; |
| 108 |
|
| 109 |
my $oid_rcKhiSlotCpu5MinAve = '.1.3.6.1.4.1.2272.1.85.10.1.1.3'; |
| 110 |
my $snmp_result = $options{snmp}->get_table( |
| 111 |
oid => $oid_rcKhiSlotCpu5MinAve, |
| 112 |
nothing_quit => 1 |
| 113 |
); |
| 114 |
|
| 115 |
foreach (keys %$snmp_result) { |
| 116 |
/.(\d+)$/; |
| 117 |
|
| 118 |
$self->{cpu}->{'slot_' . $1} = { |
| 119 |
num => 'slot_' . $1, |
| 120 |
'5m' => $snmp_result->{$_} |
| 121 |
}; |
| 122 |
} |
| 123 |
} |
| 124 |
|
| 125 |
sub manage_selection { |
| 126 |
my ($self, %options) = @_; |
| 127 |
|
| 128 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 129 |
oids => [ |
| 130 |
{ oid => $oid_rcSysCpuUtil }, |
| 131 |
{ |
| 132 |
oid => $oid_s5ChasUtilEntry, |
| 133 |
start => $mapping->{s5ChasUtilCPUUsageLast1Minute}->{oid}, |
| 134 |
end => $mapping->{s5ChasUtilCPUUsageLast1Hour}->{oid} |
| 135 |
} |
| 136 |
] |
| 137 |
); |
| 138 |
|
| 139 |
$self->{cpu} = {}; |
| 140 |
foreach my $oid (keys %{$snmp_result->{$oid_s5ChasUtilEntry}}) { |
| 141 |
next if ($oid !~ /^$mapping->{s5ChasUtilCPUUsageLast1Minute}->{oid}\.(.*)$/); |
| 142 |
my $instance = $1; |
| 143 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_s5ChasUtilEntry}, instance => $instance); |
| 144 |
|
| 145 |
$self->{cpu}->{$instance} = { |
| 146 |
num => $instance, |
| 147 |
total => $result->{s5ChasUtilTotalCPUUsage}, |
| 148 |
'1m' => $result->{s5ChasUtilCPUUsageLast1Minute}, |
| 149 |
'10m' => $result->{s5ChasUtilCPUUsageLast10Minutes}, |
| 150 |
'1h' => $result->{s5ChasUtilCPUUsageLast1Hour} |
| 151 |
}; |
| 152 |
} |
| 153 |
|
| 154 |
if (scalar(keys %{$snmp_result->{$oid_rcSysCpuUtil}}) > 0) { |
| 155 |
$self->{cpu}->{0} = { num => 0, total => $snmp_result->{$oid_rcSysCpuUtil}->{$oid_rcSysCpuUtil . '.0'} }; |
| 156 |
} |
| 157 |
|
| 158 |
if (scalar(keys %{$self->{cpu}}) <= 0) { |
| 159 |
$self->check_khi(snmp => $options{snmp}); |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
1; |
| 164 |
|
| 165 |
__END__ |
| 166 |
|
| 167 |
=head1 MODE |
| 168 |
|
| 169 |
Check CPU usages. |
| 170 |
|
| 171 |
=over 8 |
| 172 |
|
| 173 |
=item B<--filter-counters> |
| 174 |
|
| 175 |
Only display some counters (regexp can be used). |
| 176 |
Example: --filter-counters='1m|10m' |
| 177 |
|
| 178 |
=item B<--warning-*> B<--critical-*> |
| 179 |
|
| 180 |
Thresholds. |
| 181 |
Can be: 'total', '1m', '5m', '10m', '1h'. |
| 182 |
|
| 183 |
=back |
| 184 |
|
| 185 |
=cut |