| 1 |
# |
| 2 |
# Copyright 2015 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::juniper::trapeze::snmp::mode::apusers; |
| 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 }, |
| 33 |
{ name => 'ssid', type => 1, cb_prefix_output => 'prefix_ssid_output', message_multiple => 'All users by SSID are ok' }, |
| 34 |
{ name => 'ap', type => 1, cb_prefix_output => 'prefix_ap_output', message_multiple => 'All users by AP are ok' }, |
| 35 |
]; |
| 36 |
|
| 37 |
$self->{maps_counters}->{global} = [ |
| 38 |
{ label => 'total', set => { |
| 39 |
key_values => [ { name => 'total' } ], |
| 40 |
output_template => 'Total Users : %s', |
| 41 |
perfdatas => [ |
| 42 |
{ label => 'total', value => 'total', template => '%s', |
| 43 |
unit => 'users', min => 0 }, |
| 44 |
], |
| 45 |
} |
| 46 |
}, |
| 47 |
]; |
| 48 |
|
| 49 |
$self->{maps_counters}->{ssid} = [ |
| 50 |
{ label => 'ssid', set => { |
| 51 |
key_values => [ { name => 'total' }, { name => 'display' } ], |
| 52 |
output_template => 'users : %s', |
| 53 |
perfdatas => [ |
| 54 |
{ label => 'ssid', value => 'total', template => '%s', |
| 55 |
unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 56 |
], |
| 57 |
} |
| 58 |
}, |
| 59 |
]; |
| 60 |
|
| 61 |
$self->{maps_counters}->{ap} = [ |
| 62 |
{ label => 'ap', set => { |
| 63 |
key_values => [ { name => 'total' }, { name => 'display' } ], |
| 64 |
output_template => 'users : %s', |
| 65 |
perfdatas => [ |
| 66 |
{ label => 'ap', value => 'total', template => '%s', |
| 67 |
unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 68 |
], |
| 69 |
} |
| 70 |
}, |
| 71 |
]; |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
sub new { |
| 76 |
my ($class, %options) = @_; |
| 77 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 78 |
bless $self, $class; |
| 79 |
|
| 80 |
$options{options}->add_options(arguments => |
| 81 |
{ |
| 82 |
"filter-ssid:s" => { name => 'filter_ssid' }, |
| 83 |
"filter-ap:s" => { name => 'filter_ap' }, |
| 84 |
}); |
| 85 |
|
| 86 |
return $self; |
| 87 |
} |
| 88 |
|
| 89 |
sub prefix_ssid_output { |
| 90 |
my ($self, %options) = @_; |
| 91 |
|
| 92 |
return "SSID '" . $options{instance_value}->{display} . "' "; |
| 93 |
} |
| 94 |
|
| 95 |
sub prefix_ap_output { |
| 96 |
my ($self, %options) = @_; |
| 97 |
|
| 98 |
return "AP '" . $options{instance_value}->{display} . "' "; |
| 99 |
} |
| 100 |
|
| 101 |
my $mapping = { |
| 102 |
trpzClSessClientSessApSerialNum => { oid => '.1.3.6.1.4.1.14525.4.4.1.1.1.1.7' }, |
| 103 |
}; |
| 104 |
|
| 105 |
my $mapping1 = { |
| 106 |
trpzClSessClientSessSsid => { oid => '.1.3.6.1.4.1.14525.4.4.1.1.1.1.15' }, |
| 107 |
}; |
| 108 |
|
| 109 |
sub manage_selection { |
| 110 |
my ($self, %options) = @_; |
| 111 |
|
| 112 |
my $oid_trpzApStatApStatusApName = '.1.3.6.1.4.1.14525.4.5.1.1.2.1.8'; |
| 113 |
$self->{global} = { total => 0}; |
| 114 |
$self->{ssid} = {}; |
| 115 |
$self->{ap} = {}; |
| 116 |
|
| 117 |
$self->{results} = $options{snmp}->get_multiple_table(oids => [{ oid => $oid_trpzApStatApStatusApName }, { oid => $mapping->{trpzClSessClientSessApSerialNum}->{oid} }, |
| 118 |
{ oid => $mapping1->{trpzClSessClientSessSsid}->{oid} }], |
| 119 |
nothing_quit => 1); |
| 120 |
|
| 121 |
foreach my $oid (keys %{$self->{results}->{ $mapping->{trpzClSessClientSessApSerialNum}->{oid} }}) { |
| 122 |
$oid =~ /^$mapping->{trpzClSessClientSessApSerialNum}->{oid}\.(.*)$/; |
| 123 |
my $instance = $1; |
| 124 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{ $mapping->{trpzClSessClientSessApSerialNum}->{oid} }, instance => $instance); |
| 125 |
my $result1 = $options{snmp}->map_instance(mapping => $mapping1, results => $self->{results}->{ $mapping1->{trpzClSessClientSessSsid}->{oid} }, instance => $instance); |
| 126 |
my @chars = split(//,$result->{trpzClSessClientSessApSerialNum}); |
| 127 |
my $ap_oid = '12'; |
| 128 |
foreach my $char (@chars) { |
| 129 |
$ap_oid .= '.'.ord($char); |
| 130 |
} |
| 131 |
my $ap_name = $self->{results}->{$oid_trpzApStatApStatusApName}->{$oid_trpzApStatApStatusApName . '.' . $ap_oid}; |
| 132 |
if (defined($self->{option_results}->{filter_ap}) && $self->{option_results}->{filter_ap} ne '' && |
| 133 |
$ap_name !~ /$self->{option_results}->{filter_ap}/) { |
| 134 |
$self->{output}->output_add(long_msg => "Skipping '" . $ap_name . "': no matching filter.", debug => 1); |
| 135 |
next; |
| 136 |
} |
| 137 |
if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && |
| 138 |
$result1->{trpzClSessClientSessSsid} !~ /$self->{option_results}->{filter_ssid}/) { |
| 139 |
$self->{output}->output_add(long_msg => "Skipping '" . $result1->{trpzClSessClientSessSsid} . "': no matching filter.", debug => 1); |
| 140 |
next; |
| 141 |
} |
| 142 |
|
| 143 |
$self->{global}->{total}++; |
| 144 |
$self->{ap}->{$ap_name} = { total => 0, display => $ap_name } if (!defined($self->{ap}->{$ap_name})); |
| 145 |
$self->{ap}->{$ap_name}->{total}++; |
| 146 |
$self->{ssid}->{$result1->{trpzClSessClientSessSsid}} = { total => 0, display => $result1->{trpzClSessClientSessSsid} } if (!defined($self->{ssid}->{$result1->{trpzClSessClientSessSsid}})); |
| 147 |
$self->{ssid}->{$result1->{trpzClSessClientSessSsid}}->{total}++; |
| 148 |
} |
| 149 |
|
| 150 |
if (scalar(keys %{$self->{ap}}) <= 0 && scalar(keys %{$self->{ssid}}) <= 0) { |
| 151 |
$self->{output}->output_add(severity => 'OK', |
| 152 |
short_msg => 'No AP nor SSID found, check your filter or maybe we are on a slave controller ? '); |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
1; |
| 157 |
|
| 158 |
__END__ |
| 159 |
|
| 160 |
=head1 MODE |
| 161 |
|
| 162 |
Check AP users. |
| 163 |
|
| 164 |
=over 8 |
| 165 |
|
| 166 |
=item B<--filter-counters> |
| 167 |
|
| 168 |
Only display some counters (regexp can be used). |
| 169 |
|
| 170 |
=item B<--filter-ap> |
| 171 |
|
| 172 |
Filter AP name (can be a regexp). |
| 173 |
|
| 174 |
=item B<--filter-ssid> |
| 175 |
|
| 176 |
Filter SSID name (can be a regexp). |
| 177 |
|
| 178 |
=item B<--warning-*> |
| 179 |
|
| 180 |
Set warning threshold for number of user. Can be : 'total', 'ssid', 'ap' . |
| 181 |
|
| 182 |
=item B<--critical-*> |
| 183 |
|
| 184 |
Set critical threshold for number of user. Can be : 'total', 'ssid', 'ap' . |
| 185 |
|
| 186 |
=back |
| 187 |
|
| 188 |
=cut |