diff options
author | James <git@panaceas.org> | 2014-03-17 11:44:49 +0000 |
---|---|---|
committer | James <git@panaceas.org> | 2014-03-17 11:44:49 +0000 |
commit | 7c90320682fd51130564972947a3a5924f73e301 (patch) | |
tree | eaa5b31fdda30a62ccb82c0ac1e01df75af7fa5b | |
parent | dafb8e9f1b0c0d7cfe092ddb467a7650109efb51 (diff) | |
download | inf-7c90320682fd51130564972947a3a5924f73e301.tar.gz inf-7c90320682fd51130564972947a3a5924f73e301.tar.bz2 inf-7c90320682fd51130564972947a3a5924f73e301.zip |
fish
-rw-r--r-- | INF/DSRx020.pm | 36 | ||||
-rwxr-xr-x | inf.pl | 2 |
2 files changed, 23 insertions, 15 deletions
diff --git a/INF/DSRx020.pm b/INF/DSRx020.pm index 591f367..d99cfad 100644 --- a/INF/DSRx020.pm +++ b/INF/DSRx020.pm @@ -34,8 +34,8 @@ sub trim($) { my $s = shift; if ( defined $s ) { - $s =~ s/a^\s+//g; - $s =~ s/\s+$//g; + $s =~ s/^[\s\t\n\r\xa0]+//s; + $s =~ s/[\t\n\r\s\xa0]+$//s; } return $s; @@ -516,25 +516,33 @@ sub pdu_load_get($) { my $rows = [ $table->look_down( "_tag" => 'tr' ) ]; return undef unless scalar(@$rows) > 1; - my $r1 = [ $rows->[0]->look_down( "_tag" => 'td' ) ]; - my $r2 = [ $rows->[1]->look_down( "_tag" => 'td' ) ]; - - for ( my $i = 0 ; $i < scalar(@$r1) ; ++$i ) { + my $row_data = []; + for my $row (@$rows) { + push @$row_data, [ $row->look_down( "_tag" => 'td' ) ]; + } - my $title = $r1->[$i]; - my $value = $r2->[$i]; + my $top_row = shift @$row_data; + for ( my $i = 0 ; $i < scalar(@$top_row) ; ++$i ) { + my $title = $top_row->[$i]; next unless defined $title; - next unless defined $value; - $title = elm_to_txt($title); - $value = elm_to_txt($value); - - trim($value); + next unless $title =~ /current/i; + + for my $row (@$row_data) { + my $value = $row->[$i]; + next unless $value; + $value = elm_to_txt($value); + trim($value); + next unless length($value); + next if $value =~ /N\/A/; + push @$ret, sprintf( "%.2f", $value ); + } - push @$ret, $value . " " if $title =~ /current/i; } + push @$ret, "N/A" if scalar(@$ret) == 0; + return join( ",", @$ret ); } @@ -151,7 +151,7 @@ sub show_status($) { my $load = $inf->pdu_load_get(); if ( defined $load ) { - $load = sprintf( "%.1f Amps", $load ); + $load = sprintf( "%s Amps", $load ); } else { $load = "Unknown"; |