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:
Guillermo
2020-02-11 19:04:55 +01:00
committed by GitHub
parent 6fe840dc8d
commit c8fab3a13f
2 changed files with 14 additions and 1 deletions

View File

@@ -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

View File

@@ -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) {