mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Add alert_rule filtering to API ROUTE "list_alerts" (#11109)
* Add alert_rule filtering to API ROUTE "list_alerts" * move alert_rule filter before "order by" * $_GET to $request->get * spacing * multiple empty-lines
This commit is contained in:
@@ -107,6 +107,7 @@ Input:
|
||||
|
||||
- state: Filter the alerts by state, 0 = ok, 1 = alert, 2 = ack
|
||||
- severity: Filter the alerts by severity. Valid values are `ok`, `warning`, `critical`.
|
||||
- alert_rule: Filter alerts by alert rule ID.
|
||||
- order: How to order the output, default is by timestamp
|
||||
(descending). Can be appended by DESC or ASC to change the order.
|
||||
|
||||
@@ -124,6 +125,10 @@ curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/alerts?seve
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/alerts?order=timestamp%20ASC
|
||||
```
|
||||
|
||||
```curl
|
||||
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/alerts?alert_rule=49
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```json
|
||||
|
@@ -988,7 +988,15 @@ function list_alerts(\Illuminate\Http\Request $request)
|
||||
}
|
||||
|
||||
$order = 'timestamp desc';
|
||||
|
||||
|
||||
$alert_rule = $request->get('alert_rule');
|
||||
if (isset($alert_rule)) {
|
||||
if (is_numeric($alert_rule)) {
|
||||
$param[] = $alert_rule;
|
||||
$sql .= ' AND `R`.id=?';
|
||||
}
|
||||
}
|
||||
|
||||
if ($request->has('order')) {
|
||||
list($sort_column, $sort_order) = explode(' ', $request->get('order'), 2);
|
||||
if (($res = validate_column_list($sort_column, 'alerts')) !== true) {
|
||||
|
Reference in New Issue
Block a user