| 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 |
package network::cambium::cnpilot::snmp::mode::cpu; |
| 21 |
|
| 22 |
use base qw(centreon::plugins::templates::counter); |
| 23 |
|
| 24 |
use strict; |
| 25 |
use warnings; |
| 26 |
|
| 27 |
sub prefix_cpu_output { |
| 28 |
my ($self, %options) = @_; |
| 29 |
|
| 30 |
return "CPU '" . $options{instance_value}->{name} . "' usage: "; |
| 31 |
} |
| 32 |
|
| 33 |
sub set_counters { |
| 34 |
my ($self, %options) = @_; |
| 35 |
|
| 36 |
$self->{maps_counters_type} = [ |
| 37 |
{ name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' } |
| 38 |
]; |
| 39 |
|
| 40 |
$self->{maps_counters}->{cpu} = [ |
| 41 |
{ label => 'cpu-usage-prct', nlabel => 'cpu.usage.percentage', set => { |
| 42 |
key_values => [ { name => 'cpu_usage' }, { name => 'name' } ], |
| 43 |
output_template => '%.2f %%', |
| 44 |
perfdatas => [ |
| 45 |
{ label => 'cpu', template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'name' } |
| 46 |
] |
| 47 |
} |
| 48 |
} |
| 49 |
]; |
| 50 |
} |
| 51 |
|
| 52 |
sub new { |
| 53 |
my ($class, %options) = @_; |
| 54 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 55 |
bless $self, $class; |
| 56 |
|
| 57 |
$options{options}->add_options(arguments => { |
| 58 |
'filter-ap:s' => { name => 'filter_ap' } |
| 59 |
}); |
| 60 |
|
| 61 |
return $self; |
| 62 |
} |
| 63 |
|
| 64 |
sub manage_selection { |
| 65 |
my ($self, %options) = @_; |
| 66 |
|
| 67 |
# Select relevant oids for CPU monitoring |
| 68 |
my $mapping = { |
| 69 |
cambiumAPName => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.2' }, |
| 70 |
cambiumAPCPUUtilization => { oid => '.1.3.6.1.4.1.17713.22.1.1.1.6' } |
| 71 |
}; |
| 72 |
|
| 73 |
# Point at the begining of the table |
| 74 |
my $oid_cambiumAccessPointEntry = '.1.3.6.1.4.1.17713.22.1.1.1'; |
| 75 |
|
| 76 |
my $cpu_result = $options{snmp}->get_table( |
| 77 |
oid => $oid_cambiumAccessPointEntry, |
| 78 |
nothing_quit => 1 |
| 79 |
); |
| 80 |
|
| 81 |
foreach my $oid (keys %{$cpu_result}) { |
| 82 |
next if ($oid !~ /^$mapping->{cambiumAPName}->{oid}\.(.*)$/); |
| 83 |
# Catch instance in table |
| 84 |
my $instance = $1; |
| 85 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $cpu_result, instance => $instance); |
| 86 |
|
| 87 |
if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && |
| 88 |
$result->{cambiumAPName} !~ /$self->{option_results}->{filter_ap}/) { |
| 89 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{cambiumAPName} . "': no matching filter.", debug => 1); |
| 90 |
next; |
| 91 |
} |
| 92 |
|
| 93 |
$self->{cpu}->{$instance} = { |
| 94 |
name => $result->{cambiumAPName}, |
| 95 |
cpu_usage => $result->{cambiumAPCPUUtilization} |
| 96 |
}; |
| 97 |
} |
| 98 |
|
| 99 |
if (scalar(keys %{$self->{cpu}}) <= 0) { |
| 100 |
$self->{output}->add_option_msg(short_msg => "No AP matching with filter found."); |
| 101 |
$self->{output}->option_exit(); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
1; |
| 106 |
|
| 107 |
__END__ |
| 108 |
|
| 109 |
=head1 MODE |
| 110 |
|
| 111 |
Check CPU usage. |
| 112 |
|
| 113 |
=over 8 |
| 114 |
|
| 115 |
=item B<--filter-ap> |
| 116 |
|
| 117 |
Filter on one AP name. |
| 118 |
|
| 119 |
=item B<--warning> |
| 120 |
|
| 121 |
Warning threshold for CPU. |
| 122 |
|
| 123 |
=item B<--critical> |
| 124 |
|
| 125 |
Critical threshold for CPU. |
| 126 |
|
| 127 |
=back |
| 128 |
|
| 129 |
=cut |