From f0b126bfccd7ff10c2cdd0f91b8f87c340f06336 Mon Sep 17 00:00:00 2001 From: cgagnaire Date: Wed, 2 May 2018 15:45:28 +0000 Subject: [PATCH] enhance sonicwall plugin (#978) --- network/sonicwall/snmp/mode/cpu.pm | 16 ++---- network/sonicwall/snmp/mode/memory.pm | 16 ++---- network/sonicwall/snmp/mode/vpn.pm | 71 +-------------------------- 3 files changed, 12 insertions(+), 91 deletions(-) diff --git a/network/sonicwall/snmp/mode/cpu.pm b/network/sonicwall/snmp/mode/cpu.pm index 914101024..d2fe6ace5 100644 --- a/network/sonicwall/snmp/mode/cpu.pm +++ b/network/sonicwall/snmp/mode/cpu.pm @@ -29,13 +29,13 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'cpu_usage', type => 0, cb_prefix_output => 'prefix_cpu_output' }, + { name => 'cpu_usage', type => 0 }, ]; $self->{maps_counters}->{cpu_usage} = [ - { label => 'cpu', set => { + { label => 'usage', set => { key_values => [ { name => 'prct_used' } ], - output_template => '%.2f %%', + output_template => 'CPU Usage %.2f %%', perfdatas => [ { label => 'cpu', value => 'prct_used_absolute', template => '%.2f', unit => '%', min => 0, max => 100 }, @@ -58,12 +58,6 @@ sub new { return $self; } -sub prefix_cpu_output { - my ($self, %options) = @_; - - return "CPU Usage "; -} - sub manage_selection { my ($self, %options) = @_; @@ -83,11 +77,11 @@ Check CPU usage. =over 8 -=item B<--warning-cpu> +=item B<--warning-usage> Threshold warning. -=item B<--critical-cpu> +=item B<--critical-usage> Threshold critical. diff --git a/network/sonicwall/snmp/mode/memory.pm b/network/sonicwall/snmp/mode/memory.pm index d52b8fe80..79b81b0f4 100644 --- a/network/sonicwall/snmp/mode/memory.pm +++ b/network/sonicwall/snmp/mode/memory.pm @@ -29,13 +29,13 @@ sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'memory_usage', type => 0, cb_prefix_output => 'prefix_memory_output' }, + { name => 'memory_usage', type => 0 }, ]; $self->{maps_counters}->{memory_usage} = [ - { label => 'memory', set => { + { label => 'usage', set => { key_values => [ { name => 'prct_used' } ], - output_template => '%.2f %%', + output_template => 'Memory Usage %.2f %%', perfdatas => [ { label => 'memory', value => 'prct_used_absolute', template => '%.2f', unit => '%', min => 0, max => 100 }, @@ -58,12 +58,6 @@ sub new { return $self; } -sub prefix_memory_output { - my ($self, %options) = @_; - - return "Memory Usage "; -} - sub manage_selection { my ($self, %options) = @_; @@ -83,11 +77,11 @@ Check Memory usage. =over 8 -=item B<--warning-memory> +=item B<--warning-usage> Threshold warning. (percent) -=item B<--critical-memory> +=item B<--critical-usage> Threshold critical. (percent) diff --git a/network/sonicwall/snmp/mode/vpn.pm b/network/sonicwall/snmp/mode/vpn.pm index 0fb68498b..270f3c4b4 100644 --- a/network/sonicwall/snmp/mode/vpn.pm +++ b/network/sonicwall/snmp/mode/vpn.pm @@ -26,48 +26,6 @@ use strict; use warnings; use Digest::MD5 qw(md5_hex); -my $instance_mode; - -sub custom_status_threshold { - my ($self, %options) = @_; - my $status = 'ok'; - my $message; - - eval { - local $SIG{__WARN__} = sub { $message = $_[0]; }; - local $SIG{__DIE__} = sub { $message = $_[0]; }; - - if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && - eval "$instance_mode->{option_results}->{critical_status}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} - -sub custom_status_output { - my ($self, %options) = @_; - - my $msg = 'connection status : ' . $self->{result_values}->{connectstatus} . ' [activation status: ' . $self->{result_values}->{activestatus} . ']'; - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{activestatus} = $options{new_datas}->{$self->{instance} . '_activestatus'}; - $self->{result_values}->{connectstatus} = $options{new_datas}->{$self->{instance} . '_connectstatus'}; - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - return 0; -} - sub set_counters { my ($self, %options) = @_; @@ -114,28 +72,13 @@ sub new { $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{connectstatus} eq "disconnected"' }, }); return $self; } -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_status', 'critical_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - sub check_options { my ($self, %options) = @_; $self->SUPER::check_options(%options); - - $self->change_macros(); - $instance_mode = $self; } my $oid_sonicSAStatEntry = '.1.3.6.1.4.1.8741.1.3.2.1.1.1'; @@ -164,8 +107,8 @@ sub manage_selection { } $self->{vpn}->{$result->{$oid_sonicSAStatUserName . '.' . $instance}} = { traffic_in => $result->{$oid_sonicSAStatEncryptByteCount . '.' . $instance} * 8, - traffic_out => $result->{$oid_sonicSAStatDecryptByteCount . '.' . $instance} * 8, - display => $result->{$oid_sonicSAStatUserName . '.' . $instance} }; + traffic_out => $result->{$oid_sonicSAStatDecryptByteCount . '.' . $instance} * 8, + display => $result->{$oid_sonicSAStatUserName . '.' . $instance} }; } if (scalar(keys %{$self->{vpn}}) <= 0) { @@ -198,16 +141,6 @@ Can be: 'traffic-in', 'traffic-out'. Threshold critical. Can be: 'traffic-in', 'traffic-out'. -=item B<--warning-status> - -Set warning threshold for status. -Can used special variables like: %{activestatus}, %{connectstatus}, %{display} - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{connectstatus} eq "disconnected"'). -Can used special variables like: %{activestatus}, %{connectstatus}, %{display} - =back =cut