mirror of
https://github.com/centreon/centreon-plugins.git
synced 2025-07-28 16:14:21 +02:00
MON-21973-date-problem-on-storage-ibm-storwize-ssh-plugin-eventlog (#4676)
Co-authored-by: Matteo D'Alfonso <mdalfonso@centreon.com> Co-authored-by: Lucie Dubrunfaut <ldubrunfaut@CNTR-P-PF3DNAR1> Co-authored-by: Evan <eadam@centreon.com>
This commit is contained in:
parent
186afcb092
commit
dd3f3a3b36
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"libssh-session-perl",
|
"libssh-session-perl",
|
||||||
"plink"
|
"plink"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,11 @@ sub new {
|
|||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
'warning:s' => { name => 'warning', },
|
'warning:s' => { name => 'warning', },
|
||||||
'critical:s' => { name => 'critical', },
|
'critical:s' => { name => 'critical', },
|
||||||
'filter-event-id:s' => { name => 'filter_event_id' },
|
'filter-event-id:s' => { name => 'filter_event_id' },
|
||||||
'filter-message:s' => { name => 'filter_message' },
|
'filter-message:s' => { name => 'filter_message' },
|
||||||
'retention:s' => { name => 'retention' }
|
'retention:s' => { name => 'retention' }
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
@ -72,24 +72,35 @@ sub run {
|
|||||||
my $result = $options{custom}->get_hasharray(content => $content, delim => ':');
|
my $result = $options{custom}->get_hasharray(content => $content, delim => ':');
|
||||||
|
|
||||||
my ($num_eventlog_checked, $num_errors) = (0, 0);
|
my ($num_eventlog_checked, $num_errors) = (0, 0);
|
||||||
foreach (@$result) {
|
foreach my $event (@$result) {
|
||||||
$num_eventlog_checked++;
|
$num_eventlog_checked++;
|
||||||
if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' &&
|
if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' &&
|
||||||
$_->{description} !~ /$self->{option_results}->{filter_message}/) {
|
$event->{description} !~ /$self->{option_results}->{filter_message}/) {
|
||||||
$self->{output}->output_add(long_msg => "skipping '" . $_->{description} . "': no matching filter description.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $event->{description} . "': no matching filter description.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if (defined($self->{option_results}->{filter_event_id}) && $self->{option_results}->{filter_event_id} ne '' &&
|
if (defined($self->{option_results}->{filter_event_id}) && $self->{option_results}->{filter_event_id} ne '' &&
|
||||||
$_->{event_id} !~ /$self->{option_results}->{filter_event_id}/) {
|
$event->{event_id} !~ /$self->{option_results}->{filter_event_id}/) {
|
||||||
$self->{output}->output_add(long_msg => "skipping '" . $_->{event_id} . "': no matching filter event id.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $event->{event_id} . "': no matching filter event id.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my @array = ($event->{last_timestamp} =~ m/../g); # format expected is YYMMDDHHMMSS
|
||||||
|
my $date = DateTime->new(
|
||||||
|
"year" => "20" . $array[0], # DateTime expect 4 digit year, as this is log the chance of decade old data is slim.
|
||||||
|
"month" => $array[1],
|
||||||
|
"day" => $array[2],
|
||||||
|
"hour" => $array[3],
|
||||||
|
"minute" => $array[4],
|
||||||
|
"second" => $array[5],
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
$self->{output}->output_add(
|
$self->{output}->output_add(
|
||||||
long_msg => sprintf(
|
long_msg => sprintf(
|
||||||
'%s : %s - %s',
|
'%s : %s - %s',
|
||||||
scalar(localtime($_->{last_timestamp})),
|
$date->strftime("%a %b %d %T %Y"),
|
||||||
$_->{event_id}, $_->{description}
|
$event->{event_id}, $event->{description}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$num_errors++;
|
$num_errors++;
|
||||||
@ -98,16 +109,16 @@ sub run {
|
|||||||
$self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked));
|
$self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked));
|
||||||
my $exit = $self->{perfdata}->threshold_check(value => $num_errors, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
my $exit = $self->{perfdata}->threshold_check(value => $num_errors, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||||
$self->{output}->output_add(
|
$self->{output}->output_add(
|
||||||
severity => $exit,
|
severity => $exit,
|
||||||
short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors)
|
short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors)
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{output}->perfdata_add(
|
$self->{output}->perfdata_add(
|
||||||
nlabel => 'eventlogs.problems.count',
|
nlabel => 'eventlogs.problems.count',
|
||||||
value => $num_errors,
|
value => $num_errors,
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||||
min => 0
|
min => 0
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user