| 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::cisco::standard::snmp::mode::aaaservers; |
| 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_ng); |
| 28 |
use Digest::MD5 qw(md5_hex); |
| 29 |
|
| 30 |
sub custom_status_output { |
| 31 |
my ($self, %options) = @_; |
| 32 |
|
| 33 |
return sprintf( |
| 34 |
'status: %s', |
| 35 |
$self->{result_values}->{status} |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
sub prefix_aaa_output { |
| 40 |
my ($self, %options) = @_; |
| 41 |
|
| 42 |
return sprintf( |
| 43 |
"Server '%s' [protocol: %s] ", |
| 44 |
$options{instance_value}->{name}, |
| 45 |
$options{instance_value}->{protocol} |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
sub aaa_long_output { |
| 50 |
my ($self, %options) = @_; |
| 51 |
|
| 52 |
return sprintf( |
| 53 |
"checking server '%s' [protocol: %s]", |
| 54 |
$options{instance_value}->{name}, |
| 55 |
$options{instance_value}->{protocol} |
| 56 |
); |
| 57 |
} |
| 58 |
|
| 59 |
sub prefix_auth_output { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
return 'authentication '; |
| 63 |
} |
| 64 |
|
| 65 |
sub prefix_acc_output { |
| 66 |
my ($self, %options) = @_; |
| 67 |
|
| 68 |
return 'accounting '; |
| 69 |
} |
| 70 |
|
| 71 |
sub set_counters { |
| 72 |
my ($self, %options) = @_; |
| 73 |
|
| 74 |
$self->{maps_counters_type} = [ |
| 75 |
{ name => 'global', type => 0 }, |
| 76 |
{ name => 'aaa', type => 3, cb_prefix_output => 'prefix_aaa_output', cb_long_output => 'aaa_long_output', indent_long_output => ' ', message_multiple => 'All AAA servers are ok', |
| 77 |
group => [ |
| 78 |
{ name => 'global_status', type => 0, skipped_code => { -10 => 1 } }, |
| 79 |
{ name => 'global_auth', type => 0, cb_prefix_output => 'prefix_auth_output', skipped_code => { -10 => 1 } }, |
| 80 |
{ name => 'global_acc', type => 0, cb_prefix_output => 'prefix_acc_output', skipped_code => { -10 => 1 } } |
| 81 |
] |
| 82 |
} |
| 83 |
]; |
| 84 |
|
| 85 |
$self->{maps_counters}->{global} = [ |
| 86 |
{ label => 'total', nlabel => 'aaa_servers.total.count', display_ok => 0, set => { |
| 87 |
key_values => [ { name => 'total' } ], |
| 88 |
output_template => 'total servers: %s', |
| 89 |
perfdatas => [ |
| 90 |
{ template => '%s', min => 0 } |
| 91 |
] |
| 92 |
} |
| 93 |
} |
| 94 |
]; |
| 95 |
|
| 96 |
$self->{maps_counters}->{global_status} = [ |
| 97 |
{ |
| 98 |
label => 'status', type => 2, critical_default => '%{status} =~ /dead/i', |
| 99 |
set => { |
| 100 |
key_values => [ { name => 'status' }, { name => 'name' } ], |
| 101 |
closure_custom_output => $self->can('custom_status_output'), |
| 102 |
closure_custom_perfdata => sub { return 0; }, |
| 103 |
closure_custom_threshold_check => \&catalog_status_threshold_ng |
| 104 |
} |
| 105 |
} |
| 106 |
]; |
| 107 |
|
| 108 |
$self->{maps_counters}->{global_auth} = [ |
| 109 |
{ label => 'auth-requests', nlabel => 'aaa_server.authentication.requests.persecond', set => { |
| 110 |
key_values => [ { name => 'auth_requests', per_second => 1 } ], |
| 111 |
output_template => 'requests: %.2f/s', |
| 112 |
perfdatas => [ |
| 113 |
{ template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } |
| 114 |
] |
| 115 |
} |
| 116 |
}, |
| 117 |
{ label => 'auth-requests-timeout', nlabel => 'aaa_server.authentication.requests.timeout.count', set => { |
| 118 |
key_values => [ { name => 'auth_timeouts', diff => 1 } ], |
| 119 |
output_template => 'requests timeout: %s', |
| 120 |
perfdatas => [ |
| 121 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 122 |
] |
| 123 |
} |
| 124 |
}, |
| 125 |
{ label => 'auth-transactions-suceeded', nlabel => 'aaa_server.authentication.transactions.succeeded.persecond', set => { |
| 126 |
key_values => [ { name => 'auth_trans_success', per_second => 1 } ], |
| 127 |
output_template => 'transactions succeeded: %.2f/s', |
| 128 |
perfdatas => [ |
| 129 |
{ template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } |
| 130 |
] |
| 131 |
} |
| 132 |
}, |
| 133 |
{ label => 'auth-roundtrip-time', nlabel => 'aaa_server.authentication.roundtrip.time.milliseconds', set => { |
| 134 |
key_values => [ { name => 'auth_reponse_time' } ], |
| 135 |
output_template => 'round trip time: %s ms', |
| 136 |
perfdatas => [ |
| 137 |
{ template => '%s', min => 0, unit => 'ms', label_extra_instance => 1 } |
| 138 |
] |
| 139 |
} |
| 140 |
} |
| 141 |
]; |
| 142 |
|
| 143 |
$self->{maps_counters}->{global_acc} = [ |
| 144 |
{ label => 'acc-requests', nlabel => 'aaa_server.accounting.requests.persecond', set => { |
| 145 |
key_values => [ { name => 'acc_requests', per_second => 1 } ], |
| 146 |
output_template => 'requests: %.2f/s', |
| 147 |
perfdatas => [ |
| 148 |
{ template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } |
| 149 |
] |
| 150 |
} |
| 151 |
}, |
| 152 |
{ label => 'acc-requests-timeout', nlabel => 'aaa_server.accounting.requests.timeout.count', set => { |
| 153 |
key_values => [ { name => 'acc_timeouts', diff => 1 } ], |
| 154 |
output_template => 'requests timeout: %s', |
| 155 |
perfdatas => [ |
| 156 |
{ template => '%s', min => 0, label_extra_instance => 1 } |
| 157 |
] |
| 158 |
} |
| 159 |
}, |
| 160 |
{ label => 'acc-transactions-suceeded', nlabel => 'aaa_server.accounting.transactions.succeeded.persecond', set => { |
| 161 |
key_values => [ { name => 'acc_trans_success', per_second => 1 } ], |
| 162 |
output_template => 'transactions succeeded: %.2f/s', |
| 163 |
perfdatas => [ |
| 164 |
{ template => '%.2f', min => 0, unit => '/s', label_extra_instance => 1 } |
| 165 |
] |
| 166 |
} |
| 167 |
}, |
| 168 |
{ label => 'acc-roundtrip-time', nlabel => 'aaa_server.accounting.roundtrip.time.milliseconds', set => { |
| 169 |
key_values => [ { name => 'acc_reponse_time' } ], |
| 170 |
output_template => 'round trip time: %s ms', |
| 171 |
perfdatas => [ |
| 172 |
{ template => '%s', min => 0, unit => 'ms', label_extra_instance => 1 } |
| 173 |
] |
| 174 |
} |
| 175 |
} |
| 176 |
]; |
| 177 |
} |
| 178 |
|
| 179 |
sub new { |
| 180 |
my ($class, %options) = @_; |
| 181 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1); |
| 182 |
bless $self, $class; |
| 183 |
|
| 184 |
$options{options}->add_options(arguments => { |
| 185 |
'filter-name:s' => { name => 'filter_name' } |
| 186 |
}); |
| 187 |
|
| 188 |
return $self; |
| 189 |
} |
| 190 |
|
| 191 |
my $map_protocol = { |
| 192 |
1 => 'tacacsplus', 2 => 'radius', 3 => 'ldap', |
| 193 |
4 => 'kerberos', 5 => 'ntlm', 6 => 'sdi', |
| 194 |
7 => 'other' |
| 195 |
}; |
| 196 |
my $map_status = { 1 => 'up', 2 => 'dead' }; |
| 197 |
|
| 198 |
my $mapping = { |
| 199 |
auth_requests => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.1' }, # casAuthenRequests |
| 200 |
auth_timeouts => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.2' }, # casAuthenRequestTimeouts |
| 201 |
auth_reponse_time => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.6' }, # casAuthenResponseTime (unit 0.01 of sec) |
| 202 |
auth_trans_success => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.7' }, # casAuthenTransactionSuccesses |
| 203 |
acc_requests => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.17' }, # casAcctRequests |
| 204 |
acc_timeouts => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.18' }, # casAcctRequestTimeouts |
| 205 |
acc_reponse_time => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.22' }, # casAcctResponseTime (unit 0.01 of sec) |
| 206 |
acc_trans_success => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.23' }, # casAcctTransactionSuccesses |
| 207 |
status => { oid => '.1.3.6.1.4.1.9.10.56.1.2.1.1.25', map => $map_status } # casState |
| 208 |
}; |
| 209 |
my $mapping_name = { |
| 210 |
address => { oid => '.1.3.6.1.4.1.9.10.56.1.1.2.1.3' }, # casAddress |
| 211 |
authen_port => { oid => '.1.3.6.1.4.1.9.10.56.1.1.2.1.4' }, # casAuthenPort |
| 212 |
acc_port => { oid => '.1.3.6.1.4.1.9.10.56.1.1.2.1.5' } # casAcctPort |
| 213 |
}; |
| 214 |
|
| 215 |
sub manage_selection { |
| 216 |
my ($self, %options) = @_; |
| 217 |
|
| 218 |
$self->{cache_name} = 'cisco_standard_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . |
| 219 |
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . |
| 220 |
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); |
| 221 |
|
| 222 |
my $oid_casConfigEntry = '.1.3.6.1.4.1.9.10.56.1.1.2.1'; |
| 223 |
my $snmp_result = $options{snmp}->get_table( |
| 224 |
oid => $oid_casConfigEntry, |
| 225 |
start => $mapping_name->{address}->{oid}, |
| 226 |
end => $mapping_name->{acc_port}->{oid}, |
| 227 |
nothing_quit => 1 |
| 228 |
); |
| 229 |
|
| 230 |
$self->{aaa} = {}; |
| 231 |
foreach (keys %$snmp_result) { |
| 232 |
next if (! /^$mapping_name->{address}->{oid}\.((\d+).*)$/); |
| 233 |
my ($instance, $protocol) = ($1, $map_protocol->{$2}); |
| 234 |
my $result = $options{snmp}->map_instance(mapping => $mapping_name, results => $snmp_result, instance => $instance); |
| 235 |
|
| 236 |
my $name = $result->{address} . ':' . $result->{authen_port} . ':' . $result->{acc_port}; |
| 237 |
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && |
| 238 |
$name !~ /$self->{option_results}->{filter_name}/) { |
| 239 |
$self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); |
| 240 |
next; |
| 241 |
} |
| 242 |
|
| 243 |
$self->{aaa}->{$name} = { |
| 244 |
%$result, |
| 245 |
name => $name, |
| 246 |
protocol => $protocol, |
| 247 |
instance => $instance |
| 248 |
}; |
| 249 |
} |
| 250 |
|
| 251 |
$self->{global} = { total => scalar(keys %{$self->{aaa}}) }; |
| 252 |
|
| 253 |
return if (scalar(keys %{$self->{aaa}}) <= 0); |
| 254 |
|
| 255 |
$options{snmp}->load(oids => [ |
| 256 |
map($_->{oid}, values(%$mapping)) |
| 257 |
], |
| 258 |
instances => [map($_->{instance}, values(%{$self->{aaa}}))], |
| 259 |
instance_regexp => '^(.*)$' |
| 260 |
); |
| 261 |
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1); |
| 262 |
|
| 263 |
foreach (keys %{$self->{aaa}}) { |
| 264 |
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $self->{aaa}->{$_}->{instance}); |
| 265 |
|
| 266 |
$self->{aaa}->{$_}->{global_status} = { |
| 267 |
name => $self->{aaa}->{$_}->{name}, |
| 268 |
status => $result->{status} |
| 269 |
}; |
| 270 |
$self->{aaa}->{$_}->{global_auth} = { |
| 271 |
auth_requests => $result->{auth_requests}, |
| 272 |
auth_timeouts => $result->{auth_timeouts}, |
| 273 |
auth_trans_success => $result->{auth_trans_success}, |
| 274 |
auth_reponse_time => $result->{auth_reponse_time} * 10 |
| 275 |
}; |
| 276 |
$self->{aaa}->{$_}->{global_acc} = { |
| 277 |
acc_requests => $result->{acc_requests}, |
| 278 |
acc_timeouts => $result->{acc_timeouts}, |
| 279 |
acc_trans_success => $result->{acc_trans_success}, |
| 280 |
acc_reponse_time => $result->{acc_reponse_time} * 10 |
| 281 |
}; |
| 282 |
} |
| 283 |
} |
| 284 |
|
| 285 |
1; |
| 286 |
|
| 287 |
__END__ |
| 288 |
|
| 289 |
=head1 MODE |
| 290 |
|
| 291 |
Check AAA servers. |
| 292 |
|
| 293 |
=over 8 |
| 294 |
|
| 295 |
=item B<--filter-counters> |
| 296 |
|
| 297 |
Only display some counters (regexp can be used). |
| 298 |
Example: --filter-counters='auth' |
| 299 |
|
| 300 |
=item B<--filter-name> |
| 301 |
|
| 302 |
Filter AAA server by name (E.g.: 10.199.126.100:1812:1813. Format: [address]:[authPort]:[accPort]). |
| 303 |
|
| 304 |
=item B<--unknown-status> |
| 305 |
|
| 306 |
Define the conditions to match for the status to be UNKNOWN. |
| 307 |
You can use the following variables: %{status}, %{name} |
| 308 |
|
| 309 |
=item B<--warning-status> |
| 310 |
|
| 311 |
Define the conditions to match for the status to be WARNING. |
| 312 |
You can use the following variables: %{status}, %{name} |
| 313 |
|
| 314 |
=item B<--critical-status> |
| 315 |
|
| 316 |
Define the conditions to match for the status to be CRITICAL (default: '%{status} =~ /dead/i'). |
| 317 |
You can use the following variables: %{status}, %{name} |
| 318 |
|
| 319 |
=item B<--warning-*> B<--critical-*> |
| 320 |
|
| 321 |
Thresholds. |
| 322 |
Can be: 'total', |
| 323 |
'auth-requests', 'auth-requests-timeout', 'auth-transactions-suceeded', 'auth-roundtrip-time', |
| 324 |
'acc-requests', 'acc-requests-timeout', 'acc-transactions-suceeded', 'acc-roundtrip-time'. |
| 325 |
|
| 326 |
=back |
| 327 |
|
| 328 |
=cut |