X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/blobdiff_plain/72d2ded0ea9c38f3ae9d498134c89ee749aa71e4..c952fc0ba78932df14eef9e502cd5b7bb6375666:/upsgraph.pl diff --git a/upsgraph.pl b/upsgraph.pl index 55c6a62..f9d0fe3 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -189,12 +189,24 @@ sub fetch_tcp_multi(@) { } sub fetch_iotcore(@) { - my $url = shift; + my $host = shift; + my $adr = shift; + my $mask = shift; my $ua = LWP::UserAgent->new; $ua->timeout(1); - my $resp = $ua->get($url); + my $iotcore_req = { + cid => 1, + code => 10, + adr => $adr, + }; + + my $req = HTTP::Request->new(POST => "http://${host}"); + $req->content_type('application/json'); + $req->content(encode_json($iotcore_req)); + + my $resp = $ua->request($req); return undef if (!$resp->is_success); my $pdin = decode_json($resp->decoded_content); @@ -202,6 +214,10 @@ sub fetch_iotcore(@) { my $value = hex($pdin->{'data'}->{'value'}); + if (defined($mask)) { + $value = $value & $mask; + } + $value; } @@ -497,7 +513,7 @@ while(1) { $result = $multi_values{$vars->{$var}->{'multi_id'}}; } } elsif ($vars->{$var}->{'proto'} eq 'iotcore') { - $result = fetch_iotcore($vars->{$var}->{'url'}); + $result = fetch_iotcore($host->{'address'}, $vars->{$var}->{'adr'}, $vars->{$var}->{'mask'}); } next unless (defined $result);