From aa41f2d924dcb885d36408e7b55e687faf553063 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 14 Jan 2020 12:53:44 +0100 Subject: [PATCH] enhance ibm storwize compatibility eventlog --- storage/ibm/storwize/ssh/mode/eventlog.pm | 95 ++++++++++++----------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/storage/ibm/storwize/ssh/mode/eventlog.pm b/storage/ibm/storwize/ssh/mode/eventlog.pm index 925d4bac0..e6ffa3faa 100644 --- a/storage/ibm/storwize/ssh/mode/eventlog.pm +++ b/storage/ibm/storwize/ssh/mode/eventlog.pm @@ -30,24 +30,23 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "filter-event-id:s" => { name => 'filter_event_id' }, - "filter-message:s" => { name => 'filter_message' }, - "retention:s" => { name => 'retention' }, - "hostname:s" => { name => 'hostname' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options' }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning', }, + 'critical:s' => { name => 'critical', }, + 'filter-event-id:s' => { name => 'filter_event_id' }, + 'filter-message:s' => { name => 'filter_message' }, + 'retention:s' => { name => 'retention' }, + 'hostname:s' => { name => 'hostname' }, + 'ssh-option:s@' => { name => 'ssh_option' }, + 'ssh-path:s' => { name => 'ssh_path' }, + 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, + 'timeout:s' => { name => 'timeout', default => 30 }, + 'sudo' => { name => 'sudo' }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, + }); return $self; } @@ -55,7 +54,7 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); $self->{output}->option_exit(); @@ -67,7 +66,7 @@ sub check_options { if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { $self->{option_results}->{remote} = 1; } - + my $last_timestamp = ''; if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} =~ /^\d+$/) { # by default UTC timezone used @@ -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()); $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 { @@ -85,7 +84,7 @@ sub get_hasharray { return $result if ($options{content} eq ''); my ($header, @lines) = split /\n/, $options{content}; my @header_names = split /$options{delim}/, $header; - + for (my $i = 0; $i <= $#lines; $i++) { my @content = split /$options{delim}/, $lines[$i]; my $data = {}; @@ -94,21 +93,23 @@ sub get_hasharray { } push @$result, $data; } - + return $result; } sub run { my ($self, %options) = @_; - my $content = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - 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_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); + my $content = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + 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_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 + ); my $result = $self->get_hasharray(content => $content, delim => ':'); - + my ($num_eventlog_checked, $num_errors) = (0, 0); foreach (@$result) { $num_eventlog_checked++; @@ -122,25 +123,30 @@ sub run { $self->{output}->output_add(long_msg => "skipping '" . $_->{event_id} . "': no matching filter event id.", debug => 1); next; } - - $self->{output}->output_add(long_msg => sprintf("%s : %s - %s", - scalar(localtime($_->{last_timestamp})), - $_->{event_id}, $_->{description} - ) - ); + + $self->{output}->output_add( + long_msg => sprintf( + '%s : %s - %s', + scalar(localtime($_->{last_timestamp})), + $_->{event_id}, $_->{description} + ) + ); $num_errors++; } $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' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) - ); - $self->{output}->perfdata_add(label => 'problems', - value => $num_errors, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) + ); + $self->{output}->perfdata_add( + label => 'problems', + value => $num_errors, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); @@ -215,4 +221,3 @@ Command options. =back =cut - \ No newline at end of file