2017-06-25 03:27:42 +01:00
source: Alerting/Rules.md
2018-10-27 23:04:34 +01:00
path: blob/master/doc/
2017-06-25 03:27:42 +01:00
2017-08-19 14:40:50 -04:00
# Rules
2019-06-20 13:53:45 -05:00
2017-06-25 03:27:42 +01:00
Rules are defined using a logical language.
2018-03-14 20:25:19 +00:00
The GUI provides a simple way of creating rules.
2019-06-20 13:53:45 -05:00
Creating more complicated rules which may include maths calculations
and MySQL queries can be done using [macros ](Macros.md )
#### Video on how the alert rules work in LibreNMS
2017-06-25 03:27:42 +01:00
2017-10-19 03:22:05 -05:00
[Alert Rules ](https://youtu.be/ryv0j8GEkhM )
2019-06-20 13:53:45 -05:00
2017-10-19 03:22:05 -05:00
#### Video on how to use alert rule with wildcards
2019-06-20 13:53:45 -05:00
2017-10-19 03:22:05 -05:00
[Alert Rules wildcard ](https://youtu.be/eYYioFNcrAk )
2017-08-19 14:40:50 -04:00
## Syntax
2019-06-20 13:53:45 -05:00
2017-06-25 03:27:42 +01:00
Rules must consist of at least 3 elements: An __Entity__ , a __Condition__ and a __Value__ .
Rules can contain braces and __Glues__ .
2018-03-14 20:25:19 +00:00
__Entities__ are provided from Table and Field from the database. For Example: `ports.ifOperStatus` .
2019-06-20 13:53:45 -05:00
2017-06-25 03:27:42 +01:00
__Conditions__ can be any of:
- Equals `=`
- Not Equals `!=`
2018-03-14 20:25:19 +00:00
- In `IN`
- Not In `NOT IN`
- Begins with `LIKE ('%...')`
- Doesn't begin with `NOT LIKE ('%...')`
- Contains `LIKE ('%...%')`
- Doesn't Contain `NOT LIKE ('%...%')`
- Ends with `LIKE ('...%')`
- Doesn't end with `NOT LIKE ('...%')`
- Between `BETWEEN`
- Not Between `NOT BETWEEN`
- Is Empty `= ''`
- Is Not Empty `!= '''`
- Is Null `IS NULL`
- Is Not Null `IS NOT NULL`
2017-06-25 03:27:42 +01:00
- Greater `>`
- Greater or Equal `>=`
2018-03-14 20:25:19 +00:00
- Less `<`
- Less or Equal `<=`
- Regex `REGEXP`
2017-11-24 17:06:32 -06:00
2019-06-20 13:53:45 -05:00
__Values__ can be an entity or any data. If using macros as value you
must include the macro name into backticks. i.e. \`macros.past_60m\`
2017-06-25 03:27:42 +01:00
2018-09-05 14:24:07 +02:00
__Note__: Regex supports MySQL Regular expressions.
2017-06-25 03:27:42 +01:00
Arithmetics are allowed as well.
2019-04-24 10:09:48 +02:00
## Options
2017-11-24 17:06:32 -06:00
2017-06-25 03:27:42 +01:00
Here are some of the other options available when adding an alerting rule:
- Rule name: The name associated with the rule.
- Severity: How "important" the rule is.
- Max alerts: The maximum number of alerts sent for the event. `-1` means unlimited.
2019-06-20 13:53:45 -05:00
- Delay: The amount of time in seconds to wait after a rule is matched
before sending an alert out transport.
- Interval: The interval of time in seconds between alerts for an
event until Max alert is reached.
- Mute alerts: Disables sending alert rule through alert
transport. But will still show the alert in the Web UI.
- Invert match: Invert the matching rule (ie. alert on items that
_don't match the rule).
- Recovery alerts: This will disable the recovery notification from
being sent if turned off.
2017-06-25 03:27:42 +01:00
2019-04-24 10:09:48 +02:00
## Advanced
2018-09-19 13:47:45 +01:00
On the Advanced tab, you can specify some additional options for the alert rule:
- Override SQL: Enable this if you using a custom query
- Query: The query to be used for the alert.
2019-06-20 13:53:45 -05:00
2018-10-19 16:58:14 -05:00
- An example of this would be an average rule for all CPUs over 10%
```sql
SELECT *,AVG(processors.processor_usage) as cpu_avg FROM devices,processors WHERE (devices.device_id = ? AND devices.device_id = processors.device_id) AND (devices.status = 1 & & (devices.disabled = 0 & & devices.ignore = 0)) = 1 HAVING AVG(processors.processor_usage) > 10
```
2019-06-20 13:53:45 -05:00
> The 10 would then contain the average CPU usage value, you can
> change this value to be whatever you like.
2018-10-19 16:58:14 -05:00
2019-06-20 13:53:45 -05:00
- You will to need copy and paste this into the Alert Rule under
Advanced then paste into Query box and switch the Override SQL.
2018-09-19 13:47:45 +01:00
2017-11-22 19:37:39 -06:00
## Procedure
2019-06-20 13:53:45 -05:00
You can associate a rule to a procedure by giving the URL of the
procedure when creating the rule. Only links like "http://" are
supported, otherwise an error will be returned. Once configured,
procedure can be opened from the Alert widget through the "Open"
button, which can be shown/hidden from the widget configuration box.
2017-06-25 03:27:42 +01:00
2017-11-22 19:37:39 -06:00
## Examples
2017-11-24 17:06:32 -06:00
2017-06-25 03:27:42 +01:00
Alert when:
2017-11-24 17:06:32 -06:00
2018-04-04 10:00:23 +02:00
- Device goes down: `devices.status != 1`
2018-03-14 20:25:19 +00:00
- Any port changes: `ports.ifOperStatus != 'up'`
2019-06-20 13:53:45 -05:00
- Root-directory gets too full: `storage.storage_descr = '/' AND
storage.storage_perc >= '75'`
2018-03-14 20:25:19 +00:00
- Any storage gets fuller than the 'warning': `storage.storage_perc >= storage_perc_warn`
2019-06-20 13:53:45 -05:00
- If device is a server and the used storage is above the warning
level, but ignore /boot partitions: `storage.storage_perc >
storage.storage_perc_warn AND devices.type = "server" AND
storage.storage_descr != "/boot"`
- VMware LAG is not using "Source ip address hash" load balancing:
`devices.os = "vmware" AND ports.ifType = "ieee8023adLag" AND
ports.ifDescr REGEXP "Link Aggregation .*, load balancing algorithm:
Source ip address hash"`
- Syslog, authentication failure during the last 5m:
`syslog.timestamp >= macros.past_5m AND syslog.msg REGEXP ".*authentication failure.*"`
- High memory usage: `macros.device_up = 1 AND mempools.mempool_perc >=
90 AND mempools.mempool_descr REGEXP "Virtual.*"`
- High CPU usage(per core usage, not overall): `macros.device_up
= 1 AND processors.processor_usage >= 90`
- High port usage, where description is not client & ifType is not
softwareLoopback: `macros.port_usage_perc >= 80 AND
port.port_descr_type != "client" AND ports.ifType != "softwareLoopback"`
2018-03-14 20:25:19 +00:00
- Alert when mac address is located on your network `ipv4_mac.mac_address = "2c233a756912"`
2017-06-25 03:27:42 +01:00
2019-04-24 10:09:48 +02:00
## Alert Rules Collection
2019-06-20 13:53:45 -05:00
You can also select Alert Rule from the Alerts Collection. These Alert
Rules are submitted by users in the community :) If would like to
submit your alert rules to the collection, please submit them here [Alert Rules Collection ](https://github.com/librenms/librenms/blob/master/misc/alert_rules.json )
2019-04-24 10:09:48 +02:00
2017-11-08 13:21:47 -06:00
