+ add plugin for hp-ux in snmp (Fix #13)

This commit is contained in:
garnier-quentin 2016-09-01 16:26:48 +02:00
parent 48c2453be1
commit 822decba69
6 changed files with 940 additions and 0 deletions

159
os/hpux/snmp/mode/cpu.pm Normal file
View File

@ -0,0 +1,159 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package os::hpux::snmp::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' },
];
$self->{maps_counters}->{global} = [
{ label => 'user', set => {
key_values => [ { name => 'total', diff => 1 }, { name => 'user', diff => 1 } ],
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'user' },
output_template => 'User %.2f %%', output_use => 'user_prct',
perfdatas => [
{ label => 'user', value => 'user_prct', template => '%.2f', min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'sys', set => {
key_values => [ { name => 'total', diff => 1 }, { name => 'sys', diff => 1 } ],
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'sys' },
output_template => 'System %.2f %%', output_use => 'sys_prct',
perfdatas => [
{ label => 'sys', value => 'sys_prct', template => '%.2f', min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'nice', set => {
key_values => [ { name => 'total', diff => 1 }, { name => 'nice', diff => 1 } ],
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'nice' },
output_template => 'Nice %.2f %%', output_use => 'nice_prct',
perfdatas => [
{ label => 'nice', value => 'nice_prct', template => '%.2f', min => 0, max => 100, unit => '%' },
],
}
},
{ label => 'idle', set => {
key_values => [ { name => 'total', diff => 1 }, { name => 'idle', diff => 1 } ],
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'idle' },
output_template => 'Idle %.2f %%', output_use => 'idle_prct',
perfdatas => [
{ label => 'idle', value => 'idle_prct', template => '%.2f', min => 0, max => 100, unit => '%' },
],
}
},
];
}
sub custom_data_calc {
my ($self, %options) = @_;
my $label = $options{extra_options}->{label_ref};
my $delta_value = $options{new_datas}->{$self->{instance} . '_' . $label} - $options{old_datas}->{$self->{instance} . '_' . $label};
my $delta_total = $options{new_datas}->{$self->{instance} . '_total'} - $options{old_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{$label . '_prct'} = 0;
if ($delta_total > 0) {
$self->{result_values}->{$label . '_prct'} = $delta_value * 100 / $delta_total;
}
return 0;
}
sub prefix_output {
my ($self, %options) = @_;
return "CPU Usage : ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
$self->{cache_name} = "hpux_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
my $oid_computerSystemUserCPU = '.1.3.6.1.4.1.11.2.3.1.1.13.0';
my $oid_computerSystemSysCPU = '.1.3.6.1.4.1.11.2.3.1.1.14.0';
my $oid_computerSystemIdleCPU = '.1.3.6.1.4.1.11.2.3.1.1.15.0';
my $oid_computerSystemNiceCPU = '.1.3.6.1.4.1.11.2.3.1.1.16.0';
my $result = $options{snmp}->get_leef(oids => [$oid_computerSystemUserCPU, $oid_computerSystemSysCPU,
$oid_computerSystemIdleCPU, $oid_computerSystemNiceCPU],
nothing_quit => 1);
$self->{global} = {
total => $result->{$oid_computerSystemUserCPU} + $result->{$oid_computerSystemSysCPU} + $result->{$oid_computerSystemIdleCPU} + $result->{$oid_computerSystemNiceCPU},
sys => $result->{$oid_computerSystemSysCPU},
user => $result->{$oid_computerSystemUserCPU},
idle => $result->{$oid_computerSystemIdleCPU},
nice => $result->{$oid_computerSystemNiceCPU},
};
}
1;
__END__
=head1 MODE
Check system CPUs.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example : --filter-counters='^idle$'
=item B<--warning-*>
Threshold warning.
Can be: 'user', 'sys', 'idle', 'nice'.
=item B<--critical-*>
Threshold critical.
Can be: 'user', 'sys', 'idle', 'nice'.
=back
=cut

139
os/hpux/snmp/mode/load.pm Normal file
View File

@ -0,0 +1,139 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package os::hpux::snmp::mode::load;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', default => '' },
"critical:s" => { name => 'critical', default => '' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
($self->{warn1}, $self->{warn5}, $self->{warn15}) = split /,/, $self->{option_results}->{warning};
($self->{crit1}, $self->{crit5}, $self->{crit15}) = split /,/, $self->{option_results}->{critical};
if (($self->{perfdata}->threshold_validate(label => 'warn1', value => $self->{warn1})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning (1min) threshold '" . $self->{warn1} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warn5', value => $self->{warn5})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning (5min) threshold '" . $self->{warn5} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warn15', value => $self->{warn15})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning (15min) threshold '" . $self->{warn15} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'crit1', value => $self->{crit1})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical (1min) threshold '" . $self->{crit1} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'crit5', value => $self->{crit5})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical (5min) threshold '" . $self->{crit5} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'crit15', value => $self->{crit15})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical (15min) threshold '" . $self->{crit15} . "'.");
$self->{output}->option_exit();
}
}
sub run {
my ($self, %options) = @_;
my $oid_computerSystemAvgJobs1 = '.1.3.6.1.4.1.11.2.3.1.1.3.0';
my $oid_computerSystemAvgJobs5 = '.1.3.6.1.4.1.11.2.3.1.1.4.0';
my $oid_computerSystemAvgJobs15 = '.1.3.6.1.4.1.11.2.3.1.1.5.0';
my $result = $options{snmp}->get_leef(oids => [$oid_computerSystemAvgJobs1, $oid_computerSystemAvgJobs5, $oid_computerSystemAvgJobs15], nothing_quit => 1);
my $cpu_load1 = $result->{$oid_computerSystemAvgJobs1} / 100;
my $cpu_load5 = $result->{$oid_computerSystemAvgJobs5} / 100;
my $cpu_load15 = $result->{$oid_computerSystemAvgJobs15} / 100;
$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,
threshold => [ { label => 'crit1', exit_litteral => 'critical' }, { label => 'warn1', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $cpu_load5,
threshold => [ { label => 'crit5', exit_litteral => 'critical' }, { label => 'warn5', exit_litteral => 'warning' } ]);
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 => sprintf("Load average: %s, %s, %s", $cpu_load1, $cpu_load5, $cpu_load15));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check system load-average.
=over 8
=item B<--warning>
Threshold warning (1min,5min,15min).
=item B<--critical>
Threshold critical (1min,5min,15min).
=back
=cut

175
os/hpux/snmp/mode/memory.pm Normal file
View File

@ -0,0 +1,175 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package os::hpux::snmp::mode::memory;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_usage_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{label} . '_used', unit => 'B',
value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{result_values}->{label} . '-usage', exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{label} . '-usage', exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
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("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;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{label} = $options{extra_options}->{label_ref};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_used'} + $options{new_datas}->{$self->{instance} . '_free'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'};
$self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'memory', type => 0, cb_prefix_output => 'prefix_memory_output' },
{ name => 'swap', type => 0, cb_prefix_output => 'prefix_swap_output' }
];
$self->{maps_counters}->{memory} = [
{ label => 'physical-usage', set => {
key_values => [ { name => 'free' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'physical' },
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'),
}
},
];
$self->{maps_counters}->{swap} = [
{ label => 'swap-usage', set => {
key_values => [ { name => 'free' }, { name => 'used' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'swap' },
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'),
}
},
];
}
sub prefix_memory_output {
my ($self, %options) = @_;
return "Physical memory ";
}
sub prefix_swap_output {
my ($self, %options) = @_;
return "Swap memory ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-counters:s" => { name => 'filter_counters' },
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_computerSystemFreeMemory = '.1.3.6.1.4.1.11.2.3.1.1.7.0'; # in KB
my $oid_computerSystemPhysMemory = '.1.3.6.1.4.1.11.2.3.1.1.8.0'; # in KB
my $oid_computerSystemSwapConfig = '.1.3.6.1.4.1.11.2.3.1.1.10.0'; # in KB
my $oid_computerSystemFreeSwap = '.1.3.6.1.4.1.11.2.3.1.1.12.0'; # in KB
my $result = $options{snmp}->get_leef(oids => [$oid_computerSystemFreeMemory, $oid_computerSystemPhysMemory,
$oid_computerSystemSwapConfig, $oid_computerSystemFreeSwap],
nothing_quit => 1);
$self->{memory} = {
free => $result->{$oid_computerSystemFreeMemory} * 1024,
used => $result->{$oid_computerSystemPhysMemory} * 1024 - $result->{$oid_computerSystemFreeMemory} * 1024,
};
$self->{swap} = {
free => $result->{$oid_computerSystemFreeSwap} * 1024,
used => $result->{$oid_computerSystemSwapConfig} * 1024 - $result->{$oid_computerSystemFreeSwap} * 1024,
};
}
1;
__END__
=head1 MODE
Check memory usages.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example : --filter-counters='^physical-usage$'
=item B<--warning-*>
Threshold warning.
Can be: 'physical-usage' (%), 'swap-usage' (%).
=item B<--critical-*>
Threshold critical.
Can be: 'physical-usage' (%), 'swap-usage' (%).
=back
=cut

View File

@ -0,0 +1,199 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package os::hpux::snmp::mode::process;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
my %map_process_status = (
1 => 'sleep',
2 => 'run',
3 => 'stop',
4 => 'zombie',
5 => 'other',
6 => 'idle',
);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"process-cmd:s" => { name => 'process_cmd', },
"regexp-cmd" => { name => 'regexp_cmd', },
"process-status:s" => { name => 'process_status', default => 'run' },
});
return $self;
}
sub check_options {
my ($self, %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();
}
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();
}
}
my $oids = {
status => '.1.3.6.1.4.1.11.2.3.1.4.2.1.19', # processStatus
cmd => '.1.3.6.1.4.1.11.2.3.1.4.2.1.22', # processCmd
};
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
my $oid2check_filter = 'status';
# To have a better order
foreach (('cmd', 'status')) {
if (defined($self->{option_results}->{'process_' . $_}) && $self->{option_results}->{'process_' . $_} ne '') {
$oid2check_filter = $_;
last;
}
}
# Build other
my $mores_filters = {};
my $more_oids = [];
foreach (keys %$oids) {
if ($_ ne $oid2check_filter && defined($self->{option_results}->{'process_' . $_}) && $self->{option_results}->{'process_' . $_} ne '') {
push @{$more_oids}, $oids->{$_};
$mores_filters->{$_} = 1;
}
}
my $oids_multiple_table = [ { oid => $oids->{$oid2check_filter} } ];
$self->{results} = $self->{snmp}->get_multiple_table(oids => $oids_multiple_table);
my $result = $self->{results}->{$oids->{$oid2check_filter}};
my $instances_keep = {};
foreach my $key ($self->{snmp}->oid_lex_sort(keys %{$result})) {
my $option_val = $self->{option_results}->{'process_' . $oid2check_filter};
if ($oid2check_filter eq 'status') {
if ($map_process_status{$result->{$key}} =~ /$option_val/) {
$key =~ /\.([0-9]+)$/;
$instances_keep->{$1} = 1;
}
} elsif ((defined($self->{option_results}->{'regexp_' . $oid2check_filter}) && $result->{$key} =~ /$option_val/)
|| (!defined($self->{option_results}->{'regexp_' . $oid2check_filter}) && $result->{$key} eq $option_val)) {
$key =~ /\.([0-9]+)$/;
$instances_keep->{$1} = 1;
}
}
my $result2;
if (scalar(keys %$instances_keep) > 0) {
if (scalar(@$more_oids) > 0) {
$self->{snmp}->load(oids => $more_oids, instances => [ keys %$instances_keep ]);
$result2 = $self->{snmp}->get_leef();
}
foreach my $key (keys %$instances_keep) {
my $value = ($oid2check_filter eq 'status') ? $map_process_status{$result->{$oids->{$oid2check_filter} . '.' . $key}} : $result->{$oids->{$oid2check_filter} . '.' . $key};
my $long_value = '[ ' . $oid2check_filter . ' => ' . $value . ' ]';
my $deleted = 0;
foreach (keys %$mores_filters) {
my $opt_val = $self->{option_results}->{'process_' . $_};
$value = ($_ eq 'status') ? $map_process_status{$result2->{$oids->{$_} . '.' . $key}} : $result2->{$oids->{$_} . '.' . $key};
if ($_ eq 'status') {
if ($value !~ /$opt_val/) {
delete $instances_keep->{$key};
$deleted = 1;
last;
}
} elsif ((defined($self->{option_results}->{'regexp_' . $_}) && $value !~ /$opt_val/)
|| (!defined($self->{option_results}->{'regexp_' . $_}) && $value ne $opt_val)) {
delete $instances_keep->{$key};
$deleted = 1;
last;
}
$long_value .= ' [ ' . $_ . ' => ' . $value . ' ]';
}
if ($deleted == 0) {
$self->{output}->output_add(long_msg => 'Process: ' . $long_value);
}
}
}
my $num_processes_match = scalar(keys(%$instances_keep));
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 running: $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();
}
1;
__END__
=head1 MODE
Check system number of processes.
=over 8
=item B<--warning>
Threshold warning (process count).
=item B<--critical>
Threshold critical (process count).
=item B<--process-cmd>
Check process command.
=item B<--regexp-cmd>
Allows to use regexp to filter process command (with option --process-cmd).
=item B<--process-status>
Check process status (Default: 'run'). Can be a regexp.
=back
=cut

View File

@ -0,0 +1,214 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package os::hpux::snmp::mode::storage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
my $instance_mode;
sub custom_usage_perfdata {
my ($self, %options) = @_;
my $label = 'used';
my $value_perf = $self->{result_values}->{used};
if (defined($instance_mode->{option_results}->{free})) {
$label = 'free';
$value_perf = $self->{result_values}->{free};
}
my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
my %total_options = ();
if ($instance_mode->{option_results}->{units} eq '%') {
$total_options{total} = $self->{result_values}->{total};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B',
value => $value_perf,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options),
min => 0, max => $self->{result_values}->{total});
}
sub custom_usage_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value);
$threshold_value = $self->{result_values}->{used};
$threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free}));
if ($instance_mode->{option_results}->{units} eq '%') {
$threshold_value = $self->{result_values}->{prct_used};
$threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free}));
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]);
return $exit;
}
sub custom_usage_output {
my ($self, %options) = @_;
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;
}
sub custom_usage_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'};
$self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used};
$self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used};
return 0;
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok' }
];
$self->{maps_counters}->{storage} = [
{ label => 'usage', set => {
key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ],
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'),
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
"units:s" => { name => 'units', default => '%' },
"free" => { name => 'free' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$instance_mode = $self;
}
sub prefix_storage_output {
my ($self, %options) = @_;
return "Storage '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
fileSystemName => { oid => '.1.3.6.1.4.1.11.2.3.1.2.2.1.3' },
fileSystemBlock => { oid => '.1.3.6.1.4.1.11.2.3.1.2.2.1.4' },
fileSystemBfree => { oid => '.1.3.6.1.4.1.11.2.3.1.2.2.1.5' },
fileSystemBavail => { oid => '.1.3.6.1.4.1.11.2.3.1.2.2.1.6' },
fileSystemBsize => { oid => '.1.3.6.1.4.1.11.2.3.1.2.2.1.7' },
fileSystemDir => { oid => '.1.3.6.1.4.1.11.2.3.1.2.2.1.10' },
};
my $oid_fileSystemEntry = '.1.3.6.1.4.1.11.2.3.1.2.2.1';
sub manage_selection {
my ($self, %options) = @_;
$self->{storage} = {};
$self->{results} = $options{snmp}->get_table(oid => $oid_fileSystemEntry,
nothing_quit => 1);
foreach my $oid (keys %{$self->{results}}) {
next if ($oid !~ /^$mapping->{fileSystemDir}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{fileSystemDir} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{fileSystemDir} . "': no matching filter.", debug => 1);
next;
}
$self->{storage}->{$instance} = { display => $result->{fileSystemDir},
total => $result->{fileSystemBlock} * $result->{fileSystemBsize},
used => $result->{fileSystemBlock} * $result->{fileSystemBsize} - $result->{fileSystemBavail} * $result->{fileSystemBsize} };
}
if (scalar(keys %{$self->{storage}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No storage found.");
$self->{output}->option_exit();
}
}
1;
__END__
=head1 MODE
Check storages.
=over 8
=item B<--filter-name>
Filter path name (can be a regexp).
=item B<--warning-*>
Threshold warning.
Can be: 'usage'.
=item B<--critical-*>
Threshold critical.
Can be: 'usage'.
=item B<--units>
Units of thresholds (Default: '%') ('%', 'B').
=item B<--free>
Thresholds are on free space left.
=back
=cut

54
os/hpux/snmp/plugin.pm Normal file
View File

@ -0,0 +1,54 @@
#
# Copyright 2016 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package os::hpux::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'cpu' => 'os::hpux::snmp::mode::cpu',
'load' => 'os::hpux::snmp::mode::load',
'memory' => 'os::hpux::snmp::mode::memory',
'process' => 'os::hpux::snmp::mode::process',
'storage' => 'os::hpux::snmp::mode::storage',
'tcpcon' => 'snmp_standard::mode::tcpcon',
'uptime' => 'snmp_standard::mode::uptime',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check HP-UX operating systems in SNMP.
=cut