refactorize pfsense

This commit is contained in:
qgarnier 2017-07-26 15:22:29 +02:00
parent 73722d130d
commit f7194a53cd
7 changed files with 467 additions and 429 deletions

View File

@ -1,288 +0,0 @@
#
# Copyright 2017 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 apps::pfsense::snmp::mode::blockedpackets;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use POSIX;
use centreon::plugins::statefile;
use Digest::MD5 qw(md5_hex);
my $oid_pfsenseInterfaceName = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning-in:s" => { name => 'warning_in', },
"warning-out:s" => { name => 'warning_out', },
"critical-in:s" => { name => 'critical_in', },
"critical-out:s" => { name => 'critical_out', },
"name" => { name => 'use_name' },
"interface:s" => { name => 'interface' },
"regexp" => { name => 'use_regexp' },
"regexp-isensitive" => { name => 'use_regexpi' },
});
$self->{interface_id_selected} = [];
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning-in', value => $self->{option_results}->{warning_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning in threshold '" . $self->{option_results}->{warning_in} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'warning-out', value => $self->{option_results}->{warning_out})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning out threshold '" . $self->{option_results}->{warning_out} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-in', value => $self->{option_results}->{critical_in})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical in threshold '" . $self->{option_results}->{critical_in} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical-out', value => $self->{option_results}->{critical_out})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical out threshold '" . $self->{option_results}->{critical_out} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
if ($self->{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
$self->{output}->option_exit();
}
$self->manage_selection();
my $oid_pfsenseBlockedInPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.12';
my $oid_pfsenseBlockedOutPackets = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.14';
my ($result, $valueIn, $valueOut);
my $new_datas = {};
$self->{statefile_value}->read(statefile => "pfsense_" . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode} . '_' . (defined($self->{option_results}->{interface}) ? md5_hex($self->{option_results}->{interface}) : md5_hex('all')));
$self->{snmp}->load(oids => [$oid_pfsenseBlockedInPackets, $oid_pfsenseBlockedOutPackets],
instances => $self->{interface_id_selected});
$result = $self->{snmp}->get_leef();
$new_datas->{last_timestamp} = time();
my $old_timestamp;
if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp})) {
$self->{output}->output_add(severity => 'OK',
short_msg => 'All interfaces are ok.');
}
foreach (sort @{$self->{interface_id_selected}}) {
my $display_value = $self->{names}->{$_};
#################
# New values
#################
$new_datas->{'in_blocked_' . $_} = $result->{$oid_pfsenseBlockedInPackets . "." . $_};
$new_datas->{'out_blocked_' . $_} = $result->{$oid_pfsenseBlockedOutPackets . "." . $_};
################
# Old values
################
my @getting = ('in_blocked', 'out_blocked');
my $old_datas = {};
$old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
foreach my $key (@getting) {
$old_datas->{$key} = $self->{statefile_value}->get(name => $key . '_' . $_);
if (!defined($old_datas->{$key}) || $new_datas->{$key . '_' . $_} < $old_datas->{$key}) {
# We set 0. Has reboot.
$old_datas->{$key} = 0;
}
}
if (!defined($old_timestamp)) {
next;
}
my $time_delta = $new_datas->{last_timestamp} - $old_timestamp;
if ($time_delta <= 0) {
# At least one second. two fast calls ;)
$time_delta = 1;
}
###########
my $in_blocked_absolute = $new_datas->{'in_blocked_' . $_} - $old_datas->{in_blocked};
my $out_blocked_absolute = $new_datas->{'out_blocked_' . $_} - $old_datas->{out_blocked};
my $in_blocked_absolute_per_sec = $in_blocked_absolute / $time_delta;
my $out_blocked_absolute_per_sec = $out_blocked_absolute / $time_delta;
###############
# Manage Output
###############
my $exit1 = $self->{perfdata}->threshold_check(value => $in_blocked_absolute_per_sec, threshold => [ { label => 'critical-in', 'exit_litteral' => 'critical' }, { label => 'warning-in', exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $out_blocked_absolute_per_sec, threshold => [ { label => 'critical-out', 'exit_litteral' => 'critical' }, { label => 'warning-out', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
$self->{output}->output_add(long_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
$in_blocked_absolute_per_sec, $in_blocked_absolute,
$out_blocked_absolute_per_sec, $out_blocked_absolute));
if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{interface}) && !defined($self->{option_results}->{use_regexp}))) {
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("Interface '%s' Packets In Blocked : %.2f /s [%i packets], Out Blocked : %.2f /s [%i packets]", $display_value,
$in_blocked_absolute_per_sec, $in_blocked_absolute,
$out_blocked_absolute_per_sec, $out_blocked_absolute));
}
my $extra_label = '';
$extra_label = '_' . $display_value if (!defined($self->{option_results}->{interface}) || defined($self->{option_results}->{use_regexp}));
$self->{output}->perfdata_add(label => 'packets_blocked_in_per_sec' . $extra_label,
value => sprintf("%.2f", $in_blocked_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-in'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-in'),
min => 0);
$self->{output}->perfdata_add(label => 'packets_blocked_out_per_sec' . $extra_label,
value => sprintf("%.2f", $out_blocked_absolute_per_sec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-out'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-out'),
min => 0);
}
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
}
$self->{output}->display();
$self->{output}->exit();
}
sub manage_selection {
my ($self, %options) = @_;
my $all_ids = [];
$self->{names} = {};
my $result = $self->{snmp}->get_table(oid => $oid_pfsenseInterfaceName, nothing_quit => 1);
foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) {
next if ($key !~ /\.([0-9]+)$/);
push @{$all_ids}, $1;
$self->{names}->{$1} = $self->{output}->to_utf8($result->{$key});
}
if (!defined($self->{option_results}->{use_name}) && defined($self->{option_results}->{interface})) {
# get by ID
push @{$self->{interface_id_selected}}, $self->{option_results}->{interface};
if (!defined($self->{names}->{$self->{option_results}->{interface}})) {
$self->{output}->add_option_msg(short_msg => "No interface found for id '" . $self->{option_results}->{interface} . "'.");
$self->{output}->option_exit();
}
} else {
foreach my $i (@{$all_ids}) {
my $filter_name = $self->{names}->{$i};
next if (!defined($filter_name));
if (!defined($self->{option_results}->{interface})) {
push @{$self->{interface_id_selected}}, $i;
next;
}
if (defined($self->{option_results}->{use_regexp}) && defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/i) {
push @{$self->{interface_id_selected}}, $i;
}
if (defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name =~ /$self->{option_results}->{interface}/) {
push @{$self->{interface_id_selected}}, $i;
}
if (!defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $filter_name eq $self->{option_results}->{interface}) {
push @{$self->{interface_id_selected}}, $i;
}
}
if (scalar(@{$self->{interface_id_selected}}) <= 0) {
if (defined($self->{option_results}->{interface})) {
$self->{output}->add_option_msg(short_msg => "No interface found for name '" . $self->{option_results}->{interface} . "' (maybe you should reload cache file).");
} else {
$self->{output}->add_option_msg(short_msg => "No interface found (maybe you should reload cache file).");
}
$self->{output}->option_exit();
}
}
}
1;
__END__
=head1 MODE
Check pfSense blocked packets.
=over 8
=item B<--warning-in>
Threshold warning for input blocked packets.
=item B<--warning-out>
Threshold warning for output blocked packets.
=item B<--critical-in>
Threshold critical for input blocked packets.
=item B<--critical-out>
Threshold critical for output blocked packets.
=item B<--interface>
Set the interface (number expected) ex: 1, 2,... (empty means 'check all interface').
=item B<--name>
Allows to use interface name with option --interface instead of interface oid index.
=item B<--regexp>
Allows to use regexp to filter interfaces (with option --name).
=item B<--regexp-isensitive>
Allows to use regexp non case-sensitive (with --regexp).
=back
=cut

View File

@ -0,0 +1,112 @@
#
# Copyright 2017 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 apps::pfsense::snmp::mode::listpfinterfaces;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
my $oid_pfInterfacesIfDescr = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub manage_selection {
my ($self, %options) = @_;
my $snmp_result = $self->{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1);
$self->{pfint} = {};
foreach my $oid (keys %{$snmp_result}) {
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$snmp_result->{$oid} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping pfInteface '" . $snmp_result->{$oid} . "'.", debug => 1);
next;
}
$self->{pfint}->{$snmp_result->{$oid}} = { name => $snmp_result->{$oid} };
}
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection();
foreach my $name (sort keys %{$self->{pfint}}) {
$self->{output}->output_add(long_msg => "'" . $name . "'");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List pfIntefaces:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
sub disco_format {
my ($self, %options) = @_;
$self->{output}->add_disco_format(elements => ['name']);
}
sub disco_show {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->manage_selection();
foreach my $name (sort keys %{$self->{pfint}}) {
$self->{output}->add_disco_entry(name => $name);
}
}
1;
__END__
=head1 MODE
List pfInteface.
=over 8
=item B<--filter-name>
Filter by pfinterface name.
=back
=cut

View File

@ -1,130 +0,0 @@
#
# Copyright 2017 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 apps::pfsense::snmp::mode::memorydroppedpackets;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use POSIX;
use centreon::plugins::statefile;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
});
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_value}->check_options(%options);
}
sub run {
my ($self, %options) = @_;
$self->{snmp} = $options{snmp};
$self->{hostname} = $self->{snmp}->get_hostname();
$self->{snmp_port} = $self->{snmp}->get_port();
my $oid_pfsenseMemDropPackets = '.1.3.6.1.4.1.12325.1.200.1.2.6.0';
my ($result, $value);
$result = $self->{snmp}->get_leef(oids => [ $oid_pfsenseMemDropPackets ], nothing_quit => 1);
$value = $result->{$oid_pfsenseMemDropPackets};
$self->{statefile_value}->read(statefile => 'pfsense_' . $self->{hostname} . '_' . $self->{snmp_port} . '_' . $self->{mode});
my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp');
my $old_memDropPackets = $self->{statefile_value}->get(name => 'memDropPackets');
my $new_datas = {};
$new_datas->{last_timestamp} = time();
$new_datas->{memDropPackets} = $value;
$self->{statefile_value}->write(data => $new_datas);
if (!defined($old_timestamp) || !defined($old_memDropPackets)) {
$self->{output}->output_add(severity => 'OK',
short_msg => "Buffer creation...");
$self->{output}->display();
$self->{output}->exit();
}
$old_memDropPackets = 0 if ($old_memDropPackets > $new_datas->{memDropPackets});
my $delta_time = $new_datas->{last_timestamp} - $old_timestamp;
$delta_time = 1 if ($delta_time == 0);
my $memDropPacketsPerSec = ($new_datas->{memDropPackets} - $old_memDropPackets) / $delta_time;
my $exit_code = $self->{perfdata}->threshold_check(value => $memDropPacketsPerSec,
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
$self->{output}->perfdata_add(label => 'dropped_packets_Per_Sec',
value => sprintf("%.2f", $memDropPacketsPerSec),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("Dropped packets due to memory limitations : %.2f /s",
$memDropPacketsPerSec));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Check number of packets per second dropped due to memory limitations.
=over 8
=item B<--warning>
Threshold warning for dropped packets in packets per second.
=item B<--critical>
Threshold critical for dropped packets in packets per second.
=back
=cut

View File

@ -0,0 +1,167 @@
#
# Copyright 2017 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 apps::pfsense::snmp::mode::packetstats;
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 => 'global', type => 0, message_separator => ' - ' },
];
$self->{maps_counters}->{global} = [
{ label => 'match', set => {
key_values => [ { name => 'pfCounterMatch', diff => 1 } ],
per_second => 1,
output_template => 'Packets Matched Filter Rule : %.2f/s',
perfdatas => [
{ label => 'match', value => 'pfCounterMatch_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'badoffset', set => {
key_values => [ { name => 'pfCounterBadOffset', diff => 1 } ],
per_second => 1,
output_template => 'Bad Offset Packets : %.2f/s',
perfdatas => [
{ label => 'bad_offset', value => 'pfCounterBadOffset_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'fragment', set => {
key_values => [ { name => 'pfCounterFragment', diff => 1 } ],
per_second => 1,
output_template => 'Fragmented Packets : %.2f/s',
perfdatas => [
{ label => 'fragment', value => 'pfCounterFragment_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'short', set => {
key_values => [ { name => 'pfCounterShort', diff => 1 } ],
per_second => 1,
output_template => 'Short Packets : %.2f/s',
perfdatas => [
{ label => 'short', value => 'pfCounterShort_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'normalize', set => {
key_values => [ { name => 'pfCounterNormalize', diff => 1 } ],
per_second => 1,
output_template => 'Normalized Packets : %.2f/s',
perfdatas => [
{ label => 'normalize', value => 'pfCounterNormalize_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
{ label => 'memdrop', set => {
key_values => [ { name => 'pfCounterMemDrop', diff => 1 } ],
per_second => 1,
output_template => 'Dropped Packets Due To Memory : %.2f/s',
perfdatas => [
{ label => 'memdrop', value => 'pfCounterMemDrop_per_second', template => '%.2f', unit => '/s',
min => 0 },
],
}
},
];
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
});
return $self;
}
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
$self->{output}->option_exit();
}
my %oids = (
pfCounterMatch => '.1.3.6.1.4.1.12325.1.200.1.2.1.0',
pfCounterBadOffset => '.1.3.6.1.4.1.12325.1.200.1.2.2.0',
pfCounterFragment => '.1.3.6.1.4.1.12325.1.200.1.2.3.0',
pfCounterShort => '.1.3.6.1.4.1.12325.1.200.1.2.4.0',
pfCounterNormalize => '.1.3.6.1.4.1.12325.1.200.1.2.5.0',
pfCounterMemDrop => '.1.3.6.1.4.1.12325.1.200.1.2.6.0',
);
my $snmp_result = $options{snmp}->get_leef(oids => [values %oids], nothing_quit => 1);
$self->{global} = {};
foreach (keys %oids) {
$self->{global}->{$_} = $snmp_result->{$oids{$_}};
}
$self->{cache_name} = "pfsense_" . $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 global packet statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^match$'
=item B<--warning-*>
Threshold warning.
Can be: 'match', 'badoffset', 'fragment', 'short',
'normalize', 'memdrop'.
=item B<--critical-*>
Threshold critical.
Can be: 'match', 'badoffset', 'fragment', 'short',
'normalize', 'memdrop'.
=back
=cut

View File

@ -0,0 +1,181 @@
#
# Copyright 2017 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 apps::pfsense::snmp::mode::pfinterfaces;
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 => 'pfint', type => 1, cb_prefix_output => 'prefix_pfint_output', message_multiple => 'All pfInterfaes are ok' }
];
$self->{maps_counters}->{pfint} = [
{ label => 'traffic-in-pass', set => {
key_values => [ { name => 'pfInterfacesIf4BytesInPass', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic In Pass : %s %s/s',
perfdatas => [
{ label => 'traffic_in_pass', value => 'pfInterfacesIf4BytesInPass_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-out-pass', set => {
key_values => [ { name => 'pfInterfacesIf4BytesOutPass', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic Out Pass : %s %s/s',
perfdatas => [
{ label => 'traffic_out_pass', value => 'pfInterfacesIf4BytesOutPass_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-in-block', set => {
key_values => [ { name => 'pfInterfacesIf4BytesInBlock', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic In Block : %s %s/s',
perfdatas => [
{ label => 'traffic_in_block', value => 'pfInterfacesIf4BytesInBlock_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'traffic-out-block', set => {
key_values => [ { name => 'pfInterfacesIf4BytesOutBlock', diff => 1 }, { name => 'display' } ],
per_second => 1, output_change_bytes => 2,
output_template => 'Traffic Out Block : %s %s/s',
perfdatas => [
{ label => 'traffic_out_block', value => 'pfInterfacesIf4BytesOutBlock_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
sub prefix_pfint_output {
my ($self, %options) = @_;
return "pfInterface '" . $options{instance_value}->{display} . "' ";
}
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1);
bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments =>
{
"filter-name:s" => { name => 'filter_name' },
});
return $self;
}
my $oid_pfInterfacesIfDescr = '.1.3.6.1.4.1.12325.1.200.1.8.2.1.2';
my $mapping = {
pfInterfacesIf4BytesInPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.7' },
pfInterfacesIf4BytesInBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.8' },
pfInterfacesIf4BytesOutPass => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.9' },
pfInterfacesIf4BytesOutBlock => { oid => '.1.3.6.1.4.1.12325.1.200.1.8.2.1.10' },
};
sub manage_selection {
my ($self, %options) = @_;
if ($options{snmp}->is_snmpv1()) {
$self->{output}->add_option_msg(short_msg => "Can't check SNMP 64 bits counters with SNMPv1.");
$self->{output}->option_exit();
}
my $snmp_result = $options{snmp}->get_table(oid => $oid_pfInterfacesIfDescr, nothing_quit => 1);
$self->{pfint} = {};
foreach my $oid (keys %{$snmp_result}) {
$oid =~ /^$oid_pfInterfacesIfDescr\.(.*)$/;
my $instance = $1;
my $name = $snmp_result->{$oid};
if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$name !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping pfInterface '" . $name . "'.", debug => 1);
next;
}
$self->{pfint}->{$instance} = { display => $name };
}
$options{snmp}->load(oids => [$mapping->{pfInterfacesIf4BytesInPass}->{oid}, $mapping->{pfInterfacesIf4BytesOutPass}->{oid},
$mapping->{pfInterfacesIf4BytesInBlock}->{oid}, $mapping->{pfInterfacesIf4BytesOutBlock}->{oid},
],
instances => [keys %{$self->{pfint}}], instance_regexp => '^(.*)$');
$snmp_result = $options{snmp}->get_leef(nothing_quit => 1);
foreach my $instance (keys %{$self->{pfint}}) {
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
foreach (keys %$mapping) {
$self->{pfint}->{$instance}->{$_} = $result->{$_} * 8;
}
}
if (scalar(keys %{$self->{pfint}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No pfInterface found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "pfsense_" . $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')) . '_' .
(defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all'));
}
1;
__END__
=head1 MODE
Check pfInterfaces.
=over 8
=item B<--warning-*>
Threshold warning.
Can be: 'traffic-in-pass', 'traffic-out-pass', 'traffic-in-block', 'traffic-out-block'.
=item B<--critical-*>
Threshold critical.
Can be: 'traffic-in-pass', 'traffic-out-pass', 'traffic-in-block', 'traffic-out-block'.
=item B<--filter-name>
Filter by interface name (can be a regexp).
=back
=cut

View File

@ -24,7 +24,7 @@ use base qw(centreon::plugins::mode);
use strict;
use warnings;
use POSIX;
use centreon::plugins::misc;
sub new {
my ($class, %options) = @_;
@ -36,7 +36,6 @@ sub new {
{
"warning:s" => { name => 'warning', },
"critical:s" => { name => 'critical', },
"seconds" => { name => 'seconds', },
});
return $self;
@ -78,7 +77,7 @@ sub run {
min => 0);
$self->{output}->output_add(severity => $exit_code,
short_msg => sprintf("PfSense running since : %s",
defined($self->{option_results}->{seconds}) ? floor($valueRuntime / 100) . " seconds" : floor($valueRuntime / 86400 / 100) . " days" ));
centreon::plugins::misc::change_seconds(value => floor($valueRuntime / 100))));
} else {
$self->{output}->perfdata_add(label => 'runtime', unit => 's',
@ -87,7 +86,7 @@ sub run {
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
min => 0);
$self->{output}->output_add(severity => 'critical',
short_msg => sprintf("PfSense not running."));
short_msg => 'PfSense not running');
}
$self->{output}->display();
@ -112,10 +111,6 @@ Threshold warning in seconds.
Threshold critical in seconds.
=item B<--seconds>
Display runtime in seconds.
=back
=cut

View File

@ -31,9 +31,10 @@ sub new {
$self->{version} = '0.1';
%{$self->{modes}} = (
'runtime' => 'apps::pfsense::snmp::mode::runtime',
'memory-dropped-packets' => 'apps::pfsense::snmp::mode::memorydroppedpackets',
'blocked-packets' => 'apps::pfsense::snmp::mode::blockedpackets',
'list-pfinterfaces' => 'apps::pfsense::snmp::mode::listpfinterfaces',
'packet-stats' => 'apps::pfsense::snmp::mode::packetstats',
'pfinterfaces' => 'apps::pfsense::snmp::mode::pfinterfaces',
'runtime' => 'apps::pfsense::snmp::mode::runtime',
);
return $self;