enhance ibm storwize compatibility eventlog

This commit is contained in:
garnier-quentin 2020-01-14 12:53:44 +01:00
parent e3608739df
commit aa41f2d924
1 changed files with 50 additions and 45 deletions

View File

@ -31,22 +31,21 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
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' }, 'hostname:s' => { name => 'hostname' },
"hostname:s" => { name => 'hostname' }, 'ssh-option:s@' => { name => 'ssh_option' },
"ssh-option:s@" => { name => 'ssh_option' }, 'ssh-path:s' => { name => 'ssh_path' },
"ssh-path:s" => { name => 'ssh_path' }, 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, 'sudo' => { name => 'sudo' },
"sudo" => { name => 'sudo' }, 'command:s' => { name => 'command' },
"command:s" => { name => 'command' }, 'command-path:s' => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, 'command-options:s' => { name => 'command_options' },
"command-options:s" => { name => 'command_options' },
}); });
return $self; return $self;
@ -75,7 +74,7 @@ sub check_options {
my $dt_format = sprintf("%d%02d%02d%02d%02d%02d", substr($dt->year(), 2), $dt->month(), $dt->day(), $dt->hour(), $dt->minute(), $dt->second()); my $dt_format = sprintf("%d%02d%02d%02d%02d%02d", substr($dt->year(), 2), $dt->month(), $dt->day(), $dt->hour(), $dt->minute(), $dt->second());
$last_timestamp = 'last_timestamp>=' . $dt_format . ":"; $last_timestamp = 'last_timestamp>=' . $dt_format . ":";
} }
$self->{ls_command} = "lseventlog -message no -alert yes -filtervalue '${last_timestamp}fixed=no' -delim :"; $self->{ls_command} = "svcinfo lseventlog -message no -alert yes -filtervalue '${last_timestamp}fixed=no' -delim :";
} }
sub get_hasharray { sub get_hasharray {
@ -101,12 +100,14 @@ sub get_hasharray {
sub run { sub run {
my ($self, %options) = @_; my ($self, %options) = @_;
my $content = centreon::plugins::misc::execute(output => $self->{output}, my $content = centreon::plugins::misc::execute(
output => $self->{output},
options => $self->{option_results}, options => $self->{option_results},
sudo => $self->{option_results}->{sudo}, sudo => $self->{option_results}->{sudo},
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ls_command} . " ; exit ;", command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ls_command} . " ; exit ;",
command_path => $self->{option_results}->{command_path}, command_path => $self->{option_results}->{command_path},
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef); command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef
);
my $result = $self->get_hasharray(content => $content, delim => ':'); my $result = $self->get_hasharray(content => $content, delim => ':');
my ($num_eventlog_checked, $num_errors) = (0, 0); my ($num_eventlog_checked, $num_errors) = (0, 0);
@ -123,7 +124,9 @@ sub run {
next; next;
} }
$self->{output}->output_add(long_msg => sprintf("%s : %s - %s", $self->{output}->output_add(
long_msg => sprintf(
'%s : %s - %s',
scalar(localtime($_->{last_timestamp})), scalar(localtime($_->{last_timestamp})),
$_->{event_id}, $_->{description} $_->{event_id}, $_->{description}
) )
@ -133,14 +136,17 @@ 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(severity => $exit, $self->{output}->output_add(
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(label => 'problems', $self->{output}->perfdata_add(
label => 'problems',
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();
$self->{output}->exit(); $self->{output}->exit();
@ -215,4 +221,3 @@ Command options.
=back =back
=cut =cut