From 76a31e65429d60a08d26b4cbfbb69b1df5eed7ad Mon Sep 17 00:00:00 2001 From: CPbN <40244829+CPbN@users.noreply.github.com> Date: Thu, 16 Jan 2020 07:58:30 +0100 Subject: [PATCH] Support Managed endpoints --- .../apps/dynatrace/restapi/custom/api.pm | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/apps/dynatrace/restapi/custom/api.pm b/centreon-plugins/apps/dynatrace/restapi/custom/api.pm index dd346f7f8..65ca38ca5 100644 --- a/centreon-plugins/apps/dynatrace/restapi/custom/api.pm +++ b/centreon-plugins/apps/dynatrace/restapi/custom/api.pm @@ -45,6 +45,7 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { "hostname:s" => { name => 'hostname' }, + "environment-id:s" => { name => 'environment_id' }, "port:s" => { name => 'port'}, "proto:s" => { name => 'proto' }, "api-password:s" => { name => 'api_password' }, @@ -86,7 +87,8 @@ sub set_defaults { sub check_options { my ($self, %options) = @_; - $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef; + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'live.dynatrace.com'; + $self->{environment_id} = (defined($self->{option_results}->{environment_id})) ? $self->{option_results}->{environment_id} : undef; $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 30; @@ -97,6 +99,10 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify --hostname option."); $self->{output}->option_exit(); } + if (!defined($self->{environment_id}) || $self->{environment_id} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --environment-id option."); + $self->{output}->option_exit(); + } if (!defined($self->{api_password}) || $self->{api_password} eq '') { $self->{output}->add_option_msg(short_msg => "Need to specify --api-password option."); $self->{output}->option_exit(); @@ -108,7 +114,11 @@ sub check_options { sub build_options_for_httplib { my ($self, %options) = @_; - $self->{option_results}->{hostname} = $self->{hostname}; + if ($self->{hostname} eq 'live.dynatrace.com') { + $self->{option_results}->{hostname} = $self->{environment_id} . '.' . $self->{hostname}; + } else { + $self->{option_results}->{hostname} = $self->{hostname}; + } $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; $self->{option_results}->{ssl_opt} = $self->{ssl_opt}; @@ -154,7 +164,7 @@ sub request_api { sub internal_problem { my ($self, %options) = @_; - my $status = $self->request_api(method => 'GET', url_path =>'/api/v1/problem/feed?relativeTime=' . $self->{option_results}->{relative_time}); + my $status = $self->request_api(method => 'GET', url_path => (($self->{hostname} eq 'live.dynatrace.com') ? '' : '/e') . '/api/v1/problem/feed?relativeTime=' . $self->{option_results}->{relative_time}); return $status; } @@ -179,7 +189,11 @@ Dynatrace Rest API =item B<--hostname> -Set hostname or IP of Dynatrace server. +Set hostname or IP of Dynatrace server (Default: live.dynatrace.com). + +=item B<--environment-id> + +Set Dynatrace environment ID. =item B<--port>