From 515b01c2bd5014f35a8eb69b3feb11016a5af3c6 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 19 Aug 2015 19:03:26 +0000 Subject: [PATCH 1/3] Add basic Pushbullet transport. --- doc/Extensions/Alerting.md | 12 ++++++ includes/alerts/transport.pushbullet.php | 47 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 includes/alerts/transport.pushbullet.php diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index aec8ee6e56..92d264e203 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -17,6 +17,7 @@ Table of Content: - [PagerDuty](#transports-pagerduty) - [Pushover](#transports-pushover) - [Boxcar](#transports-boxcar) + - [Pushbullet](#transports-pushbullet) - [Entities](#entities) - [Devices](#entity-devices) - [BGP Peers](#entity-bgppeers) @@ -360,6 +361,17 @@ $config['alert']['transports']['boxcar'][] = array( ``` ~~ +## Pushbullet + +Enabling Pushbullet is a piece of cake. +Get your Access Token from your Pushbullet's settings page and set it in your config like: + +~~ +```php +$config['alert']['transports']['pushbullet'] = 'MYFANCYACCESSTOKEN'; +``` +~~ + # 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.pushbullet.php b/includes/alerts/transport.pushbullet.php new file mode 100644 index 0000000000..c5d75f4ef2 --- /dev/null +++ b/includes/alerts/transport.pushbullet.php @@ -0,0 +1,47 @@ +/* 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 . */ + +/** + * Pushbullet API Transport + * @author f0o + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Alerts + */ + +// Note: At this point it might be useful to iterate through $obj['contacts'] and send each of them a note ? + +$data = array("type" => "note", "title" => $obj['title'], "body" => $obj['msg']); +$data = json_encode($data); + +$curl = curl_init('https://api.pushbullet.com/v2/pushes'); +curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); +curl_setopt($curl, CURLOPT_POSTFIELDS, $data); +curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); +curl_setopt($curl, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: '.strlen($data), + 'Authorization: Bearer '.$opts, +)); + +$ret = curl_exec($curl); +$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); +if( $code > 201 ) { + if( $debug ) { + var_dump($ret); + } + return false; +} +return true; From 325d9cd82bce35ed4e4b1a46b60bd4e9df1fe989 Mon Sep 17 00:00:00 2001 From: f0o Date: Wed, 19 Aug 2015 19:37:41 +0000 Subject: [PATCH 2/3] First attempt to add the WebUI settings --- html/pages/settings/alerting.inc.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index f3a4cf0d3d..ef58465db5 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -799,6 +799,25 @@ echo '
+
+
+

+ Pushbullet +

+
+
+
+
+ +
+
+ + +
+
+
+
+
'; From 103221f76515640cf5dd4af60309c2dec36cc76f Mon Sep 17 00:00:00 2001 From: f0o Date: Mon, 24 Aug 2015 14:59:43 +0100 Subject: [PATCH 3/3] Added Config-SQL --- sql-schema/064.sql | 1 + 1 file changed, 1 insertion(+) create mode 100644 sql-schema/064.sql diff --git a/sql-schema/064.sql b/sql-schema/064.sql new file mode 100644 index 0000000000..13ebbb243d --- /dev/null +++ b/sql-schema/064.sql @@ -0,0 +1 @@ +insert into config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.transports.pushbullet','','','Pushbullet access token','alerting',0,'transports',0,'0','0');