| 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::force10::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}->{display} . "' 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 => '5s', nlabel => 'cpu.utilization.5s.percentage', set => { |
| 43 |
key_values => [ { name => 'cpu_5s' }, { name => 'display' } ], |
| 44 |
output_template => '%.2f %% (5s)', |
| 45 |
perfdatas => [ |
| 46 |
{ label => 'cpu_5s', template => '%.2f', |
| 47 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 48 |
] |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => '1m', nlabel => 'cpu.utilization.1m.percentage', set => { |
| 52 |
key_values => [ { name => 'cpu_1m' }, { name => 'display' } ], |
| 53 |
output_template => '%.2f %% (1m)', |
| 54 |
perfdatas => [ |
| 55 |
{ label => 'cpu_1m', template => '%.2f', |
| 56 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 57 |
] |
| 58 |
} |
| 59 |
}, |
| 60 |
{ label => '5m', nlabel => 'cpu.utilization.5m.percentage', set => { |
| 61 |
key_values => [ { name => 'cpu_5m' }, { name => 'display' } ], |
| 62 |
output_template => '%.2f %% (5m)', |
| 63 |
perfdatas => [ |
| 64 |
{ label => 'cpu_5m', template => '%.2f', |
| 65 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 66 |
] |
| 67 |
} |
| 68 |
} |
| 69 |
]; |
| 70 |
} |
| 71 |
|
| 72 |
sub new { |
| 73 |
my ($class, %options) = @_; |
| 74 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 75 |
bless $self, $class; |
| 76 |
|
| 77 |
$options{options}->add_options(arguments => { |
| 78 |
}); |
| 79 |
|
| 80 |
return $self; |
| 81 |
} |
| 82 |
|
| 83 |
my $mapping = { |
| 84 |
sseries => { |
| 85 |
cpu_5s => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.2' }, # chStackUnitCpuUtil5Sec |
| 86 |
cpu_1m => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.3' }, # chStackUnitCpuUtil1Min |
| 87 |
cpu_5m => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1.4' } # chStackUnitCpuUtil5Min |
| 88 |
}, |
| 89 |
mseries => { |
| 90 |
cpu_5s => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.2' }, # chStackUnitCpuUtil5Sec |
| 91 |
cpu_1m => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.3' }, # chStackUnitCpuUtil1Min |
| 92 |
cpu_5m => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1.4' } # chStackUnitCpuUtil5Min |
| 93 |
}, |
| 94 |
zseries => { |
| 95 |
cpu_5s => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.1' }, # chSysCpuUtil5Sec |
| 96 |
cpu_1m => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.2' }, # chSysCpuUtil1Min |
| 97 |
cpu_5m => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1.3' } # chSysCpuUtil5Min |
| 98 |
}, |
| 99 |
os9 => { |
| 100 |
cpu_5s => { oid => '.1.3.6.1.4.1.6027.3.26.1.4.4.1.1' }, # dellNetCpuUtil5Sec |
| 101 |
cpu_1m => { oid => '.1.3.6.1.4.1.6027.3.26.1.4.4.1.4' }, # dellNetCpuUtil1Min |
| 102 |
cpu_5m => { oid => '.1.3.6.1.4.1.6027.3.26.1.4.4.1.5' } # dellNetCpuUtil5Min |
| 103 |
} |
| 104 |
}; |
| 105 |
my $map_device_type = { |
| 106 |
1 => 'chassis', 2 => 'stack', 3 => 'rpm', 4 => 'supervisor', 5 => 'linecard', 6 => 'port-extender' |
| 107 |
}; |
| 108 |
|
| 109 |
sub load_series { |
| 110 |
my ($self, %options) = @_; |
| 111 |
|
| 112 |
foreach my $oid (keys %{$options{snmp_result}}) { |
| 113 |
next if ($oid !~ /^$mapping->{ $options{name} }->{cpu_5m}->{oid}\.(.*)/); |
| 114 |
my $instance = $1; |
| 115 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{ $options{name} }, results => $options{snmp_result}, instance => $instance); |
| 116 |
|
| 117 |
$self->{cpu}->{$instance} = { |
| 118 |
display => $instance, |
| 119 |
%$result |
| 120 |
}; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
sub load_os9 { |
| 125 |
my ($self, %options) = @_; |
| 126 |
|
| 127 |
foreach my $oid (keys %{$options{snmp_result}}) { |
| 128 |
next if ($oid !~ /^$mapping->{ $options{name} }->{cpu_5m}->{oid}\.(\d+)\.(\d+)\.(\d+)/); |
| 129 |
my $name = $map_device_type->{$1} . ':' . $2 . ':' . $3; |
| 130 |
my $result = $options{snmp}->map_instance(mapping => $mapping->{ $options{name} }, results => $options{snmp_result}, instance => $1 . '.' . $2 . '.' . $3); |
| 131 |
|
| 132 |
$self->{cpu}->{$name} = { |
| 133 |
display => $name, |
| 134 |
%$result |
| 135 |
}; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
sub manage_selection { |
| 140 |
my ($self, %options) = @_; |
| 141 |
|
| 142 |
my $oids = { |
| 143 |
sseries => { oid => '.1.3.6.1.4.1.6027.3.10.1.2.9.1', load => $self->can('load_series') }, |
| 144 |
mseries => { oid => '.1.3.6.1.4.1.6027.3.19.1.2.8.1', load => $self->can('load_series') }, |
| 145 |
zseries => { oid => '.1.3.6.1.4.1.6027.3.25.1.2.3.1', load => $self->can('load_series') }, |
| 146 |
os9 => { oid => '.1.3.6.1.4.1.6027.3.26.1.4.4.1', load => $self->can('load_os9') } |
| 147 |
}; |
| 148 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 149 |
oids => [ |
| 150 |
{ oid => $oids->{sseries}->{oid}, start => $mapping->{sseries}->{cpu_5s}->{oid}, end => $mapping->{sseries}->{cpu_5m}->{oid} }, |
| 151 |
{ oid => $oids->{mseries}->{oid}, start => $mapping->{mseries}->{cpu_5s}->{oid}, end => $mapping->{mseries}->{cpu_5m}->{oid} }, |
| 152 |
{ oid => $oids->{zseries}->{oid}, end => $mapping->{zseries}->{cpu_5m}->{oid} }, |
| 153 |
{ oid => $oids->{os9}->{oid}, end => $mapping->{os9}->{cpu_5m}->{oid} } |
| 154 |
], |
| 155 |
nothing_quit => 1 |
| 156 |
); |
| 157 |
|
| 158 |
$self->{cpu} = {}; |
| 159 |
foreach my $name (keys %$oids) { |
| 160 |
$oids->{$name}->{load}->( |
| 161 |
$self, |
| 162 |
name => $name, |
| 163 |
snmp => $options{snmp}, |
| 164 |
snmp_result => $snmp_result->{ $oids->{$name}->{oid} } |
| 165 |
); |
| 166 |
} |
| 167 |
|
| 168 |
if (scalar(keys %{$self->{cpu}}) <= 0) { |
| 169 |
$self->{output}->add_option_msg(short_msg => "No entry found."); |
| 170 |
$self->{output}->option_exit(); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
1; |
| 175 |
|
| 176 |
__END__ |
| 177 |
|
| 178 |
=head1 MODE |
| 179 |
|
| 180 |
Check CPU usage. |
| 181 |
|
| 182 |
=over 8 |
| 183 |
|
| 184 |
=item B<--warning-*> |
| 185 |
|
| 186 |
Warning threshold. |
| 187 |
Can be: '5s', '1m', '5m'. |
| 188 |
|
| 189 |
=item B<--critical-*> |
| 190 |
|
| 191 |
Critical threshold. |
| 192 |
Can be: '5s', '1m', '5m'. |
| 193 |
|
| 194 |
=back |
| 195 |
|
| 196 |
=cut |