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;