(snmp) cpu standard mode add option --use-ucd (#3943)

This commit is contained in:
qgarnier 2022-09-29 16:55:15 +02:00 committed by GitHub
parent ab788c2404
commit b539ee729f
1 changed files with 38 additions and 22 deletions

View File

@ -25,6 +25,21 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_cpu_avg_output {
my ($self, %options) = @_;
if ($self->{cpu_avg}->{count} > 0) {
return $self->{cpu_avg}->{count} . ' CPU(s) average usage is ';
}
return 'CPU(s) average usage is ';
}
sub prefix_cpu_core_output {
my ($self, %options) = @_;
return "CPU '" . $options{instance_value}->{display} . "' ";
}
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
@ -38,11 +53,10 @@ sub set_counters {
key_values => [ { name => 'average' }, { name => 'count' } ], key_values => [ { name => 'average' }, { name => 'count' } ],
output_template => '%.2f %%', output_template => '%.2f %%',
perfdatas => [ perfdatas => [
{ label => 'total_cpu_avg', value => 'average', template => '%.2f', { label => 'total_cpu_avg', template => '%.2f', min => 0, max => 100, unit => '%' }
min => 0, max => 100, unit => '%' }, ]
], }
} }
},
]; ];
$self->{maps_counters}->{cpu_core} = [ $self->{maps_counters}->{cpu_core} = [
@ -50,32 +64,20 @@ sub set_counters {
key_values => [ { name => 'cpu' }, { name => 'display' } ], key_values => [ { name => 'cpu' }, { name => 'display' } ],
output_template => 'usage : %.2f %%', output_template => 'usage : %.2f %%',
perfdatas => [ perfdatas => [
{ label => 'cpu', value => 'cpu', template => '%.2f', { label => 'cpu', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }
min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' }, ]
], }
} }
},
]; ];
} }
sub prefix_cpu_avg_output {
my ($self, %options) = @_;
return $self->{cpu_avg}->{count} . " CPU(s) average usage is ";
}
sub prefix_cpu_core_output {
my ($self, %options) = @_;
return "CPU '" . $options{instance_value}->{display} . "' ";
}
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'use-ucd' => { name => 'use_ucd' }
}); });
return $self; return $self;
@ -87,6 +89,16 @@ sub manage_selection {
$self->{cpu_avg} = {}; $self->{cpu_avg} = {};
$self->{cpu_core} = {}; $self->{cpu_core} = {};
if (defined($self->{option_results}->{use_ucd})) {
my $oid_ssCpuIdle = '.1.3.6.1.4.1.2021.11.11.0';
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_ssCpuIdle], nothing_quit => 1);
$self->{cpu_avg} = {
average => 100 - $snmp_result->{$oid_ssCpuIdle},
count => -1
};
return ;
}
my $oid_cputable = '.1.3.6.1.2.1.25.3.3.1.2'; my $oid_cputable = '.1.3.6.1.2.1.25.3.3.1.2';
my $result = $options{snmp}->get_table(oid => $oid_cputable, nothing_quit => 1); my $result = $options{snmp}->get_table(oid => $oid_cputable, nothing_quit => 1);
@ -118,12 +130,16 @@ __END__
=head1 MODE =head1 MODE
Check system CPUs (HOST-RESOURCES-MIB) Check system CPUs.
(The average, over the last minute, of the percentage (The average, over the last minute, of the percentage
of time that this processor was not idle) of time that this processor was not idle)
=over 8 =over 8
=item B<--use-ucd>
Use UCD mib for cpu average.
=item B<--warning-average> =item B<--warning-average>
Warning threshold average CPU utilization. Warning threshold average CPU utilization.