]> git.zerfleddert.de Git - upsgraph/commitdiff
support for multiple values in one tcp connection and example config
authorMichael Gernoth <michael@gernoth.net>
Thu, 17 Jan 2013 11:36:20 +0000 (12:36 +0100)
committerMichael Gernoth <michael@gernoth.net>
Thu, 17 Jan 2013 11:36:20 +0000 (12:36 +0100)
klimaschrank.conf [new file with mode: 0644]
upsgraph.pl

diff --git a/klimaschrank.conf b/klimaschrank.conf
new file mode 100644 (file)
index 0000000..8acd1c2
--- /dev/null
@@ -0,0 +1,54 @@
+package UPSGRAPH;
+
+$outdir="/var/www/klimaschrank/";
+$step=60;
+
+$hosts = [
+       {
+               'address' => "131.188.42.24",
+               'name' => "klimaschrank",
+               'rrdfile' => "/var/www/klimaschrank/.work/klimaschrank.rrd",
+
+               'fields' => [ 'kaltw', 'vorlauf', 'ruecklauf', 'abluft', 'raum' ],
+
+               'vars' => {
+                       'kaltw' => {
+                               'name' => 'Kaltwasser',
+                               'port' => '1337',
+                               'proto' => 'tcp_multi',
+                               'multi_id' => '6328',
+                               'multi_delimiter' => "  ",
+                       },
+                       'vorlauf' => {
+                               'name' => 'Vorlauftemperatur',
+                               'port' => '1337',
+                               'proto' => 'tcp_multi',
+                               'multi_id' => '2d28',
+                               'multi_delimiter' => "  ",
+                       },
+                       'ruecklauf' => {
+                               'name' => 'Ruecklauftemperatur',
+                               'port' => '1337',
+                               'proto' => 'tcp_multi',
+                               'multi_id' => '5228',
+                               'multi_delimiter' => "  ",
+                       },
+                       'abluft' => {
+                               'name' => 'Ablufttemperatur',
+                               'port' => '1337',
+                               'proto' => 'tcp_multi',
+                               'multi_id' => 'f528',
+                               'multi_delimiter' => "  ",
+                       },
+                       'raum' => {
+                               'name' => 'Raumtemperatur',
+                               'port' => '1337',
+                               'proto' => 'tcp_multi',
+                               'multi_id' => '9028',
+                               'multi_delimiter' => "  ",
+                       },
+               }
+       },
+];
+
+1;
index 2783fcf75e86ba259cd0ddad1a3469f1a4eeb0f5..10f622b7f643dd04ec4c6f458ace8d6069457c5d 100755 (executable)
@@ -137,6 +137,31 @@ sub fetch_tcp(@) {
        $value;
 }
 
+sub fetch_tcp_multi(@) {
+       my $address = shift;
+       my $port = shift;
+       my $delimiter = shift;
+       my %values;
+
+       my $sock = IO::Socket::INET->new(PeerAddr => $address,
+                       PeerPort => $port,
+                       Proto => 'tcp',
+                       Timeout => 1);
+
+       return undef if (!$sock);
+
+       while(<$sock>) {
+               chomp;
+               (my $key, my $value) = split(/${delimiter}/, $_);
+               $value=~ s/\s//g;
+               $values{$key} = $value;
+       }
+
+       close($sock);
+
+       %values;
+}
+
 if ($> == 0) {
        if (@ARGV != 2) {
                print STDERR "Running as root, please provide UID as 2th argument!\n";
@@ -333,6 +358,7 @@ while(1) {
                my $vars = $host->{'vars'};
                my $rrdfile = $host->{'rrdfile'};
                my $hostname = $host->{'name'};
+               my %multi_values = ();
 
                foreach my $var (@{$host->{'fields'}}) {
                        delete $vars->{$var}->{'value'};
@@ -345,6 +371,14 @@ while(1) {
                                $result = fetch_snmp($host->{'address'}, $host->{'community'}, $vars->{$var}->{'oid'});
                        } elsif ($vars->{$var}->{'proto'} eq 'tcp') {
                                $result = fetch_tcp($host->{'address'}, $vars->{$var}->{'port'});
+                       } elsif ($vars->{$var}->{'proto'} eq 'tcp_multi') {
+                               if (defined($multi_values{$vars->{$var}->{'multi_id'}})) {
+                                       $result = $multi_values{$vars->{$var}->{'multi_id'}}
+                               } else {
+                                       my %values = fetch_tcp_multi($host->{'address'}, $vars->{$var}->{'port'}, $vars->{$var}->{'multi_delimiter'});
+                                       @multi_values{keys %values} = values %values;
+                                       $result = $multi_values{$vars->{$var}->{'multi_id'}};
+                               }
                        }
 
                        next unless (defined $result);
Impressum, Datenschutz