From b55e848a3e1613ebe95979fd8ed5b1446d8d1029 Mon Sep 17 00:00:00 2001 From: "Ole Mathias Aa. Heggem" Date: Mon, 15 Apr 2019 21:50:23 +0100 Subject: Do not die on influx fail --- collectors/snmpfetchng.pl | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/collectors/snmpfetchng.pl b/collectors/snmpfetchng.pl index 02b75b8..cfa0d77 100755 --- a/collectors/snmpfetchng.pl +++ b/collectors/snmpfetchng.pl @@ -13,6 +13,8 @@ use IO::Socket::IP; use Scalar::Util qw(looks_like_number); use Time::HiRes qw(time); +use Try::Tiny; + SNMP::initMib(); SNMP::addMibDirs("/opt/gondul/data/mibs/StandardMibs"); SNMP::addMibDirs("/opt/gondul/data/mibs/JuniperMibs"); @@ -220,16 +222,20 @@ sub callback{ }, fields => { 'execution_time' => (time - $switch{'start'}) }, }); - my $cv = AE::cv; - $influx->write( - database => $nms::config::influx_database, - data => [@influx_tree], - on_success => $cv, - on_error => sub { - $cv->croak("Failed to write data: @_"); - } - ); - $cv->recv; + try { + my $cv = AE::cv; + $influx->write( + database => $nms::config::influx_database, + data => [@influx_tree], + on_success => $cv, + on_error => sub { + $cv->croak("Failed to write data: @_"); + } + ); + $cv->recv; + } catch { + warn "caught error: $_"; + }; if ((time - $switch{'start'}) > 10) { mylog( "Polled $switch{'sysname'} in " . (time - $switch{'start'}) . "s."); -- cgit v1.2.3