Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added transport for Pushover alerting #1180

Merged
merged 3 commits into from Jun 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Expand Up @@ -30,5 +30,6 @@ Contributors to LibreNMS:
- Freddie Cash (fjwcash@gmail.com) (fjwcash)
- Thom Seddon <thom@seddonmedia.co.uk> (thomseddon)
- Vitali Kari <vitali.kari@gmail.com> (vitalisator)
- James Campbell <neokjames@gmail.com> (neokjames)

[1]: http://observium.org/ "Observium web site"
26 changes: 26 additions & 0 deletions doc/Extensions/Alerting.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

## <a name="transports-pushover">Pushover</a>

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',
);
```

# <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>`.
Expand Down
66 changes: 66 additions & 0 deletions includes/alerts/transport.pushover.php
@@ -0,0 +1,66 @@
/* Copyright (C) 2015 James Campbell <neokjames@gmail.com>
* 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/>. */

/* Copyright (C) 2015 Daniel Preussker <f0o@devilcode.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/>. */

/**
* Pushover API Transport
* @author neokjames <neokjames@gmail.com>
* @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;