enhance typo

This commit is contained in:
garnier-quentin 2020-02-12 17:56:48 +01:00
parent 61b5858838
commit ad5af78524
1 changed files with 55 additions and 55 deletions

View File

@ -45,17 +45,17 @@ sub new {
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"subscription:s" => { name => 'subscription' }, 'subscription:s' => { name => 'subscription' },
"tenant:s" => { name => 'tenant' }, 'tenant:s' => { name => 'tenant' },
"client-id:s" => { name => 'client_id' }, 'client-id:s' => { name => 'client_id' },
"client-secret:s" => { name => 'client_secret' }, 'client-secret:s' => { name => 'client_secret' },
"login-endpoint:s" => { name => 'login_endpoint' }, 'login-endpoint:s' => { name => 'login_endpoint' },
"management-endpoint:s" => { name => 'management_endpoint' }, 'management-endpoint:s' => { name => 'management_endpoint' },
"timeframe:s" => { name => 'timeframe' }, 'timeframe:s' => { name => 'timeframe' },
"interval:s" => { name => 'interval' }, 'interval:s' => { name => 'interval' },
"aggregation:s@" => { name => 'aggregation' }, 'aggregation:s@' => { name => 'aggregation' },
"zeroed" => { name => 'zeroed' }, 'zeroed' => { name => 'zeroed' },
"timeout:s" => { name => 'timeout' }, 'timeout:s' => { name => 'timeout' },
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1);
@ -177,9 +177,11 @@ sub get_access_token {
$self->settings(); $self->settings();
my $content = $self->{http}->request(method => 'POST', query_form_post => $post_data, my $content = $self->{http}->request(
method => 'POST', query_form_post => $post_data,
full_url => $self->{login_endpoint} . '/' . $self->{tenant} . '/oauth2/token', full_url => $self->{login_endpoint} . '/' . $self->{tenant} . '/oauth2/token',
hostname => ''); hostname => ''
);
if (!defined($content) || $content eq '' || $self->{http}->get_header(name => 'content-length') == 0) { if (!defined($content) || $content eq '' || $self->{http}->get_header(name => 'content-length') == 0) {
$self->{output}->add_option_msg(short_msg => "Login endpoint API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']"); $self->{output}->add_option_msg(short_msg => "Login endpoint API returns empty content [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");
@ -191,7 +193,7 @@ sub get_access_token {
$decoded = JSON::XS->new->utf8->decode($content); $decoded = JSON::XS->new->utf8->decode($content);
}; };
if ($@) { if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->output_add(long_msg => $@, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -232,7 +234,7 @@ sub request_api {
$decoded = JSON::XS->new->utf8->decode($content); $decoded = JSON::XS->new->utf8->decode($content);
}; };
if ($@) { if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->output_add(long_msg => $@, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
@ -255,15 +257,19 @@ sub convert_duration {
my $duration; my $duration;
if ($options{time_string} =~ /^P.*S$/) { if ($options{time_string} =~ /^P.*S$/) {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime::Format::Duration::ISO8601', centreon::plugins::misc::mymodule_load(
error_msg => "Cannot load module 'DateTime::Format::Duration::ISO8601'."); output => $self->{output}, module => 'DateTime::Format::Duration::ISO8601',
error_msg => "Cannot load module 'DateTime::Format::Duration::ISO8601'."
);
my $format = DateTime::Format::Duration::ISO8601->new; my $format = DateTime::Format::Duration::ISO8601->new;
my $d = $format->parse_duration($options{time_string}); my $d = $format->parse_duration($options{time_string});
$duration = $d->minutes * 60 + $d->seconds; $duration = $d->minutes * 60 + $d->seconds;
} elsif ($options{time_string} =~ /^(\d+):(\d+):(\d+)\.\d+$/) { } elsif ($options{time_string} =~ /^(\d+):(\d+):(\d+)\.\d+$/) {
centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'DateTime::Duration', centreon::plugins::misc::mymodule_load(
error_msg => "Cannot load module 'DateTime::Format::Duration'."); output => $self->{output}, module => 'DateTime::Duration',
error_msg => "Cannot load module 'DateTime::Format::Duration'."
);
my $d = DateTime::Duration->new(hours => $1, minutes => $2, seconds => $3); my $d = DateTime::Duration->new(hours => $1, minutes => $2, seconds => $3);
$duration = $d->minutes * 60 + $d->seconds; $duration = $d->minutes * 60 + $d->seconds;
@ -411,7 +417,6 @@ sub azure_list_groups_set_url {
my ($self, %options) = @_; my ($self, %options) = @_;
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups?api-version=" . $self->{api_version}; my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups?api-version=" . $self->{api_version};
return $url; return $url;
} }
@ -420,7 +425,6 @@ sub azure_list_groups {
my $full_url = $self->azure_list_groups_set_url(%options); my $full_url = $self->azure_list_groups_set_url(%options);
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
return $response->{value}; return $response->{value};
} }
@ -438,7 +442,6 @@ sub azure_list_deployments {
my $full_url = $self->azure_list_deployments_set_url(%options); my $full_url = $self->azure_list_deployments_set_url(%options);
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
return $response->{value}; return $response->{value};
} }
@ -448,7 +451,6 @@ sub azure_list_vaults_set_url {
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription}; my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription};
$url .= "/resourceGroups/" . $options{resource_group} if (defined($options{resource_group}) && $options{resource_group} ne ''); $url .= "/resourceGroups/" . $options{resource_group} if (defined($options{resource_group}) && $options{resource_group} ne '');
$url .= "/providers/Microsoft.RecoveryServices/vaults?api-version=" . $self->{api_version}; $url .= "/providers/Microsoft.RecoveryServices/vaults?api-version=" . $self->{api_version};
return $url; return $url;
} }
@ -457,7 +459,6 @@ sub azure_list_vaults {
my $full_url = $self->azure_list_vaults_set_url(%options); my $full_url = $self->azure_list_vaults_set_url(%options);
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
return $response->{value}; return $response->{value};
} }
@ -476,7 +477,6 @@ sub azure_list_backup_jobs {
my $full_url = $self->azure_list_backup_jobs_set_url(%options); my $full_url = $self->azure_list_backup_jobs_set_url(%options);
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => ''); my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
return $response->{value}; return $response->{value};
} }