Alert Template - specify keys and values instead of a ForEach loop

I’ve set up a rule to notify when printer toner is below 10% and it is working.

toner.toner_type = “Toner” AND toner.toner_current < 10

Now I’m working on the corresponding alert template to generate an email with meaningful information. In the default alert template, there’s a @foreach loop that spits out a bunch of information.

@foreach ($alert->faults as $key => $value) #{{ $key }}: {{ $value[‘string’] }}\r\n\n @endforeach

I want to include some of this information - such as printer model (sysDescr) and cartridge description (toner_desc) - but NOT include other information that is not useful to humans - such as the sysObjectID and toner_oid. How can I go about doing that?

here is an easy test script:

$servername = "localhost";
$username = "root";
$password = "your pass";
$dbname = "librenms";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
// CHANGE 1 to your alert ID
$sql = "SELECT details FROM alert_log WHERE id = 1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
} else {
    echo "0 results";

Now u can see all keys u could use for that alert in your template

That looks amazing! Only problem is, I’m not a Linux guru and don’t really know what to do with that. Do I put that in an alert template, or is that something I do at the CLI of the server? I feel like you’ve given me what I need, but I’m too dumb to know what to do with it.


You can replace $value[‘string’] with $value['sysDescr']or any other variable element that is available.

You can use scripts/test-alert.php that will show you your alert, and also the variables that are available.

put is somewhare in your server (CLI)

Make an simple template u desire
whenn the alert goes off:
look what ID it is in alert_log and change it in the script

now where the script is in your server:

php yourscript.php

Or use the test-alert.php ( but i dont know how )