[pve-devel] [PATCH manager] api: metrics/server: test connection on add/update
Dominik Csapak
d.csapak at proxmox.com
Wed Nov 25 13:56:40 CET 2020
just a basic check, but better than not checking at all
Signed-off-by: Dominik Csapak <d.csapak at 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
More information about the pve-devel
mailing list