(plugin) apps::thales::mistral::vs9::restapi - fix cache system (#4110)

This commit is contained in:
qgarnier 2022-12-16 11:05:43 +00:00 committed by GitHub
parent 493027f934
commit 6c8fb0ff10
2 changed files with 7 additions and 5 deletions

View File

@ -60,6 +60,7 @@ sub new {
$self->{output} = $options{output}; $self->{output} = $options{output};
$self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl'); $self->{http} = centreon::plugins::http->new(%options, default_backend => 'curl');
$self->{cache} = centreon::plugins::statefile->new(%options); $self->{cache} = centreon::plugins::statefile->new(%options);
$self->{cache_connect} = centreon::plugins::statefile->new(output => $options{output});
return $self; return $self;
} }
@ -99,6 +100,7 @@ sub check_options {
} }
$self->{cache}->check_options(option_results => $self->{option_results}); $self->{cache}->check_options(option_results => $self->{option_results});
$self->{cache_connect}->check_options(option_results => $self->{option_results});
return 0; return 0;
} }
@ -121,9 +123,9 @@ sub get_connection_info {
sub get_token { sub get_token {
my ($self, %options) = @_; my ($self, %options) = @_;
my $has_cache_file = $self->{cache}->read(statefile => 'thales_mistral_connect_' . md5_hex($self->get_connection_info() . '_' . $self->{api_username})); my $has_cache_file = $self->{cache_connect}->read(statefile => 'thales_mistral_connect_' . md5_hex($self->get_connection_info() . '_' . $self->{api_username}));
my $token = $self->{cache}->get(name => 'token'); my $token = $self->{cache_connect}->get(name => 'token');
my $md5_secret_cache = $self->{cache}->get(name => 'md5_secret'); my $md5_secret_cache = $self->{cache_connect}->get(name => 'md5_secret');
my $md5_secret = md5_hex($self->{api_username} . $self->{api_password}); my $md5_secret = md5_hex($self->{api_username} . $self->{api_password});
if ($has_cache_file == 0 || if ($has_cache_file == 0 ||
@ -169,7 +171,7 @@ sub get_token {
token => $token, token => $token,
md5_secret => $md5_secret md5_secret => $md5_secret
}; };
$self->{cache}->write(data => $datas); $self->{cache_connect}->write(data => $datas);
} }
return $token; return $token;

View File

@ -241,7 +241,7 @@ sub manage_selection {
status => { status => {
clusterName => $cluster->{name}, clusterName => $cluster->{name},
gatewaysClusterStatus => $cluster->{gatewaysClusterStatus}, gatewaysClusterStatus => $cluster->{gatewaysClusterStatus},
availableForSwitching => $cluster->{availableForSwitching} =~ /true|1/i ? 'yes' : 'no' availableForSwitching => defined($cluster->{availableForSwitching}) && $cluster->{availableForSwitching} =~ /true|1/i ? 'yes' : 'no'
}, },
members => {} members => {}
}; };