wip fortiauthenticator

This commit is contained in:
garnier-quentin 2020-11-27 16:28:10 +01:00
parent a5c1c59f1c
commit 4fc03156ba
3 changed files with 263 additions and 3 deletions

View File

@ -221,6 +221,7 @@ sub run_global {
&& $options{config}->{name} =~ /$self->{option_results}->{filter_counters_block}/); && $options{config}->{name} =~ /$self->{option_results}->{filter_counters_block}/);
return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1); return undef if (defined($options{config}->{cb_init}) && $self->call_object_callback(method_name => $options{config}->{cb_init}) == 1);
my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0; my $resume = defined($options{resume}) && $options{resume} == 1 ? 1 : 0;
my $display_short = (!defined($options{config}->{display_short}) || $options{config}->{display_short} != 0) ? 1 : 0;
# Can be set when it comes from type 3 counters # Can be set when it comes from type 3 counters
my $called_multiple = defined($options{called_multiple}) && $options{called_multiple} == 1 ? 1 : 0; my $called_multiple = defined($options{called_multiple}) && $options{called_multiple} == 1 ? 1 : 0;
my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? 1 : 0; my $multiple_parent = defined($options{multiple_parent}) && $options{multiple_parent} == 1 ? 1 : 0;
@ -294,12 +295,13 @@ sub run_global {
} else { } else {
if ($long_msg ne '' && $multiple_parent == 0) { if ($long_msg ne '' && $multiple_parent == 0) {
if ($called_multiple == 0) { if ($called_multiple == 0) {
$self->{output}->output_add(short_msg => $prefix_output . $long_msg . $suffix_output) ; $self->{output}->output_add(short_msg => $prefix_output . $long_msg . $suffix_output)
if ($display_short == 1);
} else { } else {
$self->run_multiple_prefix_output( $self->run_multiple_prefix_output(
severity => 'ok', severity => 'ok',
short_msg => $prefix_output . $long_msg . $suffix_output short_msg => $prefix_output . $long_msg . $suffix_output
); ) if ($display_short == 1);
} }
} }
} }
@ -645,7 +647,13 @@ sub run_multiple {
if ($group->{type} == 1) { if ($group->{type} == 1) {
$self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance, indent_long_output => $indent_long_output); $self->run_multiple_instances(config => $group, multiple_parent => $multiple, instance_parent => $instance, indent_long_output => $indent_long_output);
} elsif ($group->{type} == 0) { } elsif ($group->{type} == 0) {
$self->run_global(config => $group, multiple_parent => $multiple, called_multiple => 1, force_instance => $instance, indent_long_output => $indent_long_output); $self->run_global(
config => $group,
multiple_parent => $multiple,
called_multiple => 1,
force_instance => $instance,
indent_long_output => $indent_long_output
);
} }
} }
} }

View File

@ -0,0 +1,251 @@
#
# Copyright 2020 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package network::fortinet::fortiauthenticator::snmp::mode::authenticator;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub custom_remaining_output {
my ($self, %options) = @_;
return sprintf(
'total: %s used: %s (%.3f%%) free: %s (%.3f%%)',
$self->{result_values}->{total},
$self->{result_values}->{used},
$self->{result_values}->{prct_used},
$self->{result_values}->{free},
$self->{result_values}->{prct_free}
);
}
sub auth_long_output {
my ($self, %options) = @_;
return 'checking authenticator';
}
sub prefix_auth_output {
my ($self, %options) = @_;
return 'Authenticator ';
}
sub prefix_users_output {
my ($self, %options) = @_;
return 'users ';
}
sub prefix_groups_output {
my ($self, %options) = @_;
return 'groups ';
}
sub prefix_radius_nas_output {
my ($self, %options) = @_;
return 'radius nas ';
}
sub prefix_authentication_output {
my ($self, %options) = @_;
return 'authentication ';
}
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'auth', type => 3, cb_prefix_output => 'prefix_auth_output', cb_long_output => 'auth_long_output', indent_long_output => ' ',
group => [
{ name => 'users', type => 0, display_short => 0, cb_prefix_output => 'prefix_users_output', skipped_code => { -10 => 1 } },
{ name => 'groups', type => 0, display_short => 0, cb_prefix_output => 'prefix_groups_output', skipped_code => { -10 => 1 } },
{ name => 'radius_nas', type => 0, display_short => 0, cb_prefix_output => 'prefix_radius_nas_output', skipped_code => { -10 => 1 } },
{ name => 'authentication', type => 0, display_short => 0, cb_prefix_output => 'prefix_authentication_output', skipped_code => { -10 => 1 } },
]
}
];
$self->{maps_counters}->{users} = [
{ label => 'users-usage', nlabel => 'authenticator.users.count', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_remaining_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', cast_int => 1 }
]
}
},
{ label => 'users-usage-prct', nlabel => 'authenticator.users.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_remaining_output'),
perfdatas => [
{ template => '%.3f', min => 0, max => 100, unit => '%' }
]
}
}
];
$self->{maps_counters}->{groups} = [
{ label => 'groups-usage', nlabel => 'authenticator.groups.count', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_remaining_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', cast_int => 1 }
]
}
},
{ label => 'groups-usage-prct', nlabel => 'authenticator.groups.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_remaining_output'),
perfdatas => [
{ template => '%.3f', min => 0, max => 100, unit => '%' }
]
}
}
];
$self->{maps_counters}->{radius_nas} = [
{ label => 'radius-nas-usage', nlabel => 'authenticator.radius.nas.count', set => {
key_values => [ { name => 'used' }, { name => 'free' }, { name => 'prct_used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_remaining_output'),
perfdatas => [
{ template => '%d', min => 0, max => 'total', cast_int => 1 }
]
}
},
{ label => 'radius-nas-usage-prct', nlabel => 'authenticator.radius.nas.percentage', display_ok => 0, set => {
key_values => [ { name => 'prct_used' }, { name => 'free' }, { name => 'used' }, { name => 'prct_free' }, { name => 'total' } ],
closure_custom_output => $self->can('custom_remaining_output'),
perfdatas => [
{ template => '%.3f', min => 0, max => 100, unit => '%' }
]
}
}
];
$self->{maps_counters}->{authentication} = [
{ label => 'authentication-events', nlabel => 'authenticator.authentication.events.persecond', set => {
key_values => [ { name => 'events_total', per_second => 1 } ],
output_template => 'events: %d/s',
perfdatas => [
{ template => '%d', min => 0, unit => '/s', cast_int => 1 }
]
}
},
{ label => 'authentication-failures', nlabel => 'authenticator.authentication.failures.persecond', set => {
key_values => [ { name => 'failures_total', per_second => 1 } ],
output_template => 'failures: %d/s',
perfdatas => [
{ template => '%d', min => 0, unit => '/s', cast_int => 1 }
]
}
}
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1, force_new_perfdata => 1);
bless $self, $class;
$options{options}->add_options(arguments => {
});
return $self;
}
my $mapping = {
users => { oid => '.1.3.6.1.4.1.12356.113.1.202.1' }, # facAuthUserCount
groups => { oid => '.1.3.6.1.4.1.12356.113.1.202.2' }, # facAuthUserCount
users_remaining => { oid => '.1.3.6.1.4.1.12356.113.1.202.4' }, # facAuthUsersRemaining
groups_remaining => { oid => '.1.3.6.1.4.1.12356.113.1.202.5' }, # facAuthGroupRemaining
radius_nas => { oid => '.1.3.6.1.4.1.12356.113.1.202.7' }, # facRadiusNasCount
radius_nas_remaining => { oid => '.1.3.6.1.4.1.12356.113.1.202.8' }, # facRadiusNasRemaining
events_total => { oid => '.1.3.6.1.4.1.12356.113.1.202.20' }, # facAuthEventsTotal
failures_total => { oid => '.1.3.6.1.4.1.12356.113.1.202.22' } # facAuthFailuresTotal
};
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_leef(oids => [ map($_->{oid} . '.0', values(%$mapping)) ], nothing_quit => 1);
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => 0);
$self->{output}->output_add(short_msg => 'Authenticator statistics are ok');
$self->{auth} = {
global => {
users => {
used => $result->{users},
free => $result->{users_remaining},
total => $result->{users} + $result->{users_remaining},
prct_used => $result->{users} / ($result->{users} + $result->{users_remaining}),
prct_free => 100 - ($result->{users} / ($result->{users} + $result->{users_remaining}))
},
groups => {
used => $result->{groups},
free => $result->{groups_remaining},
total => $result->{groups} + $result->{groups_remaining},
prct_used => $result->{groups} / ($result->{groups} + $result->{groups_remaining}),
prct_free => 100 - ($result->{groups} / ($result->{groups} + $result->{groups_remaining}))
},
radius_nas => {
used => $result->{radius_nas},
free => $result->{radius_nas_remaining},
total => $result->{radius_nas} + $result->{radius_nas_remaining},
prct_used => $result->{radius_nas} / ($result->{radius_nas} + $result->{radius_nas_remaining}),
prct_free => 100 - ($result->{radius_nas} / ($result->{radius_nas} + $result->{radius_nas_remaining}))
},
authentication => {
events_total => $result->{events_total},
failures_total => $result->{failures_total}
}
}
};
$self->{cache_name} = 'fortinet_fortiauthenticator_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check authenticator statistics.
=over 8
=item B<--warning-*> B<--critical-*>
Thresholds.
Can be: 'members-total', 'memory-usage-prct', 'memory-usage', 'memory-usage-free',
'cpu-utilization'.
=back
=cut

View File

@ -31,6 +31,7 @@ sub new {
$self->{version} = '1.0'; $self->{version} = '1.0';
$self->{modes} = { $self->{modes} = {
'authenticator' => 'network::fortinet::fortiauthenticator::snmp::mode::authenticator',
'cpu' => 'network::fortinet::fortiauthenticator::snmp::mode::cpu', 'cpu' => 'network::fortinet::fortiauthenticator::snmp::mode::cpu',
'disk-log' => 'network::fortinet::fortiauthenticator::snmp::mode::disklog', 'disk-log' => 'network::fortinet::fortiauthenticator::snmp::mode::disklog',
'ha' => 'network::fortinet::fortiauthenticator::snmp::mode::ha', 'ha' => 'network::fortinet::fortiauthenticator::snmp::mode::ha',