Important! This fix is not applicable to later versions of LibreNMS. Please refer to the article comments below. (Updated February 2019)
At the moment, LibreNMS only allows for triggering reliable alerts on single CPU devices. If a system has multiple CPU’s, and you set up an alert rule using processors.processor_usage, it will not trigger on average CPU utilization, but rather trigger if any one CPU matches the set criteria. This is a problem when you’re monitoring multi-core servers. To work around it, I’ve made this hack.
When you create an alert rule it basically generates and stores an SQL statement in the database, which is checked every time LibreNMS polls a device. But the GUI does not allow for complex statements, such as calculating an average value. So my solution is to simply create a more complex statement and insert it directly into the database.
While this approach seems to work as intended, the downside is that you’re unable to edit the rule from the GUI after inserting it. So once you’ve inserted it, you’ll have to delete it and insert a new one if you want to make adjustments to it. If you make any changes to it from the GUI, the rule will break upon saving.
I’ve created a statement generator which puts together the SQL statement. And if you’re unfamiliar with editing SQL databases, here’s a step by step guide on how to apply this rule to your LibreNMS installation.
This assumes that you have command line access to your server, and know the MySQL database username and password. You can find it in the top of your config.php file, or by running this command:
cat /opt/librenms/config.php | grep db_
Generate a SQL statement
Generate a custom statement using this generator.
Log in to the MySQL/MariaDB server
And enter the database password when prompted.
mysql -h <hostname> -u <username> -p
Insert the SQL statement
Copy and paste the SQL statement from the generator into the MySQL command line prompt, and press enter. If you’re successful, the output message will be “Query OK, 1 row affected”.
Exit the MySQL CLI by entering “exit”.
Your new rule should now be listed in the Alert Rules list.
If you only want this rule to apply to devices matching a certain criteria, you can use Rule Mapping to set up additional rules.