From 6e5405fb21f0cd3e7e40b48e7d8ddcab897dabdc Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Mon, 15 Mar 2021 09:14:55 +0100 Subject: [PATCH] metrics: influx: do not error out when credendtials could not be loaded 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 --- 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 {