| 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::ruckus::ap::snmp::mode::users; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_global_perfdata { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
if ($self->{result_values}->{limit} > 0) { |
| 32 |
$self->{output}->perfdata_add(label => 'total', unit => 'users', |
| 33 |
value => $self->{result_values}->{total}, |
| 34 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{limit}, cast_int => 1), |
| 35 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{limit}, cast_int => 1), |
| 36 |
min => 0, max => $self->{result_values}->{limit}); |
| 37 |
} else { |
| 38 |
$self->{output}->perfdata_add(label => 'total', unit => 'users', |
| 39 |
value => $self->{result_values}->{total}, |
| 40 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}), |
| 41 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}), |
| 42 |
min => 0); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
sub custom_global_threshold { |
| 47 |
my ($self, %options) = @_; |
| 48 |
|
| 49 |
my $exit; |
| 50 |
if ($self->{result_values}->{limit} > 0) { |
| 51 |
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); |
| 52 |
} else { |
| 53 |
$exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{total}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); |
| 54 |
} |
| 55 |
return $exit; |
| 56 |
} |
| 57 |
|
| 58 |
sub custom_global_output { |
| 59 |
my ($self, %options) = @_; |
| 60 |
|
| 61 |
my $msg = 'Total Users : ' . $self->{result_values}->{total}; |
| 62 |
if ($self->{result_values}->{limit} > 0) { |
| 63 |
$msg .= " (" . sprintf("%.2f", $self->{result_values}->{prct_used}) . '% used on ' . $self->{result_values}->{limit} . ")"; |
| 64 |
} |
| 65 |
|
| 66 |
return $msg; |
| 67 |
} |
| 68 |
|
| 69 |
sub custom_global_calc { |
| 70 |
my ($self, %options) = @_; |
| 71 |
|
| 72 |
$self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; |
| 73 |
$self->{result_values}->{limit} = $options{new_datas}->{$self->{instance} . '_limit'}; |
| 74 |
if ($self->{result_values}->{limit} > 0) { |
| 75 |
$self->{result_values}->{prct_used} = $self->{result_values}->{total} * 100 / $self->{result_values}->{limit}; |
| 76 |
} |
| 77 |
return 0; |
| 78 |
} |
| 79 |
|
| 80 |
sub set_counters { |
| 81 |
my ($self, %options) = @_; |
| 82 |
|
| 83 |
$self->{maps_counters_type} = [ |
| 84 |
{ name => 'global', type => 0 }, |
| 85 |
{ name => 'ssid', type => 1, cb_prefix_output => 'prefix_ssid_output', message_multiple => 'All users by SSID are ok', cb_init => 'skip_ssid', }, |
| 86 |
]; |
| 87 |
$self->{maps_counters}->{global} = [ |
| 88 |
{ label => 'total', set => { |
| 89 |
key_values => [ { name => 'total' }, { name => 'limit' } ], |
| 90 |
closure_custom_calc => $self->can('custom_global_calc'), |
| 91 |
closure_custom_output => $self->can('custom_global_output'), |
| 92 |
closure_custom_perfdata => $self->can('custom_global_perfdata'), |
| 93 |
closure_custom_threshold_check => $self->can('custom_global_threshold'), |
| 94 |
} |
| 95 |
}, |
| 96 |
]; |
| 97 |
|
| 98 |
$self->{maps_counters}->{ssid} = [ |
| 99 |
{ label => 'ssid', set => { |
| 100 |
key_values => [ { name => 'total' }, { name => 'display' } ], |
| 101 |
output_template => 'users : %s', |
| 102 |
perfdatas => [ |
| 103 |
{ label => 'ssid', value => 'total', template => '%s', |
| 104 |
unit => 'users', min => 0, label_extra_instance => 1, instance_use => 'display' }, |
| 105 |
], |
| 106 |
} |
| 107 |
}, |
| 108 |
]; |
| 109 |
} |
| 110 |
|
| 111 |
sub prefix_ssid_output { |
| 112 |
my ($self, %options) = @_; |
| 113 |
|
| 114 |
return "SSID '" . $options{instance_value}->{display} . "' "; |
| 115 |
} |
| 116 |
|
| 117 |
sub skip_ssid { |
| 118 |
my ($self, %options) = @_; |
| 119 |
|
| 120 |
scalar(keys %{$self->{ssid}}) > 1 ? return(0) : return(1); |
| 121 |
} |
| 122 |
|
| 123 |
sub new { |
| 124 |
my ($class, %options) = @_; |
| 125 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options); |
| 126 |
bless $self, $class; |
| 127 |
|
| 128 |
$options{options}->add_options(arguments => { |
| 129 |
'filter-ssid:s' => { name => 'filter_ssid' }, |
| 130 |
}); |
| 131 |
|
| 132 |
return $self; |
| 133 |
} |
| 134 |
|
| 135 |
my $oid_ruckusUnleashedSystemMaxSta = '.1.3.6.1.4.1.25053.1.15.1.1.1.1.13.0'; |
| 136 |
my $oid_ruckusUnleashedSystemStatsNumSta = '.1.3.6.1.4.1.25053.1.15.1.1.1.15.2.0'; |
| 137 |
my $mapping = { |
| 138 |
ruckusWLANStatsSSID => { oid => '.1.3.6.1.4.1.25053.1.1.6.1.1.1.4.1.1' }, |
| 139 |
ruckusWLANStatsNumSta => { oid => '.1.3.6.1.4.1.25053.1.1.6.1.1.1.4.1.3' }, |
| 140 |
}; |
| 141 |
|
| 142 |
sub manage_selection { |
| 143 |
my ($self, %options) = @_; |
| 144 |
|
| 145 |
$self->{global} = { total => -1, limit => -1 }; |
| 146 |
my $snmp_result = $options{snmp}->get_leef(oids => [$oid_ruckusUnleashedSystemMaxSta, $oid_ruckusUnleashedSystemStatsNumSta]); |
| 147 |
$self->{global}->{limit} = $snmp_result->{$oid_ruckusUnleashedSystemMaxSta} if (defined($snmp_result->{$oid_ruckusUnleashedSystemMaxSta})); |
| 148 |
$self->{global}->{total} = $snmp_result->{$oid_ruckusUnleashedSystemStatsNumSta} if (defined($snmp_result->{$oid_ruckusUnleashedSystemStatsNumSta})); |
| 149 |
|
| 150 |
return if ($self->{global}->{total} != -1); |
| 151 |
|
| 152 |
$snmp_result = $options{snmp}->get_multiple_table(oids => [ |
| 153 |
{ oid => $mapping->{ruckusWLANStatsSSID}->{oid} }, |
| 154 |
{ oid => $mapping->{ruckusWLANStatsNumSta}->{oid} } ], return_type => 1, nothing_quit => 1); |
| 155 |
|
| 156 |
$self->{ssid} = {}; |
| 157 |
foreach my $oid (keys %{$snmp_result}) { |
| 158 |
next if ($oid !~ /^$mapping->{ruckusWLANStatsNumSta}->{oid}\.(\d+)/); |
| 159 |
$self->{global}->{total} = 0 if ($self->{global}->{total} == -1); |
| 160 |
my $instance = $1; |
| 161 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 162 |
|
| 163 |
if (defined($self->{option_results}->{filter_ssid}) && $self->{option_results}->{filter_ssid} ne '' && |
| 164 |
$result->{ruckusWLANStatsSSID} !~ /$self->{option_results}->{filter_ssid}/) { |
| 165 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{ruckusWLANStatsSSID} . "': no matching filter.", debug => 1); |
| 166 |
next; |
| 167 |
} |
| 168 |
|
| 169 |
$self->{ssid}->{$result->{ruckusWLANStatsSSID}} = { display => $result->{ruckusWLANStatsSSID}, total => $result->{ruckusWLANStatsNumSta} }; |
| 170 |
$self->{global}->{total} += $result->{ruckusWLANStatsNumSta}; |
| 171 |
} |
| 172 |
|
| 173 |
if ($self->{global}->{total} == -1) { |
| 174 |
$self->{output}->add_option_msg(short_msg => "Cannot find informations"); |
| 175 |
$self->{output}->option_exit(); |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
1; |
| 180 |
|
| 181 |
__END__ |
| 182 |
|
| 183 |
=head1 MODE |
| 184 |
|
| 185 |
Check users connected. |
| 186 |
|
| 187 |
=over 8 |
| 188 |
|
| 189 |
=item B<--filter-counters> |
| 190 |
|
| 191 |
Only display some counters (regexp can be used). |
| 192 |
Example: --filter-counters='^total$' |
| 193 |
|
| 194 |
=item B<--warning-*> |
| 195 |
|
| 196 |
Warning threshold. |
| 197 |
Can be: 'total', 'ssid'. |
| 198 |
|
| 199 |
=item B<--critical-*> |
| 200 |
|
| 201 |
Critical threshold. |
| 202 |
Can be: 'total', 'ssid'. |
| 203 |
|
| 204 |
=item B<--filter-ssid> |
| 205 |
|
| 206 |
Filter by SSID (can be a regexp). |
| 207 |
|
| 208 |
=back |
| 209 |
|
| 210 |
=cut |