2017-06-25 03:27:42 +01:00
|
|
|
source: Alerting/Macros.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
|
|
|
# Macros
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Macros are shorthands to either portion of rules or pure SQL enhanced with placeholders.
|
|
|
|
|
|
|
|
You can define your own macros in your `config.php`.
|
|
|
|
|
|
|
|
Example macro-implementation of Debian-Devices
|
|
|
|
```php
|
2018-03-14 20:25:19 +00:00
|
|
|
$config['alert']['macros']['rule']['is_debian'] = 'devices.features ~ "@debian@"';
|
2017-06-25 03:27:42 +01:00
|
|
|
```
|
|
|
|
And in the Rule:
|
|
|
|
```
|
2018-03-14 20:25:19 +00:00
|
|
|
... macros.is_debian = 1 ...
|
2017-06-25 03:27:42 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
This Example-macro is a Boolean-macro, it applies a form of filter to the set of results defined by the rule.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
All macros that are not unary should return Boolean.
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
## Device (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.device`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select devices that aren't deleted, ignored or disabled.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(devices.disabled = 0 AND devices.ignore = 0)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Device is up (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.device_up`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select devices that are up.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Implies: macros.device
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(devices.status = 1 AND macros.device)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Device is down (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.device_down`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select devices that are down.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Implies: macros.device
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(devices.status = 0 AND macros.device)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
## Port (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.port`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select ports that aren't deleted, ignored or disabled.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(ports.deleted = 0 AND ports.ignore = 0 AND ports.disabled = 0)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Port is up (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.port_up`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select ports that are up and also should be up.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Implies: macros.port
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(ports.ifOperStatus = up AND ports.ifAdminStatus = up AND macros.port)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Port is down (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.port_down`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select ports that are down.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Implies: macros.port
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(ports.ifOperStatus = "down" AND ports.ifAdminStatus != "down" AND macros.port)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Port-Usage in Percent (Decimal)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.port_usage_perc`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Return port-usage in percent.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `((ports.ifInOctets_rate*8) / ports.ifSpeed)*100`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
## Time
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Now (Datetime)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.now`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Alias of MySQL's NOW()
|
|
|
|
|
|
|
|
Source: `NOW()`
|
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
### Past N Minutes (Datetime)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.past_$m`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Returns a MySQL Timestamp dated `$` Minutes in the past. `$` can only be a supported Resolution.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.past_5m` is Last 5 Minutes.
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Resolution: 5,10,15,30,60
|
|
|
|
|
|
|
|
Source: `DATE_SUB(NOW(),INTERVAL $ MINUTE)`
|
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
## Sensors (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.sensor`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Only select sensors that aren't ignored.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(sensors.sensor_alert = 1)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.sensor_port_link = 1`
|
2017-08-04 19:37:50 +01:00
|
|
|
|
|
|
|
Description: Only selects sensors that have a port linked to them, the port is up and the device is up.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(sensors.entity_link_type = "port" AND sensors.entity_link_index = ports.ifIndex AND macros.port_up AND macros.device_up))`
|
2017-08-04 19:37:50 +01:00
|
|
|
|
2017-12-02 17:03:36 -06:00
|
|
|
## State Sensors (Boolean)
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `macros.state_sensor_ok`, `macros.state_sensor_warning`, `macros.state_sensor_critical`, `macros.state_sensor_unknown`
|
2017-12-02 17:03:36 -06:00
|
|
|
|
|
|
|
Description: Select state sensors by their generic status ok (0), warning (1), critical (2), unknown (3)
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Source: `(sensors.sensor_current = state_translations.state_value AND state_translations.state_generic_value = 2)`
|
2017-12-02 17:03:36 -06:00
|
|
|
|
2017-08-19 14:40:50 -04:00
|
|
|
## Misc (Boolean)
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
### Packet Loss
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `(macros.packet_loss_5m)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Packet loss % value for the device within the last 5 minutes.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.packet_loss_5m` > 50
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `(macros.packet_loss_15m)`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Packet loss % value for the device within the last 15 minutes.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.packet_loss_15m` > 50
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
### Ports in usage perc (Int)
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `((ports.ifInOctets_rate*8)/ports.ifSpeed)*100`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Port in used more than 50%
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.port_in_usage_perc > 50
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
### Ports out usage perc (Int)
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `((ports.ifOutOctets_rate*8)/ports.ifSpeed)*100`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Port out used more than 50%
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.port_out_usage_perc > 50
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
### Ports now down (Boolean)
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `ports.ifOperStatus != ports.ifOperStatus_prev AND ports.ifOperStatus_prev = "up" AND ports.ifAdminStatus = "up"`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Ports that were previously up and have now gone down.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.port_now_down = 1`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
2018-12-11 05:20:53 +01:00
|
|
|
### Port has xDP neighbour (Boolean)
|
|
|
|
|
|
|
|
Entity: `%macros.port AND %links.local_port_id = %ports.port_id`
|
|
|
|
|
|
|
|
Description: Ports that have an xDP (lldp, cdp, etc) neighbour.
|
|
|
|
|
|
|
|
Example: `macros.port_has_xdp_neighbours = 1`
|
|
|
|
|
|
|
|
### Port has xDP neighbour already known in LibreNMS (Boolean)
|
|
|
|
|
|
|
|
Entity: `%macros.port_has_neighbours AND (%links.remote_port_id IS NOT NULL)`
|
|
|
|
|
|
|
|
Description: Ports that have an xDP (lldp, cdp, etc) neighbour that is already known in libreNMS.
|
|
|
|
|
|
|
|
Example: `macros.port_has_xdp_neighbours_device = 1`
|
|
|
|
|
2017-06-25 03:27:42 +01:00
|
|
|
### Device component down [JunOS]
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `sensors.sensor_class = "state" AND sensors.sensor_current != "6" AND sensors.sensor_type = "jnxFruState" AND sensors.sensor_current != "2"`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Device component is down such as Fan, PSU, etc for JunOS devices.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.device_component_down_junos = 1`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
### Device component down [Cisco]
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `sensors.sensor_current != 1 AND sensors.sensor_current != 5 AND sensors.sensor_type ~ "^cisco.*State$"`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: Device component is down such as Fan, PSU, etc for Cisco devices.
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.device_component_down_cisco = 1`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
### PDU over amperage [APC]
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Entity: `sensors.sensor_class = "current" AND sensors.sensor_descr = "Bank Total" AND sensors.sensor_current > sensors.sensor_limit AND devices.os = "apc"`
|
2017-06-25 03:27:42 +01:00
|
|
|
|
|
|
|
Description: APC PDU over amperage
|
|
|
|
|
2018-03-14 20:25:19 +00:00
|
|
|
Example: `macros.pdu_over_amperage_apc = 1`
|