enhance paloalto sessions

This commit is contained in:
garnier-quentin 2020-03-27 12:04:48 +01:00
parent ac9eec384b
commit 78b94f42b9
1 changed files with 114 additions and 179 deletions

View File

@ -25,6 +25,44 @@ use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub custom_vsys_active_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
label => $self->{label},
nlabel => $self->{nlabel},
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display_absolute} : undef,
value => $self->{result_values}->{sessions_active_absolute},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0,
max => $self->{result_values}->{sessions_max_absolute} != 0 ? $self->{result_values}->{sessions_max_absolute} : undef
);
}
sub custom_active_perfdata {
my ($self, %options) = @_;
$self->{output}->perfdata_add(
label => $self->{label},
nlabel => $self->{nlabel},
value => $self->{result_values}->{sessions_active_absolute},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}),
min => 0,
max => $self->{result_values}->{sessions_max_absolute} != 0 ? $self->{result_values}->{sessions_max_absolute} : undef
);
}
sub custom_active_output {
my ($self, %options) = @_;
return sprintf('active: %s (%s)',
$self->{result_values}->{sessions_active_absolute},
$self->{result_values}->{sessions_max_absolute} != 0 ? $self->{result_values}->{sessions_max_absolute} : '-'
);
}
sub set_counters {
my ($self, %options) = @_;
@ -33,76 +71,79 @@ sub set_counters {
{ name => 'vsys', type => 1, cb_prefix_output => 'prefix_vsys_output', message_multiple => 'Vsys sessions metrics are OK', skipped_code => { -10 => 1 } },
];
$self->{maps_counters}->{global} = [
{ label => 'active', set => {
key_values => [ { name => 'panSessionActive' }, { name => 'panSessionMax' } ],
closure_custom_calc => $self->can('custom_active_calc'),
{ label => 'active', nlabel => 'sessions.active.count', set => {
key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' } ],
closure_custom_output => $self->can('custom_active_output'),
closure_custom_perfdata => $self->can('custom_active_perfdata'),
closure_custom_threshold_check => $self->can('custom_active_threshold'),
closure_custom_perfdata => $self->can('custom_active_perfdata')
}
},
{ label => 'active-ssl-proxy', nlabel => 'sessions.active.vpnssl.count', set => {
key_values => [ { name => 'panSessionSslProxyUtilization' } ],
output_template => 'Active SSL Proxy : %.2f %%',
{ label => 'active-prct', nlabel => 'sessions.active.percentage', display_ok => 0, set => {
key_values => [ { name => 'sessions_active_prct' } ],
output_template => 'active: %.2f %%',
perfdatas => [
{ label => 'active_ssl_proxy', value => 'panSessionSslProxyUtilization_absolute', template => '%.2f', unit => '%',
min => 0, max => 100 },
],
{ label => 'active_prct', value => 'sessions_active_prct_absolute', template => '%.2f', unit => '%',
min => 0, max => 100 }
]
}
},
{ label => 'active-tcp', nlabel => 'sessions.active.tcp.count', set => {
key_values => [ { name => 'panSessionActiveTcp' } ],
output_template => 'Active TCP : %s',
output_template => 'active TCP: %s',
perfdatas => [
{ label => 'active_tcp', value => 'panSessionActiveTcp_absolute', template => '%s', min => 0 },
],
{ label => 'active_tcp', value => 'panSessionActiveTcp_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'active-udp', nlabel => 'sessions.active.udp.count', set => {
key_values => [ { name => 'panSessionActiveUdp' } ],
output_template => 'Active UDP : %s',
output_template => 'active UDP: %s',
perfdatas => [
{ label => 'active_udp', value => 'panSessionActiveUdp_absolute', template => '%s', min => 0 },
],
{ label => 'active_udp', value => 'panSessionActiveUdp_absolute', template => '%s', min => 0 }
]
}
},
{ label => 'active-icmp', nlabel => 'sessions.active.icmp.count', set => {
key_values => [ { name => 'panSessionActiveICMP' } ],
output_template => 'Active ICMP : %s',
output_template => 'active ICMP: %s',
perfdatas => [
{ label => 'active_icmp', value => 'panSessionActiveICMP_absolute', template => '%s', min => 0 },
],
{ label => 'active_icmp', value => 'panSessionActiveICMP_absolute', template => '%s', min => 0 }
]
}
},
}
];
$self->{maps_counters}->{vsys} = [
{ label => 'active-vsys', set => {
key_values => [ { name => 'panVsysActiveSessions' }, { name => 'panVsysMaxSessions' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_active_calc'),
{ label => 'vsys-active', nlabel => 'vsys.sessions.active.count', set => {
key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' }, { name => 'display' } ],
closure_custom_output => $self->can('custom_active_output'),
closure_custom_perfdata => $self->can('custom_active_perfdata'),
closure_custom_threshold_check => $self->can('custom_active_threshold'),
closure_custom_perfdata => $self->can('custom_vsys_active_perfdata')
}
},
{ label => 'vsys-active-prct', nlabel => 'vsys.sessions.active.percentage', display_ok => 0, set => {
key_values => [ { name => 'sessions_active_prct' } ],
output_template => 'active: %.2f %%',
perfdatas => [
{ label => 'active_prct', value => 'sessions_active_prct_absolute', template => '%.2f', unit => '%',
min => 0, max => 100 }
]
}
},
{ label => 'vsys-active-tcp', nlabel => 'vsys.sessions.active.tcp.count', set => {
key_values => [ { name => 'panVsysActiveTcpCps' }, { name => 'display' } ],
output_template => 'Active TCP : %s',
output_template => 'active TCP: %s',
perfdatas => [
{ label => 'active_tcp', value => 'panVsysActiveTcpCps_absolute', template => '%s',
label_extra_instance => 1, instance_use => 'display_absolute', min => 0 },
],
label_extra_instance => 1, min => 0 }
]
}
},
{ label => 'vsys-active-udp', nlabel => 'vsys.sessions.active.udp.count', set => {
key_values => [ { name => 'panVsysActiveUdpCps' }, { name => 'display' } ],
output_template => 'Active UDP : %s',
output_template => 'active UDP: %s',
perfdatas => [
{ label => 'active_udp', value => 'panVsysActiveUdpCps_absolute', template => '%s',
label_extra_instance => 1, instance_use => 'display_absolute', min => 0 },
],
label_extra_instance => 1, min => 0 }
]
}
},
{ label => 'vsys-active-other', nlabel => 'vsys.sessions.active.other.count', set => {
@ -110,14 +151,11 @@ sub set_counters {
output_template => 'Other : %s',
perfdatas => [
{ label => 'active_other', value => 'panVsysActiveOtherIpCps_absolute', template => '%s',
label_extra_instance => 1, instance_use => 'display_absolute', min => 0 },
],
label_extra_instance => 1, min => 0 }
]
}
},
}
];
}
sub prefix_global_output {
@ -129,102 +167,7 @@ sub prefix_global_output {
sub prefix_vsys_output {
my ($self, %options) = @_;
return "Vsys '" . $options{instance_value}->{display} . "' ";
}
sub custom_active_perfdata {
my ($self, %options) = @_;
my %total_options = ();
if ($self->{label} eq 'active') {
if ($self->{result_values}->{panSessionMax} != 0) {
$total_options{total} = $self->{result_values}->{panSessionMax};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $self->{label},
nlabel => 'sessions.active.count',
value => $self->{result_values}->{panSessionActive},
warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef,
critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef,
min => 0, max => $self->{result_values}->{panSessionMax});
} else {
if ($self->{result_values}->{panVsysMaxSessions} != 0) {
$total_options{total} = $self->{result_values}->{panVsysMaxSessions};
$total_options{cast_int} = 1;
}
$self->{output}->perfdata_add(label => $self->{label},
nlabel => $self->{result_values}->{display} . "#" . 'sessions.active.count',
value => $self->{result_values}->{panVsysActiveSessions},
warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef,
critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef,
min => 0, max => $self->{result_values}->{panVsysMaxSessions});
}
}
sub custom_active_threshold {
my ($self, %options) = @_;
my ($exit, $threshold_value) = ('ok');
if ($self->{label} eq 'active') {
if ($self->{result_values}->{panSessionMax} != 0) {
$threshold_value = $self->{result_values}->{active_prct};
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold =>
[ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value));
return $exit;
} else {
if ($self->{result_values}->{panVsysMaxSessions} != 0) {
$threshold_value = $self->{result_values}->{active_prct};
}
$exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold =>
[ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value));
return $exit;
}
}
sub custom_active_output {
my ($self, %options) = @_;
my $msg = "";
if ($self->{label} eq 'active') {
$msg = sprintf("Active : %s (%s)",
$self->{result_values}->{panSessionActive},
$self->{result_values}->{panSessionMax} != 0 ? $self->{result_values}->{active_prct} . " %" :
'-');
} else {
$msg = sprintf("Active : %s (%s)",
$self->{result_values}->{panVsysActiveSessions},
$self->{result_values}->{panVsysMaxSessions} != 0 ? $self->{result_values}->{active_prct} . " %" :
'-');
}
return $msg;
}
sub custom_active_calc {
my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{panSessionActive} = $options{new_datas}->{$self->{instance} . '_panSessionActive'};
$self->{result_values}->{panSessionMax} = $options{new_datas}->{$self->{instance} . '_panSessionMax'};
$self->{result_values}->{panVsysActiveSessions} = $options{new_datas}->{$self->{instance} . '_panVsysActiveSessions'};
$self->{result_values}->{panVsysMaxSessions} = $options{new_datas}->{$self->{instance} . '_panVsysMaxSessions'};
$self->{result_values}->{active_prct} = 0;
if ($self->{label} eq 'active') {
if ($self->{result_values}->{panSessionMax} != 0) {
$self->{result_values}->{active_prct} = $self->{result_values}->{panSessionActive} * 100 / $self->{result_values}->{panSessionMax};
}
} else {
if ($self->{result_values}->{panVsysMaxSessions} != 0) {
$self->{result_values}->{active_prct} = $self->{result_values}->{panVsysActiveSessions} * 100 / $self->{result_values}->{panVsysMaxSessions};
}
}
return 0;
return "Vsys '" . $options{instance_value}->{display} . "' sessions ";
}
sub new {
@ -233,7 +176,7 @@ sub new {
bless $self, $class;
$options{options}->add_options(arguments => {
'add-vsys' => { name => 'add_vsys' },
'add-vsys' => { name => 'add_vsys' },
});
return $self;
@ -241,56 +184,54 @@ sub new {
my $mapping_sessions = {
panSessionMax => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' },
panSessionActive => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' },
panSessionActiveTcp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.4' },
panSessionActiveUdp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.5' },
panSessionActiveICMP => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.6' },
#panSessionActiveSslProxy => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.7' }, Cannot get the max if 0...
panSessionSslProxyUtilization => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.8' },
sessions_max => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' }, # panSessionMax
sessions_active => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' }, # panSessionActive
panSessionActiveTcp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.4' },
panSessionActiveUdp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.5' },
panSessionActiveICMP => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.6' },
panSessionSslProxyUtilization => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.8' }
};
my $mapping_vsys = {
panVsysName => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' },
panVsysActiveSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' },
panVsysMaxSessions => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' },
panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' },
panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' },
panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' },
display => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, # panVsysName
sessions_active => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, # panVsysActiveSessions
sessions_max => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, # panVsysMaxSessions
panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' },
panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' },
panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' }
};
sub add_vsys {
my ($self, %options) = @_;
my $oid_panVsysEntry = '.1.3.6.1.4.1.25461.2.1.2.3.9.1';
$self->{results} = $options{snmp}->get_table(oid => $oid_panVsysEntry,
nothing_quit => 1);
my $snmp_result = $options{snmp}->get_table(
oid => $oid_panVsysEntry,
nothing_quit => 1
);
foreach my $oid (keys %{$self->{results}}) {
foreach my $oid (keys %$snmp_result) {
next if $oid !~ /^$mapping_vsys->{panVsysName}->{oid}\.(.*)$/;
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $self->{results}, instance => $instance);
$self->{vsys}->{$result->{panVsysName}} = {
display => $result->{panVsysName},
panVsysMaxSessions => defined($result->{panVsysMaxSessions}) ? $result->{panVsysMaxSessions} : 0,
panVsysActiveSessions => $result->{panVsysActiveSessions},
panVsysActiveTcpCps => $result->{panVsysActiveTcpCps},
panVsysActiveUdpCps => $result->{panVsysActiveUdpCps},
};
my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $snmp_result, instance => $instance);
$self->{vsys}->{$result->{display}} = $result;
$self->{vsys}->{$result->{display}}->{sessions_max} = 0 if (!defined($result->{sessions_max}));
$self->{vsys}->{$result->{display}}->{sessions_active_prct} = $result->{sessions_active} * 100 / $self->{vsys}->{$result->{display}}->{sessions_max}
if ($self->{vsys}->{$result->{display}}->{sessions_max} != 0);
}
}
sub manage_selection {
my ($self, %options) = @_;
my $oid_panSession = '.1.3.6.1.4.1.25461.2.1.2.3';
$self->{results} = $options{snmp}->get_table(oid => $oid_panSession,
nothing_quit => 1);
$self->{global} = $options{snmp}->map_instance(mapping => $mapping_sessions, results => $self->{results}, instance => '0');
$self->{global}->{panSessionMax} = 0 if (!defined($self->{global}->{panSessionMax}));
my $snmp_result = $options{snmp}->get_leef(
oids => [ map($_->{oid} . '.0', values(%$mapping_sessions)) ],
nothing_quit => 1
);
$self->{global} = $options{snmp}->map_instance(mapping => $mapping_sessions, results => $snmp_result, instance => '0');
$self->{global}->{sessions_max} = 0 if (!defined($self->{global}->{sessions_max}));
$self->{global}->{sessions_active_prct} = $self->{global}->{sessions_active} * 100 / $self->{global}->{sessions_max}
if ($self->{global}->{sessions_max} != 0);
$self->add_vsys(snmp => $options{snmp})
if (defined($self->{option_results}->{add_vsys}));
@ -306,17 +247,11 @@ Check sessions.
=over 8
=item B<--warning-*>
=item B<--warning-*> B<--critical-*>
Threshold warning.
Global: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%).
Per vsys: 'active-vsys' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other'
=item B<--critical-*>
Threshold critical.
Global: 'active' (%), 'active-tcp', 'active-udp', 'active-icmp', 'active-ssl-proxy' (%).
Per vsys: 'active-vsys' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other'
Thresholds.
Global: 'active', 'active-prct', (%), 'active-tcp', 'active-udp', 'active-icmp',
Per vsys: 'vsys-active', 'vsys-active-prct' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other'.
=back