]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/API2/Nodes.pm
node: add journal api
[pmg-api.git] / PMG / API2 / Nodes.pm
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',