+ Fix #98 : add watchguard snmp plugin

This commit is contained in:
garnier-quentin 2017-03-13 14:52:27 +01:00
parent 6d42b3e179
commit cc881512e3
4 changed files with 500 additions and 0 deletions

View File

@ -0,0 +1,130 @@
#
# 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 network::watchguard::snmp::mode::cpu;
use base qw(centreon::plugins::templates::counter);
use strict;
use warnings;
sub set_counters {
my ($self, %options) = @_;
$self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' }
];
$self->{maps_counters}->{global} = [
{ label => '1min', set => {
key_values => [ { name => '1min' } ],
output_template => '1 minute : %.2f %%',
perfdatas => [
{ label => 'cpu_1min', value => '1min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '5min', set => {
key_values => [ { name => '5min' } ],
output_template => '5 minutes : %.2f %%',
perfdatas => [
{ label => 'cpu_5min', value => '5min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
{ label => '15min', set => {
key_values => [ { name => '15min' } ],
output_template => '5 minutes : %.2f %%',
perfdatas => [
{ label => 'cpu_5min', value => '15min_absolute', template => '%.2f',
min => 0, max => 100, unit => '%' },
],
}
},
];
}
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU ";
}
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 =>
{
});
return $self;
}
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();
}
my $oid_wgSystemCpuUtil1 = '.1.3.6.1.4.1.3097.6.3.77.0';
my $oid_wgSystemCpuUtil5 = '.1.3.6.1.4.1.3097.6.3.78.0';
my $oid_wgSystemCpuUtil15 = '.1.3.6.1.4.1.3097.6.3.79.0';
my $snmp_result = $options{snmp}->get_leef(oids => [
$oid_wgSystemCpuUtil1, $oid_wgSystemCpuUtil5, $oid_wgSystemCpuUtil15
], nothing_quit => 1);
$self->{global} = { '1min' => $snmp_result->{$oid_wgSystemCpuUtil1}, '5min' => $snmp_result->{$oid_wgSystemCpuUtil5}, '15min' => $snmp_result->{$oid_wgSystemCpuUtil15} };
}
1;
__END__
=head1 MODE
Check CPU usages.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^(1min|5min)$'
=item B<--warning-*>
Threshold warning.
Can be: '1min', '5min', '15min'.
=item B<--critical-*>
Threshold critical.
Can be: '1min', '5min', '15min'.
=back
=cut

View File

@ -0,0 +1,179 @@
#
# 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 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} = [
{ label => 'current-connections', set => {
key_values => [ { name => 'wgPolicyCurrActiveConns' }, { name => 'display' } ],
output_template => 'Current connections : %s',
perfdatas => [
{ label => 'current_connections', value => 'wgPolicyCurrActiveConns_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'total-connections', set => {
key_values => [ { name => 'wgPolicyActiveStreams', diff => 1 }, { name => 'display' } ],
output_template => 'Total connections : %s',
perfdatas => [
{ label => 'total_connections', value => 'wgPolicyActiveStreams_absolute', template => '%s',
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'l3-traffic', set => {
key_values => [ { name => 'wgPolicyL3PackageBytes', diff => 1 }, { name => 'display' } ],
output_template => 'L3 Traffic : %s %s/s',
per_second => 1, output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_l3', value => 'wgPolicyL3PackageBytes_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
{ label => 'l2-traffic', set => {
key_values => [ { name => 'wgPolicyL2PackageBytes', diff => 1 }, { name => 'display' } ],
output_template => 'L2 Traffic : %s %s/s',
per_second => 1, output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_l2', value => 'wgPolicyL2PackageBytes_per_second', template => '%.2f',
min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' },
],
}
},
];
}
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;
}
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' },
wgPolicyL2PackageBytes => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.19' },
};
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} = {};
my $snmp_result = $options{snmp}->get_table(oid => $oid_wgPolicyEntry,
nothing_quit => 1);
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;
}
$self->{policy}->{$instance} = { display => $result->{wgPolicyName},
%$result
};
}
if (scalar(keys %{$self->{policy}}) <= 0) {
$self->{output}->add_option_msg(short_msg => "No policy found.");
$self->{output}->option_exit();
}
$self->{cache_name} = "kemp_" . $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 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

View File

@ -0,0 +1,136 @@
#
# 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 network::watchguard::snmp::mode::system;
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 => 'connections', set => {
key_values => [ { name => 'connections' } ],
output_template => 'Current connections : %s',
perfdatas => [
{ label => 'current_connections', value => 'connections_absolute', template => '%s',
min => 0 },
],
}
},
{ label => 'in-traffic', set => {
key_values => [ { name => 'in_traffic', diff => 1 } ],
output_template => 'Traffic In : %s %s/s',
per_second => 1, output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_in', value => 'in_traffic_per_second', template => '%s',
min => 0, unit => 'b/s' },
],
}
},
{ label => 'out-traffic', set => {
key_values => [ { name => 'out_traffic', diff => 1 } ],
output_template => 'Traffic Out : %s %s/s',
per_second => 1, output_change_bytes => 2,
perfdatas => [
{ label => 'traffic_out', value => 'out_traffic_per_second', template => '%s',
min => 0, unit => 'b/s' },
],
}
},
];
}
sub prefix_cpu_output {
my ($self, %options) = @_;
return "CPU ";
}
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 => "Need to use SNMP v2c or v3.");
$self->{output}->option_exit();
}
my $oid_wgSystemTotalSendBytes = '.1.3.6.1.4.1.3097.6.3.8.0';
my $oid_wgSystemTotalRecvBytes = '.1.3.6.1.4.1.3097.6.3.9.0';
my $oid_wgSystemCurrActiveConns = '.1.3.6.1.4.1.3097.6.3.80.0';
my $snmp_result = $options{snmp}->get_leef(oids => [
$oid_wgSystemTotalSendBytes, $oid_wgSystemTotalRecvBytes, $oid_wgSystemCurrActiveConns
], nothing_quit => 1);
$self->{global} = { out_traffic => $snmp_result->{$oid_wgSystemTotalSendBytes},
in_traffic => $snmp_result->{$oid_wgSystemTotalRecvBytes}, connections => $snmp_result->{$oid_wgSystemCurrActiveConns} };
$self->{cache_name} = "watchguard_" . $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 system statistics.
=over 8
=item B<--filter-counters>
Only display some counters (regexp can be used).
Example: --filter-counters='^(connections)$'
=item B<--warning-*>
Threshold warning.
Can be: 'in-traffic', 'out-traffic', 'connections'.
=item B<--critical-*>
Threshold critical.
Can be: 'in-traffic', 'out-traffic', 'connections'.
=back
=cut

View File

@ -0,0 +1,55 @@
#
# 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 network::watchguard::snmp::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_snmp);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '1.0';
%{$self->{modes}} = (
'cpu' => 'network::watchguard::snmp::mode::cpu',
'hardware' => 'snmp_standard::mode::hardwaredevice',
'interfaces' => 'snmp_standard::mode::interfaces',
'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-storages' => 'snmp_standard::mode::liststorages',
'policy-usage' => 'network::watchguard::snmp::mode::policyusage',
'storage' => 'snmp_standard::mode::storage',
'system' => 'network::watchguard::snmp::mode::system',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Watchguard equipments in SNMP.
=cut