[pve-devel] [PATCH manager 2/7] status/plugin: extend send/_connect/_disconnect/test_connection

Dominik Csapak d.csapak at proxmox.com
Wed Dec 2 10:21:07 CET 2020


by providing the id or cfg to have better context in those methods
we will need that for influxdb http api

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/ExtMetric.pm     |  4 ++--
 PVE/Status/Plugin.pm | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/PVE/ExtMetric.pm b/PVE/ExtMetric.pm
index 448d3925..3358c359 100644
--- a/PVE/ExtMetric.pm
+++ b/PVE/ExtMetric.pm
@@ -49,7 +49,7 @@ sub transactions_start {
     foreach_plug($cfg, sub {
 	my ($plugin, $id, $plugin_config) = @_;
 
-	my $connection = $plugin->_connect($plugin_config);
+	my $connection = $plugin->_connect($plugin_config, $id);
 
 	push @$transactions, {
 	    connection => $connection,
@@ -72,7 +72,7 @@ sub transactions_finish {
 	my $flush_err = $@;
 	warn "$flush_err" if $flush_err;
 
-	$plugin->_disconnect($txn->{connection});
+	$plugin->_disconnect($txn->{connection}, $txn->{cfg});
 	$txn->{connection} = undef;
 	# avoid log spam, already got a send error; disconnect would fail too
 	warn "disconnect failed: $@" if $@ && !$flush_err;
diff --git a/PVE/Status/Plugin.pm b/PVE/Status/Plugin.pm
index c3e0bec1..2fa223ca 100644
--- a/PVE/Status/Plugin.pm
+++ b/PVE/Status/Plugin.pm
@@ -70,12 +70,12 @@ sub parse_section_header {
 }
 
 sub _connect {
-    my ($class, $cfg) = @_;
+    my ($class, $cfg, $id) = @_;
     die "please implement inside plugin";
 }
 
 sub _disconnect {
-    my ($class, $connection) = @_;
+    my ($class, $connection, $cfg) = @_;
 
     $connection->close(); # overwrite if not a simple socket
 }
@@ -115,22 +115,22 @@ sub flush_data {
     return if !defined($txn->{data}) || $txn->{data} eq '';
 
     my $data = delete $txn->{data};
-    eval { $class->send($txn->{connection}, $data) };
+    eval { $class->send($txn->{connection}, $data, $txn->{cfg}) };
     die "metrics send error '$txn->{id}': $@" if $@;
 }
 
 sub send {
-    my ($class, $connection, $data) = @_;
+    my ($class, $connection, $data, $cfg) = @_;
 
     defined($connection->send($data))
 	or die "failed to send metrics: $!\n";
 }
 
 sub test_connection {
-    my ($class, $cfg) = @_;
+    my ($class, $cfg, $id) = @_;
 
-    my $conn = $class->_connect($cfg);
-    $class->_disconnect($conn);
+    my $conn = $class->_connect($cfg, $id);
+    $class->_disconnect($conn, $cfg);
 }
 
 sub update_node_status {
-- 
2.20.1






More information about the pve-devel mailing list