Don't show ifInOctets_rate content in alert mail

Hi all. I need to monitoring Bandwidth port traffic. I tried Alert function and it worked.


But when I sent mail use this Alert Template. The mail don’t have any contents about ifInOctets_rate and ifOutOctets_rate
So what is wrong with me. [The template]

> Devices: {{ $alert->hostname }} 
> Rule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif
> Physical Interface: {{$value['ifDescr']}}
> Interface Description: {{ $value }}
> Inbound Utilization: {{ (($value['ifInOctets_rate'])) }}
> Outbound Utilization: {{ (($value['ifOutOctets_rate']*8)/$value['ifSpeed'])*100 }}
> ---------------------------
> Timestamp: {{ $alert->timestamp }}
> Uptime: {{ $alert->uptime_long }}

The email I received.
image

Use standaart template inside libreNMS itself will help

https://docs.librenms.org/Alerting/Templates/

@ foreach

Ports Utilization Template:

{{ $alert->title }}
Device Name: {{ $alert->hostname }}
Severity: {{ $alert->severity }}
@if ($alert->state == 0) Time elapsed: {{ $alert->elapsed }} @endif
Timestamp: {{ $alert->timestamp }}
Rule: @if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif
    @foreach ($alert->faults as $key => $value)
    Physical Interface: {{ $value['ifDescr'] }}
    Interface Description: {{ $value['ifAlias'] }}
    Interface Speed: {{ ($value['ifSpeed']/1000000000) }} Gbs
    Inbound Utilization: {{ (($value['ifInOctets_rate']*8)/$value['ifSpeed'])*100 }}
    Outbound Utilization: {{ (($value['ifOutOctets_rate']*8)/$value['ifSpeed'])*100 }}
@endforeach
1 Like

You need to @foreach over the $alert->faults array. As shown in the template.

I pasted the template. But I dont know why it still didn’t work. I’m not sure the data has been queried from the DB or not.
This is new result.

LibreNMSxxxxxxxxxxxxxxxxx - NEW ALERT
Device Name: xxx.xxx.xxx.xxx
Severity: critical
Timestamp: 2019-06-13 08:30:37
Rule: Port utilisation over

On Alert capture

And when I queried it on mysql

Blockquote
Database changed
MariaDB [librenms]> SELECT * FROM devices,ports WHERE (devices.device_id = ? AND devices.device_id = ports.device_id) AND (((ports.ifInOctets_rate*8) / ports.ifSpeed)100) != 80;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? AND devices.device_id = ports.device_id) AND (((ports.ifInOctets_rate
8) / por’ at line 1

I found issues already. Having sthing wrong when I query in mysql.
so now my solution

Blockquote
SELECT devices.device_id, ports.ifAlias, ports.ifName, ports.ifInOctets_rate, ports.ifOutOctets_rate, ports.ifSpeed FROM devices,ports WHERE (devices.device_id = ports.device_id) AND (((ports.ifInOctets_rate*8) / ports.ifSpeed)*100) >30 AND (ports.ifAlias LIKE “%-P%-%”) AND (ports.ifName LIKE “xe-%”) ;

I query manually. It works.

Would be much easier if you just used the normal builder. Nothing in your query requires an advanced query… Just allows more issues to occur.

1 Like