From cabcc048770e815925eba91d7b5f5ffa60622501 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Mon, 1 Jun 2015 21:41:55 +1000 Subject: [PATCH 1/3] Created Pushover transport, requires testing Moved print_r references to top for debug Modified Pushover transport, testing required Pushover transport, fixed syntax issue Pushover transport, fixed another syntax issue Pushover transport, added debug Pushover transport, updated message code Pushover transport, debug Pushover transport, testing new code Pushover transport, adding more parameters and adding debug parameters Pushover transport, added severity level support Pushover transport, modified severity level code Pushover transport, updated severity code Pushover transport, debugging severity level Pushover transport, more debugging Pushover transport, debugging sound Pushover transport, fixed sound syntax issue Pushover transport, debugging sound API Pushover transport, adjusted sound code Updated contributors file to add myself Updated Alerting doc to include Pushover Pushover transport, modified code Pushover transport, fixed syntax error Pushover transport, removed debug code Ready for deployment Pushover transport, updated copyright --- AUTHORS.md | 1 + doc/Extensions/Alerting.md | 26 ++++++++++ includes/alerts/transport.pushover.php | 66 ++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 includes/alerts/transport.pushover.php diff --git a/AUTHORS.md b/AUTHORS.md index e47f58a791..127de98254 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -30,5 +30,6 @@ Contributors to LibreNMS: - Freddie Cash (fjwcash@gmail.com) (fjwcash) - Thom Seddon (thomseddon) - Vitali Kari (vitalisator) +- James Campbell (neokjames) [1]: http://observium.org/ "Observium web site" diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index 59fb295f93..a542be682d 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -15,6 +15,7 @@ Table of Content: - [Slack](#transports-slack) - [HipChat](#transports-hipchat) - [PagerDuty](#transports-pagerduty) + - [Pushover](#transports-pushover) - [Entities](#entities) - [Devices](#entity-devices) - [BGP Peers](#entity-bgppeers) @@ -265,6 +266,31 @@ That's it! __Note__: Currently ACK notifications are not transported to PagerDuty, This is going to be fixed within the next major version (version by date of writing: 2015.05) +## Pushover + +Enabling Pushover support is fairly easy, there are only two required parameters. + +Firstly you need to create a new Application (called LibreNMS, for example) in your account on the Pushover website (https://pushover.net/apps) + +Now copy your API Token/Key from the newly created Application and setup the transport in your config.php like: + +```php +$config['alert']['transports']['pushover'][] = array( + "appkey" => 'APPLICATIONAPIKEYGOESHERE', + "userkey" => 'USERKEYGOESHERE', + ); +``` + +To modify the Critical alert sound, add the 'sound_critical' parameter, example: + +```php +$config['alert']['transports']['pushover'][] = array( + "appkey" => 'APPLICATIONAPIKEYGOESHERE', + "userkey" => 'USERKEYGOESHERE', + "sound_critical" => 'siren', + ); +``` + # Entities Entities as described earlier are based on the table and column names within the database, if you are ensure of what the entity is you want then have a browse around inside MySQL using `show tables` and `desc `. diff --git a/includes/alerts/transport.pushover.php b/includes/alerts/transport.pushover.php new file mode 100644 index 0000000000..7d49e10b98 --- /dev/null +++ b/includes/alerts/transport.pushover.php @@ -0,0 +1,66 @@ +/* Copyright (C) 2015 James Campbell + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/* Copyright (C) 2015 Daniel Preussker + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Pushover API Transport + * @author neokjames + * @copyright 2015 neokjames, f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Alerts + */ + +foreach( $opts as $api ) { + $data = array(); + $data['token'] = $api['appkey']; + $data['user'] = $api['userkey']; + if( $obj['severity'] == "critical" ) { + if( !empty($api['sound_critical']) ) { + $data['sound'] = $api['sound_critical']; + } + $severity = "Critical"; + $data['priority'] = 1; + } + elseif( $obj['severity'] == "warning" ) { + $severity = "Warning"; + $data['priority'] = 0; + } + $curl = curl_init(); + $data['title'] = $severity." - ".$obj['hostname']; + $data['message'] = $obj['name']; + curl_setopt($curl, CURLOPT_URL, 'https://api.pushover.net/1/messages.json'); + curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + $ret = curl_exec($curl); + $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if( $code != 200 ) { + var_dump("Pushover returned error"); //FIXME: proper debugging + return false; + } +} +return true; From c5ed14fb91185d2458382d217eb911d4ace51df1 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Tue, 2 Jun 2015 12:25:23 +1000 Subject: [PATCH 2/3] Added logo to login page --- html/pages/logon.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/html/pages/logon.inc.php b/html/pages/logon.inc.php index e9819b1b01..bffc411f8f 100644 --- a/html/pages/logon.inc.php +++ b/html/pages/logon.inc.php @@ -3,6 +3,7 @@ if( $config['twofactor'] && isset($twofactorform) ) { echo twofactor_form(); } else { ?> +
LibreNMS Logo
From d3a55b42f475a5b8a272e9013dd456f935d84db3 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Tue, 2 Jun 2015 12:26:56 +1000 Subject: [PATCH 3/3] Revert "Added logo to login page" This reverts commit c5ed14fb91185d2458382d217eb911d4ace51df1. --- html/pages/logon.inc.php | 1 - 1 file changed, 1 deletion(-) diff --git a/html/pages/logon.inc.php b/html/pages/logon.inc.php index bffc411f8f..e9819b1b01 100644 --- a/html/pages/logon.inc.php +++ b/html/pages/logon.inc.php @@ -3,7 +3,6 @@ if( $config['twofactor'] && isset($twofactorform) ) { echo twofactor_form(); } else { ?> -
LibreNMS Logo