aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOle Mathias Aa. Heggem <olemathias.aa.heggem@gmail.com>2019-04-15 21:50:23 +0100
committerolemathias.aa.heggem@gmail.com <root@gondul.tg19.gathering.org>2019-04-15 21:50:23 +0100
commitb55e848a3e1613ebe95979fd8ed5b1446d8d1029 (patch)
tree3e88589948590174c9581325c9510fc5469ff503
parent777ddcd639201851efb7d04ceb740ee03f7bbcef (diff)
Do not die on influx fail
-rwxr-xr-xcollectors/snmpfetchng.pl26
1 files 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.");