(plugin) apps::dynatrace::restapi - enhance Dynatrace plugin with new modes and new metrics (#3737)

This commit is contained in:
itoussies 2022-06-17 12:08:04 +02:00 committed by GitHub
parent dab8e6b714
commit 92d9f59634
6 changed files with 710 additions and 72 deletions

View File

@ -80,10 +80,6 @@ sub check_options {
$self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef;
$self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef;
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
$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();
@ -123,44 +119,106 @@ sub settings {
sub request_api {
my ($self, %options) = @_;
$self->settings();
my $content = $self->{http}->request(%options,
warning_status => '', unknown_status => '%{http_code} < 200 or %{http_code} >= 300', critical_status => ''
);
my $decoded;
eval {
$decoded = JSON::XS->new->decode($content);
my $mode_mapping = {
timeseries => 'result',
events => 'events',
problems => 'problems'
};
if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
if (!defined($decoded)) {
$self->{output}->output_add(long_msg => $decoded, debug => 1);
$self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)");
$self->{output}->option_exit();
my $items = [];
$options{get_param} = defined($options{get_param}) ? $options{get_param} : [];
$self->settings();
$options{url_path} = (($self->{hostname} eq 'live.dynatrace.com') ? '' : '/e/' . $self->{option_results}->{environment_id}) . $options{endpoint};
while(1) {
my $content = $self->{http}->request(%options,
warning_status => '', unknown_status => '%{http_code} < 200 or %{http_code} >= 300', critical_status => ''
);
my $decoded;
eval {
$decoded = JSON::XS->new->decode($content);
};
if ($@) {
$self->{output}->output_add(long_msg => $content, debug => 1);
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
$self->{output}->option_exit();
}
if (!defined($decoded)) {
$self->{output}->output_add(long_msg => $decoded, debug => 1);
$self->{output}->add_option_msg(short_msg => "Error while retrieving data (add --debug option for detailed message)");
$self->{output}->option_exit();
}
if ($options{endpoint_type} eq 'timeseries') {
return $decoded;
}
last if (!defined($decoded->{$mode_mapping->{$options{endpoint_type}}}));
push @$items, @{$decoded->{$mode_mapping->{$options{endpoint_type}}}};
last if (!defined($decoded->{nextPageKey}));
$options{get_param} = [@{$options{get_param}}, 'nextPageKey=' . $decoded->{nextPageKey}];
}
return $decoded;
return $items;
}
sub internal_problem {
sub get_apdex {
my ($self, %options) = @_;
my $status = $self->request_api(
method => 'GET',
url_path => (($self->{hostname} eq 'live.dynatrace.com') ? '' : '/e/' . $self->{option_results}->{environment_id}) . '/api/v1/problem/feed?relativeTime=' . $self->{option_results}->{relative_time}
method => 'GET',
endpoint => '/api/v1/timeseries',
get_param => ['timeseriesId=com.dynatrace.builtin:app.apdex',
'queryMode=total',
'aggregationType=' . $self->{option_results}->{aggregation_type},
'relativeTime=' . $self->{option_results}->{relative_time}],
endpoint_type => 'timeseries'
);
return $status;
}
sub api_problem {
sub get_events {
my ($self, %options) = @_;
my $status = $self->request_api(
method => 'GET',
endpoint => '/api/v2/events',
get_param => ['from=now-' . $self->{option_results}->{relative_time}, 'pageSize=500'],
endpoint_type => 'events',
);
return $status;
}
sub get_problems {
my ($self, %options) = @_;
my $status = $self->internal_problem();
return $status->{result}->{problems};
my $status = $self->request_api(
method => 'GET',
endpoint => '/api/v2/problems',
get_param => ['from=now-' . $self->{option_results}->{relative_time}, 'pageSize=500'],
endpoint_type => 'problems'
);
return $status;
}
sub get_synthetic_availability {
my ($self, %options) = @_;
my $status = $self->request_api(
method => 'GET',
endpoint => '/api/v1/timeseries',
get_param => ['timeseriesId=com.dynatrace.builtin:syntheticmonitor.availability.percent',
'queryMode=total', $self->{option_results}->{relative_time},
'relativeTime=' . $self->{option_results}->{relative_time}],
endpoint_type => 'timeseries'
);
return $status;
}
1;

View File

@ -0,0 +1,130 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::monitoring::dynatrace::restapi::mode::apdex;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_entity_output {
my ($self, %options) = @_;
return sprintf(
"Entity '%s' ",
$options{instance_value}->{display}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'apdex', type => 1, cb_prefix_output => 'prefix_entity_output', message_multiple => 'All Apdex are OK', skipped_code => { -10 => 1 }}
];
$self->{maps_counters}->{apdex} = [
{ label => 'apdex', nlabel => 'apdex', set => {
key_values => [ { name => 'apdex' }, { name => 'display' } ],
output_template => 'apdex : %s',
perfdatas => [
{ template => '%s', min => 0, max => 1, label_extra_instance => 1, instance_use => 'display' }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'aggregation-type:s' => { name => 'aggregation_type', default => 'count' },
'filter-entity:s' => { name => 'filter_entity' },
'relative-time:s' => { name => 'relative_time', default => '30mins' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->get_apdex();
foreach my $apdex (keys %{$result->{result}->{dataPoints}}) {
if (defined($self->{option_results}->{filter_entity}) && $self->{option_results}->{filter_entity} ne '' &&
$result->{result}->{entities}->{$apdex} !~ /$self->{option_results}->{filter_entity}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{result}->{entities}->{$apdex} . "': no matching filter.", debug => 1);
next;
}
if (defined($result->{result}->{dataPoints}->{$apdex}[0][1])) {
$self->{apdex}->{$result->{result}->{entities}->{$apdex}} = {
display => $result->{result}->{entities}->{$apdex},
apdex => $result->{result}->{dataPoints}->{$apdex}[0][1]
};
}
}
if (scalar(keys %{$self->{apdex}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No entity found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check Apdex.
=over 8
=item B<--relative-time>
Set request relative time (Default: '30min').
Can use: min, 5mins, 10mins, 15mins, 30mins, hour, 2hours, 6hours, day, 3days, week, month.
=item B<--aggregation-type>
Set aggregation type (Default: 'count').
=item B<--filter-entity>
Filter Apdex by entity (can be a regexp).
=item B<--warning-apdex>
Set warning threshold for Apdex.
=item B<--critical-apdex>
Set critical threshold for Apdex.
=back
=cut

View File

@ -0,0 +1,171 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::monitoring::dynatrace::restapi::mode::availability;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub prefix_synthetic_output {
my ($self, %options) = @_;
return sprintf(
"Synthetick '%s' ",
$options{instance_value}->{name}
);
}
sub synthetic_long_output {
my ($self, %options) = @_;
return sprintf(
"checking Synthetic Monitor '%s'",
$options{instance_value}->{name}
);
}
sub prefix_geolocation_output {
my ($self, %options) = @_;
return sprintf(
"Geolocation '%s' ",
$options{instance_value}->{geolocation}
);
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'synthetic', type => 3, cb_prefix_output => 'prefix_synthetic_output',
cb_long_output => 'synthetic_long_output', indent_long_output => ' ',
message_multiple => 'All Synthetic are ok',
group => [
{ name => 'geolocation', type => 1, cb_prefix_output => 'prefix_geolocation_output', message_multiple => 'All geolocation are OK', skipped_code => { -10 => 1 }}
]
}
];
$self->{maps_counters}->{geolocation} = [
{ label => 'availability', nlabel => 'synthetic.monitor.availability.percentage', set => {
key_values => [ { name => 'availability' }, {name => 'name'} ],
output_template => 'availability : %.2f %%',
perfdatas => [
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
'filter-geolocation:s' => { name => 'filter_geolocation' },
'filter-synthetic:s' => { name => 'filter_synthetic' },
'relative-time:s' => { name => 'relative_time', default => '30mins' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $result = $options{custom}->get_synthetic_availability();
my @synthetic;
my $synthetic_name;
my $synthetic_geolocation;
foreach my $synthetic_mix (keys %{$result->{result}->{dataPoints}}) {
@synthetic = split(', ', $synthetic_mix);
$synthetic_name = $result->{result}->{entities}->{$synthetic[0]};
$synthetic_geolocation = $result->{result}->{entities}->{$synthetic[1]};
if (defined($self->{option_results}->{filter_synthetic}) && $self->{option_results}->{filter_synthetic} ne '' &&
$synthetic_name !~ /$self->{option_results}->{filter_synthetic}/) {
$self->{output}->output_add(long_msg => "skipping '" . $synthetic_name . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_geolocation}) && $self->{option_results}->{filter_geolocation} ne '' &&
$synthetic_geolocation !~ /$self->{option_results}->{filter_geolocation}/) {
$self->{output}->output_add(long_msg => "skipping '" . $synthetic_geolocation . "': no matching filter.", debug => 1);
next;
}
if (defined($result->{result}->{dataPoints}->{$synthetic_mix}[0][1])) {
$self->{synthetic}->{$synthetic_name}->{geolocation}->{$synthetic_geolocation} = {
name => $synthetic_name,
geolocation => $synthetic_geolocation,
availability => $result->{result}->{dataPoints}->{$synthetic_mix}[0][1]
};
}
}
if (scalar(keys %{$self->{synthetic}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No synthetic monitor found.");
$self->{output}->option_exit();
}
foreach my $syntheticmonitor (keys %{$self->{synthetic}}) {
$self->{synthetic}->{$syntheticmonitor}->{name} = $syntheticmonitor;
}
}
1;
__END__
=head1 MODE
Check Synthetic Monitor availability.
=over 8
=item B<--relative-time>
Set request relative time (Default: '30min').
Can use: min, 5mins, 10mins, 15mins, 30mins, hour, 2hours, 6hours, day, 3days, week, month.
=item B<--filter-synthetic>
Filter availability by Synthetic Monitor (can be a regexp).
=item B<--filter-geolocation>
Filter availability by geolocation (can be a regexp).
=item B<--warning-availability>
Set warning threshold for availability.
=item B<--critical-availability>
Set critical threshold for availability.
=back
=cut

View File

@ -0,0 +1,223 @@
#
# Copyright 2022 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::monitoring::dynatrace::restapi::mode::events;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use centreon::plugins::misc;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
"event '%s' [event type: %s] [management zone: %s] [name: %s]",
$self->{result_values}->{displayName},
$self->{result_values}->{eventType},
$self->{result_values}->{managementZone},
$self->{result_values}->{processName}
);
}
sub prefix_management_zones_output {
my ($self, %options) = @_;
return "Management Zone '" . $options{instance_value}->{displayName} . "' ";
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'management_zone', type => 1, cb_prefix_output => 'prefix_management_zones_output', message_multiple => 'All management zones are OK', skipped_code => { -10 => 1 } },
{ name => 'event', type => 2, group => [ { name => 'event' } ] }
];
$self->{maps_counters}->{global} = [
{ label => 'events', nlabel => 'total.events.count', display_ok => 0, set => {
key_values => [ { name => 'events' } ],
output_template => 'number of events : %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{management_zone} = [
{ label => 'managementzone-events', nlabel => 'events.count', set => {
key_values => [ { name => 'events' }, { name => 'displayName' } ],
output_template => 'number of event : %s',
perfdatas => [
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'displayName' }
]
}
}
];
$self->{maps_counters}->{event} = [
{ label => 'status', type => 2, set => {
key_values => [
{ name => 'status' }, { name => 'processName' }, { name => 'displayName' },
{ name => 'startTime' }, { name => 'endTime' }, { name => 'time' },
{ name => 'managementZone' }, { name => 'eventType' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold_ng
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' },
'filter-event-type:s' => { name => 'filter_event_type' },
'filter-management-zone:s' => { name => 'filter_management_zone' },
'relative-time:s' => { name => 'relative_time', default => '2h' }
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $event = $options{custom}->get_events();
my ($i, $time) = (1, time());
my $management_zone_names;
my $process_name;
$self->{global}->{events} = 0;
foreach my $item (@{$event}) {
$management_zone_names = @{$item->{managementZones}} ? join(",", centreon::plugins::misc::uniq(map { "$_->{name}" } @{$item->{managementZones}})) : 'undefined_management_zone';
$process_name = defined($item->{entityId}) ? $item->{entityId}->{name} : 'undefined_name_' . $i;
if (defined($self->{option_results}->{filter_management_zone}) && $self->{option_results}->{filter_management_zone} ne '' &&
$management_zone_names !~ /$self->{option_results}->{filter_management_zone}/) {
$self->{output}->output_add(long_msg => "skipping '" . $management_zone_names . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_event_type}) && $self->{option_results}->{filter_event_type} ne '' &&
$item->{eventType} !~ /$self->{option_results}->{filter_event_type}/) {
$self->{output}->output_add(long_msg => "skipping '" . $item->{eventType} . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$process_name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $process_name . "': no matching filter.", debug => 1);
next;
}
$self->{global}->{events}++;
if (@{$item->{managementZones}}) {
foreach my $management_zones (@{$item->{managementZones}}) {
if (defined($self->{option_results}->{filter_management_zone}) && $self->{option_results}->{filter_management_zone} ne '' &&
$management_zones->{name} !~ /$self->{option_results}->{filter_management_zone}/) {
next;
}
$self->{management_zone}->{$management_zones->{name}}->{events}++;
}
} else {
$self->{management_zone}->{undefined_management_zone}->{events}++;
}
$self->{event}->{global}->{event}->{$i} = {
displayName => $item->{title},
status => $item->{status},
eventType => $item->{eventType},
managementZone => @{$item->{managementZones}} ? join(",", centreon::plugins::misc::uniq(map { "$_->{name}" } @{$item->{managementZones}})) : 'undefined_management_zone',
processName => $process_name,
startTime => $item->{startTime} / 1000,
endTime => $item->{endTime} > -1 ? $item->{endTime} / 1000 : -1,
time => $time
};
$i++;
}
foreach my $management_zone (keys %{$self->{management_zone}}) {
$self->{management_zone}->{$management_zone}->{displayName} = $management_zone;
}
}
1;
__END__
=head1 MODE
Check events.
=over 8
=item B<--relative-time>
Set request relative time (Default: '2h').
Can use: Xm (minutes), Xh (hours), Xd (days), Xm (months), Xy (year) where 'X' is the amount of time.
=item B<--filter-management-zone>
Filter problems by management zone. Mutliple management zones need to be separated by comma.
Example: --management-zone='MZ1,MZ2'
=item B<--filter-event-type>
Filter event by type (can be a regexp).
=item B<--filter-name>
Filter events by entity/name (can be a regexp).
=item B<--unknown-status>
Set unknown threshold for status.
Can use special variables like: %{status}, %{managementZone}, %{entityName}, %{entityId}, %{eventType}, %{startTime}, %{endTime}, %{time}
=item B<--warning-status>
Set warning threshold for status.
Can use special variables like: %{status}, %{managementZone}, %{entityName}, %{entityId}, %{eventType}, %{startTime}, %{endTime}, %{time}
=item B<--critical-status>
Set critical threshold for status.
Can use special variables like: %{status}, %{managementZone}, %{entityName}, %{entityId}, %{eventType}, %{startTime}, %{endTime}, %{time}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'events', 'managementzone-events'.
=back
=cut

View File

@ -31,19 +31,19 @@ sub custom_status_output {
my ($self, %options) = @_;
return sprintf(
"problem '%s' [type: %s] [severity: %s] [impact: %s] [entity: %s]",
"problem '%s' [severity: %s] [impact: %s] [management zone: %s] [entity: %s]",
$self->{result_values}->{displayName},
$self->{result_values}->{eventType},
$self->{result_values}->{severityLevel},
$self->{result_values}->{impactLevel},
$self->{result_values}->{managementZone},
$self->{result_values}->{entityName}
);
}
sub prefix_service_output {
sub prefix_management_zones_output {
my ($self, %options) = @_;
return "Problem '" . $options{instance_value}->{displayName} . "' ";
return "Management Zone '" . $options{instance_value}->{displayName} . "' ";
}
sub set_counters {
@ -51,17 +51,27 @@ sub set_counters {
$self->{maps_counters_type} = [
{ name => 'global', type => 0 },
{ name => 'problems', type => 2, message_multiple => '0 problems detected', display_counter_problem => { label => 'problems', min => 0 },
group => [ { name => 'problem' } ]
}
{ name => 'management_zone', type => 1, cb_prefix_output => 'prefix_management_zones_output', message_multiple => 'All management zones are OK', skipped_code => { -10 => 1 } },
{ name => 'problem', type => 2, group => [ { name => 'problem' } ] }
];
$self->{maps_counters}->{global} = [
{ label => 'problems-open', nlabel => 'problems.open.count', display_ok => 0, set => {
{ label => 'problems-open', nlabel => 'total.problems.open.count', display_ok => 0, set => {
key_values => [ { name => 'problems_open' } ],
output_template => 'number of total open problems : %s',
perfdatas => [
{ template => '%s', min => 0 }
]
}
}
];
$self->{maps_counters}->{management_zone} = [
{ label => 'managementzone-problems-open', nlabel => 'problems.open.count', set => {
key_values => [ { name => 'problems_open' }, { name => 'displayName' } ],
output_template => 'number of open problems : %s',
perfdatas => [
{ template => '%s', value => 'problems_open', min => 0 }
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'displayName' }
]
}
}
@ -71,8 +81,8 @@ sub set_counters {
{ label => 'status', type => 2, critical_default => '%{status} eq "OPEN"', set => {
key_values => [
{ name => 'status' }, { name => 'impactLevel' }, { name => 'severityLevel' },
{ name => 'entityName' }, { name => 'eventType' }, { name => 'entityId' }, { name => 'displayName' },
{ name => 'startTime' }, { name => 'endTime' }, { name => 'commentCount' }, { name => 'time' }
{ name => 'entityName' }, { name => 'entityId' }, { name => 'displayName' },
{ name => 'startTime' }, { name => 'endTime' }, { name => 'time' }, { name => 'managementZone' }
],
closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; },
@ -89,7 +99,9 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
'relative-time:s' => { name => 'relative_time', default => 'min' }
'filter-entity:s' => { name => 'filter_entity' },
'filter-management-zone:s' => { name => 'filter_management_zone' },
'relative-time:s' => { name => 'relative_time', default => '2h' }
});
return $self;
@ -97,34 +109,65 @@ sub new {
sub manage_selection {
my ($self, %options) = @_;
my $problem = $options{custom}->api_problem(relative_time => $options{options}->{relative_time});
$self->{global} = { problems_open => 0 };
$self->{problem} = {};
$self->{problems}->{global} = { problem => {} };
my $problem = $options{custom}->get_problems();
my ($i, $time) = (1, time());
$self->{global}->{problems_open} = 0;
my $management_zone_names;
my $entity_names;
my $entity_id;
foreach my $item (@{$problem}) {
$self->{problems}->{global}->{problem}->{$i} = {
displayName => $item->{displayName},
status => $item->{status},
impactLevel => $item->{impactLevel},
severityLevel => $item->{severityLevel},
entityName => join(",", centreon::plugins::misc::uniq(map { "$_->{entityName}" } @{$item->{rankedImpacts}})),
eventType => join(",", centreon::plugins::misc::uniq(map { "$_->{eventType}" } @{$item->{rankedImpacts}})),
entityId => join(",", centreon::plugins::misc::uniq(map { "$_->{entityId}" } @{$item->{rankedImpacts}})),
startTime => $item->{startTime} / 1000,
endTime => $item->{endTime} > -1 ? $item->{endTime} / 1000 : -1,
commentCount => $item->{commentCount},
time => $time
};
if ($item->{status} eq 'OPEN') {
$self->{global}->{problems_open}++;
$management_zone_names = @{$item->{managementZones}} ? join(",", centreon::plugins::misc::uniq(map { "$_->{name}" } @{$item->{managementZones}})) : 'undefined_management_zone';
$entity_names = @{$item->{impactedEntities}} ? join(",", centreon::plugins::misc::uniq(map { "$_->{name}" } @{$item->{impactedEntities}})) : 'undefined_entity';
$entity_id = @{$item->{impactedEntities}} ? join(",", centreon::plugins::misc::uniq(map { "$_->{entityId}->{id}" } @{$item->{impactedEntities}})) : 'undefined_entity';
if (defined($self->{option_results}->{filter_management_zone}) && $self->{option_results}->{filter_management_zone} ne '' &&
$management_zone_names !~ /$self->{option_results}->{filter_management_zone}/) {
$self->{output}->output_add(long_msg => "skipping '" . $management_zone_names . "': no matching filter.", debug => 1);
next;
}
if (defined($self->{option_results}->{filter_entity}) && $self->{option_results}->{filter_entity} ne '' &&
$entity_names !~ /$self->{option_results}->{filter_entity}/) {
$self->{output}->output_add(long_msg => "skipping '" . $entity_names . "': no matching filter.", debug => 1);
next;
}
if ($item->{status} eq 'OPEN') {
$self->{global}->{problems_open}++;
if (@{$item->{managementZones}}) {
foreach my $management_zones (@{$item->{managementZones}}) {
if (defined($self->{option_results}->{filter_management_zone}) && $self->{option_results}->{filter_management_zone} ne '' &&
$management_zones->{name} !~ /$self->{option_results}->{filter_management_zone}/) {
next;
}
$self->{management_zone}->{$management_zones->{name}}->{problems_open}++;
}
} else {
$self->{management_zone}->{undefined_management_zone}->{problems_open}++;
}
}
$self->{problem}->{global}->{problem}->{$i} = {
displayName => $item->{title},
status => $item->{status},
impactLevel => $item->{impactLevel},
severityLevel => $item->{severityLevel},
managementZone => $management_zone_names,
entityName => $entity_names,
entityId => $entity_id,
startTime => $item->{startTime} / 1000,
endTime => $item->{endTime} > -1 ? $item->{endTime} / 1000 : -1,
time => $time
};
$i++;
}
foreach my $management_zone (keys %{$self->{management_zone}}) {
$self->{management_zone}->{$management_zone}->{displayName} = $management_zone;
}
}
1;
@ -133,34 +176,44 @@ __END__
=head1 MODE
Check problems.
Check open problems.
=over 8
=item B<--relative-time>
Set request relative time (Default: 'min').
Can use: min, 5mins, 10mins, 15mins, 30mins, hour, 2hours, 6hours, day, 3days, week, month.
Set request relative time (Default: '2h').
Can use: Xm (minutes), Xh (hours), Xd (days), Xm (months), Xy (year) where 'X' is the amount of time.
=item B<--filter-management-zone>
Filter problems by management zone. Mutliple management zones need to be separated by comma.
Example: --management-zone='MZ1,MZ2'
=item B<--filter-entity>
Filter problems by entity. Mutliple entities need to be separated by comma.
Example: --entity='entity1,entity2'
=item B<--unknown-status>
Set unknown threshold for status.
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}, %{time}
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{managementZone}, %{entityName}, %{entityId}, %{startTime}, %{endTime}, %{time}
=item B<--warning-status>
Set warning threshold for status.
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}, %{time}
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{managementZone}, %{entityName}, %{entityId}, %{startTime}, %{endTime}, %{time}
=item B<--critical-status>
Set critical threshold for status (Default: '%{status} eq "OPEN"').
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{entityName}, %{eventType}, %{entityId}, %{startTime}, %{endTime}, %{commentCount}, %{time}
Can use special variables like: %{status}, %{impactLevel}, %{severityLevel}, %{managementZone}, %{entityName}, %{entityId}, %{startTime}, %{endTime}, %{time}
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'problems-open'.
Can be: 'problems-open', 'managementzone-problems-open'.
=back

View File

@ -30,9 +30,12 @@ sub new {
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'problems' => 'apps::monitoring::dynatrace::restapi::mode::problems',
);
$self->{modes} = {
'apdex' => 'apps::monitoring::dynatrace::restapi::mode::apdex',
'availability' => 'apps::monitoring::dynatrace::restapi::mode::availability',
'events' => 'apps::monitoring::dynatrace::restapi::mode::events',
'problems' => 'apps::monitoring::dynatrace::restapi::mode::problems'
};
$self->{custom_modes}{api} = 'apps::monitoring::dynatrace::restapi::custom::api';
return $self;