From 7f86397bedef318bd5ae330b6e8affba0772b587 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 25 Sep 2019 11:42:12 +0200 Subject: [PATCH] fix eaton pdu snmp --- hardware/pdu/eaton/snmp/mode/group.pm | 28 +++++++++++++------------ hardware/pdu/eaton/snmp/mode/outlet.pm | 29 ++++++++++++++------------ 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/hardware/pdu/eaton/snmp/mode/group.pm b/hardware/pdu/eaton/snmp/mode/group.pm index bfe62f342..dd1f7c9cd 100644 --- a/hardware/pdu/eaton/snmp/mode/group.pm +++ b/hardware/pdu/eaton/snmp/mode/group.pm @@ -34,29 +34,29 @@ sub set_counters { $self->{maps_counters}->{group} = [ { label => 'current', nlabel => 'group.current.ampere', set => { - key_values => [ { name => 'groupCurrent', no_value => 0 } ], + key_values => [ { name => 'groupCurrent', no_value => 0 }, { name => 'display' } ], output_template => 'Current : %.2f A', perfdatas => [ { value => 'groupCurrent_absolute', template => '%.2f', - min => 0, unit => 'A', label_extra_instance => 1 }, + min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'voltage', nlabel => 'group.voltage.volt', set => { - key_values => [ { name => 'groupVoltage', no_value => 0 } ], + key_values => [ { name => 'groupVoltage', no_value => 0 }, { name => 'display' } ], output_template => 'Voltage : %.2f V', perfdatas => [ { value => 'groupVoltage_absolute', template => '%.2f', - unit => 'V', label_extra_instance => 1 }, + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'power', nlabel => 'group.power.watt', set => { - key_values => [ { name => 'groupWatts', no_value => 0 } ], + key_values => [ { name => 'groupWatts', no_value => 0 }, { name => 'display' } ], output_template => 'Power : %.2f W', perfdatas => [ { value => 'groupWatts_absolute', template => '%.2f', - unit => 'W', label_extra_instance => 1 }, + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -102,16 +102,18 @@ sub manage_selection { ); foreach my $oid (keys %{$snmp_result}) { - $oid =~ /\.(\d+\.\d+)$/; - my $instance = $1; - next if (defined($self->{group}->{$instance})); + $oid =~ /\.(\d+)\.(\d+)$/; + my ($strapping_index, $group_index) = ($1, $2); + next if (defined($self->{group}->{$strapping_index . '.' . $group_index})); - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $group_index); $result->{groupVoltage} *= 0.001 if (defined($result->{groupVoltage})); $result->{groupCurrent} *= 0.001 if (defined($result->{groupCurrent})); - my $display = $instance; - $display = $result->{groupName} if (defined($result->{groupName}) && $result->{groupName} ne ''); - $self->{group}->{$display} = { display => $display, %$result }; + my $display = $strapping_index . '.' . $group_index; + if (defined($result->{groupName}) && $result->{groupName} ne '') { + $display = $result->{groupName} . ' strapping ' . $strapping_index; + } + $self->{group}->{$strapping_index . '.' . $group_index} = { display => $display, %$result }; } if (scalar(keys %{$self->{group}}) <= 0) { diff --git a/hardware/pdu/eaton/snmp/mode/outlet.pm b/hardware/pdu/eaton/snmp/mode/outlet.pm index e346db160..81be6dcb2 100644 --- a/hardware/pdu/eaton/snmp/mode/outlet.pm +++ b/hardware/pdu/eaton/snmp/mode/outlet.pm @@ -34,29 +34,29 @@ sub set_counters { $self->{maps_counters}->{outlet} = [ { label => 'current', nlabel => 'outlet.current.ampere', set => { - key_values => [ { name => 'outletCurrent', no_value => 0 } ], + key_values => [ { name => 'outletCurrent', no_value => 0 }, { name => 'display' } ], output_template => 'Current : %.2f A', perfdatas => [ { value => 'outletCurrent_absolute', template => '%.2f', - min => 0, unit => 'A', label_extra_instance => 1 }, + min => 0, unit => 'A', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'voltage', nlabel => 'outlet.voltage.volt', set => { - key_values => [ { name => 'outletVoltage', no_value => 0 } ], + key_values => [ { name => 'outletVoltage', no_value => 0 }, { name => 'display' } ], output_template => 'Voltage : %.2f V', perfdatas => [ { value => 'outletVoltage_absolute', template => '%.2f', - unit => 'V', label_extra_instance => 1 }, + unit => 'V', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'power', nlabel => 'outlet.power.watt', set => { - key_values => [ { name => 'outletWatts', no_value => 0 } ], + key_values => [ { name => 'outletWatts', no_value => 0 }, { name => 'display' } ], output_template => 'Power : %.2f W', perfdatas => [ { value => 'outletWatts_absolute', template => '%.2f', - unit => 'W', label_extra_instance => 1 }, + unit => 'W', label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, @@ -102,16 +102,19 @@ sub manage_selection { ); foreach my $oid (keys %{$snmp_result}) { - $oid =~ /\.(\d+\.\d+)$/; - my $instance = $1; - next if (defined($self->{outlet}->{$instance})); + $oid =~ /\.(\d+)\.(\d+)$/; + my ($strapping_index, $outlet_index) = ($1, $2); - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + next if (defined($self->{outlet}->{$strapping_index . '.' . $outlet_index})); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $strapping_index . '.' . $outlet_index); $result->{outletVoltage} *= 0.001 if (defined($result->{outletVoltage})); $result->{outletCurrent} *= 0.001 if (defined($result->{outletCurrent})); - my $display = $instance; - $display = $result->{outletName} if (defined($result->{outletName}) && $result->{outletName} ne ''); - $self->{outlet}->{$display} = { display => $display, %$result }; + my $display = $strapping_index . '.' . $outlet_index; + if (defined($result->{outletName}) && $result->{outletName} ne '') { + $display = $result->{outletName} . ' strapping ' . $strapping_index; + } + $self->{outlet}->{$strapping_index . '.' . $outlet_index} = { display => $display, %$result }; } if (scalar(keys %{$self->{outlet}}) <= 0) {