Hello everyone,
I recently started using librenms. I can see that there are really, really a lot of methods to send notifications but I couldn’t find one that I need the most- a script execution.
Is this possible somehow? I would like to pass the variables from an alert to it and handle it with bash myself.
If you are wondering- the end goal is to have alert SMS sent using a gammu server located in the network.
Probably, the reason that doesn’t exist is LibreNMS is open source. People just make a transport when then need something different. See the Hue lighting transport
Hi,
So I decided to use API transport and to write a simple API that will exeute a remote command through PHP.
However I am struggling on properly setting API alerting. The docs says I should be using the same placeholders as I’m using for mailing.
This is my config:
and the result (from log) I am getting is
ssh [email protected] “gammu-smsd-inject -c /etc/gammu-smsdrc TEXT +48666666666 -unicode -text ‘{{$alert->hostname}}$alert->hostname’ -len 10000 -report”.
It just ignores the placeholders.
As soon as I can read the proper string in my api.php I am able to work this out. Can you please advise what I am doing wrong?
<?php
function log_activity($message)
{
$date = date('Y-m-d H:i:s');
error_log("$message.\n", 3, "/var/log/sms-api.log");
}
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
require_once "includes/config.php";
include ('includes/functions.inc.php');
// create SQL based on HTTP method
switch ($method)
{
case 'GET':
{
http_response_code(404);
die();
break;
}
case 'PUT':
{
http_response_code(404);
die();
break;
}
case 'POST':
{
//echo 'request ' . "<br><br><br>";
//var_dump($request);
$sms_body = $request[1];
$sms_body = urldecode($request[1]);
$message = "ssh [email protected] \"gammu-smsd-inject -c /etc/gammu-smsdrc TEXT " . $request[0] . " -unicode -text '" . $sms_body . "' -len 10000 -report\"";
log_activity($message);
//echo exec($message);
echo $message;
break;
}
case 'DELETE':
{
http_response_code(404);
die();
break;
}
}
?>
P.S.
If I use
http://sms.example.com/api.php/+48666666666/%title%hostname/
I am getting HTTP 400 response. Probably due to Percent-encoding - Wikipedia
1 Like
Maybe can someone please show me how you configured the API on your installation?
Anyone? A screenshot/ example of a working API configuration template?