| 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::ingrian::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 => 'global', type => 0, cb_init => 'skip_global', }, |
| 33 |
{ name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' } |
| 34 |
]; |
| 35 |
$self->{maps_counters}->{global} = [ |
| 36 |
{ label => 'total', set => { |
| 37 |
key_values => [ { name => 'total' } ], |
| 38 |
output_template => 'Total CPU Usage : %.2f %%', |
| 39 |
perfdatas => [ |
| 40 |
{ label => 'total_cpu_avg', value => 'total', template => '%.2f', min => 0, max => 100, unit => '%' }, |
| 41 |
], |
| 42 |
} |
| 43 |
}, |
| 44 |
]; |
| 45 |
|
| 46 |
$self->{maps_counters}->{cpu} = [ |
| 47 |
{ label => 'usage', set => { |
| 48 |
key_values => [ { name => 'usage' }, { name => 'display' }, ], |
| 49 |
output_template => 'Usage : %.2f %%', |
| 50 |
perfdatas => [ |
| 51 |
{ label => 'cpu', value => 'usage', template => '%.2f', |
| 52 |
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }, |
| 53 |
], |
| 54 |
} |
| 55 |
}, |
| 56 |
]; |
| 57 |
} |
| 58 |
|
| 59 |
sub skip_global { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
scalar(keys %{$self->{cpu}}) > 1 ? return(0) : return(1); |
| 63 |
} |
| 64 |
|
| 65 |
sub prefix_cpu_output { |
| 66 |
my ($self, %options) = @_; |
| 67 |
|
| 68 |
return "CPU '" . $options{instance_value}->{display} . "' "; |
| 69 |
} |
| 70 |
|
| 71 |
sub new { |
| 72 |
my ($class, %options) = @_; |
| 73 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 74 |
bless $self, $class; |
| 75 |
|
| 76 |
$options{options}->add_options(arguments => |
| 77 |
{ |
| 78 |
}); |
| 79 |
|
| 80 |
return $self; |
| 81 |
} |
| 82 |
|
| 83 |
my $mapping = { |
| 84 |
naeSystemCPUDescr => { oid => '.1.3.6.1.4.1.5595.3.2.4.1.2' }, |
| 85 |
naeSystemCPUUtilization => { oid => '.1.3.6.1.4.1.5595.3.2.4.1.3' }, |
| 86 |
}; |
| 87 |
|
| 88 |
sub manage_selection { |
| 89 |
my ($self, %options) = @_; |
| 90 |
|
| 91 |
my $oid_naeSystemStatCPUEntry = '.1.3.6.1.4.1.5595.3.2.4.1'; |
| 92 |
my $oid_naeSystemStatCPU = '.1.3.6.1.4.1.5595.3.2.2'; # without .0 |
| 93 |
my $snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 94 |
{ oid => $oid_naeSystemStatCPU }, |
| 95 |
{ oid => $oid_naeSystemStatCPUEntry }, |
| 96 |
], nothing_quit => 1); |
| 97 |
|
| 98 |
$self->{cpu} = {}; |
| 99 |
foreach my $oid (keys %{$snmp_result->{$oid_naeSystemStatCPUEntry}}) { |
| 100 |
next if ($oid !~ /^$mapping->{naeSystemCPUUtilization}->{oid}\.(.*)$/); |
| 101 |
my $instance = $1; |
| 102 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_naeSystemStatCPUEntry}, instance => $instance); |
| 103 |
|
| 104 |
$self->{cpu}->{$instance} = { display => $instance - 1, usage => $result->{naeSystemCPUUtilization} }; |
| 105 |
} |
| 106 |
|
| 107 |
$self->{global} = { total => $snmp_result->{$oid_naeSystemStatCPU}->{$oid_naeSystemStatCPU . '.0'} }; |
| 108 |
} |
| 109 |
|
| 110 |
1; |
| 111 |
|
| 112 |
__END__ |
| 113 |
|
| 114 |
=head1 MODE |
| 115 |
|
| 116 |
Check CPU usages. |
| 117 |
|
| 118 |
=over 8 |
| 119 |
|
| 120 |
=item B<--filter-counters> |
| 121 |
|
| 122 |
Only display some counters (regexp can be used). |
| 123 |
Example: --filter-counters='^total$' |
| 124 |
|
| 125 |
=item B<--warning-*> |
| 126 |
|
| 127 |
Warning threshold. |
| 128 |
Can be: 'total', 'usage'. |
| 129 |
|
| 130 |
=item B<--critical-*> |
| 131 |
|
| 132 |
Critical threshold. |
| 133 |
Can be: 'total', 'usage'. |
| 134 |
|
| 135 |
=back |
| 136 |
|
| 137 |
=cut |