]> git.proxmox.com Git - pmg-api.git/blobdiff - PMG/API2/Nodes.pm
PMG/API2/Nodes.pm: add rrddata API
[pmg-api.git] / PMG / API2 / Nodes.pm
index 387b90817f21092345a41d7eadc8f74a9cdbd5ba..b778eadb9e89862fa4bb40d2b2b2681681ef8949 100644 (file)
@@ -15,9 +15,15 @@ use PMG::Ticket;
 use PMG::API2::Tasks;
 use PMG::API2::Services;
 use PMG::API2::Network;
+use PMG::API2::ClamAV;
 
 use base qw(PVE::RESTHandler);
 
+__PACKAGE__->register_method ({
+    subclass => "PMG::API2::ClamAV",
+    path => 'clamav',
+});
+
 __PACKAGE__->register_method ({
     subclass => "PMG::API2::Network",
     path => 'network',
@@ -57,6 +63,7 @@ __PACKAGE__->register_method ({
        my ($param) = @_;
 
        my $result = [
+           { name => 'clamav' },
            { name => 'services' },
            { name => 'syslog' },
            { name => 'tasks' },
@@ -67,6 +74,45 @@ __PACKAGE__->register_method ({
        return $result;
     }});
 
+__PACKAGE__->register_method({
+    name => 'rrddata',
+    path => 'rrddata',
+    method => 'GET',
+    protected => 1, # fixme: can we avoid that?
+    proxyto => 'node',
+    description => "Read node RRD statistics",
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           timeframe => {
+               description => "Specify the time frame you are interested in.",
+               type => 'string',
+               enum => [ 'hour', 'day', 'week', 'month', 'year' ],
+           },
+           cf => {
+               description => "The RRD consolidation function",
+               type => 'string',
+               enum => [ 'AVERAGE', 'MAX' ],
+               optional => 1,
+           },
+       },
+    },
+    returns => {
+       type => "array",
+       items => {
+           type => "object",
+           properties => {},
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       return PMG::Utils::create_rrd_data(
+           "pmg-node-v1.rrd", $param->{timeframe}, $param->{cf});
+    }});
+
+
 __PACKAGE__->register_method({
     name => 'syslog',
     path => 'syslog',
@@ -177,9 +223,17 @@ __PACKAGE__->register_method ({
        my $family = PVE::Tools::get_host_address_family($node);
        my $port = PVE::Tools::next_vnc_port($family);
 
+       my $shcmd;
+
+       if ($user eq 'root@pam') {
+           $shcmd = [ '/bin/login', '-f', 'root' ];
+       } else {
+           $shcmd = [ '/bin/login' ];
+       }
+
        my $cmd = ['/usr/bin/vncterm', '-rfbport', $port,
                   '-timeout', 10, '-notls', '-listen', 'localhost',
-                  '-c', '/usr/bin/top'];
+                  '-c', @$shcmd];
 
        my $realcmd = sub {
            my $upid = shift;
@@ -262,6 +316,94 @@ __PACKAGE__->register_method({
        return { port => $port };
     }});
 
+__PACKAGE__->register_method({
+    name => 'dns',
+    path => 'dns',
+    method => 'GET',
+    description => "Read DNS settings.",
+    proxyto => 'node',
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+       },
+    },
+    returns => {
+       type => "object",
+       additionalProperties => 0,
+       properties => {
+           search => {
+               description => "Search domain for host-name lookup.",
+               type => 'string',
+               optional => 1,
+           },
+           dns1 => {
+               description => 'First name server IP address.',
+               type => 'string',
+               optional => 1,
+           },
+           dns2 => {
+               description => 'Second name server IP address.',
+               type => 'string',
+               optional => 1,
+           },
+           dns3 => {
+               description => 'Third name server IP address.',
+               type => 'string',
+               optional => 1,
+           },
+       },
+    },
+    code => sub {
+       my ($param) = @_;
+
+       my $res = PVE::INotify::read_file('resolvconf');
+
+       return $res;
+    }});
+
+__PACKAGE__->register_method({
+    name => 'update_dns',
+    path => 'dns',
+    method => 'PUT',
+    description => "Write DNS settings.",
+    proxyto => 'node',
+    protected => 1,
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           node => get_standard_option('pve-node'),
+           search => {
+               description => "Search domain for host-name lookup.",
+               type => 'string',
+           },
+           dns1 => {
+               description => 'First name server IP address.',
+               type => 'string', format => 'ip',
+               optional => 1,
+           },
+           dns2 => {
+               description => 'Second name server IP address.',
+               type => 'string', format => 'ip',
+               optional => 1,
+           },
+           dns3 => {
+               description => 'Third name server IP address.',
+               type => 'string', format => 'ip',
+               optional => 1,
+           },
+       },
+    },
+    returns => { type => "null" },
+    code => sub {
+       my ($param) = @_;
+
+       PVE::INotify::update_file('resolvconf', $param);
+
+       return undef;
+    }});
+
+
 __PACKAGE__->register_method({
     name => 'time',
     path => 'time',