Alert event when a device is removed

Tags: #<Tag:0x00007fdef7396150>


I’m having trouble getting alerts when a device is removed.

I wish to get a notification in my slack feed and send an HTTP reload request to a different service.

All these alert transports are working correctly, so the issue is somewhere else.

This is the query I wrote and an example output of what I wish to get:

SELECT datetime, device_id, type, username, REGEXP_SUBSTR( message, 'Device \\K\\S+' ) as hostname, message
  FROM eventlog
  WHERE type = "system"
  AND message LIKE 'Device%'
  AND message LIKE '%has been removed';
| datetime            | device_id | type   | username   | hostname            | message                                     |
| 2021-06-04 11:23:10 |         0 | system |  |   | Device has been removed   |

The query works but the problem seems to be the alert system generating one event for each active device every polling cycle.

Since there is no way to join on device_id, because eventlog shows this as 0, (devices.device_id = ?) does not work.

The current behaviour is one notification for every device currently active in my LibreNMS setup, except for the device that was removed.

Even if device_id was set correctly I’m guessing the alert would not work because at run time the device would not exist in the devices table.

Is it possible to accomplish this?

Thanks output:

-bash-4.2$ ./validate.php 
Component | Version
--------- | -------
LibreNMS  | 21.4.0
DB Schema | 2021_04_08_151101_add_foreign_keys_to_port_group_port_table (208)
PHP       | 7.3.26
Python    | 3.6.8
MySQL     | 10.3.27-MariaDB
RRDTool   | 1.7.0
SNMP      | NET-SNMP 5.7.2

[OK]    Composer Version: 2.1.1
[OK]    Dependencies up-to-date.
[OK]    Database connection successful
[OK]    Database schema correct
[INFO]  Detected Python Wrapper
[OK]    Connection to memcached is ok
[WARN]  Global lnms shortcut not installed. lnms command must be run with full path
        sudo ln -s /opt/librenms/lnms /usr/bin/lnms
[WARN]  Bash completion not installed. lnms command tab completion unavailable.
        sudo cp /opt/librenms/misc/lnms-completion.bash /etc/bash_completion.d/