aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristian Lyngstol <kristian@bohemians.org>2016-05-27 19:59:40 +0200
committerKristian Lyngstol <kristian@bohemians.org>2016-05-27 19:59:40 +0200
commita50447265364d73bfbf2d2bccef90d470fb8a894 (patch)
treeb79da63305998ade1f0aed93beb03de93599befe
parent3dcb90eaf58ce9c32532ae5524abf70100d34daa (diff)
snmpfetch: Don't insert empty data
Fixes #50
-rwxr-xr-xcollectors/snmpfetchng.pl12
1 files changed, 10 insertions, 2 deletions
diff --git a/collectors/snmpfetchng.pl b/collectors/snmpfetchng.pl
index 2f12032..060ce2d 100755
--- a/collectors/snmpfetchng.pl
+++ b/collectors/snmpfetchng.pl
@@ -110,10 +110,12 @@ sub callback{
my %ttop;
my %nics;
my @nicids;
+ my $total = 0;
for my $ret (@top) {
for my $var (@{$ret}) {
for my $inner (@{$var}) {
+ $total++;
my ($tag,$type,$name,$iid, $val) = ( $inner->tag ,$inner->type , $inner->name, $inner->iid, $inner->val);
if ($tag eq "ifPhysAddress") {
next;
@@ -136,11 +138,17 @@ sub callback{
$tree2{'misc'}{$key}{$iid} = $tree{$iid}{$key};
}
}
- $sth->execute($switch{'sysname'}, JSON::XS::encode_json(\%tree2));
+ if ($total > 0) {
+ $sth->execute($switch{'sysname'}, JSON::XS::encode_json(\%tree2));
+ }
$qunlock->execute($switch{'id'})
or die "Couldn't unlock switch";
$dbh->commit;
- mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s.");
+ if ($total > 0) {
+ mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s.");
+ } else {
+ mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s - no data. Timeout?");
+ }
}
while (1) {
inner_loop();