From dc924a1788f6ea4bb3444bc4784771c04f76fd9c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 21 Oct 2019 09:41:51 +0200 Subject: [PATCH] Fix #1682 --- .../standard/snmp/mode/components/fan.pm | 31 ++++++++++++------- .../standard/snmp/mode/components/module.pm | 6 ++-- .../standard/snmp/mode/components/physical.pm | 6 ++-- .../standard/snmp/mode/components/psu.pm | 12 +++---- .../snmp/mode/components/temperature.pm | 20 +++++++----- .../standard/snmp/mode/components/voltage.pm | 6 ++-- .../cisco/standard/snmp/mode/environment.pm | 4 +++ 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/centreon/common/cisco/standard/snmp/mode/components/fan.pm b/centreon/common/cisco/standard/snmp/mode/components/fan.pm index 1eaef0d0a..8f777a8c2 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/fan.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/fan.pm @@ -63,16 +63,19 @@ sub check_fan_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonFanStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr})); next if ($result->{ciscoEnvMonFanState} =~ /not present/i && - $self->absent_problem(section => 'fan', instance => $instance)); + $self->absent_problem(section => 'fan', instance => $instance, name => $result->{ciscoEnvMonFanStatusDescr})); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("fan '%s' status is %s [instance: %s].", - $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}, - $instance - )); - my $exit = $self->get_severity(section => 'fan', value => $result->{ciscoEnvMonFanState}); + $self->{output}->output_add( + long_msg => sprintf( + "fan '%s' status is %s [instance: %s].", + $result->{ciscoEnvMonFanStatusDescr}, $result->{ciscoEnvMonFanState}, + $instance + ) + ); + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{ciscoEnvMonFanState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("fan '%s' status is %s", @@ -94,12 +97,16 @@ sub check_fan_entity { my $fan_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFanTrayOperStatus}, instance => $instance); - next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($self->check_filter(section => 'fan', instance => $instance, name => $fan_descr)); $self->{components}->{fan}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' status is %s [instance: %s]", - $fan_descr, $result->{cefcFanTrayOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'fan', value => $result->{cefcFanTrayOperStatus}); + $self->{output}->output_add( + long_msg => sprintf( + "Fan '%s' status is %s [instance: %s]", + $fan_descr, $result->{cefcFanTrayOperStatus}, $instance + ) + ); + my $exit = $self->get_severity(section => 'fan', instance => $instance, value => $result->{cefcFanTrayOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Fan '%s/%s' status is %s", $fan_descr, $instance, $result->{cefcFanTrayOperStatus})); @@ -118,4 +125,4 @@ sub check { check_fan_entity($self); } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/module.pm b/centreon/common/cisco/standard/snmp/mode/components/module.pm index 43fef20fb..21c29c480 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/module.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/module.pm @@ -79,12 +79,12 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcModuleOperStatus}, instance => $instance); my $module_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; - next if ($self->check_filter(section => 'module', instance => $instance)); + next if ($self->check_filter(section => 'module', instance => $instance, name => $module_descr)); $self->{components}->{module}->{total}++; $self->{output}->output_add(long_msg => sprintf("Module '%s' status is %s [instance: %s]", $module_descr, $result->{cefcModuleOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'module', value => $result->{cefcModuleOperStatus}); + my $exit = $self->get_severity(section => 'module', instance => $instance, value => $result->{cefcModuleOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Module '%s/%s' status is %s", $module_descr, @@ -93,4 +93,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/physical.pm b/centreon/common/cisco/standard/snmp/mode/components/physical.pm index 2f0b461a9..232ef1064 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/physical.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/physical.pm @@ -61,12 +61,12 @@ sub check { next; } - next if ($self->check_filter(section => 'physical', instance => $instance)); + next if ($self->check_filter(section => 'physical', instance => $instance, name => $physical_descr)); $self->{components}->{physical}->{total}++; $self->{output}->output_add(long_msg => sprintf("Physical '%s' status is %s [instance: %s]", $physical_descr, $result->{cefcPhysicalStatus}, $instance)); - my $exit = $self->get_severity(section => 'physical', value => $result->{cefcPhysicalStatus}); + my $exit = $self->get_severity(section => 'physical', instance => $instance, value => $result->{cefcPhysicalStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Physical '%s/%s' status is %s", $physical_descr, @@ -75,4 +75,4 @@ sub check { } } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/psu.pm b/centreon/common/cisco/standard/snmp/mode/components/psu.pm index 41db1f1a9..2405a2c43 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/psu.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/psu.pm @@ -79,16 +79,16 @@ sub check_psu_envmon { my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonSupplyStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr})); next if ($result->{ciscoEnvMonSupplyState} =~ /not present/i && - $self->absent_problem(section => 'psu', instance => $instance)); + $self->absent_problem(section => 'psu', instance => $instance, name => $result->{ciscoEnvMonSupplyStatusDescr})); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s] [source: %s]", $result->{ciscoEnvMonSupplyStatusDescr}, $result->{ciscoEnvMonSupplyState}, $instance, $result->{ciscoEnvMonSupplySource} )); - my $exit = $self->get_severity(section => 'psu', value => $result->{ciscoEnvMonSupplyState}); + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{ciscoEnvMonSupplyState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power supply '%s' status is %s", @@ -110,12 +110,12 @@ sub check_psu_entity { my $psu_descr = $self->{results}->{$oid_entPhysicalDescr}->{$oid_entPhysicalDescr . '.' . $instance}; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_cefcFRUPowerOperStatus}, instance => $instance); - next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance, name => $psu_descr)); $self->{components}->{psu}->{total}++; $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is %s [instance: %s]", $psu_descr, $result->{cefcFRUPowerOperStatus}, $instance)); - my $exit = $self->get_severity(section => 'psu', value => $result->{cefcFRUPowerOperStatus}); + my $exit = $self->get_severity(section => 'psu', instance => $instance, value => $result->{cefcFRUPowerOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Power supply '%s/%s' status is %s", $psu_descr, $instance, $result->{cefcFRUPowerOperStatus})); @@ -134,4 +134,4 @@ sub check { check_psu_entity($self); } -1; \ No newline at end of file +1; diff --git a/centreon/common/cisco/standard/snmp/mode/components/temperature.pm b/centreon/common/cisco/standard/snmp/mode/components/temperature.pm index d11131280..25b4e9a2f 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/temperature.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/temperature.pm @@ -59,22 +59,26 @@ sub check { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonTemperatureStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'temperature', instance => $instance)); + next if ($self->check_filter(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr})); $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Temperature '%s' status is %s [instance: %s] [value: %s C]", - $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, - $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-')); - my $exit = $self->get_severity(section => 'temperature', value => $result->{ciscoEnvMonTemperatureState}); + $self->{output}->output_add( + long_msg => sprintf( + "Temperature '%s' status is %s [instance: %s] [value: %s C]", + $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState}, + $instance, defined($result->{ciscoEnvMonTemperatureStatusValue}) ? $result->{ciscoEnvMonTemperatureStatusValue} : '-' + ) + ); + my $exit = $self->get_severity(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Temperature '%s' status is %s", $result->{ciscoEnvMonTemperatureStatusDescr}, $result->{ciscoEnvMonTemperatureState})); } - + next if (!defined($result->{ciscoEnvMonTemperatureStatusValue})); - - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{ciscoEnvMonTemperatureStatusValue}); + + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, name => $result->{ciscoEnvMonTemperatureStatusDescr}, value => $result->{ciscoEnvMonTemperatureStatusValue}); if ($checked == 0) { my $warn_th = undef; my $crit_th = '~:' . $result->{ciscoEnvMonTemperatureThreshold}; diff --git a/centreon/common/cisco/standard/snmp/mode/components/voltage.pm b/centreon/common/cisco/standard/snmp/mode/components/voltage.pm index 16d3fa907..c70825cdd 100644 --- a/centreon/common/cisco/standard/snmp/mode/components/voltage.pm +++ b/centreon/common/cisco/standard/snmp/mode/components/voltage.pm @@ -60,13 +60,13 @@ sub check { my $instance = $1; my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_ciscoEnvMonVoltageStatusEntry}, instance => $instance); - next if ($self->check_filter(section => 'voltage', instance => $instance)); + next if ($self->check_filter(section => 'voltage', instance => $instance, name => $result->{ciscoEnvMonVoltageStatusDescr})); $self->{components}->{voltage}->{total}++; $self->{output}->output_add(long_msg => sprintf("Voltage '%s' status is %s [instance: %s] [value: %s C]", $result->{ciscoEnvMonVoltageStatusDescr}, $result->{ciscoEnvMonVoltageState}, $instance, $result->{ciscoEnvMonVoltageStatusValue})); - my $exit = $self->get_severity(section => 'voltage', value => $result->{ciscoEnvMonVoltageState}); + my $exit = $self->get_severity(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageState}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("Voltage '%s' status is %s", @@ -74,7 +74,7 @@ sub check { } $result->{ciscoEnvMonVoltageStatusValue} = $result->{ciscoEnvMonVoltageStatusValue} / 1000; - my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{ciscoEnvMonVoltageStatusValue}); + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, name => $result->{ciscoEnvMonVoltageStatusDescr}, value => $result->{ciscoEnvMonVoltageStatusValue}); if ($checked == 0) { my $warn_th = undef; my $crit_th = ((defined($result->{ciscoEnvMonVoltageThresholdLow}) && $result->{ciscoEnvMonVoltageThresholdLow} =~ /\d/) ? sprintf("%.3f", $result->{ciscoEnvMonVoltageThresholdLow} / 1000) : 0) . ':' . diff --git a/centreon/common/cisco/standard/snmp/mode/environment.pm b/centreon/common/cisco/standard/snmp/mode/environment.pm index c97f6ba1a..515d5a4e8 100644 --- a/centreon/common/cisco/standard/snmp/mode/environment.pm +++ b/centreon/common/cisco/standard/snmp/mode/environment.pm @@ -164,6 +164,10 @@ Can be: 'fan', 'psu', 'temperature', 'voltage', 'module', 'physical', 'sensor'. Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) Can also exclude specific instance: --filter=fan,1 +=item B<--add-name-instance> + +Add literal description for instance value (used in filter, absent-problem and threshold options). + =item B<--absent-problem> Return an error if an entity is not 'present' (default is skipping) (comma seperated list)