From 85492d245d67fc325e7380c15fd40076dcc1bb44 Mon Sep 17 00:00:00 2001 From: Lee Keitel Date: Wed, 4 Sep 2019 21:13:32 -0500 Subject: [PATCH] Catch exceptions generated by alert transports (#10565) * Catch exceptions generated by alert transports The alert.php script would completely die if a single alert transport generated an exception. For example the API transport if CURL couldn't connect to the api endpoint. The script should attempt to send alerts to all working transports and not die because a single transport fails. * Move alert transport creation into try block Catch any potential exceptions during transport creation. None of the transports currently implement __construct() but the DB could throw and in the future there may be a transport that does implement it. --- LibreNMS/Alert/RunAlerts.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/LibreNMS/Alert/RunAlerts.php b/LibreNMS/Alert/RunAlerts.php index d01f7c9962..544ce6c4d4 100644 --- a/LibreNMS/Alert/RunAlerts.php +++ b/LibreNMS/Alert/RunAlerts.php @@ -1,7 +1,7 @@ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ * * Modified by: * @author Heath Barnhart - * + * */ namespace LibreNMS\Alert; @@ -523,9 +523,13 @@ class RunAlerts $obj['alert']['title'] = $obj['title']; $obj['msg'] = $type->getBody($obj); c_echo(" :: $transport_title => "); - $instance = new $class($item['transport_id']); - $tmp = $instance->deliverAlert($obj, $item['opts']); - $this->alertLog($tmp, $obj, $obj['transport']); + try { + $instance = new $class($item['transport_id']); + $tmp = $instance->deliverAlert($obj, $item['opts']); + $this->alertLog($tmp, $obj, $obj['transport']); + } catch (\Exception $e) { + $this->alertLog($e, $obj, $obj['transport']); + } unset($instance); echo PHP_EOL; }