]> git.proxmox.com Git - pve-manager.git/commitdiff
node: add journal api
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 15 May 2019 09:15:13 +0000 (11:15 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 15 May 2019 10:09:26 +0000 (12:09 +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>
PVE/API2/Nodes.pm
debian/control

index df47be1fd0d6cb3ad25e2d0a87c262a5bd98a892..426c026e63b50e71eb8e71a0cdaa1dd358d7075d 100644 (file)
@@ -699,6 +699,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;
+    }});
+
 my $sslcert;
 
 my $shell_cmd_map = {
index eb39e1e9edb5977c2aabdf7308dbe6ee28a0e33a..1a200c0ae8994cc20b8ac707c3ae97339139601f 100644 (file)
@@ -60,6 +60,7 @@ Depends: apt-transport-https,
          pciutils,
          perl (>= 5.10.0-19),
          postfix | mail-transport-agent,
+         proxmox-mini-journalreader,
          proxmox-widget-toolkit (>= 1.0-26),
          pve-cluster (>= 5.0-27),
          pve-container (>= 2.0-21),