Alert values for printer_supplies - exposed in $alert->faults?

I have been looking at this for a few days and no luck in finding the issue. Grrr

I have had a working alert template to let me know when printer toner goes below 2% that worked fine when referencing against the “toner” table but now that it has changed to “printer_supplies” I can’t seem to get it to work. Specifically {{ $value['printer_supplies.supply_descr'] }} does not pull the value into the template for the e-mail. I have it surrounded by a @foreach

For clarity here are the lines where it is not working:

@foreach ($alert->faults as $key => $value)
	<tr>
		@if ($alert->transport == mail) 
			<td align="center"><a href="https://librenms/device/device={{ $alert->hostname }}/">{{ $alert->hostname }}</a></td>
		 @else 
			<td align="center">{{ $alert->hostname }}</td>
		 @endif 
			<td align="center"><font color=orange>{{ $value['printer_supplies.supply_descr'] }}</td>
		@if ($alert->state == 1) 
			<td align="center"><font color=red>{{ $value['printer_supplies.supply_current'] }}%</td>
		 @else 
			<td align="center"><font color=green>{{ $value['printer_supplies.supply_current'] }}%</td>
		 @endif 
		<font color=black>
	</tr>
 @endforeach 	

This is what it used to look like:

image
and here is what I am currently receiving:
image

Pretty sure I have the names right… maybe a typo I am not seeing? Or maybe they weren’t exposed to the faults loop? Here is the table I am checking against:

MariaDB [librenms]> select devices.hostname, printer_supplies.supply_descr, printer_supplies.supply_current, printer_supplies.supply_type from devices, printer_supplies WHERE (devices.device_id = printer_supplies.device_id ) AND printer_supplies.supply_type = "tonerCartridge" ;
    +----------------+--------------------------------+----------------+----------------+
    | hostname       | supply_descr                   | supply_current | supply_type    |
    +----------------+--------------------------------+----------------+----------------+
    ...
    | 192.168.2.178  | Black Cartridge 81X HP CF281X. |            2   | tonerCartridge |
    ...
    +----------------+--------------------------------+----------------+----------------+
    16 rows in set (0.001 sec)

Let me know if you see something I missed - thank you!!

Hi @Tadpole
DB data is not automatically exposed in alerts. To find out what is available, you can use the test scripts for alerts and templates :

librenms@monitoring1:~$ ./scripts/test-alert.php 

Info:
    Use this to send an actual alert via transports that is currently active.
Usage:
    -r Is the Rule ID.
    -h Is the device ID or hostname
    -d Debug

Example:
./scripts/test-alert.php -r 4 -d -h localhost

and for templates :

librenms@monitoring1:~$ ./scripts/test-template.php 

Usage:
    -t Is the template ID.
    -h Is the device ID or hostname
    -r Is the rule ID
    -p Is the transport name (optional)
    -s Is the alert state <0|1|2|3|4> (optional - defaults to current state.)
       0 = ok, 1 = alert, 2 = acknowledged, 3 = got worse, 4 = got better
    -d Debug

Example:
./scripts/test-template.php -t 10 -d -h localhost -r 2 -p mail

If the data is indeed missing, a few options :

Thanks @PipoCanaja - I was able to get this working turns out I was putting too much so rather than printer_supplies.supply_descr just supply_desc will suffice. In case anyone is looking for an alert template for reporting printer supplies, here is the entire template. (Caveat: I haven’t been able to get the “Alerts sent to” section to work yet… will post that question later)

<div style="font-family:Helvetica;">
@if ($alert->state == 1) <span style="color:DarkOrchid;">{{ $alert->severity }} @endif 
@if ($alert->state == 2) <span style="color:goldenrod;">Low Toner Acknowledged @endif 
@if ($alert->state == 3) <span style="color:DarkKhaki;">Low Toner Recovering @endif 
@if ($alert->state == 0) <span style="color:green;">Toner Replaced @endif 
</span></b>
<br><br>
@if ($alert->faults) 
<table border="1" width="60%">
        <col style="width:40%">
	<col style="width:10%">
	<col style="width:10%">
<thead>
	<tr>
		<th>Printer Name</th>
		<th>Toner</th>
		<th>Toner Available</th>
	</tr>
	</thead>
	<tbody>
	@foreach ($alert->faults as $key => $value)
		<tr>
			@if ($alert->transport == "mail") 
				<td align="center"><a href="https://librenms/device/device={{ $alert->hostname }}/">{{ $alert->hostname }}</a></td>
			 @else 
				<td align="center">{{ $alert->hostname }}</td>
			 @endif 
				<td align="center"><font color=orange>{{ $value['supply_descr'] }}</td>
			@if ($alert->state == 1) 
				<td align="center"><font color=red>{{ $value['supply_current'] }}%</td>
			 @else 
				<td align="center"><font color=green>{{ $value['supply_current'] }}%</td>
			 @endif 
			<font color=black>
		</tr>
	 @endforeach 	
	</tbody>

</table><br>
@foreach ($alert->faults as $key => $value)
<b>Device: </b>{{ $value['sysName'] }} <br>
@endforeach 
@if ($alert->location) 
<b>Location:</b> {{ $alert->location }}<br>
 @else 
<b>Location:</b> LOCATION NOT DEFINED YET!!<br>
@endif <br>
@if ($alert->alert_notes) 
<b>Notes:</b> {{ $alert->alert_notes }}<br>
@endif 
<b>Uptime:</b> {{ $alert->uptime_long }}<br>
<b>Duration:</b> {{ $alert->elapsed }}<br>
@if ($alert->description) 
<b>Description:</b> {{ $alert->description }}<br>
 @endif 
@foreach ($alert->faults as $key => $value)
<br><br>
<img src="https://librenms/graph.php?width=459&height=213&lazy_w=552&from=end-30d&device={{ $value['device_id'] }}&type=device_toner&legend=yes"><br>
<br><br>
 @endforeach 
 @endif 
<br>
<B>Alerts sent to:</b> 
Alert sent to:
@foreach ($alert->contacts as $key => $value)
  {{ $value }} <{{ $key }}>
@endforeach
1 Like

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