Skip to content

Instantly share code, notes, and snippets.

@angryp
Created August 29, 2018 08:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angryp/d5cdb8d912b0315b9627b08630523143 to your computer and use it in GitHub Desktop.
Save angryp/d5cdb8d912b0315b9627b08630523143 to your computer and use it in GitHub Desktop.
Alert acknowledgement for LibreNMS
<?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