[pve-devel] [PATCH manager 3/5] metrics: influx: do not error out when credendtials could not be loaded
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Mar 15 09:14:55 CET 2021
Not a hard error, some network box (proxy) down the line could add it
for us, or it could be just not required, so ...
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
PVE/Status/InfluxDB.pm | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/PVE/Status/InfluxDB.pm b/PVE/Status/InfluxDB.pm
index 712a30ff..137aec1b 100644
--- a/PVE/Status/InfluxDB.pm
+++ b/PVE/Status/InfluxDB.pm
@@ -208,7 +208,7 @@ sub test_connection {
my $ua = LWP::UserAgent->new();
$ua->timeout($cfg->{timeout} // 1);
# in the initial add connection test, the token may still be in $cfg
- my $token = $cfg->{token} // get_credentials($id);
+ my $token = $cfg->{token} // get_credentials($id, 1);
if (defined($token)) {
$ua->default_header("Authorization" => "Token $token");
}
@@ -330,11 +330,14 @@ sub set_credentials {
}
sub get_credentials {
- my ($id) = @_;
+ my ($id, $silent) = @_;
my $cred_file = cred_file_name($id);
- return PVE::Tools::file_get_contents($cred_file);
+ my $creds = eval { PVE::Tools::file_get_contents($cred_file) };
+ warn "could not load credentials for '$id': $@\n" if $@ && !$silent;
+
+ return $creds;
}
sub on_add_hook {
--
2.29.2
More information about the pve-devel
mailing list