Alert template array fields


Component Version
LibreNMS 1.44-38-gef13cd2
DB Schema 269
PHP 7.0.32-0ubuntu0.16.04.1
MySQL 10.0.36-MariaDB-0ubuntu0.16.04.1
RRDTool 1.5.5


[OK] Composer Version: 1.7.2
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct
[WARN] IPv6 is disabled on your server, you will not be able to add IPv6 devices.

I have been working on the new template syntax and have been having some difficulties adapting them to my needs. Mainly, I don’t know all of the fields that are available to me. Is there a way to dump the alert array to a list to see the column/field names that can be used? Or am I missing something obvious?

I’ve tried looking over the various fields in the mysql database but they don’t always match up (e.g. $alert->faults or $alert->elapsed)

Please forgive my ignorance on this. I’ve only started working with the anything other than the default template in the past couple of weeks. And, as always, thank you for your help.

In the template {{ var_export($alert, 1) }}

1 Like

Thank you, I’ll try this and report back.

Do I need to put this in some sort of foreach statement to cycle through it?

I tried just pasting {{ var_export($alert, 1) }} at the end of my template and it stops the template from working. Once I remove the above line, the template works again.

Try this:
@php var_export($alert, 1) @endphp

hmm, not having any luck.

I tried you second suggestion. Basically, I added it to an existing test template that is assigned to a specific rule for disk space usage. I then keep changing the criteria of the rule to trigger the alert. But the array contents are not getting dumped. This could be just me not doing it right.

Alert Rule:
SELECT * FROM devices,storage WHERE (devices.device_id = ? AND devices.device_id = storage.device_id) AND storage.storage_perc > 90

Alert Template (Work in progress):
{{ $alert->title }}

@php var_export($alert, 1) @endphp
Severity: {{ $alert->severity }}

@if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }} @endif
Timestamp: {{ $alert->timestamp }}

Alert-ID: {{ $alert->id }}

Rule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif

@if ($alert->faults) Faults:
@foreach ($alert->faults as $key => $value)
{{ $key }}: {{ $value[‘string’] }}

@if ($alert->faults) Faults:

@foreach ($alert->faults as $key => $value)<img src="{{ $value[‘device_id’] }}&type=storage_usage&width=459&height=213&lazy_w=552&from=end-72h>

https://REMOVED/graphs/id={{ $value[‘device_id’] }}/type=storage_usage/

Template: Storage alert


And now don’t I feel foolish! I found the list of placeholders… right in the documentation.

Haha. Thank you anyway for the help.