From f4483595238a0ec4ba4a101e34208db29c060f2b Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 12 Jun 2017 11:43:43 +0200 Subject: [PATCH] add a10 ax plugin snmp - Fix #162 --- network/a10/ax/snmp/mode/cpu.pm | 124 +++++++++++ network/a10/ax/snmp/mode/disk.pm | 134 ++++++++++++ network/a10/ax/snmp/mode/globalstats.pm | 127 +++++++++++ network/a10/ax/snmp/mode/hardware.pm | 260 ++++++++++++++++++++++ network/a10/ax/snmp/mode/listvservers.pm | 127 +++++++++++ network/a10/ax/snmp/mode/memory.pm | 135 ++++++++++++ network/a10/ax/snmp/mode/vserverusage.pm | 267 +++++++++++++++++++++++ network/a10/ax/snmp/plugin.pm | 56 +++++ 8 files changed, 1230 insertions(+) create mode 100644 network/a10/ax/snmp/mode/cpu.pm create mode 100644 network/a10/ax/snmp/mode/disk.pm create mode 100644 network/a10/ax/snmp/mode/globalstats.pm create mode 100644 network/a10/ax/snmp/mode/hardware.pm create mode 100644 network/a10/ax/snmp/mode/listvservers.pm create mode 100644 network/a10/ax/snmp/mode/memory.pm create mode 100644 network/a10/ax/snmp/mode/vserverusage.pm create mode 100644 network/a10/ax/snmp/plugin.pm diff --git a/network/a10/ax/snmp/mode/cpu.pm b/network/a10/ax/snmp/mode/cpu.pm new file mode 100644 index 000000000..732a8689e --- /dev/null +++ b/network/a10/ax/snmp/mode/cpu.pm @@ -0,0 +1,124 @@ +# +# 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::a10::ax::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 => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPUs are ok' }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'cpu-30s', set => { + key_values => [ { name => 'cpu_30s' }, { name => 'display' } ], + output_template => '30s : %s %%', + perfdatas => [ + { label => 'cpu_30s', value => 'cpu_30s_absolute', template => '%s', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'cpu-1m', set => { + key_values => [ { name => 'cpu_1m' }, { name => 'display' } ], + output_template => '1m : %s %%', + perfdatas => [ + { label => 'cpu_1m', value => 'cpu_1m_absolute', template => '%s', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{display} . "' "; +} + +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; +} + +my $oid_axSysCpuUsageValueAtPeriod = '.1.3.6.1.4.1.22610.2.4.1.3.6.1.3'; + +sub manage_selection { + my ($self, %options) = @_; + + my $results = $options{snmp}->get_table(oid => $oid_axSysCpuUsageValueAtPeriod, + nothing_quit => 1); + + $self->{cpu} = {}; + foreach my $oid (keys %$results) { + $oid =~ /\.(\d*?)\.\d*?$/; + next if (defined($self->{cpu}->{$1})); + my $instance = $1; + + $self->{cpu}->{$instance} = { display => $instance, + cpu_1m => $results->{$oid_axSysCpuUsageValueAtPeriod . '.' . $instance . '.5'}, + cpu_30s => $results->{$oid_axSysCpuUsageValueAtPeriod . '.' . $instance . '.4'} + }; + } +} + +1; + +__END__ + +=head1 MODE + +Check CPU usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example : --filter-counters='^cpu-1m$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'cpu-30s' (%), 'cpu-1m' (%). + +=item B<--critical-*> + +Threshold critical. +Can be: 'cpu-30s' (%), 'cpu-1m' (%). + +=back + +=cut diff --git a/network/a10/ax/snmp/mode/disk.pm b/network/a10/ax/snmp/mode/disk.pm new file mode 100644 index 000000000..8d9b6058a --- /dev/null +++ b/network/a10/ax/snmp/mode/disk.pm @@ -0,0 +1,134 @@ +# +# 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::a10::ax::snmp::mode::disk; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'used', unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Disk Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disk', type => 0 } + ]; + + $self->{maps_counters}->{disk} = [ + { label => 'usage', set => { + key_values => [ { name => 'free' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +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) = @_; + + my $oid_axSysDiskFreeSpace = '.1.3.6.1.4.1.22610.2.4.1.4.2.0'; # in MB + my $oid_axSysDiskTotalSpace = '.1.3.6.1.4.1.22610.2.4.1.4.1.0'; # in MB + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_axSysDiskFreeSpace, $oid_axSysDiskTotalSpace], + nothing_quit => 1); + $self->{disk} = { free => $snmp_result->{$oid_axSysDiskFreeSpace} * 1024 * 1024, total => $snmp_result->{$oid_axSysDiskTotalSpace} * 1024 * 1024 }; + +} + +1; + +__END__ + +=head1 MODE + +Check disk usage. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/network/a10/ax/snmp/mode/globalstats.pm b/network/a10/ax/snmp/mode/globalstats.pm new file mode 100644 index 000000000..bf48dfb23 --- /dev/null +++ b/network/a10/ax/snmp/mode/globalstats.pm @@ -0,0 +1,127 @@ +# +# 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::a10::ax::snmp::mode::globalstats; + +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 => 'current-connections', set => { + key_values => [ { name => 'current_connections' } ], + output_template => 'Current Connections : %s', + perfdatas => [ + { label => 'current_connections', value => 'current_connections_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-connections', set => { + key_values => [ { name => 'total_connections', diff => 1 } ], + output_template => 'Total Connections : %s', + perfdatas => [ + { label => 'total_connections', value => 'total_connections_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'total-ssl-connections', set => { + key_values => [ { name => 'total_ssl_connections', diff => 1 } ], + output_template => 'Total SSL Connections : %s', + perfdatas => [ + { label => 'total_ssl_connections', value => 'total_ssl_connections_absolute', template => '%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) = @_; + + my $oid_axAppGlobalTotalCurrentConnections = '.1.3.6.1.4.1.22610.2.4.3.1.2.1.0'; + my $oid_axAppGlobalTotalNewConnections = '.1.3.6.1.4.1.22610.2.4.3.1.2.2.0'; + my $oid_axAppGlobalTotalSSLConnections = '.1.3.6.1.4.1.22610.2.4.3.1.2.6.0'; + my $result = $options{snmp}->get_leef(oids => [ + $oid_axAppGlobalTotalCurrentConnections, $oid_axAppGlobalTotalNewConnections, + $oid_axAppGlobalTotalSSLConnections, + ], + nothing_quit => 1); + $self->{global} = { current_connections => $result->{$oid_axAppGlobalTotalCurrentConnections}, + total_connections => $result->{$oid_axAppGlobalTotalNewConnections}, + total_ssl_connections => $result->{$oid_axAppGlobalTotalSSLConnections}, + }; + + $self->{cache_name} = "a10_ax_" . $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 statistics. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^current-connections$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'current-connections', 'total-connections'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'current-connections', 'total-connections'. + +=back + +=cut diff --git a/network/a10/ax/snmp/mode/hardware.pm b/network/a10/ax/snmp/mode/hardware.pm new file mode 100644 index 000000000..4997475c7 --- /dev/null +++ b/network/a10/ax/snmp/mode/hardware.pm @@ -0,0 +1,260 @@ +# +# 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::a10::ax::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(temperature|fan|psu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fan)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['off', 'CRITICAL'], + ['on', 'OK'], + ['unknown', 'UNKNOWN'], + ], + fan => [ + ['failed', 'CRITICAL'], + ['okFixedHigh', 'OK'], + ['okLowMed', 'OK'], + ['okMedMed', 'OK'], + ['okMedHigh', 'OK'], + ['notReady', 'WARNING'], + ['unknown', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'network::a10::ax::snmp::mode::components'; + $self->{components_module} = ['psu', 'fan', 'temperature']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + my $oid_axSysHwInfo = '.1.3.6.1.4.1.22610.2.4.1.5'; + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_table(oid => $oid_axSysHwInfo); +} + +1; + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'psu', 'fan', 'temperature'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=psu,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,OK,off' + +=item B<--warning> + +Set warning threshold for 'temperature', 'fan' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature', 'fan' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut + +package network::a10::ax::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_fan_status = (0 => 'failed', 4 => 'okFixedHigh', + 5 => 'okLowMed', 6 => 'okMedMed', 7 => 'okMedHigh', + -2 => 'notReady', -1 => 'unknown' +); + +my $mapping = { + axFanName => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.9.1.2' }, + axFanStatus => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.9.1.3', map => \%map_fan_status }, + axFanSpeed => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.9.1.4' }, +}; + +sub load { } + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { + next if ($oid !~ /^$mapping->{axFanStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan '%s' status is '%s' [instance = %s, speed = %s]", + $result->{axFanName}, $result->{axFanStatus}, $instance, $result->{axFanSpeed})); + my $exit = $self->get_severity(section => 'fan', value => $result->{axFanStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("fan '%s' status is '%s'", $result->{axFanName}, $result->{axFanStatus})); + } + + if ($result->{axFanSpeed} > 0) { + my ($exit2, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{axFanSpeed}); + if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit2, + short_msg => sprintf("fan '%s' speed is %s rpm", $result->{axFanName}, $result->{axFanSpeed})); + } + $self->{output}->perfdata_add(label => $result->{axFanName}, unit => 'rpm', + value => $result->{axFanSpeed}, + warning => $warn, + critical => $crit, min => 0 + ); + } + } +} + +1; + +package network::a10::ax::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_psu_status = (0 => 'off', 1 => 'on', -1 => 'unknown'); + +my $mapping_psu = { + axSysLowerPowerSupplyStatus => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.7', map => \%map_psu_status }, + axSysUpperPowerSupplyStatus => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.8', map => \%map_psu_status }, +}; + +sub load {} + +sub check_psu { + my ($self, %options) = @_; + + return if (!defined($options{status})); + return if ($self->check_filter(section => 'psu', instance => $options{instance})); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", + $options{instance}, $options{status}, $options{instance})); + my $exit = $self->get_severity(section => 'psu', value => $options{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("power supply '%s' status is '%s'", $options{instance}, $options{status})); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_psu, results => $self->{results}, instance => '0'); + + check_psu($self, status => $result->{axSysLowerPowerSupplyStatus}, instance => 1); + check_psu($self, status => $result->{axSysUpperPowerSupplyStatus}, instance => 2); +} + +1; + +package network::a10::ax::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping_temp = { + axSysHwPhySystemTemp => { oid => '.1.3.6.1.4.1.22610.2.4.1.5.1' }, +}; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperature"); + $self->{components}->{temperature} = {name => 'temperature', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_temp, results => $self->{results}, instance => '0'); + + return if (!defined($result->{axSysHwPhySystemTemp})); + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("physical temperature is %s C [instance = %s]", + $result->{axSysHwPhySystemTemp}, '0')); + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => '0', value => $result->{axSysHwPhySystemTemp}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("physical temperature is %s C", $result->{axSysHwPhySystemTemp})); + } + $self->{output}->perfdata_add(label => 'temperature_physical', unit => 'C', + value => $result->{axSysHwPhySystemTemp}, + warning => $warn, + critical => $crit + ); +} + +1; diff --git a/network/a10/ax/snmp/mode/listvservers.pm b/network/a10/ax/snmp/mode/listvservers.pm new file mode 100644 index 000000000..6a5d9d63b --- /dev/null +++ b/network/a10/ax/snmp/mode/listvservers.pm @@ -0,0 +1,127 @@ +# +# 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::a10::ax::snmp::mode::listvservers; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +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' }, + }); + $self->{vserver} = {}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my %map_status = (1 => 'up', 2 => 'down', 3 => 'disabled'); +my $mapping = { + axVirtualServerStatName => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.2' }, + axVirtualServerStatStatus => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.10', map => \%map_status }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{axVirtualServerStatName}->{oid} }, + { oid => $mapping->{axVirtualServerStatStatus}->{oid} }, + ], + return_type => 1, nothing_quit => 1); + foreach my $oid (keys %$snmp_result) { + next if ($oid !~ /^$mapping->{axVirtualServerStatName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $result->{axVirtualServerStatName} =~ s/\\//g; + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{axVirtualServerStatName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{axVirtualServerStatName} . "': no matching filter.", debug => 1); + next; + } + + $self->{vserver}->{$instance} = { + name => $result->{axVirtualServerStatName}, status => $result->{axVirtualServerStatStatus} }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{vserver}}) { + $self->{output}->output_add(long_msg => '[name = ' . $self->{vserver}->{$instance}->{name} . + "] [status = " . $self->{vserver}->{$instance}->{status} . ']' + ); + } + + $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', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{vserver}}) { + $self->{output}->add_disco_entry(name => $self->{vserver}->{$instance}->{name}, + status => $self->{vserver}->{$instance}->{status}); + } +} + +1; + +__END__ + +=head1 MODE + +List virtual servers. + +=over 8 + +=item B<--filter-name> + +Filter by virtual server name (can be a regexp). + +=back + +=cut + diff --git a/network/a10/ax/snmp/mode/memory.pm b/network/a10/ax/snmp/mode/memory.pm new file mode 100644 index 000000000..c7946b527 --- /dev/null +++ b/network/a10/ax/snmp/mode/memory.pm @@ -0,0 +1,135 @@ +# +# 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::a10::ax::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'used', unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0 } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', set => { + key_values => [ { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +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) = @_; + + my $oid_axSysMemoryUsage = '.1.3.6.1.4.1.22610.2.4.1.2.2.0'; # in KB + my $oid_axSysMemoryTotal = '.1.3.6.1.4.1.22610.2.4.1.2.1.0'; # in KB + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_axSysMemoryUsage, $oid_axSysMemoryTotal], + nothing_quit => 1); + + $self->{memory} = { used => $snmp_result->{$oid_axSysMemoryUsage} * 1024, total => $snmp_result->{$oid_axSysMemoryTotal} * 1024 }; + +} + +1; + +__END__ + +=head1 MODE + +Check memory usage. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/network/a10/ax/snmp/mode/vserverusage.pm b/network/a10/ax/snmp/mode/vserverusage.pm new file mode 100644 index 000000000..dce59c28e --- /dev/null +++ b/network/a10/ax/snmp/mode/vserverusage.pm @@ -0,0 +1,267 @@ +# +# 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::a10::ax::snmp::mode::vserverusage; + +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 = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_axVirtualServerStatStatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vserver', type => 1, cb_prefix_output => 'prefix_vserver_output', message_multiple => 'All virtual servers are ok' } + ]; + + $self->{maps_counters}->{vserver} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'axVirtualServerStatStatus' }, { 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_status_threshold'), + } + }, + { label => 'current-con', set => { + key_values => [ { name => 'axVirtualServerStatCurConns' }, { name => 'display' } ], + output_template => 'Current Connections : %s', + perfdatas => [ + { label => 'current_connections', value => 'axVirtualServerStatCurConns_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-con', set => { + key_values => [ { name => 'axVirtualServerStatTotConns', diff => 1 }, { name => 'display' } ], + output_template => 'Total Connections : %s', + perfdatas => [ + { label => 'total_connections', value => 'axVirtualServerStatTotConns_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-in', set => { + key_values => [ { name => 'axVirtualServerStatBytesIn', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In : %s %s/s', + perfdatas => [ + { label => 'traffic_in', value => 'axVirtualServerStatBytesIn_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'traffic-out', set => { + key_values => [ { name => 'axVirtualServerStatBytesOut', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out : %s %s/s', + perfdatas => [ + { label => 'traffic_out', value => 'axVirtualServerStatBytesOut_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_vserver_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 => '%{status} =~ /down/i' }, + }); + + 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_status = ( + 1 => 'up', 2 => 'down', 3 => 'disabled', +); +my $oid_axVirtualServerStatName = '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.2'; +my $mapping = { + axVirtualServerStatBytesIn => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.4' }, + axVirtualServerStatBytesOut => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.6' }, + axVirtualServerStatTotConns => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.8' }, + axVirtualServerStatCurConns => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.9' }, + axVirtualServerStatStatus => { oid => '.1.3.6.1.4.1.22610.2.4.3.4.2.1.1.10', map => \%map_status }, +}; + +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 $snmp_result = $options{snmp}->get_table(oid => $oid_axVirtualServerStatName, nothing_quit => 1); + $self->{vserver} = {}; + foreach my $oid (keys %{$snmp_result}) { + $oid =~ /^$oid_axVirtualServerStatName\.(.*)$/; + my $instance = $1; + $snmp_result->{$oid} =~ s/\\//g; + 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 virtual server '" . $snmp_result->{$oid} . "'.", debug => 1); + next; + } + + $self->{vserver}->{$instance} = { display => $snmp_result->{$oid} }; + } + + $options{snmp}->load(oids => [$mapping->{axVirtualServerStatBytesIn}->{oid}, $mapping->{axVirtualServerStatBytesOut}->{oid}, + $mapping->{axVirtualServerStatTotConns}->{oid}, $mapping->{axVirtualServerStatCurConns}->{oid}, + $mapping->{axVirtualServerStatStatus}->{oid} + ], + instances => [keys %{$self->{vserver}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{vserver}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + + foreach my $name (('axVirtualServerStatBytesIn', 'axVirtualServerStatBytesOut')) { + $result->{$name} *= 8; + } + + foreach my $name (keys %$mapping) { + $self->{vserver}->{$_}->{$name} = $result->{$name}; + } + } + + if (scalar(keys %{$self->{vserver}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtual server found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "a10_ax_" . $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 virtual server usage. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /down/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'current-con', 'total-con', 'traffic-in', 'traffic-out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'current-con', 'total-con', 'traffic-in', 'traffic-out'. + +=item B<--filter-name> + +Filter by virtual server name (can be a regexp). + +=back + +=cut diff --git a/network/a10/ax/snmp/plugin.pm b/network/a10/ax/snmp/plugin.pm new file mode 100644 index 000000000..df5602f0f --- /dev/null +++ b/network/a10/ax/snmp/plugin.pm @@ -0,0 +1,56 @@ +# +# 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::a10::ax::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::a10::ax::snmp::mode::cpu', + 'disk' => 'network::a10::ax::snmp::mode::disk', + 'global-stats' => 'network::a10::ax::snmp::mode::globalstats', + 'hardware' => 'network::a10::ax::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-vservers' => 'network::a10::ax::snmp::mode::listvservers', + 'memory' => 'network::a10::ax::snmp::mode::memory', + 'vserver-usage' => 'network::a10::ax::snmp::mode::vserverusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check A10 AX in SNMP. + +=cut