From: Dietmar Maurer Date: Tue, 9 Jun 2015 10:15:41 +0000 (+0200) Subject: new helper dump_journal to view systemd journal X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=6de95a662fc902bfa7926fe61b94b2b12a60cbe8 new helper dump_journal to view systemd journal --- diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 8e18087..a7bcd35 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -988,6 +988,37 @@ sub dump_logfile { return ($count, $lines); } +sub dump_journal { + my ($start, $limit, $filter) = @_; + + my $lines = []; + my $count = 0; + + $start = 0 if !$start; + $limit = 50 if !$limit; + + my $parser = sub { + my $line = shift; + + return if $count++ < $start; + return if $limit <= 0; + push @$lines, { n => int($count), t => $line}; + $limit--; + }; + + my $cmd = ['journalctl', '-o', 'short', '--no-pager']; + run_command($cmd, outfunc => $parser); + + # HACK: ExtJS store.guaranteeRange() does not like empty array + # so we add a line + if (!$count) { + $count++; + push @$lines, { n => $count, t => "no content"}; + } + + return ($count, $lines); +} + sub dir_glob_regex { my ($dir, $regex) = @_;