Alert with graph

hey guys , im trying to do an alert via mail which include the graph of the latest 6 hours.
the alert is for port over threshold.

this is my validate.php
bash-4.2$ ./validate.php

Component Version
LibreNMS 21.4.0-66-g37ac9df
DB Schema 2021_04_08_151101_add_foreign_keys_to_port_group_port_table (208)
PHP 7.3.28
Python 3.6.8
MySQL 10.4.18-MariaDB
RRDTool 1.4.8
SNMP NET-SNMP 5.7.2
====================================

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

and this is my alert template :

<div style="font-family:Helvetica;">
<h2><span style="color:red;">Severity: {{ $alert->severity }}</span></h2><br>
{{ $alert->title }} <br>
Severity: {{ $alert->severity }}  <br>
@if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }} @endif
<h1><span style="color:red;"><b>Host:</b> {{ $alert->hostname }}</span></h1><br>
Timestamp: {{ $alert->timestamp }} <br>
<h2><span style="color:black;">Rule:</span><span style="color:red;">@if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif </span></h2><br>
@if ($alert->faults)
@foreach ($alert->faults as $key => $value) <img src="https://servername.com/graph.php?id= $value['port_id'].'/type=port_bits/width=600/height=300/lazy_w=552/from=end-6h'"><br>
<br>
@endforeach
Template: Port over threshold <br>
@endif
<br>
</div>

unnamed

im battling with this image for a week now…cant seem to find what is wrong

all suggestions are welcomed

regards and thanks
Ervin

Could you put your exact template, now that the syntax is properly highlighed ?
Also, this part is clearly wrong :
@foreach ($alert->faults as $key => $value) <img src="https://servername.com/graph.php?id= $value['port_id'].'/type=port_bits/width=600/height=300/lazy_w=552/from=end-6h'"><br>

everytime you want to read a variable in a text, you need {{ and }} . Meaning this would be :
@foreach ($alert->faults as $key => $value) <img src="https://servername.com/graph.php?id={{ $value['port_id'] }}/type=port_bits/width=600/height=300/lazy_w=552/from=end-6h'"><br>

thanks for the prompt reply thats all the template im using
here attaching the following screenshots

this is my first time handling templates.
so the goal is to have at the bottom of the mail the graph of the port which went over the threshold (the rule of the over threshold is left default not changed) .

in the config.php i’ve added the following:

$config[‘allow_unauth_graphs’] = 1;
$config[‘allow_unauth_graphs_cidr’] = array(‘127.0.0.1/32’);

to be able to plot the graph and if i click on the image to open up , but it doesnt

thanks again mate , for the time put into helping me :slight_smile:

The way to do this is to look at the source HTML of the email alert you receive, and check it is exactly as you want it to be.
Check each bit of the URL. graph.php?xxxxxxxx instead of graph.php/xxxxxx, for instance, etc etc.

thank you very much for your advice :
i was able to solve it:

the problem was with the link and the variables:

img src=“https://servername/graph.php?&id={{ $value[‘port_id’] }}&type=port_bits&lazy_w=805&device={{ $value=[‘hostname’] }}&?=yes&height=486&width=1656&from=end-1h”

this is what i needed on my e-mal.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.