| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package cloud::aws::health::mode::events; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_global_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return 'Events '; |
| 32 |
} |
| 33 |
|
| 34 |
sub set_counters { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
$self->{maps_counters_type} = [ |
| 38 |
{ name => 'global', cb_prefix_output => 'prefix_global_output', type => 0 } |
| 39 |
]; |
| 40 |
|
| 41 |
$self->{maps_counters}->{global} = [ |
| 42 |
{ label => 'total', nlabel => 'events.total.count', set => { |
| 43 |
key_values => [ { name => 'total' } ], |
| 44 |
output_template => 'total: %s', |
| 45 |
perfdatas => [ |
| 46 |
{ template => '%s', min => 0 } |
| 47 |
] |
| 48 |
} |
| 49 |
}, |
| 50 |
{ label => 'open', nlabel => 'events.open.count', set => { |
| 51 |
key_values => [ { name => 'open' } ], |
| 52 |
output_template => 'open: %s', |
| 53 |
perfdatas => [ |
| 54 |
{ template => '%s', min => 0 } |
| 55 |
] |
| 56 |
} |
| 57 |
}, |
| 58 |
{ label => 'closed', nlabel => 'events.closed.count', set => { |
| 59 |
key_values => [ { name => 'closed' } ], |
| 60 |
output_template => 'closed: %s', |
| 61 |
perfdatas => [ |
| 62 |
{ template => '%s', min => 0 } |
| 63 |
] |
| 64 |
} |
| 65 |
}, |
| 66 |
{ label => 'upcoming', nlabel => 'events.upcoming.count', set => { |
| 67 |
key_values => [ { name => 'upcoming' } ], |
| 68 |
output_template => 'upcoming: %s', |
| 69 |
perfdatas => [ |
| 70 |
{ template => '%s', min => 0 } |
| 71 |
] |
| 72 |
} |
| 73 |
} |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
sub new { |
| 78 |
my ($class, %options) = @_; |
| 79 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 80 |
bless $self, $class; |
| 81 |
|
| 82 |
$options{options}->add_options(arguments => { |
| 83 |
'filter-service:s@' => { name => 'filter_service' }, |
| 84 |
'filter-region:s@' => { name => 'filter_region' }, |
| 85 |
'filter-entity-value:s@' => { name => 'filter_entity_value' }, |
| 86 |
'filter-event-status:s@' => { name => 'filter_event_status' }, |
| 87 |
'filter-event-category:s@' => { name => 'filter_event_category' }, |
| 88 |
'display-affected-entities' => { name => 'display_affected_entities' } |
| 89 |
}); |
| 90 |
|
| 91 |
return $self; |
| 92 |
} |
| 93 |
|
| 94 |
sub check_options { |
| 95 |
my ($self, %options) = @_; |
| 96 |
$self->SUPER::check_options(%options); |
| 97 |
|
| 98 |
$self->{filter_options} = {}; |
| 99 |
foreach (('service', 'region', 'entity_value', 'event_status', 'event_category')) { |
| 100 |
$self->{filter_options}->{'filter_' . $_} = undef; |
| 101 |
if (defined($self->{option_results}->{'filter_' . $_})) { |
| 102 |
foreach my $option (@{$self->{option_results}->{'filter_' . $_}}) { |
| 103 |
next if ($option eq ''); |
| 104 |
|
| 105 |
$self->{filter_options}->{'filter_' . $_} = [] if (!defined($self->{filter_options}->{'filter_' . $_})); |
| 106 |
push @{$self->{filter_options}->{'filter_' . $_}}, split(/,/, $option); |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
sub manage_selection { |
| 113 |
my ($self, %options) = @_; |
| 114 |
|
| 115 |
my $results = $options{custom}->health_describe_events( |
| 116 |
%{$self->{filter_options}} |
| 117 |
); |
| 118 |
|
| 119 |
$self->{global} = { total => 0, open => 0, closed => 0, upcoming => 0 }; |
| 120 |
my $events = {}; |
| 121 |
foreach my $entry (@$results) { |
| 122 |
$self->{global}->{ lc($entry->{statusCode}) }++; |
| 123 |
$self->{global}->{total}++; |
| 124 |
|
| 125 |
$events->{ $entry->{arn} } = $entry; |
| 126 |
} |
| 127 |
|
| 128 |
my $affected_entities; |
| 129 |
my @event_arns = sort { $events->{$b}->{startTime} cmp $events->{$a}->{startTime} } keys %$events; |
| 130 |
if (scalar(@event_arns) > 0 && defined($self->{option_results}->{display_affected_entities})) { |
| 131 |
$affected_entities = $options{custom}->health_describe_affected_entities(filter_event_arns => [@event_arns]); |
| 132 |
} |
| 133 |
|
| 134 |
foreach (@event_arns) { |
| 135 |
my $entity = ''; |
| 136 |
if (defined($affected_entities)) { |
| 137 |
$entity = '[affected entity: -]'; |
| 138 |
foreach my $affected (@$affected_entities) { |
| 139 |
if ($events->{$_}->{arn} eq $affected->{eventArn}) { |
| 140 |
$entity = '[affected entity: ' . $affected->{entityValue} . ']'; |
| 141 |
last; |
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
$self->{output}->output_add(long_msg => |
| 147 |
sprintf( |
| 148 |
'[service: %s][region: %s][status: %s][type: %s][start: %s]%s', |
| 149 |
$events->{$_}->{service}, |
| 150 |
$events->{$_}->{region}, |
| 151 |
$events->{$_}->{statusCode}, |
| 152 |
$events->{$_}->{eventTypeCode}, |
| 153 |
$events->{$_}->{startTime} =~ m/^\d{4}-\d{2}-\d{2}/ ? $events->{$_}->{startTime} : scalar(localtime($events->{$_}->{startTime})), |
| 154 |
$entity |
| 155 |
) |
| 156 |
); |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
1; |
| 161 |
|
| 162 |
__END__ |
| 163 |
|
| 164 |
=head1 MODE |
| 165 |
|
| 166 |
Check health events. |
| 167 |
|
| 168 |
=over 8 |
| 169 |
|
| 170 |
=item B<--filter-service> |
| 171 |
|
| 172 |
Filter result by service (multiple option). |
| 173 |
Example: --filter-service=EC2 --filter-service=RDS |
| 174 |
|
| 175 |
=item B<--filter-region> |
| 176 |
|
| 177 |
Filter result by region (multiple option). |
| 178 |
Example: --filter-region=ap-southeast-1 --filter-region=eu-west-1 |
| 179 |
|
| 180 |
=item B<--filter-entity-value> |
| 181 |
|
| 182 |
Filter result by entity value (multiple option). |
| 183 |
Example: --filter-entity-value=i-34ab692e --filter-entity-value=vol-426ab23e |
| 184 |
|
| 185 |
=item B<--filter-event-status> |
| 186 |
|
| 187 |
Filter result by event status (multiple option). |
| 188 |
Example: --filter-event-status=open --filter-event-status=closed |
| 189 |
|
| 190 |
=item B<--filter-event-category> |
| 191 |
|
| 192 |
Filter result by event category (multiple option). |
| 193 |
Example: --filter-event-category=issue |
| 194 |
|
| 195 |
=item B<--display-affected-entities> |
| 196 |
|
| 197 |
Display affected entities by the event. |
| 198 |
|
| 199 |
=item B<--warning-*> B<--critical-*> |
| 200 |
|
| 201 |
Thresholds. |
| 202 |
Can be: 'total', 'open', 'closed', 'upcoming'. |
| 203 |
|
| 204 |
=back |
| 205 |
|
| 206 |
=cut |