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

@ -42,20 +42,20 @@ sub new {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit(); $options{output}->option_exit();
} }
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);
@ -64,7 +64,7 @@ sub new {
$self->{mode} = $options{mode}; $self->{mode} = $options{mode};
$self->{http} = centreon::plugins::http->new(%options); $self->{http} = centreon::plugins::http->new(%options);
$self->{cache} = centreon::plugins::statefile->new(%options); $self->{cache} = centreon::plugins::statefile->new(%options);
return $self; return $self;
} }
@ -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(
full_url => $self->{login_endpoint} . '/' . $self->{tenant} . '/oauth2/token', method => 'POST', query_form_post => $post_data,
hostname => ''); full_url => $self->{login_endpoint} . '/' . $self->{tenant} . '/oauth2/token',
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();
} }
@ -205,7 +207,7 @@ sub get_access_token {
my $datas = { last_timestamp => time(), access_token => $decoded->{access_token}, expires_on => $decoded->{expires_on} }; my $datas = { last_timestamp => time(), access_token => $decoded->{access_token}, expires_on => $decoded->{expires_on} };
$options{statefile}->write(data => $datas); $options{statefile}->write(data => $datas);
} }
return $access_token; return $access_token;
} }
@ -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;
@ -291,7 +297,7 @@ sub azure_get_metrics_set_url {
sub azure_get_metrics { sub azure_get_metrics {
my ($self, %options) = @_; my ($self, %options) = @_;
my $results = {}; my $results = {};
my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z'; my $start_time = DateTime->now->subtract(seconds => $options{timeframe})->iso8601.'Z';
my $end_time = DateTime->now->iso8601.'Z'; my $end_time = DateTime->now->iso8601.'Z';
@ -326,12 +332,12 @@ sub azure_get_metrics {
} }
} }
} }
if (defined($results->{$metric_name}->{average})) { if (defined($results->{$metric_name}->{average})) {
$results->{$metric_name}->{average} /= $results->{$metric_name}->{points}; $results->{$metric_name}->{average} /= $results->{$metric_name}->{points};
} }
} }
return $results, $response; return $results, $response;
} }
@ -347,16 +353,16 @@ sub azure_get_resource_health_set_url {
sub azure_get_resource_health { sub azure_get_resource_health {
my ($self, %options) = @_; my ($self, %options) = @_;
my $full_url = $self->azure_get_resource_health_set_url(%options); my $full_url = $self->azure_get_resource_health_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; return $response;
} }
sub azure_list_resources_set_url { sub azure_list_resources_set_url {
my ($self, %options) = @_; my ($self, %options) = @_;
my $filter = ''; my $filter = '';
my %filter; my %filter;
$filter{resource_type} = "resourceType eq '" . $options{namespace} . '/' . $options{resource_type} . "'" if (defined($options{namespace}) && $options{namespace} ne '' && defined($options{resource_type}) && $options{resource_type} ne ''); $filter{resource_type} = "resourceType eq '" . $options{namespace} . '/' . $options{resource_type} . "'" if (defined($options{namespace}) && $options{namespace} ne '' && defined($options{resource_type}) && $options{resource_type} ne '');
@ -375,16 +381,16 @@ sub azure_list_resources_set_url {
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resources?api-version=" . $self->{api_version}; my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resources?api-version=" . $self->{api_version};
$url .= "&\$filter=" . $encoded_filter if (defined($encoded_filter) && $encoded_filter ne ''); $url .= "&\$filter=" . $encoded_filter if (defined($encoded_filter) && $encoded_filter ne '');
return $url; return $url;
} }
sub azure_list_resources { sub azure_list_resources {
my ($self, %options) = @_; my ($self, %options) = @_;
my $full_url = $self->azure_list_resources_set_url(%options); my $full_url = $self->azure_list_resources_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};
} }
@ -400,7 +406,7 @@ sub azure_list_vms_set_url {
sub azure_list_vms { sub azure_list_vms {
my ($self, %options) = @_; my ($self, %options) = @_;
my $full_url = $self->azure_list_vms_set_url(%options); my $full_url = $self->azure_list_vms_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 => '');
@ -411,16 +417,14 @@ 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;
} }
sub azure_list_groups { sub azure_list_groups {
my ($self, %options) = @_; my ($self, %options) = @_;
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};
} }
@ -429,16 +433,15 @@ sub azure_list_deployments_set_url {
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" . my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
$options{resource_group} . "/providers/Microsoft.Resources/deployments?api-version=" . $self->{api_version}; $options{resource_group} . "/providers/Microsoft.Resources/deployments?api-version=" . $self->{api_version};
return $url; return $url;
} }
sub azure_list_deployments { sub azure_list_deployments {
my ($self, %options) = @_; my ($self, %options) = @_;
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,16 +451,14 @@ 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;
} }
sub azure_list_vaults { sub azure_list_vaults {
my ($self, %options) = @_; my ($self, %options) = @_;
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};
} }
@ -467,16 +468,15 @@ sub azure_list_backup_jobs_set_url {
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" . my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
$options{resource_group} . "/providers/Microsoft.RecoveryServices/vaults/" . $options{resource_group} . "/providers/Microsoft.RecoveryServices/vaults/" .
$options{vault_name} . "/backupJobs?api-version=" . $self->{api_version}; $options{vault_name} . "/backupJobs?api-version=" . $self->{api_version};
return $url; return $url;
} }
sub azure_list_backup_jobs { sub azure_list_backup_jobs {
my ($self, %options) = @_; my ($self, %options) = @_;
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};
} }
@ -486,16 +486,16 @@ sub azure_list_backup_items_set_url {
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" . my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
$options{resource_group} . "/providers/Microsoft.RecoveryServices/vaults/" . $options{resource_group} . "/providers/Microsoft.RecoveryServices/vaults/" .
$options{vault_name} . "/backupProtectedItems?api-version=" . $self->{api_version}; $options{vault_name} . "/backupProtectedItems?api-version=" . $self->{api_version};
return $url; return $url;
} }
sub azure_list_backup_items { sub azure_list_backup_items {
my ($self, %options) = @_; my ($self, %options) = @_;
my $full_url = $self->azure_list_backup_items_set_url(%options); my $full_url = $self->azure_list_backup_items_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};
} }
@ -505,16 +505,16 @@ sub azure_list_expressroute_circuits_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.Network/expressRouteCircuits?api-version=" . $self->{api_version}; $url .= "/providers/Microsoft.Network/expressRouteCircuits?api-version=" . $self->{api_version};
return $url; return $url;
} }
sub azure_list_expressroute_circuits { sub azure_list_expressroute_circuits {
my ($self, %options) = @_; my ($self, %options) = @_;
my $full_url = $self->azure_list_expressroute_circuits_set_url(%options); my $full_url = $self->azure_list_expressroute_circuits_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};
} }
@ -523,7 +523,7 @@ sub azure_list_vpn_gateways_set_url {
my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" . my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
$options{resource_group} . "/providers/Microsoft.Network/virtualNetworkGateways?api-version=" . $self->{api_version}; $options{resource_group} . "/providers/Microsoft.Network/virtualNetworkGateways?api-version=" . $self->{api_version};
return $url; return $url;
} }
@ -542,7 +542,7 @@ sub azure_list_virtualnetworks_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.Network/virtualNetworks?api-version=" . $self->{api_version}; $url .= "/providers/Microsoft.Network/virtualNetworks?api-version=" . $self->{api_version};
return $url; return $url;
} }
@ -562,7 +562,7 @@ sub azure_list_vnet_peerings_set_url {
$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.Network/virtualNetworks/" . $options{vnet_name} if (defined($options{vnet_name}) && $options{vnet_name} ne ''); $url .= "/providers/Microsoft.Network/virtualNetworks/" . $options{vnet_name} if (defined($options{vnet_name}) && $options{vnet_name} ne '');
$url .= "/virtualNetworkPeerings?api-version=" . $self->{api_version}; $url .= "/virtualNetworkPeerings?api-version=" . $self->{api_version};
return $url; return $url;
} }
@ -581,7 +581,7 @@ sub azure_list_sqlservers_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.Sql/servers?api-version=" . $self->{api_version}; $url .= "/providers/Microsoft.Sql/servers?api-version=" . $self->{api_version};
return $url; return $url;
} }