wip: refacto linux local
This commit is contained in:
parent
2f452f650e
commit
267f149451
|
@ -32,21 +32,13 @@ sub new {
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$options{options}->add_options(arguments => {
|
||||||
'hostname:s' => { name => 'hostname' },
|
'exec-command:s' => { name => 'exec_command' },
|
||||||
'remote' => { name => 'remote' },
|
'exec-command-path:s' => { name => 'exec_command_path' },
|
||||||
'ssh-option:s@' => { name => 'ssh_option' },
|
'exec-command-options:s' => { name => 'exec_command_options' },
|
||||||
'ssh-path:s' => { name => 'ssh_path' },
|
'manage-returns:s' => { name => 'manage_returns', default => '' },
|
||||||
'ssh-command:s' => { name => 'ssh_command', default => 'ssh' },
|
'separator:s' => { name => 'separator', default => '#' }
|
||||||
'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 => '#' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{manage_returns} = {};
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,11 +46,12 @@ sub check_options {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
$self->SUPER::init(%options);
|
$self->SUPER::init(%options);
|
||||||
|
|
||||||
if (!defined($self->{option_results}->{command})) {
|
if (!defined($self->{option_results}->{exec_command})) {
|
||||||
$self->{output}->add_option_msg(short_msg => "Need to specify command option.");
|
$self->{output}->add_option_msg(short_msg => "Need to specify exec-command option.");
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$self->{manage_returns} = {};
|
||||||
foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
|
foreach my $entry (split(/$self->{option_results}->{separator}/, $self->{option_results}->{manage_returns})) {
|
||||||
next if (!($entry =~ /(.*?),(.*?),(.*)/));
|
next if (!($entry =~ /(.*?),(.*?),(.*)/));
|
||||||
next if (!$self->{output}->is_litteral_status(status => $2));
|
next if (!$self->{output}->is_litteral_status(status => $2));
|
||||||
|
@ -77,15 +70,13 @@ sub check_options {
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my ($stdout, $exit_code) = centreon::plugins::misc::execute(
|
my ($stdout, $exit_code) = $options{custom}->execute_command(
|
||||||
output => $self->{output},
|
command => $self->{option_results}->{exec_command},
|
||||||
options => $self->{option_results},
|
command_path => $self->{option_results}->{exec_command_path},
|
||||||
sudo => $self->{option_results}->{sudo},
|
command_options => $self->{option_results}->{exec_command_options},
|
||||||
command => $self->{option_results}->{command},
|
|
||||||
command_path => $self->{option_results}->{command_path},
|
|
||||||
command_options => $self->{option_results}->{command_options},
|
|
||||||
no_quit => 1
|
no_quit => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
my $long_msg = $stdout;
|
my $long_msg = $stdout;
|
||||||
$long_msg =~ s/\|/~/mg;
|
$long_msg =~ s/\|/~/mg;
|
||||||
$self->{output}->output_add(long_msg => $long_msg);
|
$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 : #)
|
Set the separator used in --manage-returns (default : #)
|
||||||
|
|
||||||
=item B<--remote>
|
=item B<--exec-command>
|
||||||
|
|
||||||
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 test (Default: none).
|
Command to test (Default: none).
|
||||||
You can use 'sh' to use '&&' or '||'.
|
You can use 'sh' to use '&&' or '||'.
|
||||||
|
|
||||||
=item B<--command-path>
|
=item B<--exec-command-path>
|
||||||
|
|
||||||
Command path (Default: none).
|
Command path (Default: none).
|
||||||
|
|
||||||
=item B<--command-options>
|
=item B<--exec-command-options>
|
||||||
|
|
||||||
Command options (Default: none).
|
Command options (Default: none).
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,8 @@ sub set_counters {
|
||||||
output_use => 'usage_persecond', threshold_use => 'usage_persecond',
|
output_use => 'usage_persecond', threshold_use => 'usage_persecond',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'readio', value => 'usage_persecond', template => '%d',
|
{ 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 => {
|
{ 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',
|
output_use => 'usage_persecond', threshold_use => 'usage_persecond',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'writeio', value => 'usage_persecond', template => '%d',
|
{ 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 => {
|
{ label => 'read-time', nlabel => 'device.io.read.time.milliseconds', set => {
|
||||||
|
@ -94,8 +94,8 @@ sub set_counters {
|
||||||
output_template => 'read time : %.2f ms',
|
output_template => 'read time : %.2f ms',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'readtime', template => '%.2f',
|
{ 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 => {
|
{ label => 'write-time', nlabel => 'device.io.write.time.milliseconds', set => {
|
||||||
|
@ -103,8 +103,8 @@ sub set_counters {
|
||||||
output_template => 'write time : %.2f ms',
|
output_template => 'write time : %.2f ms',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'writetime', template => '%.2f',
|
{ 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 => {
|
{ label => 'utils', nlabel => 'device.io.utils.percentage', set => {
|
||||||
|
@ -122,10 +122,10 @@ sub set_counters {
|
||||||
output_use => 'utils', threshold_use => 'utils',
|
output_use => 'utils', threshold_use => 'utils',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'utils', value => 'utils', template => '%.2f',
|
{ 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;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments => {
|
$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' },
|
'name:s' => { name => 'name' },
|
||||||
'regexp' => { name => 'use_regexp' },
|
'regexp' => { name => 'use_regexp' },
|
||||||
'regexp-isensitive' => { name => 'use_regexpi' },
|
'regexp-isensitive' => { name => 'use_regexpi' },
|
||||||
'interrupt-frequency:s' => { name => 'interrupt_frequency', default => 1000 },
|
'interrupt-frequency:s' => { name => 'interrupt_frequency', default => 1000 },
|
||||||
'bytes_per_sector:s' => { name => 'bytes_per_sector', default => 512 },
|
'bytes-per-sector:s' => { name => 'bytes_per_sector', default => 512 },
|
||||||
'skip' => { name => 'skip' },
|
'skip' => { name => 'skip' }
|
||||||
});
|
});
|
||||||
|
|
||||||
$self->{hostname} = undef;
|
|
||||||
return $self;
|
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 {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my $stdout = centreon::plugins::misc::execute(
|
my ($stdout) = $options{custom}->execute_command(
|
||||||
output => $self->{output},
|
command => 'tail',
|
||||||
options => $self->{option_results},
|
command_options => '-n +1 /proc/stat /proc/diskstats 2>&1'
|
||||||
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 =~ /\/proc\/stat(.*?)\/proc\/diskstats.*?\n(.*)/msg;
|
$stdout =~ /\/proc\/stat(.*?)\/proc\/diskstats.*?\n(.*)/msg;
|
||||||
|
@ -224,7 +199,7 @@ sub manage_selection {
|
||||||
cpu_system => $cpu_system,
|
cpu_system => $cpu_system,
|
||||||
cpu_idle => $cpu_idle,
|
cpu_idle => $cpu_idle,
|
||||||
cpu_user => $cpu_user,
|
cpu_user => $cpu_user,
|
||||||
cpu_iowait => $cpu_iowait,
|
cpu_iowait => $cpu_iowait
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +212,9 @@ sub manage_selection {
|
||||||
$self->{output}->option_exit();
|
$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;
|
1;
|
||||||
|
@ -249,6 +226,8 @@ __END__
|
||||||
Check some disk io counters:
|
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
|
=over 8
|
||||||
|
|
||||||
=item B<--remote>
|
=item B<--remote>
|
||||||
|
|
|
@ -31,25 +31,16 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'warning:s' => { name => 'warning' },
|
||||||
"hostname:s" => { name => 'hostname' },
|
'critical:s' => { name => 'critical' },
|
||||||
"remote" => { name => 'remote' },
|
'separate-dirs' => { name => 'separate_dirs' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'max-depth:s' => { name => 'max_depth' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
'exclude-du:s@' => { name => 'exclude_du' },
|
||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
'filter-plugin:s' => { name => 'filter_plugin' },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
'files:s' => { name => 'files' },
|
||||||
"sudo" => { name => 'sudo' },
|
'time:s' => { name => 'time' }
|
||||||
"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', },
|
|
||||||
});
|
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -72,24 +63,23 @@ sub check_options {
|
||||||
}
|
}
|
||||||
|
|
||||||
#### Create command_options
|
#### Create command_options
|
||||||
$self->{option_results}->{command} = 'du';
|
$self->{command_options} = '-x --time-style=+%s';
|
||||||
$self->{option_results}->{command_options} = '-x --time-style=+%s';
|
|
||||||
if (defined($self->{option_results}->{separate_dirs})) {
|
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})) {
|
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})) {
|
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 {
|
} else {
|
||||||
$self->{option_results}->{command_options} .= ' --time';
|
$self->{command_options} .= ' --time';
|
||||||
}
|
}
|
||||||
foreach my $exclude (@{$self->{option_results}->{exclude_du}}) {
|
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->{command_options} .= ' ' . $self->{option_results}->{files};
|
||||||
$self->{option_results}->{command_options} .= ' 2>&1';
|
$self->{command_options} .= ' 2>&1';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
|
@ -97,15 +87,15 @@ sub run {
|
||||||
my $total_size = 0;
|
my $total_size = 0;
|
||||||
my $current_time = time();
|
my $current_time = time();
|
||||||
|
|
||||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
my ($stdout) = $options{custom}->execute_command(
|
||||||
options => $self->{option_results},
|
command => 'du',
|
||||||
sudo => $self->{option_results}->{sudo},
|
command_options => $self->{command_options}
|
||||||
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',
|
$self->{output}->output_add(
|
||||||
short_msg => "All file/directory times are ok.");
|
severity => 'OK',
|
||||||
|
short_msg => 'All file/directory times are ok.'
|
||||||
|
);
|
||||||
foreach (split(/\n/, $stdout)) {
|
foreach (split(/\n/, $stdout)) {
|
||||||
next if (!/(\d+)\t+(\d+)\t+(.*)/);
|
next if (!/(\d+)\t+(\d+)\t+(.*)/);
|
||||||
my ($size, $time, $name) = ($1, $2, centreon::plugins::misc::trim($3));
|
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 '' &&
|
next if (defined($self->{option_results}->{filter_plugin}) && $self->{option_results}->{filter_plugin} ne '' &&
|
||||||
$name !~ /$self->{option_results}->{filter_plugin}/);
|
$name !~ /$self->{option_results}->{filter_plugin}/);
|
||||||
|
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $diff_time,
|
my $exit_code = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
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))));
|
$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')) {
|
if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("%s: %s seconds (time: %s)", $name, $diff_time, scalar(localtime($time))));
|
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',
|
$self->{output}->perfdata_add(
|
||||||
value => $diff_time,
|
label => $name, unit => 's',
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
value => $diff_time,
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
);
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{output}->display();
|
$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!!!
|
Filter files/directories in the plugin. Values from exclude files/directories are counted in parent directories!!!
|
||||||
Perl Regexp can be used.
|
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
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
|
@ -31,27 +31,18 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'warning-one:s' => { name => 'warning_one' },
|
||||||
"hostname:s" => { name => 'hostname' },
|
'critical-one:s' => { name => 'critical_one' },
|
||||||
"remote" => { name => 'remote' },
|
'warning-total:s' => { name => 'warning_total' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'critical-total:s' => { name => 'critical_total' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
'separate-dirs' => { name => 'separate_dirs' },
|
||||||
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
|
'max-depth:s' => { name => 'max_depth' },
|
||||||
"timeout:s" => { name => 'timeout', default => 30 },
|
'all-files' => { name => 'all_files' },
|
||||||
"sudo" => { name => 'sudo' },
|
'exclude-du:s@' => { name => 'exclude_du' },
|
||||||
"command-path:s" => { name => 'command_path' },
|
'filter-plugin:s' => { name => 'filter_plugin' },
|
||||||
"warning-one:s" => { name => 'warning_one', },
|
'files:s' => { name => 'files' }
|
||||||
"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;
|
return $self;
|
||||||
}
|
}
|
||||||
|
@ -81,35 +72,31 @@ sub check_options {
|
||||||
$self->{output}->option_exit();
|
$self->{output}->option_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
#### Create command_options
|
$self->{command_options} = '-x -b';
|
||||||
$self->{option_results}->{command} = 'du';
|
|
||||||
$self->{option_results}->{command_options} = '-x -b';
|
|
||||||
if (defined($self->{option_results}->{separate_dirs})) {
|
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})) {
|
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})) {
|
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}}) {
|
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->{command_options} .= ' ' . $self->{option_results}->{files};
|
||||||
$self->{option_results}->{command_options} .= ' 2>&1';
|
$self->{command_options} .= ' 2>&1';
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
my $total_size = 0;
|
my $total_size = 0;
|
||||||
|
|
||||||
my $stdout = centreon::plugins::misc::execute(output => $self->{output},
|
my ($stdout) = $options{custom}->execute_command(
|
||||||
options => $self->{option_results},
|
command => 'du',
|
||||||
sudo => $self->{option_results}->{sudo},
|
command_options => $self->{command_options}
|
||||||
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',
|
$self->{output}->output_add(severity => 'OK',
|
||||||
short_msg => "All file/directory sizes are ok.");
|
short_msg => "All file/directory sizes are ok.");
|
||||||
|
@ -121,35 +108,47 @@ sub run {
|
||||||
$name !~ /$self->{option_results}->{filter_plugin}/);
|
$name !~ /$self->{option_results}->{filter_plugin}/);
|
||||||
|
|
||||||
$total_size += $size;
|
$total_size += $size;
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $size,
|
my $exit_code = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical_one', exit_litteral => 'critical' }, { label => 'warning_one', exit_litteral => 'warning' } ]);
|
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);
|
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));
|
$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')) {
|
if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("'%s' size is %s", $name, $size_value . ' ' . $size_unit));
|
severity => $exit_code,
|
||||||
|
short_msg => sprintf("'%s' size is %s", $name, $size_value . ' ' . $size_unit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$self->{output}->perfdata_add(label => $name, unit => 'B',
|
$self->{output}->perfdata_add(
|
||||||
value => $size,
|
label => $name, unit => 'B',
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_one'),
|
value => $size,
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_one'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_one'),
|
||||||
min => 0);
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_one'),
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
# Total Size
|
# Total Size
|
||||||
my $exit_code = $self->{perfdata}->threshold_check(value => $total_size,
|
my $exit_code = $self->{perfdata}->threshold_check(
|
||||||
threshold => [ { label => 'critical_total', exit_litteral => 'critical' }, { label => 'warning_total', exit_litteral => 'warning' } ]);
|
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);
|
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));
|
$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')) {
|
if (!$self->{output}->is_status(litteral => 1, value => $exit_code, compare => 'ok')) {
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
$self->{output}->output_add(
|
||||||
short_msg => sprintf("Total size is %s", $size_value . ' ' . $size_unit));
|
severity => $exit_code,
|
||||||
|
short_msg => sprintf('Total size is %s', $size_value . ' ' . $size_unit)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
$self->{output}->perfdata_add(label => 'total', unit => 'B',
|
$self->{output}->perfdata_add(
|
||||||
value => $total_size,
|
label => 'total', unit => 'B',
|
||||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_total'),
|
value => $total_size,
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_total'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_total'),
|
||||||
min => 0);
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_total'),
|
||||||
|
min => 0
|
||||||
|
);
|
||||||
|
|
||||||
$self->{output}->display();
|
$self->{output}->display();
|
||||||
$self->{output}->exit();
|
$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!!!
|
Filter files/directories in the plugin. Values from exclude files/directories are counted in parent directories!!!
|
||||||
Perl Regexp can be used.
|
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
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
|
@ -36,13 +36,13 @@ sub set_counters {
|
||||||
$self->{maps_counters}->{inodes} = [
|
$self->{maps_counters}->{inodes} = [
|
||||||
{ label => 'usage', set => {
|
{ label => 'usage', set => {
|
||||||
key_values => [ { name => 'used' }, { name => 'display' } ],
|
key_values => [ { name => 'used' }, { name => 'display' } ],
|
||||||
output_template => 'Used: %s %%',
|
output_template => 'used: %s %%',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'used', value => 'used', template => '%d',
|
{ label => 'used', template => '%d',
|
||||||
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' },
|
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' }
|
||||||
],
|
]
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,40 +57,26 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'filter-type:s' => { name => 'filter_type', },
|
||||||
"hostname:s" => { name => 'hostname' },
|
'filter-fs:s' => { name => 'filter_fs', },
|
||||||
"remote" => { name => 'remote' },
|
'name:s' => { name => 'name' },
|
||||||
"ssh-option:s@" => { name => 'ssh_option' },
|
'regexp' => { name => 'use_regexp' },
|
||||||
"ssh-path:s" => { name => 'ssh_path' },
|
'regexp-isensitive' => { name => 'use_regexpi' }
|
||||||
"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} = {};
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
my ($stdout, $exit_code) = centreon::plugins::misc::execute(
|
my ($stdout, $exit_code) = $options{custom}->execute_command(
|
||||||
output => $self->{output},
|
command => 'df',
|
||||||
options => $self->{option_results},
|
command_options => '-P -i -T 2>&1',
|
||||||
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_quit => 1
|
no_quit => 1
|
||||||
);
|
);
|
||||||
|
|
||||||
$self->{inodes} = {};
|
$self->{inodes} = {};
|
||||||
my @lines = split /\n/, $stdout;
|
my @lines = split /\n/, $stdout;
|
||||||
foreach my $line (@lines) {
|
foreach my $line (@lines) {
|
||||||
|
@ -110,6 +96,7 @@ sub manage_selection {
|
||||||
&& $mount ne $self->{option_results}->{name});
|
&& $mount ne $self->{option_results}->{name});
|
||||||
|
|
||||||
$percent =~ s/%//g;
|
$percent =~ s/%//g;
|
||||||
|
next if ($percent eq '-');
|
||||||
$self->{inodes}->{$mount} = { display => $mount, fs => $fs, type => $type, total => $size, used => $percent };
|
$self->{inodes}->{$mount} = { display => $mount, fs => $fs, type => $type, total => $size, used => $percent };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,49 +117,10 @@ __END__
|
||||||
|
|
||||||
Check Inodes space usage on partitions.
|
Check Inodes space usage on partitions.
|
||||||
|
|
||||||
|
Command used: df -P -i -T 2>&1
|
||||||
|
|
||||||
=over 8
|
=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>
|
=item B<--warning-usage>
|
||||||
|
|
||||||
Threshold warning in percent.
|
Threshold warning in percent.
|
||||||
|
|
Loading…
Reference in New Issue