Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MON-22575] [Plugin] centreon-plugin-Hardware-Ups-Standard-Rfc1628-Snmp mode input-lines, no perfdata and thresholds when value equal 0 #4751

2 changes: 1 addition & 1 deletion .github/workflows/tests-functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
run: |
sudo useradd snmp
sudo mkdir -p /usr/snmpsim/data
sudo cp tests/resources/snmp/* /usr/snmpsim/data/
sudo cp -r tests/resources/snmp/* /usr/snmpsim/data/
snmpsimd --agent-udpv4-endpoint=127.0.0.1:2024 --process-user=snmp --process-group=snmp &
robot tests/functional/snmp
19 changes: 15 additions & 4 deletions src/hardware/ups/standard/rfc1628/snmp/mode/inputlines.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;

$options{options}->add_options(arguments => {});


$options{options}->add_options(arguments => {
'exclude-id:s' => { name => 'exclude_id' }
});

return $self;
}

Expand All @@ -102,11 +104,15 @@ sub manage_selection {
next if ($oid !~ /^(.*)\.(.*?)\.(.*?)$/);
my ($base, $instance) = ($1 . '.' . $2, $3);
next if (!defined($oids->{$base}));
next if ($results->{$oid} !~ /\d/ || $results->{$oid} == 0);
next if ($results->{$oid} !~ /\d/);
next if (defined($self->{option_results}->{exclude_id}) && $self->{option_results}->{exclude_id} ne '' &&
$self->{option_results}->{exclude_id} =~ /$instance(,|\h|$)/);

$self->{line}->{$instance} = { display => $instance } if (!defined($self->{line}->{$instance}));
$self->{line}->{$instance}->{$oids->{$base}->{name}} = $results->{$oid} * $oids->{$base}->{factor};
}


}

1;
Expand All @@ -124,6 +130,11 @@ Check input lines metrics (frequence, voltage, current and true power).
Only display some counters (regexp can be used).
Example: --filter-counters='^power$'

=item B<--exclude-id>

Define the IDs of the instances to exclude in result.
Example: --exclude-id=2,3

=item B<--warning-*> B<--critical-*>

Thresholds.
Expand Down
101 changes: 101 additions & 0 deletions tests/functional/snmp/hardware-ups-standard-snmp.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
*** Settings ***
Documentation Hardware UPS standard SNMP plugin

Library OperatingSystem
Library String

Test Timeout 120s


*** Variables ***
${CENTREON_PLUGINS} ${CURDIR}${/}..${/}..${/}..${/}src${/}centreon_plugins.pl

${CMD} perl ${CENTREON_PLUGINS} --plugin=hardware::ups::standard::rfc1628::snmp::plugin

&{ups_standard_test_with_values}
... snmpcommunity=hardware-ups/hardware-ups-standard
... warningpower=
... criticalcurrent=
... warningvoltage=
... warningfrequence=
... excludeid=
... result=OK: All input lines are ok | '1#line.input.frequence.hertz'=49.9Hz;;;; '1#line.input.voltage.volt'=233V;;;; '1#line.input.current.ampere'=0A;;;; '1#line.input.power.watt'=0W;;;; '2#line.input.frequence.hertz'=49.9Hz;;;; '2#line.input.voltage.volt'=234V;;;; '2#line.input.current.ampere'=0A;;;; '2#line.input.power.watt'=0W;;;; '3#line.input.frequence.hertz'=49.9Hz;;;; '3#line.input.voltage.volt'=234V;;;; '3#line.input.current.ampere'=0A;;;; '3#line.input.power.watt'=0W;;;;
&{ups_standard_test_critical_with_null_values}
... snmpcommunity=hardware-ups/hardware-ups-standard_null_val
... warningpower='215:'
... criticalcurrent='@0:214'
... warningvoltage='@0:214'
... warningfrequence='@0:214'
... excludeid=
... result=CRITICAL: Input Line '1' Frequence : 0.00 Hz, Voltage : 0.00 V, Current : 0.00 A, Power : 0.00 W - Input Line '2' Frequence : 0.00 Hz, Voltage : 0.00 V, Current : 0.00 A, Power : 0.00 W - Input Line '3' Frequence : 0.00 Hz, Voltage : 0.00 V, Current : 0.00 A, Power : 0.00 W | '1#line.input.frequence.hertz'=0Hz;@0:214;;; '1#line.input.voltage.volt'=0V;@0:214;;; '1#line.input.current.ampere'=0A;;@0:214;; '1#line.input.power.watt'=0W;215:;;; '2#line.input.frequence.hertz'=0Hz;@0:214;;; '2#line.input.voltage.volt'=0V;@0:214;;; '2#line.input.current.ampere'=0A;;@0:214;; '2#line.input.power.watt'=0W;215:;;; '3#line.input.frequence.hertz'=0Hz;@0:214;;; '3#line.input.voltage.volt'=0V;@0:214;;; '3#line.input.current.ampere'=0A;;@0:214;; '3#line.input.power.watt'=0W;215:;;;
&{ups_standard_test_with_exclude_option_1}
... snmpcommunity=hardware-ups/hardware-ups-standard
... warningpower=
... criticalcurrent=
... warningvoltage=
... warningfrequence=
... excludeid='1,2'
... result=OK: Input Line '3' Frequence : 49.90 Hz, Voltage : 234.00 V, Current : 0.00 A, Power : 0.00 W | '3#line.input.frequence.hertz'=49.9Hz;;;; '3#line.input.voltage.volt'=234V;;;; '3#line.input.current.ampere'=0A;;;; '3#line.input.power.watt'=0W;;;;
&{ups_standard_test_with_exclude_option_2}
... snmpcommunity=hardware-ups/hardware-ups-standard
... warningpower=
... criticalcurrent=
... warningvoltage=
... warningfrequence=
... excludeid='1, 2'
... result=OK: Input Line '3' Frequence : 49.90 Hz, Voltage : 234.00 V, Current : 0.00 A, Power : 0.00 W | '3#line.input.frequence.hertz'=49.9Hz;;;; '3#line.input.voltage.volt'=234V;;;; '3#line.input.current.ampere'=0A;;;; '3#line.input.power.watt'=0W;;;;
&{ups_standard_test_with_exclude_option_3}
... snmpcommunity=hardware-ups/hardware-ups-standard
... warningpower=
... criticalcurrent=
... warningvoltage=
... warningfrequence=
... excludeid='1 ,3'
... result=OK: Input Line '2' Frequence : 49.90 Hz, Voltage : 234.00 V, Current : 0.00 A, Power : 0.00 W | '2#line.input.frequence.hertz'=49.9Hz;;;; '2#line.input.voltage.volt'=234V;;;; '2#line.input.current.ampere'=0A;;;; '2#line.input.power.watt'=0W;;;;
@{ups_standard_tests}
... &{ups_standard_test_with_values}
... &{ups_standard_test_critical_with_null_values}
... &{ups_standard_test_with_exclude_option_1}
... &{ups_standard_test_with_exclude_option_2}
... &{ups_standard_test_with_exclude_option_3}


*** Test Cases ***
Hardware UPS Standard SNMP input lines
[Documentation] Hardware UPS standard SNMP input lines
[Tags] hardware UPS snmp
FOR ${ups_standard_test} IN @{ups_standard_tests}
${command} Catenate
... ${CMD}
... --mode=input-lines
... --hostname=127.0.0.1
... --snmp-version=2c
... --snmp-port=2024
... --snmp-community=${ups_standard_test.snmpcommunity}
${length} Get Length ${ups_standard_test.warningpower}
IF ${length} > 0
${command} Catenate ${command} --warning-power=${ups_standard_test.warningpower}
END
${length} Get Length ${ups_standard_test.criticalcurrent}
IF ${length} > 0
${command} Catenate ${command} --critical-current=${ups_standard_test.criticalcurrent}
END
${length} Get Length ${ups_standard_test.warningvoltage}
IF ${length} > 0
${command} Catenate ${command} --warning-voltage=${ups_standard_test.warningvoltage}
END
${length} Get Length ${ups_standard_test.warningfrequence}
IF ${length} > 0
${command} Catenate ${command} --warning-frequence=${ups_standard_test.warningfrequence}
END
${length} Get Length ${ups_standard_test.excludeid}
IF ${length} > 0
${command} Catenate ${command} --exclude-id=${ups_standard_test.excludeid}
END
${output} Run ${command}
${output} Strip String ${output}
Should Be Equal As Strings
... ${output}
... ${ups_standard_test.result}
... Wrong output result for compliance of ${ups_standard_test.result}{\n}Command output:{\n}${output}{\n}{\n}{\n}
END
10 changes: 10 additions & 0 deletions tests/resources/snmp/hardware-ups/hardware-ups-socomec.snmpwalk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.1.3.6.1.4.1.4555.1.1.7.1.3.2.0 = INTEGER: 500
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.1.1 = INTEGER: 1
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.1.2 = INTEGER: 2
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.1.3 = INTEGER: 3
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2.1 = INTEGER: 2330
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2.2 = INTEGER: 2360
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2.3 = INTEGER: 2360
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3.1 = INTEGER: 35
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3.2 = INTEGER: 36
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3.3 = INTEGER: 36
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.1.3.6.1.4.1.4555.1.1.7.1.3.2.0 = INTEGER: 0
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.1.1 = INTEGER: 1
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.1.2 = INTEGER: 2
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.1.3 = INTEGER: 3
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2.1 = INTEGER: 0
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2.2 = INTEGER: 0
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.2.3 = INTEGER: 0
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3.1 = INTEGER: 0
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3.2 = INTEGER: 0
.1.3.6.1.4.1.4555.1.1.7.1.3.3.1.3.3 = INTEGER: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.1.3.6.1.2.1.33.1.3.3.1.2.1 = INTEGER: 499
.1.3.6.1.2.1.33.1.3.3.1.2.2 = INTEGER: 499
.1.3.6.1.2.1.33.1.3.3.1.2.3 = INTEGER: 499
.1.3.6.1.2.1.33.1.3.3.1.3.1 = INTEGER: 233
.1.3.6.1.2.1.33.1.3.3.1.3.2 = INTEGER: 234
.1.3.6.1.2.1.33.1.3.3.1.3.3 = INTEGER: 234
.1.3.6.1.2.1.33.1.3.3.1.4.1 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.4.2 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.4.3 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.5.1 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.5.2 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.5.3 = INTEGER: 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.1.3.6.1.2.1.33.1.3.3.1.2.1 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.2.2 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.2.3 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.3.1 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.3.2 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.3.3 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.4.1 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.4.2 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.4.3 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.5.1 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.5.2 = INTEGER: 0
.1.3.6.1.2.1.33.1.3.3.1.5.3 = INTEGER: 0
Loading