From 646dfb2b05a2d70aa88b840849a6e85785c2805d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 15:31:46 +0200 Subject: [PATCH] + Ref #517 --- network/cyberoam/snmp/mode/cpu.pm | 99 ++++++++++++++ network/cyberoam/snmp/mode/memory.pm | 177 +++++++++++++++++++++++++ network/cyberoam/snmp/mode/requests.pm | 151 +++++++++++++++++++++ network/cyberoam/snmp/mode/storage.pm | 134 +++++++++++++++++++ network/cyberoam/snmp/plugin.pm | 53 ++++++++ 5 files changed, 614 insertions(+) create mode 100644 network/cyberoam/snmp/mode/cpu.pm create mode 100644 network/cyberoam/snmp/mode/memory.pm create mode 100644 network/cyberoam/snmp/mode/requests.pm create mode 100644 network/cyberoam/snmp/mode/storage.pm create mode 100644 network/cyberoam/snmp/plugin.pm diff --git a/network/cyberoam/snmp/mode/cpu.pm b/network/cyberoam/snmp/mode/cpu.pm new file mode 100644 index 000000000..5fda445f4 --- /dev/null +++ b/network/cyberoam/snmp/mode/cpu.pm @@ -0,0 +1,99 @@ +# +# Copyright 2016 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::cyberoam::snmp::mode::cpu; + +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 => + { + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + }); + + 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(); + } +} + +sub run { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + my $oid_cpuPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.2.1.0'; + my $result = $self->{snmp}->get_leef(oids => [$oid_cpuPercentUsage], nothing_quit => 1); + + my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_cpuPercentUsage}, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU Usage : %.2f", $result->{$oid_cpuPercentUsage})); + $self->{output}->perfdata_add(label => "cpu", + value => $result->{$oid_cpuPercentUsage}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check current processor usage. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut + \ No newline at end of file diff --git a/network/cyberoam/snmp/mode/memory.pm b/network/cyberoam/snmp/mode/memory.pm new file mode 100644 index 000000000..f54c2103f --- /dev/null +++ b/network/cyberoam/snmp/mode/memory.pm @@ -0,0 +1,177 @@ +# +# Copyright 2016 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::cyberoam::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 => $self->{result_values}->{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->{result_values}->{label} . '-usage', exit_litteral => 'critical' }, { label => 'warning-' . $self->{result_values}->{label} . '-usage', 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("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}->{label} = $options{extra_options}->{label_ref}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_used'} + $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0, cb_prefix_output => 'prefix_memory_output' }, + { name => 'swap', type => 0, cb_prefix_output => 'prefix_swap_output' } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'physical-usage', set => { + key_values => [ { name => 'free' }, { name => 'used' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'physical' }, + 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'), + } + }, + ]; + $self->{maps_counters}->{swap} = [ + { label => 'swap-usage', set => { + key_values => [ { name => 'free' }, { name => 'used' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'swap' }, + 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 prefix_memory_output { + my ($self, %options) = @_; + + return "Physical memory "; +} + +sub prefix_swap_output { + my ($self, %options) = @_; + + return "Swap memory "; +} + +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-counters:s" => { name => 'filter_counters' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_memoryCapacity = '.1.3.6.1.4.1.21067.2.1.2.4.1.0'; # in MB + my $oid_memoryPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.4.2.0'; + my $oid_swapCapacity = '.1.3.6.1.4.1.21067.2.1.2.4.3.0'; # in MB + my $oid_swapPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.4.4.0'; + + my $result = $options{snmp}->get_leef(oids => [$oid_memoryCapacity, $oid_memoryPercentUsage, + $oid_swapCapacity, $oid_swapPercentUsage], + nothing_quit => 1); + my $memory_used = $result->{$oid_memoryPercentUsage} * $result->{$oid_memoryCapacity} * 1024 * 1024 / 100; + my $swap_used = $result->{$oid_swapPercentUsage} * $result->{$oid_swapCapacity} * 1024 * 1024 / 100; + $self->{memory} = { + free => $result->{$oid_memoryCapacity} * 1024 * 1024 - $memory_used, + used => $memory_used, + }; + $self->{swap} = { + free => $result->{$oid_swapCapacity} * 1024 * 1024 - $swap_used, + used => $swap_used, + }; +} + +1; + +__END__ + +=head1 MODE + +Check memory usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example : --filter-counters='^physical-usage$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'physical-usage' (%), 'swap-usage' (%). + +=item B<--critical-*> + +Threshold critical. +Can be: 'physical-usage' (%), 'swap-usage' (%). + +=back + +=cut diff --git a/network/cyberoam/snmp/mode/requests.pm b/network/cyberoam/snmp/mode/requests.pm new file mode 100644 index 000000000..7a84d7dd4 --- /dev/null +++ b/network/cyberoam/snmp/mode/requests.pm @@ -0,0 +1,151 @@ +# +# Copyright 2016 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::cyberoam::snmp::mode::requests; + +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, cb_prefix_output => 'prefix_output' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'http-hits', set => { + key_values => [ { name => 'http_hits', diff => 1 } ], + output_template => 'http hits = %s', + perfdatas => [ + { label => 'http_hits', value => 'http_hits_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'ftp-hits', set => { + key_values => [ { name => 'ftp_hits', diff => 1 } ], + output_template => 'ftp hits = %s', + perfdatas => [ + { label => 'ftp_hits', value => 'ftp_hits_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'pop3-hits', set => { + key_values => [ { name => 'pop3_hits', diff => 1 } ], + output_template => 'pop3 hits = %s', + perfdatas => [ + { label => 'pop3_hits', value => 'pop3_hits_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'imap-hits', set => { + key_values => [ { name => 'imap_hits', diff => 1 } ], + output_template => 'imap hits = %s', + perfdatas => [ + { label => 'imap_hits', value => 'imap_hits_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'smtp-hits', set => { + key_values => [ { name => 'smtp_hits', diff => 1 } ], + output_template => 'smtp hits = %s', + perfdatas => [ + { label => 'smtp_hits', value => 'smtp_hits_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Requests: "; +} + +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_httpHits = '.1.3.6.1.4.1.21067.2.1.2.7.0'; + my $oid_ftpHits = '.1.3.6.1.4.1.21067.2.1.2.8.0'; + my $oid_pop3Hits = '.1.3.6.1.4.1.21067.2.1.2.9.1.0'; + my $oid_imapHits = '.1.3.6.1.4.1.21067.2.1.2.9.2.0'; + my $oid_smtpHits = '.1.3.6.1.4.1.21067.2.1.2.9.3.0'; + my $result = $options{snmp}->get_leef(oids => [$oid_httpHits, $oid_ftpHits, $oid_pop3Hits, + $oid_imapHits, $oid_smtpHits], nothing_quit => 1); + + $self->{cache_name} = "cyberoam_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{global} = { http_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.1.0'}, + ftp_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.2.0'}, + pop3_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.3.0'}, + imap_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.4.0'}, + smtp_hits => $result->{'.1.3.6.1.4.1.3417.2.11.3.1.1.5.0'} }; +} + +1; + +__END__ + +=head1 MODE + +Check request statistics. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='http-hits' + +=item B<--warning-*> + +Threshold warning. +Can be: http-hits, ftp-hits, pop3-hits, imap-hits, smtp-hits. + +=item B<--critical-*> + +Threshold critical. +Can be: http-hits, ftp-hits, pop3-hits, imap-hits, smtp-hits. + +=back + +=cut diff --git a/network/cyberoam/snmp/mode/storage.pm b/network/cyberoam/snmp/mode/storage.pm new file mode 100644 index 000000000..d1643bd7a --- /dev/null +++ b/network/cyberoam/snmp/mode/storage.pm @@ -0,0 +1,134 @@ +# +# Copyright 2016 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::cyberoam::snmp::mode::storage; + +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("Storage Usage 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}->{free} = $options{new_datas}->{$self->{instance} . '_total'} - $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{prct_free} = $self->{result_values}->{free} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'storage', type => 0 } + ]; + + $self->{maps_counters}->{storage} = [ + { 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_diskCapacity = '.1.3.6.1.4.1.21067.2.1.2.3.1.0'; # in MB + my $oid_diskPercentUsage = '.1.3.6.1.4.1.21067.2.1.2.3.2.0'; + my $result = $options{snmp}->get_leef(oids => [$oid_diskCapacity, $oid_diskPercentUsage], + nothing_quit => 1); + my $memory_used = $result->{$oid_memoryPercentUsage} * $result->{$oid_memoryCapacity} * 1024 * 1024 / 100; + $self->{memory} = { used => $result->{$oid_diskPercentUsage} * $result->{$oid_diskCapacity} * 1024 * 1024 / 100;, + total => $result->{$oid_diskCapacity} * 1024 * 1024 }; +} + +1; + +__END__ + +=head1 MODE + +Check storage usage. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut \ No newline at end of file diff --git a/network/cyberoam/snmp/plugin.pm b/network/cyberoam/snmp/plugin.pm new file mode 100644 index 000000000..173b00067 --- /dev/null +++ b/network/cyberoam/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2016 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::cyberoam::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} = '0.1'; + %{$self->{modes}} = ( + 'cpu' => 'network::cyberoam::snmp::mode::cpu', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::cyberoam::snmp::mode::memory', + 'requests' => 'network::cyberoam::snmp::mode::requests', + 'storage' => 'network::cyberoam::snmp::mode::storage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Cyberoam equipments in SNMP. + +=cut