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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-03-15 09:14:55 +01:00 committed by Dominik Csapak
parent bb35a833d1
commit 6e5405fb21

View File

@ -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 {