| 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::aruba::instant::snmp::mode::apusage; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng); |
| 28 |
|
| 29 |
sub custom_status_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my $msg = "Status is '" . $self->{result_values}->{status} . "'"; |
| 33 |
return $msg; |
| 34 |
} |
| 35 |
|
| 36 |
sub custom_memory_output { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
my $msg = sprintf("Memory Total: %s %s Used: %s %s (%.2f%%) Free: %s %s (%.2f%%)", |
| 40 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{total}), |
| 41 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{used}), |
| 42 |
$self->{result_values}->{prct_used}, |
| 43 |
$self->{perfdata}->change_bytes(value => $self->{result_values}->{free}), |
| 44 |
$self->{result_values}->{prct_free}); |
| 45 |
return $msg; |
| 46 |
} |
| 47 |
|
| 48 |
sub prefix_ap_output { |
| 49 |
my ($self, %options) = @_; |
| 50 |
|
| 51 |
return "Access Point '" . $options{instance_value}->{display} . "' "; |
| 52 |
} |
| 53 |
|
| 54 |
sub set_counters { |
| 55 |
my ($self, %options) = @_; |
| 56 |
|
| 57 |
$self->{maps_counters_type} = [ |
| 58 |
{ name => 'global', type => 0 }, |
| 59 |
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', |
| 60 |
message_multiple => 'All access points are ok', skipped_code => { -10 => 1 } } |
| 61 |
]; |
| 62 |
|
| 63 |
$self->{maps_counters}->{global} = [ |
| 64 |
{ label => 'total-ap', nlabel => 'accesspoints.total.count', set => { |
| 65 |
key_values => [ { name => 'total' } ], |
| 66 |
output_template => 'total access points: %s', |
| 67 |
perfdatas => [ |
| 68 |
{ template => '%s', min => 0 } |
| 69 |
] |
| 70 |
} |
| 71 |
} |
| 72 |
]; |
| 73 |
|
| 74 |
$self->{maps_counters}->{ap} = [ |
| 75 |
{ label => 'status', type => 2, critical_default => '%{status} !~ /up/i', set => { |
| 76 |
key_values => [ { name => 'status' }, { name => 'display' } ], |
| 77 |
closure_custom_output => $self->can('custom_status_output'), |
| 78 |
closure_custom_perfdata => sub { return 0; }, |
| 79 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 80 |
} |
| 81 |
}, |
| 82 |
{ label => 'clients', nlabel => 'clients.current.count', set => { |
| 83 |
key_values => [ { name => 'clients' }, { name => 'display' } ], |
| 84 |
output_template => 'Current Clients: %s', |
| 85 |
perfdatas => [ |
| 86 |
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 87 |
] |
| 88 |
} |
| 89 |
}, |
| 90 |
{ label => 'cpu', nlabel => 'cpu.utilization.percentage', set => { |
| 91 |
key_values => [ { name => 'cpu' }, { name => 'display' } ], |
| 92 |
output_template => 'Cpu: %.2f%%', |
| 93 |
perfdatas => [ |
| 94 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' } |
| 95 |
] |
| 96 |
} |
| 97 |
}, |
| 98 |
{ label => 'mem-usage', nlabel => 'memory.usage.bytes', set => { |
| 99 |
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, |
| 100 |
{ name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], |
| 101 |
closure_custom_output => $self->can('custom_memory_output'), |
| 102 |
perfdatas => [ |
| 103 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' } |
| 104 |
] |
| 105 |
} |
| 106 |
}, |
| 107 |
{ label => 'mem-usage-free', display_ok => 0, nlabel => 'memory.free.bytes', set => { |
| 108 |
key_values => [ { name => 'free' }, { name => 'used' }, { name => 'prct_used' }, |
| 109 |
{ name => 'prct_free' }, { name => 'total' }, { name => 'display' } ], |
| 110 |
closure_custom_output => $self->can('custom_memory_output'), |
| 111 |
perfdatas => [ |
| 112 |
{ template => '%d', min => 0, max => 'total', unit => 'B', cast_int => 1, label_extra_instance => 1, instance_use => 'display' } |
| 113 |
] |
| 114 |
} |
| 115 |
}, |
| 116 |
{ label => 'mem-usage-prct', display_ok => 0, nlabel => 'memory.usage.percentage', set => { |
| 117 |
key_values => [ { name => 'prct_used' }, { name => 'display' } ], |
| 118 |
output_template => 'Memory Used: %.2f %%', |
| 119 |
perfdatas => [ |
| 120 |
{ template => '%.2f', min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display' } |
| 121 |
] |
| 122 |
} |
| 123 |
} |
| 124 |
]; |
| 125 |
} |
| 126 |
|
| 127 |
sub new { |
| 128 |
my ($class, %options) = @_; |
| 129 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 130 |
bless $self, $class; |
| 131 |
|
| 132 |
$options{options}->add_options(arguments => { |
| 133 |
'filter-name:s' => { name => 'filter_name' } |
| 134 |
}); |
| 135 |
|
| 136 |
return $self; |
| 137 |
} |
| 138 |
|
| 139 |
my $map_ap_status = { |
| 140 |
1 => 'up', 2 => 'down' |
| 141 |
}; |
| 142 |
|
| 143 |
my $mapping = { |
| 144 |
aiAPName => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.2' }, |
| 145 |
aiAPIPAddress => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.3' }, |
| 146 |
aiAPCPUUtilization => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.7' }, |
| 147 |
aiAPMemoryFree => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.8' }, |
| 148 |
aiAPTotalMemory => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.10' }, |
| 149 |
aiAPStatus => { oid => '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1.11', map => $map_ap_status } |
| 150 |
}; |
| 151 |
my $oid_aiAccessPointEntry = '.1.3.6.1.4.1.14823.2.3.3.1.2.1.1'; |
| 152 |
my $oid_aiClientAPIPAddress = '.1.3.6.1.4.1.14823.2.3.3.1.2.4.1.4'; |
| 153 |
|
| 154 |
sub manage_selection { |
| 155 |
my ($self, %options) = @_; |
| 156 |
|
| 157 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 158 |
oids => [ |
| 159 |
{ oid => $oid_aiAccessPointEntry, start => $mapping->{aiAPName}->{oid}, end => $mapping->{aiAPStatus}->{oid} }, |
| 160 |
{ oid => $oid_aiClientAPIPAddress } |
| 161 |
] |
| 162 |
); |
| 163 |
|
| 164 |
my $link_ap = {}; |
| 165 |
$self->{global} = { total => 0 }; |
| 166 |
$self->{ap} = {}; |
| 167 |
foreach my $oid (keys %{$snmp_result->{$oid_aiAccessPointEntry}}) { |
| 168 |
next if ($oid !~ /^$mapping->{aiAPName}->{oid}\.(.*)$/); |
| 169 |
my $instance = $1; |
| 170 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_aiAccessPointEntry}, instance => $instance); |
| 171 |
|
| 172 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 173 |
$result->{aiAPName} !~ /$self->{option_results}->{filter_name}/) { |
| 174 |
$self->{output}->output_add(long_msg => "skipping access point '" . $result->{aiAPName} . "'.", debug => 1); |
| 175 |
next; |
| 176 |
} |
| 177 |
|
| 178 |
$self->{global}->{total}++; |
| 179 |
$self->{ap}->{ $result->{aiAPName} } = { |
| 180 |
display => $result->{aiAPName}, |
| 181 |
status => $result->{aiAPStatus}, |
| 182 |
cpu => $result->{aiAPCPUUtilization}, |
| 183 |
clients => 0 |
| 184 |
}; |
| 185 |
if (defined($result->{aiAPTotalMemory}) && $result->{aiAPTotalMemory} > 0) { |
| 186 |
$self->{ap}->{ $result->{aiAPName} }->{free} = $result->{aiAPMemoryFree}; |
| 187 |
$self->{ap}->{ $result->{aiAPName} }->{total} = $result->{aiAPTotalMemory}; |
| 188 |
$self->{ap}->{ $result->{aiAPName} }->{used} = $result->{aiAPTotalMemory} - $result->{aiAPMemoryFree}; |
| 189 |
$self->{ap}->{ $result->{aiAPName} }->{prct_free} = $result->{aiAPMemoryFree} * 100 / $result->{aiAPTotalMemory}; |
| 190 |
$self->{ap}->{ $result->{aiAPName} }->{prct_used} = 100 - ($result->{aiAPMemoryFree} * 100 / $result->{aiAPTotalMemory}); |
| 191 |
} |
| 192 |
$link_ap->{ $result->{aiAPIPAddress} } = $self->{ap}->{$result->{aiAPName}}; |
| 193 |
} |
| 194 |
|
| 195 |
if (scalar(keys %{$snmp_result->{$oid_aiAccessPointEntry}}) == 0 && scalar(keys %{$snmp_result->{$oid_aiClientAPIPAddress}}) > 0) { |
| 196 |
$self->{ap}->{default} = { |
| 197 |
display => 'default', |
| 198 |
clients => 0 |
| 199 |
}; |
| 200 |
} |
| 201 |
|
| 202 |
foreach my $oid (keys %{$snmp_result->{$oid_aiClientAPIPAddress}}) { |
| 203 |
my $ap_ipaddress = $snmp_result->{$oid_aiClientAPIPAddress}->{$oid}; |
| 204 |
if (defined($link_ap->{$ap_ipaddress})) { |
| 205 |
$link_ap->{$ap_ipaddress}->{clients}++; |
| 206 |
} elsif (defined($self->{ap}->{default})) { # default "AP" is only handled when no AP is identified (see above) |
| 207 |
$self->{ap}->{default}->{clients}++; |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
1; |
| 213 |
|
| 214 |
__END__ |
| 215 |
|
| 216 |
=head1 MODE |
| 217 |
|
| 218 |
Check access point usage. |
| 219 |
|
| 220 |
=over 8 |
| 221 |
|
| 222 |
=item B<--filter-counters> |
| 223 |
|
| 224 |
Only display some counters (regexp can be used). |
| 225 |
Example: --filter-counters='^cpu$' |
| 226 |
|
| 227 |
=item B<--filter-name> |
| 228 |
|
| 229 |
Filter access point name (can be a regexp). |
| 230 |
|
| 231 |
=item B<--warning-status> |
| 232 |
|
| 233 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 234 |
You can use the following variables: %{status}, %{display} |
| 235 |
|
| 236 |
=item B<--critical-status> |
| 237 |
|
| 238 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} !~ /up/i'). |
| 239 |
You can use the following variables: %{status}, %{display} |
| 240 |
|
| 241 |
=item B<--warning-*> B<--critical-*> |
| 242 |
|
| 243 |
Thresholds. |
| 244 |
Can be: 'total-ap', 'cpu', 'clients', |
| 245 |
'mem-usage' (B), 'mem-usage-free' (B), 'mem-usage-prct' (%). |
| 246 |
|
| 247 |
=back |
| 248 |
|
| 249 |
=cut |