From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id D26A663CCA for ; Wed, 25 Nov 2020 13:56:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C8C201A5B5 for ; Wed, 25 Nov 2020 13:56:41 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 542461A5AD for ; Wed, 25 Nov 2020 13:56:41 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 239E843B36 for ; Wed, 25 Nov 2020 13:56:41 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 25 Nov 2020 13:56:40 +0100 Message-Id: <20201125125640.5711-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.309 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [plugin.pm, metricserver.pm] Subject: [pve-devel] [PATCH manager] api: metrics/server: test connection on add/update X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2020 12:56:41 -0000 just a basic check, but better than not checking at all Signed-off-by: Dominik Csapak --- 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