feat: Add sortorder parameter to list_logs (#14600)

This commit is contained in:
Talk Straight Ltd
2022-11-08 17:20:34 +00:00
committed by GitHub
parent b807fd526b
commit 9826fa9089
2 changed files with 4 additions and 1 deletions

View File

@@ -33,6 +33,7 @@ Example:
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/logs/eventlog/:hostname
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/logs/syslog/:hostname?limit=20
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/logs/eventlog/:hostname?limit=20&start=5&from=2017-07-22%2023:00:00
curl -H 'X-Auth-Token: YOURAPITOKENHERE' https://librenms.org/api/v0/logs/eventlog/:hostname?sortorder=DESC
```
Output:

View File

@@ -2601,9 +2601,11 @@ function list_logs(Illuminate\Http\Request $request, Router $router)
$param[] = $to;
}
$sort_order = $request->get('sortorder') === 'DESC' ? 'DESC' : 'ASC';
$count_query = $count_query . $query;
$count = dbFetchCell($count_query, $param);
$full_query = $full_query . $query . " ORDER BY $timestamp ASC LIMIT $start,$limit";
$full_query = $full_query . $query . " ORDER BY $timestamp $sort_order LIMIT $start,$limit";
$logs = dbFetchRows($full_query, $param);
if ($type === 'list_alertlog') {