Merge pull request #1721 from f0o/issue-1478

Add basic Pushbullet transport.
This commit is contained in:
Neil Lathwood 2015-08-24 19:37:50 +01:00
commit 065ad345c6
4 changed files with 79 additions and 0 deletions

View File

@ -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(
```
~~
## <a name="transports-pushbullet">Pushbullet</a>
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';
```
~~
# <a name="entities">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 <tablename>`.

View File

@ -799,6 +799,25 @@ echo '<div id="boxcar_appkey_template" class="hide">
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#pushbullet_transport_expand">Pushbullet</a> <button name="test-alert" id="test-alert" type="button" data-transport="pushbullet" class="btn btn-primary btn-xs pull-right">Test transport</button>
</h4>
</div>
<div id="pushbullet_transport_expand" class="panel-collapse collapse">
<div class="panel-body">
<div class="form-group has-feedback">
<label for="pushbullet" class="col-sm-4 control-label">Pushbullet Access Token </label>
<div data-toggle="tooltip" title="'.$config_groups['alert.transports.pushbullet']['config_descr'].'" class="toolTip glyphicon glyphicon-question-sign"></div>
<div class="col-sm-4">
<input id="pushbullet" class="form-control" type="text" name="global-config-input" value="'.$config_groups['alert.transports.pushbullet']['config_value'].'" data-config_id="'.$config_groups['alert.transports.pushbullet']['config_id'].'">
<span class="glyphicon form-control-feedback" aria-hidden="true"></span>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
';

View File

@ -0,0 +1,47 @@
/* Copyright (C) 2015 Daniel Preussker <f0o@librenms.org>
* 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 <http://www.gnu.org/licenses/>. */
/**
* Pushbullet API Transport
* @author f0o <f0o@librenms.org>
* @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;

1
sql-schema/064.sql Normal file
View File

@ -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');