Created
August 29, 2018 08:10
-
-
Save angryp/d5cdb8d912b0315b9627b08630523143 to your computer and use it in GitHub Desktop.
Alert acknowledgement for LibreNMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* LibreNMS | |
* | |
* Copyright (c) 2018 Olegs Vasiljevs <https://github.com/angryp> | |
* | |
* 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. | |
* | |
* Place this in html directory of your LibreNMS install path. | |
* | |
* Usage: | |
* open https://your.librenms.address/ack.php?rule_id=1&device_id=1 | |
* where rule_id and device_id are variables that should be expanded from | |
* alert template in LibreNMS. | |
*/ | |
$base_url = 'https://your.librenms.address/api/v0/alerts'; | |
$rule_id = $_GET['rule_id']; | |
$device_id = $_GET['device_id']; | |
$alert_id = ""; | |
$url = ($base_url . '?state=1'); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Token: YourLibreNMSAPITokenHere')); | |
$output = json_decode(curl_exec($ch), true); | |
for($x=0; $x<count($output['alerts']); $x++){ | |
if($output['alerts'][$x]['device_id']==$device_id and $output['alerts'][$x]['rule_id']==$rule_id){ | |
$alert_id = ($output['alerts'][$x]['id']); | |
} | |
} | |
$url = ($base_url . '/' . $alert_id); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_PUT, true); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Token: YourLibreNMSAPITokenHere')); | |
$output = json_decode(curl_exec($ch), true); | |
if($output['message'] == "This API route doesn't exist."){ | |
echo "This alert is not active anymore."; | |
} else { | |
print($output['message']); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment