From 21b40b5f16716c95ea0cdd2b95bbffb76f48d217 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 25 Mar 2016 11:27:10 +0100 Subject: [PATCH 01/22] + Fix #356 --- apps/tomcat/web/mode/applications.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/tomcat/web/mode/applications.pm b/apps/tomcat/web/mode/applications.pm index 7056a985a..f360564b8 100644 --- a/apps/tomcat/web/mode/applications.pm +++ b/apps/tomcat/web/mode/applications.pm @@ -65,7 +65,7 @@ sub manage_selection { my $webcontent = $self->{http}->request(); - while ($webcontent =~ m/(.*):(.*):(.*):(.*)/g) { + while ($webcontent =~ /^(.*?):(.*?):(.*?):(.*)/mg) { my ($context, $state, $sessions, $contextpath) = ($1, $2, $3, $4); next if (defined($self->{option_results}->{filter_path}) && $self->{option_results}->{filter_path} ne '' && From a53df7e504cc182bbc6f3ea65ecda77107ec17ad Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 29 Mar 2016 11:44:50 +0200 Subject: [PATCH 02/22] + Fix time-host command issue --- apps/vmware/connector/mode/timehost.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/vmware/connector/mode/timehost.pm b/apps/vmware/connector/mode/timehost.pm index d16c02cfe..f1dce6305 100644 --- a/apps/vmware/connector/mode/timehost.pm +++ b/apps/vmware/connector/mode/timehost.pm @@ -66,7 +66,6 @@ sub run { my ($self, %options) = @_; $self->{connector} = $options{custom}; - $self->{connector}->set_discovery(); $self->{connector}->add_params(params => $self->{option_results}, command => 'timehost'); $self->{connector}->run(); From 38973bc97843df7dcdf283ff12cd8ff112749e04 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 30 Mar 2016 10:27:41 +0200 Subject: [PATCH 03/22] + Add mode 'data-files-status' for oracle --- database/oracle/mode/datafilesstatus.pm | 218 ++++++++++++++++++++++++ database/oracle/plugin.pm | 2 +- 2 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 database/oracle/mode/datafilesstatus.pm diff --git a/database/oracle/mode/datafilesstatus.pm b/database/oracle/mode/datafilesstatus.pm new file mode 100644 index 000000000..119632ba9 --- /dev/null +++ b/database/oracle/mode/datafilesstatus.pm @@ -0,0 +1,218 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package database::oracle::mode::datafilesstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'df', type => 1, cb_prefix_output => 'prefix_df_output', message_multiple => 'All data files are ok' }, + ]; + + $self->{maps_counters}->{df} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'online-status', threshold => 0, set => { + key_values => [ { name => 'online_status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_online_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + ]; +} + +my $instance_mode; + +sub custom_threshold_output { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label_th}}) && $instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label_th}} ne '' && + eval "$instance_mode->{option_results}->{'critical_' . $self->{result_values}->{label_th}}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label_th}}) && $instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label_th}} ne '' && + eval "$instance_mode->{option_results}->{'warning_' . $self->{result_values}->{label_th}}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = $self->{result_values}->{label_display} . ' : ' . $self->{result_values}->{$self->{result_values}->{label_th}}; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{label_display} = 'Status'; + $self->{result_values}->{label_th} = 'status'; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_online_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{label_display} = 'Online Status'; + $self->{result_values}->{label_th} = 'online_status'; + $self->{result_values}->{online_status} = $options{new_datas}->{$self->{instance} . '_online_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-tablespace:s" => { name => 'filter_tablespace' }, + "filter-data-file:s" => { name => 'filter_data_file' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + "warning-online-status:s" => { name => 'warning_online_status', default => '%{online_status} =~ /sysoff/i' }, + "critical-online-status:s" => { name => 'critical_online_status', default => '%{online_status} =~ /system|offline|recover/i' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status', 'warning_online_status', 'critical_online_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub prefix_df_output { + my ($self, %options) = @_; + + return "Data file '" . $options{instance_value}->{display} . "' "; +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + $options{sql}->query(query => "SELECT file_name, tablespace_name, status, online_status + FROM dba_data_files"); + my $result = $options{sql}->fetchall_arrayref(); + + $self->{df} = {}; + foreach my $row (@$result) { + if (defined($self->{option_results}->{filter_data_file}) && $self->{option_results}->{filter_data_file} ne '' && + $$row[0] !~ /$self->{option_results}->{filter_data_file}/) { + $self->{output}->output_add(long_msg => "skipping '" . $$row[0] . "': no matching filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_tablespace}) && $self->{option_results}->{filter_tablespace} ne '' && + $$row[1] !~ /$self->{option_results}->{filter_tablespace}/) { + $self->{output}->output_add(long_msg => "skipping '" . $$row[1] . "': no matching filter.", debug => 1); + next + } + $self->{df}->{$$row[1] . '/' . $$row[0]} = { status => $$row[2], online_status => $$row[3], display => $$row[1] . '/' . $$row[0] }; + } +} + +1; + +__END__ + +=head1 MODE + +Check data files status. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). + +=item B<--filter-tablespace> + +Filter tablespace name (can be a regexp). + +=item B<--filter-data-file> + +Filter data file name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: none). +Can used special variables like: %{display}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: none). +Can used special variables like: %{display}, %{status} + +=item B<--warning-online-status> + +Set warning threshold for online status (Default: '%{online_status} =~ /sysoff/i'). +Can used special variables like: %{display}, %{online_status} + +=item B<--critical-online-status> + +Set critical threshold for online status (Default: '%{online_status} =~ /system|offline|recover/i'). +Can used special variables like: %{display}, %{online_status} + +=back + +=cut diff --git a/database/oracle/plugin.pm b/database/oracle/plugin.pm index ff665ab2a..24a6d39a3 100644 --- a/database/oracle/plugin.pm +++ b/database/oracle/plugin.pm @@ -29,7 +29,6 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( @@ -37,6 +36,7 @@ sub new { 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', 'connected-users' => 'database::oracle::mode::connectedusers', 'corrupted-blocks' => 'database::oracle::mode::corruptedblocks', + 'data-files-status' => 'database::oracle::mode::datafilesstatus', 'datacache-hitratio' => 'database::oracle::mode::datacachehitratio', 'process-usage' => 'database::oracle::mode::processusage', 'rman-backup-problems' => 'database::oracle::mode::rmanbackupproblems', From 738464a65980c7e3cea0a48d8a443345d3e2ba21 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 30 Mar 2016 14:15:13 +0200 Subject: [PATCH 04/22] + change oracle data-files-status mode threshold --- database/oracle/mode/datafilesstatus.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/oracle/mode/datafilesstatus.pm b/database/oracle/mode/datafilesstatus.pm index 119632ba9..78ed67f56 100644 --- a/database/oracle/mode/datafilesstatus.pm +++ b/database/oracle/mode/datafilesstatus.pm @@ -118,7 +118,7 @@ sub new { "warning-status:s" => { name => 'warning_status', default => '' }, "critical-status:s" => { name => 'critical_status', default => '' }, "warning-online-status:s" => { name => 'warning_online_status', default => '%{online_status} =~ /sysoff/i' }, - "critical-online-status:s" => { name => 'critical_online_status', default => '%{online_status} =~ /system|offline|recover/i' }, + "critical-online-status:s" => { name => 'critical_online_status', default => '%{online_status} =~ /offline|recover/i' }, }); return $self; } @@ -210,7 +210,7 @@ Can used special variables like: %{display}, %{online_status} =item B<--critical-online-status> -Set critical threshold for online status (Default: '%{online_status} =~ /system|offline|recover/i'). +Set critical threshold for online status (Default: '%{online_status} =~ /offline|recover/i'). Can used special variables like: %{display}, %{online_status} =back From 45bd68a0f05aa8a266d3ad48dd2e317f92cd98dc Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 1 Apr 2016 11:26:58 +0200 Subject: [PATCH 05/22] + add a case for mysql replication slave mode --- database/mysql/mode/replicationmasterslave.pm | 67 +++++++++++-------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/database/mysql/mode/replicationmasterslave.pm b/database/mysql/mode/replicationmasterslave.pm index 516e253d6..b8988adbe 100644 --- a/database/mysql/mode/replicationmasterslave.pm +++ b/database/mysql/mode/replicationmasterslave.pm @@ -45,18 +45,17 @@ sub check_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(); + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); } } sub run { my ($self, %options) = @_; - # $options{sql} = sqlmode object if (ref($options{sql}) ne 'ARRAY') { $self->{output}->add_option_msg(short_msg => "Need to use --multiple options."); @@ -232,7 +231,7 @@ sub run { my $slave_position = $result2->{Read_Master_Log_Pos}; # 'Read_Master_Log_Pos' my $num_sec_lates = $result2->{Seconds_Behind_Master}; - my $exit_code_sec = $self->{perfdata}->threshold_check(value => $num_sec_lates, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code_sec = $self->{perfdata}->threshold_check(value => $num_sec_lates, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code_sec, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code_sec, short_msg => sprintf("Slave has %d seconds latency behind master", $num_sec_lates)); @@ -262,51 +261,63 @@ sub run { $position_status_error .= " Slave replication has connection issue with the master."; } elsif (($master_file ne $slave_file || $master_position != $slave_position) && $slave_sql_thread_warning == 0) { $position_status = -1; - $position_status_error .= " Slave replication is late but it's progressing.."; + $position_status_error .= " Slave replication is late but it's progressing."; } elsif (($master_file ne $slave_file || $master_position != $slave_position) && $slave_sql_thread_ok == 0) { $position_status = -1; - $position_status_error .= " Slave replication is late but it's progressing.."; + $position_status_error .= " Slave replication is late but it's progressing."; + } else { + $master_file =~ /(\d+)$/; + my $master_bin_num = $1; + $slave_file =~ /(\d+)$/; + my $slave_bin_num = $1; + my $diff_binlog = abs($master_bin_num - $slave_bin_num); + + # surely of missconfiguration of the plugin + if ($diff_binlog > 1 && $num_sec_lates < 10) { + $position_status = -3; + $position_status_error .= " Surely a configuration problem of the plugin (not good master and slave server used)"; + } } } } - - $self->replication_add($slave_status, "Slave Thread Status", $slave_status_error); - $self->replication_add($position_status, "Position Status", $position_status_error); + $self->replication_add($position_status, "Position Status", $position_status_error); $self->{output}->display(); $self->{output}->exit(); } sub replication_add { - my ($self, $lstate, $str_display, $lerr) = @_; - my $status; + my ($self, $lstate, $str_display, $lerr) = @_; + my $status; my $status_msg; - if ($lstate == 0) { - $status = 'OK'; - } elsif ($lstate == -1) { - $status = 'WARNING'; - } elsif ($lstate == -2) { - $status = 'CRITICAL'; + if ($lstate == 0) { + $status = 'OK'; + } elsif ($lstate == -1) { + $status = 'WARNING'; + } elsif ($lstate == -2) { + $status = 'CRITICAL'; $status_msg = 'SKIP'; - } else { - $status = 'CRITICAL'; - } + } elsif ($lstate == -3) { + $status = 'UNKNOWN'; + } else { + $status = 'CRITICAL'; + } my $output; - if (defined($lerr) && $lerr ne "") { - $output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "] [" . $lerr . "]"; - } else { - $output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "]"; - } + if (defined($lerr) && $lerr ne "") { + $output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "] [" . $lerr . "]"; + } else { + $output = $str_display . " [" . (defined($status_msg) ? $status_msg : $status) . "]"; + } if (!$self->{output}->is_status(value => $status, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $status, short_msg => $output); } - $self->{output}->output_add(long_msg => $output); + $self->{output}->output_add(long_msg => $output); } 1; From 8075883b0bf9bc0391d17211f663575d1fc8b999 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 14 Apr 2016 15:56:10 +0200 Subject: [PATCH 06/22] + add mode for netbackup + add new type in counter template system --- apps/backup/netbackup/local/mode/jobstatus.pm | 36 ++- apps/backup/netbackup/local/mode/tapeusage.pm | 256 ++++++++++++++++++ apps/backup/netbackup/local/plugin.pm | 2 +- centreon/plugins/templates/counter.pm | 66 ++++- 4 files changed, 347 insertions(+), 13 deletions(-) create mode 100644 apps/backup/netbackup/local/mode/tapeusage.pm diff --git a/apps/backup/netbackup/local/mode/jobstatus.pm b/apps/backup/netbackup/local/mode/jobstatus.pm index a4b275d83..0a1bee52f 100644 --- a/apps/backup/netbackup/local/mode/jobstatus.pm +++ b/apps/backup/netbackup/local/mode/jobstatus.pm @@ -173,7 +173,9 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'job', type => 1, cb_prefix_output => 'prefix_job_output', message_multiple => 'All jobs are ok', skipped_code => { -11 => 1 } } + { name => 'policy', type => 2, cb_prefix_output => 'prefix_policy_output', cb_long_output => 'policy_long_output', message_multiple => 'All policies are ok', + group => [ { name => 'job', cb_prefix_output => 'prefix_job_output', skipped_code => { -11 => 1 } } ] + } ]; $self->{maps_counters}->{job} = [ @@ -244,10 +246,22 @@ sub check_options { $self->change_macros(); } +sub policy_long_output { + my ($self, %options) = @_; + + return "checking policy '" . $options{instance_value}->{display} . "'"; +} + +sub prefix_policy_output { + my ($self, %options) = @_; + + return "policy '" . $options{instance_value}->{display} . "' "; +} + sub prefix_job_output { my ($self, %options) = @_; - return "Job '" . $options{instance_value}->{display} . "' "; + return "job '" . $options{instance_value}->{display} . "' "; } sub change_macros { @@ -291,32 +305,34 @@ sub manage_selection { command => $self->{option_results}->{command}, command_path => $self->{option_results}->{command_path}, command_options => $self->{option_results}->{command_options}); - $self->{job} = {}; + $self->{policy} = {}; my $current_time = time(); foreach my $line (split /\n/, $stdout) { my @values = split /,/, $line; my ($job_id, $job_type, $job_state, $job_status, $job_pname, $job_start_time, $job_end_time, $job_kb) = ($values[0], $values[1], $values[2], $values[3], $values[4], $values[8], $values[10], $values[14]); - my $display = (defined($job_pname) ? $job_pname : '-') . '/' . $job_id; + $job_pname = defined($job_pname) && $job_pname ne '' ? $job_pname : 'unknown'; + $job_status = defined($job_status) && $job_status =~ /[0-9]/ ? $job_status : undef; if (defined($self->{option_results}->{filter_policy_name}) && $self->{option_results}->{filter_policy_name} ne '' && $job_pname !~ /$self->{option_results}->{filter_policy_name}/) { - $self->{output}->output_add(long_msg => "skipping '" . $display . "': no matching filter.", debug => 1); + $self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': no matching filter.", debug => 1); next; } if (defined($self->{option_results}->{filter_end_time}) && $self->{option_results}->{filter_end_time} =~ /[0-9]+/ && defined($job_end_time) && $job_end_time =~ /[0-9]+/ && $job_end_time < $current_time - $self->{option_results}->{filter_end_time}) { - $self->{output}->output_add(long_msg => "skipping '" . $display . "': too old.", debug => 1); + $self->{output}->output_add(long_msg => "skipping job '" . $job_pname . "/" . $job_id . "': too old.", debug => 1); next; } + $self->{policy}->{$job_pname} = { job => {}, display => $job_pname } if (!defined($self->{policy}->{$job_pname})); my $elapsed_time = $current_time - $job_start_time; - $self->{job}->{$display} = { display => $display, elapsed => $elapsed_time, - status => $job_status, state => $job_state{$job_state}, type => $job_type{$job_type}, - kb => defined($job_kb) && $job_kb =~ /[0-9]+/ ? $job_kb : undef }; + $self->{policy}->{$job_pname}->{job}->{$job_id} = { display => $job_id, elapsed => $elapsed_time, + status => $job_status, state => $job_state{$job_state}, type => $job_type{$job_type}, + kb => defined($job_kb) && $job_kb =~ /[0-9]+/ ? $job_kb : undef }; } - if (scalar(keys %{$self->{job}}) <= 0) { + if (scalar(keys %{$self->{policy}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No job found."); $self->{output}->option_exit(); } diff --git a/apps/backup/netbackup/local/mode/tapeusage.pm b/apps/backup/netbackup/local/mode/tapeusage.pm new file mode 100644 index 000000000..90c8da675 --- /dev/null +++ b/apps/backup/netbackup/local/mode/tapeusage.pm @@ -0,0 +1,256 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::backup::netbackup::local::mode::tapeusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label, + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my $msg = sprintf("Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $self->{result_values}->{total}, + $self->{result_values}->{used}, $self->{result_values}->{prct_used}, + $self->{result_values}->{free}, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', set => { + key_values => [ { name => 'total' }, { name => 'used' } ], + closure_custom_calc => \&custom_usage_calc, + closure_custom_output => \&custom_usage_output, + closure_custom_perfdata => \&custom_usage_perfdata, + closure_custom_threshold_check => \&custom_usage_threshold, + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "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', default => 'vmquery' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-a -w' }, + "filter-scratch:s" => { name => 'filter_scratch', default => 'scratch' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + $self->{global} = { total => 0, used => 0 }; + #media optical media barcode robot robot robot robot side/ volume prev # of max # of create assigned first mount last mount expiration off sent off return off off + #ID partner type barcode partner host type # slot face group pool pool # pool mounts mounts cleanings datetime datetime datetime datetime datetime status offsite location datetime datetime slot ses id version description + #-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + #000001 - HCART2 000001L5 - - NONE - - - --- VP-05WEEKS-EXT 9 VP-SCRATCH 1250 0 - 30/11/2012 15:30 29/02/2016 20:43 27/01/2013 17:57 02/03/2016 01:36 00/00/0000 00:00 0 - 00/00/0000 00:00 00/00/0000 00:00 - - 50 --- + #000002 - HCART2 000002L5 - XXX-NBU-XXX TLD 0 8 - 000_00000_TLD VP-SCRATCH 4 VP-05WEEKS-EXT + + # Remove header + $stdout =~ s/\x00//msg; + $stdout =~ s/^.*?----.*?\n//ms; + foreach my $line (split /\n/, $stdout) { + $line =~ /^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+(\S+)/; + my ($robot_host, $robot_slot, $pool) = ($1, $2, $3); + + next if ($robot_slot !~ /[0-9]/); + + $self->{global}->{total}++; + if (defined($self->{option_results}->{filter_scratch}) && $self->{option_results}->{filter_scratch} ne '' && + $pool !~ /$self->{option_results}->{filter_scratch}/i) { + $self->{global}->{used}++; + } + } + + if ($self->{global}->{total} == 0) { + $self->{output}->add_option_msg(short_msg => "No tape found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check tapes available in library. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'vmquery'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-a -w'). + +=item B<--filter-scratch> + +Filter tape scratch (Default: 'scratch'). + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'absolute'). + +=item B<--free> + +Thresholds are on free tape left. + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=back + +=cut diff --git a/apps/backup/netbackup/local/plugin.pm b/apps/backup/netbackup/local/plugin.pm index 66a3b91e6..3c575df15 100644 --- a/apps/backup/netbackup/local/plugin.pm +++ b/apps/backup/netbackup/local/plugin.pm @@ -28,7 +28,6 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - # $options->{options} = options object $self->{version} = '0.1'; %{$self->{modes}} = ( @@ -37,6 +36,7 @@ sub new { 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', 'job-status' => 'apps::backup::netbackup::local::mode::jobstatus', 'list-policies' => 'apps::backup::netbackup::local::mode::listpolicies', + 'tape-usage' => 'apps::backup::netbackup::local::mode::tapeusage', ); return $self; diff --git a/centreon/plugins/templates/counter.pm b/centreon/plugins/templates/counter.pm index ef7961376..3bda7758b 100644 --- a/centreon/plugins/templates/counter.pm +++ b/centreon/plugins/templates/counter.pm @@ -190,13 +190,16 @@ sub run_instances { my ($self, %options) = @_; return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); + my $display_status_lo = defined($options{display_status_long_output}) && $options{display_status_long_output} == 1 ? 1 : 0; + my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0; + $self->{lproblems} = 0; $self->{multiple} = 1; if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { $self->{multiple} = 0; } - if ($self->{multiple} == 1) { + if ($self->{multiple} == 1 && $resume == 0) { $self->{output}->output_add(severity => 'OK', short_msg => $options{config}->{message_multiple}); } @@ -230,6 +233,7 @@ sub run_instances { $long_msg_append = $message_separator; if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $self->{lproblems}++; $short_msg .= $short_msg_append . $output; $short_msg_append = $message_separator; } @@ -246,8 +250,13 @@ sub run_instances { if (defined($options{config}->{cb_suffix_output})); $suffix_output = '' if (!defined($suffix_output)); - $self->{output}->output_add(long_msg => "${prefix_output}${long_msg}${suffix_output}"); my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + $self->{output}->output_add(long_msg => ($display_status_lo == 1 ? lc($exit) . ': ' : '') . "${prefix_output}${long_msg}${suffix_output}"); + if ($resume == 1) { + $self->{most_critical_instance} = $self->{output}->get_most_critical(status => [ $self->{most_critical_instance}, $exit ]); + next; + } + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { $self->{output}->output_add(severity => $exit, short_msg => "${prefix_output}${short_msg}${suffix_output}" @@ -260,6 +269,57 @@ sub run_instances { } } +sub run_group { + my ($self, %options) = @_; + + my $multiple = 1; + if (scalar(keys %{$self->{$options{config}->{name}}}) == 1) { + $multiple = 0; + } + + if ($multiple == 1) { + $self->{output}->output_add(severity => 'OK', + short_msg => $options{config}->{message_multiple}); + } + + my ($global_exit, $total_problems) = ([], 0); + foreach my $id (sort keys %{$self->{$options{config}->{name}}}) { + $self->{most_critical_instance} = 'ok'; + if (defined($options{config}->{cb_long_output})) { + $self->{output}->output_add(long_msg => $self->call_object_callback(method_name => $options{config}->{cb_long_output}, + instance_value => $self->{$options{config}->{name}}->{$id})); + } + + foreach my $group (@{$options{config}->{group}}) { + $self->{$group->{name}} = $self->{$options{config}->{name}}->{$id}->{$group->{name}}; + + # we resume datas + $self->run_instances(config => $group, display_status_long_output => 1, resume => 1); + + push @{$global_exit}, $self->{most_critical_instance}; + $total_problems += $self->{lproblems}; + + my $prefix_output; + $prefix_output = $self->call_object_callback(method_name => $options{config}->{cb_prefix_output}, instance_value => $self->{$options{config}->{name}}->{$id}) + if (defined($options{config}->{cb_prefix_output})); + $prefix_output = '' if (!defined($prefix_output)); + + if ($multiple == 0) { + $self->{output}->output_add(severity => $self->{most_critical_instance}, + short_msg => "${prefix_output}$self->{lproblems} problem(s) detected"); + } + } + } + + if ($multiple == 1) { + my $exit = $self->{output}->get_most_critical(status => [ @{$global_exit} ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "$total_problems problem(s) detected"); + } + } +} + sub run { my ($self, %options) = @_; @@ -277,6 +337,8 @@ sub run { $self->run_global(config => $entry); } elsif ($entry->{type} == 1) { $self->run_instances(config => $entry); + } elsif ($entry->{type} == 2) { + $self->run_group(config => $entry); } } From a5bec63a9c20ebd4b08646f2c42a80c2d81e7275 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 14 Apr 2016 15:57:02 +0200 Subject: [PATCH 07/22] + add a comment for ntp mode windows --- os/windows/local/mode/ntp.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/windows/local/mode/ntp.pm b/os/windows/local/mode/ntp.pm index fcb4697da..a8e327db3 100644 --- a/os/windows/local/mode/ntp.pm +++ b/os/windows/local/mode/ntp.pm @@ -99,7 +99,7 @@ sub run { } my %ntp; - + # Need to set following patch: https://rt.cpan.org/Public/Bug/Display.html?id=59607 eval { %ntp = Net::NTP::get_ntp_response($ntp_hostname, $self->{option_results}->{ntp_port}); }; From 9c5dcab285cbe612b85da45d1ae2d9aa7e6694e0 Mon Sep 17 00:00:00 2001 From: Etienne G Date: Tue, 19 Apr 2016 09:11:42 +0200 Subject: [PATCH 08/22] Get only issue type ticket Add filter on issue type --- apps/github/mode/issues.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/github/mode/issues.pm b/apps/github/mode/issues.pm index 353c52b63..0fffc26c5 100644 --- a/apps/github/mode/issues.pm +++ b/apps/github/mode/issues.pm @@ -74,7 +74,7 @@ sub check_options { $self->{output}->option_exit(); } - $self->{option_results}->{url_path} = "/search/issues?q=state:open+repo:" . $self->{option_results}->{owner} . "/" . $self->{option_results}->{repository}; + $self->{option_results}->{url_path} = "/search/issues?q=state:open+is:issue+repo:" . $self->{option_results}->{owner} . "/" . $self->{option_results}->{repository}; if (defined($self->{option_results}->{label}) && $self->{option_results}->{label} ne '') { $self->{option_results}->{url_path} .= "+label:" . $self->{option_results}->{label}; } From 63ee930b70ad3393990b53be792e75a8173d7bea Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 19 Apr 2016 20:16:44 +0200 Subject: [PATCH 09/22] + Fix ntp protocol plugin mode offset --- apps/protocols/ntp/mode/offset.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/protocols/ntp/mode/offset.pm b/apps/protocols/ntp/mode/offset.pm index 370cdb53f..600a48ffc 100644 --- a/apps/protocols/ntp/mode/offset.pm +++ b/apps/protocols/ntp/mode/offset.pm @@ -77,7 +77,7 @@ sub run { } my $localtime = time(); - my $offset = ($ntp{'Receive Timestamp'} - $ntp{'Originate Timestamp'}) + ($ntp{'Transmit Timestamp'} - $localtime) / 2); + my $offset = (($ntp{'Receive Timestamp'} - $ntp{'Originate Timestamp'}) + ($ntp{'Transmit Timestamp'} - $localtime)) / 2; my $exit = $self->{perfdata}->threshold_check(value => $offset, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); From 3fb754568bdd05a89d736a26c1db7bdb59c97a73 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 23 Apr 2016 18:11:57 +0200 Subject: [PATCH 10/22] + add symmetrix dmx34 plugin --- .../dmx34/local/mode/components/config.pm | 56 ++++ .../dmx34/local/mode/components/director.pm | 92 ++++++ .../dmx34/local/mode/components/directors.pm | 70 +++++ .../dmx34/local/mode/components/disk.pm | 116 ++++++++ .../local/mode/components/environment.pm | 56 ++++ .../dmx34/local/mode/components/memory.pm | 92 ++++++ .../dmx34/local/mode/components/test.pm | 60 ++++ .../dmx34/local/mode/components/xcm.pm | 75 +++++ .../symmetrix/dmx34/local/mode/hardware.pm | 281 ++++++++++++++++++ storage/emc/symmetrix/dmx34/local/plugin.pm | 48 +++ 10 files changed, 946 insertions(+) create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/config.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/director.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/directors.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/disk.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/environment.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/memory.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/test.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/xcm.pm create mode 100644 storage/emc/symmetrix/dmx34/local/mode/hardware.pm create mode 100644 storage/emc/symmetrix/dmx34/local/plugin.pm diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/config.pm b/storage/emc/symmetrix/dmx34/local/mode/components/config.pm new file mode 100644 index 000000000..65812a25f --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/config.pm @@ -0,0 +1,56 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::config; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +# ---------[ Configuration Information ]--------- +# +#... +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking config"); + $self->{components}->{config} = {name => 'config', total => 0, skip => 0}; + return if ($self->check_filter(section => 'config')); + + if ($self->{content_file_health} !~ /----\[ Configuration Information(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find config'); + return ; + } + + my $content = $1; + $self->{components}->{config}->{total}++; + + # Error if not present: + # CODE OK! + if ($content !~ /CODE OK!/msi) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("problem of configuration")); + } else { + $self->{output}->output_add(long_msg => sprintf("no configuration problem detected")); + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/director.pm b/storage/emc/symmetrix/dmx34/local/mode/components/director.pm new file mode 100644 index 000000000..5c8fa18ae --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/director.pm @@ -0,0 +1,92 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::director; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +# ---------------[ Director Status ]------------- +# +# 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 +# +# D ON .. .. .. .. .. .. ON ON .. .. .. .. .. .. ON +# C ON .. .. .. .. .. .. ON ON .. .. .. .. .. .. ON +# B ON .. .. .. .. .. .. DD ON .. .. .. .. .. .. ON +# A ON .. .. .. .. .. .. ON ON .. .. .. .. .. .. ON +# +# Key: +# ON - Director is online +# OF - Director is offline +# OF - DA is offline +# DD - Director is in DD state +# PR - Director is in Probe mode +# NC - Director is not comunicating +# ** - Director status is unknown + +my %mapping = ( + DD => 'DD state', + PR => 'Probe mode', + NC => 'not comunicating', + '**' => 'unknown',, + OF => 'offline', + ON => 'online',, + '..' => 'not configured', +); + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking directors"); + $self->{components}->{director} = {name => 'directors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'director')); + + if ($self->{content_file_health} !~ /---------------\[ Director Status(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find directors'); + return ; + } + + my $content = $1; + while ($content =~ /\s([A-Z]\s+.*?)\n/msig) { + my ($director, @nums) = split /\s+/, $1; + my $i = 0; + foreach (@nums) { + $i++; + my $state = defined($mapping{$_}) ? $mapping{$_} : 'unknown'; + my $instance = $director . '.' . $i; + + next if ($self->check_filter(section => 'director', instance => $instance)); + $self->{components}->{director}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("director '%s' state is '%s'", + $instance, $state)); + my $exit = $self->get_severity(section => 'director', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Director '%s' state is '%s'", + $instance, $state)); + } + } + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/directors.pm b/storage/emc/symmetrix/dmx34/local/mode/components/directors.pm new file mode 100644 index 000000000..c8a79299f --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/directors.pm @@ -0,0 +1,70 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::netapp::snmp::mode::components::communication; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %map_com_states = ( + 1 => 'initializing', + 2 => 'transitioning', + 3 => 'active', + 4 => 'inactive', + 5 => 'reconfiguring', + 6 => 'nonexistent', +); +my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; +my $oid_enclContactState = '.1.3.6.1.4.1.789.1.21.1.2.1.2'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_enclContactState }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking communications"); + $self->{components}->{communication} = {name => 'communications', total => 0, skip => 0}; + return if ($self->check_filter(section => 'communication')); + + for (my $i = 1; $i <= $self->{number_shelf}; $i++) { + my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; + my $com_state = $map_com_states{$self->{results}->{$oid_enclContactState}->{$oid_enclContactState . '.' . $i}}; + + next if ($self->check_filter(section => 'communication', instance => $shelf_addr)); + + $self->{components}->{communication}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Shelve '%s' communication state is '%s'", + $shelf_addr, $com_state)); + my $exit = $self->get_severity(section => 'communication', value => $com_state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Shelve '%s' communication state is '%s'", + $shelf_addr, $com_state)); + } + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/disk.pm b/storage/emc/symmetrix/dmx34/local/mode/components/disk.pm new file mode 100644 index 000000000..01f7e9c54 --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/disk.pm @@ -0,0 +1,116 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::disk; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +# ------------[ Device Information ]------------- +# +# RAID6 Configured: NO +# RAID5 Configured: NO +# RDF Configured: NO_RDF + +# Verify Volume Status +# There are 16 local devices are not ready (device(DA)):- à 0 si pas de problème +# 10000(01a) 10072(01a) 20086(01a) 1009A(01a) 200AE(01a) 100C2(01a) 100EA(01a) +# 10112(01a) 20075(01d) 10089(01d) 2009D(01d) 100B1(01d) 100C9(01d) 100F1(01d) +# 10119(01d) 20061(01d) +# +# No local devices have invalid tracks +# +# Deferred disk service is NOT enabled +# +# 8 hot spares are configured, 1 are invoked, none are not ready à none si pas de problème +# +# HotSpare 16d:D5 is invoked against 1d:D4 Time: MAR/24/16 04:48:49 à récupérer si pb +# +# No DAs have any volumes with Not Ready bit set +# +# All DAs have Write Optimize enabled +# +# No devices have TimeFinder Lock +# +# No Devices Found in Transient State + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking disks"); + $self->{components}->{disk} = {name => 'disks (1 means all)', total => 0, skip => 0}; + return if ($self->check_filter(section => 'disk')); + + if ($self->{content_file_health} !~ /----\[ Device Information(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find devices'); + return ; + } + + my $content = $1; + $self->{components}->{disk}->{total}++; + + # Error if not present: + # No local devices have invalid tracks + + if ($content !~ /No local devices have invalid tracks/msi) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("problem of invalid tracks on disks")); + } else { + $self->{output}->output_add(long_msg => sprintf("no invalid tracks on disks")); + } + + # Error if not present: + # All local devices are ready + if ($content !~ /All local devices are ready/msi) { + $content =~ /There are\s+(\S+)\s+local devices are not ready.*?\n(.*?)\n\s*\n/msi; + my ($num, $disks) = ($1, $2); + $disks =~ s/\n/ /msg; + $disks =~ s/\s+/ /msg; + $disks =~ s/^\s+//; + $self->{output}->output_add(long_msg => sprintf("problem on following disks '%s'", $disks)); + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("problem on '%s' disks", $num)); + } else { + $self->{output}->output_add(long_msg => sprintf("all devices are ready")); + } + + return if ($content !~ /(\S+) hot spares are configured, (\S+) are invoked/msi); + my ($total, $used) = ($1, $2); + $used = 0 if ($used =~ /none/i); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'disk', instance => '1', value => $total - $used); + + $self->{output}->output_add(long_msg => sprintf("'%s' spare disk availables on '%s'", + $total - $used, $total)); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("'%s' spare disk availables on '%s'", + $total - $used, $total)); + } + + $self->{output}->perfdata_add(label => "disk_spare_available", + value => $total - $used, + warning => $warn, + critical => $crit, min => 0, max => $total); +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/environment.pm b/storage/emc/symmetrix/dmx34/local/mode/components/environment.pm new file mode 100644 index 000000000..8edda26ae --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/environment.pm @@ -0,0 +1,56 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::environment; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +# -------------[ Power Information ]------------- +# +# No Environmental Problems found +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking environment"); + $self->{components}->{environment} = {name => 'environment', total => 0, skip => 0}; + return if ($self->check_filter(section => 'environment')); + + if ($self->{content_file_health} !~ /----\[ Power Information(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find environment'); + return ; + } + + my $content = $1; + $self->{components}->{environment}->{total}++; + + # Error if not present: + # No Environmental Problems found + if ($content !~ /No Environmental Problems found/msi) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("environment problem detected")); + } else { + $self->{output}->output_add(long_msg => sprintf("no environment problem detected")); + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/memory.pm b/storage/emc/symmetrix/dmx34/local/mode/components/memory.pm new file mode 100644 index 000000000..e36f700d8 --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/memory.pm @@ -0,0 +1,92 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::memory; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +#------------[ Memory Information ]------------- +# +# Memory Size: 80 GB +# Cache start Addr: 00088000 (Hex) +# Cache start Bank: 00000022 (Hex) +# Cache last Addr: 01400000 (Hex) +# Cache last Bank: 000004FF (Hex) +# +# Board Number M0 M1 M2 M3 M4 M5 M6 M7 +# Slot Number 10 11 12 13 14 15 16 17 +# ---------------------------------------------------------- +# Size (GB) 16 16 16 16 8 8 .. .. +# Mode OPER OPER OPER OPER OPER OPER .. .. +# Status OK OK OK OK OK OK .. .. +# +# Status Key +# OK - Board is operating normally + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking memory"); + $self->{components}->{memory} = {name => 'memory', total => 0, skip => 0}; + return if ($self->check_filter(section => 'memory')); + + if ($self->{content_file_health} !~ /----\[ Memory Information(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find memory'); + return ; + } + + my $content = $1; + + $content =~ /Board Number\s+(.*?)\n/msi; + my @board_numbers = split /\s+/, $1; + + $content =~ /Slot Number\s+(.*?)\n/msi; + my @slot_numbers = split /\s+/, $1; + + $content =~ /Mode\s+(.*?)\n/msi; + my @modes = split /\s+/, $1; + + $content =~ /Status\s+(.*?)\n/msi; + my @status = split /\s+/, $1; + + my $i = -1; + foreach my $name (@board_numbers) { + $i++; + my $instance = $name . '#' . $slot_numbers[$i]; + my $state = $modes[$i] . '/' . $status[$i]; + + next if ($self->check_filter(section => 'memory', instance => $instance)); + $self->{components}->{memory}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("memory '%s' state is '%s'", + $instance, $state)); + my $exit = $self->get_severity(section => 'memory', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Memory '%s' state is '%s'", + $instance, $state)); + } + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/test.pm b/storage/emc/symmetrix/dmx34/local/mode/components/test.pm new file mode 100644 index 000000000..09f9b05fa --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/test.pm @@ -0,0 +1,60 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::test; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +#--------------[ Director Tests ]--------------- +# +# No offline pending DAs are present +# 1C test: All Directors Passed +# F2,SAME,,,EE test: All Directors Passed +# EE test: All Directors Passed +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking test"); + $self->{components}->{test} = {name => 'test', total => 0, skip => 0}; + return if ($self->check_filter(section => 'test')); + + if ($self->{content_file_health} !~ /----\[ Director Tests(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find tests'); + return ; + } + + my $content = $1; + $self->{components}->{test}->{total}++; + + foreach (('No offline pending DAs are present', '1C test: All Directors Passed', + 'F2,SAME,,,EE test: All Directors Passed', 'EE test: All Directors Passed')) { + if ($content !~ /$_/msi) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("test problem detected")); + } else { + $self->{output}->output_add(long_msg => sprintf("%s", $_)); + } + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/xcm.pm b/storage/emc/symmetrix/dmx34/local/mode/components/xcm.pm new file mode 100644 index 000000000..21b4c0505 --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/components/xcm.pm @@ -0,0 +1,75 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::components::xcm; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +# --------------[ XCM Information ]-------------- +# +#XCM/ECM/CCM status +# XCM0 XCM1 +# EMUL EMUL +# +#Message Bus status + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking xcm"); + $self->{components}->{xcm} = {name => 'xcm', total => 0, skip => 0}; + return if ($self->check_filter(section => 'xcm')); + + if ($self->{content_file_health} !~ /----\[ XCM Information(.*?)----\[/msi) { + $self->{output}->output_add(long_msg => 'skipping: cannot find xcm'); + return ; + } + + my $content = $1; + + if ($content =~ /XCM\/ECM\/CCM status\s*\n\s*(.*?)\n\s*(.*?)\n\s*\n/msig) { + my @names = split /\s+/, $1; + my @status = split /\s+/, $2; + + my $i = -1; + foreach my $name (@names) { + $i++; + my $instance = $name; + my $state = $status[$i]; + + next if ($self->check_filter(section => 'xcm', instance => $instance)); + $self->{components}->{xcm}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("xcm '%s' state is '%s'", + $instance, $state)); + my $exit = $self->get_severity(section => 'xcm', value => $state); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("XCM '%s' state is '%s'", + $instance, $state)); + } + } + } +} + +1; diff --git a/storage/emc/symmetrix/dmx34/local/mode/hardware.pm b/storage/emc/symmetrix/dmx34/local/mode/hardware.pm new file mode 100644 index 000000000..be3fcab6d --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/mode/hardware.pm @@ -0,0 +1,281 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::plugins::statefile; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_numeric_check_section_option} = '^(disk)$'; + + $self->{cb_hook1} = 'read_files'; + $self->{cb_hook4} = 'send_email'; + + $self->{thresholds} = { + director => [ + ['DD state', 'CRITICAL'], + ['Probe mode', 'CRITICAL'], + ['not comunicating', 'CRITICAL'], + ['unknown', 'CRITICAL'], + ['offline', 'OK'], + ['online', 'OK'], + ['not configured', 'OK'], + ], + xcm => [ + ['emul', 'OK'], + ['.*', 'CRITICAL'], + ], + memory => [ + ['OPER/OK', 'OK'], + ['\.\./.*', 'OK'], + ['.*', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'storage::emc::symmetrix::dmx34::local::mode::components'; + $self->{components_module} = ['director', 'xcm', 'disk', 'memory', 'config', 'environment', 'test']; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $self->{statefile_cache}->check_options(%options); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "file-health:s" => { name => 'file_health' }, + "file-health-env:s" => { name => 'file_health_env' }, + # Email + "email-warning:s" => { name => 'email_warning' }, + "email-critical:s" => { name => 'email_critical' }, + "email-smtp-host:s" => { name => 'email_smtp_host' }, + "email-smtp-username:s" => { name => 'email_smtp_username' }, + "email-smtp-password:s" => { name => 'email_smtp_password' }, + "email-smtp-from:s" => { name => 'email_smtp_from' }, + "email-smtp-options:s@" => { name => 'email_smtp_options' }, + "email-memory" => { name => 'email_memory' }, + }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); + $self->{components_exec_load} = 0; + return $self; +} + +sub read_files { + my ($self, %options) = @_; + + if (!defined($self->{option_results}->{file_health}) || !defined($self->{option_results}->{file_health_env})) { + $self->{output}->add_option_msg(short_msg => "Please set option --file-health and --file-health-env."); + $self->{output}->option_exit(); + } + $self->{content_file_health} = do { + local $/ = undef; + if (!open my $fh, "<", $self->{option_results}->{file_health}) { + $self->{output}->add_option_msg(short_msg => "Could not open file $self->{option_results}->{file_health} : $!"); + $self->{output}->option_exit(); + } + <$fh>; + }; + + # We remove color syntax + $self->{content_file_health} =~ s/\x{1b}\[.*?m|\r//msg; + + # ***************************************************************** + #* Health Check Run From Scheduler Version 2.0 * + #* * + #* Serial: 000290103984 Run Time: 03/24/2016 12:27:07 * + #* Run Type: FULL Code Level: 5773-184-130 * + #***************************************************************** + + my ($serial, $site) = ('unknown', 'unknown'); + $serial = $1 if ($self->{content_file_health} =~ /Serial:\s*(\S+)/msi); + + $self->{output}->output_add(long_msg => sprintf('serial number: %s, site name: %s', $serial, $site)); +} + +# +# maybe we should add it in core (with cleaner code ;) +# + +sub send_email { + my ($self, %options) = @_; + + ####### + # Check SMTP options + return if (!((defined($self->{option_results}->{email_warning}) && $self->{option_results}->{email_warning} ne '') + || (defined($self->{option_results}->{email_critical}) && $self->{option_results}->{email_critical} ne ''))); + + if (!defined($self->{option_results}->{email_smtp_host})) { + $self->{output}->add_option_msg(short_msg => "Please set the --email-smtp-host option"); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{email_smtp_from})) { + $self->{output}->add_option_msg(short_msg => "Please set --email-smtp-from option"); + $self->{output}->option_exit(); + } + + my %smtp_options = ('-auth' => 'none'); + if (defined($self->{option_results}->{email_smtp_username}) && $self->{option_results}->{email_smtp_username} ne '') { + $smtp_options{-login} = $self->{option_results}->{email_smtp_username}; + delete $smtp_options{-auth}; + } + if (defined($self->{option_results}->{email_smtp_username}) && defined($self->{option_results}->{email_smtp_password})) { + $smtp_options{-pass} = $self->{option_results}->{email_smtp_password}; + } + foreach my $option (@{$self->{option_results}->{smtp_options}}) { + next if ($option !~ /^(.+?)=(.+)$/); + $smtp_options{-$1} = $2; + } + + ####### + # Get current data + my $stdout; + { + local *STDOUT; + open STDOUT, '>', \$stdout; + $self->{output}->display(force_long_output => 1); + } + + $stdout =~ /^(.*?)(\||\n)/msi; + my $subject = $1; + my $status = lc($self->{output}->get_litteral_status()); + + my $send_email = 0; + $send_email = 1 if ($status ne 'ok'); + ####### + # Check memory file + if (defined($self->{option_results}->{email_memory})) { + $self->{new_datas} = { status => $status, output => $subject }; + $self->{statefile_cache}->read(statefile => "cache_emc_symmetrix_dmx34_email"); + my $prev_status = $self->{statefile_cache}->get(name => 'status'); + my $prev_output = $self->{statefile_cache}->get(name => 'output'); + # non-ok output is the same + $send_email = 0 if ($status ne 'ok' && defined($prev_output) && $prev_output eq $subject); + # recovery email + $send_email = 1 if ($status eq 'ok' && defined($prev_status) && $prev_status ne 'ok'); + } + + my $smtp_to = ''; + $smtp_to = $self->{option_results}->{email_warning} if ($status eq 'warning' && defined($self->{option_results}->{email_warning} && $self->{option_results}->{email_warning}) ne ''); + $smtp_to = $self->{option_results}->{email_critical} if ($status eq 'critical' && defined($self->{option_results}->{email_critical} && $self->{option_results}->{email_critical}) ne ''); + if ($send_email == 1 && $status eq 'ok') { + my $append = ''; + foreach (('email_warning', 'email_critical')) { + if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') { + $smtp_to .= $append . $self->{option_results}->{$_}; + $append .= ','; + } + } + } + + if ($send_email == 0) { + $self->{output}->add_option_msg(severity => 'OK', short_msg => "No email to send"); + return ; + } + + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => 'Email::Send::SMTP::Gmail', + error_msg => "Cannot load module 'Email::Send::SMTP::Gmail'."); + my ($mail, $error) = Email::Send::SMTP::Gmail->new(-smtp => $self->{option_results}->{email_smtp_host}, + %smtp_options); + if ($mail == -1) { + $self->{output}->add_option_msg(short_msg => "session error: " . $error); + $self->{output}->option_exit(); + } + my $result = $mail->send(-to => $smtp_to, + -from => $self->{option_results}->{email_smtp_from}, + -subject => $subject, + -body => $stdout, + -attachments => $self->{option_results}->{file_health_env}); + $mail->bye(); + if ($result == -1) { + $self->{output}->add_option_msg(severity => 'UNKNOWN', short_msg => "problem to send the email"); + } else { + $self->{output}->add_option_msg(severity => 'OK', short_msg => "email sent"); + } +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'director', 'xcm', 'disk', 'memory', 'config', 'environment', 'test' + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=director --filter=xcm) +Can also exclude specific instance: --filter=director,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='director,CRITICAL,^(?!(online)$)' + +=item B<--warning> + +Set warning threshold for disk (syntax: type,regexp,threshold) +Example: --warning='disk,.*,5:' + +=item B<--critical> + +Set critical threshold for disk (syntax: type,regexp,threshold) +Example: --critical='disk,.*,3:' + +=item B<--file-health> + +The location of the global storage file status (Should be something like: C:/xxxx/HealthCheck.log). + +=item B<--file-health-env> + +The location of the environment storage file status (Should be something like: C:/xxxx/HealthCheck_ENV.log). + +=back + +=cut + \ No newline at end of file diff --git a/storage/emc/symmetrix/dmx34/local/plugin.pm b/storage/emc/symmetrix/dmx34/local/plugin.pm new file mode 100644 index 000000000..366220252 --- /dev/null +++ b/storage/emc/symmetrix/dmx34/local/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::emc::symmetrix::dmx34::local::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'hardware' => 'storage::emc::symmetrix::dmx34::local::mode::hardware', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check symmetrix DMX 3 and 4. The plugin needs to be installed on Windows Management. + +=cut From c702666bbbc590bfb14ed58ad4271d192ff0d615 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 23 Apr 2016 18:13:29 +0200 Subject: [PATCH 11/22] + remove file --- .../dmx34/local/mode/components/directors.pm | 70 ------------------- 1 file changed, 70 deletions(-) delete mode 100644 storage/emc/symmetrix/dmx34/local/mode/components/directors.pm diff --git a/storage/emc/symmetrix/dmx34/local/mode/components/directors.pm b/storage/emc/symmetrix/dmx34/local/mode/components/directors.pm deleted file mode 100644 index c8a79299f..000000000 --- a/storage/emc/symmetrix/dmx34/local/mode/components/directors.pm +++ /dev/null @@ -1,70 +0,0 @@ -# -# Copyright 2016 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package storage::netapp::snmp::mode::components::communication; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %map_com_states = ( - 1 => 'initializing', - 2 => 'transitioning', - 3 => 'active', - 4 => 'inactive', - 5 => 'reconfiguring', - 6 => 'nonexistent', -); -my $oid_enclChannelShelfAddr = '.1.3.6.1.4.1.789.1.21.1.2.1.3'; -my $oid_enclContactState = '.1.3.6.1.4.1.789.1.21.1.2.1.2'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_enclContactState }; -} - -sub check { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking communications"); - $self->{components}->{communication} = {name => 'communications', total => 0, skip => 0}; - return if ($self->check_filter(section => 'communication')); - - for (my $i = 1; $i <= $self->{number_shelf}; $i++) { - my $shelf_addr = $self->{shelf_addr}->{$oid_enclChannelShelfAddr . '.' . $i}; - my $com_state = $map_com_states{$self->{results}->{$oid_enclContactState}->{$oid_enclContactState . '.' . $i}}; - - next if ($self->check_filter(section => 'communication', instance => $shelf_addr)); - - $self->{components}->{communication}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Shelve '%s' communication state is '%s'", - $shelf_addr, $com_state)); - my $exit = $self->get_severity(section => 'communication', value => $com_state); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Shelve '%s' communication state is '%s'", - $shelf_addr, $com_state)); - } - } -} - -1; From 659cd6183101a5802ae5d21d99d4839b7413b249 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 23 Apr 2016 18:43:38 +0200 Subject: [PATCH 12/22] + add callback --- centreon/plugins/templates/hardware.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/centreon/plugins/templates/hardware.pm b/centreon/plugins/templates/hardware.pm index 0c16369fe..d01a5e600 100644 --- a/centreon/plugins/templates/hardware.pm +++ b/centreon/plugins/templates/hardware.pm @@ -39,6 +39,7 @@ sub set_system { #$self->{cb_hook1} = 'callbackname'; # before the loads #$self->{cb_hook2} = 'callbackname'; # between loads and requests #$self->{cb_hook3} = 'callbackname'; # after requests + #$self->{cb_hook4} = 'callbackname'; # after output # Example for threshold: #$self->{thresholds} = { @@ -283,6 +284,8 @@ sub run { short_msg => 'No components are checked.'); } + $self->call_object_callback(method_name => $self->{cb_hook4}, %options); + $self->{output}->display(); $self->{output}->exit(); } From aacbb8c3cbacc013f6c5ba9a4a3beff05be737f5 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 23 Apr 2016 18:54:50 +0200 Subject: [PATCH 13/22] + fix help --- apps/protocols/smtp/mode/message.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/protocols/smtp/mode/message.pm b/apps/protocols/smtp/mode/message.pm index 41665455b..db8857c56 100644 --- a/apps/protocols/smtp/mode/message.pm +++ b/apps/protocols/smtp/mode/message.pm @@ -113,7 +113,7 @@ Check send a message to a SMTP Server. =item B<--hostname> -IP Addr/FQDN of the ftp host +IP Addr/FQDN of the smtp host =item B<--port> From 23efe69fc32de46b69acf76bf78b557a87107d13 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Sat, 23 Apr 2016 20:17:13 +0200 Subject: [PATCH 14/22] + fix option smtp --- storage/emc/symmetrix/dmx34/local/mode/hardware.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/storage/emc/symmetrix/dmx34/local/mode/hardware.pm b/storage/emc/symmetrix/dmx34/local/mode/hardware.pm index be3fcab6d..f2667401b 100644 --- a/storage/emc/symmetrix/dmx34/local/mode/hardware.pm +++ b/storage/emc/symmetrix/dmx34/local/mode/hardware.pm @@ -131,7 +131,7 @@ sub read_files { sub send_email { my ($self, %options) = @_; - + ####### # Check SMTP options return if (!((defined($self->{option_results}->{email_warning}) && $self->{option_results}->{email_warning} ne '') @@ -154,7 +154,7 @@ sub send_email { if (defined($self->{option_results}->{email_smtp_username}) && defined($self->{option_results}->{email_smtp_password})) { $smtp_options{-pass} = $self->{option_results}->{email_smtp_password}; } - foreach my $option (@{$self->{option_results}->{smtp_options}}) { + foreach my $option (@{$self->{option_results}->{email_smtp_options}}) { next if ($option !~ /^(.+?)=(.+)$/); $smtp_options{-$1} = $2; } From 02602d226b0fdf0a10ae67b44909483daf2b91a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duret?= Date: Tue, 26 Apr 2016 09:04:09 +0200 Subject: [PATCH 15/22] =?UTF-8?q?Probl=C3=A8me=20avec=20la=20gestion=20des?= =?UTF-8?q?=20seuils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: on comparait le timestamp avec les seuils alors qu'il faut comparer la différence (timestamp - localtime) --- database/postgres/mode/timesync.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/postgres/mode/timesync.pm b/database/postgres/mode/timesync.pm index 2da789d90..94b3bb798 100644 --- a/database/postgres/mode/timesync.pm +++ b/database/postgres/mode/timesync.pm @@ -74,7 +74,7 @@ SELECT extract(epoch FROM now()) AS epok } my $diff = $result - $ltime; - my $exit_code = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $diff, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("%.3fs time diff between servers", $diff)); From 9452678090819c9c4ecb73d2b045a9332ff0ee0a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 2 May 2016 21:04:46 +0200 Subject: [PATCH 16/22] Fix #392 --- snmp_standard/mode/uptime.pm | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/snmp_standard/mode/uptime.pm b/snmp_standard/mode/uptime.pm index debe77f5b..f2fda5626 100644 --- a/snmp_standard/mode/uptime.pm +++ b/snmp_standard/mode/uptime.pm @@ -25,6 +25,7 @@ use base qw(centreon::plugins::mode); use strict; use warnings; use POSIX; +use centreon::plugins::misc; sub new { my ($class, %options) = @_; @@ -36,7 +37,6 @@ sub new { { "warning:s" => { name => 'warning', }, "critical:s" => { name => 'critical', }, - "seconds" => { name => 'seconds', }, "force-oid:s" => { name => 'force_oid', }, }); @@ -59,7 +59,6 @@ sub check_options { sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; # To be used first for OS @@ -89,8 +88,8 @@ sub run { min => 0); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("System uptime is: %s", - defined($self->{option_results}->{seconds}) ? floor($value / 100) . " seconds" : floor($value / 86400 / 100) . " days" )); + short_msg => sprintf("System uptime is: %s", + centreon::plugins::misc::change_seconds(value => floor($value / 100)))); $self->{output}->display(); $self->{output}->exit(); @@ -114,10 +113,6 @@ Threshold warning in seconds. Threshold critical in seconds. -=item B<--seconds> - -Display uptime in seconds. - =item B<--force-oid> Can choose your oid (numeric format only). From 2b9d0b7a47c8fd189e8570f1b755a3bed3b28584 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 2 May 2016 21:06:27 +0200 Subject: [PATCH 17/22] + Fix #380 --- centreon/plugins/misc.pm | 8 +++++--- centreon/plugins/script.pm | 5 +++-- centreon/plugins/script_custom.pm | 4 ++-- centreon/plugins/script_simple.pm | 4 ++-- centreon/plugins/script_snmp.pm | 4 ++-- centreon/plugins/script_sql.pm | 4 ++-- centreon/plugins/script_wsman.pm | 4 ++-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index 13e8377cb..1a1086c21 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -214,11 +214,13 @@ sub unix_execute { sub mymodule_load { my (%options) = @_; my $file; - ($file = $options{module} . ".pm") =~ s{::}{/}g; - + ($file = ($options{module} =~ /\.pm$/ ? $options{module} : $options{module} . ".pm")) =~ s{::}{/}g; + eval { local $SIG{__DIE__} = 'IGNORE'; require $file; + $file =~ s{/}{::}g; + $file =~ s/\.pm$//; }; if ($@) { return 1 if (defined($options{no_quit}) && $options{no_quit} == 1); @@ -226,7 +228,7 @@ sub mymodule_load { $options{output}->add_option_msg(short_msg => $options{error_msg}); $options{output}->option_exit(); } - return 0; + return wantarray ? (0, $file) : 0; } sub backtick { diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm index eba9379e6..39b1f053c 100644 --- a/centreon/plugins/script.pm +++ b/centreon/plugins/script.pm @@ -273,8 +273,9 @@ sub run { $self->check_relaunch(); - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin}, - error_msg => "Cannot load module --plugin."); + (undef, $self->{plugin}) = + centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{plugin}, + error_msg => "Cannot load module --plugin."); my $plugin = $self->{plugin}->new(options => $self->{options}, output => $self->{output}); $plugin->init(help => $self->{help}, version => $self->{version}); diff --git a/centreon/plugins/script_custom.pm b/centreon/plugins/script_custom.pm index b7b122acf..92e1672db 100644 --- a/centreon/plugins/script_custom.pm +++ b/centreon/plugins/script_custom.pm @@ -115,8 +115,8 @@ sub init { error_msg => "Cannot load module --mode."); $self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, - error_msg => "Cannot load module --dyn-mode."); + (undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, + error_msg => "Cannot load module --dyn-mode."); $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); diff --git a/centreon/plugins/script_simple.pm b/centreon/plugins/script_simple.pm index 7d0b4c23b..208a5ece5 100644 --- a/centreon/plugins/script_simple.pm +++ b/centreon/plugins/script_simple.pm @@ -86,8 +86,8 @@ sub init { error_msg => "Cannot load module --mode."); $self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, - error_msg => "Cannot load module --dyn-mode."); + (undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, + error_msg => "Cannot load module --dyn-mode."); $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); diff --git a/centreon/plugins/script_snmp.pm b/centreon/plugins/script_snmp.pm index d07470a0e..d04dbb017 100644 --- a/centreon/plugins/script_snmp.pm +++ b/centreon/plugins/script_snmp.pm @@ -91,8 +91,8 @@ sub init { error_msg => "Cannot load module --mode."); $self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, - error_msg => "Cannot load module --dyn-mode."); + (undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, + error_msg => "Cannot load module --dyn-mode."); $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); diff --git a/centreon/plugins/script_sql.pm b/centreon/plugins/script_sql.pm index 57bd0522e..bce150a78 100644 --- a/centreon/plugins/script_sql.pm +++ b/centreon/plugins/script_sql.pm @@ -107,8 +107,8 @@ sub init { error_msg => "Cannot load module --mode."); $self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, - error_msg => "Cannot load module --dyn-mode."); + (undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, + error_msg => "Cannot load module --dyn-mode."); $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); diff --git a/centreon/plugins/script_wsman.pm b/centreon/plugins/script_wsman.pm index 5d6697fe8..f4734d205 100644 --- a/centreon/plugins/script_wsman.pm +++ b/centreon/plugins/script_wsman.pm @@ -91,8 +91,8 @@ sub init { error_msg => "Cannot load module --mode."); $self->{mode} = $self->{modes}{$self->{mode_name}}->new(options => $self->{options}, output => $self->{output}, mode => $self->{mode_name}); } elsif (defined($self->{dynmode_name}) && $self->{dynmode_name} ne '') { - centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, - error_msg => "Cannot load module --dyn-mode."); + (undef, $self->{dynmode_name}) = centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $self->{dynmode_name}, + error_msg => "Cannot load module --dyn-mode."); $self->{mode} = $self->{dynmode_name}->new(options => $self->{options}, output => $self->{output}, mode => $self->{dynmode_name}); } else { $self->{output}->add_option_msg(short_msg => "Need to specify '--mode' or '--dyn-mode' option."); From b5e0a0b5fed42fbab93f8a1097298dd8ea9ea10f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 2 May 2016 21:06:44 +0200 Subject: [PATCH 18/22] + typo code style --- .../dell/compellent/local/mode/volumeusage.pm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/storage/dell/compellent/local/mode/volumeusage.pm b/storage/dell/compellent/local/mode/volumeusage.pm index 0cdcc0830..8da5629ab 100644 --- a/storage/dell/compellent/local/mode/volumeusage.pm +++ b/storage/dell/compellent/local/mode/volumeusage.pm @@ -37,10 +37,10 @@ sub set_counters { $self->{maps_counters}->{sc} = [ { label => 'sc-total', set => { key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' }, { name => 'type' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), } }, ]; @@ -48,10 +48,10 @@ sub set_counters { $self->{maps_counters}->{volume} = [ { label => 'volume-usage', set => { key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' }, { name => 'type' } ], - closure_custom_calc => \&custom_usage_calc, - closure_custom_output => \&custom_usage_output, - closure_custom_perfdata => \&custom_usage_perfdata, - closure_custom_threshold_check => \&custom_usage_threshold, + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), } }, { label => 'volume-overhead', set => { From 6ee977033dc493c8c08c351d4166eb209f47cdad Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 2 May 2016 21:21:15 +0200 Subject: [PATCH 19/22] + enhance output for aruba (can manage an error if no ap associated) --- centreon/common/airespace/snmp/mode/apstatus.pm | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon/common/airespace/snmp/mode/apstatus.pm index 0034f233a..9fca60b16 100644 --- a/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon/common/airespace/snmp/mode/apstatus.pm @@ -149,7 +149,7 @@ sub check_options { sub skip_global { my ($self, %options) = @_; - scalar(keys %{$self->{ap}}) > 1 ? return(0) : return(1); + scalar(keys %{$self->{ap}}) == 1 ? return(1) : return(0); } sub prefix_ap_output { @@ -208,7 +208,7 @@ sub manage_selection { my $result3 = $options{snmp}->map_instance(mapping => $mapping3, results => $self->{results}->{ $mapping3->{bsnAPAdminStatus}->{oid} }, instance => $instance); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $result->{bsnAPName} !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $result->{bsnAPName} . "': no matching filter.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $result->{bsnAPName} . "': no matching filter.", debug => 1); next; } @@ -220,8 +220,7 @@ sub manage_selection { } if (scalar(keys %{$self->{ap}}) <= 0) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'No AP associated (can be: slave wireless controller or your filter)'); + $self->{output}->output_add(long_msg => 'no AP associated (can be: slave wireless controller or your filter)'); } } From a6db7e1e954886589b9aa4b8266297701e08618c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 3 May 2016 14:03:06 +0200 Subject: [PATCH 20/22] + Ref #392 --- centreon/plugins/misc.pm | 2 ++ snmp_standard/mode/uptime.pm | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/centreon/plugins/misc.pm b/centreon/plugins/misc.pm index 1a1086c21..a32abb0b7 100644 --- a/centreon/plugins/misc.pm +++ b/centreon/plugins/misc.pm @@ -374,8 +374,10 @@ sub change_seconds { { unit => 'm', value => 60 }, { unit => 's', value => 1 }, ]; + my %values = ('y' => 1, 'M' => 2, 'w' => 3, 'd' => 4, 'h' => 5, 'm' => 6, 's' => 7); foreach (@$periods) { + next if (defined($options{start}) && $values{$_->{unit}} < $values{$options{start}}); my $count = int($options{value} / $_->{value}); next if ($count == 0); diff --git a/snmp_standard/mode/uptime.pm b/snmp_standard/mode/uptime.pm index f2fda5626..0264c7c24 100644 --- a/snmp_standard/mode/uptime.pm +++ b/snmp_standard/mode/uptime.pm @@ -89,7 +89,7 @@ sub run { $self->{output}->output_add(severity => $exit_code, short_msg => sprintf("System uptime is: %s", - centreon::plugins::misc::change_seconds(value => floor($value / 100)))); + centreon::plugins::misc::change_seconds(value => floor($value / 100), start => 'd'))); $self->{output}->display(); $self->{output}->exit(); From e3800f7695c2126ee2b2913d81f89f3e5af9d702 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 3 May 2016 15:05:00 +0200 Subject: [PATCH 21/22] + Fix #368 --- apps/cluster/mscs/local/mode/listresources.pm | 6 ++++-- apps/cluster/mscs/local/mode/networkstatus.pm | 3 ++- apps/cluster/mscs/local/mode/resourcegroupstatus.pm | 8 +++++--- apps/cluster/mscs/local/mode/resourcestatus.pm | 6 ++++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/cluster/mscs/local/mode/listresources.pm b/apps/cluster/mscs/local/mode/listresources.pm index 504c36e76..da61a9b98 100644 --- a/apps/cluster/mscs/local/mode/listresources.pm +++ b/apps/cluster/mscs/local/mode/listresources.pm @@ -80,6 +80,8 @@ sub manage_selection { my $name = $obj->{Name}; my $state = $map_state{$obj->{State}}; my $class = $map_class{$obj->{ResourceClass}}; + my $id = defined($obj->{Id}) ? $obj->{Id} : $name; + my $owner_node = defined($obj->{OwnerNode}) ? $obj->{OwnerNode} : '-'; if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { @@ -87,8 +89,8 @@ sub manage_selection { next; } - $self->{resources}->{$obj->{Id}} = { name => $name, state => $state, owner_node => $obj->{OwnerNode}, - class => $class }; + $self->{resources}->{$id} = { name => $name, state => $state, owner_node => $owner_node, + class => $class }; } } diff --git a/apps/cluster/mscs/local/mode/networkstatus.pm b/apps/cluster/mscs/local/mode/networkstatus.pm index f14298e97..b3a6c907a 100644 --- a/apps/cluster/mscs/local/mode/networkstatus.pm +++ b/apps/cluster/mscs/local/mode/networkstatus.pm @@ -154,6 +154,7 @@ sub manage_selection { foreach my $obj (in $resultset) { my $name = $obj->{Name}; my $state = $map_state{$obj->{State}}; + my $id = defined($obj->{ID}) ? $obj->{ID} : $name; if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { @@ -161,7 +162,7 @@ sub manage_selection { next; } - $self->{network}->{$obj->{ID}} = { display => $name, state => $state }; + $self->{network}->{$id} = { display => $name, state => $state }; } } diff --git a/apps/cluster/mscs/local/mode/resourcegroupstatus.pm b/apps/cluster/mscs/local/mode/resourcegroupstatus.pm index 6731475da..bdf277526 100644 --- a/apps/cluster/mscs/local/mode/resourcegroupstatus.pm +++ b/apps/cluster/mscs/local/mode/resourcegroupstatus.pm @@ -196,15 +196,17 @@ sub manage_selection { foreach my $obj (in $resultset) { my $name = $obj->{Name}; my $state = $map_state{$obj->{State}}; + my $id = defined($obj->{Id}) ? $obj->{Id} : $name; + my $owner_node = defined($obj->{OwnerNode}) ? $obj->{OwnerNode} : '-'; if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); next; } - $self->{rg}->{$obj->{Id}} = { display => $name, state => $state, owner_node => $obj->{OwnerNode}, - preferred_owners => defined($preferred_nodes->{$name}) ? $preferred_nodes->{$name} : [] }; + $self->{rg}->{$id} = { display => $name, state => $state, owner_node => $owner_node, + preferred_owners => defined($preferred_nodes->{$name}) ? $preferred_nodes->{$name} : [] }; } } diff --git a/apps/cluster/mscs/local/mode/resourcestatus.pm b/apps/cluster/mscs/local/mode/resourcestatus.pm index 381535539..28ed41a42 100644 --- a/apps/cluster/mscs/local/mode/resourcestatus.pm +++ b/apps/cluster/mscs/local/mode/resourcestatus.pm @@ -159,14 +159,16 @@ sub manage_selection { foreach my $obj (in $resultset) { my $name = $obj->{Name}; my $state = $map_state{$obj->{State}}; + my $id = defined($obj->{Id}) ? $obj->{Id} : $name; + my $owner_node = defined($obj->{OwnerNode}) ? $obj->{OwnerNode} : '-'; if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && $name !~ /$self->{option_results}->{filter_name}/) { - $self->{output}->output_add(long_msg => "Skipping '" . $name . "': no matching filter.", debug => 1); + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); next; } - $self->{resource}->{$obj->{Id}} = { display => $name, state => $state, owner_node => $obj->{OwnerNode} }; + $self->{resource}->{$id} = { display => $name, state => $state, owner_node => $owner_node }; } } From 9be192d59d21027a2e0252a2c0e4371e8683d693 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 3 May 2016 16:34:02 +0200 Subject: [PATCH 22/22] + Ref #368 --- apps/cluster/mscs/local/mode/listresources.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/cluster/mscs/local/mode/listresources.pm b/apps/cluster/mscs/local/mode/listresources.pm index da61a9b98..47ad9e578 100644 --- a/apps/cluster/mscs/local/mode/listresources.pm +++ b/apps/cluster/mscs/local/mode/listresources.pm @@ -79,7 +79,7 @@ sub manage_selection { foreach my $obj (in $resultset) { my $name = $obj->{Name}; my $state = $map_state{$obj->{State}}; - my $class = $map_class{$obj->{ResourceClass}}; + my $class = defined($obj->{ResourceClass}) ? $map_class{$obj->{ResourceClass}} : '-'; my $id = defined($obj->{Id}) ? $obj->{Id} : $name; my $owner_node = defined($obj->{OwnerNode}) ? $obj->{OwnerNode} : '-';