fix hp oneview + vmware vcsa

This commit is contained in:
garnier-quentin 2019-09-25 16:22:06 +02:00
parent 8d0e73ef2f
commit d335a55774
2 changed files with 7 additions and 7 deletions

View File

@ -208,7 +208,7 @@ sub request_api {
# Maybe there is an issue with the session_id. So we retry. # Maybe there is an issue with the session_id. So we retry.
if ($self->{http}->get_code() != 200) { if ($self->{http}->get_code() != 200) {
$self->clean_session_id(); $self->clean_session_id(statefile => $self->{cache});
$self->authenticate(statefile => $self->{cache}); $self->authenticate(statefile => $self->{cache});
$content = $self->{http}->request(%options, $content = $self->{http}->request(%options,
warning_status => '', unknown_status => '', critical_status => '' warning_status => '', unknown_status => '', critical_status => ''

View File

@ -154,15 +154,15 @@ sub clean_session_id {
my ($self, %options) = @_; my ($self, %options) = @_;
my $datas = { last_timestamp => time() }; my $datas = { last_timestamp => time() };
$options{statefile}->write(data => $datas); $self->{cache}->write(data => $datas);
$self->{session_id} = undef; $self->{session_id} = undef;
} }
sub authenticate { sub authenticate {
my ($self, %options) = @_; my ($self, %options) = @_;
my $has_cache_file = $options{statefile}->read(statefile => 'hp_oneview_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username})); my $has_cache_file = $self->{cache}->read(statefile => 'hp_oneview_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username}));
my $session_id = $options{statefile}->get(name => 'session_id'); my $session_id = $self->{cache}->get(name => 'session_id');
if ($has_cache_file == 0 || !defined($session_id)) { if ($has_cache_file == 0 || !defined($session_id)) {
my $json_request = { userName => $self->{api_username}, password => $self->{api_password} }; my $json_request = { userName => $self->{api_username}, password => $self->{api_password} };
@ -196,7 +196,7 @@ sub authenticate {
} }
my $datas = { last_timestamp => time(), session_id => $session_id }; my $datas = { last_timestamp => time(), session_id => $session_id };
$options{statefile}->write(data => $datas); $self->{cache}->write(data => $datas);
} }
$self->{session_id} = $session_id; $self->{session_id} = $session_id;
@ -207,7 +207,7 @@ sub request_api {
$self->settings(); $self->settings();
if (!defined($self->{session_id})) { if (!defined($self->{session_id})) {
$self->authenticate(statefile => $self->{cache}); $self->authenticate();
} }
my $content = $self->{http}->request( my $content = $self->{http}->request(
%options, %options,
@ -217,7 +217,7 @@ sub request_api {
# Maybe there is an issue with the session_id. So we retry. # Maybe there is an issue with the session_id. So we retry.
if ($self->{http}->get_code() != 200) { if ($self->{http}->get_code() != 200) {
$self->clean_session_id(); $self->clean_session_id();
$self->authenticate(statefile => $self->{cache}); $self->authenticate();
$content = $self->{http}->request(%options, $content = $self->{http}->request(%options,
warning_status => '', unknown_status => '', critical_status => '' warning_status => '', unknown_status => '', critical_status => ''
); );