| 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 centreon::common::fortinet::fortigate::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); |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return 'status: ' . $self->{result_values}->{status} . ' [admin: ' . $self->{result_values}->{admin} . ']'; |
| 34 |
} |
| 35 |
|
| 36 |
sub set_counters { |
| 37 |
my ($self, %options) = @_; |
| 38 |
|
| 39 |
$self->{maps_counters_type} = [ |
| 40 |
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All access points are ok', skipped_code => { -10 => 1 } } |
| 41 |
]; |
| 42 |
|
| 43 |
$self->{maps_counters}->{ap} = [ |
| 44 |
{ label => 'status', threshold => 0, set => { |
| 45 |
key_values => [ { name => 'status' }, { name => 'admin' }, { name => 'display' } ], |
| 46 |
closure_custom_output => $self->can('custom_status_output'), |
| 47 |
closure_custom_perfdata => sub { return 0; }, |
| 48 |
closure_custom_threshold_check => \&catalog_status_threshold |
| 49 |
} |
| 50 |
}, |
| 51 |
{ label => 'in-traffic', nlabel => 'accesspoint.traffic.in.bitspersecond', set => { |
| 52 |
key_values => [ { name => 'in', per_second => 1 }, { name => 'display' } ], |
| 53 |
output_change_bytes => 2, |
| 54 |
output_template => 'traffic in: %s %s/s', |
| 55 |
perfdatas => [ |
| 56 |
{ label => 'traffic_in', template => '%.2f', |
| 57 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 58 |
] |
| 59 |
} |
| 60 |
}, |
| 61 |
{ label => 'out-traffic', nlabel => 'accesspoint.traffic.out.bitspersecond', set => { |
| 62 |
key_values => [ { name => 'out', per_second => 1 }, { name => 'display' } ], |
| 63 |
output_change_bytes => 2, |
| 64 |
output_template => 'traffic out: %s %s/s', |
| 65 |
perfdatas => [ |
| 66 |
{ label => 'traffic_out', template => '%.2f', |
| 67 |
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' } |
| 68 |
] |
| 69 |
} |
| 70 |
}, |
| 71 |
{ label => 'clients', nlabel => 'accesspoint.clients.current.count', set => { |
| 72 |
key_values => [ { name => 'clients' }, { name => 'display' } ], |
| 73 |
output_template => 'current client connections: %s', |
| 74 |
perfdatas => [ |
| 75 |
{ label => 'clients', template => '%s', |
| 76 |
min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 77 |
] |
| 78 |
} |
| 79 |
}, |
| 80 |
{ label => 'cpu', nlabel => 'accesspoint.cpu.utilization.percentage', set => { |
| 81 |
key_values => [ { name => 'cpu' }, { name => 'display' } ], |
| 82 |
output_template => 'cpu usage: %.2f %%', |
| 83 |
perfdatas => [ |
| 84 |
{ label => 'cpu', template => '%.2f', |
| 85 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 86 |
] |
| 87 |
} |
| 88 |
}, |
| 89 |
{ label => 'memory', nlabel => 'accesspoint.memory.usage.bytes', set => { |
| 90 |
key_values => [ { name => 'memory' }, { name => 'display' } ], |
| 91 |
output_template => 'memory usage: %.2f %%', |
| 92 |
perfdatas => [ |
| 93 |
{ label => 'memory', template => '%.2f', |
| 94 |
unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display' } |
| 95 |
] |
| 96 |
} |
| 97 |
} |
| 98 |
]; |
| 99 |
} |
| 100 |
|
| 101 |
sub prefix_ap_output { |
| 102 |
my ($self, %options) = @_; |
| 103 |
|
| 104 |
return "Access point '" . $options{instance_value}->{display} . "' "; |
| 105 |
} |
| 106 |
|
| 107 |
sub new { |
| 108 |
my ($class, %options) = @_; |
| 109 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); |
| 110 |
bless $self, $class; |
| 111 |
|
| 112 |
$options{options}->add_options(arguments => { |
| 113 |
'filter-name:s' => { name => 'filter_name' }, |
| 114 |
'unknown-status:s' => { name => 'unknown_status', default => '' }, |
| 115 |
'warning-status:s' => { name => 'warning_status', default => '' }, |
| 116 |
'critical-status:s' => { name => 'critical_status', default => '%{admin} eq "enable" and %{status} !~ /online/i' } |
| 117 |
}); |
| 118 |
|
| 119 |
return $self; |
| 120 |
} |
| 121 |
|
| 122 |
sub check_options { |
| 123 |
my ($self, %options) = @_; |
| 124 |
$self->SUPER::check_options(%options); |
| 125 |
|
| 126 |
$self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); |
| 127 |
} |
| 128 |
|
| 129 |
my %map_ap_admin = ( |
| 130 |
0 => 'other', 1 => 'discovered', 2 => 'disable', 3 => 'enable', |
| 131 |
); |
| 132 |
|
| 133 |
my %map_ap_connect_status = ( |
| 134 |
0 => 'other', 1 => 'offLine', 2 => 'onLine', 3 => 'downloadingImage', 4 => 'connectedImage', |
| 135 |
); |
| 136 |
|
| 137 |
my $mapping = { |
| 138 |
fgWcWtpConfigWtpAdmin => { oid => '.1.3.6.1.4.1.12356.101.14.4.3.1.2', map => \%map_ap_admin }, |
| 139 |
fgWcWtpConfigWtpName => { oid => '.1.3.6.1.4.1.12356.101.14.4.3.1.3' } |
| 140 |
}; |
| 141 |
|
| 142 |
my $mapping2 = { |
| 143 |
fgWcWtpSessionConnectionState => { oid => '.1.3.6.1.4.1.12356.101.14.4.4.1.7', map => \%map_ap_connect_status }, |
| 144 |
fgWcWtpSessionWtpStationCount => { oid => '.1.3.6.1.4.1.12356.101.14.4.4.1.17'}, |
| 145 |
fgWcWtpSessionWtpByteRxCount => { oid => '.1.3.6.1.4.1.12356.101.14.4.4.1.18' }, |
| 146 |
fgWcWtpSessionWtpByteTxCount => { oid => '.1.3.6.1.4.1.12356.101.14.4.4.1.19' }, |
| 147 |
fgWcWtpSessionWtpCpuUsage => { oid => '.1.3.6.1.4.1.12356.101.14.4.4.1.20' }, |
| 148 |
fgWcWtpSessionWtpMemoryUsage => { oid => '.1.3.6.1.4.1.12356.101.14.4.4.1.21' } |
| 149 |
}; |
| 150 |
my $oid_fgWcWtpConfigEntry = '.1.3.6.1.4.1.12356.101.14.4.3.1'; |
| 151 |
|
| 152 |
sub manage_selection { |
| 153 |
my ($self, %options) = @_; |
| 154 |
|
| 155 |
my $snmp_result = $options{snmp}->get_table( |
| 156 |
oid => $oid_fgWcWtpConfigEntry, |
| 157 |
start => $mapping->{fgWcWtpConfigWtpAdmin}->{oid}, |
| 158 |
end => $mapping->{fgWcWtpConfigWtpName}->{oid}, |
| 159 |
nothing_quit => 1 |
| 160 |
); |
| 161 |
|
| 162 |
$self->{ap} = {}; |
| 163 |
foreach my $oid (keys %{$snmp_result}) { |
| 164 |
next if ($oid !~ /^$mapping->{fgWcWtpConfigWtpName}->{oid}\.(.*)$/); |
| 165 |
my $instance = $1; |
| 166 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 167 |
|
| 168 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 169 |
$result->{fgWcWtpConfigWtpName} !~ /$self->{option_results}->{filter_name}/) { |
| 170 |
$self->{output}->output_add(long_msg => "skipping access point '" . $result->{fgWcWtpConfigWtpName} . "'.", debug => 1); |
| 171 |
next; |
| 172 |
} |
| 173 |
|
| 174 |
$self->{ap}->{$instance} = { |
| 175 |
display => $result->{fgWcWtpConfigWtpName}, |
| 176 |
admin => $result->{fgWcWtpConfigWtpAdmin}, |
| 177 |
status => 'n/a', |
| 178 |
}; |
| 179 |
} |
| 180 |
|
| 181 |
if (scalar(keys %{$self->{ap}}) <= 0) { |
| 182 |
$self->{output}->add_option_msg(short_msg => "No access point found."); |
| 183 |
$self->{output}->option_exit(); |
| 184 |
} |
| 185 |
|
| 186 |
$options{snmp}->load( |
| 187 |
oids => [ |
| 188 |
$mapping2->{fgWcWtpSessionConnectionState}->{oid}, $mapping2->{fgWcWtpSessionWtpStationCount}->{oid}, |
| 189 |
$mapping2->{fgWcWtpSessionWtpByteRxCount}->{oid}, $mapping2->{fgWcWtpSessionWtpByteTxCount}->{oid}, |
| 190 |
$mapping2->{fgWcWtpSessionWtpCpuUsage}->{oid}, $mapping2->{fgWcWtpSessionWtpMemoryUsage}->{oid}, |
| 191 |
], |
| 192 |
instances => [keys %{$self->{ap}}], |
| 193 |
instance_regexp => '^(.*)$' |
| 194 |
); |
| 195 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 196 |
|
| 197 |
foreach (keys %{$self->{ap}}) { |
| 198 |
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); |
| 199 |
|
| 200 |
$self->{ap}->{$_}->{status} = $result->{fgWcWtpSessionConnectionState}; |
| 201 |
$self->{ap}->{$_}->{in} = defined($result->{fgWcWtpSessionWtpByteRxCount}) ? ($result->{fgWcWtpSessionWtpByteRxCount} * 8) : undef; |
| 202 |
$self->{ap}->{$_}->{out} = defined($result->{fgWcWtpSessionWtpByteTxCount}) ? ($result->{fgWcWtpSessionWtpByteTxCount} * 8) : undef; |
| 203 |
$self->{ap}->{$_}->{clients} = $result->{fgWcWtpSessionWtpStationCount}; |
| 204 |
$self->{ap}->{$_}->{cpu} = $result->{fgWcWtpSessionWtpCpuUsage}; |
| 205 |
$self->{ap}->{$_}->{memory} = $result->{fgWcWtpSessionWtpMemoryUsage}; |
| 206 |
} |
| 207 |
|
| 208 |
$self->{cache_name} = 'fortigate_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 209 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 210 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 211 |
} |
| 212 |
|
| 213 |
1; |
| 214 |
|
| 215 |
__END__ |
| 216 |
|
| 217 |
=head1 MODE |
| 218 |
|
| 219 |
Check access point usage. |
| 220 |
|
| 221 |
=over 8 |
| 222 |
|
| 223 |
=item B<--warning-*> |
| 224 |
|
| 225 |
Warning threshold. |
| 226 |
Can be: 'in-traffic', 'out-traffic', 'cpu' (%), 'memory' (%), |
| 227 |
'clients'. |
| 228 |
|
| 229 |
=item B<--critical-*> |
| 230 |
|
| 231 |
Critical threshold. |
| 232 |
Can be: 'in-traffic', 'out-traffic', 'cpu' (%), 'memory' (%), |
| 233 |
'clients'. |
| 234 |
|
| 235 |
=item B<--filter-name> |
| 236 |
|
| 237 |
Filter by access point name (can be a regexp). |
| 238 |
|
| 239 |
=item B<--unknown-status> |
| 240 |
|
| 241 |
Define the conditions to match for the status to be UNKNOWN (default: ''). |
| 242 |
You can use the following variables: %{admin}, %{status}, %{display} |
| 243 |
|
| 244 |
=item B<--warning-status> |
| 245 |
|
| 246 |
Define the conditions to match for the status to be WARNING (default: ''). |
| 247 |
You can use the following variables: %{admin}, %{status}, %{display} |
| 248 |
|
| 249 |
=item B<--critical-status> |
| 250 |
|
| 251 |
Define the conditions to match for the status to be CRITICAL (default: '%{admin} eq "enable" and %{status} !~ /online/i''). |
| 252 |
You can use the following variables: %{admin}, %{status}, %{display} |
| 253 |
|
| 254 |
=back |
| 255 |
|
| 256 |
=cut |