diff --git a/centreon/plugins/dbi.pm b/centreon/plugins/dbi.pm index fa11987c3..3ce9ab8fd 100644 --- a/centreon/plugins/dbi.pm +++ b/centreon/plugins/dbi.pm @@ -99,8 +99,10 @@ sub handle_ALRM { $self->prepare_destroy(); $self->disconnect(); - $self->{output}->output_add(severity => $self->{sql_errors_exit}, - short_msg => 'Timeout'); + $self->{output}->output_add( + severity => $self->{sql_errors_exit}, + short_msg => 'Timeout' + ); $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon/plugins/script_sql.pm b/centreon/plugins/script_sql.pm index 9f0094a4e..bca7c8d6f 100644 --- a/centreon/plugins/script_sql.pm +++ b/centreon/plugins/script_sql.pm @@ -75,7 +75,7 @@ sub init { $self->{options}->display_help(); $self->{output}->option_exit(); } - if (defined($options{version}) && !defined($self->{mode_name})&& !defined($self->{dynmode_name})) { + if (defined($options{version}) && !defined($self->{mode_name}) && !defined($self->{dynmode_name})) { $self->version(); } if (defined($self->{list_mode})) { diff --git a/centreon/plugins/templates/catalog_functions.pm b/centreon/plugins/templates/catalog_functions.pm index 7c3815744..484c93105 100644 --- a/centreon/plugins/templates/catalog_functions.pm +++ b/centreon/plugins/templates/catalog_functions.pm @@ -25,7 +25,7 @@ use warnings; use Exporter; our @ISA = qw(Exporter); -our @EXPORT_OK = qw(catalog_status_threshold catalog_status_calc); +our @EXPORT_OK = qw(catalog_status_threshold catalog_status_threshold_ng catalog_status_calc); sub catalog_status_threshold { my ($self, %options) = @_; @@ -59,6 +59,34 @@ sub catalog_status_threshold { return $status; } +sub catalog_status_threshold_ng { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + my $label = $self->{label}; + if (defined($self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}) && $self->{instance_mode}->{option_results}->{'critical-' . $label} ne '' && + eval "$self->{instance_mode}->{option_results}->{'critical-' . $self->{label}}") { + $status = 'critical'; + } elsif (defined($self->{instance_mode}->{option_results}->{'warning-' . $label}) && $self->{instance_mode}->{option_results}->{'warning-' . $label} ne '' && + eval "$self->{instance_mode}->{option_results}->{'warning-' . $label}") { + $status = 'warning'; + } elsif (defined($self->{instance_mode}->{option_results}->{'unknown-' . $label}) && $self->{instance_mode}->{option_results}->{'unknown-' . $label} ne '' && + eval "$self->{instance_mode}->{option_results}->{'unknown-' . $label}") { + $status = 'unknown'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + sub catalog_status_calc { my ($self, %options) = @_; diff --git a/centreon/plugins/templates/counter.pm b/centreon/plugins/templates/counter.pm index 8dd1a8d6d..23c3ef946 100644 --- a/centreon/plugins/templates/counter.pm +++ b/centreon/plugins/templates/counter.pm @@ -123,7 +123,7 @@ sub new { 'filter-counters-block:s' => { name => 'filter_counters_block' }, 'filter-counters:s' => { name => 'filter_counters' }, 'display-ok-counters:s' => { name => 'display_ok_counters' }, - 'list-counters' => { name => 'list_counters' }, + 'list-counters' => { name => 'list_counters' } }); $self->{statefile_value} = undef; if (defined($options{statefile}) && $options{statefile}) { @@ -150,21 +150,24 @@ sub new { if (!defined($_->{threshold}) || $_->{threshold} != 0) { $options{options}->add_options(arguments => { - 'warning-' . $thlabel . ':s' => { name => 'warning-' . $thlabel }, - 'critical-' . $thlabel . ':s' => { name => 'critical-' . $thlabel }, + 'unknown-' . $thlabel . ':s' => { name => 'unknown-' . $thlabel, default => $_->{unknown_default} }, + 'warning-' . $thlabel . ':s' => { name => 'warning-' . $thlabel, default => $_->{warning_default} }, + 'critical-' . $thlabel . ':s' => { name => 'critical-' . $thlabel, default => $_->{critical_default} } }); if (defined($_->{nlabel})) { $options{options}->add_options(arguments => { - 'warning-' . $_->{label} . ':s' => { name => 'warning-' . $_->{label}, redirect => 'warning-' . $thlabel }, - 'critical-' . $_->{label} . ':s' => { name => 'critical-' . $_->{label}, redirect => 'critical-' . $thlabel }, + 'unknown-' . $_->{label} . ':s' => { name => 'unknown-' . $_->{label}, redirect => 'unknown-' . $thlabel }, + 'warning-' . $_->{label} . ':s' => { name => 'warning-' . $_->{label}, redirect => 'warning-' . $thlabel }, + 'critical-' . $_->{label} . ':s' => { name => 'critical-' . $_->{label}, redirect => 'critical-' . $thlabel } }); } } + $_->{obj} = centreon::plugins::values->new( statefile => $self->{statefile_value}, output => $self->{output}, perfdata => $self->{perfdata}, - label => $_->{label}, nlabel => $_->{nlabel}, thlabel => $thlabel, + label => $_->{label}, nlabel => $_->{nlabel}, thlabel => $thlabel ); $_->{obj}->set(%{$_->{set}}); } @@ -193,13 +196,19 @@ sub check_options { $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1); $self->{output}->exit(); } + + my $change_macros_opt = []; foreach my $key (keys %{$self->{maps_counters}}) { foreach (@{$self->{maps_counters}->{$key}}) { + push @$change_macros_opt, 'unknown-' . $_->{label}, 'warning-' . $_->{label}, 'critical-' . $_->{label} + if (defined($_->{type}) && $_->{type} == 2); $_->{obj}->{instance_mode} = $self; $_->{obj}->init(option_results => $self->{option_results}); } } - + + $self->change_macros(macros => $change_macros_opt) if (scalar(@$change_macros_opt) > 0); + if (defined($self->{statefile_value})) { $self->{statefile_value}->check_options(%options); } diff --git a/database/mysql/mysqlcmd.pm b/database/mysql/mysqlcmd.pm index 6b8d6b75f..961b4da1a 100644 --- a/database/mysql/mysqlcmd.pm +++ b/database/mysql/mysqlcmd.pm @@ -56,7 +56,7 @@ sub new { $options{options}->add_help(package => __PACKAGE__, sections => 'MYSQLCMD OPTIONS', once => 1); $self->{output} = $options{output}; - $self->{custommode_name} = $options{custommode_name}; + $self->{sqlmode_name} = $options{sqlmode_name}; $self->{args} = undef; $self->{stdout} = undef; $self->{columns} = undef; @@ -81,7 +81,7 @@ sub set_defaults { my ($self, %options) = @_; foreach (keys %{$options{default}}) { - if ($_ eq $self->{custommode_name}) { + if ($_ eq $self->{sqlmode_name}) { for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { foreach my $opt (keys %{$options{default}->{$_}[$i]}) { if (!defined($self->{option_results}->{$opt}[$i])) { diff --git a/database/oracle/sqlpluscmd.pm b/database/oracle/sqlpluscmd.pm index c26a34fb5..2b0016c29 100644 --- a/database/oracle/sqlpluscmd.pm +++ b/database/oracle/sqlpluscmd.pm @@ -63,7 +63,7 @@ sub new { $options{options}->add_help(package => __PACKAGE__, sections => 'sqlpluscmd OPTIONS', once => 1); $self->{output} = $options{output}; - $self->{custommode_name} = $options{custommode_name}; + $self->{sqlmode_name} = $options{sqlmode_name}; $self->{args} = undef; $self->{stdout} = undef; $self->{columns} = undef; @@ -87,7 +87,7 @@ sub set_defaults { my ($self, %options) = @_; foreach (keys %{$options{default}}) { - if ($_ eq $self->{custommode_name}) { + if ($_ eq $self->{sqlmode_name}) { for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { foreach my $opt (keys %{$options{default}->{$_}[$i]}) { if (!defined($self->{option_results}->{$opt}[$i])) { diff --git a/database/postgres/psqlcmd.pm b/database/postgres/psqlcmd.pm index 8386dd687..721cc8ec3 100644 --- a/database/postgres/psqlcmd.pm +++ b/database/postgres/psqlcmd.pm @@ -56,7 +56,7 @@ sub new { $options{options}->add_help(package => __PACKAGE__, sections => 'PSQLCMD OPTIONS', once => 1); $self->{output} = $options{output}; - $self->{custommode_name} = $options{custommode_name}; + $self->{sqlmode_name} = $options{sqlmode_name}; $self->{args} = undef; $self->{stdout} = undef; $self->{columns} = undef; @@ -84,7 +84,7 @@ sub set_defaults { my ($self, %options) = @_; foreach (keys %{$options{default}}) { - if ($_ eq $self->{custommode_name}) { + if ($_ eq $self->{sqlmode_name}) { for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { foreach my $opt (keys %{$options{default}->{$_}[$i]}) { if (!defined($self->{option_results}->{$opt}[$i])) { diff --git a/network/f5/bigip/snmp/mode/trunks.pm b/network/f5/bigip/snmp/mode/trunks.pm index aa6714d42..2b7224437 100644 --- a/network/f5/bigip/snmp/mode/trunks.pm +++ b/network/f5/bigip/snmp/mode/trunks.pm @@ -24,7 +24,7 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); +use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); use Digest::MD5 qw(md5_hex); sub custom_traffic_perfdata { @@ -224,11 +224,13 @@ sub set_counters { ]; $self->{maps_counters}->{trunk_global} = [ - { label => 'status', threshold => 0, set => { + { + label => 'status', type => 2, critical_default => '%{status} =~ /uninitialized|down/', + set => { key_values => [ { name => 'status' }, { name => 'display' } ], output_template => "status is '%s'", output_error_template => 'status: %s', closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } }, { label => 'traffic-in', set => { @@ -296,11 +298,11 @@ sub set_counters { ]; $self->{maps_counters}->{interfaces} = [ - { label => 'interface-status', threshold => 0, set => { + { label => 'interface-status', type => 2, set => { key_values => [ { name => 'status' }, { name => 'display' } ], output_template => "status is '%s'", closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&catalog_status_threshold + closure_custom_threshold_check => \&catalog_status_threshold_ng } } ]; @@ -315,12 +317,6 @@ sub new { 'filter-name:s' => { name => 'filter_name' }, 'units-traffic:s' => { name => 'units_traffic', default => '%' }, 'speed:s' => { name => 'speed' }, - 'unknown-status:s' => { name => 'unknown_status', default => '' }, - 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} =~ /uninitialized|down/' }, - 'unknown-interface-status:s' => { name => 'unknown_interface_status', default => '' }, - 'warning-interface-status:s' => { name => 'warning_interface_status', default => '' }, - 'critical-interface-status:s' => { name => 'critical_interface_status', default => '' }, 'add-interfaces' => { name => 'add_interfaces' } }); diff --git a/snmp_standard/mode/ntp.pm b/snmp_standard/mode/ntp.pm index c7e67fc51..e7fba9129 100644 --- a/snmp_standard/mode/ntp.pm +++ b/snmp_standard/mode/ntp.pm @@ -49,10 +49,10 @@ sub set_counters { key_values => [ { name => 'offset' }, { name => 'date' } ], closure_custom_output => $self->can('custom_usage_output'), perfdatas => [ - { label => 'offset', value => 'offset', template => '%d', unit => 's' }, - ], + { label => 'offset', template => '%d', unit => 's' } + ] } - }, + } ]; } @@ -60,11 +60,11 @@ sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - + $options{options}->add_options(arguments => { 'ntp-hostname:s' => { name => 'ntp_hostname' }, 'ntp-port:s' => { name => 'ntp_port', default => 123 }, - 'timezone:s' => { name => 'timezone' }, + 'timezone:s' => { name => 'timezone' } }); return $self; @@ -98,13 +98,13 @@ sub get_target_time { my $tz = centreon::plugins::misc::set_timezone(name => $timezone); my $dt = DateTime->new( - year => $remote_date[0], - month => $remote_date[1], - day => $remote_date[2], - hour => $remote_date[3], - minute => $remote_date[4], - second => $remote_date[5], - %$tz + year => $remote_date[0], + month => $remote_date[1], + day => $remote_date[2], + hour => $remote_date[3], + minute => $remote_date[4], + second => $remote_date[5], + %$tz ); return ($dt->epoch, \@remote_date, $timezone); @@ -117,7 +117,7 @@ sub manage_selection { my $ref_time; if (defined($self->{option_results}->{ntp_hostname}) && $self->{option_results}->{ntp_hostname} ne '') { my %ntp; - + eval { %ntp = Net::NTP::get_ntp_response($self->{option_results}->{ntp_hostname}, $self->{option_results}->{ntp_port}); }; @@ -129,7 +129,7 @@ sub manage_selection { $self->{output}->display(); $self->{output}->exit(); } - + $ref_time = $ntp{'Transmit Timestamp'}; } else { $ref_time = time(); @@ -143,7 +143,7 @@ sub manage_selection { ); $self->{offset} = { - offset => sprintf("%d", $offset), + offset => sprintf('%d', $offset), date => $remote_date_formated, }; }