mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
API: Allow logs to be filtered by min/max id (#12471)
* Allow logs to be filtered by min/max id * typo
This commit is contained in:
@@ -11,8 +11,8 @@ Input:
|
||||
|
||||
- start: The page number to request.
|
||||
- limit: The limit of results to be returned.
|
||||
- from: The date and time to search from.
|
||||
- to: The data and time to search to.
|
||||
- from: The date and time or the event id to search from.
|
||||
- to: The data and time or the event id to search to.
|
||||
|
||||
### `list_eventlog`
|
||||
|
||||
|
@@ -2235,18 +2235,22 @@ function list_logs(Illuminate\Http\Request $request, Router $router)
|
||||
$query = ' FROM eventlog LEFT JOIN `devices` ON `eventlog`.`device_id`=`devices`.`device_id` WHERE 1';
|
||||
$full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `eventlog`.`device_id` as `host`, `eventlog`.*'; // inject host for backward compat
|
||||
$timestamp = 'datetime';
|
||||
$id_field = 'event_id';
|
||||
} elseif ($type === 'list_syslog') {
|
||||
$query = ' FROM syslog LEFT JOIN `devices` ON `syslog`.`device_id`=`devices`.`device_id` WHERE 1';
|
||||
$full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `syslog`.*';
|
||||
$timestamp = 'timestamp';
|
||||
$id_field = 'seq';
|
||||
} elseif ($type === 'list_alertlog') {
|
||||
$query = ' FROM alert_log LEFT JOIN `devices` ON `alert_log`.`device_id`=`devices`.`device_id` WHERE 1';
|
||||
$full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `alert_log`.*';
|
||||
$timestamp = 'time_logged';
|
||||
$id_field = 'id';
|
||||
} elseif ($type === 'list_authlog') {
|
||||
$query = ' FROM authlog WHERE 1';
|
||||
$full_query = 'SELECT `authlog`.*';
|
||||
$timestamp = 'datetime';
|
||||
$id_field = 'id';
|
||||
} else {
|
||||
$query = ' FROM eventlog LEFT JOIN `devices` ON `eventlog`.`device_id`=`devices`.`device_id` WHERE 1';
|
||||
$full_query = 'SELECT `devices`.`hostname`, `devices`.`sysName`, `eventlog`.*';
|
||||
@@ -2264,12 +2268,20 @@ function list_logs(Illuminate\Http\Request $request, Router $router)
|
||||
}
|
||||
|
||||
if ($from) {
|
||||
$query .= " AND $timestamp >= ?";
|
||||
if (is_numeric($from)) {
|
||||
$query .= " AND $id_field >= ?";
|
||||
} else {
|
||||
$query .= " AND $timestamp >= ?";
|
||||
}
|
||||
$param[] = $from;
|
||||
}
|
||||
|
||||
if ($to) {
|
||||
$query .= " AND $timestamp <= ?";
|
||||
if (is_numeric($to)) {
|
||||
$query .= " AND $id_field <= ?";
|
||||
} else {
|
||||
$query .= " AND $timestamp <= ?";
|
||||
}
|
||||
$param[] = $to;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user