centreon-plugins/network/watchguard/snmp/mode/policyusage.pm

185 lines
6.4 KiB
Perl
Raw Normal View History

2017-03-13 14:52:27 +01:00
#
2021-02-08 09:55:50 +01:00
# Copyright 2021 Centreon (http://www.centreon.com/)
2017-03-13 14:52:27 +01:00
#
# 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::watchguard::snmp::mode::policyusage;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
use Digest::MD5 qw(md5_hex);
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'policy', type => 1, cb_prefix_output => 'prefix_policy_output', message_multiple => 'All policies are ok' }
];
$self->{maps_counters}->{policy} = [
2020-07-27 10:32:22 +02:00
{ label => 'current-connections', nlabel => 'policy.connections.current.count', set => {
2017-03-13 14:52:27 +01:00
key_values => [ { name => 'wgPolicyCurrActiveConns' }, { name => 'display' } ],
2020-07-27 10:32:22 +02:00
output_template => 'current connections: %s',
2017-03-13 14:52:27 +01:00
perfdatas => [
2020-07-27 10:32:22 +02:00
{ label => 'current_connections', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
2017-03-13 14:52:27 +01:00
}
},
2020-07-27 10:32:22 +02:00
{ label => 'total-connections', nlabel => 'policy.connections.total.count', set => {
2017-03-13 14:52:27 +01:00
key_values => [ { name => 'wgPolicyActiveStreams', diff => 1 }, { name => 'display' } ],
2020-07-27 10:32:22 +02:00
output_template => 'total connections: %s',
2017-03-13 14:52:27 +01:00
perfdatas => [
2020-07-27 10:32:22 +02:00
{ label => 'total_connections', template => '%s', min => 0, label_extra_instance => 1, instance_use => 'display' }
]
2017-03-13 14:52:27 +01:00
}
},
2020-07-27 10:32:22 +02:00
{ label => 'l3-traffic', nlabel => 'policy.traffic.l3.bitspersecond', set => {
2020-05-13 14:18:28 +02:00
key_values => [ { name => 'wgPolicyL3PackageBytes', per_second => 1 }, { name => 'display' } ],
2020-07-27 10:32:22 +02:00
output_template => 'L3 traffic: %s %s/s',
2020-05-13 14:18:28 +02:00
output_change_bytes => 2,
2017-03-13 14:52:27 +01:00
perfdatas => [
2020-07-27 10:32:22 +02:00
{ label => 'traffic_l3', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
2017-03-13 14:52:27 +01:00
}
},
2020-07-27 10:32:22 +02:00
{ label => 'l2-traffic', nlabel => 'policy.traffic.l2.bitspersecond', set => {
2020-05-13 14:18:28 +02:00
key_values => [ { name => 'wgPolicyL2PackageBytes', per_second => 1 }, { name => 'display' } ],
2020-07-27 10:32:22 +02:00
output_template => 'L2 traffic: %s %s/s',
2020-05-13 14:18:28 +02:00
output_change_bytes => 2,
2017-03-13 14:52:27 +01:00
perfdatas => [
2020-07-27 10:32:22 +02:00
{ label => 'traffic_l2', template => '%.2f', min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display' }
]
2017-03-13 14:52:27 +01:00
}
2020-07-27 10:32:22 +02:00
}
2017-03-13 14:52:27 +01:00
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
2020-05-13 14:18:28 +02:00
$options{options}->add_options(arguments => {
'filter-name:s' => { name => 'filter_name' }
});
2017-03-13 14:52:27 +01:00
return $self;
}
sub prefix_policy_output {
my ($self, %options) = @_;
return "Policy '" . $options{instance_value}->{display} . "' ";
}
my $mapping = {
wgPolicyName => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.2' },
wgPolicyL3PackageBytes => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.3' },
wgPolicyActiveStreams => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.12' },
wgPolicyCurrActiveConns => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.18' },
2020-07-27 10:32:22 +02:00
wgPolicyL2PackageBytes => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.19' }
2017-03-13 14:52:27 +01:00
};
my $oid_wgPolicyEntry = '.1.3.6.1.4.1.3097.4.2.2.1';
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
$self->{policy} = {};
2020-07-27 10:32:22 +02:00
my $snmp_result = $options{snmp}->get_table(
oid => $oid_wgPolicyEntry,
nothing_quit => 1
);
2017-03-13 14:52:27 +01:00
foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{wgPolicyName}->{oid}\.(.*)$/);
my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{wgPolicyName} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping '" . $result->{wgPolicyName} . "': no matching filter.", debug => 1);
next;
}
2020-07-24 15:24:22 +02:00
# Must be a Watchguard bug, where wgPolicyCurrActiveConns sporadically returns 2^321...
if ($result->{wgPolicyCurrActiveConns} == 4294967295) {
$result->{wgPolicyCurrActiveConns} = 0;
}
2020-07-27 10:32:22 +02:00
$result->{wgPolicyL3PackageBytes} *= 8;
$result->{wgPolicyL2PackageBytes} *= 8;
$self->{policy}->{$instance} = {
display => $result->{wgPolicyName},
2017-03-13 14:52:27 +01:00
%$result
};
}
if (scalar(keys %{$self->{policy}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No policy found.");
$self->{output}->option_exit();
}
2020-07-27 10:32:22 +02:00
$self->{cache_name} = 'watchguard_' . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' .
2017-03-17 13:32:56 +01:00
(defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' .
2017-05-15 11:16:36 +02:00
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
2017-03-13 14:52:27 +01:00
}
1;
__END__
=head1 MODE
Check policy usage.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^total-connections$'
=item B<--filter-name>
Filter policy name (can be a regexp).
=item B<--warning-*>
Threshold warning.
Can be: 'total-connections', 'current-connections'
'l3-traffic' (b/s), 'l2-traffic' (b/s).
=item B<--critical-*>
Threshold critical.
Can be: 'total-connections', 'current-connections'
'l3-traffic' (b/s), 'l2-traffic' (b/s).
=back
=cut