| 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 network::paloalto::snmp::mode::sessions; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub custom_vsys_active_perfdata { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
$self->{output}->perfdata_add( |
| 32 |
label => $self->{label}, |
| 33 |
nlabel => $self->{nlabel}, |
| 34 |
instances => $self->use_instances(extra_instance => $options{extra_instance}) ? $self->{result_values}->{display} : undef, |
| 35 |
value => $self->{result_values}->{sessions_active}, |
| 36 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 37 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 38 |
min => 0, |
| 39 |
max => $self->{result_values}->{sessions_max} != 0 ? $self->{result_values}->{sessions_max} : undef |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
sub custom_active_perfdata { |
| 44 |
my ($self, %options) = @_; |
| 45 |
|
| 46 |
$self->{output}->perfdata_add( |
| 47 |
label => $self->{label}, |
| 48 |
nlabel => $self->{nlabel}, |
| 49 |
value => $self->{result_values}->{sessions_active}, |
| 50 |
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{thlabel}), |
| 51 |
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{thlabel}), |
| 52 |
min => 0, |
| 53 |
max => $self->{result_values}->{sessions_max} != 0 ? $self->{result_values}->{sessions_max} : undef |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
sub custom_active_output { |
| 58 |
my ($self, %options) = @_; |
| 59 |
|
| 60 |
return sprintf('active: %s (%s)', |
| 61 |
$self->{result_values}->{sessions_active}, |
| 62 |
$self->{result_values}->{sessions_max} != 0 ? $self->{result_values}->{sessions_max} : '-' |
| 63 |
); |
| 64 |
} |
| 65 |
|
| 66 |
sub prefix_global_output { |
| 67 |
my ($self, %options) = @_; |
| 68 |
|
| 69 |
return "Sessions "; |
| 70 |
} |
| 71 |
|
| 72 |
sub prefix_vsys_output { |
| 73 |
my ($self, %options) = @_; |
| 74 |
|
| 75 |
return "Vsys '" . $options{instance_value}->{display} . "' sessions "; |
| 76 |
} |
| 77 |
|
| 78 |
sub set_counters { |
| 79 |
my ($self, %options) = @_; |
| 80 |
|
| 81 |
$self->{maps_counters_type} = [ |
| 82 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, |
| 83 |
{ name => 'vsys', type => 1, cb_prefix_output => 'prefix_vsys_output', message_multiple => 'Vsys sessions metrics are OK', skipped_code => { -10 => 1 } }, |
| 84 |
]; |
| 85 |
$self->{maps_counters}->{global} = [ |
| 86 |
{ label => 'active', nlabel => 'sessions.active.count', set => { |
| 87 |
key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' } ], |
| 88 |
closure_custom_output => $self->can('custom_active_output'), |
| 89 |
closure_custom_perfdata => $self->can('custom_active_perfdata') |
| 90 |
} |
| 91 |
}, |
| 92 |
{ label => 'active-prct', nlabel => 'sessions.active.percentage', display_ok => 0, set => { |
| 93 |
key_values => [ { name => 'sessions_active_prct' } ], |
| 94 |
output_template => 'active: %.2f %%', |
| 95 |
perfdatas => [ |
| 96 |
{ label => 'active_prct', value => 'sessions_active_prct', template => '%.2f', unit => '%', |
| 97 |
min => 0, max => 100 } |
| 98 |
] |
| 99 |
} |
| 100 |
}, |
| 101 |
{ label => 'active-tcp', nlabel => 'sessions.active.tcp.count', set => { |
| 102 |
key_values => [ { name => 'panSessionActiveTcp' } ], |
| 103 |
output_template => 'active TCP: %s', |
| 104 |
perfdatas => [ |
| 105 |
{ label => 'active_tcp', value => 'panSessionActiveTcp', template => '%s', min => 0 } |
| 106 |
] |
| 107 |
} |
| 108 |
}, |
| 109 |
{ label => 'active-udp', nlabel => 'sessions.active.udp.count', set => { |
| 110 |
key_values => [ { name => 'panSessionActiveUdp' } ], |
| 111 |
output_template => 'active UDP: %s', |
| 112 |
perfdatas => [ |
| 113 |
{ label => 'active_udp', value => 'panSessionActiveUdp', template => '%s', min => 0 } |
| 114 |
] |
| 115 |
} |
| 116 |
}, |
| 117 |
{ label => 'active-icmp', nlabel => 'sessions.active.icmp.count', set => { |
| 118 |
key_values => [ { name => 'panSessionActiveICMP' } ], |
| 119 |
output_template => 'active ICMP: %s', |
| 120 |
perfdatas => [ |
| 121 |
{ label => 'active_icmp', value => 'panSessionActiveICMP', template => '%s', min => 0 } |
| 122 |
] |
| 123 |
} |
| 124 |
} |
| 125 |
]; |
| 126 |
|
| 127 |
$self->{maps_counters}->{vsys} = [ |
| 128 |
{ label => 'vsys-active', nlabel => 'vsys.sessions.active.count', set => { |
| 129 |
key_values => [ { name => 'sessions_active' }, { name => 'sessions_max' }, { name => 'display' } ], |
| 130 |
closure_custom_output => $self->can('custom_active_output'), |
| 131 |
closure_custom_perfdata => $self->can('custom_vsys_active_perfdata') |
| 132 |
} |
| 133 |
}, |
| 134 |
{ label => 'vsys-active-prct', nlabel => 'vsys.sessions.active.percentage', display_ok => 0, set => { |
| 135 |
key_values => [ { name => 'sessions_active_prct' } ], |
| 136 |
output_template => 'active: %.2f %%', |
| 137 |
perfdatas => [ |
| 138 |
{ label => 'active_prct', value => 'sessions_active_prct', template => '%.2f', unit => '%', |
| 139 |
min => 0, max => 100 } |
| 140 |
] |
| 141 |
} |
| 142 |
}, |
| 143 |
{ label => 'vsys-active-tcp', nlabel => 'vsys.sessions.active.tcp.count', set => { |
| 144 |
key_values => [ { name => 'panVsysActiveTcpCps' }, { name => 'display' } ], |
| 145 |
output_template => 'active TCP: %s', |
| 146 |
perfdatas => [ |
| 147 |
{ label => 'active_tcp', value => 'panVsysActiveTcpCps', template => '%s', |
| 148 |
label_extra_instance => 1, min => 0 } |
| 149 |
] |
| 150 |
} |
| 151 |
}, |
| 152 |
{ label => 'vsys-active-udp', nlabel => 'vsys.sessions.active.udp.count', set => { |
| 153 |
key_values => [ { name => 'panVsysActiveUdpCps' }, { name => 'display' } ], |
| 154 |
output_template => 'active UDP: %s', |
| 155 |
perfdatas => [ |
| 156 |
{ label => 'active_udp', value => 'panVsysActiveUdpCps', template => '%s', |
| 157 |
label_extra_instance => 1, min => 0 } |
| 158 |
] |
| 159 |
} |
| 160 |
}, |
| 161 |
{ label => 'vsys-active-other', nlabel => 'vsys.sessions.active.other.count', set => { |
| 162 |
key_values => [ { name => 'panVsysActiveOtherIpCps' }, { name => 'display' } ], |
| 163 |
output_template => 'other: %s', |
| 164 |
perfdatas => [ |
| 165 |
{ label => 'active_other', value => 'panVsysActiveOtherIpCps', template => '%s', |
| 166 |
label_extra_instance => 1, min => 0 } |
| 167 |
] |
| 168 |
} |
| 169 |
} |
| 170 |
]; |
| 171 |
} |
| 172 |
|
| 173 |
sub new { |
| 174 |
my ($class, %options) = @_; |
| 175 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 176 |
bless $self, $class; |
| 177 |
|
| 178 |
$options{options}->add_options(arguments => { |
| 179 |
'add-vsys' => { name => 'add_vsys' }, |
| 180 |
'filter-vsys-name:s' => { name => 'filter_vsys_name' } |
| 181 |
}); |
| 182 |
|
| 183 |
return $self; |
| 184 |
} |
| 185 |
|
| 186 |
|
| 187 |
my $mapping_sessions = { |
| 188 |
sessions_max => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' }, # panSessionMax |
| 189 |
sessions_active => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' }, # panSessionActive |
| 190 |
panSessionActiveTcp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.4' }, |
| 191 |
panSessionActiveUdp => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.5' }, |
| 192 |
panSessionActiveICMP => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.6' }, |
| 193 |
panSessionSslProxyUtilization => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.8' } |
| 194 |
}; |
| 195 |
my $mapping_vsys = { |
| 196 |
display => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.2' }, # panVsysName |
| 197 |
sessions_active => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.4' }, # panVsysActiveSessions |
| 198 |
sessions_max => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.5' }, # panVsysMaxSessions |
| 199 |
panVsysActiveTcpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.6' }, |
| 200 |
panVsysActiveUdpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.7' }, |
| 201 |
panVsysActiveOtherIpCps => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.9.1.8' } |
| 202 |
}; |
| 203 |
|
| 204 |
sub add_vsys { |
| 205 |
my ($self, %options) = @_; |
| 206 |
|
| 207 |
my $oid_panVsysEntry = '.1.3.6.1.4.1.25461.2.1.2.3.9.1'; |
| 208 |
my $snmp_result = $options{snmp}->get_table( |
| 209 |
oid => $oid_panVsysEntry, |
| 210 |
nothing_quit => 1 |
| 211 |
); |
| 212 |
|
| 213 |
foreach my $oid (keys %$snmp_result) { |
| 214 |
next if ($oid !~ /^$mapping_vsys->{display}->{oid}\.(.*)$/); |
| 215 |
my $instance = $1; |
| 216 |
|
| 217 |
my $result = $options{snmp}->map_instance(mapping => $mapping_vsys, results => $snmp_result, instance => $instance); |
| 218 |
if (defined($self->{option_results}->{filter_vsys_name}) && $self->{option_results}->{filter_vsys_name} ne '' && |
| 219 |
$result->{display} !~ /$self->{option_results}->{filter_vsys_name}/) { |
| 220 |
$self->{output}->output_add(long_msg => "skipping '" . $result->{display} . "'.", debug => 1); |
| 221 |
next; |
| 222 |
} |
| 223 |
|
| 224 |
$self->{vsys}->{$result->{display}} = $result; |
| 225 |
$self->{vsys}->{$result->{display}}->{sessions_max} = 0 if (!defined($result->{sessions_max})); |
| 226 |
$self->{vsys}->{$result->{display}}->{sessions_active_prct} = $result->{sessions_active} * 100 / $self->{vsys}->{$result->{display}}->{sessions_max} |
| 227 |
if ($self->{vsys}->{$result->{display}}->{sessions_max} != 0); |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
sub manage_selection { |
| 232 |
my ($self, %options) = @_; |
| 233 |
|
| 234 |
my $snmp_result = $options{snmp}->get_leef( |
| 235 |
oids => [ map($_->{oid} . '.0', values(%$mapping_sessions)) ], |
| 236 |
nothing_quit => 1 |
| 237 |
); |
| 238 |
$self->{global} = $options{snmp}->map_instance(mapping => $mapping_sessions, results => $snmp_result, instance => '0'); |
| 239 |
$self->{global}->{sessions_max} = 0 if (!defined($self->{global}->{sessions_max})); |
| 240 |
$self->{global}->{sessions_active_prct} = $self->{global}->{sessions_active} * 100 / $self->{global}->{sessions_max} |
| 241 |
if ($self->{global}->{sessions_max} != 0); |
| 242 |
|
| 243 |
$self->add_vsys(snmp => $options{snmp}) |
| 244 |
if (defined($self->{option_results}->{add_vsys})); |
| 245 |
} |
| 246 |
|
| 247 |
1; |
| 248 |
|
| 249 |
__END__ |
| 250 |
|
| 251 |
=head1 MODE |
| 252 |
|
| 253 |
Check sessions. |
| 254 |
|
| 255 |
=over 8 |
| 256 |
|
| 257 |
=item B<--add-vsys> |
| 258 |
|
| 259 |
Monitor virtual systems. |
| 260 |
|
| 261 |
=item B<--filter-vsys-name> |
| 262 |
|
| 263 |
Filter virtual systems by name (can be a regexp). |
| 264 |
|
| 265 |
=item B<--warning-*> B<--critical-*> |
| 266 |
|
| 267 |
Thresholds. |
| 268 |
Global: 'active', 'active-prct', (%), 'active-tcp', 'active-udp', 'active-icmp', |
| 269 |
Per vsys: 'vsys-active', 'vsys-active-prct' (%), 'vsys-active-tcp' 'vsys-active-udp' 'vsys-active-other'. |
| 270 |
|
| 271 |
=back |
| 272 |
|
| 273 |
=cut |