| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package os::hpux::snmp::mode::cpu; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub set_counters { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
$self->{maps_counters_type} = [ |
| 33 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output' }, |
| 34 |
]; |
| 35 |
$self->{maps_counters}->{global} = [ |
| 36 |
{ label => 'user', set => { |
| 37 |
key_values => [ { name => 'total', diff => 1 }, { name => 'user', diff => 1 } ], |
| 38 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'user' }, |
| 39 |
output_template => 'User %.2f %%', output_use => 'user_prct', threshold_use => 'user_prct', |
| 40 |
perfdatas => [ |
| 41 |
{ label => 'user', value => 'user_prct', template => '%.2f', min => 0, max => 100, unit => '%' }, |
| 42 |
], |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'sys', set => { |
| 46 |
key_values => [ { name => 'total', diff => 1 }, { name => 'sys', diff => 1 } ], |
| 47 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'sys' }, |
| 48 |
output_template => 'System %.2f %%', output_use => 'sys_prct', threshold_use => 'sys_prct', |
| 49 |
perfdatas => [ |
| 50 |
{ label => 'sys', value => 'sys_prct', template => '%.2f', min => 0, max => 100, unit => '%' }, |
| 51 |
], |
| 52 |
} |
| 53 |
}, |
| 54 |
{ label => 'nice', set => { |
| 55 |
key_values => [ { name => 'total', diff => 1 }, { name => 'nice', diff => 1 } ], |
| 56 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'nice' }, |
| 57 |
output_template => 'Nice %.2f %%', output_use => 'nice_prct', threshold_use => 'nice_prct', |
| 58 |
perfdatas => [ |
| 59 |
{ label => 'nice', value => 'nice_prct', template => '%.2f', min => 0, max => 100, unit => '%' }, |
| 60 |
], |
| 61 |
} |
| 62 |
}, |
| 63 |
{ label => 'idle', set => { |
| 64 |
key_values => [ { name => 'total', diff => 1 }, { name => 'idle', diff => 1 } ], |
| 65 |
closure_custom_calc => $self->can('custom_data_calc'), closure_custom_calc_extra_options => { label_ref => 'idle' }, |
| 66 |
output_template => 'Idle %.2f %%', output_use => 'idle_prct', threshold_use => 'idle_prct', |
| 67 |
perfdatas => [ |
| 68 |
{ label => 'idle', value => 'idle_prct', template => '%.2f', min => 0, max => 100, unit => '%' }, |
| 69 |
], |
| 70 |
} |
| 71 |
}, |
| 72 |
]; |
| 73 |
} |
| 74 |
|
| 75 |
sub custom_data_calc { |
| 76 |
my ($self, %options) = @_; |
| 77 |
|
| 78 |
my $label = $options{extra_options}->{label_ref}; |
| 79 |
my $delta_value = $options{new_datas}->{$self->{instance} . '_' . $label} - $options{old_datas}->{$self->{instance} . '_' . $label}; |
| 80 |
my $delta_total = $options{new_datas}->{$self->{instance} . '_total'} - $options{old_datas}->{$self->{instance} . '_total'}; |
| 81 |
|
| 82 |
$self->{result_values}->{$label . '_prct'} = 0; |
| 83 |
if ($delta_total > 0) { |
| 84 |
$self->{result_values}->{$label . '_prct'} = $delta_value * 100 / $delta_total; |
| 85 |
} |
| 86 |
return 0; |
| 87 |
} |
| 88 |
|
| 89 |
sub prefix_output { |
| 90 |
my ($self, %options) = @_; |
| 91 |
|
| 92 |
return "CPU Usage : "; |
| 93 |
} |
| 94 |
|
| 95 |
sub new { |
| 96 |
my ($class, %options) = @_; |
| 97 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 98 |
bless $self, $class; |
| 99 |
|
| 100 |
$options{options}->add_options(arguments => |
| 101 |
{ |
| 102 |
"filter-counters:s" => { name => 'filter_counters' }, |
| 103 |
}); |
| 104 |
|
| 105 |
return $self; |
| 106 |
} |
| 107 |
|
| 108 |
sub manage_selection { |
| 109 |
my ($self, %options) = @_; |
| 110 |
|
| 111 |
$self->{cache_name} = "hpux_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . |
| 112 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); |
| 113 |
|
| 114 |
my $oid_computerSystemUserCPU = '.1.3.6.1.4.1.11.2.3.1.1.13.0'; |
| 115 |
my $oid_computerSystemSysCPU = '.1.3.6.1.4.1.11.2.3.1.1.14.0'; |
| 116 |
my $oid_computerSystemIdleCPU = '.1.3.6.1.4.1.11.2.3.1.1.15.0'; |
| 117 |
my $oid_computerSystemNiceCPU = '.1.3.6.1.4.1.11.2.3.1.1.16.0'; |
| 118 |
|
| 119 |
my $result = $options{snmp}->get_leef(oids => [$oid_computerSystemUserCPU, $oid_computerSystemSysCPU, |
| 120 |
$oid_computerSystemIdleCPU, $oid_computerSystemNiceCPU], |
| 121 |
nothing_quit => 1); |
| 122 |
$self->{global} = { |
| 123 |
total => $result->{$oid_computerSystemUserCPU} + $result->{$oid_computerSystemSysCPU} + $result->{$oid_computerSystemIdleCPU} + $result->{$oid_computerSystemNiceCPU}, |
| 124 |
sys => $result->{$oid_computerSystemSysCPU}, |
| 125 |
user => $result->{$oid_computerSystemUserCPU}, |
| 126 |
idle => $result->{$oid_computerSystemIdleCPU}, |
| 127 |
nice => $result->{$oid_computerSystemNiceCPU}, |
| 128 |
}; |
| 129 |
} |
| 130 |
|
| 131 |
1; |
| 132 |
|
| 133 |
__END__ |
| 134 |
|
| 135 |
=head1 MODE |
| 136 |
|
| 137 |
Check system CPUs. |
| 138 |
|
| 139 |
=over 8 |
| 140 |
|
| 141 |
=item B<--filter-counters> |
| 142 |
|
| 143 |
Only display some counters (regexp can be used). |
| 144 |
Example : --filter-counters='^idle$' |
| 145 |
|
| 146 |
=item B<--warning-*> |
| 147 |
|
| 148 |
Warning threshold. |
| 149 |
Can be: 'user', 'sys', 'idle', 'nice'. |
| 150 |
|
| 151 |
=item B<--critical-*> |
| 152 |
|
| 153 |
Critical threshold. |
| 154 |
Can be: 'user', 'sys', 'idle', 'nice'. |
| 155 |
|
| 156 |
=back |
| 157 |
|
| 158 |
=cut |