| 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 network::perle::ids::snmp::mode::systemusage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub set_counters { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{maps_counters_type} = [ |
| 32 |
{ name => 'global', type => 0, message_separator => ' - ' }, |
| 33 |
]; |
| 34 |
|
| 35 |
$self->{maps_counters}->{global} = [ |
| 36 |
{ label => 'cpu-load', nlabel => 'cpu.utilization.percentage', set => { |
| 37 |
key_values => [ { name => 'cpu_load' } ], |
| 38 |
output_template => 'cpu load : %.2f %%', |
| 39 |
perfdatas => [ |
| 40 |
{ value => 'cpu_load', template => '%.2f', |
| 41 |
min => 0, max => 100, unit => '%' }, |
| 42 |
], |
| 43 |
} |
| 44 |
}, |
| 45 |
{ label => 'memory-free', nlabel => 'memory.free.bytes', set => { |
| 46 |
key_values => [ { name => 'memory_free' } ], |
| 47 |
output_template => 'memory free : %s %s', |
| 48 |
output_change_bytes => 1, |
| 49 |
perfdatas => [ |
| 50 |
{ value => 'memory_free', template => '%d', |
| 51 |
min => 0, unit => 'B' }, |
| 52 |
], |
| 53 |
} |
| 54 |
}, |
| 55 |
{ label => 'flashdisk-free', nlabel => 'flashdisk.free.bytes', set => { |
| 56 |
key_values => [ { name => 'flashdisk_free' } ], |
| 57 |
output_template => 'flash disk free : %s %s', |
| 58 |
output_change_bytes => 1, |
| 59 |
perfdatas => [ |
| 60 |
{ value => 'flashdisk_free', template => '%d', |
| 61 |
min => 0, unit => 'B' }, |
| 62 |
], |
| 63 |
} |
| 64 |
}, |
| 65 |
]; |
| 66 |
} |
| 67 |
|
| 68 |
sub new { |
| 69 |
my ($class, %options) = @_; |
| 70 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 71 |
bless $self, $class; |
| 72 |
|
| 73 |
$options{options}->add_options(arguments => {}); |
| 74 |
|
| 75 |
return $self; |
| 76 |
} |
| 77 |
|
| 78 |
sub manage_selection { |
| 79 |
my ($self, %options) = @_; |
| 80 |
|
| 81 |
my $oid_perleAverageCPUUtilization = '.1.3.6.1.4.1.1966.22.44.1.24.0'; |
| 82 |
my $oid_perleMemory = '.1.3.6.1.4.1.1966.22.44.1.25.0'; # 295928 Kbytes free |
| 83 |
my $oid_perleFlashdisk = '.1.3.6.1.4.1.1966.22.44.1.26.0'; |
| 84 |
my $result = $options{snmp}->get_leef( |
| 85 |
oids => [ |
| 86 |
$oid_perleAverageCPUUtilization, $oid_perleMemory, $oid_perleFlashdisk |
| 87 |
], |
| 88 |
nothing_quit => 1 |
| 89 |
); |
| 90 |
|
| 91 |
my ($cpu_load, $mem_free, $flashdisk_free); |
| 92 |
$cpu_load = $1 |
| 93 |
if (defined($result->{$oid_perleAverageCPUUtilization}) && $result->{$oid_perleAverageCPUUtilization} =~ /((?:\d+)(?:\.\d+)?)/); |
| 94 |
$mem_free = $1 * 1024 if (defined($result->{$oid_perleMemory}) && $result->{$oid_perleMemory} =~ /(\d+)/); |
| 95 |
$flashdisk_free = $1 * 1024 if (defined($result->{$oid_perleFlashdisk}) && $result->{$oid_perleFlashdisk} =~ /(\d+)/); |
| 96 |
$self->{global} = { |
| 97 |
cpu_load => $cpu_load, |
| 98 |
memory_free => $mem_free, |
| 99 |
flashdisk_free => $flashdisk_free, |
| 100 |
}; |
| 101 |
} |
| 102 |
|
| 103 |
1; |
| 104 |
|
| 105 |
__END__ |
| 106 |
|
| 107 |
=head1 MODE |
| 108 |
|
| 109 |
Check system usage. |
| 110 |
|
| 111 |
=over 8 |
| 112 |
|
| 113 |
=item B<--filter-counters> |
| 114 |
|
| 115 |
Only display some counters (regexp can be used). |
| 116 |
Example: --filter-counters='^memory-free$' |
| 117 |
|
| 118 |
=item B<--warning-*> B<--critical-*> |
| 119 |
|
| 120 |
Thresholds. |
| 121 |
Can be: 'memory-free' (B), 'cpu-load' (%), 'flashdisk-free' (B) |
| 122 |
|
| 123 |
=back |
| 124 |
|
| 125 |
=cut |