From 6e3f079a1655d3c0072a2c64d24c70fcfb86e287 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 12 Feb 2016 15:41:47 +0100 Subject: [PATCH] + Enhance cpu for cisco ironport --- network/cisco/ironport/snmp/mode/cpu.pm | 99 ++++++++++++------------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/network/cisco/ironport/snmp/mode/cpu.pm b/network/cisco/ironport/snmp/mode/cpu.pm index 78c3887e8..26f49cfa5 100644 --- a/network/cisco/ironport/snmp/mode/cpu.pm +++ b/network/cisco/ironport/snmp/mode/cpu.pm @@ -20,11 +20,39 @@ package network::cisco::ironport::snmp::mode::cpu; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'mail', set => { + key_values => [ { name => 'perCentCPUUtilization' } ], + output_template => 'CPU Mail usage is: %.2f%%', + perfdatas => [ + { label => 'cpu_mail', value => 'perCentCPUUtilization_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'websecurity', set => { + key_values => [ { name => 'cacheCpuUsage' } ], + output_template => 'CPU WebSecurity usage is: %.2f%%', + perfdatas => [ + { label => 'cpu_websecurity', value => 'cacheCpuUsage_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -32,62 +60,24 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + { }); return $self; } -sub check_options { +sub manage_selection { my ($self, %options) = @_; - $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); + my %oids = ( + perCentCPUUtilization => '.1.3.6.1.4.1.15497.1.1.1.2.0', + cacheCpuUsage => '.1.3.6.1.4.1.15497.1.2.3.1.2.0', + ); + my $result = $options{snmp}->get_leef(oids => [values %oids], nothing_quit => 1); + $self->{global} = {}; + foreach (keys %oids) { + $self->{global}->{$_} = $result->{$oids{$_}} if (defined($result->{$oids{$_}})); } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_perCentCPUUtilization = '.1.3.6.1.4.1.15497.1.1.1.2.0'; - my $oid_cacheCpuUsage = '.1.3.6.1.4.1.15497.1.2.3.1.2.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_perCentCPUUtilization, $oid_cacheCpuUsage], nothing_quit => 1); - - if (defined($result->{$oid_perCentCPUUtilization})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_perCentCPUUtilization}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("CPU Mail usage is: %.2f%%", $result->{$oid_perCentCPUUtilization})); - $self->{output}->perfdata_add(label => 'cpu_mail', unit => '%', - value => sprintf("%.2f", $result->{$oid_perCentCPUUtilization}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - } - if (defined($result->{$oid_cacheCpuUsage})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_cacheCpuUsage}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("CPU WebSecurity usage is: %.2f%%", $result->{$oid_cacheCpuUsage})); - $self->{output}->perfdata_add(label => 'cpu_websecurity', unit => '%', - value => sprintf("%.2f", $result->{$oid_cacheCpuUsage}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - } - - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -97,16 +87,19 @@ __END__ =head1 MODE Check cpu usage of web security and mail (ASYNCOS-MAIL-MIB, ASYNCOSWEBSECURITYAPPLIANCE-MIB). +Use linux SNMP plugin for global CPU. =over 8 -=item B<--warning> +=item B<--warning-*> -Threshold warning in percent. +Threshold warning. +Can be: 'mail', 'websecurity'. -=item B<--critical> +=item B<--critical-*> -Threshold critical in percent. +Threshold critical. +Can be: 'mail', 'websecurity'. =back