Template variable expansion vs $obj

Hello!,

I’m trying to implement a new transport, and want to move as much as possible to templates. Can anybody confirm if all the variables available in the transport as $obj[‘var’] should be available within templates?.

I’m trying to figure why {{ $alert->rule }} doesn’t expand, but $obj[‘rule’] does

[email protected]:~> ./validate.php

Component Version
LibreNMS 22.8.0
DB Schema 2022_07_19_081224_plugins_unique_index (244)
PHP 8.1.10
Python 3.6.15
Database MariaDB 10.6.8-MariaDB
RRDTool 1.7.0
SNMP 5.7.3

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

[OK] Composer Version: 2.4.1
[OK] Dependencies up-to-date.
[OK] Database connection successful
[OK] Database Schema is current
[OK] SQL Server meets minimum requirements
[OK] lower_case_table_names is enabled
[OK] MySQL engine is optimal
[OK]
[OK] Database schema correct
[OK] MySQl and PHP time match
[OK] Active pollers found
[OK] Dispatcher Service not detected
[OK] Locks are functional
[OK] Python poller wrapper is polling
[WARN] Using database for locking, you should set CACHE_DRIVER=redis
[OK] rrd_dir is writable
[OK] rrdtool version ok
[WARN] Your install is over 24 hours out of date, last update: Tue, 06 Sep 2022 21:43:51 +0000
[FIX]:
Make sure your daily.sh cron is running and run ./daily.sh by hand to see if there are any errors.

The template has already been run by the time the transport is called.

Why would you need to access transport variables within the template? Doing that would make a template locked to a transport, breaking with other transports.

Hello!, is the other way around. I would like to include rule ID in the message. According to the documentation (Templates - LibreNMS Docs) $alert->rule should be available in a template, but doesn’t seem to be the case.

If I define in the template {{ $alert-> rule }} within the template, the ID is not passed to the transport.

Perhaps a bug?

PR sent as Fix reference to Rule ID by ciroiriarte · Pull Request #14344 · librenms/librenms · GitHub