diff --git a/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm b/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm index 3627cd9f4..be82a2ed5 100644 --- a/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm +++ b/centreon-plugins/apps/antivirus/clamav/local/mode/updatestatus.pm @@ -124,7 +124,14 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + $self->{clamav_command} = 'echo "==== CLAMD ===" ; clamd -V ; echo "==== DAILY ===="; sigtool --info ' . $self->{option_results}->{dailydb_file} . '; echo "==== MAIN ====" ; sigtool --info ' . $self->{option_results}->{maindb_file}; } diff --git a/centreon-plugins/apps/apcupsd/local/custom/cli.pm b/centreon-plugins/apps/apcupsd/local/custom/cli.pm new file mode 100644 index 000000000..9f4c01b2b --- /dev/null +++ b/centreon-plugins/apps/apcupsd/local/custom/cli.pm @@ -0,0 +1,100 @@ +# +# Copyright 2022 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::apcupsd::local::custom::cli; + +use base qw(centreon::plugins::script_custom::cli); + +use strict; +use warnings; + +sub execute_command { + my ($self, %options) = @_; + + my ($stdout) = $self->SUPER::execute_command(%options); + + my $searchpattern = $options{searchpattern}; + my ($valueok, $value) = (0); + foreach (split(/\n/, $stdout)) { + if (/^$searchpattern\s*:\s*(.*)\s(Percent Load Capacity|Percent|Minutes|Seconds|Volts|Hz|seconds|C Internal|F Internal|C|F)/i) { + $valueok = 1; + $value = $1; + }; + }; + + if ($valueok != 1) { + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => 'NO DATA FOUND' + ); + $self->{output}->display(); + $self->{output}->exit(); + } + + return $value; +} + +1; + +__END__ + +=head1 NAME + +ssh + +=head1 SYNOPSIS + +my ssh + +=head1 CLI OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 45). Default value can be override by the mode. + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=item B<--sudo> + +sudo command. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm b/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm index 9c82f855c..fa42645b2 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/batterycharge.pm @@ -24,72 +24,68 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'BCHARGE' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'BCHARGE' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); $self->{output}->display(); $self->{output}->exit(); @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check battery charge. + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back =cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm b/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm index 9ad79a765..14471ea33 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/batteryvoltage.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'BATTV' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'BATTV' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); + + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check battery voltage + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/libgetdata.pm b/centreon-plugins/apps/apcupsd/local/mode/libgetdata.pm deleted file mode 100644 index de6b36264..000000000 --- a/centreon-plugins/apps/apcupsd/local/mode/libgetdata.pm +++ /dev/null @@ -1,63 +0,0 @@ -# -# Copyright 2022 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::apcupsd::local::mode::libgetdata; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::misc; - -sub getdata { - 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->{option_results}->{apchost} . ":" . $self->{option_results}->{apcport} . $self->{option_results}->{command_options2}); - - my $searchpattern = $self->{option_results}->{searchpattern}; - my ($valueok); - my ($value); - #print $stdout; - foreach (split(/\n/, $stdout)) { - if (/^$searchpattern\s*:\s*(.*)\s(Percent Load Capacity|Percent|Minutes|Seconds|Volts|Hz|seconds|C Internal|F Internal|C|F)/i) { - $valueok = "1"; - $value = $1; - #print $value; - #print "\n"; - }; - }; - - if ($valueok == "1") { - #print $value; - return $value; - } else { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => 'NO DATA FOUND'); - $self->{output}->display(); - $self->{output}->exit(); - }; -}; - -1; diff --git a/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm b/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm index 0a6d721f7..b1acd89a9 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/linefrequency.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'LINEFREQ' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'LINEFREQ' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; + + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check line frequency + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back =cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm b/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm index 2b089fe93..de887e82c 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/linevoltage.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'LINEV' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'LINEV' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); + + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check line voltage + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back =cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm b/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm index 27e7d429b..1cabc28de 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/loadpercentage.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'LOADPCT' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'LOADPCT' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); + + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check load percentage + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back =cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm b/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm index 0324b2738..60a895499 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/outputvoltage.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'OUTPUTV' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'OUTPUTV' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); + + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check output voltage + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back =cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/temperature.pm b/centreon-plugins/apps/apcupsd/local/mode/temperature.pm index f695477e1..d6becfe24 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/temperature.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/temperature.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'ITEMP' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'ITEMP' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); + + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check temperature + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back -=cut \ No newline at end of file +=cut diff --git a/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm b/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm index 20416e50c..09b69ad86 100644 --- a/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm +++ b/centreon-plugins/apps/apcupsd/local/mode/timeleft.pm @@ -24,75 +24,71 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use apps::apcupsd::local::mode::libgetdata; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'apcaccess' }, - "command-path:s" => { name => 'command_path', default => '/sbin/' }, - "command-options:s" => { name => 'command_options', default => ' status ' }, - "command-options2:s" => { name => 'command_options2', default => ' 2>&1' }, - "apchost:s" => { name => 'apchost', default => 'localhost' }, - "apcport:s" => { name => 'apcport', default => '3551' }, - "searchpattern:s" => { name => 'searchpattern', default => 'TIMELEFT' }, - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); + + $options{options}->add_options(arguments => { + 'apchost:s' => { name => 'apchost', default => 'localhost' }, + 'apcport:s' => { name => 'apcport', default => '3551' }, + 'searchpattern:s' => { name => 'searchpattern', default => 'TIMELEFT' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { - my ($self, %options) = @_; $self->SUPER::init(%options); if (!defined($self->{option_results}->{apchost})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Host."); + $self->{output}->option_exit(); } if (!defined($self->{option_results}->{apcport})) { - $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify an APC Port."); + $self->{output}->option_exit(); } 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) = @_; - - my $result = apps::apcupsd::local::mode::libgetdata::getdata($self); - my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result)); + my $result = $options{custom}->execute_command( + command_path => '/sbin', + command => 'apcaccess', + command_options => 'status ' . $self->{option_results}->{apchost} . ':' . $self->{option_results}->{apcport} . ' 2>&1', + searchpattern => $self->{option_results}->{searchpattern} + ); + + my $exit = $self->{perfdata}->threshold_check(value => $result, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf($self->{option_results}->{searchpattern} . ": %f", $result) + ); + + $self->{output}->perfdata_add( + label => $self->{option_results}->{searchpattern}, + value => $result, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); - $self->{output}->perfdata_add(label => $self->{option_results}->{searchpattern}, - value => $result, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') - ); $self->{output}->display(); $self->{output}->exit(); - } 1; @@ -101,7 +97,9 @@ __END__ =head1 MODE -Check apcupsd Status +Check battery time left + +Command used: /sbin/apcaccess status %(apchost):%(apcport) 2>&1 =over 8 @@ -121,18 +119,6 @@ Warning Threshold Critical Threshold -=item B<--remote> - -If you dont wanna install the apcupsd client on your local system you can run it remotely with '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'). - =back =cut diff --git a/centreon-plugins/apps/apcupsd/local/plugin.pm b/centreon-plugins/apps/apcupsd/local/plugin.pm index 2fa211be8..ba8905a1e 100644 --- a/centreon-plugins/apps/apcupsd/local/plugin.pm +++ b/centreon-plugins/apps/apcupsd/local/plugin.pm @@ -76,24 +76,26 @@ package apps::apcupsd::local::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'batterycharge' => 'apps::apcupsd::local::mode::batterycharge', # BCHARGE - 'temperature' => 'apps::apcupsd::local::mode::temperature', # ITEMP - 'timeleft' => 'apps::apcupsd::local::mode::timeleft', # TIMELEFT MAXTIME MINTIMEL - 'linevoltage' => 'apps::apcupsd::local::mode::linevoltage', # LINEV - 'batteryvoltage' => 'apps::apcupsd::local::mode::batteryvoltage', # BATTV - 'outputvoltage' => 'apps::apcupsd::local::mode::outputvoltage', # OUTPUTV - 'linefrequency' => 'apps::apcupsd::local::mode::linefrequency', # LINEFREQ - 'loadpercentage' => 'apps::apcupsd::local::mode::loadpercentage', # LOADPCT - ); + $self->{modes} = { + 'batterycharge' => 'apps::apcupsd::local::mode::batterycharge', # BCHARGE + 'temperature' => 'apps::apcupsd::local::mode::temperature', # ITEMP + 'timeleft' => 'apps::apcupsd::local::mode::timeleft', # TIMELEFT MAXTIME MINTIMEL + 'linevoltage' => 'apps::apcupsd::local::mode::linevoltage', # LINEV + 'batteryvoltage' => 'apps::apcupsd::local::mode::batteryvoltage', # BATTV + 'outputvoltage' => 'apps::apcupsd::local::mode::outputvoltage', # OUTPUTV + 'linefrequency' => 'apps::apcupsd::local::mode::linefrequency', # LINEFREQ + 'loadpercentage' => 'apps::apcupsd::local::mode::loadpercentage' # LOADPCT + }; + + $self->{custom_modes}->{cli} = 'apps::apcupsd::local::custom::cli'; + return $self; } diff --git a/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm b/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm index cdda64866..a5d239af2 100644 --- a/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm +++ b/centreon-plugins/apps/automation/ansible/cli/custom/cli.pm @@ -20,81 +20,30 @@ package apps::automation::ansible::cli::custom::cli; +use base qw(centreon::plugins::script_custom::cli); + use strict; use warnings; use JSON::XS; -sub new { - my ($class, %options) = @_; - my $self = {}; - bless $self, $class; - - if (!defined($options{output})) { - print "Class Custom: Need to specify 'output' argument.\n"; - exit 3; - } - if (!defined($options{options})) { - $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); - $options{output}->option_exit(); - } - - if (!defined($options{noptions})) { - $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 => 50 }, - 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '' } - }); - } - $options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1); - - $self->{output} = $options{output}; - - return $self; -} - -sub set_options { +sub execute_command { my ($self, %options) = @_; - $self->{option_results} = $options{option_results}; -} - -sub set_defaults {} - -sub check_options { - my ($self, %options) = @_; - - return 0; -} - -sub execute { - my ($self, %options) = @_; - - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1); - - my ($response) = 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 => $options{cmd_options}, - no_errors => { 4 => 1 } + my ($stdout, $exit_code) = $self->SUPER::execute_command( + %options, + no_quit => 1 ); + if ($exit_code != 0 && $exit_code != 4) { + $self->{output}->add_option_msg(short_msg => "Command error: $stdout"); + $self->{output}->option_exit(); + } my $raw_results; - eval { - $raw_results = JSON::XS->new->utf8->decode($response); + $raw_results = JSON::XS->new->utf8->decode($stdout); }; if ($@) { - $self->{output}->output_add(long_msg => $response, debug => 1); + $self->{output}->output_add(long_msg => $stdout, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); $self->{output}->option_exit(); } @@ -102,25 +51,6 @@ sub execute { return $raw_results; } -sub ansible_list_hosts_set_cmd { - my ($self, %options) = @_; - - return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne ''); - - my $cmd_options = "$options{host_pattern} --module-name=setup"; - - return $cmd_options; -} - -sub ansible_list_hosts { - my ($self, %options) = @_; - - my $cmd_options = $self->ansible_list_hosts_set_cmd(%options); - my $raw_results = $self->execute(cmd_options => $cmd_options); - - return $raw_results; -} - 1; __END__ @@ -133,31 +63,6 @@ Ansible CLI Ansible CLI -=over 8 - -=item B<--timeout> - -Set timeout in seconds (Default: 50). - -=item B<--sudo> - -Use 'sudo' to execute the command. - -=item B<--command> - -Command to get information (Default: 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible'). -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: none). - -=back - =head1 DESCRIPTION B. diff --git a/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm b/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm index 222fab60c..db020650b 100644 --- a/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm +++ b/centreon-plugins/apps/automation/ansible/cli/mode/discovery.pm @@ -52,7 +52,10 @@ sub run { $disco_stats->{start_time} = time(); - my $result = $options{custom}->ansible_list_hosts(host_pattern => $self->{option_results}->{host_pattern}); + my $result = $options{custom}->execute_command( + command => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible', + command_options => "'" . $self->{option_results}->{host_pattern} . "' --module-name=setup", + ); $disco_stats->{end_time} = time(); $disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time}; @@ -100,6 +103,8 @@ __END__ Resources discovery. +Command used: ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible %(host_pattern) --module-name=setup + =over 8 =item B<--host-pattern> diff --git a/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm b/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm index d32516040..ecae8e170 100644 --- a/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm +++ b/centreon-plugins/apps/automation/ansible/tower/custom/towercli.pm @@ -45,9 +45,9 @@ sub new { 'password:s' => { name => 'password' }, 'timeout:s' => { name => 'timeout', default => 50 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'tower-cli' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '' }, + 'command-options:s' => { name => 'command_options' }, 'nossl' => { name => 'nossl' }, 'proxyurl:s' => { name => 'proxyurl' } }); @@ -91,13 +91,22 @@ sub check_options { sub execute { my ($self, %options) = @_; - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + my $command = defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : 'tower-cli'; + + $self->{output}->output_add(long_msg => "Command line: '" . $command . " " . $options{cmd_options} . "'", debug => 1); my ($response) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, + command => $command, command_path => $self->{option_results}->{command_path}, command_options => $options{cmd_options} ); diff --git a/centreon-plugins/apps/backup/backupexec/local/mode/alerts.pm b/centreon-plugins/apps/backup/backupexec/local/mode/alerts.pm index baca9d3d2..966210dec 100644 --- a/centreon-plugins/apps/backup/backupexec/local/mode/alerts.pm +++ b/centreon-plugins/apps/backup/backupexec/local/mode/alerts.pm @@ -101,9 +101,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -116,6 +116,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/backupexec/local/mode/disks.pm b/centreon-plugins/apps/backup/backupexec/local/mode/disks.pm index 29cbb7a16..fda9741fc 100644 --- a/centreon-plugins/apps/backup/backupexec/local/mode/disks.pm +++ b/centreon-plugins/apps/backup/backupexec/local/mode/disks.pm @@ -135,9 +135,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -149,6 +149,24 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/backupexec/local/mode/jobs.pm b/centreon-plugins/apps/backup/backupexec/local/mode/jobs.pm index 8a8d060fb..fc5b841d8 100644 --- a/centreon-plugins/apps/backup/backupexec/local/mode/jobs.pm +++ b/centreon-plugins/apps/backup/backupexec/local/mode/jobs.pm @@ -121,9 +121,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -137,6 +137,24 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/backupexec/local/mode/listdisks.pm b/centreon-plugins/apps/backup/backupexec/local/mode/listdisks.pm index 187048081..8431a0b80 100644 --- a/centreon-plugins/apps/backup/backupexec/local/mode/listdisks.pm +++ b/centreon-plugins/apps/backup/backupexec/local/mode/listdisks.pm @@ -36,9 +36,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -51,6 +51,18 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub run { diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm b/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm index e95318517..35a7e9bb1 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/tapeusage.pm @@ -182,47 +182,6 @@ Command used: vmquery -a -w =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<--exec-only> Print command output diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm b/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm index 87870bb03..1875c6271 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/listvtl.pm @@ -31,27 +31,40 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'vtconfig' }, - "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, - "command-options:s" => { name => 'command_options', default => '-l' }, - "filter-name:s" => { name => 'filter_name' }, - }); - + $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' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + "filter-name:s" => { name => 'filter_name' } + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'vtconfig' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-l' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->{option_results}->{command_path} = '/quadstorvtl/bin' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); } sub run { diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm index 446be6e5a..9ada0878d 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtldiskusage.pm @@ -109,6 +109,12 @@ sub custom_usage_calc { return 0; } +sub prefix_disk_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + sub set_counters { my ($self, %options) = @_; @@ -141,24 +147,23 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'bdconfig' }, - "command-path:s" => { name => 'command_path', default => '/quadstorvtl/bin' }, - "command-options:s" => { name => 'command_options', default => '-l -c' }, - "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, - "units:s" => { name => 'units', default => '%' }, - "free" => { name => 'free' }, - }); + $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' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /active/i' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); return $self; } @@ -167,24 +172,35 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'bdconfig' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-l -c' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->{option_results}->{command_path} = '/quadstorvtl/bin' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); + $self->change_macros(macros => ['warning_status', 'critical_status']); } -sub prefix_disk_output { - my ($self, %options) = @_; - - return "Disk '" . $options{instance_value}->{display} . "' "; -} - 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}); + 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->{disk} = {}; #ID Vendor Model SerialNumber Name Pool Size Used Status #1 Msft Virtual /dev/sdb Default 1024.00 21.28 Active diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm index 46bce1d85..d2ec75e24 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtljobstatus.pm @@ -123,14 +123,33 @@ sub new { 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'impexp' }, - 'command-path:s' => { name => 'command_path', default => '/quadstorvtl/bin' }, - 'command-options:s' => { name => 'command_options', default => '-l' } + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' } }); return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'impexp' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-l' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->{option_results}->{command_path} = '/quadstorvtl/bin' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm b/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm index a478992f8..8951b7019 100644 --- a/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm +++ b/centreon-plugins/apps/backup/quadstor/local/mode/vtltapeusage.pm @@ -162,9 +162,9 @@ sub new { 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'vcconfig' }, - 'command-path:s' => { name => 'command_path', default => '/quadstorvtl/bin' }, - 'command-options:s' => { name => 'command_options', default => '-l -v %{vtl_name}' }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, 'vtl-name:s' => { name => 'vtl_name' }, 'filter-name:s' => { name => 'filter_name' }, 'warning-status:s' => { name => 'warning_status', default => '' }, @@ -185,6 +185,20 @@ sub check_options { $self->{output}->option_exit(); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'vcconfig' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-l -v %{vtl_name}' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->{option_results}->{command_path} = '/quadstorvtl/bin' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); + $self->{option_results}->{command_options} =~ s/%\{vtl_name\}/$self->{option_results}->{vtl_name}/; $self->change_macros(macros => ['warning_status', 'critical_status']); } diff --git a/centreon-plugins/apps/backup/tsm/local/custom/api.pm b/centreon-plugins/apps/backup/tsm/local/custom/api.pm index 846b82b03..3d7a64d2f 100644 --- a/centreon-plugins/apps/backup/tsm/local/custom/api.pm +++ b/centreon-plugins/apps/backup/tsm/local/custom/api.pm @@ -49,9 +49,9 @@ sub new { 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 45 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'dsmadmc' }, - 'command-path:s' => { name => 'command_path', default => '/opt/tivoli/tsm/client/ba/bin' }, - 'command-options:s' => { name => 'command_options', default => '' } + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'TSM CLI OPTIONS', once => 1); @@ -84,6 +84,18 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to set tsm-password option."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'dsmadmc' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_path} = '/opt/tivoli/tsm/client/ba/bin' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); return 0; } diff --git a/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm b/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm index 6945e5d41..d5a4449f6 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/jobstatus.pm @@ -110,9 +110,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -135,6 +135,18 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(macros => ['ok_status', 'warning_status', 'critical_status', 'warning_long', 'critical_long']); } diff --git a/centreon-plugins/apps/backup/veeam/local/mode/licenses.pm b/centreon-plugins/apps/backup/veeam/local/mode/licenses.pm index cdd1aa9bc..5281074b4 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/licenses.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/licenses.pm @@ -159,9 +159,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -178,6 +178,18 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + if ($self->{option_results}->{unit} eq '' || !defined($unitdiv->{$self->{option_results}->{unit}})) { $self->{option_results}->{unit} = 's'; } diff --git a/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm b/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm index 96a0ed7ae..a8c0a54b8 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/listjobs.pm @@ -36,9 +36,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -51,6 +51,18 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub run { diff --git a/centreon-plugins/apps/backup/veeam/local/mode/listrepositories.pm b/centreon-plugins/apps/backup/veeam/local/mode/listrepositories.pm index 4445de0c7..3bce0de2f 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/listrepositories.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/listrepositories.pm @@ -36,9 +36,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' } @@ -50,6 +50,18 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub run { diff --git a/centreon-plugins/apps/backup/veeam/local/mode/repositories.pm b/centreon-plugins/apps/backup/veeam/local/mode/repositories.pm index 2a0d71912..d132a7842 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/repositories.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/repositories.pm @@ -136,9 +136,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -150,6 +150,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/veeam/local/mode/tapejobs.pm b/centreon-plugins/apps/backup/veeam/local/mode/tapejobs.pm index 720a0a8d0..21d32bbbb 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/tapejobs.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/tapejobs.pm @@ -88,9 +88,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -102,6 +102,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/backup/veeam/local/mode/vsbjobs.pm b/centreon-plugins/apps/backup/veeam/local/mode/vsbjobs.pm index e40caf806..530087465 100644 --- a/centreon-plugins/apps/backup/veeam/local/mode/vsbjobs.pm +++ b/centreon-plugins/apps/backup/veeam/local/mode/vsbjobs.pm @@ -120,9 +120,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -134,6 +134,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/bluemind/local/custom/api.pm b/centreon-plugins/apps/bluemind/local/custom/api.pm index 6c5607259..e04330fce 100644 --- a/centreon-plugins/apps/bluemind/local/custom/api.pm +++ b/centreon-plugins/apps/bluemind/local/custom/api.pm @@ -78,6 +78,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/apps/centreon/local/mode/centenginestats.pm b/centreon-plugins/apps/centreon/local/mode/centenginestats.pm index b9104d76b..9d5b8d1d4 100644 --- a/centreon-plugins/apps/centreon/local/mode/centenginestats.pm +++ b/centreon-plugins/apps/centreon/local/mode/centenginestats.pm @@ -162,8 +162,8 @@ sub set_counters { threshold_use => $_->[0] , closure_custom_output => $self->can('custom_' . $type . '_execution_time_output'), perfdatas => [ - { value => $_->[0] , template => '%.3f', min => 0, unit => 's' }, - ], + { value => $_->[0] , template => '%.3f', min => 0, unit => 's' } + ] } } ; @@ -183,8 +183,8 @@ sub set_counters { threshold_use => $_->[0] , closure_custom_output => $self->can('custom_' . $type . '_checked_output'), perfdatas => [ - { value => $_->[0] , template => '%d', min => 0 }, - ], + { value => $_->[0] , template => '%d', min => 0 } + ] } } ; @@ -226,8 +226,8 @@ sub set_counters { threshold_use => $_->[0] , closure_custom_output => $self->can('custom_hosts_status_output'), perfdatas => [ - { value => $_->[0] , template => '%s', min => 0, max => 'total' }, - ], + { value => $_->[0] , template => '%s', min => 0, max => 'total' } + ] } } ; @@ -247,8 +247,8 @@ sub set_counters { threshold_use => $_->[0] , closure_custom_output => $self->can('custom_services_status_output'), perfdatas => [ - { value => $_->[0] , template => '%s', min => 0, max => 'total' }, - ], + { value => $_->[0] , template => '%s', min => 0, max => 'total' } + ] } } ; @@ -268,8 +268,8 @@ sub set_counters { threshold_use => $_->[0] , closure_custom_output => $self->can('custom_commands_buffer_output'), perfdatas => [ - { value => $_->[0] , template => '%s', min => 0, max => 'total' }, - ], + { value => $_->[0] , template => '%s', min => 0, max => 'total' } + ] } } ; @@ -282,21 +282,40 @@ sub new { bless $self, $class; $options{options}->add_options(arguments => { - 'command:s' => { name => 'command', default => 'centenginestats' }, - 'command-path:s' => { name => 'command_path', default => '/usr/sbin' }, - 'command-options:s' => { name => 'command_options', default => '2>&1' }, + 'command:s' => { name => 'command' }, + 'command-path:s' => { name => 'command_path' }, + 'command-options:s' => { name => 'command_options' }, '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' }, + 'sudo' => { name => 'sudo' } }); return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'centenginestats' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '2>&1' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->{option_results}->{command_path} = '/usr/sbin' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/hddtemp/custom/cli.pm b/centreon-plugins/apps/hddtemp/custom/cli.pm index 11f67f8fa..3596324d0 100644 --- a/centreon-plugins/apps/hddtemp/custom/cli.pm +++ b/centreon-plugins/apps/hddtemp/custom/cli.pm @@ -75,6 +75,20 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_drives}, + command_options => $self->{option_results}->{command_options_drives}, + command_path => $self->{option_results}->{command_path_drives} + ); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_hddtemp}, + command_options => $self->{option_results}->{command_options_hddtemp}, + command_path => $self->{option_results}->{command_path_hddtemp} + ); + return 0; } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/activesyncmailbox.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/activesyncmailbox.pm index 19a76ade9..b1ec49c75 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/activesyncmailbox.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/activesyncmailbox.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning' }, @@ -75,6 +75,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify '--password' option."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/databases.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/databases.pm index 1aa1602ea..9cf35372a 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/databases.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/databases.pm @@ -264,9 +264,9 @@ sub new { 'no-mapi' => { name => 'no_mapi' }, 'no-copystatus' => { name => 'no_copystatus' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'ps-server-filter:s' => { name => 'ps_server_filter' }, @@ -277,6 +277,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/imapmailbox.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/imapmailbox.pm index f36a8be10..6e8bda8cc 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/imapmailbox.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/imapmailbox.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning' }, @@ -74,6 +74,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify '--password' option."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/listdatabases.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/listdatabases.pm index b052c5534..ba88931a5 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/listdatabases.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/listdatabases.pm @@ -39,9 +39,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'ps-database-filter:s' => { name => 'ps_database_filter' } @@ -53,6 +53,18 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/mailboxes.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/mailboxes.pm index c311b9c00..fb0deee21 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/mailboxes.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/mailboxes.pm @@ -115,9 +115,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'ps-server:s' => { name => 'ps_server' }, @@ -129,6 +129,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/mapimailbox.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/mapimailbox.pm index ee6e1e0db..e94f52db5 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/mapimailbox.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/mapimailbox.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning' }, @@ -69,6 +69,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/outlookwebservices.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/outlookwebservices.pm index 9d5fd340e..bc12bfbe1 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/outlookwebservices.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/outlookwebservices.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning', }, @@ -70,6 +70,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify '--mailbox' option."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/owamailbox.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/owamailbox.pm index 39bad9a1d..b156cca57 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/owamailbox.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/owamailbox.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning' }, @@ -80,6 +80,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify '--password' option."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/queues.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/queues.pm index a252598ac..bda21fdcc 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/queues.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/queues.pm @@ -84,9 +84,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' } }); @@ -94,6 +94,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/replicationhealth.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/replicationhealth.pm index ba17bb8fc..4efe7413c 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/replicationhealth.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/replicationhealth.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password', }, 'no-ps' => { name => 'no_ps', }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only', }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning', }, @@ -64,6 +64,18 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/exchange/local/mode/services.pm b/centreon-plugins/apps/microsoft/exchange/local/mode/services.pm index b3f7cda52..59478885a 100644 --- a/centreon-plugins/apps/microsoft/exchange/local/mode/services.pm +++ b/centreon-plugins/apps/microsoft/exchange/local/mode/services.pm @@ -38,9 +38,9 @@ sub new { 'remote-password:s' => { name => 'remote_password' }, 'no-ps' => { name => 'no_ps' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'warning:s' => { name => 'warning' }, @@ -64,6 +64,18 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(); } diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/listnodevms.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/listnodevms.pm index 3ab4a0664..f472d4877 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/listnodevms.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/listnodevms.pm @@ -36,9 +36,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' } @@ -50,6 +50,18 @@ sub new { sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm index 670755aa8..099d32e7c 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -103,9 +103,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -117,6 +117,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodereplication.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodereplication.pm index 63eae337b..6dc231891 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodereplication.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodereplication.pm @@ -72,9 +72,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -84,6 +84,24 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm index d3bbc1ec4..e9a91176f 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodesnapshot.pm @@ -77,9 +77,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -91,6 +91,24 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm index 4b00b45d3..27e781ac4 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/nodevmstatus.pm @@ -66,9 +66,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -79,6 +79,24 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm index aee60bab7..919c3c63a 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmdiscovery.pm @@ -48,9 +48,9 @@ sub new { 'scvmm-password:s' => { name => 'scvmm_password' }, 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, 'timeout:s' => { name => 'timeout', default => 90 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' } @@ -79,6 +79,18 @@ sub check_options { $self->{output}->option_exit(); } } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub powershell_exec { diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm index aea96c54e..7a64e106a 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmintegrationservice.pm @@ -151,9 +151,9 @@ sub new { 'scvmm-password:s' => { name => 'scvmm_password' }, 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -178,6 +178,18 @@ sub check_options { $self->{output}->option_exit(); } } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm index 735a5082b..75c9640f0 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmsnapshot.pm @@ -68,9 +68,9 @@ sub new { 'scvmm-password:s' => { name => 'scvmm_password' }, 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -95,6 +95,18 @@ sub check_options { $self->{output}->option_exit(); } } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm index 0039daa3a..f421fae4b 100644 --- a/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm +++ b/centreon-plugins/apps/microsoft/hyperv/2012/local/mode/scvmmvmstatus.pm @@ -71,9 +71,9 @@ sub new { 'scvmm-password:s' => { name => 'scvmm_password' }, 'scvmm-port:s' => { name => 'scvmm_port', default => 8100 }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -97,6 +97,18 @@ sub check_options { $self->{output}->option_exit(); } } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/apps/microsoft/sccm/local/mode/databasereplicationstatus.pm b/centreon-plugins/apps/microsoft/sccm/local/mode/databasereplicationstatus.pm index 03382fe8f..3c9ae0c2f 100644 --- a/centreon-plugins/apps/microsoft/sccm/local/mode/databasereplicationstatus.pm +++ b/centreon-plugins/apps/microsoft/sccm/local/mode/databasereplicationstatus.pm @@ -147,9 +147,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -159,6 +159,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/sccm/local/mode/sitestatus.pm b/centreon-plugins/apps/microsoft/sccm/local/mode/sitestatus.pm index 522f407b3..f67024a66 100644 --- a/centreon-plugins/apps/microsoft/sccm/local/mode/sitestatus.pm +++ b/centreon-plugins/apps/microsoft/sccm/local/mode/sitestatus.pm @@ -115,9 +115,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' } @@ -126,6 +126,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/wsus/local/mode/computersstatus.pm b/centreon-plugins/apps/microsoft/wsus/local/mode/computersstatus.pm index 967bf557e..f98a1d6af 100644 --- a/centreon-plugins/apps/microsoft/wsus/local/mode/computersstatus.pm +++ b/centreon-plugins/apps/microsoft/wsus/local/mode/computersstatus.pm @@ -92,9 +92,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -107,6 +107,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/wsus/local/mode/serverstatistics.pm b/centreon-plugins/apps/microsoft/wsus/local/mode/serverstatistics.pm index 16a4a9844..0d9333d91 100644 --- a/centreon-plugins/apps/microsoft/wsus/local/mode/serverstatistics.pm +++ b/centreon-plugins/apps/microsoft/wsus/local/mode/serverstatistics.pm @@ -110,9 +110,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -124,6 +124,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/microsoft/wsus/local/mode/synchronisationstatus.pm b/centreon-plugins/apps/microsoft/wsus/local/mode/synchronisationstatus.pm index c8b45741c..b5e91af0d 100644 --- a/centreon-plugins/apps/microsoft/wsus/local/mode/synchronisationstatus.pm +++ b/centreon-plugins/apps/microsoft/wsus/local/mode/synchronisationstatus.pm @@ -218,9 +218,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -241,6 +241,18 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); + $self->change_macros(macros => [ 'warning_synchronisation_status', 'critical_synchronisation_status', 'warning_last_synchronisation_status', 'critical_last_synchronisation_status'] diff --git a/centreon-plugins/apps/microsoft/wsus/local/mode/updatesstatus.pm b/centreon-plugins/apps/microsoft/wsus/local/mode/updatesstatus.pm index aa0ff9e65..334f8426c 100644 --- a/centreon-plugins/apps/microsoft/wsus/local/mode/updatesstatus.pm +++ b/centreon-plugins/apps/microsoft/wsus/local/mode/updatesstatus.pm @@ -92,9 +92,9 @@ sub new { $options{options}->add_options(arguments => { 'timeout:s' => { name => 'timeout', default => 30 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, @@ -106,6 +106,23 @@ sub new { return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + sub manage_selection { my ($self, %options) = @_; diff --git a/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm b/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm index cbb4157d2..c2ba76a78 100644 --- a/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm +++ b/centreon-plugins/apps/monitoring/openmetrics/mode/scrapemetrics.pm @@ -40,7 +40,7 @@ sub new { 'subinstance:s' => { name => 'subinstance' }, 'filter-instance:s' => { name => 'filter_instance' }, 'filter-subinstance:s' => { name => 'filter_subinstance' }, - 'new-perfdata' => { name => 'new_perfdata' }, + 'new-perfdata' => { name => 'new_perfdata' } }); return $self; @@ -51,19 +51,19 @@ 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) = @_; - $self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options,strip_chars => "[\"']"); + $self->{metrics} = centreon::common::monitoring::openmetrics::scrape::parse(%options, strip_chars => "[\"']"); my @exits; my $short_msg = 'All metrics are ok'; @@ -100,8 +100,11 @@ sub run { push @exits, $self->{perfdata}->threshold_check( value => $data->{value}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, - { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ + { label => 'critical', exit_litteral => 'critical' }, + { label => 'warning', exit_litteral => 'warning' } + ] + ); $self->{output}->perfdata_add( label => $label, @@ -110,11 +113,15 @@ sub run { critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') ); - $self->{output}->output_add(long_msg => sprintf("Metric '%s' value is '%s' [Help: \"%s\"] [Type: '%s'] [Dimensions: \"%s\"]", - $metric, $data->{value}, - (defined($self->{metrics}->{$metric}->{help})) ? $self->{metrics}->{$metric}->{help} : '-', - (defined($self->{metrics}->{$metric}->{type})) ? $self->{metrics}->{$metric}->{type} : '-', - $data->{dimensions_string})); + $self->{output}->output_add( + long_msg => sprintf( + "Metric '%s' value is '%s' [Help: \"%s\"] [Type: '%s'] [Dimensions: \"%s\"]", + $metric, $data->{value}, + (defined($self->{metrics}->{$metric}->{help})) ? $self->{metrics}->{$metric}->{help} : '-', + (defined($self->{metrics}->{$metric}->{type})) ? $self->{metrics}->{$metric}->{type} : '-', + $data->{dimensions_string} + ) + ); } } @@ -122,7 +129,7 @@ sub run { $self->{output}->add_option_msg(short_msg => "No metrics found."); $self->{output}->option_exit(); } - + my $exit = $self->{output}->get_most_critical(status => \@exits); $short_msg = 'Some metrics are not ok' if ($exit !~ /OK/i); $self->{output}->output_add(severity => $exit, short_msg => $short_msg); @@ -153,7 +160,7 @@ Examples: --custommode=file --command-options='/tmp/metrics' --filter-metrics='cpu' --verbose # perl centreon_plugins.pl --plugin=apps::monitoring::openmetrics::plugin --mode=scrape-metrics ---custommode=file --hostname=10.2.3.4 --ssh-option='-l=centreon-engine' --ssh-option='-p=52' +--custommode=file --hostname=10.2.3.4 --ssh-username='centreon-engine' --ssh-port='52' --command-options='/my/app/path/metrics' --verbose =over 8 diff --git a/centreon-plugins/apps/monitoring/openmetrics/plugin.pm b/centreon-plugins/apps/monitoring/openmetrics/plugin.pm index c774c4e04..36c4b188e 100644 --- a/centreon-plugins/apps/monitoring/openmetrics/plugin.pm +++ b/centreon-plugins/apps/monitoring/openmetrics/plugin.pm @@ -29,12 +29,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'scrape-metrics' => 'apps::monitoring::openmetrics::mode::scrapemetrics', - ); - $self->{custom_modes}{web} = 'centreon::common::monitoring::openmetrics::custom::web'; - $self->{custom_modes}{file} = 'centreon::common::monitoring::openmetrics::custom::file'; + $self->{modes} = { + 'scrape-metrics' => 'apps::monitoring::openmetrics::mode::scrapemetrics' + }; + + $self->{custom_modes}->{web} = 'centreon::common::monitoring::openmetrics::custom::web'; + $self->{custom_modes}->{file} = 'centreon::common::monitoring::openmetrics::custom::file'; return $self; } diff --git a/centreon-plugins/apps/oracle/gg/local/custom/cli.pm b/centreon-plugins/apps/oracle/gg/local/custom/cli.pm index e54d1d328..0199e2fcc 100644 --- a/centreon-plugins/apps/oracle/gg/local/custom/cli.pm +++ b/centreon-plugins/apps/oracle/gg/local/custom/cli.pm @@ -78,6 +78,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm b/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm index 046021e49..d30195965 100644 --- a/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm +++ b/centreon-plugins/centreon/common/monitoring/openmetrics/custom/file.pm @@ -20,6 +20,8 @@ package centreon::common::monitoring::openmetrics::custom::file; +use base qw(centreon::plugins::script_custom::cli); + use strict; use warnings; use centreon::plugins::misc; @@ -27,51 +29,29 @@ use Digest::MD5 qw(md5_hex); sub new { my ($class, %options) = @_; - my $self = {}; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, nohelp => 1); bless $self, $class; - if (!defined($options{output})) { - print "Class Custom: Need to specify 'output' argument.\n"; - exit 3; - } - if (!defined($options{options})) { - $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); - $options{output}->option_exit(); - } - - if (!defined($options{noptions})) { - $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'ssh-option:s@' => { name => 'ssh_option' }, - 'ssh-path:s' => { name => 'ssh_path' }, - 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, - 'timeout:s' => { name => 'timeout', default => 10 }, - 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'cat' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options' } - }); - } $options{options}->add_help(package => __PACKAGE__, sections => 'FILE OPTIONS', once => 1); - $self->{output} = $options{output}; - return $self; } -sub set_options { - my ($self, %options) = @_; - - $self->{option_results} = $options{option_results}; -} - -sub set_defaults {} - sub check_options { my ($self, %options) = @_; - if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { - $self->{option_results}->{remote} = 1; + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'cat' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + + if (defined($self->{option_results}->{command_options})) { + # we remove illegal characters + $self->{option_results}->{command_options} =~ s/[`;!&]//g; } return 0; @@ -89,14 +69,8 @@ sub get_uuid { sub scrape { my ($self, %options) = @_; - return 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}, - ); + my ($stdout) = $self->SUPER::execute_command(%options); + return $stdout; } 1; @@ -117,27 +91,7 @@ Openmetrics file custom mode =item B<--hostname> -Endpoint hostname (If 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. +Hostname to query (with ssh). =item B<--command> @@ -149,11 +103,7 @@ Command path. =item B<--command-options> -Command options). - -=item B<--timeout> - -Set SSH timeout (Default: 10). +Command options. =back diff --git a/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm b/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm index c16cb71b2..67b153f29 100644 --- a/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm +++ b/centreon-plugins/centreon/common/monitoring/openmetrics/scrape.pm @@ -28,7 +28,7 @@ sub parse { my (%options) = @_; my $result; - my $response = $options{custom}->scrape; + my $response = $options{custom}->scrape(); foreach my $line (split /\n/, $response) { $result->{metrics}->{$1}->{type} = $2 if ($line =~ /^#\sTYPE\s(\w+)\s(.*)$/); diff --git a/centreon-plugins/centreon/common/powershell/backupexec/disks.pm b/centreon-plugins/centreon/common/powershell/backupexec/disks.pm index ee61999c3..8a1e03b5a 100644 --- a/centreon-plugins/centreon/common/powershell/backupexec/disks.pm +++ b/centreon-plugins/centreon/common/powershell/backupexec/disks.pm @@ -23,7 +23,7 @@ package centreon::common::powershell::backupexec::disks; use strict; use warnings; use centreon::common::powershell::functions; -use centreon::common::powershell::veeam::functions; +use centreon::common::powershell::backupexec::functions; sub get_powershell { my (%options) = @_; diff --git a/centreon-plugins/centreon/plugins/backend/ssh/plink.pm b/centreon-plugins/centreon/plugins/backend/ssh/plink.pm index c80dd485b..e1bfa9dd4 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/plink.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/plink.pm @@ -31,7 +31,7 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - 'plink-command:s' => { name => 'plink_command', default => 'plink' }, + 'plink-command:s' => { name => 'plink_command' }, 'plink-path:s' => { name => 'plink_path' }, 'plink-option:s@' => { name => 'plink_option' } }); @@ -54,6 +54,13 @@ sub check_options { $self->{ssh_username} = $options{option_results}->{ssh_username}; $self->{ssh_password} = $options{option_results}->{ssh_password}; + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $options{option_results}->{plink_command}, + command_options => join('', @{$self->{ssh_option}}), + command_path => $self->{ssh_path} + ); + push @{$self->{ssh_option}}, '-batch'; push @{$self->{ssh_option}}, '-l=' . $self->{ssh_username} if (defined($self->{ssh_username}) && $self->{ssh_username} ne ''); push @{$self->{ssh_option}}, '-pw=' . $self->{ssh_password} if (defined($self->{ssh_password}) && $self->{ssh_password} ne ''); diff --git a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm index 59ca432b5..3a6014f40 100644 --- a/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm +++ b/centreon-plugins/centreon/plugins/backend/ssh/sshcli.pm @@ -31,7 +31,7 @@ sub new { if (!defined($options{noptions}) || $options{noptions} != 1) { $options{options}->add_options(arguments => { - 'sshcli-command:s' => { name => 'sshcli_command', default => 'ssh' }, + 'sshcli-command:s' => { name => 'sshcli_command' }, 'sshcli-path:s' => { name => 'sshcli_path' }, 'sshcli-option:s@' => { name => 'sshcli_option' } }); @@ -57,6 +57,13 @@ sub check_options { $self->{output}->option_exit(); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $options{option_results}->{sshcli_command}, + command_options => join('', @{$self->{ssh_option}}), + command_path => $self->{ssh_path} + ); + push @{$self->{ssh_option}}, '-o=BatchMode=yes'; push @{$self->{ssh_option}}, '-l=' . $self->{ssh_username} if (defined($self->{ssh_username}) && $self->{ssh_username} ne ''); push @{$self->{ssh_option}}, '-p=' . $self->{ssh_port} if (defined($self->{ssh_port}) && $self->{ssh_port} ne ''); diff --git a/centreon-plugins/centreon/plugins/misc.pm b/centreon-plugins/centreon/plugins/misc.pm index 186e217ce..7ce696b9c 100644 --- a/centreon-plugins/centreon/plugins/misc.pm +++ b/centreon-plugins/centreon/plugins/misc.pm @@ -23,6 +23,7 @@ package centreon::plugins::misc; use strict; use warnings; use utf8; +use JSON::XS; sub execute { my (%options) = @_; @@ -616,6 +617,56 @@ sub eval_ssl_options { return $ssl_context; } +sub slurp_file { + my (%options) = @_; + + my $content = do { + local $/ = undef; + if (!open my $fh, '<', $options{file}) { + $options{output}->add_option_msg(short_msg => "Could not open file $options{file}: $!"); + $options{output}->option_exit(); + } + <$fh>; + }; + + return $content; +} + +sub check_security_command { + my (%options) = @_; + + return 0 if (!( + (defined($options{command}) && $options{command} ne '') || + (defined($options{command_options}) && $options{command_options} ne '') || + (defined($options{command_path}) && $options{command_path} ne '')) + ); + + my $security_file = '/etc/centreon-plugins/security.json'; + if ($^O eq 'MSWin32') { + $security_file = 'C:/Program Files/centreon-plugins/security.json'; + } + + return 0 if (! -r "$security_file" || -z "$security_file"); + + my $content = slurp_file(output => $options{output}, file => $security_file); + + my $security; + eval { + $security = JSON::XS->new->utf8->decode($content); + }; + if ($@) { + $options{output}->add_option_msg(short_msg => 'Cannot decode security file content'); + $options{output}->option_exit(); + } + + if (defined($security->{block_command_overload}) && $security->{block_command_overload} == 1) { + $options{output}->add_option_msg(short_msg => 'Cannot overload command (security)'); + $options{output}->option_exit(); + } + + return 0; +} + 1; __END__ diff --git a/centreon-plugins/centreon/plugins/script_custom/cli.pm b/centreon-plugins/centreon/plugins/script_custom/cli.pm index 79e7ed2cc..54bf6ed19 100644 --- a/centreon-plugins/centreon/plugins/script_custom/cli.pm +++ b/centreon-plugins/centreon/plugins/script_custom/cli.pm @@ -50,7 +50,8 @@ sub new { }); } - $options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1); + $options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1) + if (!defined($options{nohelp})); $self->{output} = $options{output}; $self->{ssh} = centreon::plugins::ssh->new(%options); @@ -76,6 +77,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } @@ -92,6 +100,7 @@ sub get_identifier { sub execute_command { my ($self, %options) = @_; + my $timeout = $self->{timeout}; if (!defined($timeout)) { $timeout = defined($options{timeout}) ? $options{timeout} : 45; diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm index 301850113..d5630cc00 100644 --- a/centreon-plugins/cloud/aws/custom/awscli.pm +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -22,6 +22,7 @@ package cloud::aws::custom::awscli; use strict; use warnings; +use centreon::plugins::misc; use DateTime; use JSON::XS; @@ -54,9 +55,9 @@ sub new { 'zeroed' => { name => 'zeroed' }, 'timeout:s' => { name => 'timeout', default => 50 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'aws' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '' }, + 'command-options:s' => { name => 'command_options' }, 'skip-ssl-check' => { name => 'skip_ssl_check' }, 'proxyurl:s' => { name => 'proxyurl' } }); @@ -148,22 +149,31 @@ sub check_options { $self->{endpoint_url} = (defined($self->{option_results}->{endpoint_url})) ? $self->{option_results}->{endpoint_url} : undef; + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } sub execute { my ($self, %options) = @_; + my $command = defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : 'aws'; + my $cmd_options = $options{cmd_options}; $cmd_options .= " --debug" if ($self->{output}->is_debug()); - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1); + $self->{output}->output_add(long_msg => "Command line: '" . $command . " " . $cmd_options . "'", debug => 1); my ($response) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, + command => $command, command_path => $self->{option_results}->{command_path}, command_options => $cmd_options, redirect_stderr => ($self->{output}->is_debug()) ? 0 : 1 diff --git a/centreon-plugins/cloud/azure/custom/azcli.pm b/centreon-plugins/cloud/azure/custom/azcli.pm index 9a1ce7ffc..5afb81903 100644 --- a/centreon-plugins/cloud/azure/custom/azcli.pm +++ b/centreon-plugins/cloud/azure/custom/azcli.pm @@ -22,6 +22,7 @@ package cloud::azure::custom::azcli; use strict; use warnings; +use centreon::plugins::misc; use DateTime; use JSON::XS; @@ -51,9 +52,9 @@ sub new { 'zeroed' => { name => 'zeroed' }, 'timeout:s' => { name => 'timeout', default => 50 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'az' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '' }, + 'command-options:s' => { name => 'command_options' }, 'proxyurl:s' => { name => 'proxyurl' } }); } @@ -91,21 +92,31 @@ sub check_options { $self->{subscription} = (defined($self->{option_results}->{subscription})) ? $self->{option_results}->{subscription} : undef; + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } sub execute { my ($self, %options) = @_; - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $options{cmd_options} . "'", debug => 1); + my $command = defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : 'az'; + + $self->{output}->output_add(long_msg => "Command line: '" . $command . " " . $options{cmd_options} . "'", debug => 1); my ($response) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, + command => $command, command_path => $self->{option_results}->{command_path}, - command_options => $options{cmd_options}); + command_options => $options{cmd_options} + ); my $raw_results; diff --git a/centreon-plugins/cloud/kubernetes/custom/kubectl.pm b/centreon-plugins/cloud/kubernetes/custom/kubectl.pm index 9948116c4..2be1809e0 100644 --- a/centreon-plugins/cloud/kubernetes/custom/kubectl.pm +++ b/centreon-plugins/cloud/kubernetes/custom/kubectl.pm @@ -22,6 +22,7 @@ package cloud::kubernetes::custom::kubectl; use strict; use warnings; +use centreon::plugins::misc; use JSON::XS; sub new { @@ -48,9 +49,9 @@ sub new { 'config-file:s' => { name => 'config_file', default => '~/.kube/config' }, 'context:s' => { name => 'context' }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'kubectl' }, + 'command:s' => { name => 'command', default => '' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '' }, + 'command-options:s' => { name => 'command_options' }, 'proxyurl:s' => { name => 'proxyurl' }, }); } @@ -95,13 +96,22 @@ sub check_options { $ENV{HTTP_PROXY} = $self->{option_results}->{proxyurl}; $ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl}; } - + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } sub execute { my ($self, %options) = @_; + my $command = defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : 'kubectl'; + my $cmd_options = $options{cmd_options}; # See https://kubernetes.io/docs/reference/kubectl/cheatsheet/#kubectl-output-verbosity-and-debugging $cmd_options .= " --v='9'" if ($self->{output}->is_debug()); @@ -110,13 +120,13 @@ sub execute { $cmd_options = $self->{option_results}->{command_options}; } - $self->{output}->output_add(long_msg => "Command line: '" . $self->{option_results}->{command} . " " . $cmd_options . "'", debug => 1); + $self->{output}->output_add(long_msg => "Command line: '" . $command . " " . $cmd_options . "'", debug => 1); my ($response, $exit_code) = centreon::plugins::misc::execute( output => $self->{output}, options => $self->{option_results}, sudo => $self->{option_results}->{sudo}, - command => $self->{option_results}->{command}, + command => $command, command_path => $self->{option_results}->{command_path}, command_options => $cmd_options, redirect_stderr => ($self->{output}->is_debug()) ? 0 : 1, diff --git a/centreon-plugins/database/rrdtool/local/custom/cli.pm b/centreon-plugins/database/rrdtool/local/custom/cli.pm index c570d02ea..d09e41ee4 100644 --- a/centreon-plugins/database/rrdtool/local/custom/cli.pm +++ b/centreon-plugins/database/rrdtool/local/custom/cli.pm @@ -77,6 +77,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm index 1b9529be5..cca078e6b 100644 --- a/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm +++ b/centreon-plugins/hardware/devices/safenet/hsm/protecttoolkit/mode/hardware.pm @@ -90,14 +90,31 @@ sub new { 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, 'timeout:s' => { name => 'timeout', default => 30 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'ctconf' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-v' } + 'command-options:s' => { name => 'command_options' } }); return $self; } +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'ctconf' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-v' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); +} + 1; __END__ diff --git a/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm b/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm index 55de6e0bf..33b9d6cd3 100644 --- a/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm +++ b/centreon-plugins/hardware/sensors/temperhum/local/mode/environment.pm @@ -26,6 +26,12 @@ use strict; use warnings; use centreon::plugins::misc; +sub prefix_device_output { + my ($self, %options) = @_; + + return "'" . $options{instance_value}->{display} . "' "; +} + sub set_counters { my ($self, %options) = @_; @@ -78,38 +84,51 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "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 => 'tempered' }, - "command-path:s" => { name => 'command_path', default => '/opt/PCsensor/TEMPered/utils/' }, - "command-options:s" => { name => 'command_options' }, - "filter-drive:s" => { name => 'filter_drive', default => '.*' }, - }); + $options{options}->add_options(arguments => { + "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' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + "filter-drive:s" => { name => 'filter_drive', default => '.*' } + }); + return $self; } -sub prefix_device_output { +sub check_options { my ($self, %options) = @_; + $self->SUPER::check_options(%options); - return "'" . $options{instance_value}->{display} . "' "; + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'tempered' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_path} = '/opt/PCsensor/TEMPered/utils/' + if (!defined($self->{option_results}->{command_path}) || $self->{option_results}->{command_path} eq ''); } sub manage_selection { my ($self, %options) = @_; $self->{drive} = {}; - 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}); + 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} + ); foreach (split(/\n/, $stdout)) { next if !/(\/dev\/[a-z0-9]+).*temperature\s(\d*\.?\d+).*relative\shumidity\s(\d*\.?\d+).*dew\spoint\s(\d*\.?\d+)/; diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm index 2152f8f5f..64073f5f9 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/environmentsf2xx.pm @@ -32,14 +32,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => 23 }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 30 }, - }); + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => 23 }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "timeout:s" => { name => 'timeout', default => 30 } + }); + return $self; } diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm index 0bb7ac304..c43e84d31 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showboards.pm @@ -33,19 +33,19 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port', default => 23 }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "memory" => { name => 'memory' }, - "command-plink:s" => { name => 'command_plink', default => 'plink' }, - "ssh" => { name => 'ssh' }, - "exclude:s" => { name => 'exclude' }, - "no-component:s" => { name => 'no_component' }, - }); + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => 23 }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "timeout:s" => { name => 'timeout', default => 50 }, + "memory" => { name => 'memory' }, + "command-plink:s" => { name => 'command_plink' }, + "ssh" => { name => 'ssh' }, + "exclude:s" => { name => 'exclude' }, + "no-component:s" => { name => 'no_component' } + }); + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); $self->{components} = {}; $self->{no_components} = undef; @@ -77,7 +77,7 @@ sub check_options { if (!defined($self->{option_results}->{ssh})) { require hardware::server::sun::mgmt_cards::lib::telnet; } - + if (defined($self->{option_results}->{no_component})) { if ($self->{option_results}->{no_component} ne '') { $self->{no_components} = $self->{option_results}->{no_component}; @@ -85,6 +85,14 @@ sub check_options { $self->{no_components} = 'critical'; } } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_plink} + ); + + $self->{option_results}->{command} = 'plink' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); } sub telnet_shell_plateform { @@ -114,10 +122,11 @@ sub ssh_command { my $cmd_in = "0" . $username . $self->{option_results}->{password} . '\nshowboards\ndisconnect\n'; my $cmd = "echo -e '$cmd_in' | " . $self->{option_results}->{command_plink} . " -batch " . $self->{option_results}->{hostname} . " 2>&1"; my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( - command => $cmd, - timeout => $self->{option_results}->{timeout}, - wait_exit => 1 - ); + command => $cmd, + timeout => $self->{option_results}->{timeout}, + wait_exit => 1 + ); + $stdout =~ s/\r//g; if ($lerror <= -1000) { $self->{output}->output_add(severity => 'UNKNOWN', diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm index 778561bbd..262dea445 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showenvironment.pm @@ -79,7 +79,7 @@ sub new { 'username:s' => { name => 'username' }, 'password:s' => { name => 'password' }, 'timeout:s' => { name => 'timeout', default => 30 }, - 'command-plink:s' => { name => 'command_plink', default => 'plink' }, + 'command-plink:s' => { name => 'command_plink' }, 'ssh' => { name => 'ssh' } }); @@ -106,6 +106,14 @@ sub check_options { if (!defined($self->{option_results}->{ssh})) { require hardware::server::sun::mgmt_cards::lib::telnet; } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_plink} + ); + + $self->{option_results}->{command} = 'plink' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); } sub ssh_command { diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm index 143032359..f75541a2f 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaults.pm @@ -31,14 +31,14 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "command-plink:s" => { name => 'command_plink', default => 'plink' }, - }); + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "command-plink:s" => { name => 'command_plink' } + }); + return $self; } @@ -58,6 +58,14 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify a password."); $self->{output}->option_exit(); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_plink} + ); + + $self->{option_results}->{command} = 'plink' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); } sub run { @@ -68,10 +76,11 @@ sub run { ###### my $cmd = "echo -e '" . $self->{option_results}->{username} . "\n" . $self->{option_results}->{password} . "\nshowfaults\nlogout\n' | " . $self->{option_results}->{command_plink} . ' -T -batch ' . $self->{option_results}->{hostname} . " 2>&1"; my ($lerror, $stdout, $exit_code) = centreon::plugins::misc::backtick( - command => $cmd, - timeout => $self->{option_results}->{timeout}, - wait_exit => 1 - ); + command => $cmd, + timeout => $self->{option_results}->{timeout}, + wait_exit => 1 + ); + $stdout =~ s/\r//g; if ($lerror <= -1000) { $self->{output}->output_add(severity => 'UNKNOWN', diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm index 3baec37ba..cfea52026 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showfaulty.pm @@ -38,7 +38,7 @@ sub new { 'password:s' => { name => 'password' }, 'timeout:s' => { name => 'timeout', default => 30 }, 'memory' => { name => 'memory' }, - 'command-plink:s' => { name => 'command_plink', default => 'plink' }, + 'command-plink:s' => { name => 'command_plink' } }); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); @@ -65,6 +65,14 @@ sub check_options { if (defined($self->{option_results}->{memory})) { $self->{statefile_cache}->check_options(%options); } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_plink} + ); + + $self->{option_results}->{command} = 'plink' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); } sub run { diff --git a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm index 478499145..3db489a3b 100644 --- a/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm +++ b/centreon-plugins/hardware/server/sun/mgmt_cards/mode/showstatus.pm @@ -39,16 +39,16 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "username:s" => { name => 'username' }, - "password:s" => { name => 'password' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "command-plink:s" => { name => 'command_plink', default => 'plink' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - "exclude:s@" => { name => 'exclude' }, - }); + $options{options}->add_options(arguments => { + "hostname:s" => { name => 'hostname' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "command-plink:s" => { name => 'command_plink' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + "exclude:s@" => { name => 'exclude' } + }); + return $self; } @@ -82,6 +82,14 @@ sub check_options { } push @{$self->{overload_th}}, {filter => $filter, status => $status}; } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command_plink} + ); + + $self->{option_results}->{command} = 'plink' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); } sub get_severity { @@ -109,8 +117,12 @@ sub check_exclude { foreach (@{$self->{option_results}->{exclude}}) { if ($options{value} =~ /$_/i) { - $self->{output}->output_add(long_msg => sprintf("Skip Component '%s'", - $options{value})); + $self->{output}->output_add( + long_msg => sprintf( + "Skip Component '%s'", + $options{value} + ) + ); return 1; } } @@ -134,29 +146,42 @@ sub check_tree { $long_instance = $stack[$#stack]->{long_instance} . '>' . $unit_number; $long_status = $stack[$#stack]->{long_status} . ' > ' . $unit_number . ' Status:' . $status; if ($indent > $stack[$#stack]->{indent}) { - push @stack, { indent => $indent, - long_instance => $stack[$#stack]->{long_instance} . '>' . $unit_number, - long_status => $stack[$#stack]->{long_status} . ' > ' . $unit_number . ' Status:' . $status }; + push @stack, { + indent => $indent, + long_instance => $stack[$#stack]->{long_instance} . '>' . $unit_number, + long_status => $stack[$#stack]->{long_status} . ' > ' . $unit_number . ' Status:' . $status + }; } next if ($self->check_exclude(value => $long_instance)); my $exit = $self->get_severity(value => $status); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Component '%s' status is '%s'", - $unit_number, $status)); + $self->{output}->output_add( + severity => $exit, + short_msg => sprintf( + "Component '%s' status is '%s'", + $unit_number, $status + ) + ); } - $self->{output}->output_add(long_msg => sprintf("Component '%s' status is '%s' [%s] [%s]", - $unit_number, $status, $long_instance, $long_status)); + $self->{output}->output_add( + long_msg => sprintf( + "Component '%s' status is '%s' [%s] [%s]", + $unit_number, $status, $long_instance, $long_status + ) + ); $total_components++; } - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok.", - $total_components) - ); + $self->{output}->output_add( + severity => 'OK', + short_msg => sprintf( + "All %s components are ok.", + $total_components + ) + ); } sub run { @@ -167,31 +192,38 @@ sub run { # Command execution ###### ($lerror, $self->{stdout}, $exit_code) = centreon::plugins::misc::backtick( - command => $self->{option_results}->{command_plink}, - timeout => $self->{option_results}->{timeout}, - arguments => ['-batch', '-l', $self->{option_results}->{username}, - '-pw', $self->{option_results}->{password}, - $self->{option_results}->{hostname}, 'showhardconf'], - wait_exit => 1, - redirect_stderr => 1 - ); + command => $self->{option_results}->{command_plink}, + timeout => $self->{option_results}->{timeout}, + arguments => [ + '-batch', '-l', $self->{option_results}->{username}, + '-pw', $self->{option_results}->{password}, + $self->{option_results}->{hostname}, 'showhardconf' + ], + wait_exit => 1, + redirect_stderr => 1 + ); + $self->{stdout} =~ s/\r//g; if ($lerror <= -1000) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => $self->{stdout}); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => $self->{stdout} + ); $self->{output}->display(); $self->{output}->exit(); } if ($exit_code != 0) { $self->{stdout} =~ s/\n/ - /g; - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command error: $self->{stdout}"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Command error: $self->{stdout}" + ); $self->{output}->display(); $self->{output}->exit(); } - + $self->check_tree(); - + $self->{output}->display(); $self->{output}->exit(); } diff --git a/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm b/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm index b7981e6b2..283cb4dd7 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/mode/boards.pm @@ -31,24 +31,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote:s" => { 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-pasv" => { name => 'sudo_pasv' }, - "command-pasv:s" => { name => 'command_pasv', default => 'showfailover' }, - "command-path-pasv:s" => { name => 'command_path_pasv', default => '/opt/SUNWSMS/bin' }, - "command-options-pasv:s" => { name => 'command_options_pasv', default => '-r 2>&1' }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'showboards' }, - "command-path:s" => { name => 'command_path', default => '/opt/SUNWSMS/bin' }, - "command-options:s" => { name => 'command_options', default => '2>&1' }, - "show-output:s" => { name => 'show_output' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } @@ -59,36 +43,40 @@ sub check_options { sub run { my ($self, %options) = @_; - - my ($stdout, $exit_code) = centreon::plugins::misc::execute(label => 'pasv', output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo_pasv}, - command => $self->{option_results}->{command_pasv}, - command_path => $self->{option_results}->{command_path_pasv}, - command_options => $self->{option_results}->{command_options_pasv}); + + my ($stdout) = $options{custom}->execute_command( + command => 'showfailover', + command_options => '-r 2>&1', + command_path => '/opt/SUNWSMS/bin' + ); if ($stdout =~ /SPARE/i) { - $self->{output}->output_add(severity => 'OK', - short_msg => "System Controller is in spare mode."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "System Controller is in spare mode." + ); $self->{output}->display(); $self->{output}->exit(); } elsif ($stdout !~ /MAIN/i) { $self->{output}->output_add(long_msg => $stdout); - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command problems (see additional info)."); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Command problems (see additional info)." + ); $self->{output}->display(); $self->{output}->exit(); } - $stdout = centreon::plugins::misc::execute(label => 'showboards', 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}); + ($stdout) = $options{custom}->execute_command( + command => 'showboards', + command_options => '2>&1', + command_path => '/opt/SUNWSMS/bin' + ); - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems detected."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems detected." + ); if ($stdout =~ /^Location(.*)/ims) { #Location Pwr Type of Board Board Status Test Status Domain #-------- --- ------------- ------------ ----------- ------ @@ -105,8 +93,10 @@ sub run { my ($location, $pwr, $type_board, $board_status, $test_status, $domain) = ($1, $2, $3, $4, $5, $6); if ($test_status =~ /Failed|Degraded/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Error on board '$location' ($type_board) with test status '$test_status'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Error on board '$location' ($type_board) with test status '$test_status'" + ); } } } @@ -125,68 +115,6 @@ Check Sun 'sfxxk' boards. =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-pasv> - -Use 'sudo' to execute the command pasv. - -=item B<--command-pasv> - -Command to know if system controller is 'active' (Default: 'showfailover'). - -=item B<--command-path-pasv> - -Command pasv path (Default: '/opt/SUNWSMS/bin'). - -=item B<--command-options-pasv> - -Command pasv options (Default: '-r 2>&1'). - -=item B<--sudo> - -Use 'sudo' to execute the command. - -=item B<--command> - -Command to get information (Default: 'showboards'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/opt/SUNWSMS/bin'). - -=item B<--command-options> - -Command options (Default: '2>&1'). - -=item B<--show-output> - -Display command output (for debugging or saving in a file). -A mode can have multiple (can specify the label for the command). - =back =cut diff --git a/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm b/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm index 0bfd5c221..a7e2b9597 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/mode/environment.pm @@ -31,24 +31,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "remote:s" => { 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-pasv" => { name => 'sudo_pasv' }, - "command-pasv:s" => { name => 'command_pasv', default => 'showfailover' }, - "command-path-pasv:s" => { name => 'command_path_pasv', default => '/opt/SUNWSMS/bin' }, - "command-options-pasv:s" => { name => 'command_options_pasv', default => '-r 2>&1' }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'showenvironment' }, - "command-path:s" => { name => 'command_path', default => '/opt/SUNWSMS/bin' }, - "command-options:s" => { name => 'command_options', default => '2>&1' }, - "show-output:s" => { name => 'show_output' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } @@ -59,36 +43,40 @@ sub check_options { sub run { my ($self, %options) = @_; - my $stdout; - - $stdout = centreon::plugins::misc::execute(label => 'pasv', output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo_pasv}, - command => $self->{option_results}->{command_pasv}, - command_path => $self->{option_results}->{command_path_pasv}, - command_options => $self->{option_results}->{command_options_pasv}); + + my ($stdout) = $options{custom}->execute_command( + command => 'showfailover', + command_options => '-r 2>&1', + command_path => '/opt/SUNWSMS/bin' + ); + if ($stdout =~ /SPARE/i) { - $self->{output}->output_add(severity => 'OK', - short_msg => "System Controller is in spare mode."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "System Controller is in spare mode." + ); $self->{output}->display(); $self->{output}->exit(); } elsif ($stdout !~ /MAIN/i) { $self->{output}->output_add(long_msg => $stdout); - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command problems (see additional info)."); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Command problems (see additional info)." + ); $self->{output}->display(); $self->{output}->exit(); } - $stdout = centreon::plugins::misc::execute(label => 'showenvironment', 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}); + ($stdout) = $options{custom}->execute_command( + command => 'showenvironment', + command_options => '2>&1', + command_path => '/opt/SUNWSMS/bin' + ); - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems detected."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems detected." + ); if ($stdout =~ /^LOCATION(.*?)\n\n/ims) { #LOCATION SENSOR VALUE UNIT AGE STATUS #---------- ------------ ----- ---- ------ ------ @@ -108,8 +96,10 @@ sub run { my $sensor = $2; $sensor = centreon::plugins::misc::trim($sensor); - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Sensor '$location/$sensor' status is '" . $sensor_status . "'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Sensor '$location/$sensor' status is '" . $sensor_status . "'" + ); } } } @@ -131,8 +121,10 @@ sub run { my $fanspeed = $3; if ($fanspeed !~ /^NORMAL$/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "FanTray '$fantray' speed status is '" . $fanspeed . "'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "FanTray '$fantray' speed status is '" . $fanspeed . "'" + ); } my $fan_num = 0; @@ -143,8 +135,10 @@ sub run { next if ($status eq ''); if ($status !~ /^OK$/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "FanTray '$fantray' fan '$fan_num' status is '" . $status . "'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "FanTray '$fantray' fan '$fan_num' status is '" . $status . "'" + ); } $fan_num++; } @@ -172,8 +166,10 @@ sub run { $errors .= ' [DC1=' . centreon::plugins::misc::trim($fan0) . ']' if ($fan0 !~ /OK/i); $errors .= ' [DC1=' . centreon::plugins::misc::trim($fan1) . ']' if ($fan1 !~ /OK/i); if ($errors ne '') { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Some errors on power '$power_name':" . $errors); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Some errors on power '$power_name':" . $errors + ); } } } @@ -208,68 +204,6 @@ Check Sun 'sfxxk' environment. =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-pasv> - -Use 'sudo' to execute the command pasv. - -=item B<--command-pasv> - -Command to know if system controller is 'active' (Default: 'showfailover'). - -=item B<--command-path-pasv> - -Command pasv path (Default: '/opt/SUNWSMS/bin'). - -=item B<--command-options-pasv> - -Command pasv options (Default: '-r 2>&1'). - -=item B<--sudo> - -Use 'sudo' to execute the command. - -=item B<--command> - -Command to get information (Default: 'showenvironment'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/opt/SUNWSMS/bin'). - -=item B<--command-options> - -Command options (Default: '2>&1'). - -=item B<--show-output> - -Display command output (for debugging or saving in a file). -A mode can have multiple (can specify the label for the command). - =back =cut diff --git a/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm b/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm index 1f5cbeb09..9de20c339 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/mode/failover.pm @@ -31,23 +31,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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-pasv" => { name => 'sudo_pasv' }, - "command-pasv:s" => { name => 'command_pasv', default => 'showfailover' }, - "command-path-pasv:s" => { name => 'command_path_pasv', default => '/opt/SUNWSMS/bin' }, - "command-options-pasv:s" => { name => 'command_options_pasv', default => '-r 2>&1' }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'showfailover' }, - "command-path:s" => { name => 'command_path', default => '/opt/SUNWSMS/bin' }, - "command-options:s" => { name => 'command_options', default => '2>&1' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } @@ -58,44 +43,50 @@ sub check_options { sub run { my ($self, %options) = @_; - my $stdout; - - $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo_pasv}, - command => $self->{option_results}->{command_pasv}, - command_path => $self->{option_results}->{command_path_pasv}, - command_options => $self->{option_results}->{command_options_pasv}); + + my ($stdout) = $options{custom}->execute_command( + command => 'showfailover', + command_options => '-r 2>&1', + command_path => '/opt/SUNWSMS/bin' + ); + if ($stdout =~ /SPARE/i) { - $self->{output}->output_add(severity => 'OK', - short_msg => "System Controller is in spare mode."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "System Controller is in spare mode." + ); $self->{output}->display(); $self->{output}->exit(); } elsif ($stdout !~ /MAIN/i) { $self->{output}->output_add(long_msg => $stdout); - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Command problems (see additional info)."); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Command problems (see additional info)." + ); $self->{output}->display(); $self->{output}->exit(); } - $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}); - + ($stdout) = $options{custom}->execute_command( + command => 'showfailover', + command_options => '2>&1', + command_path => '/opt/SUNWSMS/bin' + ); + # 'ACTIVITING' is like 'ACTIVE' for us. - $self->{output}->output_add(severity => 'OK', - short_msg => "System Controller Failover Status is ACTIVE."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "System Controller Failover Status is ACTIVE." + ); if ($stdout =~ /^SC Failover Status:(.*?)($|\n)/ims) { my $failover_status = $1; $failover_status = centreon::plugins::misc::trim($failover_status); # Can be FAILED or DISABLED if ($failover_status !~ /ACTIVE/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "System Controller Failover Status is " . $failover_status . "."); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "System Controller Failover Status is " . $failover_status . "." + ); } } @@ -113,63 +104,6 @@ Check Sun 'sfxxk' system controller failover status. =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-pasv> - -Use 'sudo' to execute the command pasv. - -=item B<--command-pasv> - -Command to know if system controller is 'active' (Default: 'showfailover'). - -=item B<--command-path-pasv> - -Command pasv path (Default: '/opt/SUNWSMS/bin'). - -=item B<--command-options-pasv> - -Command pasv options (Default: '-r 2>&1'). - -=item B<--sudo> - -Use 'sudo' to execute the command. - -=item B<--command> - -Command to get information (Default: 'showfailover'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/opt/SUNWSMS/bin'). - -=item B<--command-options> - -Command options (Default: '2>&1'). - =back =cut diff --git a/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm b/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm index e82707836..c91598f4b 100644 --- a/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm +++ b/centreon-plugins/hardware/server/sun/sfxxk/plugin.pm @@ -22,19 +22,20 @@ package hardware::server::sun::sfxxk::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - %{$self->{modes}} = ( + $self->{modes} = { 'boards' => 'hardware::server::sun::sfxxk::mode::boards', 'environment' => 'hardware::server::sun::sfxxk::mode::environment', - 'failover' => 'hardware::server::sun::sfxxk::mode::failover', - ); + 'failover' => 'hardware::server::sun::sfxxk::mode::failover' + }; + + $self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli'; return $self; } diff --git a/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm b/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm index 5143f8368..1c7f0670a 100644 --- a/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm +++ b/centreon-plugins/network/cisco/standard/ssh/custom/custom.pm @@ -20,89 +20,24 @@ package network::cisco::standard::ssh::custom::custom; +use base qw(centreon::plugins::script_custom::cli); + use strict; use warnings; -use centreon::plugins::misc; -sub new { - my ($class, %options) = @_; - my $self = {}; - bless $self, $class; - - if (!defined($options{output})) { - print "Class Custom: Need to specify 'output' argument.\n"; - exit 3; - } - if (!defined($options{options})) { - $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); - $options{output}->option_exit(); - } - - if (!defined($options{noptions})) { - $options{options}->add_options(arguments => { - 'hostname:s' => { name => 'hostname' }, - 'ssh-option:s@' => { name => 'ssh_option' }, - 'ssh-path:s' => { name => 'ssh_path' }, - 'ssh-command:s' => { name => 'ssh_command', default => 'ssh' }, - 'timeout:s' => { name => 'timeout', default => 45 }, - 'command:s' => { name => 'command' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options' } - }); - } - $options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1); - - $self->{output} = $options{output}; - - return $self; -} - -sub set_options { - my ($self, %options) = @_; - - $self->{option_results} = $options{option_results}; -} - -sub set_defaults {} - -sub check_options { - my ($self, %options) = @_; - - $self->{option_results}->{remote} = 1; - if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') { - $self->{option_results}->{remote} = undef; - } elsif (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to set hostname option."); - $self->{output}->option_exit(); - } - - return 0; -} - -############## -# Specific methods -############## sub execute_command { my ($self, %options) = @_; - - $self->{ssh_commands} = ''; + my $append = ''; foreach (@{$options{commands}}) { - $self->{ssh_commands} .= $append . " $_"; + $options{command} .= $append . " $_"; $append = "\n"; } - my ($content) = centreon::plugins::misc::execute( - ssh_pipe => 1, - output => $self->{output}, - options => $self->{option_results}, - command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands}, - command_path => $self->{option_results}->{command_path}, - command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef - ); + my ($stdout) = $self->SUPER::execute_command(%options, ssh_pipe => 1,); + $stdout =~ s/\r//mg; - $content =~ s/\r//mg; - return $content; + return $stdout; } 1; @@ -117,7 +52,7 @@ ssh my ssh -=head1 SSH OPTIONS +=head1 CLI OPTIONS =over 8 @@ -125,21 +60,9 @@ my ssh Hostname to query. -=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: 45). +Timeout in seconds for the command (Default: 45). Default value can be override by the mode. =item B<--command> @@ -153,6 +76,10 @@ Command path. Command options. +=item B<--sudo> + +sudo command. + =back =head1 DESCRIPTION diff --git a/centreon-plugins/network/cisco/standard/ssh/plugin.pm b/centreon-plugins/network/cisco/standard/ssh/plugin.pm index 7ef9dc0b5..4b5f4ac41 100644 --- a/centreon-plugins/network/cisco/standard/ssh/plugin.pm +++ b/centreon-plugins/network/cisco/standard/ssh/plugin.pm @@ -29,13 +29,12 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '1.0'; - %{$self->{modes}} = ( - 'cpu' => 'network::cisco::standard::ssh::mode::cpu', - 'voice-dial-peer' => 'network::cisco::standard::ssh::mode::voicedialpeer', - ); + $self->{modes} = { + 'cpu' => 'network::cisco::standard::ssh::mode::cpu', + 'voice-dial-peer' => 'network::cisco::standard::ssh::mode::voicedialpeer' + }; - $self->{custom_modes}{ssh} = 'network::cisco::standard::ssh::custom::custom'; + $self->{custom_modes}->{ssh} = 'network::cisco::standard::ssh::custom::custom'; return $self; } diff --git a/centreon-plugins/network/paloalto/ssh/custom/cli.pm b/centreon-plugins/network/paloalto/ssh/custom/cli.pm index 94108d402..d24272ba8 100644 --- a/centreon-plugins/network/paloalto/ssh/custom/cli.pm +++ b/centreon-plugins/network/paloalto/ssh/custom/cli.pm @@ -72,6 +72,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/network/stormshield/local/mode/qosusage.pm b/centreon-plugins/network/stormshield/local/mode/qosusage.pm index 9502e6e28..cb8c33e1b 100644 --- a/centreon-plugins/network/stormshield/local/mode/qosusage.pm +++ b/centreon-plugins/network/stormshield/local/mode/qosusage.pm @@ -25,53 +25,6 @@ use base qw(centreon::plugins::templates::counter); use strict; use warnings; -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'qos', type => 1, cb_prefix_output => 'prefix_qos_output', message_multiple => 'All QoS are ok', skipped_code => { -10 => 1 } }, - ]; - - $self->{maps_counters}->{qos} = [ - { label => 'in', set => { - key_values => [ { name => 'in' }, { name => 'display' }, { name => 'speed_in' } ], - closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, - closure_custom_output => $self->can('custom_qos_output'), - closure_custom_perfdata => $self->can('custom_qos_perfdata'), - closure_custom_threshold_check => $self->can('custom_qos_threshold'), - } - }, - { label => 'in-peak', set => { - key_values => [ { name => 'in_peak' }, { name => 'display' } ], - output_template => 'In Peak : %s %s/s', - output_change_bytes => 2, - perfdatas => [ - { label => 'traffic_in_peak', value => 'in_peak', template => '%.2f', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - { label => 'out', set => { - key_values => [ { name => 'out' }, { name => 'display' }, { name => 'speed_out' } ], - closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, - closure_custom_output => $self->can('custom_qos_output'), - closure_custom_perfdata => $self->can('custom_qos_perfdata'), - closure_custom_threshold_check => $self->can('custom_qos_threshold'), - } - }, - { label => 'out-peak', set => { - key_values => [ { name => 'out_peak' }, { name => 'display' } ], - output_template => 'Out Peak : %s %s/s', - output_change_bytes => 2, - perfdatas => [ - { label => 'traffic_out_peak', value => 'out_peak', template => '%.2f', - unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], - } - }, - ]; -} - sub custom_qos_perfdata { my ($self, %options) = @_; @@ -138,6 +91,59 @@ sub custom_qos_calc { return 0; } +sub prefix_qos_output { + my ($self, %options) = @_; + + return "QoS '" . $options{instance_value}->{display} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'qos', type => 1, cb_prefix_output => 'prefix_qos_output', message_multiple => 'All QoS are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{qos} = [ + { label => 'in', set => { + key_values => [ { name => 'in' }, { name => 'display' }, { name => 'speed_in' } ], + closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_qos_output'), + closure_custom_perfdata => $self->can('custom_qos_perfdata'), + closure_custom_threshold_check => $self->can('custom_qos_threshold') + } + }, + { label => 'in-peak', set => { + key_values => [ { name => 'in_peak' }, { name => 'display' } ], + output_template => 'In Peak : %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { label => 'traffic_in_peak', template => '%.2f', + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] + } + }, + { label => 'out', set => { + key_values => [ { name => 'out' }, { name => 'display' }, { name => 'speed_out' } ], + closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_qos_output'), + closure_custom_perfdata => $self->can('custom_qos_perfdata'), + closure_custom_threshold_check => $self->can('custom_qos_threshold') + } + }, + { label => 'out-peak', set => { + key_values => [ { name => 'out_peak' }, { name => 'display' } ], + output_template => 'Out Peak : %s %s/s', + output_change_bytes => 2, + perfdatas => [ + { label => 'traffic_out_peak', template => '%.2f', + unit => 'b/s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] + } + } + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -149,40 +155,12 @@ sub new { "speed-in:s" => { name => 'speed_in' }, "speed-out:s" => { name => 'speed_out' }, "units-traffic:s" => { name => 'units_traffic', default => '%' }, - "hostname:s" => { name => 'hostname' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'tail' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-1 /log/l_monitor' }, - "config-speed-file:s" => { name => 'config_speed_file' }, + "config-speed-file:s" => { name => 'config_speed_file' } }); return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { - $self->{option_results}->{remote} = 1; - } - $self->{hostname} = $self->{option_results}->{hostname}; - if (!defined($self->{hostname})) { - $self->{hostname} = 'me'; - } -} - -sub prefix_qos_output { - my ($self, %options) = @_; - - return "QoS '" . $options{instance_value}->{display} . "' "; -} - sub load_speed_config { my ($self, %options) = @_; @@ -215,14 +193,12 @@ sub load_speed_config { sub manage_selection { my ($self, %options) = @_; - + #id=firewall time="2017-01-31 16:56:36" fw="XXXX" tz=+0100 startime="2017-01-31 16:56:36" security=70 system=1 CPU=3,2,1 Pvm=0,0,0,0,0,0,0,0,0,0,0 Vlan96=VLAN-XXX-DMZ,15140,17768,21952,28280 Vlan76=dmz-xxx-xxx,769592,948320,591584,795856 - my $content = 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}); + my ($content) = $options{custom}->execute_command( + command => 'tail', + command_options => "-1 /log/l_monitor" + ); $self->load_speed_config(); $self->{qos} = {}; @@ -232,7 +208,7 @@ sub manage_selection { if ($content !~ /$pattern/) { $pattern = '(\S+?)=([^,]+?),(\d+),(\d+),(\d+),(\d+),\d+,\d+(?:\s|\Z)'; } - + while ($content =~ /$pattern/msg) { my ($vlan, $name, $in, $in_max, $out, $out_max) = ($1, $2, $3, $4, $5, $6); if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && @@ -245,15 +221,16 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $vlan . "': no matching filter.", debug => 1); next; } - + $self->{qos}->{$name} = { display => $name, in => $in, in_peak => $in_max, out => $out, out_peak => $out_max, speed_in => defined($self->{config_speeds}->{$name}->{speed_in}) ? $self->{config_speeds}->{$name}->{speed_in} : 0, - speed_out => defined($self->{config_speeds}->{$name}->{speed_out}) ? $self->{config_speeds}->{$name}->{speed_out} : 0}; + speed_out => defined($self->{config_speeds}->{$name}->{speed_out}) ? $self->{config_speeds}->{$name}->{speed_out} : 0 + }; } - + if (scalar(keys %{$self->{qos}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No QoS found."); $self->{output}->option_exit(); @@ -268,6 +245,8 @@ __END__ Check QoS usage. +Command used: 'tail -1 /log/l_monitor' + =over 8 =item B<--filter-name> @@ -278,43 +257,6 @@ Filter by QoS name (can be a regexp). Filter by vlan name (can be a regexp). -=item B<--hostname> - -Hostname to query. - -=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: 'tail'). -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: '-1 /log/l_monitor'). - =item B<--speed-in> Set interface speed for incoming traffic (in Mb). @@ -331,15 +273,9 @@ File with speed configurations. Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). -=item B<--warning-*> +=item B<--warning-*> B<--critical-*> -Threshold warning. -Can be: 'in', 'in-peak', 'out', 'out-peak'. - -=item B<--critical-*> - -Threshold critical. -Threshold warning. +Thresholds. Can be: 'in', 'in-peak', 'out', 'out-peak'. =back diff --git a/centreon-plugins/network/stormshield/local/plugin.pm b/centreon-plugins/network/stormshield/local/plugin.pm index 1e6fd14fe..88b4a142b 100644 --- a/centreon-plugins/network/stormshield/local/plugin.pm +++ b/centreon-plugins/network/stormshield/local/plugin.pm @@ -22,17 +22,18 @@ package network::stormshield::local::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'qos-usage' => 'network::stormshield::local::mode::qosusage', - ); + $self->{modes} = { + 'qos-usage' => 'network::stormshield::local::mode::qosusage' + }; + + $self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli'; return $self; } diff --git a/centreon-plugins/os/aix/local/custom/cli.pm b/centreon-plugins/os/aix/local/custom/cli.pm index 3d67b6800..dc3d92958 100644 --- a/centreon-plugins/os/aix/local/custom/cli.pm +++ b/centreon-plugins/os/aix/local/custom/cli.pm @@ -73,6 +73,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/os/linux/local/custom/cli.pm b/centreon-plugins/os/linux/local/custom/cli.pm index de0ae93b9..8abef126a 100644 --- a/centreon-plugins/os/linux/local/custom/cli.pm +++ b/centreon-plugins/os/linux/local/custom/cli.pm @@ -82,6 +82,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } @@ -98,6 +105,13 @@ sub get_identifier { sub execute_command { my ($self, %options) = @_; + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + my $timeout = $self->{timeout}; if (!defined($timeout)) { $timeout = defined($options{timeout}) ? $options{timeout} : 45; diff --git a/centreon-plugins/os/solaris/local/mode/analyzedisks.pm b/centreon-plugins/os/solaris/local/mode/analyzedisks.pm index 2d23ea46e..5f4175407 100644 --- a/centreon-plugins/os/solaris/local/mode/analyzedisks.pm +++ b/centreon-plugins/os/solaris/local/mode/analyzedisks.pm @@ -24,29 +24,15 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'format' }, - 'command-path:s' => { name => 'command_path', default => '/usr/sbin' }, - 'command-options:s' => { name => 'command_options', default => '2>&1 << EOF -0 -quit -EOF' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } }); return $self; @@ -69,18 +55,19 @@ sub check_options { sub run { 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} + my ($stdout) = $options{custom}->execute_command( + command => 'format', + command_options => '2>&1 << EOF +0 +quit +EOF', + command_path => '/usr/sbin' ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); - + my $num_errors = 0; my $disks_name = ''; foreach (split /\n/, $stdout) { @@ -90,14 +77,20 @@ sub run { } } - my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_errors, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($exit_code) = $self->{perfdata}->threshold_check( + value => $num_errors, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($num_errors > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Disks$disks_name are on errors.")); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Disks$disks_name are on errors.") + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on disks."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on disks." + ); } $self->{output}->display(); @@ -112,6 +105,11 @@ __END__ Check disk status (need 'format' command). +Command used: '/usr/sbin/format 2>&1 << EOF +0 +quit +EOF' + =over 8 =item B<--warning> @@ -122,50 +120,6 @@ Threshold warning. Threshold critical. -=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: 'format'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: '2>&1 << EOF -0 -quit -EOF'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/cpu.pm b/centreon-plugins/os/solaris/local/mode/cpu.pm index 5cc786604..90363cc80 100644 --- a/centreon-plugins/os/solaris/local/mode/cpu.pm +++ b/centreon-plugins/os/solaris/local/mode/cpu.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; use centreon::plugins::statefile; sub new { @@ -33,22 +32,11 @@ sub new { bless $self, $class; $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 => 'kstat' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-n sys 2>&1' }, - 'warning:s' => { name => 'warning' }, - 'critical:s' => { name => 'critical' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } }); $self->{statefile_cache} = centreon::plugins::statefile->new(%options); - $self->{hostname} = undef; return $self; } @@ -66,30 +54,25 @@ sub check_options { } $self->{statefile_cache}->check_options(%options); - $self->{hostname} = $self->{option_results}->{hostname}; - if (!defined($self->{hostname})) { - $self->{hostname} = 'me'; - } } sub run { 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} + my ($stdout) = $options{custom}->execute_command( + command => 'kstat', + command_options => '-n sys 2>&1' ); - $self->{statefile_cache}->read(statefile => 'cache_solaris_local_' . $self->{hostname} . '_' . $self->{mode}); + + $self->{statefile_cache}->read(statefile => 'cache_solaris_local_' . $options{custom}->get_identifier() . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_cache}->get(name => 'last_timestamp'); my $datas = {}; $datas->{last_timestamp} = time(); - - $self->{output}->output_add(severity => 'OK', - short_msg => "CPUs usages are ok."); + + $self->{output}->output_add( + severity => 'OK', + short_msg => "CPUs usages are ok." + ); my @output_cpu_instance = split("instance", $stdout); shift @output_cpu_instance; foreach (@output_cpu_instance) { @@ -109,7 +92,7 @@ sub run { if (!defined($old_cpu_system) || !defined($old_cpu_idle) || !defined($old_cpu_user)) { next; } - + if ($datas->{'cpu_idle_' . $cpu_number} < $old_cpu_idle) { # We set 0. Has reboot. $old_cpu_user = 0; @@ -121,14 +104,18 @@ sub run { my $idle_elapsed = $datas->{'cpu_idle_' . $cpu_number} - $old_cpu_idle; my $cpu_ratio_usetime = 100 * $idle_elapsed / $total_elapsed; $cpu_ratio_usetime = 100 - $cpu_ratio_usetime; - - my $exit_code = $self->{perfdata}->threshold_check(value => $cpu_ratio_usetime, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - + + my $exit_code = $self->{perfdata}->threshold_check( + value => $cpu_ratio_usetime, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); + $self->{output}->output_add(long_msg => sprintf("CPU %d %.2f%%", $cpu_number, $cpu_ratio_usetime)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("CPU %d %.2f%%", $cpu_number, $cpu_ratio_usetime)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("CPU %d %.2f%%", $cpu_number, $cpu_ratio_usetime) + ); } $self->{output}->perfdata_add( label => 'cpu_' . $cpu_number, unit => '%', @@ -141,8 +128,10 @@ sub run { $self->{statefile_cache}->write(data => $datas); if (!defined($old_timestamp)) { - $self->{output}->output_add(severity => 'OK', - short_msg => "Buffer creation..."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Buffer creation..." + ); } $self->{output}->display(); @@ -155,7 +144,9 @@ __END__ =head1 MODE -Check system CPUs (need 'kstat' command). +Check system CPUs + +Command used: 'kstat -n sys 2>&1' =over 8 @@ -167,47 +158,6 @@ Threshold warning in percent. Threshold critical in percent. -=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: 'kstat'). -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: '-n sys 2>&1'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/fcconnected.pm b/centreon-plugins/os/solaris/local/mode/fcconnected.pm index 8082da934..6380e724e 100644 --- a/centreon-plugins/os/solaris/local/mode/fcconnected.pm +++ b/centreon-plugins/os/solaris/local/mode/fcconnected.pm @@ -24,28 +24,17 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'luxadm' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '-e port 2>&1' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } @@ -54,27 +43,28 @@ 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) = @_; - 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}); + my ($stdout) = $options{custom}->execute_command( + command => 'luxadm', + command_options => '-e port 2>&1', + command_path => '/usr/sbin' + ); - $self->{output}->output_add(severity => 'OK', - short_msg => "Fc connections are ok."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Fc connections are ok." + ); my $num_connected = 0; foreach (split /\n/, $stdout) { $self->{output}->output_add(long_msg => $_); @@ -82,12 +72,16 @@ sub run { $num_connected++; } } - - my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_connected, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + my ($exit_code) = $self->{perfdata}->threshold_check( + value => $num_connected, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Some cards are not connected (see additionnal info for more details)")); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Some cards are not connected (see additionnal info for more details)") + ); } $self->{output}->display(); @@ -102,6 +96,8 @@ __END__ Check number of fiber channel connected (need sun/oracle driver and not Emulex/Qlogic). +Command used: '/usr/sbin/luxadm -e port 2>&1' + =over 8 =item B<--warning> @@ -112,47 +108,6 @@ Threshold warning. Threshold critical. -=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: 'luxadm'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: '-e port 2>&1'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/fmadm.pm b/centreon-plugins/os/solaris/local/mode/fmadm.pm index ce3036046..5ff704926 100644 --- a/centreon-plugins/os/solaris/local/mode/fmadm.pm +++ b/centreon-plugins/os/solaris/local/mode/fmadm.pm @@ -24,28 +24,17 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'fmadm' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => 'faulty -r 2>&1' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } @@ -54,40 +43,46 @@ 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) = @_; - 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}); + my ($stdout) = $options{custom}->execute_command( + command => 'fmadm', + command_options => 'faulty -r 2>&1', + command_path => '/usr/sbin' + ); + my $num_errors = 0; foreach (split /\n/, $stdout) { $self->{output}->output_add(long_msg => $_); $num_errors++; } - my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_errors, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($exit_code) = $self->{perfdata}->threshold_check( + value => $num_errors, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($num_errors > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("The Fault Manager reports some hardware problems (see additionnal info for more details)")); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("The Fault Manager reports some hardware problems (see additionnal info for more details)") + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "The Fault Manager does not report any hardware problem."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "The Fault Manager does not report any hardware problem." + ); } - + $self->{output}->display(); $self->{output}->exit(); } @@ -98,7 +93,9 @@ __END__ =head1 MODE -Check Hardware Faults (need at least Solaris 10 and 'fmadm' command). +Check Hardware Faults (need at least Solaris 10) + +Command used: '/usr/sbin/fmadm faulty -r 2>&1' =over 8 @@ -110,47 +107,6 @@ Threshold warning. Threshold critical. -=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: 'fmadm'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: 'faulty -r 2>&1'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/hwraidctl.pm b/centreon-plugins/os/solaris/local/mode/hwraidctl.pm index 9c0610ef1..38779937b 100644 --- a/centreon-plugins/os/solaris/local/mode/hwraidctl.pm +++ b/centreon-plugins/os/solaris/local/mode/hwraidctl.pm @@ -24,28 +24,17 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - - $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 => 'raidctl' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '-S 2>&1' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } @@ -54,24 +43,24 @@ 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) = @_; - 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}); + my ($stdout) = $options{custom}->execute_command( + command => 'raidctl', + command_options => '-S 2>&1', + command_path => '/usr/sbin' + ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); @@ -88,11 +77,11 @@ sub run { #0.2.0 GOOD #0.3.0 GOOD #4 "LSI_1030" - + # For Disk if (/^\s*(\S+)\s+(FAILED)$/i ) { my $disk = $1; - + $disks_errors++; $disks .= ' [' . $disk . '/FAILED' . ']'; } elsif (/^\s*(\S+).*?(DEGRADED|FAILED)$/i) { @@ -101,26 +90,38 @@ sub run { } } - my ($exit_code) = $self->{perfdata}->threshold_check(value => $volumes_errors, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($exit_code) = $self->{perfdata}->threshold_check( + value => $volumes_errors, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($volumes_errors > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Some volumes problems:" . $volumes)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Some volumes problems:" . $volumes) + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on volumes"); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on volumes" + ); } - - ($exit_code) = $self->{perfdata}->threshold_check(value => $disks_errors, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + ($exit_code) = $self->{perfdata}->threshold_check( + value => $disks_errors, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($disks_errors > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Some disks problems:" . $disks)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Some disks problems:" . $disks) + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on disks"); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on disks" + ); } - + $self->{output}->display(); $self->{output}->exit(); } @@ -131,7 +132,9 @@ __END__ =head1 MODE -Check Hardware Raid Status (use 'raidctl' command). +Check hardware raid status + +Command used: '/usr/sbin/raidctl -S 2>&1' =over 8 @@ -143,47 +146,6 @@ Threshold warning. Threshold critical. -=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: 'raidctl'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: '-S 2>&1'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm b/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm index 26d227dd0..0495f9238 100644 --- a/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm +++ b/centreon-plugins/os/solaris/local/mode/hwsas2ircu.pm @@ -31,23 +31,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 }, - "sudo1" => { name => 'sudo1' }, - "command1:s" => { name => 'command1', default => 'metastat' }, - "command1-path:s" => { name => 'command1_path', default => '/usr/sbin' }, - "command1-options:s" => { name => 'command1_options', default => '-c 2>&1' }, - "sudo2" => { name => 'sudo2' }, - "command2:s" => { name => 'command2', default => 'metadb' }, - "command2-path:s" => { name => 'command2_path', default => '/usr/sbin' }, - "command2-options:s" => { name => 'command2_options', default => '2>&1' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } @@ -59,14 +44,16 @@ sub check_options { sub run { my ($self, %options) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo1}, - command => $self->{option_results}->{command1}, - command_path => $self->{option_results}->{command1_path}, - command_options => $self->{option_results}->{command1_options}); - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on volumes"); + my ($stdout) = $options{custom}->execute_command( + command => 'sas2ircu', + command_options => 'LIST 2>&1', + command_path => '/usr/bin' + ); + + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on volumes" + ); while (($stdout =~ /^\s*Index.*?\n.*?\n\s+(\d+)\s+/imsg)) { # Index Type ID ID Pci Address Ven ID Dev ID @@ -79,12 +66,12 @@ sub run { # 1 SAS2008 1000h 72h 00h:0bh:00h:00h 1000h 0072h #SAS2IRCU: Utility Completed Successfully. my $index = $1; - my $stdout2 = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo2}, - command => $self->{option_results}->{command2}, - command_path => $self->{option_results}->{command2_path}, - command_options => sprintf($self->{option_results}->{command2_options}, $index)); + + my ($stdout2) = $options{custom}->execute_command( + command => 'sas2ircu', + command_options => sprintf('%s DISPLAY 2>&1', $index), + command_path => '/usr/bin' + ); #IR Volume information #------------------------------------------------------------------------ @@ -99,33 +86,35 @@ sub run { # PHY[1] Enclosure#/Slot# : 1:3 #------------------------------------------------------------------------ #Physical device information - + if ($stdout2 =~ /^IR Volume information(.*)Physical device information/ims) { my @content = split(/\n/, $1); shift @content; my $volume_name = ''; foreach my $line (@content) { - + next if ($line =~ /^---/); - + if ($line =~ /Volume Name\s+:\s+(.*)/i) { $volume_name = $1; $volume_name = centreon::plugins::misc::trim($volume_name); next; } - + if ($line =~ /Status of volume\s+:\s+(.*)(\n|\()/i) { my $status_volume = $1; $status_volume = centreon::plugins::misc::trim($status_volume); if ($status_volume !~ /Okay/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Volume 'volume_name' status is '$status_volume'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Volume 'volume_name' status is '$status_volume'" + ); } } } } } - + $self->{output}->display(); $self->{output}->exit(); } @@ -136,69 +125,12 @@ __END__ =head1 MODE -Check Hardware Raid Status (use 'sas2ircu' command). +Check hardware raid status (use 'sas2ircu' command). + +Command used: '/usr/bin/sas2ircu LIST 2>&1' and '/usr/bin/sas2ircu %(index) DISPLAY 2>&1' =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<--sudo1> - -Use 'sudo' to execute the command. - -=item B<--command1> - -Command to get information (Default: 'sas2ircu'). -Can be changed if you have output in a file. - -=item B<--command1-path> - -Command path (Default: '/usr/bin'). - -=item B<--command1-options> - -Command options (Default: 'LIST 2>&1'). - -=item B<--sudo2> - -Use 'sudo' to execute the command. - -=item B<--command2> - -Command to get information (Default: 'sas2ircu'). -Can be changed if you have output in a file. - -=item B<--command2-path> - -Command path (Default: '/usr/bin'). - -=item B<--command2-options> - -Command options (Default: '%s DISPLAY 2>&1'). -!!! Modify it if you know what you do ;) !!! - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/lomv120.pm b/centreon-plugins/os/solaris/local/mode/lomv120.pm index 7191c5b24..a8d23fc3a 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv120.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv120.pm @@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; sub set_system { my ($self, %options) = @_; @@ -46,13 +45,10 @@ sub set_system { sub command_execute { my ($self, %options) = @_; - ($self->{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->{stdout}) = $options{custom}->execute_command( + command => 'lom', + command_options => '-fpv 2>&1', + command_path => '/usr/sbin', no_quit => 1 ); } @@ -62,18 +58,7 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); bless $self, $class; - $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 => 'lom' }, - 'command-path:s' => { name => 'command_path', default => '/usr/sbin' }, - 'command-options:s' => { name => 'command_options', default => '-fpv 2>&1'} - }); + $options{options}->add_options(arguments => {}); return $self; } @@ -84,51 +69,12 @@ __END__ =head1 MODE -Check Hardware Status for 'v120' (use 'lom' command). +Check hardware status for 'v120'. + +Command used: '/usr/sbin/lom -fpv 2>&1' =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: 'lom'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: '-fpv 2>&1'). - =item B<--component> Which component to check (Default: '.*'). diff --git a/centreon-plugins/os/solaris/local/mode/lomv1280.pm b/centreon-plugins/os/solaris/local/mode/lomv1280.pm index c9f67baa7..359967111 100644 --- a/centreon-plugins/os/solaris/local/mode/lomv1280.pm +++ b/centreon-plugins/os/solaris/local/mode/lomv1280.pm @@ -31,19 +31,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'lom' }, - "command-path:s" => { name => 'command_path', default => '/usr/sbin' }, - "command-options:s" => { name => 'command_options', default => '-fpv 2>&1' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } @@ -55,18 +44,20 @@ sub check_options { sub run { 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}); + my ($stdout) = $options{custom}->execute_command( + command => 'lom', + command_options => '-fpv 2>&1', + command_path => '/usr/sbin' + ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); - - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems detected."); + + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems detected." + ); if ($stdout =~ /^Fans:(.*?):/ims) { #Fans: @@ -80,12 +71,14 @@ sub run { my ($fan_name, $status) = ($2, $4); if ($status !~ /OK/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Fan '$fan_name' status is '$status'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Fan '$fan_name' status is '$status'" + ); } } } - + if ($stdout =~ /^PSUs:(.*?):/ims) { #PSUs: # PS0 OK @@ -98,8 +91,10 @@ sub run { my ($psu_num, $status) = ($1, $2); if ($status !~ /OK/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Psu '$psu_num' status is '$status'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Psu '$psu_num' status is '$status'" + ); } } } @@ -123,8 +118,10 @@ sub run { my $status = $1; my $name = join(' ', @fields); if ($status !~ /OK/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Supply voltage '$name' status is '$status'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Supply voltage '$name' status is '$status'" + ); } } } @@ -150,8 +147,10 @@ sub run { my $status = $1; my $name = join(' ', @fields); if ($status !~ /OK/i) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "System '$name' flag status is '$status'"); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "System '$name' flag status is '$status'" + ); } } } @@ -166,51 +165,12 @@ __END__ =head1 MODE -Check Hardware Status for 'v1280' (use 'lom' command). +Check hardware status for 'v1280'. + +Command used '/usr/sbin/lom -fpv 2>&1' =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: 'lom'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command-options> - -Command options (Default: '-fpv 2>&1'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/prtdiag.pm b/centreon-plugins/os/solaris/local/mode/prtdiag.pm index 8344ef33a..e3f69b4cc 100644 --- a/centreon-plugins/os/solaris/local/mode/prtdiag.pm +++ b/centreon-plugins/os/solaris/local/mode/prtdiag.pm @@ -34,21 +34,11 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 => 'prtdiag' }, - "command-path:s" => { name => 'command_path', default => '/usr/platform/`/sbin/uname -i`/sbin' }, - "command-options:s" => { name => 'command_options', default => '-v 2>&1' }, - "config-file:s" => { name => 'config_file' }, - "exclude:s@" => { name => 'exclude' }, - }); + $options{options}->add_options(arguments => { + 'config-file:s' => { name => 'config_file' }, + 'exclude:s@' => { name => 'exclude' } + }); + $self->{conf} = {}; $self->{excludes} = {}; $self->{syst} = undef; @@ -63,7 +53,7 @@ sub check_options { } else { $self->{config_file} = dirname(__FILE__) . '/../conf/prtdiag.conf'; } - + foreach (@{$self->{option_results}->{exclude}}) { next if (! /^(.*?),(.*?),(.*)$/); my ($section, $tpl, $filter) = ($1, $2, $3); @@ -94,17 +84,19 @@ sub check_exclude { sub prtdiag { 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}, - no_errors => { 1 => 1 }); - - my @diag = split (/\n/, $stdout); - + + my ($stdout, $exit_code) = $options{custom}->execute_command( + command => 'prtdiag', + command_options => '-v 2>&1', + command_path => '/usr/platform/`/sbin/uname -i`/sbin' + ); + if ($exit_code != 0 && $exit_code != 1) { + $self->{output}->add_option_msg(short_msg => "Command error: $stdout"); + $self->{output}->option_exit(); + } + + my @diag = split(/\n/, $stdout); + # Look for system type unless( defined($self->{syst}) ) { FSYS: @@ -121,30 +113,38 @@ sub prtdiag { # Check for unidentified system type unless( defined($self->{syst}) ) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Unable to identify system type !"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Unable to identify system type !" + ); return ; } $self->{output}->output_add(long_msg => "Using system type : $self->{syst}"); # Further config checks unless( defined($self->{conf}->{$self->{syst}}->{'system.checks'}) ) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Initialization failed - Missing 'system.checks' entry for section '$self->{syst}' in file '$self->{config_file}' !"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Initialization failed - Missing 'system.checks' entry for section '$self->{syst}' in file '$self->{config_file}' !" + ); return ; } my @checks = split(/\s*,\s*/,$self->{conf}->{$self->{syst}}->{'system.checks'}); if( scalar(@checks) == 0 ) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "No check defined in 'system.checks' entry for section '$self->{syst}' in file '$self->{config_file}' !"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "No check defined in 'system.checks' entry for section '$self->{syst}' in file '$self->{config_file}' !" + ); return ; } foreach my $check ( @checks ) { foreach my $param ( "description", "begin_match", "end_match", "data_match", "data_labels", "ok_condition", "output_string" ) { my $param_name = "checks.$check.$param"; unless( defined($self->{conf}->{$self->{syst}}->{$param_name}) ) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Initialization error - Missing '$param_name' entry for section '$self->{syst}' in file '$self->{config_file}' !"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Initialization error - Missing '$param_name' entry for section '$self->{syst}' in file '$self->{config_file}' !" + ); return ; } } @@ -162,7 +162,7 @@ sub prtdiag { my $dcount = 0; my $lcount = 0; my %data = (); - + $self->{output}->output_add(long_msg => "Checking $description:"); # Parse prtdiag output @@ -266,15 +266,21 @@ sub prtdiag { my $checked = scalar(@passed) + scalar(@failed); if( scalar(@failed) > 0 ) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Checked $checked component" . ( $checked le 1 ? "" : "s") . ", found " . scalar(@failed) . " errors : " . join(', ',@failed)); + $self->{output}->output_add( + severity => 'CRITICAL', + short_msg => "Checked $checked component" . ( $checked le 1 ? "" : "s") . ", found " . scalar(@failed) . " errors : " . join(', ',@failed) + ); $self->{output}->output_add(long_msg => join("\n",@passed)); } elsif( $checked == 0 ) { - $self->{output}->output_add(severity => 'WARNING', - short_msg => "Found nothing to check !"); + $self->{output}->output_add( + severity => 'WARNING', + short_msg => "Found nothing to check !" + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "Successfully checked $checked component" . ( $checked le 1 ? "" : "s")); + $self->{output}->output_add( + severity => 'OK', + short_msg => "Successfully checked $checked component" . ( $checked le 1 ? "" : "s") + ); $self->{output}->output_add(long_msg => join("\n", @passed)); } } @@ -283,7 +289,7 @@ sub run { my ($self, %options) = @_; $self->load_prtdiag_config(); - $self->prtdiag(); + $self->prtdiag(custom => $options{custom}); $self->{output}->display(); $self->{output}->exit(); } @@ -292,8 +298,10 @@ sub load_prtdiag_config { my ($self, %options) = @_; unless( open(CONFIG,"<$self->{config_file}") ) { - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => "Initialization error - unable to open file '" . $self->{config_file} . "' : $!"); + $self->{output}->output_add( + severity => 'UNKNOWN', + short_msg => "Initialization error - unable to open file '" . $self->{config_file} . "' : $!" + ); $self->{output}->display(); $self->{output}->exit(); } @@ -323,51 +331,12 @@ __END__ =head1 MODE -Check Sun Hardware with 'prtdiag' command. +Check Sun hardware. + +Command used: '/usr/platform/`/sbin/uname -i`/sbin/prtdiag -v 2>&1' =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: 'prtdiag'). -Can be changed if you have output in a file. - -=item B<--command-path> - -Command path (Default: '/usr/platform/`/sbin/uname -i`/sbin'). - -=item B<--command-options> - -Command options (Default: '-v 2>&1'). - =item B<--config-file> Config file with prtdiag output description (Default: Directory 'conf/prtdiag.conf' under absolute mode path). diff --git a/centreon-plugins/os/solaris/local/mode/svmdisks.pm b/centreon-plugins/os/solaris/local/mode/svmdisks.pm index 78ff0ca86..5eb3fe311 100644 --- a/centreon-plugins/os/solaris/local/mode/svmdisks.pm +++ b/centreon-plugins/os/solaris/local/mode/svmdisks.pm @@ -24,32 +24,17 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 }, - "sudo1" => { name => 'sudo1' }, - "command1:s" => { name => 'command1', default => 'metastat' }, - "command1-path:s" => { name => 'command1_path', default => '/usr/sbin' }, - "command1-options:s" => { name => 'command1_options', default => '2>&1' }, - "sudo2" => { name => 'sudo2' }, - "command2:s" => { name => 'command2', default => 'metadb' }, - "command2-path:s" => { name => 'command2_path', default => '/usr/sbin' }, - "command2-options:s" => { name => 'command2_options', default => '2>&1' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } @@ -58,34 +43,34 @@ 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) = @_; - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo1}, - command => $self->{option_results}->{command1}, - command_path => $self->{option_results}->{command1_path}, - command_options => $self->{option_results}->{command1_options}); + my ($stdout) = $options{custom}->execute_command( + command => 'metastat', + command_options => '2>&1', + command_path => '/usr/sbin' + ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); - my $stdout2 = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo2}, - command => $self->{option_results}->{command2}, - command_path => $self->{option_results}->{command2_path}, - command_options => $self->{option_results}->{command2_options}); + my ($stdout2) = $options{custom}->execute_command( + command => 'metadb', + command_options => '2>&1', + command_path => '/usr/sbin' + ); + $long_msg = $stdout2; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); @@ -164,24 +149,36 @@ sub run { } } - my ($exit_code) = $self->{perfdata}->threshold_check(value => $num_metastat_errors, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my ($exit_code) = $self->{perfdata}->threshold_check( + value => $num_metastat_errors, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($num_metastat_errors > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Some metadevices need maintenance:" . $metastat_name)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Some metadevices need maintenance:" . $metastat_name) + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on metadevices"); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on metadevices" + ); } - ($exit_code) = $self->{perfdata}->threshold_check(value => $num_metadb_errors, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + ($exit_code) = $self->{perfdata}->threshold_check( + value => $num_metadb_errors, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($num_metadb_errors > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Some replicas have problems:" . $metadb_name)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Some replicas have problems:" . $metadb_name) + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on replicas"); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on replicas" + ); } $self->{output}->display(); @@ -194,7 +191,9 @@ __END__ =head1 MODE -Check SolarisVm disk status (use 'metastat' and 'metadb' command). +Check SolarisVm disk status + +Command used: '/usr/sbin/metastat 2>&1' and '/usr/sbin/metadb 2>&1' =over 8 @@ -206,64 +205,6 @@ Threshold warning. Threshold critical. -=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<--sudo1> - -Use 'sudo' to execute the command. - -=item B<--command1> - -Command to get information (Default: 'metastat'). -Can be changed if you have output in a file. - -=item B<--command1-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command1-options> - -Command options (Default: '2>&1'). - -=item B<--sudo2> - -Use 'sudo' to execute the command. - -=item B<--command2> - -Command to get information (Default: 'metadb'). -Can be changed if you have output in a file. - -=item B<--command2-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command2-options> - -Command options (Default: '2>&1'). - =back =cut diff --git a/centreon-plugins/os/solaris/local/mode/vxdisks.pm b/centreon-plugins/os/solaris/local/mode/vxdisks.pm index c5badf0e5..44103bb01 100644 --- a/centreon-plugins/os/solaris/local/mode/vxdisks.pm +++ b/centreon-plugins/os/solaris/local/mode/vxdisks.pm @@ -24,34 +24,19 @@ use base qw(centreon::plugins::mode); use strict; use warnings; -use centreon::plugins::misc; sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $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 }, - "sudo1" => { name => 'sudo1' }, - "command1:s" => { name => 'command1', default => 'vxdisk' }, - "command1-path:s" => { name => 'command1_path', default => '/usr/sbin' }, - "command1-options:s" => { name => 'command1_options', default => 'list 2>&1' }, - "skip-vxdisk" => { name => 'skip_vxdisk' }, - "sudo2" => { name => 'sudo2' }, - "command2:s" => { name => 'command2', default => 'vxprint' }, - "command2-path:s" => { name => 'command2_path', default => '/usr/sbin' }, - "command2-options:s" => { name => 'command2_options', default => '-Ath 2>&1' }, - "skip-vxprint" => { name => 'skip_vxprint' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'skip-vxdisk' => { name => 'skip_vxdisk' }, + 'skip-vxprint' => { name => 'skip_vxprint' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } @@ -60,28 +45,28 @@ 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 vdisk_execute { my ($self, %options) = @_; - - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo1}, - command => $self->{option_results}->{command1}, - command_path => $self->{option_results}->{command1_path}, - command_options => $self->{option_results}->{command1_options}); + + my ($stdout) = $options{custom}->execute_command( + command => 'vxdisk', + command_options => 'list 2>&1', + command_path => '/usr/sbin' + ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); - + foreach (split /\n/, $stdout) { if (/(failed)/i ) { my $status = $1; @@ -94,17 +79,17 @@ sub vdisk_execute { sub vxprint_execute { my ($self, %options) = @_; - - my $stdout = centreon::plugins::misc::execute(output => $self->{output}, - options => $self->{option_results}, - sudo => $self->{option_results}->{sudo2}, - command => $self->{option_results}->{command2}, - command_path => $self->{option_results}->{command2_path}, - command_options => $self->{option_results}->{command2_options}); + + my ($stdout) = $options{custom}->execute_command( + command => 'vxprint', + command_options => '-Ath 2>&1', + command_path => '/usr/sbin' + ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); - + foreach (split /\n/, $stdout) { if (/(NODEVICE|FAILING)/i ) { my $status = $1; @@ -122,22 +107,28 @@ sub run { $self->{vxprint_name} = ''; if (!defined($self->{option_results}->{skip_vxdisk})) { - $self->vdisk_execute(); + $self->vdisk_execute(custom => $options{custom}); } if (!defined($self->{option_results}->{skip_vxprint})) { - $self->vxprint_execute(); + $self->vxprint_execute(custom => $options{custom}); } - - my ($exit_code) = $self->{perfdata}->threshold_check(value => $self->{num_errors}, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + my ($exit_code) = $self->{perfdata}->threshold_check( + value => $self->{num_errors}, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); if ($self->{num_errors} > 0) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Problems on some disks:" . $self->{vxdisks_name} . $self->{vxprint_name})); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Problems on some disks:" . $self->{vxdisks_name} . $self->{vxprint_name}) + ); } else { - $self->{output}->output_add(severity => 'OK', - short_msg => "No problems on disks."); + $self->{output}->output_add( + severity => 'OK', + short_msg => "No problems on disks." + ); } - + $self->{output}->display(); $self->{output}->exit(); } @@ -148,7 +139,9 @@ __END__ =head1 MODE -Check Veritas disk status (use 'vxdisk' and 'vxprint' command). +Check Veritas disk status. + +Command used: '/usr/sbin/vxdisk list 2>&1' and '/usr/sbin/vxprint -Ath 2>&1' =over 8 @@ -160,64 +153,6 @@ Threshold warning. Threshold critical. -=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<--sudo1> - -Use 'sudo' to execute the command. - -=item B<--command1> - -Command to get information (Default: 'vxdisk'). -Can be changed if you have output in a file. - -=item B<--command1-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command1-options> - -Command options (Default: 'list 2>&1'). - -=item B<--sudo2> - -Use 'sudo' to execute the command. - -=item B<--command2> - -Command to get information (Default: 'vxprint'). -Can be changed if you have output in a file. - -=item B<--command2-path> - -Command path (Default: '/usr/sbin'). - -=item B<--command2-options> - -Command options (Default: '-Ath 2>&1'). - =item B<--skip-vxdisk> Skip 'vxdisk' command (not executed). diff --git a/centreon-plugins/os/solaris/local/plugin.pm b/centreon-plugins/os/solaris/local/plugin.pm index 3a1767837..7876ce16b 100644 --- a/centreon-plugins/os/solaris/local/plugin.pm +++ b/centreon-plugins/os/solaris/local/plugin.pm @@ -22,15 +22,14 @@ package os::solaris::local::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - %{$self->{modes}} = ( + $self->{modes} = { 'prtdiag' => 'os::solaris::local::mode::prtdiag', 'cpu' => 'os::solaris::local::mode::cpu', 'fc-connected' => 'os::solaris::local::mode::fcconnected', @@ -41,8 +40,10 @@ sub new { 'hwraidctl-status' => 'os::solaris::local::mode::hwraidctl', 'hwsas2ircu-status' => 'os::solaris::local::mode::hwsas2ircu', 'lom-v120-status' => 'os::solaris::local::mode::lomv120', - 'lom-v1280-status' => 'os::solaris::local::mode::lomv1280', - ); + 'lom-v1280-status' => 'os::solaris::local::mode::lomv1280' + }; + + $self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli'; return $self; } diff --git a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm index be09af937..d8e803594 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/hbausage.pm @@ -113,16 +113,16 @@ sub new { 'cem-port:s' => { name => 'cem_port', default => 3033 }, 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, 'start-time:s' => { name => 'start_time' }, 'end-time:s' => { name => 'end_time' }, - 'timezone:s' => { name => 'timezone' }, + 'timezone:s' => { name => 'timezone' } }); return $self; @@ -185,6 +185,18 @@ sub check_options { $dt_start = $dt_end->subtract(minutes => 30); } $self->{start_time} = $self->get_iso8601(date => $dt_start); + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm index 730d2f578..1c73e1675 100644 --- a/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm +++ b/centreon-plugins/storage/dell/compellent/local/mode/volumeusage.pm @@ -41,9 +41,9 @@ sub set_counters { 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'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } - }, + } ]; $self->{maps_counters}->{volume} = [ @@ -52,7 +52,7 @@ sub set_counters { 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'), + closure_custom_threshold_check => $self->can('custom_usage_threshold') } }, { label => 'volume-overhead', set => { @@ -60,9 +60,9 @@ sub set_counters { output_template => 'Raid Overhead : %s %s', output_change_bytes => 1, perfdatas => [ - { label => 'volume_overhead', value => 'overhead', template => '%d', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'volume_overhead', template => '%d', + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'volume-replay', set => { @@ -70,11 +70,11 @@ sub set_counters { output_template => 'Replay : %s %s', output_change_bytes => 1, perfdatas => [ - { label => 'volume_replay', value => 'replay', template => '%d', - unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'volume_replay', template => '%d', + unit => 'B', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } - }, + } ]; } @@ -186,16 +186,16 @@ sub new { 'cem-port:s' => { name => 'cem_port', default => 3033 }, 'sdk-path-dll:s' => { name => 'sdk_path_dll' }, 'timeout:s' => { name => 'timeout', default => 50 }, - 'command:s' => { name => 'command', default => 'powershell.exe' }, + 'command:s' => { name => 'command' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + 'command-options:s' => { name => 'command_options' }, 'no-ps' => { name => 'no_ps' }, 'ps-exec-only' => { name => 'ps_exec_only' }, 'ps-display' => { name => 'ps_display' }, 'ps-sc-filter:s' => { name => 'ps_sc_filter' }, 'ps-sc-volume:s' => { name => 'ps_sc_volume' }, 'units:s' => { name => 'units', default => '%' }, - 'free' => { name => 'free' }, + 'free' => { name => 'free' } }); return $self; @@ -212,7 +212,19 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify --" . $label_opt . " option."); $self->{output}->option_exit(); } - } + } + + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + + $self->{option_results}->{command} = 'powershell.exe' + if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq ''); + $self->{option_results}->{command_options} = '-InputFormat none -NoLogo -EncodedCommand' + if (!defined($self->{option_results}->{command_options}) || $self->{option_results}->{command_options} eq ''); } sub manage_selection { diff --git a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm index fb5b6e124..de1996264 100644 --- a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm +++ b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/monitoredparameters.pm @@ -31,45 +31,31 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'get_monitored_parameters' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '' }, - "min-severity:s" => { name => 'min_severity', default => 'minor' }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); + $options{options}->add_options(arguments => { + 'min-severity:s' => { name => 'min_severity', default => 'minor' }, + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' } + }); + return $self; } sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - - if (!defined($self->{option_results}->{command})) { - $self->{output}->add_option_msg(short_msg => "Need to specify command option."); - $self->{output}->option_exit(); - } if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Need to specify hostname."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify hostname."); + $self->{output}->option_exit(); } 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(); } if ($self->{option_results}->{min_severity} !~ /^(minor|major|critical)$/) { $self->{output}->add_option_msg(short_msg => 'Min-severity must be minor, major or critical.'); @@ -80,16 +66,13 @@ sub check_options { sub run { my ($self, %options) = @_; - my $min_severity = ' min_severity=' . $self->{option_results}->{min_severity}; - $self->{option_results}->{remote} = 1; + my $min_severity = 'min_severity=' . $self->{option_results}->{min_severity}; + + my ($stdout) = $options{custom}->execute_command( + command => 'get_monitored_parameters', + command_options => $min_severity + ); - my ($stdout, $exit_code) = 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} . $min_severity, - ); my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; @@ -100,18 +83,24 @@ sub run { } } - $exit_code = $self->{perfdata}->threshold_check(value => $count, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check(value => $count, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(long_msg => $long_msg); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%i problems found.", - $count)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + "%i problems found.", + $count + ) + ); - $self->{output}->perfdata_add(label => "problems", - value => $count, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $self->{output}->perfdata_add( + label => "problems", + value => $count, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); @@ -123,47 +112,12 @@ __END__ =head1 MODE -Check monitored paramaters by RecoveryPoint Appliance. +Check monitored parameters by RecoveryPoint Appliance. + +Command used: 'get_monitored_parameters min_severity=%(min_severity)' =over 8 -=item B<--hostname> - -Hostname to query. - -=item B<--ssh-option> - -Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-pw=password'). - -=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 test (Default: get_monitored_parameters). -You can use 'sh' to use '&&' or '||'. - -=item B<--command-path> - -Command path (Default: none). - -=item B<--command-options> - -Command options. - =item B<--min-severity> Minimum severity level you want to count (Default: minor). diff --git a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm index 28107218d..4d7b5cde4 100644 --- a/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm +++ b/centreon-plugins/storage/emc/recoverypoint/ssh/mode/systemstatus.pm @@ -31,18 +31,8 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "ssh-option:s@" => { name => 'ssh_option' }, - "ssh-path:s" => { name => 'ssh_path' }, - "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "sudo" => { name => 'sudo' }, - "command:s" => { name => 'command', default => 'get_system_status' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => 'category=system summary=yes' }, - }); + $options{options}->add_options(arguments => {}); + return $self; } @@ -51,28 +41,19 @@ sub check_options { $self->SUPER::init(%options); if (!defined($self->{option_results}->{hostname})) { - $self->{output}->add_option_msg(short_msg => "Need to specify hostname."); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{command})) { - $self->{output}->add_option_msg(short_msg => "Need to specify command option."); - $self->{output}->option_exit(); + $self->{output}->add_option_msg(short_msg => "Need to specify hostname."); + $self->{output}->option_exit(); } } sub run { my ($self, %options) = @_; - $self->{option_results}->{remote} = 1; + my ($stdout) = $options{custom}->execute_command( + command => 'get_system_status', + command_options => 'category=system summary=yes' + ); - my ($stdout, $exit_code) = 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}, - ); my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; @@ -89,15 +70,19 @@ sub run { } } - $exit_code = 'ok'; + my $exit_code = 'ok'; if (($system !~ /OK/im) || ($clusters !~ /OK/im) || ($wans !~ /OK/im) || ($groups !~ /OK/im)) { $exit_code = 'critical' } $self->{output}->output_add(long_msg => $long_msg); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("System %s, Clusters %s, WANs %s, Groups %s.", - $system, $clusters, $wans, $groups)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + "System %s, Clusters %s, WANs %s, Groups %s.", + $system, $clusters, $wans, $groups) + ); + $self->{output}->display(); $self->{output}->exit(); } @@ -108,47 +93,12 @@ __END__ =head1 MODE -Check system status. +Check system status + +Command used: 'get_system_status category=system summary=yes' =over 8 -=item B<--hostname> - -Hostname to query. - -=item B<--ssh-option> - -Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-pw=password'). - -=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 test (Default: get_system_status). -You can use 'sh' to use '&&' or '||'. - -=item B<--command-path> - -Command path (Default: none). - -=item B<--command-options> - -Command options (Default: category=system summary=yes). - =back =cut diff --git a/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm b/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm index 0927a55c1..0c53ff5b8 100644 --- a/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm +++ b/centreon-plugins/storage/emc/recoverypoint/ssh/plugin.pm @@ -22,18 +22,19 @@ package storage::emc::recoverypoint::ssh::plugin; use strict; use warnings; -use base qw(centreon::plugins::script_simple); +use base qw(centreon::plugins::script_custom); sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.1'; - %{$self->{modes}} = ( + $self->{modes} = { 'monitored-parameters' => 'storage::emc::recoverypoint::ssh::mode::monitoredparameters', - 'system-status' => 'storage::emc::recoverypoint::ssh::mode::systemstatus', - ); + 'system-status' => 'storage::emc::recoverypoint::ssh::mode::systemstatus' + }; + + $self->{custom_modes}->{cli} = 'centreon::plugins::script_custom::cli'; return $self; } diff --git a/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm b/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm index e38816810..3fbb29f48 100644 --- a/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm +++ b/centreon-plugins/storage/hp/3par/ssh/custom/custom.pm @@ -71,6 +71,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/storage/hp/eva/cli/custom/api.pm b/centreon-plugins/storage/hp/eva/cli/custom/api.pm index 22435aced..82811235a 100644 --- a/centreon-plugins/storage/hp/eva/cli/custom/api.pm +++ b/centreon-plugins/storage/hp/eva/cli/custom/api.pm @@ -47,9 +47,9 @@ sub new { 'manager-system:s' => { name => 'manager_system' }, 'timeout:s' => { name => 'timeout', default => 50 }, 'sudo' => { name => 'sudo' }, - 'command:s' => { name => 'command', default => 'sssu_linux_x64' }, + 'command:s' => { name => 'command', default => '' }, 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options', default => '' } + 'command-options:s' => { name => 'command_options' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'SSU CLI OPTIONS', once => 1); @@ -87,6 +87,13 @@ sub check_options { $self->{output}->option_exit(); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } @@ -103,20 +110,24 @@ sub ssu_build_options { sub ssu_execute { my ($self, %options) = @_; - + $self->ssu_build_options(%options); - my ($response) = 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}); + my $command = defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : 'sssu_linux_x64'; + my ($response) = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $command, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options} + ); + my $xml_root = ''; while ($response =~ /(.*?<\/object>)/msig) { $xml_root .= $1; } $xml_root .= ''; - + my $xml_result; eval { $xml_result = XMLin($xml_root, @@ -128,7 +139,7 @@ sub ssu_execute { $self->{output}->add_option_msg(short_msg => "Cannot decode xml response: $@"); $self->{output}->option_exit(); } - + $self->{output}->output_add(long_msg => $response, debug => 1); return $xml_result; } diff --git a/centreon-plugins/storage/hp/storeonce/ssh/custom/custom.pm b/centreon-plugins/storage/hp/storeonce/ssh/custom/custom.pm index e87177d0e..cf79eb77b 100644 --- a/centreon-plugins/storage/hp/storeonce/ssh/custom/custom.pm +++ b/centreon-plugins/storage/hp/storeonce/ssh/custom/custom.pm @@ -71,6 +71,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/storage/ibm/storwize/ssh/custom/api.pm b/centreon-plugins/storage/ibm/storwize/ssh/custom/api.pm index 45c373f73..766b67091 100644 --- a/centreon-plugins/storage/ibm/storwize/ssh/custom/api.pm +++ b/centreon-plugins/storage/ibm/storwize/ssh/custom/api.pm @@ -72,6 +72,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; } diff --git a/centreon-plugins/storage/quantum/dxi/ssh/custom/api.pm b/centreon-plugins/storage/quantum/dxi/ssh/custom/api.pm index 93d7040f9..81c146031 100644 --- a/centreon-plugins/storage/quantum/dxi/ssh/custom/api.pm +++ b/centreon-plugins/storage/quantum/dxi/ssh/custom/api.pm @@ -72,6 +72,13 @@ sub check_options { $self->{ssh}->check_options(option_results => $self->{option_results}); } + centreon::plugins::misc::check_security_command( + output => $self->{output}, + command => $self->{option_results}->{command}, + command_options => $self->{option_results}->{command_options}, + command_path => $self->{option_results}->{command_path} + ); + return 0; }