From 59ad5d06c4c7021eedbc78768b2a447acb1014c3 Mon Sep 17 00:00:00 2001 From: Robert Gornall Date: Wed, 23 Mar 2016 16:50:16 +0000 Subject: [PATCH 1/2] Catch failed transports that don't return 'false'. Pass error message into event log. --- alerts.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/alerts.php b/alerts.php index 4ccf2e2fb..b3bb308a3 100755 --- a/alerts.php +++ b/alerts.php @@ -345,14 +345,18 @@ function ExtTransports($obj) { $prefix = array( 0=>"recovery", 1=>$obj['severity']." alert", 2=>"acknowledgment" ); $prefix[3] = &$prefix[0]; $prefix[4] = &$prefix[0]; - if ($tmp) { + if ($tmp === true) { echo 'OK'; log_event('Issued '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']); } - else { + elseif ($tmp === false) { echo 'ERROR'; log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."'", $obj['device_id']); } + else { + echo 'ERROR: '.$tmp."\r\n"; + log_event('Could not issue '.$prefix[$obj['state']]." for rule '".$obj['name']."' to transport '".$transport."' Error: ".$tmp, $obj['device_id']); + } } echo '; '; From 5115095d8fc1fcd0bd9f05d45689f515003b2efe Mon Sep 17 00:00:00 2001 From: Robert Gornall Date: Wed, 23 Mar 2016 17:01:06 +0000 Subject: [PATCH 2/2] Give slightly more information on Transport API failure. --- includes/alerts/transport.api.php | 2 +- includes/alerts/transport.hipchat.php | 6 +++++- includes/alerts/transport.pagerduty.php | 2 +- includes/alerts/transport.pushbullet.php | 2 +- includes/alerts/transport.pushover.php | 2 +- includes/alerts/transport.slack.php | 2 +- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/includes/alerts/transport.api.php b/includes/alerts/transport.api.php index 33089b464..20afc1f5e 100644 --- a/includes/alerts/transport.api.php +++ b/includes/alerts/transport.api.php @@ -41,7 +41,7 @@ foreach( $opts as $method=>$apis ) { var_dump("API '$host' returned Error"); //FIXME: propper debuging var_dump("Params: ".$api); //FIXME: propper debuging var_dump("Return: ".$ret); //FIXME: propper debuging - return false; + return 'HTTP Status code '.$code; } } } diff --git a/includes/alerts/transport.hipchat.php b/includes/alerts/transport.hipchat.php index 5a209bbef..a829004c4 100644 --- a/includes/alerts/transport.hipchat.php +++ b/includes/alerts/transport.hipchat.php @@ -28,6 +28,10 @@ foreach($opts as $option) { } $curl = curl_init(); + if (empty($obj["msg"])) { + return "Empty Message"; + } + if (empty($option["message_format"])) { $option["message_format"] = 'text'; } @@ -60,7 +64,7 @@ foreach($opts as $option) { var_dump("API '$url' returned Error"); var_dump("Params: " . $message); var_dump("Return: " . $ret); - return false; + return 'HTTP Status code '.$code; } } return true; diff --git a/includes/alerts/transport.pagerduty.php b/includes/alerts/transport.pagerduty.php index 4b760df79..8fb613fa0 100644 --- a/includes/alerts/transport.pagerduty.php +++ b/includes/alerts/transport.pagerduty.php @@ -48,6 +48,6 @@ $ret = curl_exec($curl); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if( $code != 200 ) { var_dump("PagerDuty returned Error, retry later"); //FIXME: propper debuging - return false; + return 'HTTP Status code '.$code; } return true; diff --git a/includes/alerts/transport.pushbullet.php b/includes/alerts/transport.pushbullet.php index c5d75f4ef..f54e7448a 100644 --- a/includes/alerts/transport.pushbullet.php +++ b/includes/alerts/transport.pushbullet.php @@ -42,6 +42,6 @@ if( $code > 201 ) { if( $debug ) { var_dump($ret); } - return false; + return 'HTTP Status code '.$code; } return true; diff --git a/includes/alerts/transport.pushover.php b/includes/alerts/transport.pushover.php index 5205c14f6..d2f8fba4f 100644 --- a/includes/alerts/transport.pushover.php +++ b/includes/alerts/transport.pushover.php @@ -86,7 +86,7 @@ foreach( $opts as $api ) { $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); if( $code != 200 ) { var_dump("Pushover returned error"); //FIXME: proper debugging - return false; + return 'HTTP Status code '.$code; } } return true; diff --git a/includes/alerts/transport.slack.php b/includes/alerts/transport.slack.php index e770918e8..cbb910121 100644 --- a/includes/alerts/transport.slack.php +++ b/includes/alerts/transport.slack.php @@ -45,7 +45,7 @@ foreach( $opts as $tmp_api ) { var_dump("API '$host' returned Error"); //FIXME: propper debuging var_dump("Params: ".$alert_message); //FIXME: propper debuging var_dump("Return: ".$ret); //FIXME: propper debuging - return false; + return 'HTTP Status code '.$code; } } return true;