| 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::airespace::snmp::mode::radiusaccservers; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use Digest::MD5 qw(md5_hex); |
| 28 |
|
| 29 |
sub prefix_servers_output { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
return "Radius accounting server '" . $options{instance_value}->{name} . "' "; |
| 33 |
} |
| 34 |
|
| 35 |
sub set_counters { |
| 36 |
my ($self, %options) = @_; |
| 37 |
|
| 38 |
$self->{maps_counters_type} = [ |
| 39 |
{ name => 'global', type => 0 }, |
| 40 |
{ name => 'servers', type => 1, cb_prefix_output => 'prefix_servers_output', message_multiple => 'All radius accounting servers are ok' } |
| 41 |
]; |
| 42 |
|
| 43 |
$self->{maps_counters}->{global} = [ |
| 44 |
{ label => 'accservers-total', nlabel => 'radius.accservers.total.count', display_ok => 0, set => { |
| 45 |
key_values => [ { name => 'total' } ], |
| 46 |
output_template => 'total accounting servers: %s', |
| 47 |
perfdatas => [ |
| 48 |
{ ltemplate => '%s', min => 0 } |
| 49 |
] |
| 50 |
} |
| 51 |
} |
| 52 |
]; |
| 53 |
|
| 54 |
$self->{maps_counters}->{servers} = [ |
| 55 |
{ label => 'accservers-roundtrip-time', nlabel => 'radius.accservers.roundtrip.time.milliseconds', set => { |
| 56 |
key_values => [ { name => 'round_trip_time' }, { name => 'name' } ], |
| 57 |
output_template => 'round trip time: %s ms', |
| 58 |
perfdatas => [ |
| 59 |
{ template => '%s', min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'name' } |
| 60 |
] |
| 61 |
} |
| 62 |
}, |
| 63 |
{ label => 'accservers-packets-sent', nlabel => 'radius.accservers.packets.sent.persecond', set => { |
| 64 |
key_values => [ { name => 'requests', per_second => 1 }, { name => 'name' } ], |
| 65 |
output_template => 'packets sent: %.2f/s', |
| 66 |
perfdatas => [ |
| 67 |
{ template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'name' } |
| 68 |
] |
| 69 |
} |
| 70 |
}, |
| 71 |
{ label => 'accservers-packets-received', nlabel => 'radius.accservers.packets.received.persecond', set => { |
| 72 |
key_values => [ { name => 'responses', per_second => 1 }, { name => 'name' } ], |
| 73 |
output_template => 'packets received: %.2f/s', |
| 74 |
perfdatas => [ |
| 75 |
{ template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1, instance_use => 'name' } |
| 76 |
] |
| 77 |
} |
| 78 |
}, |
| 79 |
{ label => 'accservers-clients-timeout', nlabel => 'radius.accservers.clients.timeout.count', set => { |
| 80 |
key_values => [ { name => 'timeouts', diff => '1' }, { name => 'name' } ], |
| 81 |
output_template => 'clients timeout: %s', |
| 82 |
perfdatas => [ |
| 83 |
{ template => '%s', min => 0, label_extra_instance => 1, instance_use => 'name' } |
| 84 |
] |
| 85 |
} |
| 86 |
} |
| 87 |
]; |
| 88 |
} |
| 89 |
|
| 90 |
sub new { |
| 91 |
my ($class, %options) = @_; |
| 92 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1, statefile => 1); |
| 93 |
bless $self, $class; |
| 94 |
|
| 95 |
$options{options}->add_options(arguments => { |
| 96 |
'filter-name:s' => { name => 'filter_name' } |
| 97 |
}); |
| 98 |
|
| 99 |
return $self; |
| 100 |
} |
| 101 |
|
| 102 |
my $map_server_status = { |
| 103 |
0 => 'disable', 1 => 'enable' |
| 104 |
}; |
| 105 |
my $mapping = { |
| 106 |
address => { oid => '.1.3.6.1.4.1.14179.2.5.2.1.2' }, # bsnRadiusAccServerAddress |
| 107 |
port => { oid => '.1.3.6.1.4.1.14179.2.5.2.1.3' }, # bsnRadiusAccClientServerPortNumber |
| 108 |
status => { oid => '.1.3.6.1.4.1.14179.2.5.2.1.5', map => $map_server_status } # bsnRadiusAccServerStatus |
| 109 |
}; |
| 110 |
my $mapping2 = { |
| 111 |
round_trip_time => { oid => '.1.3.6.1.4.1.14179.2.5.4.1.6' }, # bsnRadiusAccClientRoundTripTime |
| 112 |
requests => { oid => '.1.3.6.1.4.1.14179.2.5.4.1.7' }, # bsnRadiusAccClientRequests |
| 113 |
responses => { oid => '.1.3.6.1.4.1.14179.2.5.4.1.9' }, # bsnRadiusAccClientResponses |
| 114 |
timeouts => { oid => '.1.3.6.1.4.1.14179.2.5.4.1.13' } # bsnRadiusAccClientTimeouts |
| 115 |
}; |
| 116 |
my $oid_bsnRadiusAccServerEntry = '.1.3.6.1.4.1.14179.2.5.2.1'; |
| 117 |
|
| 118 |
sub manage_selection { |
| 119 |
my ($self, %options) = @_; |
| 120 |
|
| 121 |
my $snmp_result = $options{snmp}->get_table( |
| 122 |
oid => $oid_bsnRadiusAccServerEntry, |
| 123 |
start => $mapping->{address}->{oid}, |
| 124 |
end => $mapping->{status}->{oid}, |
| 125 |
nothing_quit => 1 |
| 126 |
); |
| 127 |
|
| 128 |
$self->{global} = { total => 0 }; |
| 129 |
$self->{servers} = {}; |
| 130 |
foreach my $oid (keys %$snmp_result) { |
| 131 |
next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)$/); |
| 132 |
my $instance = $1; |
| 133 |
|
| 134 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); |
| 135 |
my $name = $result->{address} . ':' . $result->{port}; |
| 136 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 137 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 138 |
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); |
| 139 |
next; |
| 140 |
} |
| 141 |
if ($result->{status} eq 'disable') { |
| 142 |
$self->{output}->output_add(long_msg => "skipping '" . $name . "': disabled.", debug => 1); |
| 143 |
next; |
| 144 |
} |
| 145 |
|
| 146 |
$self->{servers}->{$instance} = { name => $name }; |
| 147 |
$self->{global}->{total}++; |
| 148 |
} |
| 149 |
|
| 150 |
return if (scalar(keys %{$self->{servers}}) <= 0); |
| 151 |
|
| 152 |
$options{snmp}->load( |
| 153 |
oids => [ map($_->{oid}, values(%$mapping2)) ], |
| 154 |
instances => [keys %{$self->{servers}}], |
| 155 |
instance_regexp => '^(.*)$' |
| 156 |
); |
| 157 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 158 |
|
| 159 |
foreach (keys %{$self->{servers}}) { |
| 160 |
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); |
| 161 |
|
| 162 |
$self->{servers}->{$_} = { %{$self->{servers}->{$_}}, %$result }; |
| 163 |
} |
| 164 |
|
| 165 |
$self->{cache_name} = 'cisco_wlc_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 166 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 167 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
1; |
| 172 |
|
| 173 |
__END__ |
| 174 |
|
| 175 |
=head1 MODE |
| 176 |
|
| 177 |
Check radius accounting servers. |
| 178 |
|
| 179 |
=over 8 |
| 180 |
|
| 181 |
=item B<--filter-counters> |
| 182 |
|
| 183 |
Only display some counters (regexp can be used). |
| 184 |
Example: --filter-counters='^total$' |
| 185 |
|
| 186 |
=item B<--filter-name> |
| 187 |
|
| 188 |
Filter radius servers by name (can be a regexp). |
| 189 |
|
| 190 |
=item B<--warning-*> B<--critical-*> |
| 191 |
|
| 192 |
Thresholds. |
| 193 |
Can be: 'accservers-total', 'accservers-roundtrip-time', |
| 194 |
'accservers-packets-sent', 'accservers-packets-received', |
| 195 |
'accservers-clients-timeout'. |
| 196 |
|
| 197 |
=back |
| 198 |
|
| 199 |
=cut |