Support for other sensors in alert template

Good day,

We have multiple UPS devices in different locations. While alerting in LibreNMS works great, I would like to include more information when a UPS switches to battery — such as the load, battery charge, remaining runtime, and % load.

The challenge I’m facing is that these sensors are not triggered, so they don’t appear in the faults section. I’ve tried pulling the information from the device parameters, but without success. After some experimenting (and struggling with ChatGPT and Copilot), I’ve learned that LibreNMS evaluates alerts at the sensor level, which makes it difficult to include data from other sensors in the same alert.

Has anyone found a way to get this additional information only when the UPS is on battery or not online?

If you have a look in your override SQL you might see something like

SELECT * FROM devices,sensors WHERE (devices.device_id = ? AND devices.device_id = sensors.device_id) AND (sensors.sensor_current = 3 AND sensors.sensor_type = “upsBasicOutputStatus”)

If you stuff that into mySQL with your device_id you see all the fields returned .. now you basically just need to write a SQL query that returns the rows you want when those conditions are met (and has that device_id = ? thing)

That probably doesn’t make much sense? Hope it helps

I Managed to create a macro that sees if the ups is on battery or not.
and if it is then all sensors are triggert. The comando is this:

lnms config:set alert.macros.rule.device_ups_on_battery “(
SELECT 1
FROM sensors
WHERE sensors.device_id = devices.device_id
AND sensors.sensor_type = ‘upsBasicOutputStatus’
AND sensors.sensor_current = 3
)”

You have to fill this out in the commandline of librenms in the host.
the device id is important because now not only the sensor is selected but the whole ups and now all other sensors report because of ups itself is in “fault“ or the macro is true.

then i set for all other sensors the values so high or low that thy always trigger.

The alert trigger sql is this:
SELECT * FROM devices,sensors WHERE (devices.device_id = ? AND devices.device_id = sensors.device_id) AND ((sensors.sensor_class = “Load” AND sensors.sensor_type = “apc” AND sensors.sensor_current >= 0) OR (sensors.sensor_type = “apc” AND sensors.sensor_class = “power” AND sensors.sensor_current >= 0) OR (sensors.sensor_descr = “Battery Charge” AND sensors.sensor_current < 101) OR (sensors.sensor_type = “upsBasicOutputStatus” AND (sensors.sensor_current != 2 OR sensors.sensor_current = 3)) OR (sensors.sensor_descr = “Runtime” AND sensors.sensor_current >= 0)) AND ((
SELECT 1
FROM sensors
WHERE sensors.device_id = devices.device_id
AND sensors.sensor_type = ‘upsBasicOutputStatus’
AND sensors.sensor_current = 3
) = 1)

one example of the output that i get:

Alert for device APC UPS 750 - APC UPS Switched to Battery Power

Device Information:

  • Display Name: APC UPS 750
  • SysName: apc4bf4ba
  • IP: 10.1.50.205
  • Location: Rack 05
  • Uptime: 5d 4h 5m

Alert Details:

  • Severity: warning
  • Timestamp: 2025-12-19 12:10:12
  • Rule: APC UPS Switched to Battery Power
  • Description:

Faults (Triggered Sensors):

#1: Battery Charge
Current: 38.4%
Previous: 51.6%

#2: Load(VA)
Current: 17.5%
Previous: 18.5%

#3: Active Power
Current: 69W
Previous: 71W

#4: Runtime
Current: 25.116666666667Min
Previous: 32.9Min

#5: Output Status
Current: 3
Previous: 2

Output Status:
On Battery

This is the Transport that i created

{{ $alert->title }}

Device Information:

  • Display Name: {{ $alert->display }}
  • SysName: {{ $alert->sysName }}
  • Hardware: {{ $alert->hardware }}
  • OS: {{ $alert->os }}
  • IP: {{ $alert->hostname }}
  • Location: {{ $alert->location }}
  • Uptime: {{ $alert->uptime_short }}

Alert Details:

  • Severity: {{ $alert->severity }}
  • Timestamp: {{ $alert->timestamp }}
    @if ($alert->state == 0)
  • Time elapsed: {{ $alert->elapsed }}
    @endif
  • Rule: {{ $alert->name ?? $alert->rule }}
  • Description: {{ $alert->description }}
  • Features: {{ $alert->features }}
  • Notes: {{ $alert->notes }}

Faults (Triggered Sensors):

@if ($alert->faults)
@foreach ($alert->faults as $key => $value)
@php($unit = __(“sensors.${value[“sensor_class”]}.unit”))
#{{ $key }}: {{ $value[‘sensor_descr’] ?? ‘Sensor’ }}
Current: {{ $value[‘sensor_current’].$unit }}
Previous: {{ $value[‘sensor_prev’].$unit }}

@if ($value[‘sensor_descr’] == ‘Output Status’)
Output Status:
@switch($value[‘sensor_current’])
@case(1) Unknown @break
@case(2) On Line @break
@case(3) On Battery @break
@case(4) On Smart Boost @break
@case(5) Timed Sleeping @break
@case(6) Software Bypass @break
@case(7) Off @break
@case(8) Rebooting @break
@case(9) Switched Bypass @break
@case(10) Hardware Failure Bypass @break
@case(11) Sleeping Until Power Return @break
@case(12) On Smart Trim @break
@case(13) Eco Mode @break
@case(14) Hot Standby @break
@case(15) On Battery Test @break
@case(16) Emergency Static Bypass @break
@case(17) Static Bypass Standby @break
@case(18) Power Saving Mode @break
@case(19) Spot Mode @break
@case(20) eConversion @break
@case(21) Charger Spotmode @break
@case(22) Inverter Spotmode @break
@default - Unknown

@endswitch
@endif
@endforeach
@endif

I hope it helps somebody to create alerts for their ups

sidenote! this are APC upsses so mayby other upsses use different values

sorry i copyed the wrong sql

((sensors.sensor_class = “Load” AND sensors.sensor_type = “apc” AND sensors.sensor_current >= 0) OR (sensors.sensor_type = “apc” AND sensors.sensor_class = “power” AND sensors.sensor_current >= 0) OR (sensors.sensor_descr = “Battery Charge” AND sensors.sensor_current < 101) OR (sensors.sensor_type = “upsBasicOutputStatus” AND (sensors.sensor_current != 2 OR sensors.sensor_current = 3)) OR (sensors.sensor_descr = “Runtime” AND sensors.sensor_current >= 0)) AND (macros.device_ups_on_battery = 1)

this is the right one

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