| 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::cisco::wap::snmp::mode::clients; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_radio_output { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return sprintf( |
| 32 |
"Radio interface '%s' ", |
| 33 |
$options{instance_value}->{name} |
| 34 |
); |
| 35 |
} |
| 36 |
|
| 37 |
sub set_counters { |
| 38 |
my ($self, %options) = @_; |
| 39 |
|
| 40 |
$self->{maps_counters_type} = [ |
| 41 |
{ name => 'global', type => 0 }, |
| 42 |
{ name => 'radios', type => 1, cb_prefix_output => 'prefix_radio_output' } |
| 43 |
]; |
| 44 |
|
| 45 |
$self->{maps_counters}->{global} = [ |
| 46 |
{ label => 'clients-connected', nlabel => 'clients.connected.count', set => { |
| 47 |
key_values => [ { name => 'clients_connected' } ], |
| 48 |
output_template => 'clients connected: %s', |
| 49 |
perfdatas => [ |
| 50 |
{ template => '%s', min => 0 } |
| 51 |
] |
| 52 |
} |
| 53 |
} |
| 54 |
]; |
| 55 |
|
| 56 |
$self->{maps_counters}->{radios} = [ |
| 57 |
{ label => 'radio-clients-connected', nlabel => 'radio.clients.connected.count', set => { |
| 58 |
key_values => [ { name => 'clients_connected' } ], |
| 59 |
output_template => 'clients connected: %s', |
| 60 |
perfdatas => [ |
| 61 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 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 |
'filter-radio-name:s' => { name => 'filter_radio_name' } |
| 75 |
}); |
| 76 |
|
| 77 |
return $self; |
| 78 |
} |
| 79 |
|
| 80 |
my $map_status = { 0 => 'down', 1 => 'up' }; |
| 81 |
|
| 82 |
my $mapping_radio = { |
| 83 |
admin_status => { oid => '.1.3.6.1.4.1.9.6.1.104.1.6.1.1.2', map => $map_status }, # apRadioStatus |
| 84 |
name => { oid => '.1.3.6.1.4.1.9.6.1.104.1.6.1.1.3' } # apRadioName |
| 85 |
}; |
| 86 |
|
| 87 |
sub manage_selection { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
my $oid_radio_table = '.1.3.6.1.4.1.9.6.1.104.1.6.1'; # apRadioTable |
| 91 |
my $oid_assoc_interface = '.1.3.6.1.4.1.9.6.1.104.1.7.1.1.2'; # apAssocInterface |
| 92 |
my $snmp_result = $options{snmp}->get_multiple_table( |
| 93 |
oids => [ |
| 94 |
{ oid => $oid_radio_table, start => $mapping_radio->{admin_status}->{oid}, end => $mapping_radio->{name}->{oid} }, |
| 95 |
{ oid => $oid_assoc_interface } |
| 96 |
], |
| 97 |
nothing_quit => 1 |
| 98 |
); |
| 99 |
|
| 100 |
$self->{global} = { clients_connected => 0 }; |
| 101 |
$self->{radios} = {}; |
| 102 |
foreach (keys %{$snmp_result->{$oid_radio_table}}) { |
| 103 |
next if (! /^$mapping_radio->{name}->{oid}\.(.*)$/); |
| 104 |
|
| 105 |
my $result = $options{snmp}->map_instance(mapping => $mapping_radio, results => $snmp_result->{$oid_radio_table}, instance => $1); |
| 106 |
next if ($result->{admin_status} eq 'down'); |
| 107 |
if (defined($self->{option_results}->{filter_radio_name}) && $self->{option_results}->{filter_radio_name} ne '' && |
| 108 |
$result->{name} !~ /$self->{option_results}->{filter_radio_name}/) { |
| 109 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{name} . "': no matching filter.", debug => 1); |
| 110 |
next; |
| 111 |
} |
| 112 |
|
| 113 |
$self->{radios}->{ $result->{name} } = { |
| 114 |
name => $result->{name}, |
| 115 |
clients_connected => 0 |
| 116 |
}; |
| 117 |
} |
| 118 |
|
| 119 |
foreach (keys %{$snmp_result->{$oid_assoc_interface}}) { |
| 120 |
next if (!defined($self->{radios}->{ $snmp_result->{$oid_assoc_interface}->{$_} })); |
| 121 |
$self->{radios}->{ $snmp_result->{$oid_assoc_interface}->{$_} }->{clients_connected}++; |
| 122 |
$self->{global}->{clients_connected}++; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
1; |
| 127 |
|
| 128 |
__END__ |
| 129 |
|
| 130 |
=head1 MODE |
| 131 |
|
| 132 |
Check clients connected. |
| 133 |
|
| 134 |
=over 8 |
| 135 |
|
| 136 |
=item B<--filter-counters> |
| 137 |
|
| 138 |
Only display some counters (regexp can be used). |
| 139 |
Example: --filter-counters='^clients' |
| 140 |
|
| 141 |
=item B<--filter-radio-name> |
| 142 |
|
| 143 |
Filter radio interfaces by name (can be a regexp). |
| 144 |
|
| 145 |
=item B<--warning-*> B<--critical-*> |
| 146 |
|
| 147 |
Thresholds. |
| 148 |
Can be: 'clients-connected', 'radio-clients-connected'. |
| 149 |
|
| 150 |
=back |
| 151 |
|
| 152 |
=cut |