refacto linux local
This commit is contained in:
parent
f0e668fb10
commit
bd2c73b8a2
|
@ -110,7 +110,7 @@ sub execute_command {
|
|||
hostname => $self->{option_results}->{hostname},
|
||||
sudo => $self->{option_results}->{sudo},
|
||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_path => defined($self->{option_results}->{command}) && $self->{option_results}->{command_path} ne '' ? $self->{option_results}->{command_path} : $options{command_path},
|
||||
command_options => $command_options,
|
||||
timeout => $timeout,
|
||||
no_quit => $options{no_quit}
|
||||
|
@ -121,7 +121,7 @@ sub execute_command {
|
|||
sudo => $self->{option_results}->{sudo},
|
||||
options => { timeout => $timeout },
|
||||
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_path => defined($self->{option_results}->{command}) && $self->{option_results}->{command_path} ne '' ? $self->{option_results}->{command_path} : $options{command_path},
|
||||
command_options => $command_options,
|
||||
no_quit => $options{no_quit}
|
||||
);
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
my %map_ss_states = (
|
||||
UNCONN => 'closed',
|
||||
|
@ -410,7 +409,7 @@ nagios-perfdata - number of connections.
|
|||
|
||||
=item B<--con-mode>
|
||||
|
||||
Default mode for parsing and command (Default: 'netstat').
|
||||
Default mode for parsing and command: 'netstat' (default) or 'ss'.
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub custom_cpu_avg_calc {
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::statefile;
|
||||
|
||||
my $maps = [
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
|
||||
sub custom_usage_calc {
|
||||
|
|
|
@ -32,14 +32,14 @@ sub new {
|
|||
bless $self, $class;
|
||||
|
||||
$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' }
|
||||
'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;
|
||||
|
|
|
@ -98,8 +98,10 @@ sub run {
|
|||
command_options => $self->{command_options}
|
||||
);
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => "All file/directory sizes are ok.");
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => "All file/directory sizes are ok."
|
||||
);
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
next if (!/(\d+)\t+(.*)/);
|
||||
my ($size, $name) = ($1, centreon::plugins::misc::trim($2));
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -32,23 +31,12 @@ 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 => 'ip' },
|
||||
"command-path:s" => { name => 'command_path', default => '/sbin' },
|
||||
"command-options:s" => { name => 'command_options', default => '-s addr 2>&1' },
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"filter-state:s" => { name => 'filter_state' },
|
||||
"no-loopback" => { name => 'no_loopback' },
|
||||
"skip-novalues" => { name => 'skip_novalues' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-state:s' => { name => 'filter_state' },
|
||||
'no-loopback' => { name => 'no_loopback' },
|
||||
'skip-novalues' => { name => 'skip_novalues' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -60,31 +48,29 @@ sub check_options {
|
|||
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_path => '/sbin',
|
||||
command => 'ip',
|
||||
command_options => '-s addr 2>&1'
|
||||
);
|
||||
|
||||
|
||||
my $mapping = {
|
||||
ifconfig => {
|
||||
get_interface => '^(\S+)(.*?)(\n\n|\n$)',
|
||||
test => 'RX bytes:\S+.*?TX bytes:\S+',
|
||||
test => 'RX bytes:\S+.*?TX bytes:\S+'
|
||||
},
|
||||
iproute => {
|
||||
get_interface => '^\d+:\s+(\S+)(.*?)(?=\n\d|\Z$)',
|
||||
test => 'RX:\s+bytes.*?\d+',
|
||||
},
|
||||
test => 'RX:\s+bytes.*?\d+'
|
||||
}
|
||||
};
|
||||
|
||||
my $type = 'ifconfig';
|
||||
if ($stdout =~ /^\d+:\s+\S+:\s+</ms) {
|
||||
$type = 'iproute';
|
||||
}
|
||||
|
||||
|
||||
my $results = {};
|
||||
while ($stdout =~ /$mapping->{$type}->{get_interface}/msg) {
|
||||
my ($interface_name, $values) = ($1, $2);
|
||||
$interface_name =~ s/:$//;
|
||||
|
@ -112,38 +98,42 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$interface_name} = { state => $states };
|
||||
$results->{$interface_name} = { state => $states };
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [state = '" . $self->{result}->{$name}->{state} . "']");
|
||||
my $results = $self->manage_selection(custom => $options{custom});
|
||||
foreach my $name (sort(keys %$results)) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [state = '" . $results->{$name}->{state} . "']");
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List interfaces:');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List interfaces:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
||||
sub disco_format {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
$self->{output}->add_disco_format(elements => ['name', 'state']);
|
||||
}
|
||||
|
||||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
my $results = $self->manage_selection(custom => $options{custom});
|
||||
foreach my $name (sort(keys %$results)) {
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $name,
|
||||
state => $self->{result}->{$name}->{state}
|
||||
state => $results->{$name}->{state}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -156,49 +146,10 @@ __END__
|
|||
|
||||
List storages.
|
||||
|
||||
Command used: /sbin/ip -s addr 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: 'ip').
|
||||
Can be changed if you have output in a file.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: '/sbin').
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '-s addr 2>&1').
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter interface name (regexp can be used).
|
||||
|
|
|
@ -24,28 +24,16 @@ 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 => 'cat' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '/proc/partitions 2>&1' },
|
||||
"filter-name:s" => { name => 'filter_name', },
|
||||
});
|
||||
$self->{result} = {};
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -57,12 +45,12 @@ sub check_options {
|
|||
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 => 'cat',
|
||||
command_options => '/proc/partitions 2>&1'
|
||||
);
|
||||
|
||||
my $results = {};
|
||||
my @lines = split /\n/, $stdout;
|
||||
# Header not needed
|
||||
shift @lines;
|
||||
|
@ -76,20 +64,24 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$name} = 1;
|
||||
$results->{$name} = 1;
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
my $results = $self->manage_selection(custom => $options{custom});
|
||||
foreach my $name (sort(keys %$results)) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "'");
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List partitions:');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List partitions:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -103,10 +95,9 @@ sub disco_format {
|
|||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->add_disco_entry(name => $name,
|
||||
);
|
||||
my $results = $self->manage_selection(custom => $options{custom});
|
||||
foreach my $name (sort(keys %$results)) {
|
||||
$self->{output}->add_disco_entry(name => $name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,53 +109,14 @@ __END__
|
|||
|
||||
List partitions.
|
||||
|
||||
Command used: cat /proc/partitions 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: 'cat').
|
||||
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: '/proc/partitions 2>&1').
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter partition name (regexp can be used).
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
=cut
|
||||
|
|
|
@ -24,30 +24,18 @@ 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 => 'df' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-P -k -T 2>&1' },
|
||||
"filter-type:s" => { name => 'filter_type', },
|
||||
"filter-fs:s" => { name => 'filter_fs', },
|
||||
"filter-mount:s" => { name => 'filter_mount', },
|
||||
});
|
||||
$self->{result} = {};
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-type:s' => { name => 'filter_type' },
|
||||
'filter-fs:s' => { name => 'filter_fs' },
|
||||
'filter-mount:s' => { name => 'filter_mount' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -59,15 +47,13 @@ sub check_options {
|
|||
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) = $options{custom}->execute_command(
|
||||
command => 'df',
|
||||
command_options => '-P -k -T 2>&1',
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
my $results = {};
|
||||
my @lines = split /\n/, $stdout;
|
||||
foreach my $line (@lines) {
|
||||
next if ($line !~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/);
|
||||
|
@ -75,34 +61,38 @@ sub manage_selection {
|
|||
|
||||
if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' &&
|
||||
$fs !~ /$self->{option_results}->{filter_fs}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter filesystem");
|
||||
$self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter filesystem", debug => 1);
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' &&
|
||||
$type !~ /$self->{option_results}->{filter_type}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter filesystem type");
|
||||
$self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter filesystem type", debug => 1);
|
||||
next;
|
||||
}
|
||||
if (defined($self->{option_results}->{filter_mount}) && $self->{option_results}->{filter_mount} ne '' &&
|
||||
$mount !~ /$self->{option_results}->{filter_mount}/) {
|
||||
$self->{output}->output_add(long_msg => "Skipping storage '" . $mount . "': no matching filter mount point");
|
||||
$self->{output}->output_add(long_msg => "skipping storage '" . $mount . "': no matching filter mount point", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
$self->{result}->{$mount} = {fs => $fs, type => $type};
|
||||
|
||||
$results->{$mount} = { fs => $fs, type => $type };
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $self->{result}->{$name}->{fs} . '] [type = ' . $self->{result}->{$name}->{type} . ']');
|
||||
my $results = $self->manage_selection(custom => $options{custom});
|
||||
foreach my $name (sort(keys %$results)) {
|
||||
$self->{output}->output_add(long_msg => "'" . $name . "' [fs = " . $results->{$name}->{fs} . '] [type = ' . $results->{$name}->{type} . ']');
|
||||
}
|
||||
|
||||
$self->{output}->output_add(severity => 'OK',
|
||||
short_msg => 'List storages:');
|
||||
$self->{output}->output_add(
|
||||
severity => 'OK',
|
||||
short_msg => 'List storages:'
|
||||
);
|
||||
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -116,12 +106,13 @@ sub disco_format {
|
|||
sub disco_show {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->manage_selection();
|
||||
foreach my $name (sort(keys %{$self->{result}})) {
|
||||
$self->{output}->add_disco_entry(name => $name,
|
||||
fs => $self->{result}->{$name}->{fs},
|
||||
type => $self->{result}->{$name}->{type},
|
||||
);
|
||||
my $results = $self->manage_selection(custom => $options{custom});
|
||||
foreach my $name (sort(keys %$results)) {
|
||||
$self->{output}->add_disco_entry(
|
||||
name => $name,
|
||||
fs => $results->{$name}->{fs},
|
||||
type => $results->{$name}->{type},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,49 +124,10 @@ __END__
|
|||
|
||||
List storages.
|
||||
|
||||
Command used: df -P -k -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 -k -T 2>&1').
|
||||
|
||||
=item B<--filter-type>
|
||||
|
||||
Filter filesystem type (regexp can be used).
|
||||
|
@ -190,4 +142,4 @@ Filter mount point (regexp can be used).
|
|||
|
||||
=back
|
||||
|
||||
=cut
|
||||
=cut
|
||||
|
|
|
@ -24,29 +24,18 @@ 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 => 'tail' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-n +1 /proc/loadavg /proc/stat 2>&1' },
|
||||
"warning:s" => { name => 'warning', default => '' },
|
||||
"critical:s" => { name => 'critical', default => '' },
|
||||
"average" => { name => 'average' },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning:s' => { name => 'warning', default => '' },
|
||||
'critical:s' => { name => 'critical', default => '' },
|
||||
'average' => { name => 'average' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -86,12 +75,10 @@ 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 => 'tail',
|
||||
command_options => '-n +1 /proc/loadavg /proc/stat 2>&1'
|
||||
);
|
||||
|
||||
my ($load1m, $load5m, $load15m);
|
||||
my ($msg, $cpu_load1, $cpu_load5, $cpu_load15);
|
||||
|
@ -123,57 +110,75 @@ sub run {
|
|||
$msg = sprintf("Load average: %s [%s/%s CPUs], %s [%s/%s CPUs], %s [%s/%s CPUs]", $cpu_load1, $load1m, $countCpu,
|
||||
$cpu_load5, $load5m, $countCpu,
|
||||
$cpu_load15, $load15m, $countCpu);
|
||||
$self->{output}->perfdata_add(label => 'avg_load1',
|
||||
value => $cpu_load1,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'avg_load5',
|
||||
value => $cpu_load5,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'avg_load15',
|
||||
value => $cpu_load15,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'load1',
|
||||
value => $load1m,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1', op => '*', value => $countCpu),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1', op => '*', value => $countCpu),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'load5',
|
||||
value => $load5m,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5', op => '*', value => $countCpu),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5', op => '*', value => $countCpu),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'load15',
|
||||
value => $load15m,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15', op => '*', value => $countCpu),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15', op => '*', value => $countCpu),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'avg_load1',
|
||||
value => $cpu_load1,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'avg_load5',
|
||||
value => $cpu_load5,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'avg_load15',
|
||||
value => $cpu_load15,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'load1',
|
||||
value => $load1m,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1', op => '*', value => $countCpu),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1', op => '*', value => $countCpu),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'load5',
|
||||
value => $load5m,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5', op => '*', value => $countCpu),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5', op => '*', value => $countCpu),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'load15',
|
||||
value => $load15m,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15', op => '*', value => $countCpu),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15', op => '*', value => $countCpu),
|
||||
min => 0
|
||||
);
|
||||
} else {
|
||||
$cpu_load1 = $load1m;
|
||||
$cpu_load5 = $load5m;
|
||||
$cpu_load15 = $load15m;
|
||||
|
||||
$msg = sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15);
|
||||
$self->{output}->perfdata_add(label => 'load1',
|
||||
value => $cpu_load1,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'load5',
|
||||
value => $cpu_load5,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(label => 'load15',
|
||||
value => $cpu_load15,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'load1',
|
||||
value => $cpu_load1,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'load5',
|
||||
value => $cpu_load5,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn5'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit5'),
|
||||
min => 0
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'load15',
|
||||
value => $cpu_load15,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn15'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit15'),
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
|
||||
my $exit1 = $self->{perfdata}->threshold_check(value => $cpu_load1,
|
||||
|
@ -183,8 +188,10 @@ sub run {
|
|||
my $exit3 = $self->{perfdata}->threshold_check(value => $cpu_load15,
|
||||
threshold => [ { label => 'crit15', 'exit_litteral' => 'critical' }, { label => 'warn15', exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => $msg);
|
||||
$self->{output}->output_add(
|
||||
severity => $exit,
|
||||
short_msg => $msg
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
@ -198,6 +205,8 @@ __END__
|
|||
|
||||
Check system load-average. (need '/proc/loadavg' file).
|
||||
|
||||
Command used: tail -n +1 /proc/loadavg /proc/stat 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
@ -212,47 +221,6 @@ Threshold critical (1min,5min,15min).
|
|||
|
||||
Load average for the number of CPUs.
|
||||
|
||||
=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: '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: '-n +1 /proc/loadavg /proc/stat 2>&1').
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
|
@ -32,18 +31,8 @@ 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 => 'cat' },
|
||||
'command-path:s' => { name => 'command_path' },
|
||||
'command-options:s' => { name => 'command_options', default => '/proc/meminfo /etc/redhat-release 2>&1' },
|
||||
'warning:s' => { name => 'warning' },
|
||||
'critical:s' => { name => 'critical' },
|
||||
'warning:s' => { name => 'warning' },
|
||||
'critical:s' => { name => 'critical' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -74,13 +63,9 @@ sub check_rhel_version {
|
|||
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 => 'cat',
|
||||
command_options => '/proc/meminfo /etc/redhat-release 2>&1',
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
|
@ -172,6 +157,8 @@ __END__
|
|||
|
||||
Check physical memory (need '/proc/meminfo' file).
|
||||
|
||||
Command used: cat /proc/meminfo /etc/redhat-release 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning>
|
||||
|
@ -182,47 +169,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: 'cat').
|
||||
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: '/proc/meminfo 2>&1').
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
|
||||
sub custom_status_output {
|
||||
|
@ -51,7 +50,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'display' }, { name => 'options' }, { name => 'type' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
}
|
||||
];
|
||||
|
@ -62,25 +61,14 @@ 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 => 'mount' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => ' 2>&1' },
|
||||
"filter-device:s" => { name => 'filter_device' },
|
||||
"filter-mountpoint:s" => { name => 'filter_mountpoint' },
|
||||
"filter-type:s" => { name => 'filter_type' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{options} !~ /^rw/i && %{type} !~ /tmpfs/i' },
|
||||
});
|
||||
$self->{result} = {};
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-device:s' => { name => 'filter_device' },
|
||||
'filter-mountpoint:s' => { name => 'filter_mountpoint' },
|
||||
'filter-type:s' => { name => 'filter_type' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{options} !~ /^rw/i && %{type} !~ /tmpfs|squashfs/i' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -94,13 +82,9 @@ sub check_options {
|
|||
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) = $options{custom}->execute_command(
|
||||
command => 'mount',
|
||||
command_options => '2>&1',
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
|
@ -148,48 +132,10 @@ __END__
|
|||
|
||||
Check mount points options.
|
||||
|
||||
Command used: mount 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: 'mount').
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: ' 2>&1').
|
||||
|
||||
=item B<--filter-mountpoint>
|
||||
|
||||
Filter mount point name (Can use regexp).
|
||||
|
@ -209,7 +155,7 @@ Threshold warning.
|
|||
=item B<--critical-status>
|
||||
|
||||
Threshold critical
|
||||
(Default: '%{options} !~ /^rw/i && %{type} !~ /tmpfs/i').
|
||||
(Default: '%{options} !~ /^rw/i && %{type} !~ /tmpfs|squashfs/i').
|
||||
|
||||
=back
|
||||
|
||||
|
|
|
@ -71,12 +71,12 @@ my %unit_map_chronyc = (
|
|||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf("[type: %s] [reach: %s] [state: %s]",
|
||||
return sprintf(
|
||||
'[type: %s] [reach: %s] [state: %s]',
|
||||
$self->{result_values}->{type},
|
||||
$self->{result_values}->{reach},
|
||||
$self->{result_values}->{state}
|
||||
);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_status_calc {
|
||||
|
@ -142,11 +142,10 @@ sub set_counters {
|
|||
key_values => [ { name => 'peers' } ],
|
||||
output_template => 'Number of ntp peers : %d',
|
||||
perfdatas => [
|
||||
{ label => 'peers', value => 'peers', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
{ label => 'peers', template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{peers} = [
|
||||
|
@ -155,7 +154,7 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_status_calc'),
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
},
|
||||
{ label => 'offset', display_ok => 0, set => {
|
||||
|
@ -164,20 +163,18 @@ sub set_counters {
|
|||
closure_custom_threshold_check => $self->can('custom_offset_threshold'),
|
||||
closure_custom_perfdata => $self->can('custom_offset_perfdata'),
|
||||
perfdatas => [
|
||||
{ label => 'offset', value => 'offset', template => '%s',
|
||||
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'offset', template => '%s', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'stratum', display_ok => 0, set => {
|
||||
key_values => [ { name => 'stratum' }, { name => 'display' } ],
|
||||
output_template => 'Stratum : %s',
|
||||
perfdatas => [
|
||||
{ label => 'stratum', value => 'stratum', template => '%s',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
{ label => 'stratum', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -193,21 +190,12 @@ 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 => 'ntpq' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '' },
|
||||
"filter-name:s" => { name => 'filter_name' },
|
||||
"filter-state:s" => { name => 'filter_state' },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '' },
|
||||
'ntp-mode:s' => { name => 'ntp_mode', default => 'ntpq' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'filter-state:s' => { name => 'filter_state' },
|
||||
'unknown-status:s' => { name => 'unknown_status', default => '' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -217,14 +205,16 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if ($self->{option_results}->{command} eq 'ntpq') {
|
||||
if ($self->{option_results}->{ntp_mode} eq 'ntpq') {
|
||||
$self->{regex} = '^(\+|\*|\.|\-|\#|x|\<sp\>|o)(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)';
|
||||
$self->{option_results}->{command_options} = '-p -n 2>&1';
|
||||
} elsif ($self->{option_results}->{command} eq 'chronyc') {
|
||||
$self->{command} = 'ntpq';
|
||||
$self->{command_options} = '-p -n 2>&1';
|
||||
} elsif ($self->{option_results}->{ntp_mode} eq 'chronyc') {
|
||||
$self->{regex} = '^(.)(\+|\*|\.|\-|\#|x|\<sp\>)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*?)(\d+)(\w+)$';
|
||||
$self->{option_results}->{command_options} = '-n sources 2>&1';
|
||||
$self->{command} = 'chronyc';
|
||||
$self->{command_options} = '-n sources 2>&1';
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "command '" . $self->{option_results}->{command} . "' not implemented" );
|
||||
$self->{output}->add_option_msg(short_msg => "ntp mode '" . $self->{option_results}->{ntp_mode} . "' not implemented" );
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
|
@ -233,14 +223,10 @@ sub check_options {
|
|||
|
||||
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 => $self->{command},
|
||||
command_options => $self->{command_options}
|
||||
);
|
||||
|
||||
$self->{global} = { peers => 0 };
|
||||
|
@ -310,44 +296,13 @@ __END__
|
|||
|
||||
Check ntp daemons.
|
||||
|
||||
Command used: 'ntpq -p -n 2>&1' or 'chronyc -n sources 2>&1'
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
=item B<--con-mode>
|
||||
|
||||
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: 'ntpq').
|
||||
Can also be 'chronyc'.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
Default mode for parsing and command: 'ntpq' (default) or 'chronyc'.
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -38,10 +37,10 @@ sub set_counters {
|
|||
key_values => [ { name => 'openfiles' } ],
|
||||
output_template => 'current open files: %s',
|
||||
perfdatas => [
|
||||
{ value => 'openfiles', template => '%s', min => 0 },
|
||||
],
|
||||
{ template => '%s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -51,44 +50,20 @@ 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 => 'lsof' },
|
||||
'command-path:s' => { name => 'command_path' },
|
||||
'command-options:s' => { name => 'command_options', default => '-a -d ^mem -d ^cwd -d ^rtd -d ^txt -d ^DEL 2>&1' },
|
||||
'filter-username:s' => { name => 'filter_username' },
|
||||
'filter-appname:s' => { name => 'filter_appname' },
|
||||
'filter-pid:s' => { name => 'filter_pid' },
|
||||
'filter-pid:s' => { name => 'filter_pid' }
|
||||
});
|
||||
|
||||
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 => 'lsof',
|
||||
command_options => '-a -d ^mem -d ^cwd -d ^rtd -d ^txt -d ^DEL 2>&1'
|
||||
);
|
||||
|
||||
$self->{global} = { openfiles => 0 };
|
||||
|
@ -116,49 +91,10 @@ __END__
|
|||
|
||||
Check open files.
|
||||
|
||||
Command used: lsof -a -d ^mem -d ^cwd -d ^rtd -d ^txt -d ^DEL 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: 'lsof').
|
||||
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 -d ^mem -d ^cwd -d ^rtd -d ^txt -d ^DEL 2>&1').
|
||||
|
||||
=item B<--filter-appname>
|
||||
|
||||
Filter application name (can be a regexp).
|
||||
|
|
|
@ -26,7 +26,6 @@ use strict;
|
|||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -37,7 +36,8 @@ sub custom_status_output {
|
|||
sub custom_packet_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return sprintf('Packet %s %s : %.2f %% (%s)',
|
||||
return sprintf(
|
||||
'Packet %s %s : %.2f %% (%s)',
|
||||
ucfirst($self->{result_values}->{type}),
|
||||
ucfirst($self->{result_values}->{label}),
|
||||
$self->{result_values}->{result_prct},
|
||||
|
@ -64,7 +64,7 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', skipped_code => { -10 => 1 } },
|
||||
{ name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{interface} = [
|
||||
|
@ -72,7 +72,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'status' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
},
|
||||
{ label => 'in-discard', set => {
|
||||
|
@ -82,8 +82,8 @@ sub set_counters {
|
|||
threshold_use => 'result_prct',
|
||||
perfdatas => [
|
||||
{ label => 'packets_discard_in', value => 'result_prct', template => '%.2f', min => 0, max => 100,
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'out-discard', set => {
|
||||
|
@ -93,8 +93,8 @@ sub set_counters {
|
|||
threshold_use => 'result_prct',
|
||||
perfdatas => [
|
||||
{ label => 'packets_discard_out', value => 'result_prct', template => '%.2f', min => 0, max => 100,
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'in-error', set => {
|
||||
|
@ -104,8 +104,8 @@ sub set_counters {
|
|||
threshold_use => 'result_prct',
|
||||
perfdatas => [
|
||||
{ label => 'packets_error_in', value => 'result_prct', template => '%.2f', min => 0, max => 100,
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'out-error', set => {
|
||||
|
@ -115,10 +115,10 @@ sub set_counters {
|
|||
threshold_use => 'result_prct',
|
||||
perfdatas => [
|
||||
{ label => 'packets_error_out', value => 'result_prct', template => '%.2f', min => 0, max => 100,
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' },
|
||||
],
|
||||
unit => '%', label_extra_instance => 1, instance_use => 'display' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -128,24 +128,14 @@ 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 => 'ip' },
|
||||
"command-path:s" => { name => 'command_path', default => '/sbin' },
|
||||
"command-options:s" => { name => 'command_options', default => '-s addr 2>&1' },
|
||||
"filter-state:s" => { name => 'filter_state', },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
"no-loopback" => { name => 'no_loopback', },
|
||||
"unknown-status:s" => { name => 'unknown_status', default => '' },
|
||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
||||
"critical-status:s" => { name => 'critical_status', default => '%{status} ne "RU"' },
|
||||
'filter-state:s' => { name => 'filter_state', },
|
||||
'name:s' => { name => 'name' },
|
||||
'regexp' => { name => 'use_regexp' },
|
||||
'regexp-isensitive' => { name => 'use_regexpi' },
|
||||
'no-loopback' => { name => 'no_loopback', },
|
||||
'unknown-status:s' => { name => 'unknown_status', default => '' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{status} ne "RU"' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -161,24 +151,16 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->{hostname} = $self->{option_results}->{hostname};
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{hostname} = 'me';
|
||||
}
|
||||
|
||||
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']);
|
||||
}
|
||||
|
||||
sub do_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 => 'ip',
|
||||
command_path => '/sbin',
|
||||
command_options => '-s addr 2>&1'
|
||||
);
|
||||
|
||||
my $mapping = {
|
||||
|
@ -249,8 +231,8 @@ sub do_selection {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->do_selection();
|
||||
$self->{cache_name} = "cache_linux_local_" . $self->{hostname} . '_' . $self->{mode} . '_' .
|
||||
$self->do_selection(custom => $options{custom});
|
||||
$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'));
|
||||
}
|
||||
|
@ -263,6 +245,8 @@ __END__
|
|||
|
||||
Check packets errors and discards on interfaces.
|
||||
|
||||
Command used: /sbin/ip -s addr 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
|
|
|
@ -25,7 +25,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
use strict;
|
||||
use warnings;
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -40,8 +39,8 @@ sub set_counters {
|
|||
output_template => 'pgpgin : %s %s/s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'pgpgin', template => '%d', unit => 'B/s', min => 0 },
|
||||
],
|
||||
{ label => 'pgpgin', template => '%d', unit => 'B/s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'pgpgout', nlabel => 'system.pgpgout.usage.bytespersecond', set => {
|
||||
|
@ -49,8 +48,8 @@ sub set_counters {
|
|||
output_template => 'pgpgout : %s %s/s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'pgpgout', template => '%d', unit => 'B/s', min => 0 },
|
||||
],
|
||||
{ label => 'pgpgout', template => '%d', unit => 'B/s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'pswpin', nlabel => 'system.pswpin.usage.bytespersecond', set => {
|
||||
|
@ -58,8 +57,8 @@ sub set_counters {
|
|||
output_template => 'pswpin : %s %s/s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'pswpin', template => '%d', unit => 'B/s', min => 0 },
|
||||
],
|
||||
{ label => 'pswpin', template => '%d', unit => 'B/s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'pswpout', nlabel => 'system.pswpout.usage.bytespersecond', set => {
|
||||
|
@ -67,8 +66,8 @@ sub set_counters {
|
|||
output_template => 'pswpout : %s %s/s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'pswpout', template => '%d', unit => 'B/s', min => 0 },
|
||||
],
|
||||
{ label => 'pswpout', template => '%d', unit => 'B/s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'pgfault', nlabel => 'system.pgfault.usage.bytespersecond', set => {
|
||||
|
@ -76,8 +75,8 @@ sub set_counters {
|
|||
output_template => 'pgfault : %s %s/s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'pgfault', template => '%d', unit => 'B/s', min => 0 },
|
||||
],
|
||||
{ label => 'pgfault', template => '%d', unit => 'B/s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'pgmajfault', nlabel => 'system.pgmajfault.usage.bytespersecond', set => {
|
||||
|
@ -85,10 +84,10 @@ sub set_counters {
|
|||
output_template => 'pgmajfault : %s %s/s',
|
||||
output_change_bytes => 1,
|
||||
perfdatas => [
|
||||
{ label => 'pgmajfault', template => '%d', unit => 'B/s', min => 0 },
|
||||
],
|
||||
{ label => 'pgmajfault', template => '%d', unit => 'B/s', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -98,16 +97,6 @@ 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 => 'cat' },
|
||||
'command-path:s' => { name => 'command_path' },
|
||||
'command-options:s' => { name => 'command_options', default => '/proc/vmstat 2>&1' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -119,26 +108,12 @@ sub prefix_global_output {
|
|||
return 'Paging ';
|
||||
}
|
||||
|
||||
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 => 'cat',
|
||||
command_options => '/proc/vmstat 2>&1'
|
||||
);
|
||||
|
||||
$self->{global} = {};
|
||||
|
@ -149,7 +124,7 @@ sub manage_selection {
|
|||
$self->{global}->{pgfault} = $stdout =~ /^pgfault.*?(\d+)/msi ? $1 * 1024: undef;
|
||||
$self->{global}->{pgmajfault} = $stdout =~ /^pgmajfault.*?(\d+)/msi ? $1 * 1014: undef;
|
||||
|
||||
$self->{cache_name} = "cache_linux_local_" . $self->{hostname} . '_' . $self->{mode} . '_' .
|
||||
$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'));
|
||||
}
|
||||
|
||||
|
@ -161,49 +136,10 @@ __END__
|
|||
|
||||
Check paging informations.
|
||||
|
||||
Command used: cat /proc/vmstat 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: 'cat').
|
||||
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: '/proc/vmstat 2>&1').
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -39,44 +38,32 @@ sub set_counters {
|
|||
key_values => [ { name => 'total' } ],
|
||||
output_template => 'Number of pending updates : %d',
|
||||
perfdatas => [
|
||||
{ label => 'total', value => 'total', template => '%d',
|
||||
min => 0 },
|
||||
],
|
||||
{ label => 'total', template => '%d', min => 0 }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{updates} = [
|
||||
{ label => 'update', set => {
|
||||
key_values => [ { name => 'package' }, { name => 'version' }, { name => 'repository' } ],
|
||||
closure_custom_calc => $self->can('custom_updates_calc'),
|
||||
closure_custom_output => $self->can('custom_updates_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => sub { return 'ok'; }
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
sub custom_updates_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf(
|
||||
return sprintf(
|
||||
"Package '%s' [version: %s] [repository: %s]",
|
||||
$self->{result_values}->{package},
|
||||
$self->{result_values}->{version},
|
||||
$self->{result_values}->{repository}
|
||||
);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub custom_updates_calc {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{result_values}->{package} = $options{new_datas}->{$self->{instance} . '_package'};
|
||||
$self->{result_values}->{version} = $options{new_datas}->{$self->{instance} . '_version'};
|
||||
$self->{result_values}->{repository} = $options{new_datas}->{$self->{instance} . '_repository'};
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub new {
|
||||
|
@ -85,34 +72,42 @@ 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 => 'yum' },
|
||||
'command-path:s' => { name => 'command_path', },
|
||||
'command-options:s' => { name => 'command_options', default => 'check-update 2>&1' },
|
||||
'os-mode:s' => { name => 'os_mode', default => 'rhel' },
|
||||
'filter-package:s' => { name => 'filter_package' },
|
||||
'filter-repository:s' => { name => 'filter_repository' },
|
||||
'filter-repository:s' => { name => 'filter_repository' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
if (!defined($self->{option_results}->{os_mode}) ||
|
||||
$self->{option_results}->{os_mode} eq '' ||
|
||||
$self->{option_results}->{os_mode} eq 'rhel'
|
||||
) {
|
||||
$self->{command} = 'yum';
|
||||
$self->{command_options} = 'check-update 2>&1';
|
||||
} elsif ($self->{option_results}->{os_mode} eq 'debian') {
|
||||
$self->{command} = 'apt-get';
|
||||
$self->{command_options} = 'upgrade -sVq 2>&1';
|
||||
} elsif ($self->{option_results}->{os_mode} eq 'suse') {
|
||||
$self->{command} = 'zypper';
|
||||
$self->{command_options} = 'list-updates 2>&1';
|
||||
} else {
|
||||
$self->{output}->add_option_msg(short_msg => "os mode '" . $self->{option_results}->{os_mode} . "' not implemented" );
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
}
|
||||
|
||||
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) = $options{custom}->execute_command(
|
||||
command => $self->{command},
|
||||
command_options => $self->{command_options},
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
|
@ -136,7 +131,7 @@ sub manage_selection {
|
|||
$self->{output}->output_add(long_msg => "skipping '" . $repository . "': no matching filter.", debug => 1);
|
||||
next;
|
||||
}
|
||||
|
||||
|
||||
$self->{updates}->{$package} = {
|
||||
package => $package,
|
||||
version => $version,
|
||||
|
@ -155,49 +150,15 @@ __END__
|
|||
|
||||
Check pending updates.
|
||||
|
||||
For rhel/centos: yum check-update 2>&1
|
||||
For Debian: apt-get upgrade -sVq 2>&1
|
||||
For Suse: zypper list-updates 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
=item B<--os-mode>
|
||||
|
||||
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: 'yum').
|
||||
Use 'apt-get' for Debian, 'zypper' for SUSE.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: none).
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: 'check-updates 2>&1').
|
||||
Use 'upgrade -sVq 2>&1' for Debian, 'list-updates 2>&1' for SUSE.
|
||||
Default mode for parsing and command: 'rhel' (default), 'debian', 'suse'.
|
||||
|
||||
=item B<--warning-total>
|
||||
|
||||
|
|
|
@ -34,36 +34,25 @@ my %state_map = (
|
|||
S => 'InterruptibleSleep',
|
||||
R => 'running',
|
||||
D => 'UninterrupibleSleep',
|
||||
I => 'IdleKernelThread',
|
||||
I => 'IdleKernelThread'
|
||||
);
|
||||
|
||||
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 => 'ps' },
|
||||
"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' },
|
||||
"warning:s" => { name => 'warning' },
|
||||
"critical:s" => { name => 'critical' },
|
||||
"warning-time:s" => { name => 'warning_time' },
|
||||
"critical-time:s" => { name => 'critical_time' },
|
||||
"filter-command:s" => { name => 'filter_command' },
|
||||
"filter-arg:s" => { name => 'filter_arg' },
|
||||
"filter-state:s" => { name => 'filter_state' },
|
||||
"filter-ppid:s" => { name => 'filter_ppid' },
|
||||
'warning:s' => { name => 'warning' },
|
||||
'critical:s' => { name => 'critical' },
|
||||
'warning-time:s' => { name => 'warning_time' },
|
||||
'critical-time:s' => { name => 'critical_time' },
|
||||
'filter-command:s' => { name => 'filter_command' },
|
||||
'filter-arg:s' => { name => 'filter_arg' },
|
||||
'filter-state:s' => { name => 'filter_state' },
|
||||
'filter-ppid:s' => { name => 'filter_ppid' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -92,18 +81,18 @@ sub check_options {
|
|||
sub parse_output {
|
||||
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 => 'ps',
|
||||
command_options => '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a -w 2>&1'
|
||||
);
|
||||
|
||||
$self->{result} = {};
|
||||
my @lines = split /\n/, $stdout;
|
||||
my $line = shift @lines;
|
||||
foreach my $line (@lines) {
|
||||
next if ($line !~ /^(.*?)===(.*?)===(.*?)===(.*?)===(.*?)===(.*)$/);
|
||||
my ($state, $elapsed, $pid, $ppid, $cmd, $args) = ($1, $2, $3, $4, $5, $6);
|
||||
|
||||
|
||||
$self->{result}->{centreon::plugins::misc::trim($pid)} = {
|
||||
ppid => centreon::plugins::misc::trim($ppid),
|
||||
state => centreon::plugins::misc::trim($state),
|
||||
|
@ -116,7 +105,7 @@ sub parse_output {
|
|||
|
||||
sub check_time {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
my $time = $self->{result}->{$options{pid}}->{elapsed};
|
||||
# Format: [[dd-]hh:]mm:ss
|
||||
my @values = split /:/, $time;
|
||||
|
@ -134,15 +123,17 @@ sub check_time {
|
|||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $total_seconds_elapsed, threshold => [ { label => 'critical-time', 'exit_litteral' => 'critical' }, { label => 'warning-time', exit_litteral => 'warning' } ]);
|
||||
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Time issue for process " . $self->{result}->{$options{pid}}->{cmd});
|
||||
$self->{output}->output_add(
|
||||
severity => $exit,
|
||||
short_msg => "Time issue for process " . $self->{result}->{$options{pid}}->{cmd}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->parse_output();
|
||||
$self->parse_output(custom => $options{custom});
|
||||
|
||||
my $num_processes_match = 0;
|
||||
foreach my $pid (keys %{$self->{result}}) {
|
||||
|
@ -155,22 +146,29 @@ sub run {
|
|||
next if (defined($self->{option_results}->{filter_ppid}) && $self->{option_results}->{filter_ppid} ne '' &&
|
||||
$self->{result}->{$pid}->{ppid} !~ /$self->{option_results}->{filter_ppid}/);
|
||||
|
||||
$self->{output}->output_add(long_msg => 'Process: [command => ' . $self->{result}->{$pid}->{cmd} .
|
||||
'] [arg => ' . $self->{result}->{$pid}->{args} .
|
||||
'] [state => ' . $state_map{$self->{result}->{$pid}->{state}} . ']');
|
||||
$self->{output}->output_add(
|
||||
long_msg =>
|
||||
'Process: [command => ' . $self->{result}->{$pid}->{cmd} .
|
||||
'] [arg => ' . $self->{result}->{$pid}->{args} .
|
||||
'] [state => ' . $state_map{$self->{result}->{$pid}->{state}} . ']'
|
||||
);
|
||||
$self->check_time(pid => $pid);
|
||||
$num_processes_match++;
|
||||
}
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $num_processes_match, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => "Number of current processes: $num_processes_match");
|
||||
$self->{output}->perfdata_add(label => 'nbproc',
|
||||
value => $num_processes_match,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
|
||||
$self->{output}->output_add(
|
||||
severity => $exit,
|
||||
short_msg => "Number of current processes: $num_processes_match"
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'nbproc',
|
||||
value => $num_processes_match,
|
||||
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();
|
||||
}
|
||||
|
@ -184,49 +182,10 @@ __END__
|
|||
Check linux processes.
|
||||
Can filter on commands, arguments and states.
|
||||
|
||||
Command used: ps -e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a -w 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: 'ps').
|
||||
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: '-e -o state -o ===%t===%p===%P=== -o comm:50 -o ===%a -w 2>&1').
|
||||
|
||||
=item B<--warning>
|
||||
|
||||
Threshold warning (in absolute of processes count. After filters).
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -34,19 +33,25 @@ sub custom_usage_perfdata {
|
|||
if (!defined($options{extra_instance}) || $options{extra_instance} != 0) {
|
||||
$extra_label .= '_' . $self->{result_values}->{display};
|
||||
}
|
||||
$self->{output}->perfdata_add(label => $self->{result_values}->{label_ref} . '_used' . $extra_label, unit => $unit,
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{warn_label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{crit_label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
min => 0);
|
||||
$self->{output}->perfdata_add(
|
||||
label => $self->{result_values}->{label_ref} . '_used' . $extra_label, unit => $unit,
|
||||
value => $self->{result_values}->{used},
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{warn_label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{crit_label}, total => $self->{result_values}->{total}, cast_int => 1),
|
||||
min => 0
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_threshold {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used},
|
||||
threshold => [ { label => 'critical-' . $self->{result_values}->{crit_label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{result_values}->{warn_label}, exit_litteral => 'warning' } ]);
|
||||
my $exit = $self->{perfdata}->threshold_check(
|
||||
value => $self->{result_values}->{used},
|
||||
threshold => [
|
||||
{ label => 'critical-' . $self->{result_values}->{crit_label}, exit_litteral => 'critical' },
|
||||
{ label => 'warning-' . $self->{result_values}->{warn_label}, exit_litteral => 'warning' }
|
||||
]
|
||||
);
|
||||
return $exit;
|
||||
}
|
||||
|
||||
|
@ -66,11 +71,12 @@ sub custom_usage_output {
|
|||
$limit_hard = sprintf(" (%.2f %% of hard limit)", $self->{result_values}->{used} * 100 / $self->{result_values}->{crit_limit});
|
||||
}
|
||||
|
||||
my $msg = sprintf("%s Used: %s%s%s",
|
||||
ucfirst($self->{result_values}->{label_ref}),
|
||||
$value,
|
||||
$limit_soft, $limit_hard);
|
||||
return $msg;
|
||||
return sprintf(
|
||||
"%s Used: %s%s%s",
|
||||
ucfirst($self->{result_values}->{label_ref}),
|
||||
$value,
|
||||
$limit_soft, $limit_hard
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_calc {
|
||||
|
@ -113,7 +119,7 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'data' },
|
||||
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 => 'inode-usage', set => {
|
||||
|
@ -121,9 +127,9 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'inode' },
|
||||
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')
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -139,34 +145,19 @@ 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 => 'repquota' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-a -i 2>&1' },
|
||||
"filter-user:s" => { name => 'filter_user', },
|
||||
"filter-fs:s" => { name => 'filter_fs', },
|
||||
'filter-user:s' => { name => 'filter_user' },
|
||||
'filter-fs:s' => { name => 'filter_fs' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
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 => 'repquota',
|
||||
command_options => '-a -i 2>&1',
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
|
@ -201,7 +192,8 @@ sub manage_selection {
|
|||
next;
|
||||
}
|
||||
|
||||
$self->{quota}->{$name} = { display => $name,
|
||||
$self->{quota}->{$name} = {
|
||||
display => $name,
|
||||
data_used => $data_used, data_soft => $data_soft, data_hard => $data_hard,
|
||||
inode_used => $inode_used, inode_soft => $inode_soft, inode_hard => $inode_hard,
|
||||
};
|
||||
|
@ -225,57 +217,13 @@ __END__
|
|||
|
||||
Check quota usage on partitions.
|
||||
|
||||
Command used: repquota -a -i 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--remote>
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
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: 'repquota').
|
||||
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 -i 2>&1').
|
||||
|
||||
=item B<--warning-*>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'inode-usage', 'data-usage'.
|
||||
|
||||
=item B<--critical-*>
|
||||
|
||||
Threshold critical.
|
||||
Thresholds.
|
||||
Can be: 'inode-usage', 'data-usage'.
|
||||
|
||||
=item B<--filter-user>
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub custom_usage_perfdata {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -72,11 +71,12 @@ sub custom_usage_output {
|
|||
my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total});
|
||||
my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used});
|
||||
my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free});
|
||||
my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)",
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free});
|
||||
return $msg;
|
||||
return sprintf(
|
||||
'Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)',
|
||||
$total_size_value . " " . $total_size_unit,
|
||||
$total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used},
|
||||
$total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}
|
||||
);
|
||||
}
|
||||
|
||||
sub custom_usage_calc {
|
||||
|
@ -109,9 +109,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')
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -125,69 +125,55 @@ 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 => 'df' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '-P -k -T 2>&1' },
|
||||
"filter-type:s" => { name => 'filter_type', },
|
||||
"filter-fs:s" => { name => 'filter_fs', },
|
||||
"units:s" => { name => 'units', default => '%' },
|
||||
"free" => { name => 'free' },
|
||||
"name:s" => { name => 'name' },
|
||||
"regexp" => { name => 'use_regexp' },
|
||||
"regexp-isensitive" => { name => 'use_regexpi' },
|
||||
"space-reservation:s" => { name => 'space_reservation' },
|
||||
'filter-type:s' => { name => 'filter_type', },
|
||||
'filter-fs:s' => { name => 'filter_fs', },
|
||||
'units:s' => { name => 'units', default => '%' },
|
||||
'free' => { name => 'free' },
|
||||
'name:s' => { name => 'name' },
|
||||
'regexp' => { name => 'use_regexp' },
|
||||
'regexp-isensitive' => { name => 'use_regexpi' },
|
||||
'space-reservation:s' => { name => 'space_reservation' }
|
||||
});
|
||||
|
||||
$self->{result} = {};
|
||||
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 -k -T 2>&1',
|
||||
no_quit => 1
|
||||
);
|
||||
|
||||
$self->{disks} = {};
|
||||
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 '' &&
|
||||
$type !~ /$self->{option_results}->{filter_type}/);
|
||||
|
||||
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi})
|
||||
&& $mount !~ /$self->{option_results}->{name}/i);
|
||||
next if (defined($self->{option_results}->{name}) && defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi})
|
||||
&& $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});
|
||||
|
||||
|
||||
$size *= 1024;
|
||||
if (defined($self->{option_results}->{space_reservation})) {
|
||||
$size = int($size - ($self->{option_results}->{space_reservation} * $size / 100));
|
||||
}
|
||||
$self->{disks}->{$mount} = { display => $mount, fs => $fs, type => $type, total => $size, used => $used * 1024 };
|
||||
}
|
||||
|
||||
|
||||
if (scalar(keys %{$self->{disks}}) <= 0) {
|
||||
if ($exit_code != 0) {
|
||||
$self->{output}->output_add(long_msg => "command output:" . $stdout);
|
||||
|
@ -205,49 +191,10 @@ __END__
|
|||
|
||||
Check storage usages.
|
||||
|
||||
Command used: df -P -k -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 -k -T 2>&1').
|
||||
|
||||
=item B<--warning-usage>
|
||||
|
||||
Threshold warning.
|
||||
|
|
|
@ -24,28 +24,25 @@ use base qw(centreon::plugins::templates::counter);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub custom_swap_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $output = sprintf(
|
||||
return sprintf(
|
||||
'Swap Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)',
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}),
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}),
|
||||
$self->{result_values}->{prct_used},
|
||||
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}),
|
||||
$self->{result_values}->{prct_free},
|
||||
$self->{result_values}->{prct_free}
|
||||
);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'swap', type => 0, skipped_code => { -10 => 1 } },
|
||||
{ name => 'swap', type => 0, skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{swap} = [
|
||||
|
@ -53,27 +50,26 @@ sub set_counters {
|
|||
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||
closure_custom_output => $self->can('custom_swap_output'),
|
||||
perfdatas => [
|
||||
{ label => 'used', value => 'used', template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 },
|
||||
],
|
||||
},
|
||||
{ label => 'used', template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'usage-free', display_ok => 0, nlabel => 'swap.free.bytes', set => {
|
||||
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
|
||||
closure_custom_output => $self->can('custom_swap_output'),
|
||||
perfdatas => [
|
||||
{ label => 'free', value => 'free', template => '%d', min => 0, max => 'total',
|
||||
unit => 'B', cast_int => 1 },
|
||||
],
|
||||
},
|
||||
{ label => 'free', template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1 }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'usage-prct', display_ok => 0, nlabel => 'swap.usage.percentage', set => {
|
||||
key_values => [ { name => 'prct_used' } ],
|
||||
output_template => 'Swap used: %.2f %%',
|
||||
perfdatas => [
|
||||
{ label => 'used_prct', value => 'prct_used', template => '%.2f', min => 0, max => 100, unit => '%' },
|
||||
],
|
||||
},
|
||||
},
|
||||
{ label => 'used_prct', template => '%.2f', min => 0, max => 100, unit => '%' }
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -83,17 +79,7 @@ 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 => 'cat' },
|
||||
'command-path:s' => { name => 'command_path' },
|
||||
'command-options:s' => { name => 'command_options', default => '/proc/meminfo 2>&1' },
|
||||
'no-swap:s' => { name => 'no_swap' },
|
||||
'no-swap:s' => { name => 'no_swap' }
|
||||
});
|
||||
|
||||
$self->{no_swap} = 'critical';
|
||||
|
@ -117,15 +103,11 @@ sub check_options {
|
|||
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 => 'cat',
|
||||
command_options => '/proc/meminfo 2>&1'
|
||||
);
|
||||
|
||||
|
||||
my ($total_size, $swap_free);
|
||||
foreach (split(/\n/, $stdout)) {
|
||||
if (/^SwapTotal:\s+(\d+)/i) {
|
||||
|
@ -141,8 +123,10 @@ sub manage_selection {
|
|||
}
|
||||
|
||||
if ($total_size == 0) {
|
||||
$self->{output}->output_add(severity => $self->{no_swap},
|
||||
short_msg => 'No active swap.');
|
||||
$self->{output}->output_add(
|
||||
severity => $self->{no_swap},
|
||||
short_msg => 'No active swap.'
|
||||
);
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
}
|
||||
|
@ -171,53 +155,14 @@ __END__
|
|||
|
||||
Check swap memory (need '/proc/meminfo' file).
|
||||
|
||||
Command used: cat /proc/meminfo 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--no-swap>
|
||||
|
||||
Threshold if no active swap (default: '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: 'cat').
|
||||
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: '/proc/meminfo 2>&1').
|
||||
|
||||
=item B<--warning-*> B<--critical-*>
|
||||
|
||||
Threshold, can be 'usage' (in Bytes), 'usage-free' (in Bytes), 'usage-prct' (%).
|
||||
|
|
|
@ -30,14 +30,13 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
|
|||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $msg = sprintf(
|
||||
return sprintf(
|
||||
'status : %s/%s/%s [boot: %s]',
|
||||
$self->{result_values}->{load},
|
||||
$self->{result_values}->{active},
|
||||
$self->{result_values}->{sub},
|
||||
$self->{result_values}->{boot}
|
||||
);
|
||||
return $msg;
|
||||
}
|
||||
|
||||
sub set_counters {
|
||||
|
@ -53,47 +52,43 @@ sub set_counters {
|
|||
key_values => [ { name => 'running' }, { name => 'total' } ],
|
||||
output_template => 'Total Running: %s',
|
||||
perfdatas => [
|
||||
{ label => 'total_running', value => 'running', template => '%s',
|
||||
min => 0, max => 'total' },
|
||||
],
|
||||
{ label => 'total_running', template => '%s', min => 0, max => 'total' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'total-failed', nlabel => 'systemd.services.failed.count', set => {
|
||||
key_values => [ { name => 'failed' }, { name => 'total' } ],
|
||||
output_template => 'Total Failed: %s',
|
||||
perfdatas => [
|
||||
{ label => 'total_failed', value => 'failed', template => '%s',
|
||||
min => 0, max => 'total' },
|
||||
],
|
||||
{ label => 'total_failed', template => '%s', min => 0, max => 'total' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'total-dead', nlabel => 'systemd.services.dead.count', set => {
|
||||
key_values => [ { name => 'dead' }, { name => 'total' } ],
|
||||
output_template => 'Total Dead: %s',
|
||||
perfdatas => [
|
||||
{ label => 'total_dead', value => 'dead', template => '%s',
|
||||
min => 0, max => 'total' },
|
||||
],
|
||||
{ label => 'total_dead', template => '%s', min => 0, max => 'total' }
|
||||
]
|
||||
}
|
||||
},
|
||||
{ label => 'total-exited', nlabel => 'systemd.services.exited.count', set => {
|
||||
key_values => [ { name => 'exited' }, { name => 'total' } ],
|
||||
output_template => 'Total Exited: %s',
|
||||
perfdatas => [
|
||||
{ label => 'total_exited', value => 'exited', template => '%s',
|
||||
min => 0, max => 'total' },
|
||||
],
|
||||
{ label => 'total_exited', template => '%s', min => 0, max => 'total' }
|
||||
]
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
$self->{maps_counters}->{sc} = [
|
||||
{ label => 'status', threshold => 0, set => {
|
||||
key_values => [ { name => 'load' }, { name => 'active' }, { name => 'sub' }, { name => 'boot' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -101,22 +96,11 @@ 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 => 'systemctl' },
|
||||
'command-path:s' => { name => 'command_path' },
|
||||
'command-options:s' => { name => 'command_options', default => '-a --no-pager --no-legend' },
|
||||
'command-options2:s' => { name => 'command_options2', default => 'list-unit-files --no-pager --no-legend' },
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{active} =~ /failed/i' },
|
||||
|
||||
$options{options}->add_options(arguments => {
|
||||
'filter-name:s' => { name => 'filter_name' },
|
||||
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||
'critical-status:s' => { name => 'critical_status', default => '%{active} =~ /failed/i' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
|
@ -131,20 +115,16 @@ sub check_options {
|
|||
|
||||
sub prefix_sc_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
|
||||
return "Service '" . $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) = $options{custom}->execute_command(
|
||||
command => 'systemctl',
|
||||
command_options => '-a --no-pager --no-legend'
|
||||
);
|
||||
|
||||
$self->{global} = { running => 0, exited => 0, failed => 0, dead => 0, total => 0 };
|
||||
|
@ -171,13 +151,9 @@ sub manage_selection {
|
|||
$self->{output}->option_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_options2}
|
||||
($stdout) = $options{custom}->execute_command(
|
||||
command => 'systemctl',
|
||||
command_options => 'list-unit-files --no-pager --no-legend'
|
||||
);
|
||||
#runlevel4.target enabled
|
||||
#runlevel5.target static
|
||||
|
@ -197,53 +173,10 @@ __END__
|
|||
|
||||
Check systemd services status.
|
||||
|
||||
Command used: 'systemctl -a --no-pager --no-legend' and 'systemctl list-unit-files --no-pager --no-legend'
|
||||
|
||||
=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: 'systemctl').
|
||||
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 --no-pager --no-legend').
|
||||
|
||||
=item B<--command-options2>
|
||||
|
||||
Command options (Default: 'list-unit-files --no-pager --no-legend').
|
||||
|
||||
=item B<--filter-name>
|
||||
|
||||
Filter service name (can be a regexp).
|
||||
|
|
|
@ -26,7 +26,6 @@ use strict;
|
|||
use warnings;
|
||||
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold);
|
||||
use Digest::MD5 qw(md5_hex);
|
||||
use centreon::plugins::misc;
|
||||
|
||||
sub custom_status_output {
|
||||
my ($self, %options) = @_;
|
||||
|
@ -101,7 +100,7 @@ sub set_counters {
|
|||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', skipped_code => { -10 => 1 } },
|
||||
{ name => 'interface', type => 1, cb_prefix_output => 'prefix_interface_output', message_multiple => 'All interfaces are ok', skipped_code => { -10 => 1 } }
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{interface} = [
|
||||
|
@ -109,7 +108,7 @@ sub set_counters {
|
|||
key_values => [ { name => 'status' }, { name => 'display' } ],
|
||||
closure_custom_output => $self->can('custom_status_output'),
|
||||
closure_custom_perfdata => sub { return 0; },
|
||||
closure_custom_threshold_check => \&catalog_status_threshold,
|
||||
closure_custom_threshold_check => \&catalog_status_threshold
|
||||
}
|
||||
},
|
||||
{ label => 'in', set => {
|
||||
|
@ -117,7 +116,7 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'in' },
|
||||
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic In : %s',
|
||||
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_traffic_threshold')
|
||||
}
|
||||
},
|
||||
{ label => 'out', set => {
|
||||
|
@ -125,9 +124,9 @@ sub set_counters {
|
|||
closure_custom_calc => $self->can('custom_traffic_calc'), closure_custom_calc_extra_options => { label_ref => 'out' },
|
||||
closure_custom_output => $self->can('custom_traffic_output'), output_error_template => 'Traffic Out : %s',
|
||||
closure_custom_perfdata => $self->can('custom_traffic_perfdata'),
|
||||
closure_custom_threshold_check => $self->can('custom_traffic_threshold'),
|
||||
closure_custom_threshold_check => $self->can('custom_traffic_threshold')
|
||||
}
|
||||
},
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -137,16 +136,6 @@ 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 => 'ip' },
|
||||
'command-path:s' => { name => 'command_path', default => '/sbin' },
|
||||
'command-options:s' => { name => 'command_options', default => '-s addr 2>&1' },
|
||||
'filter-state:s' => { name => 'filter_state', },
|
||||
'units:s' => { name => 'units', default => 'b/s' },
|
||||
'name:s' => { name => 'name' },
|
||||
|
@ -172,10 +161,6 @@ sub check_options {
|
|||
my ($self, %options) = @_;
|
||||
$self->SUPER::check_options(%options);
|
||||
|
||||
$self->{hostname} = $self->{option_results}->{hostname};
|
||||
if (!defined($self->{hostname})) {
|
||||
$self->{hostname} = 'me';
|
||||
}
|
||||
if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') {
|
||||
if ($self->{option_results}->{speed} !~ /^[0-9]+(\.[0-9]+){0,1}$/) {
|
||||
$self->{output}->add_option_msg(short_msg => "Speed must be a positive number '" . $self->{option_results}->{speed} . "' (can be a float also).");
|
||||
|
@ -196,14 +181,10 @@ sub check_options {
|
|||
sub do_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{interface} = {};
|
||||
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 => 'ip',
|
||||
command_path => '/sbin',
|
||||
command_options => '-s addr 2>&1'
|
||||
);
|
||||
|
||||
# ifconfig
|
||||
|
@ -212,7 +193,8 @@ sub do_selection {
|
|||
# ip addr
|
||||
$interface_pattern = '^\d+:\s+(\S+)(.*?)(?=\n\d|\Z$)';
|
||||
}
|
||||
|
||||
|
||||
$self->{interface} = {};
|
||||
while ($stdout =~ /$interface_pattern/msg) {
|
||||
my ($interface_name, $values) = ($1, $2);
|
||||
|
||||
|
@ -258,8 +240,8 @@ sub do_selection {
|
|||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->do_selection();
|
||||
$self->{cache_name} = "cache_linux_local_" . $self->{hostname} . '_' . $self->{mode} . '_' .
|
||||
$self->do_selection(custom => $options{custom});
|
||||
$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'));
|
||||
}
|
||||
|
@ -272,49 +254,10 @@ __END__
|
|||
|
||||
Check Traffic
|
||||
|
||||
Command used: /sbin/ip -s addr 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: 'ip').
|
||||
Can be changed if you have output in a file.
|
||||
|
||||
=item B<--command-path>
|
||||
|
||||
Command path (Default: '/sbin').
|
||||
|
||||
=item B<--command-options>
|
||||
|
||||
Command options (Default: '-s addr 2>&1').
|
||||
|
||||
=item B<--warning-in>
|
||||
|
||||
Threshold warning in percent for 'in' traffic.
|
||||
|
|
|
@ -24,7 +24,6 @@ use base qw(centreon::plugins::mode);
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::plugins::misc;
|
||||
use POSIX;
|
||||
|
||||
sub new {
|
||||
|
@ -32,22 +31,12 @@ 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 => 'cat' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '/proc/uptime 2>&1' },
|
||||
"warning:s" => { name => 'warning', default => '' },
|
||||
"critical:s" => { name => 'critical', default => '' },
|
||||
"seconds" => { name => 'seconds', },
|
||||
});
|
||||
$options{options}->add_options(arguments => {
|
||||
'warning:s' => { name => 'warning', default => '' },
|
||||
'critical:s' => { name => 'critical', default => '' },
|
||||
'seconds' => { name => 'seconds' }
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -56,45 +45,52 @@ 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 => 'cat',
|
||||
command_options => '/proc/uptime 2>&1'
|
||||
);
|
||||
|
||||
my ($uptime, $idletime);
|
||||
if ($stdout =~ /([0-9\.]+)\s+([0-9\.]+)/) {
|
||||
($uptime, $idletime) = ($1, $2)
|
||||
}
|
||||
|
||||
if (!defined($uptime) || !defined($idletime)) {
|
||||
$self->{output}->add_option_msg(short_msg => "Some informations missing.");
|
||||
$self->{output}->add_option_msg(short_msg => 'Some informations missing.');
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
|
||||
my $exit_code = $self->{perfdata}->threshold_check(value => floor($uptime),
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
||||
$self->{output}->perfdata_add(label => 'uptime', unit => 's',
|
||||
value => floor($uptime),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
my $exit_code = $self->{perfdata}->threshold_check(
|
||||
value => floor($uptime),
|
||||
threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]
|
||||
);
|
||||
$self->{output}->perfdata_add(
|
||||
label => 'uptime', unit => 's',
|
||||
value => floor($uptime),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0
|
||||
);
|
||||
|
||||
$self->{output}->output_add(severity => $exit_code,
|
||||
short_msg => sprintf("System uptime is: %s",
|
||||
defined($self->{option_results}->{seconds}) ? floor($uptime) . " seconds" : floor($uptime / 86400) . " days" ));
|
||||
$self->{output}->output_add(
|
||||
severity => $exit_code,
|
||||
short_msg => sprintf(
|
||||
"System uptime is: %s",
|
||||
defined($self->{option_results}->{seconds}) ? floor($uptime) . " seconds" : floor($uptime / 86400) . " days"
|
||||
)
|
||||
);
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
@ -107,7 +103,9 @@ __END__
|
|||
|
||||
=head1 MODE
|
||||
|
||||
Check system uptime. (need '/proc/uptime' file).
|
||||
Check system uptime.
|
||||
|
||||
Command used: cat /proc/uptime 2>&1
|
||||
|
||||
=over 8
|
||||
|
||||
|
@ -123,47 +121,6 @@ Threshold critical in seconds.
|
|||
|
||||
Display uptime in seconds.
|
||||
|
||||
=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: 'cat').
|
||||
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: '/proc/uptime 2>&1').
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
Loading…
Reference in New Issue