enhance vpn fortigate
This commit is contained in:
parent
ffe94f3ee3
commit
9f0a54ccc3
|
@ -46,34 +46,39 @@ sub set_counters {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{maps_counters_type} = [
|
$self->{maps_counters_type} = [
|
||||||
{ name => 'vdstats', type => 1, cb_prefix_output => 'prefix_vd_output', message_multiple => 'All virtual domains are OK' },
|
{ name => 'vd', type => 3, cb_prefix_output => 'prefix_vd_output', cb_long_output => 'vd_long_output', indent_long_output => ' ', message_multiple => 'All virtual domains are OK',
|
||||||
{ name => 'vpn', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All VPNs states are OK' },
|
group => [
|
||||||
|
{ name => 'global', type => 0, skipped_code => { -10 => 1 } },
|
||||||
|
{ name => 'vpn', display_long => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All vpn are ok', type => 1, skipped_code => { -10 => 1 } },
|
||||||
|
]
|
||||||
|
}
|
||||||
];
|
];
|
||||||
$self->{maps_counters}->{vdstats} = [
|
|
||||||
|
$self->{maps_counters}->{global} = [
|
||||||
{ label => 'users', set => {
|
{ label => 'users', set => {
|
||||||
key_values => [ { name => 'users' }, { name => 'display' } ],
|
key_values => [ { name => 'users' } ],
|
||||||
output_template => 'Logged users: %s',
|
output_template => 'Logged users: %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'users', value => 'users_absolute', template => '%d',
|
{ label => 'users', value => 'users_absolute', template => '%d',
|
||||||
min => 0, unit => 'users', label_extra_instance => 1, instance_use => 'display_absolute' },
|
min => 0, unit => 'users', label_extra_instance => 1 },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'sessions', set => {
|
{ label => 'sessions', set => {
|
||||||
key_values => [ { name => 'sessions' }, { name => 'display' } ],
|
key_values => [ { name => 'sessions' }],
|
||||||
output_template => 'Active web sessions: %s',
|
output_template => 'Active web sessions: %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'sessions', value => 'sessions_absolute', template => '%d',
|
{ label => 'sessions', value => 'sessions_absolute', template => '%d',
|
||||||
min => 0, unit => 'sessions', label_extra_instance => 1, instance_use => 'display_absolute' },
|
min => 0, unit => 'sessions', label_extra_instance => 1 },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ label => 'tunnels', set => {
|
{ label => 'tunnels', set => {
|
||||||
key_values => [ { name => 'tunnels' }, { name => 'display' } ],
|
key_values => [ { name => 'tunnels' } ],
|
||||||
output_template => 'Active Tunnels: %s',
|
output_template => 'Active Tunnels: %s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'active_tunnels', value => 'tunnels_absolute', template => '%d',
|
{ label => 'active_tunnels', value => 'tunnels_absolute', template => '%d',
|
||||||
min => 0, unit => 'tunnels', label_extra_instance => 1, instance_use => 'display_absolute' },
|
min => 0, unit => 'tunnels', label_extra_instance => 1 },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -94,7 +99,7 @@ sub set_counters {
|
||||||
output_template => 'Traffic In: %s %s/s',
|
output_template => 'Traffic In: %s %s/s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f',
|
{ label => 'traffic_in', value => 'traffic_in_per_second', template => '%.2f',
|
||||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
|
min => 0, unit => 'b/s', label_extra_instance => 1 },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -104,7 +109,7 @@ sub set_counters {
|
||||||
output_template => 'Traffic Out: %s %s/s',
|
output_template => 'Traffic Out: %s %s/s',
|
||||||
perfdatas => [
|
perfdatas => [
|
||||||
{ label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f',
|
{ label => 'traffic_out', value => 'traffic_out_per_second', template => '%.2f',
|
||||||
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
|
min => 0, unit => 'b/s', label_extra_instance => 1 },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +122,12 @@ sub prefix_vd_output {
|
||||||
return "Virtual domain '" . $options{instance_value}->{display} . "' ";
|
return "Virtual domain '" . $options{instance_value}->{display} . "' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub vd_long_output {
|
||||||
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
return "checking virtual domain '" . $options{instance_value}->{display} . "'";
|
||||||
|
}
|
||||||
|
|
||||||
sub prefix_vpn_output {
|
sub prefix_vpn_output {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
|
@ -128,13 +139,13 @@ sub new {
|
||||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
|
||||||
bless $self, $class;
|
bless $self, $class;
|
||||||
|
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments => {
|
||||||
{
|
'filter-vpn:s' => { name => 'filter_vpn' },
|
||||||
"filter-vpn:s" => { name => 'filter_vpn' },
|
'filter-vdomain:s' => { name => 'filter_vdomain' },
|
||||||
"filter-vdomain:s" => { name => 'filter_vdomain' },
|
'warning-status:s' => { name => 'warning_status', default => '' },
|
||||||
"warning-status:s" => { name => 'warning_status', default => '' },
|
'critical-status:s' => { name => 'critical_status', default => '%{state} eq "down"' },
|
||||||
"critical-status:s" => { name => 'critical_status', default => '%{state} eq "down"' },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,16 +156,14 @@ sub check_options {
|
||||||
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
$self->change_macros(macros => ['warning_status', 'critical_status']);
|
||||||
}
|
}
|
||||||
|
|
||||||
my %map_status = (
|
my $map_status = { 1 => 'down', 2 => 'up' };
|
||||||
1 => 'down',
|
|
||||||
2 => 'up',
|
|
||||||
);
|
|
||||||
|
|
||||||
my $mapping = {
|
my $mapping = {
|
||||||
fgVpnTunEntPhase2Name => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.3' },
|
fgVpnTunEntPhase2Name => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.3' },
|
||||||
fgVpnTunEntInOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.18' },
|
fgVpnTunEntInOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.18' },
|
||||||
fgVpnTunEntOutOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.19' },
|
fgVpnTunEntOutOctets => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.19' },
|
||||||
fgVpnTunEntStatus => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.20', map => \%map_status },
|
fgVpnTunEntStatus => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.20', map => $map_status },
|
||||||
|
fgVpnTunEntVdom => { oid => '.1.3.6.1.4.1.12356.101.12.2.2.1.21' },
|
||||||
};
|
};
|
||||||
|
|
||||||
my $mapping2 = {
|
my $mapping2 = {
|
||||||
|
@ -170,48 +179,62 @@ my $oid_fgVdEntName = '.1.3.6.1.4.1.12356.101.3.2.1.1.2';
|
||||||
sub manage_selection {
|
sub manage_selection {
|
||||||
my ($self, %options) = @_;
|
my ($self, %options) = @_;
|
||||||
|
|
||||||
$self->{snmp} = $options{snmp};
|
|
||||||
$self->{cache_name} = "fortigate_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
|
$self->{cache_name} = "fortigate_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' .
|
||||||
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
|
||||||
(defined($self->{option_results}->{filter_vpn}) ? md5_hex($self->{option_results}->{filter_vpn}) : md5_hex('all')) . '_' .
|
(defined($self->{option_results}->{filter_vpn}) ? md5_hex($self->{option_results}->{filter_vpn}) : md5_hex('all')) . '_' .
|
||||||
(defined($self->{option_results}->{filter_vdomain}) ? md5_hex($self->{option_results}->{filter_vdomain}) : md5_hex('all'));
|
(defined($self->{option_results}->{filter_vdomain}) ? md5_hex($self->{option_results}->{filter_vdomain}) : md5_hex('all'));
|
||||||
|
|
||||||
$self->{results} = $options{snmp}->get_multiple_table(oids => [
|
my $snmp_result = $options{snmp}->get_multiple_table(
|
||||||
|
oids => [
|
||||||
{ oid => $oid_fgVdEntName },
|
{ oid => $oid_fgVdEntName },
|
||||||
{ oid => $oid_fgVpnTunTable },
|
{ oid => $oid_fgVpnTunTable },
|
||||||
{ oid => $oid_fgVpnSslStatsTable },
|
{ oid => $oid_fgVpnSslStatsTable },
|
||||||
],
|
],
|
||||||
, nothing_quit => 1);
|
nothing_quit => 1
|
||||||
|
);
|
||||||
|
|
||||||
foreach my $oid (keys %{$self->{results}->{ $oid_fgVdEntName }}) {
|
$self->{vd} = {};
|
||||||
|
foreach my $oid (keys %{$snmp_result->{ $oid_fgVdEntName }}) {
|
||||||
$oid =~ /^$oid_fgVdEntName\.(.*)$/;
|
$oid =~ /^$oid_fgVdEntName\.(.*)$/;
|
||||||
my $instance = $1;
|
my $vdom_instance = $1;
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping2, results => $self->{results}->{$oid_fgVpnSslStatsTable}, instance => $instance);
|
my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_fgVpnSslStatsTable}, instance => $vdom_instance);
|
||||||
my $vdomain_name = $self->{results}->{$oid_fgVdEntName}->{$oid_fgVdEntName.'.'.$instance};
|
my $vdomain_name = $snmp_result->{$oid_fgVdEntName}->{$oid_fgVdEntName . '.' . $vdom_instance};
|
||||||
|
|
||||||
if (defined($self->{option_results}->{filter_vdomain}) && $self->{option_results}->{filter_vdomain} ne '' &&
|
if (defined($self->{option_results}->{filter_vdomain}) && $self->{option_results}->{filter_vdomain} ne '' &&
|
||||||
$vdomain_name !~ /$self->{option_results}->{filter_vdomain}/) {
|
$vdomain_name !~ /$self->{option_results}->{filter_vdomain}/) {
|
||||||
$self->{output}->output_add(long_msg => "Skipping '" . $vdomain_name . "': no matching filter.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $vdomain_name . "': no matching filter.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
$self->{vdstats}->{$vdomain_name} = { users => $result->{fgVpnSslStatsLoginUsers},
|
|
||||||
sessions => $result->{fgVpnSslStatsActiveWebSessions},
|
|
||||||
tunnels => $result->{fgVpnSslStatsActiveTunnels},
|
|
||||||
display => $vdomain_name };
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach my $oid (sort keys %{$self->{results}->{$oid_fgVpnTunTable}}) {
|
$self->{vd}->{$vdomain_name} = {
|
||||||
next if ($oid !~ /^$mapping->{fgVpnTunEntStatus}->{oid}\.(.*)$/);
|
display => $vdomain_name,
|
||||||
my $instance = $1;
|
global => {
|
||||||
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fgVpnTunTable}, instance => $instance);
|
users => $result->{fgVpnSslStatsLoginUsers},
|
||||||
|
tunnels => $result->{fgVpnSslStatsActiveTunnels},
|
||||||
|
sessions => $result->{fgVpnSslStatsActiveWebSessions}
|
||||||
|
},
|
||||||
|
vpn => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (keys %{$snmp_result->{$oid_fgVpnTunTable}}) {
|
||||||
|
next if (/^$mapping->{fgVpnTunEntVdom}->{oid}\.(.*)$/ &&
|
||||||
|
$snmp_result->{$oid_fgVpnTunTable}->{$_} != $vdom_instance
|
||||||
|
);
|
||||||
|
$result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_fgVpnTunTable}, instance => $1);
|
||||||
|
|
||||||
if (defined($self->{option_results}->{filter_vpn}) && $self->{option_results}->{filter_vpn} ne '' &&
|
if (defined($self->{option_results}->{filter_vpn}) && $self->{option_results}->{filter_vpn} ne '' &&
|
||||||
$result->{fgVpnTunEntPhase2Name} !~ /$self->{option_results}->{filter_vpn}/) {
|
$result->{fgVpnTunEntPhase2Name} !~ /$self->{option_results}->{filter_vpn}/) {
|
||||||
$self->{output}->output_add(long_msg => "Skipping '" . $result->{fgVpnTunEntPhase2Name} . "': no matching filter.", debug => 1);
|
$self->{output}->output_add(long_msg => "skipping '" . $result->{fgVpnTunEntPhase2Name} . "': no matching filter.", debug => 1);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
$self->{vpn}->{$result->{fgVpnTunEntPhase2Name}} = { state => $result->{fgVpnTunEntStatus},
|
|
||||||
|
$self->{vd}->{$vdomain_name}->{vpn}->{$result->{fgVpnTunEntPhase2Name}} = {
|
||||||
|
display => $result->{fgVpnTunEntPhase2Name},
|
||||||
|
state => $result->{fgVpnTunEntStatus},
|
||||||
traffic_in => $result->{fgVpnTunEntInOctets},
|
traffic_in => $result->{fgVpnTunEntInOctets},
|
||||||
traffic_out => $result->{fgVpnTunEntOutOctets},
|
traffic_out => $result->{fgVpnTunEntOutOctets},
|
||||||
display => $result->{fgVpnTunEntPhase2Name} };
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue