]> git.proxmox.com Git - pmg-api.git/commitdiff
node: add journal api
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 15 May 2019 09:38:19 +0000 (11:38 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 16 May 2019 10:54:53 +0000 (12:54 +0200)
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@proxmox.com>
PMG/API2/Nodes.pm
debian/control

index 7734977e9aadd3319dbcc72169be25778c096065..c91e910ab251f227642fbc60d365882f262c3ec0 100644 (file)
@@ -260,6 +260,72 @@ __PACKAGE__->register_method({
        return $lines;
     }});
 
+__PACKAGE__->register_method({
+    name => 'journal',
+    path => 'journal',
+    method => 'GET',
+    description => "Read Journal",
+    proxyto => 'node',
+    permissions => { check => [ 'admin', 'audit' ] },
+    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 $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',
index 49861fa93a71fc927c200b3486be6e8e15a38d2d..e0b038c8feb4f6901b507a5492a38e3004be2154 100644 (file)
@@ -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,