From b3b5957a5dbaf1da71f35b7789e9ff6e2c1cbfd6 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 10 Aug 2015 13:42:00 +0200 Subject: [PATCH] + Ref #122 (WIP) --- .../raritan/snmp/mode/components/resources.pm | 14 +++++++ .../raritan/snmp/mode/components/sensor.pm | 18 ++++---- .../pdu/raritan/snmp/mode/inletsensors.pm | 42 ++++++++++++------- .../pdu/raritan/snmp/mode/outletsensors.pm | 42 ++++++++++++------- 4 files changed, 78 insertions(+), 38 deletions(-) diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/resources.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/resources.pm index 15ae8baa8..dbe93fb38 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/resources.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/resources.pm @@ -85,6 +85,20 @@ $mapping = { State => { oid => '.1.3.6.1.4.1.13742.6.5.2.3.1.3', map => \%map_state }, # measurementsInletSensorState Value => { oid => '.1.3.6.1.4.1.13742.6.5.2.3.1.4' }, # measurementsInletSensorValue }, + outlet_label => { + Label => { oid => '.1.3.6.1.4.1.13742.6.3.5.3.1.2' }, # outletLabel + }, + outlet => { + Unit => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.6', map => \%map_units }, # outletSensorUnits + Decimal => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.7' }, # outletSensorDecimalDigits + EnabledThresholds => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.25' }, # outletSensorEnabledThresholds + LowerCriticalThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.21' }, # outletSensorLowerCriticalThreshold + LowerWarningThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.22' }, # outletSensorLowerWarningThreshold + UpperCriticalThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.23' }, # outletSensorUpperCriticalThreshold + UpperWarningThreshold => { oid => '.1.3.6.1.4.1.13742.6.3.5.4.1.24' }, # outletSensorUpperWarningThreshold + State => { oid => '.1.3.6.1.4.1.13742.6.5.4.3.1.3', map => \%map_state }, # measurementsOutletSensorState + Value => { oid => '.1.3.6.1.4.1.13742.6.5.4.3.1.4' }, # measurementsOutletSensorValue + }, }; %raritan_type = ( diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/sensor.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/sensor.pm index 8ce3b6b5a..e145b295e 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/sensor.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/components/sensor.pm @@ -47,7 +47,7 @@ sub check { my $long_msg = 0; next if ($component !~ /$options{component}/); $self->{components}->{$component} = {name => $component, total => 0, skip => 0}; - next if ($self->check_exclude(section => $component)); + next if ($self->check_filter(section => $component)); my $instance_type = $raritan_type{$component}; my $value_type = $map_type{$instance_type}; @@ -57,7 +57,9 @@ sub check { my $result = $self->{snmp}->map_instance(mapping => $mapping->{$options{type}}, results => $self->{results}, instance => $instance); my $result2 = $self->{snmp}->map_instance(mapping => $mapping->{$options{type} . '_label'}, results => $self->{results}, instance => $1 . '.' . $2); - next if ($self->check_exclude(section => $component, instance => $instance)); + $instance = defined($result2->{Label}) && $result2->{Label} ne '' ? $result2->{Label} : $1 . '.' . $2; + + next if ($self->check_filter(section => $component, instance => $instance)); if ($long_msg == 0) { $self->{output}->output_add(long_msg => "Checking " . $component); @@ -70,15 +72,15 @@ sub check { if ($value =~ /[0-9]/) { $value *= 10 ** -int($result->{Decimal}); } - $self->{output}->output_add(long_msg => sprintf("'%s' %s state is '%s' [instance: %s, value: %s, unit: %s]", - $result2->{Label}, $component, $result->{State}, - $instance, $value, $result->{Unit})); + $self->{output}->output_add(long_msg => sprintf("'%s' %s state is '%s' [instance: %s, value: %s, unit: %s, label: %s]", + $instance, $component, $result->{State}, + $instance, $value, $result->{Unit}, $result2->{Label})); my $exit = $self->get_severity(section => $component, label => $value_type, instance => $instance, value => $result->{State}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, short_msg => sprintf("'%s' %s state is '%s'", - $result2->{Label}, $component, $result->{State})); + $instance, $component, $result->{State})); } if ($value->{value} =~ /[0-9]/) { @@ -98,9 +100,9 @@ sub check { if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit2, short_msg => sprintf("'%s' %s value is %s %s", - $result2->{Label}, $component, $value, $result->{Unit})); + $instance, $component, $value, $result->{Unit})); } - $self->{output}->perfdata_add(label => $result2->{label} . "_" . $component, unit => $result->{Unit}, + $self->{output}->perfdata_add(label => $instance . "_" . $component, unit => $result->{Unit}, value => $value, warning => $warn, critical => $crit); diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm index 5ed7eeeda..3117028ee 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/inletsensors.pm @@ -34,9 +34,9 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, + "filter:s@" => { name => 'filter' }, + "component:s" => { name => 'component', default => '.*' }, + "no-component:s" => { name => 'no_component' }, "threshold-overload:s@" => { name => 'threshold_overload' }, "warning:s@" => { name => 'warning' }, "critical:s@" => { name => 'critical' }, @@ -60,6 +60,16 @@ sub check_options { } } + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + my @values = split (/,/, $val); + if (scalar(@values) < 2) { + $self->{output}->add_option_msg(short_msg => "Wrong filter option '" . $val . "'."); + $self->{output}->option_exit(); + } + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { my @values = split (/,/, $val); @@ -152,19 +162,21 @@ sub run { $self->{output}->exit(); } -sub check_exclude { +sub check_filter { my ($self, %options) = @_; - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; } + return 0; } @@ -226,10 +238,10 @@ Check inlet sensors. Which component to check (Default: '.*'). -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=airPressure,rmsVoltage) -Can also exclude specific instance: --exclude=rmsVoltage#1.2.3#,airPressure +Exclude some parts (comma seperated list) (Example: --filter=airPressure --filter=rmsVoltage) +Can also exclude specific instance: --filter=rmsVoltage,I1 =item B<--no-component> diff --git a/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm b/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm index f902b44f9..a03d5454b 100644 --- a/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm +++ b/centreon-plugins/hardware/pdu/raritan/snmp/mode/outletsensors.pm @@ -34,9 +34,9 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => '.*' }, - "no-component:s" => { name => 'no_component' }, + "filter:s@" => { name => 'filter' }, + "component:s" => { name => 'component', default => '.*' }, + "no-component:s" => { name => 'no_component' }, "threshold-overload:s@" => { name => 'threshold_overload' }, "warning:s@" => { name => 'warning' }, "critical:s@" => { name => 'critical' }, @@ -60,6 +60,16 @@ sub check_options { } } + $self->{filter} = []; + foreach my $val (@{$self->{option_results}->{filter}}) { + my @values = split (/,/, $val); + if (scalar(@values) < 2) { + $self->{output}->add_option_msg(short_msg => "Wrong filter option '" . $val . "'."); + $self->{output}->option_exit(); + } + push @{$self->{filter}}, { filter => $values[0], instance => $values[1] }; + } + $self->{overload_th} = {}; foreach my $val (@{$self->{option_results}->{threshold_overload}}) { my @values = split (/,/, $val); @@ -152,19 +162,21 @@ sub run { $self->{output}->exit(); } -sub check_exclude { +sub check_filter { my ($self, %options) = @_; - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; + foreach (@{$self->{filter}}) { + if ($options{section} =~ /$_->{filter}/) { + if (!defined($options{instance}) && !defined($_->{instance})) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); + return 1; + } elsif (defined($options{instance}) && $options{instance} =~ /$_->{instance}/) { + $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); + return 1; + } } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; } + return 0; } @@ -226,10 +238,10 @@ Check outlet sensors. Which component to check (Default: '.*'). -=item B<--exclude> +=item B<--filter> -Exclude some parts (comma seperated list) (Example: --exclude=airPressure,rmsVoltage) -Can also exclude specific instance: --exclude=rmsVoltage#1.2.3#,airPressure +Exclude some parts (comma seperated list) (Example: --filter=airPressure --filter=rmsVoltage) +Can also exclude specific instance: --filter=rmsVoltage,I1 =item B<--no-component>