-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ add plugin for hp-ux in snmp (Fix #13)
- Loading branch information
garnier-quentin
committed
Sep 1, 2016
1 parent
48c2453
commit 822decb
Showing
6 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Oops, something went wrong.