This commit is contained in:
garnier-quentin 2019-03-25 14:57:10 +01:00
parent db50bade74
commit 56707e2473
1 changed files with 35 additions and 37 deletions

View File

@ -33,7 +33,8 @@ my %state_map = (
T => 'stopped', T => 'stopped',
S => 'InterruptibleSleep', S => 'InterruptibleSleep',
R => 'running', R => 'running',
D => 'UninterrupibleSleep' D => 'UninterrupibleSleep',
I => 'IdleKernelThread',
); );
sub new { sub new {
@ -42,27 +43,27 @@ sub new {
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments => {
{ "hostname:s" => { name => 'hostname' },
"hostname:s" => { name => 'hostname' }, "remote" => { name => 'remote' },
"remote" => { name => 'remote' }, "ssh-option:s@" => { name => 'ssh_option' },
"ssh-option:s@" => { name => 'ssh_option' }, "ssh-path:s" => { name => 'ssh_path' },
"ssh-path:s" => { name => 'ssh_path' }, "ssh-command:s" => { name => 'ssh_command', default => 'ssh' },
"ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, "timeout:s" => { name => 'timeout', default => 30 },
"timeout:s" => { name => 'timeout', default => 30 }, "sudo" => { name => 'sudo' },
"sudo" => { name => 'sudo' }, "command:s" => { name => 'command', default => 'ps' },
"command:s" => { name => 'command', default => 'ps' }, "command-path:s" => { name => 'command_path' },
"command-path:s" => { name => 'command_path' }, "command-options:s" => { name => 'command_options', default => '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a -w 2>&1' },
"command-options:s" => { name => 'command_options', default => '-e -o etime,pid,ppid,state,comm,args -w 2>&1' }, "warning:s" => { name => 'warning' },
"warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' },
"critical:s" => { name => 'critical' }, "warning-time:s" => { name => 'warning_time' },
"warning-time:s" => { name => 'warning_time' }, "critical-time:s" => { name => 'critical_time' },
"critical-time:s" => { name => 'critical_time' }, "filter-command:s" => { name => 'filter_command' },
"filter-command:s" => { name => 'filter_command' }, "filter-arg:s" => { name => 'filter_arg' },
"filter-arg:s" => { name => 'filter_arg' }, "filter-state:s" => { name => 'filter_state' },
"filter-state:s" => { name => 'filter_state' }, "filter-ppid:s" => { name => 'filter_ppid' },
"filter-ppid:s" => { name => 'filter_ppid' }, });
});
$self->{result} = {}; $self->{result} = {};
return $self; return $self;
} }
@ -70,6 +71,7 @@ sub new {
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::init(%options); $self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { 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}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit(); $self->{output}->option_exit();
@ -98,22 +100,18 @@ sub parse_output {
command_path => $self->{option_results}->{command_path}, command_path => $self->{option_results}->{command_path},
command_options => $self->{option_results}->{command_options}); command_options => $self->{option_results}->{command_options});
my @lines = split /\n/, $stdout; my @lines = split /\n/, $stdout;
# Header to manage output
# ELAPSED PID PPID S COMMAND COMMAND
my $line = shift @lines; my $line = shift @lines;
$line =~ /^(\s*?\S+\s*?\S+\s*?\S+\s*?\S+\s*?)(\S+\s*?)\S+/;
my ($pos1, $pos2) = (length($1), length($1) + length($2));
foreach my $line (@lines) { foreach my $line (@lines) {
$line =~ /^(\s*?\S+\s*?)(\S+\s*?)(\S+\s*?)(\S+\s*?)/; next if ($line !~ /^(.*?)===(.*?)===(.*?)===(.*?)===(.*?)===(.*)$/);
my ($elapsed, $pid, $ppid, $state) = ($1, $2, $3, $4); my ($state, $elapsed, $pid, $ppid, $cmd, $args) = ($1, $2, $3, $4, $5, $6);
my $cmd = substr($line, $pos1, $pos2 - $pos1);
my $args = substr($line, $pos2);
$self->{result}->{centreon::plugins::misc::trim($pid)} = {ppid => centreon::plugins::misc::trim($ppid), $self->{result}->{centreon::plugins::misc::trim($pid)} = {
state => centreon::plugins::misc::trim($state), ppid => centreon::plugins::misc::trim($ppid),
elapsed => centreon::plugins::misc::trim($elapsed), state => centreon::plugins::misc::trim($state),
cmd => centreon::plugins::misc::trim($cmd), elapsed => centreon::plugins::misc::trim($elapsed),
args => centreon::plugins::misc::trim($args)}; cmd => centreon::plugins::misc::trim($cmd),
args => centreon::plugins::misc::trim($args)
};
} }
} }
@ -155,7 +153,7 @@ sub run {
$self->{result}->{$pid}->{args} !~ /$self->{option_results}->{filter_arg}/); $self->{result}->{$pid}->{args} !~ /$self->{option_results}->{filter_arg}/);
next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' && next if (defined($self->{option_results}->{filter_state}) && $self->{option_results}->{filter_state} ne '' &&
$state_map{$self->{result}->{$pid}->{state}} !~ /$self->{option_results}->{filter_state}/i); $state_map{$self->{result}->{$pid}->{state}} !~ /$self->{option_results}->{filter_state}/i);
next if (defined($self->{option_results}->{filter_ppid}) && $self->{option_results}->{filter_ppid} ne '' && next if (defined($self->{option_results}->{filter_ppid}) && $self->{option_results}->{filter_ppid} ne '' &&
$self->{result}->{$pid}->{ppid} !~ /$self->{option_results}->{filter_ppid}/); $self->{result}->{$pid}->{ppid} !~ /$self->{option_results}->{filter_ppid}/);
$self->{output}->output_add(long_msg => 'Process: [command => ' . $self->{result}->{$pid}->{cmd} . $self->{output}->output_add(long_msg => 'Process: [command => ' . $self->{result}->{$pid}->{cmd} .
@ -228,7 +226,7 @@ Command path (Default: none).
=item B<--command-options> =item B<--command-options>
Command options (Default: '-e -o etime,pid,ppid,state,comm,args -w 2>&1'). Command options (Default: '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a -w 2>&1').
=item B<--warning> =item B<--warning>