Template Variables not working in Alert Template

Hi,

We are having trouble with variables in running templates. As you can see in te test-template below.
The templates and alert definitions were working ok up to feb 18th.

Linux Version:
CENTOS 3.10.0-862.6.3.el7.x86_64 #1 SMP Tue Jun 26 16:32:21 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Validate:
./validate.php

Component Version
LibreNMS 1.48.1-70-g2eac72d
DB Schema 2019_01_16_195644_add_vrf_id_and_bgpLocalAs (131)
PHP 7.2.6
MySQL 5.5.56-MariaDB
RRDTool 1.4.8
SNMP NET-SNMP 5.7.2

====================================

[OK] Composer Version: 1.8.4
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database schema correct

Template Test
./scripts/test-template.php -t 10 -d -h 192.0.1.127 -r 64 -p mail
SQL[SELECT device_id FROM devices WHERE hostname = ? [“192.0.1.127”] 0.42ms]

SQL[SELECT alerts.id, alerts.device_id, alerts.rule_id, alerts.state, alerts.note, alerts.info FROM alerts WHERE alerts.device_id=406 && alerts.rule_id=64 [] 0.39ms]

SQL[SELECT alert_log.id,alert_log.rule_id,alert_log.device_id,alert_log.state,alert_log.details,alert_log.time_logged,alert_rules.rule,alert_rules.severity,alert_rules.extra,alert_rules.name,alert_rules.builder FROM alert_log,alert_rules WHERE alert_log.rule_id = alert_rules.id && alert_log.device_id = ? && alert_log.rule_id = ? && alert_rules.disabled = 0 ORDER BY alert_log.id DESC LIMIT 1 [406,64] 3.39ms]

SQL[SELECT DISTINCT a.* FROM alert_rules a
LEFT JOIN alert_device_map d ON a.id=d.rule_id
LEFT JOIN alert_group_map g ON a.id=g.rule_id
LEFT JOIN device_group_device dg ON g.group_id=dg.device_group_id
WHERE a.disabled = 0 AND ((d.device_id IS NULL AND g.group_id IS NULL) OR d.device_id=? OR dg.device_id=?) [406,406] 1.18ms]

SQL[SELECT hostname, sysName, sysDescr, sysContact, os, type, ip, hardware, version, purpose, notes, uptime, status, status_reason, locations.location FROM devices LEFT JOIN locations ON locations.id = devices.location_id WHERE device_id = ? [406] 0.34ms]

SQL[SELECT * FROM devices_attribs WHERE device_id = ? [406] 0.35ms]

SQL[select * from device_perf where device_id = ? order by timestamp desc limit 1 [406] 6.66ms]

SQL[select * from alert_templates where exists (select * from alert_template_map where alert_templates.id = alert_template_map.alert_templates_id and alert_rule_id = ?) limit 1 [64] 0.37ms]

Array
(
[hostname] => 192.0.1.127
[sysName] => SITE 1 (Blindex Pasillo)
[sysDescr] =>
[sysContact] =>
[os] => ping
[type] => server
[ip] =>
[hardware] =>
[version] =>
[location] => Casa Central
[uptime] =>
[uptime_short] =>
[uptime_long] =>
[description] =>
[notes] => infra
[alert_notes] =>
[device_id] => 406
[rule_id] => 64
[status] => 0
[status_reason] => icmp
[ping_timestamp] =>
[ping_loss] => 0
[ping_min] => 0
[ping_max] => 0
[ping_avg] => 0
[debug] => Array
(
)

[title] => Alerta %sysName DOWN
[faults] => Array
    (
        [1] => Array
            (
                [device_id] => 406
                [hostname] => 192.0.1.127
                [sysName] => SITE 1 (Blindex Pasillo)
                [ip] =>
                [community] =>
                [authlevel] =>
                [authname] =>
                [authpass] =>
                [authalgo] =>
                [cryptopass] =>
                [cryptoalgo] =>
                [snmpver] => v2c
                [port] => 161
                [transport] => udp
                [timeout] =>
                [retries] =>
                [snmp_disable] => 1
                [bgpLocalAs] =>
                [sysObjectID] =>
                [sysDescr] =>
                [sysContact] =>
                [version] =>
                [hardware] =>
                [features] =>
                [location_id] => 5
                [os] => ping
                [status] => 0
                [status_reason] => icmp
                [ignore] => 0
                [disabled] => 0
                [uptime] =>
                [agent_uptime] => 0
                [last_polled] => 2019-02-19 19:32:08
                [last_poll_attempted] =>
                [last_polled_timetaken] => 1.03
                [last_discovered_timetaken] =>
                [last_discovered] =>
                [last_ping] => 2019-02-19 19:32:08
                [last_ping_timetaken] => 1.77
                [purpose] =>
                [type] => server
                [serial] =>
                [icon] =>
                [poller_group] => 0
                [override_sysLocation] => 1
                [notes] => infra
                [port_association_mode] => 1
                [max_depth] => 0
                [string] => location_id = 5; override_sysLocation = 1;
            )

    )

[elapsed] => 1h 20m 51s
[builder] => {"condition":"OR","rules":[{"id":"macros.device_down","field":"macros.device_down","type":"integer","input":"radio","operator":"equal","value":"1"}],"valid":true}
[uid] => 55408
[alert_id] => 3448
[severity] => critical
[rule] =>
[name] => Devices up/down
[timestamp] => 2019-02-19 19:36:53
[contacts] => Array
    (
        [[email protected]] =>
    )

[state] => 1
[transport] => mail
[msg] => Alerta %sysName DOWN

Severidad: critical
Hora Evento: 2019-02-19 19:36:53
Unique-ID: 55408
SysName: SITE 1 (Blindex Pasillo)
Sitio: Casa Central
Descrip:
Regla: Devices up/down
)

Hope someone can tell us how to fix this.

Thanks in advance,

Eugenio

Hi @maeseoli

All the explanations are here, this is an announced change from October 2018 with application in Feb 2019 :

Bye
PipoCanaja

Pipo,

Thanks for the note.
I will explain thoroughly, our templates where updated long, long, long time ago (oct/2018). And they alll where working until feb 17th/18th.

Here you have an example of one of the templates:

{{ $alert->title }}
Sevidad: {{ $alert->severity }}
@if ($alert->state == 0) Tiempo Transcurrido: {{ $alert->elapsed }} @endif
Hora Evento: {{ $alert->timestamp }}
Unique-ID: {{ $alert->uid }}
SysName: {{ $alert->sysName }}
Sitio: {{ $alert->location }}
Descrip: {{ $alert->sysDescr }}
Regla: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif
@if ($alert->faults) 

Fallas:
@foreach ($alert->faults as $key => $value)
  #{{ $key }}: {{ $value['string'] }}
@endforeach
@endif

Alertas enviadas a:
@foreach ($alert->contacts as $key => $value)
  {{ $value }} <{{ $key }}>
@endforeach

Alert Msg: NMS ALERTA - Host DOWN (%sysName - %hostname)
Recvery Msg: NMS ALERTA - Host UP (%sysName - %hostname)

Hope this clarification note fills the help requirement gap.

Yours,
Eugenio

The subject needs changing as well -
Alert Msg: ({{ $alert->hostname }}) - NEW ALERT

1 Like

Thank you John!

The problem was with the template converter/update/wizard provided, it did not check on subjects.