From bb4770f8d554a3df1a3f46824322df1024e8adf7 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Thu, 4 May 2017 14:18:13 +0200 Subject: [PATCH] add vserver mode for alteon --- .../radware/alteon/snmp/mode/listvservers.pm | 131 +++++++++ .../radware/alteon/snmp/mode/vserverstatus.pm | 263 ++++++++++++++++++ network/radware/alteon/snmp/plugin.pm | 8 +- 3 files changed, 399 insertions(+), 3 deletions(-) create mode 100644 network/radware/alteon/snmp/mode/listvservers.pm create mode 100644 network/radware/alteon/snmp/mode/vserverstatus.pm diff --git a/network/radware/alteon/snmp/mode/listvservers.pm b/network/radware/alteon/snmp/mode/listvservers.pm new file mode 100644 index 000000000..4bd3e5a1d --- /dev/null +++ b/network/radware/alteon/snmp/mode/listvservers.pm @@ -0,0 +1,131 @@ +# +# 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::radware::alteon::snmp::mode::listvservers; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %map_state = ( + 2 => 'enabled', + 3 => 'disabled', +); + +my $mapping = { + slbCurCfgVirtServerState => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.4', map => \%map_state }, + slbCurCfgVirtServerVname => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.10' }, +}; + +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_multiple_table(oids => [ + { oid => $mapping->{slbCurCfgVirtServerState}->{oid} }, + { oid => $mapping->{slbCurCfgVirtServerVname}->{oid} }, + ], return_type => 1, nothing_quit => 1); + $self->{vservers} = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{slbCurCfgVirtServerVname}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (!defined($result->{slbCurCfgVirtServerVname}) || $result->{slbCurCfgVirtServerVname} eq '') { + $self->{output}->output_add(long_msg => "skipping Virtual Server '$instance': cannot get a name. please set it.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{slbCurCfgVirtServerVname} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{slbCurCfgVirtServerVname} . "'.", debug => 1); + next; + } + + $self->{vservers}->{$instance} = { name => $result->{slbCurCfgVirtServerVname}, state => $result->{slbCurCfgVirtServerState} }; + } +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + foreach my $instance (sort keys %{$self->{vservers}}) { + $self->{output}->output_add(long_msg => "'" . $self->{vservers}->{$instance}->{name} . "' [state = '" . $self->{vservers}->{$instance}->{state} . "']"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List Virtual Servers:'); + $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', 'state']); +} + +sub disco_show { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + foreach my $instance (sort keys %{$self->{vservers}}) { + $self->{output}->add_disco_entry(name => $self->{vservers}->{$instance}->{name}, state => $self->{vservers}->{$instance}->{state}); + } +} + +1; + +__END__ + +=head1 MODE + +List Virtual Servers. + +=over 8 + +=item B<--filter-name> + +Filter by virtual server name. + +=back + +=cut + diff --git a/network/radware/alteon/snmp/mode/vserverstatus.pm b/network/radware/alteon/snmp/mode/vserverstatus.pm new file mode 100644 index 000000000..2d58f7770 --- /dev/null +++ b/network/radware/alteon/snmp/mode/vserverstatus.pm @@ -0,0 +1,263 @@ +# +# 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::radware::alteon::snmp::mode::vserverstatus; + +use base qw(centreon::plugins::templates::counter); + +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 = 'state : ' . $self->{result_values}->{state}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vservers', type => 1, cb_prefix_output => 'prefix_vservers_output', message_multiple => 'All Virtual Servers are ok' } + ]; + + $self->{maps_counters}->{vservers} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'traffic', set => { + key_values => [ { name => 'traffic', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic : %s %s/s', + perfdatas => [ + { label => 'traffic', value => 'traffic_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-sessions', set => { + key_values => [ { name => 'current_sessions' }, { name => 'display' } ], + output_template => 'Current Sessions : %s', + perfdatas => [ + { label => 'current_sessions', value => 'current_sessions_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-sessions', set => { + key_values => [ { name => 'total_sessions', diff => 1 }, { name => 'display' } ], + output_template => 'Total Sessions : %s', + perfdatas => [ + { label => 'total_sessions', value => 'total_sessions_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_vservers_output { + my ($self, %options) = @_; + + return "Virtual Server '" . $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' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +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; + } + } +} + +my %map_state = ( + 2 => 'enabled', + 3 => 'disabled', +); + +my $mapping = { + slbCurCfgVirtServerState => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.4', map => \%map_state }, + slbCurCfgVirtServerVname => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.10' }, + slbCurCfgVirtServerAvail => { oid => '.1.3.6.1.4.1.1872.2.5.4.1.1.4.2.1.8' }, # can't get mapping for that. If someones has it, i'm interested :) +}; +my $mapping2 = { + slbStatVServerCurrSessions => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.2' }, + slbStatVServerTotalSessions => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.3' }, + slbStatVServerHCOctetsLow32 => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.5' }, + slbStatVServerHCOctetsHigh32 => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.6' }, + slbStatVServerHCOctets => { oid => '.1.3.6.1.4.1.1872.2.5.4.2.4.1.13' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $mapping->{slbCurCfgVirtServerState}->{oid} }, + { oid => $mapping->{slbCurCfgVirtServerVname}->{oid} }, + ], return_type => 1, nothing_quit => 1); + $self->{vservers} = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{slbCurCfgVirtServerVname}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (!defined($result->{slbCurCfgVirtServerVname}) || $result->{slbCurCfgVirtServerVname} eq '') { + $self->{output}->output_add(long_msg => "skipping Virtual Server '$instance': cannot get a name. please set it.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{slbCurCfgVirtServerVname} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{slbCurCfgVirtServerVname} . "'.", debug => 1); + next; + } + + $self->{vservers}->{$instance} = { display => $result->{slbCurCfgVirtServerVname}, state => $result->{slbCurCfgVirtServerState} }; + } + + $options{snmp}->load(oids => [$mapping2->{slbStatVServerCurrSessions}->{oid}, $mapping2->{slbStatVServerTotalSessions}->{oid}, + $mapping2->{slbStatVServerHCOctetsLow32}->{oid}, $mapping2->{slbStatVServerHCOctetsHigh32}->{oid}, + $mapping2->{slbStatVServerHCOctets}->{oid} + ], + instances => [keys %{$self->{vservers}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{vservers}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); + + $self->{vservers}->{$_}->{traffic} = (defined($result->{slbStatVServerHCOctets}) ? $result->{slbStatVServerHCOctets} * 8 : + (($result->{slbStatVServerHCOctetsHigh32} << 32) + $result->{slbStatVServerHCOctetsLow32})) * 8; + $self->{vservers}->{$_}->{current_sessions} = $result->{slbStatVServerCurrSessions}; + $self->{vservers}->{$_}->{total_sessions} = $result->{slbStatVServerTotalSessions}; + } + + if (scalar(keys %{$self->{vservers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtual server found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "alteon_" . $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 vservers status. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'traffic', 'total-sessions', 'current-sessions'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'traffic', 'total-sessions', 'current-sessions'. + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{state}, %{display} + +=item B<--critical-status> + +Set critical threshold for status. +Can used special variables like: %{state}, %{display} + +=item B<--filter-name> + +Filter by virtual server name (can be a regexp). + +=back + +=cut diff --git a/network/radware/alteon/snmp/plugin.pm b/network/radware/alteon/snmp/plugin.pm index e2da10efe..fafb8bea0 100644 --- a/network/radware/alteon/snmp/plugin.pm +++ b/network/radware/alteon/snmp/plugin.pm @@ -31,9 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::radware::alteon::snmp::mode::cpu', - 'hardware' => 'network::radware::alteon::snmp::mode::hardware', - 'memory' => 'network::radware::alteon::snmp::mode::memory', + 'cpu' => 'network::radware::alteon::snmp::mode::cpu', + 'hardware' => 'network::radware::alteon::snmp::mode::hardware', + 'list-vservers' => 'network::radware::alteon::snmp::mode::listvservers', + 'memory' => 'network::radware::alteon::snmp::mode::memory', + 'vserver-status' => 'network::radware::alteon::snmp::mode::vserverstatus', ); return $self;