BUG - test-template.php not running after laravel upgrade

Hi,

The ./scripts/test-template.php is not working anymore. It seems that this issue may be linked to the Laravel code merged for alerting recently.

https://p.libren.ms/view/93042510

It is reproducible with any combination of template_id, rule_id and device_id so it is probably a general issue.

What kind of test should I do to help ?

librenms@host:~$ ./validate.php

Component Version
LibreNMS 1.41-24-gad6ec7f72
DB Schema 254
PHP 7.0.30-0+deb9u1
MySQL 10.1.26-MariaDB-0+deb9u1
RRDTool 1.6.0
SNMP NET-SNMP 5.7.3

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

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

Looks like the exception source is in this code in file ./LibreNMS/Alert/Template.php, called from ./includes/alerts.inc.php:

class Template
{
public $template;

public function getTemplate($obj = null)
{
    d_echo($obj);
    if ($this->template) {
        // Return the cached template information.
        return $this->template;
    }

// Generate Exception

$this->template = AlertTemplate::whereHas(‘map’, function ($query) use ($obj) {
$query->where(‘alert_rule_id’, ‘=’, $obj[‘rule_id’]);
})->first();

// End Generate Exception

@PipoCanaja submit the fix to https://github.com/librenms/librenms/pulls :slight_smile:

Hello

I have no idea of the fix. Still trying to understand what’s going on. The best I have done so far is to identify the piece of code up to which the function executes correctly. But I have no clue what this code is doing after…

If somebody who understands this code can try to have a look …

Bye
PipoCanaja

1 Like

What does test-template.php do?

It allows to generate in the CLI the text of an alert/alert_rule/template, during the troubleshooting of the template writing.

With the new syntax, it’s a good way to check if something is broken before missing a mail :wink:

PipoCanaja

Seems very similar to test-alert.php

Does more or less the same, but in CLI instead of using the transport. (and spaming my colleagues in my case :wink: )

Seems that I get it.

Need to cleanup the code but should come with a PR.

Done here

PipoCanaja