[pve-devel] [PATCH pmg-api v2 1/1] node: add journal api
Dominik Csapak
d.csapak at proxmox.com
Wed May 15 11:15:15 CEST 2019
this uses the new journalreader instead of journalctl, which is a bit
faster and can read from/to cursor and returns a start/end cursor
also you can give an unix epoch as time parameters
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PMG/API2/Nodes.pm | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
debian/control | 1 +
2 files changed, 72 insertions(+)
diff --git a/PMG/API2/Nodes.pm b/PMG/API2/Nodes.pm
index 7734977..f836af8 100644
--- a/PMG/API2/Nodes.pm
+++ b/PMG/API2/Nodes.pm
@@ -260,6 +260,77 @@ __PACKAGE__->register_method({
return $lines;
}});
+__PACKAGE__->register_method({
+ name => 'journal',
+ path => 'journal',
+ method => 'GET',
+ description => "Read Journal",
+ proxyto => 'node',
+ permissions => {
+ check => ['perm', '/nodes/{node}', [ 'Sys.Syslog' ]],
+ },
+ protected => 1,
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ node => get_standard_option('pve-node'),
+ since => {
+ type=> 'number',
+ description => "Display all log since this UNIX epoch.",
+ optional => 1,
+ },
+ until => {
+ type=> 'number',
+ description => "Display all log until this UNIX epoch.",
+ optional => 1,
+ },
+ lastentries => {
+ description => "Limit to the last X lines.",
+ type => 'integer',
+ optional => 1,
+ },
+ startcursor => {
+ description => "Start after the given Cursor.",
+ type => 'string',
+ optional => 1,
+ },
+ endcursor => {
+ description => "End before the given Cursor.",
+ type => 'string',
+ optional => 1,
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "string",
+ }
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+ my $user = $rpcenv->get_user();
+
+ my $lines = [];
+
+ my $parser = sub {
+ push @$lines, shift;
+ };
+
+ my $cmd = ["/usr/bin/mini-journalreader"];
+ push @$cmd, '-n', $param->{lastentries} if $param->{lastentries};
+ push @$cmd, '-b', $param->{since} if $param->{since};
+ push @$cmd, '-e', $param->{until} if $param->{until};
+ push @$cmd, '-f', $param->{startcursor} if $param->{startcursor};
+ push @$cmd, '-t', $param->{endcursor} if $param->{endcursor};
+
+ PVE::Tools::run_command($cmd, outfunc => $parser);
+
+ return $lines;
+ }});
+
__PACKAGE__->register_method ({
name => 'termproxy',
diff --git a/debian/control b/debian/control
index 49861fa..e0b038c 100644
--- a/debian/control
+++ b/debian/control
@@ -65,6 +65,7 @@ Depends: apt,
pmg-log-tracker,
postfix (>= 2.5.5),
postgresql-9.6,
+ proxmox-mini-journalreader,
proxmox-spamassassin,
pve-xtermjs (>= 1.0-1),
rrdcached,
--
2.11.0
More information about the pve-devel
mailing list