@@ -25,7 +25,7 @@ use warnings;
2525use centreon::plugins::http;
2626use centreon::plugins::statefile;
2727use Digest::SHA qw( sha256_hex) ;
28- use centreon::plugins::misc qw/ json_encode/ ;
28+ use centreon::plugins::misc qw/ json_encode is_not_empty / ;
2929use MIME::Base64;
3030
3131sub new {
@@ -198,8 +198,19 @@ sub refresh_authent_token
198198 if $content =~ / accessToken\" :\s *\" ([^\" ]+)\" /m ;
199199 $refreshToken = $1
200200 if $content =~ / refreshToken\" :\s *\" ([^\" ]+)\" /m ;
201- $expiryTime = $1
202- if $content =~ / tokenExpiryTimes.amp\" :\s *(\d +)/m ; # Commvault returns Times}amp instead of Timestamp
201+
202+ my $token_expiry_timestamp = $1
203+ if $content =~ / "tokenExpiryTimestamp"\s *:\s *(-?\d +)/m ;
204+ my $expires_in = $1
205+ if $content =~ / "expiresIn"\s *:\s *(\d +)/m ;
206+ if ( is_not_empty($token_expiry_timestamp ) ) {
207+ $expiryTime = $token_expiry_timestamp ;
208+ } elsif ( is_not_empty($expires_in ) ) {
209+ $expiryTime = time () + $expires_in ;
210+ } else {
211+ $expiryTime = $1
212+ if $content =~ / tokenExpiryTimes\. amp"\s *:\s *(\d +)/m ; # Commvault returns Times}amp instead of Timestamp
213+ }
203214 }
204215
205216 $self -> {output }-> option_exit(short_msg => " Cannot extract tokens !" )
@@ -284,6 +295,7 @@ sub request_internal {
284295 $self -> {output }-> option_exit(short_msg => ' Tokens where not found. This check can be run after next execution of "token" mode' )
285296 if $authent_token eq ' ' ;
286297
298+ $expiry_time = 0 if !defined ($expiry_time ) || $expiry_time !~ / ^\d +$ / ;
287299 $expiry_time -= time ;
288300 $self -> {output }-> output_add(long_msg => $expiry_time > 0 ? " Token will expire in $expiry_time seconds" : " Token has expired" , debug => 1);
289301
0 commit comments