X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph/blobdiff_plain/29f39945993945c6dfb2a70c84458453c5a271d6..72d2ded0ea9c38f3ae9d498134c89ee749aa71e4:/upsgraph.pl?ds=sidebyside diff --git a/upsgraph.pl b/upsgraph.pl index adf33c9..55c6a62 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -15,6 +15,8 @@ use IO::Select; use RRDs; use File::Copy; use Data::Dumper; +use LWP::UserAgent; +use JSON; $UPSGRAPH::outdir = ""; $UPSGRAPH::daysCovered = 370; @@ -186,6 +188,23 @@ sub fetch_tcp_multi(@) { %values; } +sub fetch_iotcore(@) { + my $url = shift; + + my $ua = LWP::UserAgent->new; + $ua->timeout(1); + + my $resp = $ua->get($url); + return undef if (!$resp->is_success); + + my $pdin = decode_json($resp->decoded_content); + return undef if (!defined($pdin)); + + my $value = hex($pdin->{'data'}->{'value'}); + + $value; +} + sub dayGraphFunc { my $dataSrc = shift; my $mode = shift; @@ -477,6 +496,8 @@ while(1) { @multi_values{keys %values} = values %values; $result = $multi_values{$vars->{$var}->{'multi_id'}}; } + } elsif ($vars->{$var}->{'proto'} eq 'iotcore') { + $result = fetch_iotcore($vars->{$var}->{'url'}); } next unless (defined $result);