]> git.proxmox.com Git - pve-manager.git/commitdiff
api: notification: allow to test targets
authorLukas Wagner <l.wagner@proxmox.com>
Thu, 3 Aug 2023 12:17:02 +0000 (14:17 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 16 Aug 2023 09:11:06 +0000 (11:11 +0200)
This API call allows the user to test a notification target.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
PVE/API2/Cluster/Notifications.pm

index d6f29291a3fb0bf5bac7b4922942f6757787a4f1..065d6690e12ab4c583b3de4af7edf0d7db993359 100644 (file)
@@ -211,6 +211,46 @@ __PACKAGE__->register_method ({
     }
 });
 
+__PACKAGE__->register_method ({
+    name => 'test_target',
+    path => 'targets/{name}/test',
+    protected => 1,
+    method => 'POST',
+    description => 'Send a test notification to a provided target.',
+    permissions => {
+       check => ['or',
+           ['perm', '/mapping/notification/{name}', ['Mapping.Use']],
+           ['perm', '/mapping/notification/{name}', ['Mapping.Modify']],
+           ['perm', '/mapping/notification/{name}', ['Mapping.Audit']],
+       ],
+    },
+    parameters => {
+       additionalProperties => 0,
+       properties => {
+           name => {
+               description => 'Name of the target.',
+               type => 'string',
+               format => 'pve-configid'
+           },
+       },
+    },
+    returns => { type => 'null' },
+    code => sub {
+       my ($param) = @_;
+       my $name = extract_param($param, 'name');
+
+       my $config = PVE::Notify::read_config();
+
+       eval {
+           $config->test_target($name);
+       };
+
+       raise_api_error($@) if $@;
+
+       return;
+    }
+});
+
 my $group_properties = {
     name => {
        description => 'Name of the group.',