From 9826fa9089acfe6962dd11bf5bcb6daf18dd9b41 Mon Sep 17 00:00:00 2001 From: Talk Straight Ltd <69851117+talkstraightuk@users.noreply.github.com> Date: Tue, 8 Nov 2022 17:20:34 +0000 Subject: [PATCH] feat: Add sortorder parameter to list_logs (#14600) --- doc/API/Logs.md | 1 + includes/html/api_functions.inc.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/API/Logs.md b/doc/API/Logs.md index 65813dac4b..b5f480d0d1 100644 --- a/doc/API/Logs.md +++ b/doc/API/Logs.md @@ -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: diff --git a/includes/html/api_functions.inc.php b/includes/html/api_functions.inc.php index 16ebc0a2c8..398c7089d7 100644 --- a/includes/html/api_functions.inc.php +++ b/includes/html/api_functions.inc.php @@ -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') {