Fix #5152
This commit is contained in:
parent
2db5691f44
commit
789383f00f
|
@ -60,7 +60,7 @@ 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->{warn1} . "'.");
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
|
|
|
@ -50,14 +50,18 @@ sub new {
|
|||
{
|
||||
"warning:s" => { name => 'warning', },
|
||||
"critical:s" => { name => 'critical', },
|
||||
"warning-mem-total:s" => { name => 'warning_mem_total', },
|
||||
"critical-mem-total:s" => { name => 'critical_mem_total', },
|
||||
"warning-mem-avg:s" => { name => 'warning_mem_avg', },
|
||||
"critical-mem-avg:s" => { name => 'critical_mem_avg', },
|
||||
"process-name:s" => { name => 'process_name', },
|
||||
"regexp-name" => { name => 'regexp_name', },
|
||||
"process-path:s" => { name => 'process_path', },
|
||||
"regexp-path" => { name => 'regexp_path', },
|
||||
"process-args:s" => { name => 'process_args', },
|
||||
"regexp-args" => { name => 'regexp_args', },
|
||||
"memory" => { name => 'memory', },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
@ -66,13 +70,29 @@ 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->{warn1} . "'.");
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{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->{critical} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-mem-total', value => $self->{option_results}->{warning_mem_total})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-mem-total threshold '" . $self->{warning_mem_total} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-mem-total', value => $self->{option_results}->{critical_mem_total})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-mem-total threshold '" . $self->{critical_mem_total} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'warning-mem-avg', value => $self->{option_results}->{warning_mem_avg})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning-mem-avg threshold '" . $self->{warning_mem_avg} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical-mem-avg', value => $self->{option_results}->{critical_mem_avg})) == 0) {
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong critical-mem-avg threshold '" . $self->{critical_mem_avg} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{option_results}->{process_name}) &&
|
||||
!defined($self->{option_results}->{process_path}) &&
|
||||
!defined($self->{option_results}->{process_args})
|
||||
|
@ -94,6 +114,7 @@ sub run {
|
|||
};
|
||||
|
||||
my $oid_hrSWRunStatus = '.1.3.6.1.2.1.25.4.2.1.7';
|
||||
my $oid_hrSWRunPerfMem = '.1.3.6.1.2.1.25.5.1.1.2';
|
||||
|
||||
my $oid2check_filter;
|
||||
foreach (keys %$oids) {
|
||||
|
@ -105,6 +126,9 @@ sub run {
|
|||
# Build other
|
||||
my $mores_filters = {};
|
||||
my $more_oids = [$oid_hrSWRunStatus];
|
||||
if (defined($self->{option_results}->{memory})) {
|
||||
push @{$more_oids}, $oid_hrSWRunPerfMem;
|
||||
}
|
||||
foreach (keys %$oids) {
|
||||
if ($_ ne $oid2check_filter && defined($self->{option_results}->{'process_' . $_})) {
|
||||
push @{$more_oids}, $oids->{$_};
|
||||
|
@ -124,9 +148,10 @@ sub run {
|
|||
}
|
||||
}
|
||||
|
||||
my $result2;
|
||||
if (scalar(keys %$instances_keep) > 0) {
|
||||
$self->{snmp}->load(oids => $more_oids, instances => [keys %$instances_keep ]);
|
||||
my $result2 = $self->{snmp}->get_leef();
|
||||
$result2 = $self->{snmp}->get_leef();
|
||||
|
||||
foreach my $key (keys %$instances_keep) {
|
||||
# 1 = running, 2 = runnable, 3 = notRunnable, 4 => invalid
|
||||
|
@ -165,6 +190,33 @@ sub run {
|
|||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||
min => 0);
|
||||
# Check memory
|
||||
if (defined($self->{option_results}->{memory}) && $num_processes_match > 0) {
|
||||
my $total_memory = 0;
|
||||
foreach my $key (keys %$instances_keep) {
|
||||
$total_memory += ($result2->{$oid_hrSWRunPerfMem . "." . $key} * 1024);
|
||||
}
|
||||
|
||||
$exit = $self->{perfdata}->threshold_check(value => $total_memory, threshold => [ { label => 'critical-mem-total', 'exit_litteral' => 'critical' }, { label => 'warning-mem-total', exit_litteral => 'warning' } ]);
|
||||
my ($total_mem_value, $total_mem_unit) = $self->{perfdata}->change_bytes(value => $total_memory);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Total memory usage: %s", $total_mem_value . " " . $total_mem_unit));
|
||||
$self->{output}->perfdata_add(label => 'mem_total',
|
||||
value => $total_memory,
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_mem_total'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_mem_total'),
|
||||
min => 0);
|
||||
|
||||
$exit = $self->{perfdata}->threshold_check(value => $total_memory / $num_processes_match, threshold => [ { label => 'critical-mem-avg', 'exit_litteral' => 'critical' }, { label => 'warning-mem-avg', exit_litteral => 'warning' } ]);
|
||||
my ($avg_mem_value, $avg_mem_unit) = $self->{perfdata}->change_bytes(value => $total_memory / $num_processes_match);
|
||||
$self->{output}->output_add(severity => $exit,
|
||||
short_msg => sprintf("Average memory usage: %.2f %s", $avg_mem_value, $avg_mem_unit));
|
||||
$self->{output}->perfdata_add(label => 'mem_avg',
|
||||
value => sprintf("%.2f", $total_memory / $num_processes_match),
|
||||
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_avg_total'),
|
||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_avg_total'),
|
||||
min => 0);
|
||||
}
|
||||
|
||||
$self->{output}->display();
|
||||
$self->{output}->exit();
|
||||
|
@ -177,6 +229,7 @@ __END__
|
|||
=head1 MODE
|
||||
|
||||
Check system number of processes.
|
||||
Can also check memory usage.
|
||||
|
||||
=over 8
|
||||
|
||||
|
@ -188,6 +241,22 @@ Threshold warning.
|
|||
|
||||
Threshold critical.
|
||||
|
||||
=item B<--warning-mem-total>
|
||||
|
||||
Threshold warning in Bytes of total memory usage processes.
|
||||
|
||||
=item B<--critical-mem-total>
|
||||
|
||||
Threshold warning in Bytes of total memory usage processes.
|
||||
|
||||
=item B<--warning-mem-avg>
|
||||
|
||||
Threshold warning in Bytes of average memory usage processes.
|
||||
|
||||
=item B<--critical-mem-avg>
|
||||
|
||||
Threshold warning in Bytes of average memory usage processes.
|
||||
|
||||
=item B<--process-name>
|
||||
|
||||
Check process name.
|
||||
|
@ -212,6 +281,10 @@ Check process args.
|
|||
|
||||
Allows to use regexp to filter process args (with option --process-args).
|
||||
|
||||
=item B<--memory>
|
||||
|
||||
Check memory.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -62,7 +62,7 @@ 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->{warn1} . "'.");
|
||||
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{warning} . "'.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
|
||||
|
|
Loading…
Reference in New Issue