diff --git a/centreon/plugins/options.pm b/centreon/plugins/options.pm index 531100cea..27e85c538 100644 --- a/centreon/plugins/options.pm +++ b/centreon/plugins/options.pm @@ -56,6 +56,16 @@ sub new { return $self; } +sub set_sanity { + my ($self, %options) = @_; + + Getopt::Long::Configure('no_pass_through'); + $SIG{__WARN__} = sub { + $self->{output}->add_option_msg(short_msg => $_[0]); + $self->{output}->option_exit(nolabel => 1); + }; +} + sub set_output { my ($self, %options) = @_; diff --git a/centreon/plugins/script_custom.pm b/centreon/plugins/script_custom.pm index d4537427c..a8bd0eca9 100644 --- a/centreon/plugins/script_custom.pm +++ b/centreon/plugins/script_custom.pm @@ -57,6 +57,7 @@ sub new { 'custommode:s' => { name => 'custommode_name' }, 'list-custommode' => { name => 'list_custommode' }, 'multiple' => { name => 'multiple' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -98,6 +99,9 @@ sub init { if (defined($self->{list_custommode})) { $self->list_custommode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -250,17 +254,25 @@ __END__ Choose a mode. +=item B<--dyn-mode> + +Specify a mode with the path (separated by '::'). + =item B<--list-mode> List available modes. +=item B<--mode-version> + +Check minimal version of mode. If not, unknown error. + =item B<--version> Display plugin version. -=item B<--dyn-mode> +=item B<--sanity-options> -Specify a mode with the path (separated by '::'). +Check unknown options (for debug purpose). =item B<--custommode> diff --git a/centreon/plugins/script_simple.pm b/centreon/plugins/script_simple.pm index 8fe717cb7..35ebbc39a 100644 --- a/centreon/plugins/script_simple.pm +++ b/centreon/plugins/script_simple.pm @@ -50,10 +50,11 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode' }, + 'mode:s' => { name => 'mode_name' }, 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -61,9 +62,10 @@ sub new { $self->{default} = undef; $self->{options}->parse_options(); - $self->{mode_name} = $self->{options}->get_option(argument => 'mode'); - $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode'); - $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version'); + $self->{option_results} = $self->{options}->get_options(); + foreach (keys %{$self->{option_results}}) { + $self->{$_} = $self->{option_results}->{$_}; + } $self->{options}->clean(); $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION'); @@ -87,6 +89,9 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -210,6 +215,10 @@ Check minimal version of mode. If not, unknown error. Display plugin version. +=item B<--sanity-options> + +Check unknown options (for debug purpose). + =back =head1 DESCRIPTION diff --git a/centreon/plugins/script_snmp.pm b/centreon/plugins/script_snmp.pm index 273e2aad3..af66c0bfc 100644 --- a/centreon/plugins/script_snmp.pm +++ b/centreon/plugins/script_snmp.pm @@ -56,6 +56,7 @@ sub new { 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -90,6 +91,9 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -219,6 +223,10 @@ Check minimal version of mode. If not, unknown error. Display plugin version. +=item B<--sanity-options> + +Check unknown options (for debug purpose). + =back =head1 DESCRIPTION diff --git a/centreon/plugins/script_sql.pm b/centreon/plugins/script_sql.pm index c8be98bef..ecf7e9c4a 100644 --- a/centreon/plugins/script_sql.pm +++ b/centreon/plugins/script_sql.pm @@ -58,6 +58,7 @@ sub new { 'sqlmode:s' => { name => 'sqlmode_name', default => 'dbi' }, 'list-sqlmode' => { name => 'list_sqlmode' }, 'multiple' => { name => 'multiple' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -99,6 +100,9 @@ sub init { if (defined($self->{list_sqlmode})) { $self->list_sqlmode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -256,21 +260,25 @@ __END__ Choose a mode. +=item B<--dyn-mode> + +Specify a mode with the path (separated by '::'). + =item B<--list-mode> List available modes. -=item B<--version> - -Display plugin version. - =item B<--mode-version> Check minimal version of mode. If not, unknown error. -=item B<--dyn-mode> +=item B<--version> -Specify a mode with the path (separated by '::'). +Display plugin version. + +=item B<--sanity-options> + +Check unknown options (for debug purpose). =item B<--sqlmode> diff --git a/centreon/plugins/script_wsman.pm b/centreon/plugins/script_wsman.pm index 651c9485e..4cb6ae015 100644 --- a/centreon/plugins/script_wsman.pm +++ b/centreon/plugins/script_wsman.pm @@ -52,10 +52,11 @@ sub new { $self->{options}->add_options( arguments => { - 'mode:s' => { name => 'mode' }, + 'mode:s' => { name => 'mode_name' }, 'dyn-mode:s' => { name => 'dynmode_name' }, 'list-mode' => { name => 'list_mode' }, 'mode-version:s' => { name => 'mode_version' }, + 'sanity-options' => { name => 'sanity_options' }, } ); $self->{version} = '1.0'; @@ -63,9 +64,10 @@ sub new { $self->{default} = undef; $self->{options}->parse_options(); - $self->{mode_name} = $self->{options}->get_option(argument => 'mode'); - $self->{list_mode} = $self->{options}->get_option(argument => 'list_mode'); - $self->{mode_version} = $self->{options}->get_option(argument => 'mode_version'); + $self->{option_results} = $self->{options}->get_options(); + foreach (keys %{$self->{option_results}}) { + $self->{$_} = $self->{option_results}->{$_}; + } $self->{options}->clean(); $self->{options}->add_help(package => $options{package}, sections => 'PLUGIN DESCRIPTION'); @@ -89,6 +91,9 @@ sub init { if (defined($self->{list_mode})) { $self->list_mode(); } + if (defined($self->{sanity_options})) { + $self->{options}->set_sanity(); + } # Output HELP $self->{options}->add_help(package => 'centreon::plugins::output', sections => 'OUTPUT OPTIONS'); @@ -206,13 +211,17 @@ Specify a mode with the path (separated by '::'). List available modes. +=item B<--mode-version> + +Check minimal version of mode. If not, unknown error. + =item B<--version> Display plugin version. -=item B<--mode-version> +=item B<--sanity-options> -Check minimal version of mode. If not, unknown error. +Check unknown options (for debug purpose). =back