We want to simplify the content of emails from alert State Sensor Critical.
Here’s an example of the content with the default template:
Alert for device - State Sensor Critical
Severity: critical
Timestamp: 2019-12-10 16:15:21
Unique-ID: 100
Rule: State Sensor Critical Faults:
#1: sysObjectID = .1.3.6.1.4.1.9.1.1745; sysDescr = Cisco IOS Software,
IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M),
Version 03.06.06E RELEASE SOFTWARE (fc1)
Technical Support: Support - Cisco Support and Downloads – Documentation, Tools, Cases - Cisco
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Sat 17-Dec-; location_id = 5; override_sysLocation = 1; sensor_id =
75; sensor_oid = .1.3.6.1.4.1.9.9.117.1.1.2.1.2.1001; sensor_descr = Switch
1 - Power Supply A Container; state_descr = off (other);
Alert sent to:
To avoid obfuscation, we want to change that to something like:
1 - Power Supply A Container; state_descr = off (other);
Timestamp: 2019-12-10 16:15:21
Rule: State Sensor Critical
We created a custom template:
{{ $alert->title }}
@if ($alert->faults) Faults:
@foreach ($alert->faults as $key => $value)
{{ $key }}: {{ $value[‘string’] }}
@endforeach
@endif
@if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }} @endif
Timestamp: {{ $alert->timestamp }}
Rule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif
That resulted in:
Alert for device edge1-mgt.iciti.av - State Sensor Critical
Faults:
1: sysObjectID = .1.3.6.1.4.1.14988.1; sysDescr = RouterOS
CCR1009-7G-1C-1S+; override_sysLocation = 1; sensor_id = 102; sensor_oid =
.1.3.6.1.4.1.14988.1.1.3.16.0; sensor_descr = Backup PSU; state_descr =
false; Timestamp: 2019-12-17 12:20:11
Rule: State Sensor Critical
We should be competent to refine that except for line “sysObjectID = .1.3.6.1.4.1.14988.1; sysDescr = RouterOS CCR1009-7G-1C-1S+; override_sysLocation = 1; sensor_id = 102; sensor_oid = .1.3.6.1.4.1.14988.1.1.3.16.0; sensor_descr = Backup PSU; state_descr = false;”
From https://docs.librenms.org/Alerting/Templates:
Faults, Only available on alert ($alert->state != 0), must be iterated in a foreach (@foreach ($alert->faults as $key => $value) @endforeach). Holds all available information about the Fault, accessible in the format $value[‘Column’], for example: $value[‘ifDescr’]. Special field $value[‘string’] has most Identification-information (IDs, Names, Descrs) as single string, this is the equivalent of the default used and must be encased in {{ }}
Presumably the (IDs, Names, Descrs) are device specific so we can not, in general, output only the ones we want such as $value[‘ifDescr’]. So we need to print all values except for the ones we do not want such as sysObjectID, sysDescr, override_sysLocation … .
I cannot imagine any way to do that other than by iterating $value.
Is there a better solution? If not, can $value be iterated?
Best
Charles