mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
alerting: Added Philips Hue as transport (#8320)
* Add Phillips Hue Bridge as Alerting transport * Add Comment * Update Transport docs * Update Phillips to Philips Add sql schema
This commit is contained in:
committed by
Neil Lathwood
parent
9897b5fbd4
commit
a0c2783d27
71
LibreNMS/Alert/Transport/Hue.php
Normal file
71
LibreNMS/Alert/Transport/Hue.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/* Copyright (C) 2018 Paul Heinrichs <pdheinrichs@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/>. */
|
||||
|
||||
/*
|
||||
* API Transport
|
||||
* @author Paul Heinrichs <pdheinrichs@gmail.com>
|
||||
* @copyright 2018 Paul Heinrichs
|
||||
* @license GPL
|
||||
* @package LibreNMS
|
||||
* @subpackage Alerts
|
||||
*/
|
||||
namespace LibreNMS\Alert\Transport;
|
||||
|
||||
use LibreNMS\Interfaces\Alert\Transport;
|
||||
|
||||
/**
|
||||
* The Hue API currently is fairly limited for alerts.
|
||||
* At it's current implementation we can send ['lselect' => "15 second flash", 'select' => "1 second flash"]
|
||||
* If a colour request is sent with it it will permenantly change the colour which is less than desired
|
||||
*/
|
||||
class Hue implements Transport
|
||||
{
|
||||
public function deliverAlert($obj, $opts)
|
||||
{
|
||||
// Don't alert on resolve at this time
|
||||
if ($obj['state'] == 0) {
|
||||
return true;
|
||||
} else {
|
||||
$device = device_by_id_cache($obj['device_id']); // for event logging
|
||||
$hue_user = $opts['user'];
|
||||
$url = $opts['bridge'] . "/api/$hue_user/groups/0/action";
|
||||
$curl = curl_init();
|
||||
$duration = $opts['duration'];
|
||||
$data = array("alert" => $duration);
|
||||
$datastring = json_encode($data);
|
||||
|
||||
set_curl_proxy($curl);
|
||||
|
||||
$headers = array('Accept: application/json', 'Content-Type: application/json');
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $datastring);
|
||||
|
||||
$ret = curl_exec($curl);
|
||||
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($code == 200) {
|
||||
d_echo("Sent alert to Phillips Hue Bridge " . $opts['host'] . " for " . $device);
|
||||
return true;
|
||||
} else {
|
||||
d_echo("Hue bridge connection error: " . serialize($ret));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -459,3 +459,24 @@ $config['alert']['transports']['gitlab']['host'] = 'http://gitlab.host.tld';
|
||||
$config['alert']['transports']['gitlab']['project_id'] = '1';
|
||||
$config['alert']['transports']['gitlab']['key'] = 'AbCdEf12345';
|
||||
```
|
||||
|
||||
## Philips Hue
|
||||
|
||||
Want to spice up your noc life? LibreNMS will flash all lights connected to your philips hue bridge whenever an alert is triggered.
|
||||
|
||||
To setup, go to the you http://`your-bridge-ip`/debug/clip.html
|
||||
|
||||
- Update the "URL:" field to `/api`
|
||||
- Paste this in the "Message Body" {"devicetype":"librenms"}
|
||||
- Press the round button on your `philips Hue Bridge`
|
||||
- Click on `POST`
|
||||
- In the `Command Response` You should see output with your username. Copy this without the quotes
|
||||
|
||||
|
||||
More Info: [Philips Hue Documentation](https://www.developers.meethue.com/documentation/getting-started)
|
||||
|
||||
```php
|
||||
$config['alert']['transports']['hue']['bridge'] = 'http://bridge.example.com';
|
||||
$config['alert']['transports']['hue']['user'] = 'af89jauaf98aj34r';
|
||||
$config['alert']['transports']['hue']['duration'] = 'lselect';
|
||||
```
|
||||
|
@@ -1430,6 +1430,55 @@ echo '
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
// Philips Hue Transport Section
|
||||
|
||||
$hue_bridge = get_config_by_name('alert.transports.hue.bridge');
|
||||
$hue_user = get_config_by_name('alert.transports.hue.user');
|
||||
$hue_duration = get_config_by_name('alert.transports.hue.duration');
|
||||
echo '
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">
|
||||
<a data-toggle="collapse" data-parent="#accordion" href="#hue_transport_expand"><i class="fa fa-caret-down"></i> Philips Hue transport</a> <button name="test-alert" id="test-alert" type="button" data-transport="hue" class="btn btn-primary btn-xs pull-right">Test transport</button>
|
||||
</h4>
|
||||
</div>
|
||||
<div id="hue_transport_expand" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
<div class="form-group has-feedback">
|
||||
<label for="hue_host" class="col-sm-4 control-label">Hue Host</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="hue_host" class="form-control validation" type="url" name="global-config-input" value="'.$hue_bridge['config_value'].'" data-config_id="'.$hue_bridge['config_id'].'" pattern="[a-zA-Z0-9]{1,5}://.*">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="hue_user" class="col-sm-4 control-label">Philips Hue User</label>
|
||||
<div class="col-sm-4">
|
||||
<input id="hue_user" class="form-control" type="text" name="global-config-input" value="'.$hue_user['config_value'].'" data-config_id="'.$hue_user['config_id'].'">
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
<label for="hue_duration" class="col-sm-4 control-label">Philips Hue Duration</label>
|
||||
<div class="col-sm-4">
|
||||
<select id="hue_duration" class="form-control" name="global-config-select" data-config_id="'.$hue_duration['config_id'].'">
|
||||
<option '.( $hue_duration['config_value'] == "select" ? "selected" : ""). ' value="select">1 Second</option>
|
||||
<option '.( $hue_duration['config_value'] == "lselect" ? "selected" : ""). ' value="lselect">15 Seconds</option>
|
||||
</select>
|
||||
<span class="form-control-feedback">
|
||||
<i class="fa" aria-hidden="true"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
|
||||
// Jira Transport Section
|
||||
$jira_prj = get_config_by_name('alert.transports.jira.prjkey');
|
||||
$jira_url = get_config_by_name('alert.transports.jira.url');
|
||||
|
4
sql-schema/240.sql
Normal file
4
sql-schema/240.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
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.hue.bridge','','','Philips Hue Bridge IP','alerting','0','transports','0','0','0');
|
||||
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.hue.user','','','Philips Hue User','alerting','0','transports','0','0','0');
|
||||
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.hue.duration','','lselect','Philips Hue Alert Duration','alerting','0','transports','0','0','0');
|
||||
|
Reference in New Issue
Block a user