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 6146360149 for ; Wed, 2 Dec 2020 10:21:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5ED091907B for ; Wed, 2 Dec 2020 10:21:16 +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)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 0B75519047 for ; Wed, 2 Dec 2020 10:21:15 +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 C5BDC44A91 for ; Wed, 2 Dec 2020 10:21:14 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 2 Dec 2020 10:21:07 +0100 Message-Id: <20201202092113.15911-5-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092113.15911-1-d.csapak@proxmox.com> References: <20201202092113.15911-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.303 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, extmetric.pm] Subject: [pve-devel] [PATCH manager 2/7] status/plugin: extend send/_connect/_disconnect/test_connection 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, 02 Dec 2020 09:21:16 -0000 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 --- 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