Skip to content

Commit

Permalink
fix(raritan): fix powerfactor when sensor is off
Browse files Browse the repository at this point in the history
Fix powerFactor output when the sensor is off

Refs: CTOR-1082
  • Loading branch information
itoussies committed Jan 22, 2025
1 parent eb25261 commit e020ba6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/hardware/pdu/raritan/snmp/mode/components/resources.pm
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ $mapping = {
$thresholds = {
numeric => [
['unavailable', 'UNKNOWN'],
['absent', 'OK'],
['normal', 'OK'],
['belowLowerCritical', 'CRITICAL'],
['belowLowerWarning', 'WARNING'],
Expand Down
34 changes: 22 additions & 12 deletions src/hardware/pdu/raritan/snmp/mode/components/sensor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ sub load {
sub check {
my ($self, %options) = @_;

my $components_onoff_info;
my $power_factor_dependencies;
foreach my $component (sort keys %raritan_type) {
my $long_msg = 0;
next if ($component !~ /$options{component}/);
if ($options{component} eq 'powerFactor') {
next if ($component !~ /activePower|onOff|powerFactor/);
} elsif ($component !~ /$options{component}/) {
next;
}
$self->{components}->{$component} = { name => $component, total => 0, skip => 0 };
next if ($self->check_filter(section => $component));

my $instance_type = $raritan_type{$component};
my $value_type = $map_type{$instance_type};
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) {
Expand Down Expand Up @@ -78,24 +81,31 @@ sub check {

next if ($self->check_filter(section => $component, instance => $instance));

if ($long_msg == 0) {
$self->{output}->output_add(long_msg => "Checking " . $component);
$long_msg = 1;
if ($component =~ /$options{component}/) {
$self->{components}->{$component}->{total}++;
}

$self->{components}->{$component}->{total}++;

my $value = (defined($result->{Value}) && $result->{Value} ne '') ? $result->{Value} : '-';
if ($value =~ /[0-9]/) {
$value *= 10 ** -int($result->{Decimal});
}

if ($component eq 'onOff') {
$components_onoff_info->{$instance} = $result->{State};
if ($component eq 'activePower' && $value == 0) {
$power_factor_dependencies->{$instance} = 1
}

if ($component eq 'powerFactor' && defined($components_onoff_info->{$instance}) && $components_onoff_info->{$instance} eq 'off') {
$result->{State} = 'normal';
if ($component eq 'onOff' && $result->{State} eq 'off') {
$power_factor_dependencies->{$instance} = 1;
}

if ($component eq 'powerFactor' && defined($power_factor_dependencies->{$instance})) {
$result->{State} = 'absent';
}

next if ($component !~ /$options{component}/);
if ($long_msg == 0) {
$self->{output}->output_add(long_msg => "Checking " . $component);
$long_msg = 1;
}

$self->{output}->output_add(
Expand Down

0 comments on commit e020ba6

Please sign in to comment.