'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',
},
'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;
}
use Net::SNMP;
+use IO::Socket::INET;
use RRDs;
use Data::Dumper;
(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) {
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'};
}