which uses the new journalreader tool instead of journalctl,
with different parameters and a different return format:

array of strings with a start/end cursor

Signed-off-by: Dominik Csapak <d.csa...@proxmox.com>
---
 src/PVE/Tools.pm | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 4dd073f..4195cde 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -54,6 +54,8 @@ O_TMPFILE
 my $pvelogdir = "/var/log/pve";
 my $pvetaskdir = "$pvelogdir/tasks";
 
+my $JOURNALREADER = "/usr/bin/journalreader";
+
 mkdir $pvelogdir;
 mkdir $pvetaskdir;
 
@@ -1235,6 +1237,29 @@ sub dump_logfile {
     return ($count, $lines);
 }
 
+# returns the given journal range/entries as an array
+# the first and last entries are cursors where the user can continue
+sub read_journal {
+    my ($since, $until, $lastentries, $startcursor, $endcursor) = @_;
+
+       my $lines = [];
+
+       my $parser = sub {
+           push @$lines, shift;
+       };
+
+       my $cmd = [$JOURNALREADER];
+       push @$cmd, '-n', $lastentries if $lastentries;
+       push @$cmd, '-b', $since if $since;
+       push @$cmd, '-e', $until if $until;
+       push @$cmd, '-f', $startcursor if $startcursor;
+       push @$cmd, '-t', $endcursor if $endcursor;
+
+       run_command($cmd, outfunc => $parser);
+
+       return $lines;
+}
+
 sub dump_journal {
     my ($start, $limit, $since, $until, $service) = @_;
 
-- 
2.11.0


_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to