]> git.zerfleddert.de Git - upsgraph/commitdiff
add raw tcp to query values (to read poempelfox temp)
authorMichael Gernoth <michael@gernoth.net>
Mon, 8 Feb 2010 22:45:02 +0000 (23:45 +0100)
committerMichael Gernoth <michael@gernoth.net>
Mon, 8 Feb 2010 22:45:02 +0000 (23:45 +0100)
temperature.conf
upsgraph.pl

index 6aac5cbc9f7d8f54d22c3b60ffadfb406eae6dc9..68ed2c786999010ea6c53e32cd608dc199ddd132 100644 (file)
@@ -65,7 +65,7 @@ $hosts = [
                'vars' => {
                        'temp' => {
                                'name' => 'Internal Temperature',
-                               'oid' => '1.3.6.1.4.1.9.9.13.1.3.1.3',
+                               'oid' => '1.3.6.1.4.1.9.9.13.1.3.1.3.1004',
                                'min' => '0',
                                'max' => '200',
                        },
@@ -82,12 +82,29 @@ $hosts = [
                'vars' => {
                        'temp' => {
                                'name' => 'Internal Temperature',
-                               'oid' => '1.3.6.1.4.1.9.9.13.1.3.1.3',
+                               'oid' => '1.3.6.1.4.1.9.9.13.1.3.1.3.1004',
                                'min' => '0',
                                'max' => '200',
                        },
                }
        },
+       {
+               'address' => "217.173.147.33",
+               'name' => "effrafax",
+               'rrdfile' => "/var/spool/upsgraph/temp.effrafax.rrd",
+
+               'fields' => [ 'az' ],
+
+               'vars' => {
+                       'az' => {
+                               'name' => 'Arbeitszimmer',
+                               'port' => '31337',
+                               'proto' => 'tcp',
+                               'min' => '0',
+                               'max' => '100',
+                       },
+               }
+       },
 ];
 
 1;
index 812de11d19898a8ba02b5ca83734d4f720f77981..2e4019667ac33c937620dc8813f38671610edc9b 100755 (executable)
@@ -6,6 +6,7 @@ if ((@ARGV != 1) && (@ARGV != 2)) {
 }
 
 use Net::SNMP;
+use IO::Socket::INET;
 use RRDs;
 use Data::Dumper;
 
@@ -54,15 +55,43 @@ sub fetch_snmp(@) {
        (my $session, my $error) = Net::SNMP->session(Hostname => $address,
                        Community => $community);
 
-       die "session error: $error" unless ($session);
+       if (!$session) {
+               print STDERR "session error: $error";
+       }
 
        $session->translate(0);
 
-       my $val = $session->get_request($oid);
+       my $result = $session->get_request($oid);
 
        $session->close;
 
-       $val;
+       return undef if (!defined($result));
+
+       $result->{$oid};
+}
+
+sub fetch_tcp(@) {
+       my $address = shift;
+       my $port = shift;
+
+       my $sock = IO::Socket::INET->new(PeerAddr => $address,
+                       PeerPort => $port,
+                       Proto => 'tcp',
+                       Timeout => 1);
+
+       return undef if (!$sock);
+
+       chomp(my $value = <$sock>);
+
+       close($sock);
+
+       if (!$value) {
+               return undef;
+       }
+
+       $value=~ s/\s//g;
+
+       $value;
 }
 
 if ($> == 0) {
@@ -223,10 +252,19 @@ while(1) {
                foreach my $var (@{$host->{'fields'}}) {
                        delete $vars->{$var}->{'value'};
 
-                       my $result = fetch_snmp($host->{'address'}, $host->{'community'}, $vars->{$var}->{'oid'});
+                       my $result;
+
+                       if ((!defined($vars->{$var}->{'proto'})) ||
+                           ($vars->{$var}->{'proto'} eq '') ||
+                           ($vars->{$var}->{'proto'} eq 'snmp')) {
+                               $result = fetch_snmp($host->{'address'}, $host->{'community'}, $vars->{$var}->{'oid'});
+                       } elsif ($vars->{$var}->{'proto'} eq 'tcp') {
+                               $result = fetch_tcp($host->{'address'}, $vars->{$var}->{'port'});
+                       }
+
                        next unless (defined $result);
 
-                       $vars->{$var}->{'value'} = $result->{$vars->{$var}->{'oid'}};
+                       $vars->{$var}->{'value'} = $result;
                        if (defined($vars->{$var}->{'factor'})) {
                                $vars->{$var}->{'value'} *= $vars->{$var}->{'factor'};
                        }
Impressum, Datenschutz