From 7dd11a8dbb32e6a0cfb5715383545c6998efbe46 Mon Sep 17 00:00:00 2001 From: tcharles Date: Thu, 6 Oct 2016 16:16:48 +0200 Subject: [PATCH 1/9] Update ec2instancenetwork.pm --- cloud/aws/mode/metrics/ec2instancenetwork.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/cloud/aws/mode/metrics/ec2instancenetwork.pm b/cloud/aws/mode/metrics/ec2instancenetwork.pm index 414bdb09d..cdd5c71a8 100644 --- a/cloud/aws/mode/metrics/ec2instancenetwork.pm +++ b/cloud/aws/mode/metrics/ec2instancenetwork.pm @@ -47,6 +47,7 @@ $Param[1] = { 'NameSpace' => 'AWS/EC2', 'MetricName' => 'NetworkOut', 'ObjectName' => 'InstanceId', + 'Unit' => 'Bytes', 'Labels' => { 'ShortOutput' => "Traffic Out %s Bytes", 'LongOutput' => "Traffic Out %s Bytes", From 5278699a43db6be3269865bf76740da11467496f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 13 Oct 2016 15:18:29 +0200 Subject: [PATCH 2/9] + add database sybase plugin --- database/sybase/mode/blockedprocesses.pm | 99 +++++++++++ database/sybase/mode/connectedusers.pm | 99 +++++++++++ database/sybase/mode/databasessize.pm | 217 +++++++++++++++++++++++ database/sybase/plugin.pm | 104 +++++++++++ 4 files changed, 519 insertions(+) create mode 100644 database/sybase/mode/blockedprocesses.pm create mode 100644 database/sybase/mode/connectedusers.pm create mode 100644 database/sybase/mode/databasessize.pm create mode 100644 database/sybase/plugin.pm diff --git a/database/sybase/mode/blockedprocesses.pm b/database/sybase/mode/blockedprocesses.pm new file mode 100644 index 000000000..4065cb973 --- /dev/null +++ b/database/sybase/mode/blockedprocesses.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 database::sybase::mode::blockedprocesses; + +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) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + $self->{sql}->query(query => q{SELECT count(*) FROM master.dbo.sysprocesses WHERE blocked <> 0}); + my $blocked = $self->{sql}->fetchrow_array(); + + my $exit_code = $self->{perfdata}->threshold_check(value => $blocked, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("%i blocked process(es).", $blocked)); + $self->{output}->perfdata_add(label => 'blocked_processes', + value => $blocked, + 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 MSSQL blocked processes. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/database/sybase/mode/connectedusers.pm b/database/sybase/mode/connectedusers.pm new file mode 100644 index 000000000..a903f7df4 --- /dev/null +++ b/database/sybase/mode/connectedusers.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 database::sybase::mode::connectedusers; + +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) = @_; + # $options{sql} = sqlmode object + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + $self->{sql}->query(query => q{SELECT count(*) FROM master..sysprocesses WHERE spid >= 51}); + my $users = $self->{sql}->fetchrow_array(); + + my $exit_code = $self->{perfdata}->threshold_check(value => $users, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("%i Connected user(s).", $users)); + $self->{output}->perfdata_add(label => 'connected_users', + value => $users, + 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 MSSQL connected users. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut diff --git a/database/sybase/mode/databasessize.pm b/database/sybase/mode/databasessize.pm new file mode 100644 index 000000000..2146a2dc4 --- /dev/null +++ b/database/sybase/mode/databasessize.pm @@ -0,0 +1,217 @@ +# +# 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 database::sybase::mode::databasessize; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'database', type => 1, cb_prefix_output => 'prefix_database_output', message_multiple => 'All databases are OK', message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{database} = [ + { label => 'data', set => { + key_values => [ { name => 'data_used' }, { name => 'data_size' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'data' }, + 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'), + } + }, + { label => 'log', set => { + key_values => [ { name => 'log_used' }, { name => 'log_size' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'log' }, + 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 custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = $self->{result_values}->{label} . '_used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = $self->{result_values}->{label} . '_free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, 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("Total %s: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + ucfirst($self->{result_values}->{label}), + $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) = @_; + + my $label = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_' . $label . '_size'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_' . $label . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{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}->{label} = $label; + + return 0; +} + +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-database:s" => { name => 'filter_database' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + return $self; +} + +sub prefix_database_output { + my ($self, %options) = @_; + + return "Database '" . $options{instance_value}->{display} . "' "; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + $options{sql}->query(query => q{ + select db_name(d.dbid) as db_name, +ceiling(sum(case when u.segmap != 4 then u.size/1.*@@maxpagesize end )) as data_size, +ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1.*@@maxpagesize) as data_used, +ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end)) as log_size, +ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end) - lct_admin("logsegment_freepages",d.dbid)/1.*@@maxpagesize) as log_used +from master..sysdatabases d, master..sysusages u +where u.dbid = d.dbid and d.status not in (256,4096) +group by d.dbid +order by db_name(d.dbid) + }); + + my $result = $options{sql}->fetchall_arrayref(); + + foreach my $row (@$result) { + if (defined($self->{option_results}->{filter_database}) && $self->{option_results}->{filter_database} ne '' && + $$row[0] !~ /$self->{option_results}->{filter_database}/) { + $self->{output}->output_add(long_msg => "skipping '" . $$row[0] . "': no matching filter.", debug => 1); + next; + } + + $self->{database}->{$$row[0]} = { data_size => $$row[1], data_used => $$row[2], + log_size => $$row[3], log_used => $$row[4], + display => lc($$row[0]) }; + } +} + +1; + +__END__ + +=head1 MODE + +Check MSSQL Database usage + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'data', 'log'. + +=item B<--critical-*> + +Threshold warning. +Can be: 'data', 'log'. + +=item B<--filter-database> + +Filter database by name. Can be a regex + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/database/sybase/plugin.pm b/database/sybase/plugin.pm new file mode 100644 index 000000000..b85f4ee2b --- /dev/null +++ b/database/sybase/plugin.pm @@ -0,0 +1,104 @@ +# +# 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 database::sybase::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_sql); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'blocked-processes' => 'database::sybase::mode::blockedprocesses', + 'connected-users' => 'database::sybase::mode::connectedusers', + 'connection-time' => 'centreon::common::protocols::sql::mode::connectiontime', + 'databases-size' => 'database::sybase::mode::databasessize', + 'sql' => 'centreon::common::protocols::sql::mode::sql', + ); + + return $self; +} + +sub init { + my ($self, %options) = @_; + + $self->{options}->add_options( + arguments => { + 'hostname:s@' => { name => 'hostname' }, + 'port:s@' => { name => 'port' }, + 'tds-level:s@' => { name => 'tds_level' }, + 'database:s' => { name => 'database' }, + } + ); + $self->{options}->parse_options(); + my $options_result = $self->{options}->get_options(); + $self->{options}->clean(); + + if (defined($options_result->{hostname})) { + @{$self->{sqldefault}->{dbi}} = (); + for (my $i = 0; $i < scalar(@{$options_result->{hostname}}); $i++) { + $self->{sqldefault}->{dbi}[$i] = { data_source => 'Sybase:host=' . $options_result->{hostname}[$i] }; + my $port = defined($options_result->{port}[$i]) && $options_result->{port}[$i] ne '' + ? $options_result->{port}[$i] : 2638; + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $port; + + my $tds_level = defined($options_result->{tds_level}[$i]) && $options_result->{tds_level}[$i] ne '' + ? $options_result->{tds_level}[$i] : 'CS_TDS_50'; + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';tdsLevel=' . $tds_level; + + if ((defined($options_result->{database})) && ($options_result->{database} ne '')) { + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{database}; + } + } + } + $self->SUPER::init(%options); +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Sybase Server. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--port> + +Database Server Port (Default: 2638). + +=item B<--tds-level> + +TDS protocol level to use (Default: 'CS_TDS_50') + +=back + +=cut From 6ae21ddd4d93bcf4b167009d6e7d532678256c1e Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 13 Oct 2016 22:52:03 +0200 Subject: [PATCH 3/9] + Fix #489 --- database/postgres/mode/hitratio.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/postgres/mode/hitratio.pm b/database/postgres/mode/hitratio.pm index c9b3e482b..335e730e7 100644 --- a/database/postgres/mode/hitratio.pm +++ b/database/postgres/mode/hitratio.pm @@ -105,8 +105,8 @@ WHERE d.oid=sd.datid my %prcts = (); my $total_read_requests = $new_datas->{$$row[2] . '_blks_hit'} - $old_blks_hit; my $total_read_disk = $new_datas->{$$row[2] . '_blks_read'} - $old_blks_read; - $prcts{hitratio_now} = ($total_read_requests == 0) ? 100 : ($total_read_requests - $total_read_disk) * 100 / $total_read_requests; - $prcts{hitratio} = ($new_datas->{$$row[2] . '_blks_hit'} == 0) ? 100 : ($new_datas->{$$row[2] . '_blks_hit'} - $new_datas->{$$row[2] . '_blks_read'}) * 100 / $new_datas->{$$row[2] . '_blks_hit'}; + $prcts{hitratio_now} = (($total_read_requests + $total_read_disk) == 0) ? 100 : $total_read_requests * 100 / ($total_read_requests + $total_read_disk); + $prcts{hitratio} = (($new_datas->{$$row[2] . '_blks_hit'} + + $new_datas->{$$row[2] . '_blks_read'}) == 0) ? 100 : $new_datas->{$$row[2] . '_blks_hit'} * 100 / ($new_datas->{$$row[2] . '_blks_hit'} + $new_datas->{$$row[2] . '_blks_read'}); my $exit_code = $self->{perfdata}->threshold_check(value => $prcts{'hitratio' . ((defined($self->{option_results}->{lookback})) ? '' : '_now' )}, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(long_msg => sprintf("Database '%s' hitratio at %.2f%%", From 90afd86b6bb8d4457f8a02e0b0403a447a4647a7 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 12:12:17 +0200 Subject: [PATCH 4/9] + enhance vtom mode --- apps/vtom/restapi/mode/jobstatus.pm | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/vtom/restapi/mode/jobstatus.pm b/apps/vtom/restapi/mode/jobstatus.pm index 74f018948..ec3eb05f0 100644 --- a/apps/vtom/restapi/mode/jobstatus.pm +++ b/apps/vtom/restapi/mode/jobstatus.pm @@ -55,6 +55,9 @@ sub custom_status_threshold { sub custom_status_output { my ($self, %options) = @_; my $msg = 'status : ' . $self->{result_values}->{status}; + if ($self->{result_values}->{information} ne '') { + $msg .= ' [information: ' . $self->{result_values}->{information} . ']'; + } return $msg; } @@ -66,6 +69,7 @@ sub custom_status_calc { $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{exit_code} = $options{new_datas}->{$self->{instance} . '_exit_code'}; $self->{result_values}->{family} = $options{new_datas}->{$self->{instance} . '_family'}; + $self->{result_values}->{information} = $options{new_datas}->{$self->{instance} . '_information'}; return 0; } @@ -124,7 +128,7 @@ sub set_counters { $self->{maps_counters}->{job} = [ { label => 'status', threshold => 0, set => { - key_values => [ { name => 'status' }, { name => 'display' }, { name => 'exit_code' }, { name => 'family' } ], + key_values => [ { name => 'status' }, { name => 'display' }, { name => 'exit_code' }, { name => 'family' }, { name => 'information' } ], closure_custom_calc => $self->can('custom_status_calc'), closure_custom_output => $self->can('custom_status_output'), closure_custom_perfdata => sub { return 0; }, @@ -199,6 +203,7 @@ sub new { $options{options}->add_options(arguments => { "filter-name:s" => { name => 'filter_name' }, + "filter-family:s" => { name => 'filter_family' }, "warning-status:s" => { name => 'warning_status' }, "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Error/i' }, "warning-long:s" => { name => 'warning_long' }, @@ -261,16 +266,24 @@ sub manage_selection { $self->{output}->output_add(long_msg => "skipping '" . $entry->{name} . "': no matching filter.", debug => 1); next; } + my $family = defined($entry->{family}) ? $entry->{family} : '-'; + if (defined($self->{option_results}->{filter_family}) && $self->{option_results}->{filter_family} ne '' && + $family !~ /$self->{option_results}->{filter_family}/) { + $self->{output}->output_add(long_msg => "skipping '" . $family . "': no matching filter.", debug => 1); + next; + } + my $information = defined($entry->{information}) ? $entry->{information} : ''; + $information =~ s/\|/-/msg; my $elapsed_time = $current_time - $entry->{timeBegin}; $self->{global}->{total} += 1; $self->{global}->{lc($mapping_job_status{$entry->{status}})} += 1; $self->{job}->{$entry->{id}} = { display => $entry->{name}, - status => $mapping_job_status{$entry->{status}}, + status => $mapping_job_status{$entry->{status}}, information => $information, exit_code => $entry->{retcode}, - family => defined($entry->{family}) ? $entry->{family} : '-', + family => $family, elapsed => $elapsed_time }; } @@ -296,6 +309,10 @@ Check job status. Filter name (can be a regexp). +=item B<--filter-family> + +Filter family (can be a regexp). + =item B<--filter-counters> Only display some counters (regexp can be used). @@ -316,12 +333,14 @@ Can be: 'total-error', 'total-running', 'total-unplanned', =item B<--warning-status> Set warning threshold for status (Default: -) -Can used special variables like: %{display}, %{status}, %{exit_code}, %{family} +Can used special variables like: %{display}, %{status}, +%{exit_code}, %{family}, %{information} =item B<--critical-status> Set critical threshold for status (Default: '%{exit_code} =~ /Error/i'). -Can used special variables like: %{display}, %{status}, %{exit_code}, %{family} +Can used special variables like: %{display}, %{status}, +%{exit_code}, %{family}, %{information} =item B<--warning-long> From 646dfb2b05a2d70aa88b840849a6e85785c2805d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 15:31:46 +0200 Subject: [PATCH 5/9] + 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 From 9106b516705651e07ad28877e37fa940be5bc397 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 15:51:31 +0200 Subject: [PATCH 6/9] + Fix #517 --- network/cyberoam/snmp/mode/cpu.pm | 2 +- network/cyberoam/snmp/mode/requests.pm | 10 +++++----- network/cyberoam/snmp/mode/storage.pm | 3 +-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/network/cyberoam/snmp/mode/cpu.pm b/network/cyberoam/snmp/mode/cpu.pm index 5fda445f4..4392467f6 100644 --- a/network/cyberoam/snmp/mode/cpu.pm +++ b/network/cyberoam/snmp/mode/cpu.pm @@ -66,7 +66,7 @@ sub run { $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}, + value => sprintf("%.2f", $result->{$oid_cpuPercentUsage}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0); diff --git a/network/cyberoam/snmp/mode/requests.pm b/network/cyberoam/snmp/mode/requests.pm index 7a84d7dd4..c67433565 100644 --- a/network/cyberoam/snmp/mode/requests.pm +++ b/network/cyberoam/snmp/mode/requests.pm @@ -114,11 +114,11 @@ sub manage_selection { $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'} }; + $self->{global} = { http_hits => $result->{$oid_httpHits}, + ftp_hits => $result->{$oid_ftpHits}, + pop3_hits => $result->{$oid_pop3Hits}, + imap_hits => $result->{$oid_imapHits}, + smtp_hits => $result->{$oid_smtpHits} }; } 1; diff --git a/network/cyberoam/snmp/mode/storage.pm b/network/cyberoam/snmp/mode/storage.pm index d1643bd7a..026016b75 100644 --- a/network/cyberoam/snmp/mode/storage.pm +++ b/network/cyberoam/snmp/mode/storage.pm @@ -106,8 +106,7 @@ sub manage_selection { 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;, + $self->{storage} = { used => $result->{$oid_diskPercentUsage} * $result->{$oid_diskCapacity} * 1024 * 1024 / 100, total => $result->{$oid_diskCapacity} * 1024 * 1024 }; } From 08e85d7edd48cefc1fa88b578c5786693b241554 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 15:53:49 +0200 Subject: [PATCH 7/9] + add unit in perfdata --- network/cyberoam/snmp/mode/cpu.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/cyberoam/snmp/mode/cpu.pm b/network/cyberoam/snmp/mode/cpu.pm index 4392467f6..127a2d6c1 100644 --- a/network/cyberoam/snmp/mode/cpu.pm +++ b/network/cyberoam/snmp/mode/cpu.pm @@ -65,7 +65,7 @@ sub run { 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", + $self->{output}->perfdata_add(label => "cpu", unit => '%', value => sprintf("%.2f", $result->{$oid_cpuPercentUsage}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), From 4f1b145bed55f4ffd8245881306a84c41b643993 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 15:54:58 +0200 Subject: [PATCH 8/9] + add percent in output --- network/cyberoam/snmp/mode/cpu.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network/cyberoam/snmp/mode/cpu.pm b/network/cyberoam/snmp/mode/cpu.pm index 127a2d6c1..458c83af3 100644 --- a/network/cyberoam/snmp/mode/cpu.pm +++ b/network/cyberoam/snmp/mode/cpu.pm @@ -64,7 +64,7 @@ sub run { 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})); + short_msg => sprintf("CPU Usage : %.2f %%", $result->{$oid_cpuPercentUsage})); $self->{output}->perfdata_add(label => "cpu", unit => '%', value => sprintf("%.2f", $result->{$oid_cpuPercentUsage}), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), From 5f7cb6eb2ff50b0b431faa0f4d991854d8767110 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 14 Oct 2016 16:02:40 +0200 Subject: [PATCH 9/9] + prepare release --- centreon/plugins/script.pm | 2 +- changelog | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm index 92a0e4a9e..cb46d945c 100644 --- a/centreon/plugins/script.pm +++ b/centreon/plugins/script.pm @@ -30,7 +30,7 @@ use Pod::Find qw(pod_where); my %handlers = (DIE => {}); -my $global_version = 20160902; +my $global_version = 20161014; my $alternative_fatpacker = 0; sub new { diff --git a/changelog b/changelog index 5ca6549db..3fd6a9beb 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,13 @@ +2016-10-14 Quentin Garnier + * Plugin added: to check StorageTek SLxxx + * Plugin added: to check HP Storeonce Rest API + * Plugin added: to check Gorgy ntpserver SNMP + * Plugin added: to check Nortel/Avaya SNMP + * Plugin added: to check Vtom Rest API + * Plugin added: to check Sybase + * Plugin added: to check Cyberoam SNMP (#517) + * Minor fixes and enhancement + 2016-09-02 Quentin Garnier * Plugin added: to check HP-UX SNMP (#13) * Plugin added: to check Hitachi HNAS