mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-10-04 09:46:01 +00:00
status/plugin: extend send/_connect/_disconnect/test_connection
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@proxmox.com>
This commit is contained in:
parent
161d904f13
commit
fa97819773
@ -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;
|
||||
|
@ -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,25 +115,25 @@ 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) = @_;
|
||||
|
||||
# do not check connection for disabled plugins
|
||||
return if $cfg->{disable};
|
||||
|
||||
my $conn = $class->_connect($cfg);
|
||||
$class->_disconnect($conn);
|
||||
my $conn = $class->_connect($cfg, $id);
|
||||
$class->_disconnect($conn, $cfg);
|
||||
}
|
||||
|
||||
sub update_node_status {
|
||||
|
Loading…
Reference in New Issue
Block a user