diff --git a/os/linux/local/mode/cmdreturn.pm b/os/linux/local/mode/cmdreturn.pm index 8b3a87a75..981a600e6 100644 --- a/os/linux/local/mode/cmdreturn.pm +++ b/os/linux/local/mode/cmdreturn.pm @@ -32,21 +32,13 @@ 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' }, - 'command-path:s' => { name => 'command_path' }, - 'command-options:s' => { name => 'command_options' }, - 'manage-returns:s' => { name => 'manage_returns', default => '' }, - 'separator:s' => { name => 'separator', default => '#' }, + 'exec-command:s' => { name => 'exec_command' }, + 'exec-command-path:s' => { name => 'exec_command_path' }, + 'exec-command-options:s' => { name => 'exec_command_options' }, + 'manage-returns:s' => { name => 'manage_returns', default => '' }, + 'separator:s' => { name => 'separator', default => '#' } }); - $self->{manage_returns} = {}; return $self; } @@ -54,11 +46,12 @@ 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."); + if (!defined($self->{option_results}->{exec_command})) { + $self->{output}->add_option_msg(short_msg => "Need to specify exec-command option."); $self->{output}->option_exit(); } - + + $self->{manage_returns} = {}; foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) { next if (!($entry =~ /(.*?),(.*?),(.*)/)); next if (!$self->{output}->is_litteral_status(status => $2)); @@ -77,15 +70,13 @@ sub check_options { sub run { my ($self, %options) = @_; - 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 ($stdout, $exit_code) = $options{custom}->execute_command( + command => $self->{option_results}->{exec_command}, + command_path => $self->{option_results}->{exec_command_path}, + command_options => $self->{option_results}->{exec_command_options}, no_quit => 1 ); + my $long_msg = $stdout; $long_msg =~ s/\|/~/mg; $self->{output}->output_add(long_msg => $long_msg); @@ -137,44 +128,16 @@ Example: 0,OK,File xxx exist#1,CRITICAL,File xxx not exist#,UNKNOWN,Command prob Set the separator used in --manage-returns (default : #) -=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> +=item B<--exec-command> Command to test (Default: none). You can use 'sh' to use '&&' or '||'. -=item B<--command-path> +=item B<--exec-command-path> Command path (Default: none). -=item B<--command-options> +=item B<--exec-command-options> Command options (Default: none). diff --git a/os/linux/local/mode/diskio.pm b/os/linux/local/mode/diskio.pm index 085b360f6..87a96995d 100644 --- a/os/linux/local/mode/diskio.pm +++ b/os/linux/local/mode/diskio.pm @@ -73,8 +73,8 @@ sub set_counters { output_use => 'usage_persecond', threshold_use => 'usage_persecond', perfdatas => [ { label => 'readio', value => 'usage_persecond', template => '%d', - unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'write-usage', nlabel => 'device.io.write.usage.bytespersecond', set => { @@ -85,8 +85,8 @@ sub set_counters { output_use => 'usage_persecond', threshold_use => 'usage_persecond', perfdatas => [ { label => 'writeio', value => 'usage_persecond', template => '%d', - unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'B/s', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'read-time', nlabel => 'device.io.read.time.milliseconds', set => { @@ -94,8 +94,8 @@ sub set_counters { output_template => 'read time : %.2f ms', perfdatas => [ { label => 'readtime', template => '%.2f', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'write-time', nlabel => 'device.io.write.time.milliseconds', set => { @@ -103,8 +103,8 @@ sub set_counters { output_template => 'write time : %.2f ms', perfdatas => [ { label => 'writetime', template => '%.2f', - unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display' } + ] } }, { label => 'utils', nlabel => 'device.io.utils.percentage', set => { @@ -122,10 +122,10 @@ sub set_counters { output_use => 'utils', threshold_use => 'utils', perfdatas => [ { label => 'utils', value => 'utils', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } - }, + } ]; } @@ -141,48 +141,23 @@ 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 => 'tail' }, - 'command-path:s' => { name => 'command_path', }, - 'command-options:s' => { name => 'command_options', default => '-n +1 /proc/stat /proc/diskstats 2>&1' }, 'name:s' => { name => 'name' }, 'regexp' => { name => 'use_regexp' }, 'regexp-isensitive' => { name => 'use_regexpi' }, 'interrupt-frequency:s' => { name => 'interrupt_frequency', default => 1000 }, - 'bytes_per_sector:s' => { name => 'bytes_per_sector', default => 512 }, - 'skip' => { name => 'skip' }, + 'bytes-per-sector:s' => { name => 'bytes_per_sector', default => 512 }, + 'skip' => { name => 'skip' } }); - $self->{hostname} = undef; return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - $self->{hostname} = $self->{option_results}->{hostname}; - if (!defined($self->{hostname})) { - $self->{hostname} = 'me'; - } -} - 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) = $options{custom}->execute_command( + command => 'tail', + command_options => '-n +1 /proc/stat /proc/diskstats 2>&1' ); $stdout =~ /\/proc\/stat(.*?)\/proc\/diskstats.*?\n(.*)/msg; @@ -224,7 +199,7 @@ sub manage_selection { cpu_system => $cpu_system, cpu_idle => $cpu_idle, cpu_user => $cpu_user, - cpu_iowait => $cpu_iowait, + cpu_iowait => $cpu_iowait }; } @@ -237,7 +212,9 @@ sub manage_selection { $self->{output}->option_exit(); } - $self->{cache_name} = 'cache_linux_local_' . $self->{hostname} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')) + $self->{cache_name} = 'cache_linux_local_' . $options{custom}->get_identifier() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{name}) ? md5_hex($self->{option_results}->{name}) : md5_hex('all')); } 1; @@ -247,7 +224,9 @@ __END__ =head1 MODE Check some disk io counters: -read and writes bytes per seconds, milliseconds time spent reading and writing, %util (like iostat) +read and writes bytes per seconds, milliseconds time spent reading and writing, %util (like iostat) + +Command used: tail -n +1 /proc/stat /proc/diskstats 2>&1 =over 8 diff --git a/os/linux/local/mode/filesdate.pm b/os/linux/local/mode/filesdate.pm index c7f3035e7..c0658a5c4 100644 --- a/os/linux/local/mode/filesdate.pm +++ b/os/linux/local/mode/filesdate.pm @@ -31,25 +31,16 @@ 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-path:s" => { name => 'command_path' }, - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "separate-dirs" => { name => 'separate_dirs', }, - "max-depth:s" => { name => 'max_depth', }, - "exclude-du:s@" => { name => 'exclude_du', }, - "filter-plugin:s" => { name => 'filter_plugin', }, - "files:s" => { name => 'files', }, - "time:s" => { name => 'time', }, - }); + $options{options}->add_options(arguments => { + 'warning:s' => { name => 'warning' }, + 'critical:s' => { name => 'critical' }, + 'separate-dirs' => { name => 'separate_dirs' }, + 'max-depth:s' => { name => 'max_depth' }, + 'exclude-du:s@' => { name => 'exclude_du' }, + 'filter-plugin:s' => { name => 'filter_plugin' }, + 'files:s' => { name => 'files' }, + 'time:s' => { name => 'time' } + }); return $self; } @@ -70,26 +61,25 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify files option."); $self->{output}->option_exit(); } - + #### Create command_options - $self->{option_results}->{command} = 'du'; - $self->{option_results}->{command_options} = '-x --time-style=+%s'; + $self->{command_options} = '-x --time-style=+%s'; if (defined($self->{option_results}->{separate_dirs})) { - $self->{option_results}->{command_options} .= ' --separate-dirs'; + $self->{command_options} .= ' --separate-dirs'; } if (defined($self->{option_results}->{max_depth})) { - $self->{option_results}->{command_options} .= ' --max-depth=' . $self->{option_results}->{max_depth}; + $self->{command_options} .= ' --max-depth=' . $self->{option_results}->{max_depth}; } if (defined($self->{option_results}->{time})) { - $self->{option_results}->{command_options} .= ' --time=' . $self->{option_results}->{time}; + $self->{command_options} .= ' --time=' . $self->{option_results}->{time}; } else { - $self->{option_results}->{command_options} .= ' --time'; + $self->{command_options} .= ' --time'; } foreach my $exclude (@{$self->{option_results}->{exclude_du}}) { - $self->{option_results}->{command_options} .= " --exclude='" . $exclude . "'"; + $self->{command_options} .= " --exclude='" . $exclude . "'"; } - $self->{option_results}->{command_options} .= ' ' . $self->{option_results}->{files}; - $self->{option_results}->{command_options} .= ' 2>&1'; + $self->{command_options} .= ' ' . $self->{option_results}->{files}; + $self->{command_options} .= ' 2>&1'; } sub run { @@ -97,15 +87,15 @@ sub run { my $total_size = 0; my $current_time = time(); - 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->{output}->output_add(severity => 'OK', - short_msg => "All file/directory times are ok."); + my ($stdout) = $options{custom}->execute_command( + command => 'du', + command_options => $self->{command_options} + ); + + $self->{output}->output_add( + severity => 'OK', + short_msg => 'All file/directory times are ok.' + ); foreach (split(/\n/, $stdout)) { next if (!/(\d+)\t+(\d+)\t+(.*)/); my ($size, $time, $name) = ($1, $2, centreon::plugins::misc::trim($3)); @@ -114,18 +104,23 @@ sub run { next if (defined($self->{option_results}->{filter_plugin}) && $self->{option_results}->{filter_plugin} ne '' && $name !~ /$self->{option_results}->{filter_plugin}/); - my $exit_code = $self->{perfdata}->threshold_check(value => $diff_time, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check( + value => $diff_time, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ] + ); $self->{output}->output_add(long_msg => sprintf("%s: %s seconds (time: %s)", $name, $diff_time, scalar(localtime($time)))); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("%s: %s seconds (time: %s)", $name, $diff_time, scalar(localtime($time)))); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf('%s: %s seconds (time: %s)', $name, $diff_time, scalar(localtime($time))) + ); } - $self->{output}->perfdata_add(label => $name, unit => 's', - value => $diff_time, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - ); + $self->{output}->perfdata_add( + label => $name, unit => 's', + value => $diff_time, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical') + ); } $self->{output}->display(); @@ -176,38 +171,6 @@ Shell pattern can be used. Filter files/directories in the plugin. Values from exclude files/directories are counted in parent directories!!! Perl Regexp can be used. -=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-path> - -Command path (Default: none). - =back =cut diff --git a/os/linux/local/mode/filessize.pm b/os/linux/local/mode/filessize.pm index f1e8664f9..20fa6535b 100644 --- a/os/linux/local/mode/filessize.pm +++ b/os/linux/local/mode/filessize.pm @@ -31,27 +31,18 @@ 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-path:s" => { name => 'command_path' }, - "warning-one:s" => { name => 'warning_one', }, - "critical-one:s" => { name => 'critical_one', }, - "warning-total:s" => { name => 'warning_total', }, - "critical-total:s" => { name => 'critical_total', }, - "separate-dirs" => { name => 'separate_dirs', }, - "max-depth:s" => { name => 'max_depth', }, - "all-files" => { name => 'all_files', }, - "exclude-du:s@" => { name => 'exclude_du', }, - "filter-plugin:s" => { name => 'filter_plugin', }, - "files:s" => { name => 'files', }, - }); + $options{options}->add_options(arguments => { + 'warning-one:s' => { name => 'warning_one' }, + 'critical-one:s' => { name => 'critical_one' }, + 'warning-total:s' => { name => 'warning_total' }, + 'critical-total:s' => { name => 'critical_total' }, + 'separate-dirs' => { name => 'separate_dirs' }, + 'max-depth:s' => { name => 'max_depth' }, + 'all-files' => { name => 'all_files' }, + 'exclude-du:s@' => { name => 'exclude_du' }, + 'filter-plugin:s' => { name => 'filter_plugin' }, + 'files:s' => { name => 'files' } + }); return $self; } @@ -80,36 +71,32 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify files option."); $self->{output}->option_exit(); } - - #### Create command_options - $self->{option_results}->{command} = 'du'; - $self->{option_results}->{command_options} = '-x -b'; + + $self->{command_options} = '-x -b'; if (defined($self->{option_results}->{separate_dirs})) { - $self->{option_results}->{command_options} .= ' --separate-dirs'; + $self->{command_options} .= ' --separate-dirs'; } if (defined($self->{option_results}->{max_depth})) { - $self->{option_results}->{command_options} .= ' --max-depth=' . $self->{option_results}->{max_depth}; + $self->{command_options} .= ' --max-depth=' . $self->{option_results}->{max_depth}; } if (defined($self->{option_results}->{all_files})) { - $self->{option_results}->{command_options} .= ' --all'; + $self->{command_options} .= ' --all'; } foreach my $exclude (@{$self->{option_results}->{exclude_du}}) { - $self->{option_results}->{command_options} .= " --exclude='" . $exclude . "'"; + $self->{command_options} .= " --exclude='" . $exclude . "'"; } - $self->{option_results}->{command_options} .= ' ' . $self->{option_results}->{files}; - $self->{option_results}->{command_options} .= ' 2>&1'; + $self->{command_options} .= ' ' . $self->{option_results}->{files}; + $self->{command_options} .= ' 2>&1'; } sub run { my ($self, %options) = @_; my $total_size = 0; - 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 => 'du', + command_options => $self->{command_options} + ); $self->{output}->output_add(severity => 'OK', short_msg => "All file/directory sizes are ok."); @@ -121,35 +108,47 @@ sub run { $name !~ /$self->{option_results}->{filter_plugin}/); $total_size += $size; - my $exit_code = $self->{perfdata}->threshold_check(value => $size, - threshold => [ { label => 'critical_one', exit_litteral => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check( + value => $size, + threshold => [ { label => 'critical_one', exit_litteral => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ] + ); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $size); $self->{output}->output_add(long_msg => sprintf("%s: %s", $name, $size_value . ' ' . $size_unit)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("'%s' size is %s", $name, $size_value . ' ' . $size_unit)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("'%s' size is %s", $name, $size_value . ' ' . $size_unit) + ); } - $self->{output}->perfdata_add(label => $name, unit => 'B', - value => $size, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_one'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_one'), - min => 0); + $self->{output}->perfdata_add( + label => $name, unit => 'B', + value => $size, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_one'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_one'), + min => 0 + ); } # Total Size - my $exit_code = $self->{perfdata}->threshold_check(value => $total_size, - threshold => [ { label => 'critical_total', exit_litteral => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]); + my $exit_code = $self->{perfdata}->threshold_check( + value => $total_size, + threshold => [ { label => 'critical_total', exit_litteral => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ] + ); my ($size_value, $size_unit) = $self->{perfdata}->change_bytes(value => $total_size); $self->{output}->output_add(long_msg => sprintf("Total: %s", $size_value . ' ' . $size_unit)); if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) { - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Total size is %s", $size_value . ' ' . $size_unit)); + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf('Total size is %s', $size_value . ' ' . $size_unit) + ); } - $self->{output}->perfdata_add(label => 'total', unit => 'B', - value => $total_size, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_total'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_total'), - min => 0); + $self->{output}->perfdata_add( + label => 'total', unit => 'B', + value => $total_size, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_total'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_total'), + min => 0 + ); $self->{output}->display(); $self->{output}->exit(); @@ -207,38 +206,6 @@ Shell pattern can be used. Filter files/directories in the plugin. Values from exclude files/directories are counted in parent directories!!! Perl Regexp can be used. -=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-path> - -Command path (Default: none). - =back =cut diff --git a/os/linux/local/mode/inodes.pm b/os/linux/local/mode/inodes.pm index 0014f110a..4d15b511d 100644 --- a/os/linux/local/mode/inodes.pm +++ b/os/linux/local/mode/inodes.pm @@ -36,19 +36,19 @@ sub set_counters { $self->{maps_counters}->{inodes} = [ { label => 'usage', set => { key_values => [ { name => 'used' }, { name => 'display' } ], - output_template => 'Used: %s %%', + output_template => 'used: %s %%', perfdatas => [ - { label => 'used', value => 'used', template => '%d', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }, - ], + { label => 'used', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } + ] } - }, + } ]; } sub prefix_inodes_output { my ($self, %options) = @_; - + return "Inodes partition '" . $options{instance_value}->{display} . "' "; } @@ -57,46 +57,32 @@ 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 => 'df' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-P -i -T 2>&1' }, - "filter-type:s" => { name => 'filter_type', }, - "filter-fs:s" => { name => 'filter_fs', }, - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "regexp-isensitive" => { name => 'use_regexpi' }, - }); - $self->{result} = {}; + $options{options}->add_options(arguments => { + 'filter-type:s' => { name => 'filter_type', }, + 'filter-fs:s' => { name => 'filter_fs', }, + 'name:s' => { name => 'name' }, + 'regexp' => { name => 'use_regexp' }, + 'regexp-isensitive' => { name => 'use_regexpi' } + }); + return $self; } sub manage_selection { my ($self, %options) = @_; - 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 ($stdout, $exit_code) = $options{custom}->execute_command( + command => 'df', + command_options => '-P -i -T 2>&1', no_quit => 1 ); + $self->{inodes} = {}; my @lines = split /\n/, $stdout; foreach my $line (@lines) { next if ($line !~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/); my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7); - + next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && $fs !~ /$self->{option_results}->{filter_fs}/); next if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && @@ -108,11 +94,12 @@ sub manage_selection { && $mount !~ /$self->{option_results}->{name}/); next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $mount ne $self->{option_results}->{name}); - + $percent =~ s/%//g; + next if ($percent eq '-'); $self->{inodes}->{$mount} = { display => $mount, fs => $fs, type => $type, total => $size, used => $percent }; } - + if (scalar(keys %{$self->{inodes}}) <= 0) { if ($exit_code != 0) { $self->{output}->output_add(long_msg => "command output:" . $stdout); @@ -130,49 +117,10 @@ __END__ Check Inodes space usage on partitions. +Command used: df -P -i -T 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: 'df'). -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: '-P -i -T 2>&1'). - =item B<--warning-usage> Threshold warning in percent. @@ -203,4 +151,4 @@ Filter filesystem (regexp can be used). =back -=cut \ No newline at end of file +=cut