public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] api: metrics/server: test connection on add/update
Date: Wed, 25 Nov 2020 13:56:40 +0100	[thread overview]
Message-ID: <20201125125640.5711-1-d.csapak@proxmox.com> (raw)

just a basic check, but better than not checking at all

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 PVE/API2/Cluster/MetricServer.pm | 5 +++++
 PVE/Status/Plugin.pm             | 7 +++++++
 2 files changed, 12 insertions(+)

diff --git a/PVE/API2/Cluster/MetricServer.pm b/PVE/API2/Cluster/MetricServer.pm
index b96228b0..9a14985e 100644
--- a/PVE/API2/Cluster/MetricServer.pm
+++ b/PVE/API2/Cluster/MetricServer.pm
@@ -159,6 +159,9 @@ __PACKAGE__->register_method ({
 		if $cfg->{ids}->{$id};
 
 	    my $opts = $plugin->check_config($id, $param, 1, 1);
+
+	    $plugin->test_connection($opts);
+
 	    $cfg->{ids}->{$id} = $opts;
 
 	    PVE::Cluster::cfs_write_file('status.cfg', $cfg);
@@ -198,6 +201,8 @@ __PACKAGE__->register_method ({
 	    my $plugin = PVE::Status::Plugin->lookup($data->{type});
 	    my $opts = $plugin->check_config($id, $param, 0, 1);
 
+	    $plugin->test_connection($opts);
+
 	    for my $k (keys %$opts) {
 		$data->{$k} = $opts->{$k};
 	    }
diff --git a/PVE/Status/Plugin.pm b/PVE/Status/Plugin.pm
index 0faf0da6..c3e0bec1 100644
--- a/PVE/Status/Plugin.pm
+++ b/PVE/Status/Plugin.pm
@@ -126,6 +126,13 @@ sub send {
 	or die "failed to send metrics: $!\n";
 }
 
+sub test_connection {
+    my ($class, $cfg) = @_;
+
+    my $conn = $class->_connect($cfg);
+    $class->_disconnect($conn);
+}
+
 sub update_node_status {
     my ($class, $txn, $node, $data, $ctime) = @_;
     die "please implement inside plugin";
-- 
2.20.1





             reply	other threads:[~2020-11-25 12:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25 12:56 Dominik Csapak [this message]
2020-11-25 13:56 ` [pve-devel] applied: " Thomas Lamprecht
2020-12-03 16:55 ` [pve-devel] " Thomas Lamprecht
2020-12-07 14:30   ` Thomas Lamprecht
2020-12-07 14:32     ` Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201125125640.5711-1-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal