Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/api/v2/status/logs does not query all log events #509

Closed
aeleus opened this issue Jul 13, 2024 · 1 comment
Closed

/api/v2/status/logs does not query all log events #509

aeleus opened this issue Jul 13, 2024 · 1 comment
Labels
enhancement Issues or PRs that enhance existing features

Comments

@aeleus
Copy link

aeleus commented Jul 13, 2024

Describe the bug
I just upgraded to REST API v2.01 from 1.75. I can no longer query all system and firewall events.

To Reproduce
Steps to reproduce the behavior:
When querying https://pfsense.domain.tld/api/v2/status/logs/system (or firewall), the oldest event is always the first event in the current log file. Example:
Jul 13 15:08:00 pfSense newsyslog[83161]: logfile turned over due to size>500K

No events from the rotated log files are returned. If the query is run just after the log files are rotated, only a single result is returned.
Changing values for limit=0&offset=0 still only returns results from the current log file.

Expected behavior
The ability to query all log events like the UI does (https://pfsense.domain.tld/status_logs.php and https://pfsense.domain.tld/status_logs_filter.php)

pfSense Version & Package Version:

  • pfSense Version: 2.7.2-RELEASE
  • Package Version: 2.0_1

Affected Endpoints:

  • URL: /api/v2/status/logs/system
  • URL: /api/v2/status/logs/firewall
@jaredhendrickson13 jaredhendrickson13 added the enhancement Issues or PRs that enhance existing features label Jul 14, 2024
@jaredhendrickson13
Copy link
Owner

This doesn't look like a bug, both v1 and v2 only look at the most recent log file and don't attempt to decompress or look at log files that have already been rotated:

public function action() {
$log = file_get_contents("/var/log/system.log");
$log = explode("\n", $log);
$log = array_filter($log);
unset($log[count($log) - 1]);
return APIResponse\get(0, $log);

protected function get_system_log(): array {
$system_log = [];
$log = file_get_contents('/var/log/system.log');
$log_lines = explode("\n", $log);
$log = array_filter($log_lines);
unset($log[count($log_lines) - 1]);
foreach ($log_lines as $line) {
$system_log[] = ['text' => $line];
}
return $system_log;
}
}

In v1 this was intentionally done to prevent API calls from hanging when reading a large number of logs, but it's likely feasible to do this in v2 now that pagination is supported. I'll see if I can work it into v2.1.0.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issues or PRs that enhance existing features
Projects
No open projects
Status: Done
Development

No branches or pull requests

2 participants