Implement fetching values from IFM IoTcore
[upsgraph] / upsgraph.pl
index adf33c968e96bfd7e71c5f612cae759f9e40a3d8..55c6a62a85998e88fcd82e1239113e2d57e645c2 100755 (executable)
@@ -15,6 +15,8 @@ use IO::Select;
 use RRDs;
 use File::Copy;
 use Data::Dumper;
 use RRDs;
 use File::Copy;
 use Data::Dumper;
+use LWP::UserAgent;
+use JSON;
 
 $UPSGRAPH::outdir = "";
 $UPSGRAPH::daysCovered = 370;
 
 $UPSGRAPH::outdir = "";
 $UPSGRAPH::daysCovered = 370;
@@ -186,6 +188,23 @@ sub fetch_tcp_multi(@) {
        %values;
 }
 
        %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;
 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'}};
                                }
                                        @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);
                        }
 
                        next unless (defined $result);
Impressum, Datenschutz