From 6e433f98fb05aa55e0f0511b3f0642102b774278 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Thu, 16 Aug 2018 15:14:10 +0000 Subject: [PATCH] enh h3c hardware mode to allow count thresholds (#1080) * enh h3c hardware mode to allow count thresholds * + use ternary operator --- network/h3c/snmp/mode/components/default.pm | 8 +++--- network/h3c/snmp/mode/components/fan.pm | 4 ++- network/h3c/snmp/mode/components/psu.pm | 4 ++- network/h3c/snmp/mode/components/sensor.pm | 4 ++- network/h3c/snmp/mode/hardware.pm | 28 ++++++++++++++++++--- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/network/h3c/snmp/mode/components/default.pm b/network/h3c/snmp/mode/components/default.pm index 97eb6a7a4..ca0461a70 100644 --- a/network/h3c/snmp/mode/components/default.pm +++ b/network/h3c/snmp/mode/components/default.pm @@ -37,7 +37,7 @@ my %map_default_status = ( 33 => 'sfpBothError', 41 => 'fanError', 51 => 'psuError', - 61 => 'rpsError(', + 61 => 'rpsError', 71 => 'moduleFaulty', 81 => 'sensorError', 91 => 'hardwareFaulty', @@ -64,10 +64,12 @@ sub check { next; } - my $name = $self->get_long_name(instance => $instance); + my $name = ''; + $name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1); + $name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne ''); $self->{components}->{$options{component}}->{total}++; $self->{output}->output_add(long_msg => sprintf("%s '%s' status is '%s' [instance = %s]", - $options{component}, $name, $result->{EntityExtErrorStatus}, $instance)); + ucfirst($options{component}), $name, $result->{EntityExtErrorStatus}, $instance)); my $exit = $self->get_severity(section => $options{component}, value => $result->{EntityExtErrorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, diff --git a/network/h3c/snmp/mode/components/fan.pm b/network/h3c/snmp/mode/components/fan.pm index caf9dfc5c..408463b52 100644 --- a/network/h3c/snmp/mode/components/fan.pm +++ b/network/h3c/snmp/mode/components/fan.pm @@ -52,7 +52,9 @@ sub check { next; } - my $name = $self->get_long_name(instance => $instance); + my $name = ''; + $name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1); + $name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne ''); $self->{components}->{fan}->{total}++; $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is '%s' [instance = %s]", $name, $result->{EntityExtErrorStatus}, $instance)); diff --git a/network/h3c/snmp/mode/components/psu.pm b/network/h3c/snmp/mode/components/psu.pm index 3eb487aa1..e9605a9d5 100644 --- a/network/h3c/snmp/mode/components/psu.pm +++ b/network/h3c/snmp/mode/components/psu.pm @@ -52,7 +52,9 @@ sub check { next; } - my $name = $self->get_long_name(instance => $instance); + my $name = ''; + $name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1); + $name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne ''); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s' [instance = %s]", $name, $result->{EntityExtErrorStatus}, $instance)); diff --git a/network/h3c/snmp/mode/components/sensor.pm b/network/h3c/snmp/mode/components/sensor.pm index 60917ec5c..419d2041a 100644 --- a/network/h3c/snmp/mode/components/sensor.pm +++ b/network/h3c/snmp/mode/components/sensor.pm @@ -65,7 +65,9 @@ sub check { next; } - my $name = $self->get_long_name(instance => $instance); + my $name = ''; + $name = $self->get_short_name(instance => $instance) if (defined($self->{short_name}) && $self->{short_name} == 1); + $name = $self->get_long_name(instance => $instance) unless (defined($self->{short_name}) && $self->{short_name} == 1 && defined($name) && $name ne ''); $self->{components}->{sensor}->{total}++; $self->{output}->output_add(long_msg => sprintf("Sensor '%s' status is '%s' [instance = %s]", diff --git a/network/h3c/snmp/mode/hardware.pm b/network/h3c/snmp/mode/hardware.pm index d40e9087c..56acfb627 100644 --- a/network/h3c/snmp/mode/hardware.pm +++ b/network/h3c/snmp/mode/hardware.pm @@ -113,7 +113,8 @@ sub set_system { }; $self->{components_path} = 'network::h3c::snmp::mode::components'; - $self->{components_module} = ['fan', 'psu', 'slot', 'temperature']; + $self->{components_module} = ['chassis', 'backplane', 'container', 'psu', 'fan', 'sensor', + 'module', 'port', 'stack', 'cpu', 'other', 'unknown']; $self->{mapping_name} = { 1 => 'other', 2 => 'unknown', 3 => 'chassis', 4 => 'backplane', 5 => 'container', 6 => 'psu', @@ -162,6 +163,7 @@ sub new { $options{options}->add_options(arguments => { "reload-cache-time:s" => { name => 'reload_cache_time', default => 180 }, + "short-name" => { name => 'short_name' }, }); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); @@ -171,6 +173,8 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + + $self->{short_name} = (defined($self->{option_results}->{short_name})) ? 1 : 0; $self->{statefile_cache}->check_options(%options); } @@ -211,6 +215,12 @@ sub write_cache { } } +sub get_short_name { + my ($self, %options) = @_; + + return $self->{results}->{$oid_entPhysicalEntry}->{$oid_entPhysicalName . '.' . $options{instance}}; +} + sub get_long_name { my ($self, %options) = @_; @@ -279,7 +289,7 @@ Check Hardware (Fans, Power Supplies, Module,...). =item B<--component> Which component to check (Default: '.*'). -Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane', +Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane', 'container', 'module', 'port', 'stack', 'cpu'. =item B<--filter> @@ -313,6 +323,18 @@ Example: --warning='temperature,.*,40' Set critical threshold for 'temperature' (syntax: type,regexp,threshold) Example: --critical='temperature,.*,45' +=item B<--warning-count-*> + +Set warning threshold for component count. +Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane', +'container', 'module', 'port', 'stack', 'cpu'. + +=item B<--critical-count-*> + +Set critical threshold for component count. +Can be: 'fan', 'psu', 'other', 'unknown', 'sensor', 'chassis', 'backplane', +'container', 'module', 'port', 'stack', 'cpu'. + =item B<--reload-cache-time> Time in seconds before reloading cache file (Default: 180). @@ -320,4 +342,4 @@ Use '-1' to disable cache reload. =back -=cut \ No newline at end of file +=cut