| 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 storage::ibm::storwize::ssh::mode::eventlog; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::mode); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use DateTime; |
| 28 |
|
| 29 |
sub new { |
| 30 |
my ($class, %options) = @_; |
| 31 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 32 |
bless $self, $class; |
| 33 |
|
| 34 |
$options{options}->add_options(arguments => { |
| 35 |
'warning:s' => { name => 'warning', }, |
| 36 |
'critical:s' => { name => 'critical', }, |
| 37 |
'filter-event-id:s' => { name => 'filter_event_id' }, |
| 38 |
'filter-message:s' => { name => 'filter_message' }, |
| 39 |
'retention:s' => { name => 'retention' } |
| 40 |
}); |
| 41 |
|
| 42 |
return $self; |
| 43 |
} |
| 44 |
|
| 45 |
sub check_options { |
| 46 |
my ($self, %options) = @_; |
| 47 |
$self->SUPER::init(%options); |
| 48 |
|
| 49 |
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { |
| 50 |
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); |
| 51 |
$self->{output}->option_exit(); |
| 52 |
} |
| 53 |
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { |
| 54 |
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); |
| 55 |
$self->{output}->option_exit(); |
| 56 |
} |
| 57 |
|
| 58 |
my $last_timestamp = ''; |
| 59 |
if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} =~ /^\d+$/) { |
| 60 |
# by default UTC timezone used |
| 61 |
my $dt = DateTime->from_epoch(epoch => time() - $self->{option_results}->{retention}); |
| 62 |
my $dt_format = sprintf("%d%02d%02d%02d%02d%02d", substr($dt->year(), 2), $dt->month(), $dt->day(), $dt->hour(), $dt->minute(), $dt->second()); |
| 63 |
$last_timestamp = 'last_timestamp>=' . $dt_format . ":"; |
| 64 |
} |
| 65 |
$self->{ls_command} = "svcinfo lseventlog -message no -alert yes -filtervalue '${last_timestamp}fixed=no' -delim :"; |
| 66 |
} |
| 67 |
|
| 68 |
sub run { |
| 69 |
my ($self, %options) = @_; |
| 70 |
|
| 71 |
my $content = $options{custom}->execute_command(command => $self->{ls_command}); |
| 72 |
my $result = $options{custom}->get_hasharray(content => $content, delim => ':'); |
| 73 |
|
| 74 |
my ($num_eventlog_checked, $num_errors) = (0, 0); |
| 75 |
foreach my $event (@$result) { |
| 76 |
$num_eventlog_checked++; |
| 77 |
if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && |
| 78 |
$event->{description} !~ /$self->{option_results}->{filter_message}/) { |
| 79 |
$self->{output}->output_add(long_msg => "skipping '" . $event->{description} . "': no matching filter description.", debug => 1); |
| 80 |
next; |
| 81 |
} |
| 82 |
if (defined($self->{option_results}->{filter_event_id}) && $self->{option_results}->{filter_event_id} ne '' && |
| 83 |
$event->{event_id} !~ /$self->{option_results}->{filter_event_id}/) { |
| 84 |
$self->{output}->output_add(long_msg => "skipping '" . $event->{event_id} . "': no matching filter event id.", debug => 1); |
| 85 |
next; |
| 86 |
} |
| 87 |
|
| 88 |
my @array = ($event->{last_timestamp} =~ m/../g); # format expected is YYMMDDHHMMSS |
| 89 |
my $date = DateTime->new( |
| 90 |
"year" => "20" . $array[0], # DateTime expect 4 digit year, as this is log the chance of decade old data is slim. |
| 91 |
"month" => $array[1], |
| 92 |
"day" => $array[2], |
| 93 |
"hour" => $array[3], |
| 94 |
"minute" => $array[4], |
| 95 |
"second" => $array[5], |
| 96 |
|
| 97 |
); |
| 98 |
|
| 99 |
$self->{output}->output_add( |
| 100 |
long_msg => sprintf( |
| 101 |
'%s : %s - %s', |
| 102 |
$date->strftime("%a %b %d %T %Y"), |
| 103 |
$event->{event_id}, $event->{description} |
| 104 |
) |
| 105 |
); |
| 106 |
$num_errors++; |
| 107 |
} |
| 108 |
|
| 109 |
$self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked)); |
| 110 |
my $exit = $self->{perfdata}->threshold_check(value => $num_errors, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); |
| 111 |
$self->{output}->output_add( |
| 112 |
severity => $exit, |
| 113 |
short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) |
| 114 |
); |
| 115 |
|
| 116 |
$self->{output}->perfdata_add( |
| 117 |
nlabel => 'eventlogs.problems.count', |
| 118 |
value => $num_errors, |
| 119 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), |
| 120 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), |
| 121 |
min => 0 |
| 122 |
); |
| 123 |
|
| 124 |
$self->{output}->display(); |
| 125 |
$self->{output}->exit(); |
| 126 |
} |
| 127 |
|
| 128 |
1; |
| 129 |
|
| 130 |
__END__ |
| 131 |
|
| 132 |
=head1 MODE |
| 133 |
|
| 134 |
Check event logs. |
| 135 |
|
| 136 |
=over 8 |
| 137 |
|
| 138 |
=item B<--warning> |
| 139 |
|
| 140 |
Warning threshold. |
| 141 |
|
| 142 |
=item B<--critical> |
| 143 |
|
| 144 |
Critical threshold. |
| 145 |
|
| 146 |
=item B<--filter-event-id> |
| 147 |
|
| 148 |
Filter on event id. |
| 149 |
|
| 150 |
=item B<--filter-message> |
| 151 |
|
| 152 |
Filter on event message. |
| 153 |
|
| 154 |
=item B<--retention> |
| 155 |
|
| 156 |
Get eventlog of X last seconds. For the last minutes: --retention=60 |
| 157 |
|
| 158 |
=back |
| 159 |
|
| 160 |
=cut |