enhance dynatrace

This commit is contained in:
garnier-quentin 2020-01-16 10:13:38 +01:00
parent 3703244780
commit 75530a3b76
4 changed files with 50 additions and 34 deletions

View File

@ -18,7 +18,7 @@
# limitations under the License. # limitations under the License.
# #
package apps::dynatrace::restapi::custom::api; package apps::monitoring::dynatrace::restapi::custom::api;
use base qw(centreon::plugins::mode); use base qw(centreon::plugins::mode);
@ -44,12 +44,12 @@ sub new {
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' }, 'hostname:s' => { name => 'hostname' },
"environment-id:s" => { name => 'environment_id' }, 'environment-id:s' => { name => 'environment_id' },
"port:s" => { name => 'port'}, 'port:s' => { name => 'port'},
"proto:s" => { name => 'proto' }, 'proto:s' => { name => 'proto' },
"api-password:s" => { name => 'api_password' }, 'api-password:s' => { name => 'api_password' },
"timeout:s" => { name => 'timeout', default => 30 }, 'timeout:s' => { name => 'timeout', default => 30 },
}); });
} }
@ -138,7 +138,6 @@ sub request_api {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->settings(); $self->settings();
my $content = $self->{http}->request(%options, my $content = $self->{http}->request(%options,
warning_status => '', unknown_status => '%{http_code} < 200 or %{http_code} >= 300', critical_status => '' warning_status => '', unknown_status => '%{http_code} < 200 or %{http_code} >= 300', critical_status => ''
); );

View File

@ -18,20 +18,26 @@
# limitations under the License. # limitations under the License.
# #
package apps::dynatrace::restapi::mode::problem; package apps::monitoring::dynatrace::restapi::mode::problems;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use List::MoreUtils qw(uniq); use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold catalog_status_calc);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'detected'; return sprintf(
return $msg; "problem '%s' [type: %s] [severity: %s] [impact: %s] [entity: %s]",
$self->{result_values}->{displayName},
$self->{result_values}->{eventType},
$self->{result_values}->{severityLevel},
$self->{result_values}->{impactLevel},
$self->{result_values}->{entityName}
);
} }
sub set_counters { sub set_counters {
@ -39,15 +45,17 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
{ name => 'problem', type => 1, cb_prefix_output => 'prefix_service_output', message_multiple => 'No problem detected' } { name => 'problems', type => 2, message_multiple => '0 problems detected', display_counter_problem => { label => 'problems', min => 0 },
group => [ { name => 'problem' } ]
}
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'problems-open', nlabel => 'problems.open.count', set => { { label => 'problems-open', nlabel => 'problems.open.count', display_ok => 0, set => {
key_values => [ { name => 'problems_open' } ], key_values => [ { name => 'problems_open' } ],
output_template => 'Number of open problems : %s', output_template => 'number of open problems : %s',
perfdatas => [ perfdatas => [
{ template => '%s', value => 'problems_open_absolute', min => 0 }, { value => 'problems_open_absolute', template => '%s', value => 'problems_open_absolute', min => 0 },
], ],
} }
}, },
@ -55,7 +63,10 @@ sub set_counters {
$self->{maps_counters}->{problem} = [ $self->{maps_counters}->{problem} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'status' }, { name => 'impactLevel' }, { name => 'severityLevel' }, { name => 'entityName' }, { name => 'eventType' }, { name => 'entityId' }, { name => 'startTime' }, { name => 'endTime' }, { name => 'commentCount' } ], key_values => [ { name => 'status' }, { name => 'impactLevel' }, { name => 'severityLevel' },
{ name => 'entityName' }, { name => 'eventType' }, { name => 'entityId' }, { name => 'displayName' },
{ name => 'startTime' }, { name => 'endTime' }, { name => 'commentCount' }
],
closure_custom_calc => \&catalog_status_calc, closure_custom_calc => \&catalog_status_calc,
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
@ -100,29 +111,31 @@ sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $problem = $options{custom}->api_problem(relative_time => $options{options}->{relative_time}); my $problem = $options{custom}->api_problem(relative_time => $options{options}->{relative_time});
my $problems_open = 0;
$self->{global} = { problems_open => 0 };
$self->{problem} = {}; $self->{problem} = {};
$self->{problems}->{global} = { problem => {} };
my $i = 1;
foreach my $item (@{$problem}) { foreach my $item (@{$problem}) {
$self->{problem}->{$item->{displayName}} = { $self->{problems}->{global}->{problem}->{$i} = {
displayName => $item->{displayName}, displayName => $item->{displayName},
status => $item->{status}, status => $item->{status},
impactLevel => $item->{impactLevel}, impactLevel => $item->{impactLevel},
severityLevel => $item->{severityLevel}, severityLevel => $item->{severityLevel},
entityName => join(",", uniq map { "$_->{entityName}" } @{$item->{rankedImpacts}}), entityName => join(",", centreon::plugins::misc::uniq(map { "$_->{entityName}" } @{$item->{rankedImpacts}})),
eventType => join(",", uniq map { "$_->{eventType}" } @{$item->{rankedImpacts}}), eventType => join(",", centreon::plugins::misc::uniq(map { "$_->{eventType}" } @{$item->{rankedImpacts}})),
entityId => join(",", uniq map { "$_->{entityId}" } @{$item->{rankedImpacts}}), entityId => join(",", centreon::plugins::misc::uniq(map { "$_->{entityId}" } @{$item->{rankedImpacts}})),
startTime => $item->{startTime} / 1000, startTime => $item->{startTime} / 1000,
endTime => $item->{endTime} > -1 ? $item->{endTime} / 1000 : -1, endTime => $item->{endTime} > -1 ? $item->{endTime} / 1000 : -1,
commentCount => $item->{commentCount}, commentCount => $item->{commentCount},
}; };
if ($item->{status} eq 'OPEN') { if ($item->{status} eq 'OPEN') {
$problems_open++; $self->{global}->{problems_open}++;
}
} }
$self->{global} = { $i++;
problems_open => $problems_open, }
};
} }
1; 1;
@ -131,7 +144,7 @@ __END__
=head1 MODE =head1 MODE
Check problem Check problems.
=over 8 =over 8
@ -140,7 +153,6 @@ Check problem
Set request relative time (Default: 'min'). Set request relative time (Default: 'min').
Can use: min, 5mins, 10mins, 15mins, 30mins, hour, 2hours, 6hours, day, 3days, week, month. Can use: min, 5mins, 10mins, 15mins, 30mins, hour, 2hours, 6hours, day, 3days, week, month.
=item B<--unknown-status> =item B<--unknown-status>
Set unknown threshold for status. Set unknown threshold for status.

View File

@ -18,7 +18,7 @@
# limitations under the License. # limitations under the License.
# #
package apps::dynatrace::restapi::plugin; package apps::monitoring::dynatrace::restapi::plugin;
use strict; use strict;
use warnings; use warnings;
@ -26,16 +26,15 @@ use base qw(centreon::plugins::script_custom);
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
%{$self->{modes}} = ( %{$self->{modes}} = (
'problem' => 'apps::dynatrace::restapi::mode::problem', 'problems' => 'apps::monitoring::dynatrace::restapi::mode::problems',
); );
$self->{custom_modes}{api} = 'apps::dynatrace::restapi::custom::api'; $self->{custom_modes}{api} = 'apps::monitoring::dynatrace::restapi::custom::api';
return $self; return $self;
} }

View File

@ -536,6 +536,12 @@ sub set_timezone {
return {}; return {};
} }
sub uniq {
my %seen;
return grep { !$seen{$_}++ } @_;
}
1; 1;
__END__ __END__