From 5c95dd6bce636fa7b40c3d9aae99a19a282557fa Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 3 Feb 2016 16:22:26 +0100 Subject: [PATCH 01/17] + fix help --- centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm b/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm index 274efdd52..d2c1b124d 100644 --- a/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm +++ b/centreon-plugins/network/juniper/trapeze/snmp/mode/apusers.pm @@ -160,7 +160,7 @@ __END__ =head1 MODE -Check AP status. +Check AP users. =over 8 From e61effc10acd6036af711d1a1904d86dce701440 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 4 Feb 2016 11:25:44 +0100 Subject: [PATCH 02/17] + enhance oracle database: when bytes is superior than maxbytes --- centreon-plugins/database/oracle/mode/tablespaceusage.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/centreon-plugins/database/oracle/mode/tablespaceusage.pm b/centreon-plugins/database/oracle/mode/tablespaceusage.pm index 14976bcd8..f751d6d67 100644 --- a/centreon-plugins/database/oracle/mode/tablespaceusage.pm +++ b/centreon-plugins/database/oracle/mode/tablespaceusage.pm @@ -99,7 +99,7 @@ sub run { SELECT a.tablespace_name, SUM(a.bytes) bytes, - SUM(DECODE(a.autoextensible, 'YES', a.maxbytes, 'NO', a.bytes)) maxbytes + SUM(DECODE(a.autoextensible, 'YES', CASE WHEN (a.bytes > a.maxbytes) THEN 0 ELSE a.maxbytes END, 'NO', a.bytes)) maxbytes FROM dba_data_files a GROUP BY @@ -140,7 +140,7 @@ sub run { b.contents "Type", b.extent_management "Extent Mgmt", sum(a.bytes_free + a.bytes_used) bytes, -- allocated - SUM(DECODE(d.autoextensible, 'YES', d.maxbytes, 'NO', d.bytes)) bytes_max, + SUM(DECODE(d.autoextensible, 'YES', CASE WHEN (d.bytes > d.maxbytes) THEN 0 ELSE d.maxbytes END, 'NO', d.bytes)) bytes_max, SUM(a.bytes_free + a.bytes_used - NVL(c.bytes_used, 0)) bytes_free FROM sys.v_$TEMP_SPACE_HEADER a, From bc2cf868b87909c47b6c55032d69db13ee53204f Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 4 Feb 2016 16:39:26 +0100 Subject: [PATCH 03/17] + begin to work on netbackup plugin --- .../netbackup/local/mode/drivestatus.pm | 233 ++++++++++++++++++ .../apps/backup/netbackup/local/plugin.pm | 49 ++++ 2 files changed, 282 insertions(+) create mode 100644 centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm create mode 100644 centreon-plugins/apps/backup/netbackup/local/plugin.pm diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm b/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm new file mode 100644 index 000000000..cba6c1161 --- /dev/null +++ b/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm @@ -0,0 +1,233 @@ +# +# 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 apps::backup::netbackup::local::mode::drivestatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +my $instance_mode; + +sub custom_threshold_output { + 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} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'drive', type => 1, cb_prefix_output => 'prefix_drive_output', message_multiple => 'All drive status are ok' } + ]; + + $self->{maps_counters}->{drive} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + ]; +} + +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 => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'tpconfig' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-l 2>&1' }, + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /up/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_drive_output { + my ($self, %options) = @_; + + return "Drive '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $stdout = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + $self->{drive} = {}; + #robot 0 - TLD - - - - {3,0,0,1} + # drive - 0 hcart2 2 UP - IBM.ULT3580-HH5.000 {3,0,1,0} + # drive - 2 hcart2 1 UP - IBM.ULT3580-HH5.002 {3,0,0,0} + while ($stdout =~ /^robot\s+(\d+)(.*?)(?=robot\s+\d+|\z)/msig) { + my ($robot_num, $drives) = ($1, $2); + while ($drives =~ /drive\s+\S+\s+(\d+)\s+\S+\s+\S+\s+(\S+)/msig) { + my $name = $robot_num . '.' . $1; + $self->{drive}->{$name} = { display => $name, status => $2 }; + } + } + + if (scalar(keys %{$self->{drive}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No drives found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check drive status. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'tpconfig'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-l 2>&1'). + +=item B<--filter-name> + +Filter drive name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{display}, %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /up/i'). +Can used special variables like: %{display}, %{status} + +=back + +=cut diff --git a/centreon-plugins/apps/backup/netbackup/local/plugin.pm b/centreon-plugins/apps/backup/netbackup/local/plugin.pm new file mode 100644 index 000000000..fdc3b750e --- /dev/null +++ b/centreon-plugins/apps/backup/netbackup/local/plugin.pm @@ -0,0 +1,49 @@ +# +# 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 apps::backup::netbackup::local::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Netbackup through local commands (the plugin can use SSH). + +=cut From f673f49e83541c9011f3193d3ef94184cf4e9fbd Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 4 Feb 2016 17:00:20 +0100 Subject: [PATCH 04/17] + add mode for netbackup (WIP) --- .../netbackup/local/mode/drivecleaning.pm | 179 ++++++++++++++++++ .../netbackup/local/mode/drivestatus.pm | 6 + .../apps/backup/netbackup/local/plugin.pm | 1 + 3 files changed, 186 insertions(+) create mode 100644 centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm b/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm new file mode 100644 index 000000000..ce8f8a721 --- /dev/null +++ b/centreon-plugins/apps/backup/netbackup/local/mode/drivecleaning.pm @@ -0,0 +1,179 @@ +# +# 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 apps::backup::netbackup::local::mode::drivecleaning; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'drive', type => 0 } + ]; + + $self->{maps_counters}->{drive} = [ + { label => 'cleaning', set => { + key_values => [ { name => 'num_cleaning' }, { name => 'total' } ], + output_template => '%d drives needs a reset mount time', + perfdatas => [ + { label => 'cleaning', value => 'num_cleaning_absolute', template => '%s', + min => 0, max => 'total_absolute' }, + ], + } + }, + ]; +} + +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 => + { + "hostname:s" => { name => 'hostname' }, + "remote" => { name => 'remote' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'tpconfig' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-l 2>&1' }, + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $stdout = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + $self->{drive} = { total => 0, num_cleaning => 0 }; + #Drive Name Type Mount Time Frequency Last Cleaned Comment + #********** **** ********** ********* **************** ******* + #IBM.ULT3580-HH5.000 hcart2* 18.3 96 05:29 21/12/2015 + #IBM.ULT3580-HH5.002 hcart2* 36.8 0 11:10 20/12/2015 + my @lines = split /\n/, $stdout; + splice(@lines, 0, 2); + foreach my $line (@lines) { + $line =~ /^(\S+)/; + my $name = $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + $self->{output}->output_add(long_msg => "drive '" . $name . "' checked.", debug => 1); + + $self->{drive}->{total}++; + if ($line =~ /NEEDS CLEANING/i) { + $self->{drive}->{num_cleaning}++; + } + } + + if (scalar(keys %{$self->{drive}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No drives found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check drive cleaning. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'tpconfig'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-l 2>&1'). + +=item B<--filter-name> + +Filter drive name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'cleaning'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'cleaning'. + +=back + +=cut diff --git a/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm b/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm index cba6c1161..683f6f99f 100644 --- a/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm +++ b/centreon-plugins/apps/backup/netbackup/local/mode/drivestatus.pm @@ -153,6 +153,12 @@ sub manage_selection { my ($robot_num, $drives) = ($1, $2); while ($drives =~ /drive\s+\S+\s+(\d+)\s+\S+\s+\S+\s+(\S+)/msig) { my $name = $robot_num . '.' . $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } $self->{drive}->{$name} = { display => $name, status => $2 }; } } diff --git a/centreon-plugins/apps/backup/netbackup/local/plugin.pm b/centreon-plugins/apps/backup/netbackup/local/plugin.pm index fdc3b750e..a99c2b50d 100644 --- a/centreon-plugins/apps/backup/netbackup/local/plugin.pm +++ b/centreon-plugins/apps/backup/netbackup/local/plugin.pm @@ -32,6 +32,7 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( + 'drive-cleaning' => 'apps::backup::netbackup::local::mode::drivecleaning', 'drive-status' => 'apps::backup::netbackup::local::mode::drivestatus', ); From 4c3b7b61a8ca3f1aec5def3e9f1552de964ea8b7 Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 4 Feb 2016 22:00:12 +0100 Subject: [PATCH 05/17] * Enhance mode clusterhealth.pm --- .../storage/emc/xtremio/restapi/mode/clusterhealth.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm index 0e349e8c1..25ac27600 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/clusterhealth.pm @@ -131,6 +131,7 @@ sub run { name => $item); foreach my $sensor (@sensors) { + next if (!defined($details->{$sensor}) || $details->{$sensor} eq ''); $self->{output}->output_add(long_msg => sprintf("Sensor '%s' state is '%s'", $sensor, $details->{$sensor})); From b53a2736123ceedd5ee53e5001cd81c5278d1a0d Mon Sep 17 00:00:00 2001 From: Sims24 Date: Thu, 4 Feb 2016 22:06:35 +0100 Subject: [PATCH 06/17] + enhance help and correct threshold unit --- .../storage/emc/xtremio/restapi/mode/ssdiops.pm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm index 8edd9e6f7..046e74c6d 100644 --- a/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm +++ b/centreon-plugins/storage/emc/xtremio/restapi/mode/ssdiops.pm @@ -200,17 +200,16 @@ Check IOPS (Global, Read, Write) on each SSDs. =item B<--warning-*> -Threshold warning. -Can be: 'global' (%), 'read' (%), 'write' (%). +Threshold warning (number of iops) +Can be: 'global', 'read', 'write'. =item B<--critical-*> - -Threshold critical. -Can be: 'global' (%), 'read' (%), 'write' (%). +Threshold critical (number of iops) +Can be: 'global', 'read', 'write'. =item B<--filter-name> -Filter SSD name (can be a regexp). +Filter SSD name (can be a regexp). (e.g --filter-name '.*' for all SSDs) =back From 838f449a3aa3801fa2886ae38a0f672f4f1098d2 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 5 Feb 2016 13:11:33 +0100 Subject: [PATCH 07/17] + add slack to send notification --- centreon-plugins/centreon/plugins/http.pm | 13 +- .../notification/slack/mode/alert.pm | 343 ++++++++++++++++++ centreon-plugins/notification/slack/plugin.pm | 48 +++ 3 files changed, 402 insertions(+), 2 deletions(-) create mode 100644 centreon-plugins/notification/slack/mode/alert.pm create mode 100644 centreon-plugins/notification/slack/plugin.pm diff --git a/centreon-plugins/centreon/plugins/http.pm b/centreon-plugins/centreon/plugins/http.pm index de399a190..59e5fb41b 100644 --- a/centreon-plugins/centreon/plugins/http.pm +++ b/centreon-plugins/centreon/plugins/http.pm @@ -205,7 +205,9 @@ sub request { my ($response, $content); my ($req, $url); - if (defined($request_options->{port}) && $request_options->{port} =~ /^[0-9]+$/) { + if (defined($request_options->{full_url})) { + $url = $request_options->{full_url}; + } elsif (defined($request_options->{port}) && $request_options->{port} =~ /^[0-9]+$/) { $url = $request_options->{proto}. "://" . $request_options->{hostname} . ':' . $request_options->{port} . $request_options->{url_path}; } else { $url = $request_options->{proto}. "://" . $request_options->{hostname} . $request_options->{url_path}; @@ -304,7 +306,8 @@ sub request { $self->{output}->exit(); } - $self->{headers} = $response->headers; + $self->{headers} = $response->{headers}; + $self->{response} = $response; return $response->content; } @@ -314,4 +317,10 @@ sub get_header { return $self->{headers}; } +sub get_response { + my ($self, %options) = @_; + + return $self->{response}; +} + 1; diff --git a/centreon-plugins/notification/slack/mode/alert.pm b/centreon-plugins/notification/slack/mode/alert.pm new file mode 100644 index 000000000..6b5a2fe14 --- /dev/null +++ b/centreon-plugins/notification/slack/mode/alert.pm @@ -0,0 +1,343 @@ +# +# 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 notification::slack::mode::alert; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::http; +use JSON; + +my %slack_color_host = ( + up => 'good', + down => 'danger', + unreachable => 'danger', +); +my %slack_color_service = ( + ok => 'good', + warning => 'warning', + critical => 'danger', + unknown => 'warning', +); + +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 => + { + "slack-url:s" => { name => 'slack_url' }, + "slack-channel:s" => { name => 'slack_channel' }, + "slack-username:s" => { name => 'slack_username' }, + "host-name:s" => { name => 'host_name' }, + "host-state:s" => { name => 'host_state' }, + "host-output:s" => { name => 'host_output' }, + "service-description:s" => { name => 'service_description' }, + "service-state:s" => { name => 'service_state' }, + "service-output:s" => { name => 'service_output' }, + "slack-color:s" => { name => 'slack_color' }, + "slack-emoji:s" => { name => 'slack_emoji', }, + "graph-url:s" => { name => 'graph_url' }, + "priority:s" => { name => 'priority' }, + "zone:s" => { name => 'zone' }, + "link-url:s" => { name => 'link_url' }, + "centreon-url:s" => { name => 'centreon_url' }, + "centreon-token:s" => { name => 'centreon_token' }, + + "credentials" => { name => 'credentials' }, + "ntlm" => { name => 'ntlm' }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "proxyurl:s" => { name => 'proxyurl' }, + "proxypac:s" => { name => 'proxypac' }, + "timeout:s" => { name => 'timeout' }, + }); + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + $self->{payload_attachment} = { fields => [] }; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{slack_url}) || $self->{option_results}->{slack_url} eq '') { + $self->{output}->add_option_msg(short_msg => "You need to specify --slack-url option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{slack_channel}) || $self->{option_results}->{slack_channel} eq '') { + $self->{output}->add_option_msg(short_msg => "You need to specify --slack-channel option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{host_name}) || $self->{option_results}->{host_name} eq '') { + $self->{output}->add_option_msg(short_msg => "You need to specify --host-name option."); + $self->{output}->option_exit(); + } + + foreach (('graph_url', 'link_url')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{option_results}->{$1}/g; + eval "\$self->{option_results}->{\$_} = \"$self->{option_results}->{$_}\""; + } + } + + $self->{http}->set_options(%{$self->{option_results}}, hostname => 'dummy'); +} + +sub format_payload { + my ($self, %options) = @_; + + my $json = JSON->new; + my $payload = { channel => $self->{option_results}->{slack_channel}, + attachments => [ $self->{payload_attachment} ] }; + if (defined($self->{option_results}->{slack_emoji}) && $self->{option_results}->{slack_emoji} ne '') { + $payload->{icon_emoji} = $self->{option_results}->{slack_emoji}; + } + if (defined($self->{option_results}->{slack_username}) && $self->{option_results}->{slack_username} ne '') { + $payload->{username} = $self->{option_results}->{slack_username}; + } + eval { + $self->{payload_str} = $json->encode($payload); + }; + if ($@) { + $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); + $self->{output}->option_exit(); + } +} + +sub host_message { + my ($self, %options) = @_; + + my $url_host = $self->{option_results}->{host_name}; + if (defined($self->{option_results}->{link_url}) && $self->{option_results}->{link_url} ne '') { + $url_host = '<' . $self->{option_results}->{link_url} . '|' . $self->{option_results}->{host_name} . '>'; + $self->{payload_attachment}->{fallback} = "Host " . $self->{option_results}->{host_name}; + } + $self->{payload_attachment}->{text} = "Host " . $url_host; + + if (defined($self->{option_results}->{host_state}) && $self->{option_results}->{host_state} ne '') { + $self->{payload_attachment}->{text} .= ' is ' . $self->{option_results}->{host_state}; + $self->{payload_attachment}->{fallback} .= ' is ' . $self->{option_results}->{host_state}; + if (defined($slack_color_host{lc($self->{option_results}->{host_state})})) { + $self->{payload_attachment}->{color} = $slack_color_host{lc($self->{option_results}->{host_state})}; + } + } else { + $self->{payload_attachment}->{text} .= ' alert'; + $self->{payload_attachment}->{fallback} .= ' alert'; + } + + if (defined($self->{option_results}->{link_url}) && $self->{option_results}->{link_url} ne '') { + $self->{payload_attachment}->{fallback} .= ' : ' . $self->{option_results}->{link_url}; + } + + if (defined($self->{option_results}->{host_output}) && $self->{option_results}->{host_output} ne '') { + push @{$self->{payload_attachment}->{fields}}, { title => 'output', value => $self->{option_results}->{host_output} }; + } +} + +sub service_message { + my ($self, %options) = @_; + + my $url_service = $self->{option_results}->{service_description}; + if (defined($self->{option_results}->{link_url}) && $self->{option_results}->{link_url} ne '') { + $url_service = '<' . $self->{option_results}->{link_url} . '|' . $self->{option_results}->{host_name} . '/' . $self->{option_results}->{service_description} . '>'; + $self->{payload_attachment}->{fallback} = "Service " . $self->{option_results}->{host_name} . '/' . $self->{option_results}->{service_description}; + } + $self->{payload_attachment}->{text} = "Service " . $url_service; + + if (defined($self->{option_results}->{service_state}) && $self->{option_results}->{service_state} ne '') { + $self->{payload_attachment}->{text} .= ' is ' . $self->{option_results}->{service_state}; + $self->{payload_attachment}->{fallback} .= ' is ' . $self->{option_results}->{service_state}; + if (defined($slack_color_service{lc($self->{option_results}->{service_state})})) { + $self->{payload_attachment}->{color} = $slack_color_service{lc($self->{option_results}->{service_state})}; + } + } else { + $self->{payload_attachment}->{text} .= ' alert'; + $self->{payload_attachment}->{fallback} .= ' alert'; + } + + if (defined($self->{option_results}->{link_url}) && $self->{option_results}->{link_url} ne '') { + $self->{payload_attachment}->{fallback} .= ' : ' . $self->{option_results}->{link_url}; + } + + if (defined($self->{option_results}->{service_output}) && $self->{option_results}->{service_output} ne '') { + push @{$self->{payload_attachment}->{fields}}, { title => 'output', value => $self->{option_results}->{service_output} }; + } + + if (defined($self->{option_results}->{graph_url}) && $self->{option_results}->{graph_url} ne '') { + $self->{payload_attachment}->{image_url} = $self->{option_results}->{graph_url}; + } +} + +sub set_payload { + my ($self, %options) = @_; + + if (!defined($self->{option_results}->{service_description}) && $self->{option_results}->{service_description} ne '') { + $self->host_message(); + } else { + $self->service_message(); + } + + if (defined($self->{option_results}->{slack_color}) && $self->{option_results}->{slack_color} ne '') { + $self->{payload_attachment}->{color} = $self->{option_results}->{slack_color}; + } + + if (defined($self->{option_results}->{priority}) && $self->{option_results}->{priority} ne '') { + push @{$self->{payload_attachment}->{fields}}, { title => 'Priority', value => $self->{option_results}->{priority}, short => 'true' }; + } + if (defined($self->{option_results}->{zone}) && $self->{option_results}->{zone} ne '') { + push @{$self->{payload_attachment}->{fields}}, { title => 'Zone', value => $self->{option_results}->{zone}, short => 'true' }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->set_payload(); + $self->format_payload(); + my $response = $self->{http}->request(full_url => $self->{option_results}->{slack_url}, + method => 'POST', + post_param => ['payload=' . $self->{payload_str}]); + + $self->{output}->output_add(short_msg => 'slack response: ' . $response); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Send slack alerts. + +Example for a host: +centreon_plugins.pl --plugin=notification::slack::plugin --mode=alert --slack-url='https://hooks.slack.com/services/T0A754E2V/B0E0CEL4B/81V8kCJusL7kafDSdsd' --slack-channel='#testchannel' --slack-username='bot' --slack-emoji=':ghost:' --host-name='srvi-clus-win' --host-state='DOWN' --host-output='test output' --priority='High' --zone='Production' --centreon-url='https://centreon.test.com/centreon/' --link-url='%{centreon_url}/main.php?p=20202&o=svc&host_search=%{host_name}' + +Example for a service: +centreon_plugins.pl --plugin=notification::slack::plugin --mode=alert --slack-url='https://hooks.slack.com/services/T0A754E2V/B0E0CEL4B/81V8kCJusL7kafDSdsd' --slack-channel='#tmptestqga' --slack-username='bot' --slack-emoji=':ghost:' --host-name='srvi-clus-win' --service-description='Ping' --service-state='WARNING' --service-output='CRITICAL - 10.50.1.78: rta nan, lost 100%' --priority='High' --zone='Production' --centreon-url='https://ces.merethis.net/centreon/' --link-url='%{centreon_url}/main.php?p=20201&o=svc&host_search=%{host_name}&svc_search=%{service_description}' --centreon-token='LxTQxFbLU6' --graph-url='%{centreon_url}/include/views/graphs/generateGraphs/generateImage.php?username=myuser&token=%{centreon_token}&hostname=%{host_name}&service=%{service_description}' + +=over 8 + +=item B<--slack-url> + +Specify slack url (Required). + +=item B<--slack-channel> + +Specify slack channel (Required). + +=item B<--slack-username> + +Specify slack username. + +=item B<--host-name> + +Specify host server name for the alert (Required). + +=item B<--host-state> + +Specify host server state for the alert. + +=item B<--host-output> + +Specify host server output message for the alert. + +=item B<--service-description> + +Specify service description name for the alert. + +=item B<--service-state> + +Specify service state for the alert. + +=item B<--service-output> + +Specify service output message for the alert. + +=item B<--slack-color> + +Specify slack color (According state option, color will be choosed). + +=item B<--slack-emoji> + +Specify slack emoji. + +=item B<--priority> + +Specify the priority message. + +=item B<--zone> + +Specify the zone message. + +=item B<--centreon-url> + +Specify the centreon url macro (could be used in link-url and graph-url option). + +=item B<--centreon-token> + +Specify the centreon token for autologin macro (could be used in link-url and graph-url option). + +=item B<--graph-url> + +Specify the graph url (Example: %{centreon_url}/include/views/graphs/generateGraphs/generateImage.php?username=myuser&token=%{centreon_token}&hostname=%{host_name}&service=%{service_description}). + +=item B<--link-url> + +Specify the link url (Example: %{centreon_url}/main.php?p=20201&o=svc&host_search=%{host_name}&svc_search=%{service_description}) + +=item B<--proxyurl> + +Proxy URL + +=item B<--proxypac> + +Proxy pac file (can be an url or local file) + +=item B<--credentials> + +Specify this option if you access webpage over basic authentification + +=item B<--ntlm> + +Specify this option if you access webpage over ntlm authentification (Use with --credentials option) + +=item B<--username> + +Specify username for basic authentification (Mandatory if --credentials is specidied) + +=item B<--password> + +Specify password for basic authentification (Mandatory if --credentials is specidied) + +=item B<--timeout> + +Threshold for HTTP timeout (Default: 5) + +=back + +=cut diff --git a/centreon-plugins/notification/slack/plugin.pm b/centreon-plugins/notification/slack/plugin.pm new file mode 100644 index 000000000..b221d5af5 --- /dev/null +++ b/centreon-plugins/notification/slack/plugin.pm @@ -0,0 +1,48 @@ +# +# 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 notification::slack::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'alert' => 'notification::slack::mode::alert', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Send Slack notifications. + +=cut From 61f8f122efe39b1f88fb2d22c86c3e66271caf0c Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 8 Feb 2016 22:33:53 +0100 Subject: [PATCH 08/17] + Enhance cisco ASA sessions (Fix #315) --- .../cisco/standard/snmp/mode/sessions.pm | 289 ++++++++++++++++++ .../network/cisco/asa/mode/sessions.pm | 154 ---------- centreon-plugins/network/cisco/asa/plugin.pm | 2 +- 3 files changed, 290 insertions(+), 155 deletions(-) create mode 100644 centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm delete mode 100644 centreon-plugins/network/cisco/asa/mode/sessions.pm diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm new file mode 100644 index 000000000..09a59e4ba --- /dev/null +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm @@ -0,0 +1,289 @@ +# +# 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 centreon::common::cisco::standard::snmp::mode::sessions; + +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 => 'connections', type => 0, cb_prefix_output => 'prefix_connections_output', skipped_code => { -10 => 1 } }, + { name => 'sessions', type => 0, cb_prefix_output => 'prefix_sessions_output', skipped_code => { -10 => 1 } }, + ]; + $self->{maps_counters}->{connections} = [ + { label => 'connections-current', set => { + key_values => [ { name => 'cufwConnGlobalNumActive' } ], + output_template => 'current : %s', output_error_template => "current : %s", + perfdatas => [ + { label => 'connections_current', value => 'cufwConnGlobalNumActive_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'connections-1m', set => { + key_values => [ { name => 'cufwConnGlobalConnSetupRate1' } ], + output_template => 'average last 1min %s', output_error_template => "average last 1min : %s", + perfdatas => [ + { label => 'connections_1m', value => 'cufwConnGlobalConnSetupRate1_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'connections-5m', set => { + key_values => [ { name => 'cufwConnGlobalConnSetupRate5' } ], + output_template => 'average last 5min : %s', output_error_template => "average last 5min : %s", + perfdatas => [ + { label => 'connections_5m', value => 'cufwConnGlobalConnSetupRate5_absolute', template => '%d', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{sessions} = [ + { label => 'sessions-total', set => { + key_values => [ { name => 'crasNumSessions' } ], + output_template => 'total : %s', output_error_template => "total : %s", + perfdatas => [ + { label => 'sessions_total', value => 'crasNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-email-current', set => { + key_values => [ { name => 'crasEmailNumSessions' } ], + output_template => 'current email proxy : %s', output_error_template => "current email proxy : %s", + perfdatas => [ + { label => 'sessions_email_current', value => 'crasEmailNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-email-psec', set => { + key_values => [ { name => 'crasEmailCumulateSessions', diff => 1 } ], + output_template => 'email proxy : %.2f/s', output_error_template => "email proxy : %s", + per_second => 1, + perfdatas => [ + { label => 'sessions_email_psec', value => 'crasEmailCumulateSessions_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'sessions-ipsec-current', set => { + key_values => [ { name => 'crasIPSecNumSessions' } ], + output_template => 'current ipsec : %s', output_error_template => "current ipsec : %s", + perfdatas => [ + { label => 'sessions_ipsec_current', value => 'crasIPSecNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-ipsec-psec', set => { + key_values => [ { name => 'crasIPSecCumulateSessions', diff => 1 } ], + output_template => 'ipsec : %.2f/s', output_error_template => "ipsec : %s", + per_second => 1, + perfdatas => [ + { label => 'sessions_ipsec_psec', value => 'crasIPSecCumulateSessions_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'sessions-l2l-current', set => { + key_values => [ { name => 'crasL2LNumSessions' } ], + output_template => 'current LAN to LAN : %s', output_error_template => "current LAN to LAN : %s", + perfdatas => [ + { label => 'sessions_l2l_current', value => 'crasL2LNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-l2l-psec', set => { + key_values => [ { name => 'crasL2LCumulateSessions', diff => 1 } ], + output_template => 'LAN to LAN : %.2f/s', output_error_template => "LAN to LAN : %s", + per_second => 1, + perfdatas => [ + { label => 'sessions_l2l_psec', value => 'crasL2LCumulateSessions_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'sessions-lb-current', set => { + key_values => [ { name => 'crasLBNumSessions' } ], + output_template => 'current load balancing : %s', output_error_template => "current load balancing : %s", + perfdatas => [ + { label => 'sessions_lb_current', value => 'crasLBNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-lb-psec', set => { + key_values => [ { name => 'crasLBCumulateSessions', diff => 1 } ], + output_template => 'load balancing : %.2f/s', output_error_template => "load balancing : %s", + per_second => 1, + perfdatas => [ + { label => 'sessions_lb_psec', value => 'crasLBCumulateSessions_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'sessions-svc-current', set => { + key_values => [ { name => 'crasSVCNumSessions' } ], + output_template => 'current SVC : %s', output_error_template => "current SVC : %s", + perfdatas => [ + { label => 'sessions_svc_current', value => 'crasSVCNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-svc-psec', set => { + key_values => [ { name => 'crasSVCCumulateSessions', diff => 1 } ], + output_template => 'SVC : %.2f/s', output_error_template => "SVC : %s", + per_second => 1, + perfdatas => [ + { label => 'sessions_svc_psec', value => 'crasSVCCumulateSessions_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + { label => 'sessions-webvpn-current', set => { + key_values => [ { name => 'crasWebvpnNumSessions' } ], + output_template => 'current webvpn : %s', output_error_template => "current webvpn : %s", + perfdatas => [ + { label => 'sessions_webvpn_current', value => 'crasWebvpnNumSessions_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'sessions-webvpn-psec', set => { + key_values => [ { name => 'crasWebvpnCumulateSessions', diff => 1 } ], + output_template => 'webvpn : %.2f/s', output_error_template => "webvpn : %s", + per_second => 1, + perfdatas => [ + { label => 'sessions_webvpn_psec', value => 'crasWebvpnCumulateSessions_per_second', template => '%.2f', + min => 0 }, + ], + } + }, + ]; +} + +sub prefix_connections_output { + my ($self, %options) = @_; + + return "Connections "; +} + +sub prefix_sessions_output { + my ($self, %options) = @_; + + return "Sessions "; +} + +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; +} + +my %oids_connections = ( + cufwConnGlobalNumActive => '.1.3.6.1.4.1.9.9.491.1.1.1.6.0', + cufwConnGlobalConnSetupRate1 => '.1.3.6.1.4.1.9.9.491.1.1.1.10.0', + cufwConnGlobalConnSetupRate5 => '.1.3.6.1.4.1.9.9.491.1.1.1.11.0', +); +my %oids_sessions = ( + crasNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.1.0', + crasEmailNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.23.0', + crasEmailCumulateSessions => '.1.3.6.1.4.1.9.9.392.1.3.24.0', + crasIPSecNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.26.0', + crasIPSecCumulateSessions => '.1.3.6.1.4.1.9.9.392.1.3.27.0', + crasL2LNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.29.0', + crasL2LCumulateSessions => '.1.3.6.1.4.1.9.9.392.1.3.30.0', + crasLBNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.32.0', + crasLBCumulateSessions => '.1.3.6.1.4.1.9.9.392.1.3.33.0', + crasSVCNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.35.0', + crasSVCCumulateSessions => '.1.3.6.1.4.1.9.9.392.1.3.36.0', + crasWebvpnNumSessions => '.1.3.6.1.4.1.9.9.392.1.3.38.0', + crasWebvpnCumulateSessions => '.1.3.6.1.4.1.9.9.392.1.3.39.0', +); + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "cisco_standard_" . $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->{connections} = {}; + $self->{sessions} = {}; + + $self->{results} = $options{snmp}->get_leef(oids => [values %oids_connections, values %oids_sessions], + nothing_quit => 1); + foreach my $name (keys %oids_connections) { + next if (!defined($self->{results}->{$oids_connections{$name}}) || $self->{results}->{$oids_connections{$name}} == 0); + $self->{connections}->{$name} = $self->{results}->{$oids_connections{$name}}; + } + foreach my $name (keys %oids_sessions) { + next if (!defined($self->{results}->{$oids_sessions{$name}}) || $self->{results}->{$oids_sessions{$name}} == 0); + $self->{sessions}->{$name} = $self->{results}->{$oids_sessions{$name}}; + } +} + +1; + +__END__ + +=head1 MODE + +Check sessions. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'connections-current', 'connections-1m', 'connections-5m', +'sessions-total', 'sessions-email-current', 'sessions-email-psec', +'sessions-ipsec-current', 'sessions-ipsec-psec', 'sessions-l2l-current', 'sessions-lb-psec' +'sessions-lb-current', 'sessions-lb-psec', 'sessions-svc-current', 'sessions-svc-psec', +'sessions-webvpn-current', 'sessions-webvpn-psec'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'connections-current', 'connections-1m', 'connections-5m', +'sessions-total', 'sessions-email-current', 'sessions-email-psec', +'sessions-ipsec-current', 'sessions-ipsec-psec', 'sessions-l2l-current', 'sessions-lb-psec' +'sessions-lb-current', 'sessions-lb-psec', 'sessions-svc-current', 'sessions-svc-psec', +'sessions-webvpn-current', 'sessions-webvpn-psec'. + +=back + +=cut diff --git a/centreon-plugins/network/cisco/asa/mode/sessions.pm b/centreon-plugins/network/cisco/asa/mode/sessions.pm deleted file mode 100644 index a82602f0d..000000000 --- a/centreon-plugins/network/cisco/asa/mode/sessions.pm +++ /dev/null @@ -1,154 +0,0 @@ -# -# 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::cisco::asa::mode::sessions; - -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-average:s" => { name => 'warning_average', default => '' }, - "critical-average:s" => { name => 'critical_average', default => '' }, - "warning-current:s" => { name => 'warning_current' }, - "critical-current:s" => { name => 'critical_current' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - ($self->{warn_avg1m}, $self->{warn_avg5m}) = split /,/, $self->{option_results}->{warning_average}; - ($self->{crit_avg1m}, $self->{crit_avg5m}) = split /,/, $self->{option_results}->{critical_average}; - - if (($self->{perfdata}->threshold_validate(label => 'warn_avg1m', value => $self->{warn_avg1m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning average (1min) threshold '" . $self->{warn_avg1m} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn_avg5m', value => $self->{warn_avg5m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning average (5min) threshold '" . $self->{warn_avg5m} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit_avg1m', value => $self->{crit_avg1m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical average (1min) threshold '" . $self->{crit_avg1m} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit_avg5m', value => $self->{crit_avg5m})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical average (5min) threshold '" . $self->{crit_avg5m} . "'."); - $self->{output}->option_exit(); - } - - if (($self->{perfdata}->threshold_validate(label => 'warning_current', value => $self->{option_results}->{warning_current})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning current threshold '" . $self->{option_results}->{warning_current} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical_current', value => $self->{option_results}->{critical_current})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical current threshold '" . $self->{option_results}->{critical_current} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_cufwConnGlobalNumActive = '.1.3.6.1.4.1.9.9.491.1.1.1.6.0'; - my $oid_cufwConnGlobalConnSetupRate1 = '.1.3.6.1.4.1.9.9.491.1.1.1.10.0'; - my $oid_cufwConnGlobalConnSetupRate5 = '.1.3.6.1.4.1.9.9.491.1.1.1.11.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_cufwConnGlobalNumActive, $oid_cufwConnGlobalConnSetupRate1, - $oid_cufwConnGlobalConnSetupRate5], nothing_quit => 1); - - my $exit1 = $self->{perfdata}->threshold_check(value => $result->{$oid_cufwConnGlobalConnSetupRate1}, - threshold => [ { label => 'crit_avg1m', 'exit_litteral' => 'critical' }, { label => 'warn_avg1m', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $result->{$oid_cufwConnGlobalConnSetupRate5}, - threshold => [ { label => 'crit_avg5m', 'exit_litteral' => 'critical' }, { label => 'warn_avg5m', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Average Connections per seconds: %d (last 1min), %d (last 5min)", - $result->{$oid_cufwConnGlobalConnSetupRate1}, $result->{$oid_cufwConnGlobalConnSetupRate5})); - - $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_cufwConnGlobalNumActive}, - threshold => [ { label => 'critical_current', 'exit_litteral' => 'critical' }, { label => 'warning_current', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Current active connections: %d", - $result->{$oid_cufwConnGlobalNumActive})); - - $self->{output}->perfdata_add(label => "connections_1m", unit => 'con/s', - value => $result->{$oid_cufwConnGlobalConnSetupRate1}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn_avg1m'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit_avg1m'), - min => 0); - $self->{output}->perfdata_add(label => "connections_5m", unit => 'con/s', - value => $result->{$oid_cufwConnGlobalConnSetupRate1}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn_avg1m'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit_avg1m'), - min => 0); - $self->{output}->perfdata_add(label => "connections_current", - value => $result->{$oid_cufwConnGlobalNumActive}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning_current'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical_current'), - min => 0); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check current/average connections on Cisco ASA (CISCO-UNIFIED-FIREWALL-MIB). - -=over 8 - -=item B<--warning-average> - -Threshold warning: averaged number of connections which the firewall establishing per second (1min,5min). - -=item B<--critical-average> - -Threshold critical: averaged number of connections which the firewall establishing per second (1min,5min). - -=item B<--warning-current> - -Threshold warning: number of connections which are currently active. - -=item B<--critical-current> - -Threshold critical: number of connections which are currently active. - -=back - -=cut - \ No newline at end of file diff --git a/centreon-plugins/network/cisco/asa/plugin.pm b/centreon-plugins/network/cisco/asa/plugin.pm index d87fbb019..09eaa3ba9 100644 --- a/centreon-plugins/network/cisco/asa/plugin.pm +++ b/centreon-plugins/network/cisco/asa/plugin.pm @@ -37,7 +37,7 @@ sub new { 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'memory' => 'centreon::common::cisco::standard::snmp::mode::memory', - 'sessions' => 'network::cisco::asa::mode::sessions', + 'sessions' => 'centreon::common::cisco::standard::snmp::mode::sessions', ); return $self; From 1db8008e52191774dbb025f504e34e3e9214156a Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 9 Feb 2016 13:26:05 +0100 Subject: [PATCH 09/17] + Fix MSSQL threshold for mode 'failed-jobs' --- centreon-plugins/database/mssql/mode/failedjobs.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/centreon-plugins/database/mssql/mode/failedjobs.pm b/centreon-plugins/database/mssql/mode/failedjobs.pm index 37e5740a6..dba5a75e9 100644 --- a/centreon-plugins/database/mssql/mode/failedjobs.pm +++ b/centreon-plugins/database/mssql/mode/failedjobs.pm @@ -66,11 +66,11 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning_duration})) == 0) { + if (($self->{perfdata}->threshold_validate(label => 'warning-duration', value => $self->{option_results}->{warning_duration})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong warning duration threshold '" . $self->{option_results}->{warning_duration} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical_duration})) == 0) { + if (($self->{perfdata}->threshold_validate(label => 'critical-duration', value => $self->{option_results}->{critical_duration})) == 0) { $self->{output}->add_option_msg(short_msg => "Wrong critical duration threshold '" . $self->{option_results}->{critical_duration} . "'."); $self->{output}->option_exit(); } @@ -132,7 +132,7 @@ sub run { $count_failed++; push (@job_failed, $job_name); } else { - my $exit_code1 = $self->{perfdata}->threshold_check(value => $run_duration, threshold => [ { label => 'critical_duration', 'exit_litteral' => 'critical' }, { label => 'warning_duration', exit_litteral => 'warning' } ]); + my $exit_code1 = $self->{perfdata}->threshold_check(value => $run_duration, threshold => [ { label => 'critical-duration', exit_litteral => 'critical' }, { label => 'warning-duration', exit_litteral => 'warning' } ]); if (!$self->{output}->is_status(value => $exit_code1, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit_code1, short_msg => sprintf("Job '%s' duration : %d minutes", $job_name, $run_duration)); @@ -141,7 +141,7 @@ sub run { $self->{output}->output_add(long_msg => sprintf("Job '%s' status %s [Runtime : %s %s] [Duration : %d minutes]", $job_name, $states{$run_status}, $run_date, $run_time, $run_duration)); } - my $exit_code2 = $self->{perfdata}->threshold_check(value => $count_failed, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit_code2 = $self->{perfdata}->threshold_check(value => $count_failed, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); if(!defined($self->{option_results}->{skip}) && $count == 0) { $self->{output}->output_add(severity => 'Unknown', short_msg => "No job found."); From 51fd1e94c9356e1a7c3c3dfee4c2745de5ebcc73 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 9 Feb 2016 14:00:20 +0100 Subject: [PATCH 10/17] + Fix #315 --- .../centreon/common/cisco/standard/snmp/mode/sessions.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm index 09a59e4ba..366285234 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/sessions.pm @@ -45,7 +45,7 @@ sub set_counters { }, { label => 'connections-1m', set => { key_values => [ { name => 'cufwConnGlobalConnSetupRate1' } ], - output_template => 'average last 1min %s', output_error_template => "average last 1min : %s", + output_template => 'average last 1min : %s', output_error_template => "average last 1min : %s", perfdatas => [ { label => 'connections_1m', value => 'cufwConnGlobalConnSetupRate1_absolute', template => '%d', min => 0 }, From 2c8206ad32841e4396e081e1209085978a994801 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 9 Feb 2016 15:24:18 +0100 Subject: [PATCH 11/17] + add plugin for emerson liebert pdu --- .../pdu/emerson/snmp/mode/globalstatus.pm | 206 ++++++++++++++++++ .../hardware/pdu/emerson/snmp/mode/psusage.pm | 167 ++++++++++++++ .../hardware/pdu/emerson/snmp/mode/rbusage.pm | 191 ++++++++++++++++ .../hardware/pdu/emerson/snmp/plugin.pm | 50 +++++ 4 files changed, 614 insertions(+) create mode 100644 centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm create mode 100644 centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm create mode 100644 centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm create mode 100644 centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm new file mode 100644 index 000000000..c9a747a3d --- /dev/null +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/globalstatus.pm @@ -0,0 +1,206 @@ +# +# 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 hardware::pdu::emerson::snmp::mode::globalstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_threshold_output { + 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 is '" . $self->{result_values}->{status} . "'"; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pdu', type => 1, cb_prefix_output => 'prefix_pdu_output', message_multiple => 'All PDU status are ok' } + ]; + + $self->{maps_counters}->{pdu} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + ]; +} + +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' }, + "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /normalWithWarning/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /normalWithAlarm|abnormalOperation/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_pdu_output { + my ($self, %options) = @_; + + return "PDU '" . $options{instance_value}->{display} . "' "; +} + +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 %bitmap_status = ( + 1 => 'normalOperation', + 2 => 'startUp', + 8 => 'normalWithWarning', + 16 => 'normalWithAlarm', + 32 => 'abnormalOperation', +); +my $mapping = { + lgpPduEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.10' }, + lgpPduEntrySysStatus => { oid => '.1.3.6.1.4.1.476.1.42.3.8.20.1.25' }, +}; +my $oid_lgpPduEntry = '.1.3.6.1.4.1.476.1.42.3.8.20.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{pdu} = {}; + $self->{results} = $options{snmp}->get_table(oid => $oid_lgpPduEntry, + start => $mapping->{lgpPduEntryUsrLabel}->{oid}, + end => $mapping->{lgpPduEntrySysStatus}->{oid}, + nothing_quit => 1); + + foreach my $oid (keys %{$self->{results}}) { + next if ($oid !~ /^$mapping->{lgpPduEntrySysStatus}->{oid}\.(.*)$/); + my $instance = $1; + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + my $name = defined($result->{lgpPduEntryUsrLabel}) && $result->{lgpPduEntryUsrLabel} ne '' ? + $result->{lgpPduEntryUsrLabel} : $instance; + my $status = 'unknow'; + foreach (keys %bitmap_status) { + if (($result->{lgpPduEntrySysStatus} & $_)) { + $status = $bitmap_status{$_}; + last; + } + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + + $self->{pdu}->{$instance} = { display => $name, + status => $status }; + } + + if (scalar(keys %{$self->{pdu}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Cannot found pdu."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check global status. + +=over 8 + +=item B<--filter-name> + +Filter PDU name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /normalWithWarning/i'). +Can used special variables like: %{status}, %{display}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /normalWithAlarm|abnormalOperation/i'). +Can used special variables like: %{status}, %{display} + +=back + +=cut diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm new file mode 100644 index 000000000..3e581086d --- /dev/null +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/psusage.pm @@ -0,0 +1,167 @@ +# +# 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 hardware::pdu::emerson::snmp::mode::psusage; + +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 => 'ps', type => 1, cb_prefix_output => 'prefix_ps_output', message_multiple => 'All power sources are ok' }, + ]; + + $self->{maps_counters}->{ps} = [ + { label => 'power', set => { + key_values => [ { name => 'PwrTotal' }, { name => 'display' } ], + output_template => 'total input power : %s W', output_error_template => "total input power : %s", + perfdatas => [ + { label => 'power', value => 'PwrTotal_absolute', template => '%s', + unit => 'W', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'energy', set => { + key_values => [ { name => 'EnergyAccum', diff => 1 }, { name => 'display' } ], + output_template => 'Total energy : %.3f kWh', output_error_template => "Total energy : %s", + perfdatas => [ + { label => 'energy', value => 'EnergyAccum_absolute', template => '%.3f', + unit => 'kWh', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-neutral', set => { + key_values => [ { name => 'EcNeutral' }, { name => 'display' } ], + output_template => 'Current neutral : %s Amp AC RMS', output_error_template => "Current neutral : %s", + perfdatas => [ + { label => 'current_neutral', value => 'EcNeutral_absolute', template => '%s', + unit => 'AmpAcRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_ps_output { + my ($self, %options) = @_; + + return "Power source '" . $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' }, + }); + + return $self; +} + +my $mapping = { + lgpPduPsEntrySysAssignLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.15' }, + lgpPduPsEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.50' }, # 0.1 Kilowatt-Hour + lgpPduPsEntryPwrTotal => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.65' }, # Watt + lgpPduPsEntryEcNeutral => { oid => '.1.3.6.1.4.1.476.1.42.3.8.30.20.1.70' }, # 0.1 Amp-AC-RMS +}; +my $oid_lgpPduEntryUsrLabel = '.1.3.6.1.4.1.476.1.42.3.8.20.1.10'; +my $oid_lgpPduPsEntry = '.1.3.6.1.4.1.476.1.42.3.8.30.20.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "pdu_emerson_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{ps} = {}; + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_lgpPduEntryUsrLabel }, + { oid => $oid_lgpPduPsEntry }, + ], + nothing_quit => 1); + foreach my $oid (keys %{$self->{results}->{$oid_lgpPduPsEntry}}) { + next if ($oid !~ /^$mapping->{lgpPduPsEntryPwrTotal}->{oid}\.(\d+)\.(\d+)/); + my ($pdu_index, $ps_index) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lgpPduPsEntry}, instance => $pdu_index . '.' . $ps_index); + my $pdu_name = defined($self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index}) && $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} ne '' ? + $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} : $pdu_index; + my $ps_name = defined($result->{lgpPduPsEntrySysAssignLabel}) && $result->{lgpPduPsEntrySysAssignLabel} ne '' ? + $result->{lgpPduPsEntrySysAssignLabel} : $ps_index; + my $name = $pdu_name . '/' . $ps_name; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + + $self->{ps}->{$pdu_index . '.' . $ps_index} = { display => $name, + EnergyAccum => $result->{lgpPduPsEntryEnergyAccum} * 0.1, + PwrTotal => $result->{lgpPduPsEntryPwrTotal}, + EcNeutral => $result->{lgpPduPsEntryEcNeutral} * 0.1}; + } + + if (scalar(keys %{$self->{ps}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Cannot found power sources."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check power source usage. + +=over 8 + +=item B<--filter-name> + +Filter power source name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^(power|energy)$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'power', 'energy', 'current-neutral'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'power', 'energy', 'current-neutral'. + +=back + +=cut diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm b/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm new file mode 100644 index 000000000..2de7a63d7 --- /dev/null +++ b/centreon-plugins/hardware/pdu/emerson/snmp/mode/rbusage.pm @@ -0,0 +1,191 @@ +# +# 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 hardware::pdu::emerson::snmp::mode::rbusage; + +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 => 'rb', type => 1, cb_prefix_output => 'prefix_rb_output', message_multiple => 'All receptacle branches are ok' }, + ]; + + $self->{maps_counters}->{rb} = [ + { label => 'energy', set => { + key_values => [ { name => 'EnergyAccum', diff => 1 }, { name => 'display' } ], + output_template => 'total energy : %.3f kWh', output_error_template => "total energy : %s", + perfdatas => [ + { label => 'energy', value => 'EnergyAccum_absolute', template => '%.3f', + unit => 'kWh', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-real-neutral', set => { + key_values => [ { name => 'Pwr' }, { name => 'display' } ], + output_template => 'line-to-neutral real power : %s W', output_error_template => "line-to-neutral real power : %s", + perfdatas => [ + { label => 'power_real_neutral', value => 'Pwr_absolute', template => '%s', + unit => 'W', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'power-apparent-neutral', set => { + key_values => [ { name => 'Ap' }, { name => 'display' } ], + output_template => 'line-to-neutral apparent power : %s VA', output_error_template => "line-to-neutral apparent power : %s", + perfdatas => [ + { label => 'power_apparent_neutral', value => 'Ap_absolute', template => '%s', + unit => 'VA', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'current-neutral', set => { + key_values => [ { name => 'EcHundredths' }, { name => 'display' } ], + output_template => 'line-to-neutral current : %s Amp AC RMS', output_error_template => "line-to-neutral current : %s", + perfdatas => [ + { label => 'current_neutral', value => 'EcHundredths_absolute', template => '%s', + unit => 'AmpAcRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'potential-neutral', set => { + key_values => [ { name => 'EpLNTenths' }, { name => 'display' } ], + output_template => 'line-to-neutral potential : %s VoltRMS', output_error_template => "line-to-neutral potential : %s", + perfdatas => [ + { label => 'potential_neutral', value => 'EpLNTenths_absolute', template => '%s', + unit => 'VoltRMS', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_rb_output { + my ($self, %options) = @_; + + return "Receptacle branch '" . $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' }, + }); + + return $self; +} + +my $mapping = { + lgpPduRbEntryUsrLabel => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.8' }, + lgpPduRbEntryEnergyAccum => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.85' }, # 0.1 Kilowatt-Hour + lgpPduRbEntryEpLNTenths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.100' }, # 0.1 VoltRMS + lgpPduRbEntryPwr => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.115' }, # Watt + lgpPduRbEntryAp => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.120' }, # VoltAmp + lgpPduRbEntryEcHundredths => { oid => '.1.3.6.1.4.1.476.1.42.3.8.40.20.1.130' }, # 0.01 Amp-AC-RMS +}; +my $oid_lgpPduEntryUsrLabel = '.1.3.6.1.4.1.476.1.42.3.8.20.1.10'; +my $oid_lgpPduRbEntry = '.1.3.6.1.4.1.476.1.42.3.8.40.20.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cache_name} = "pdu_emerson_" . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . $self->{mode} . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); + + $self->{rb} = {}; + $self->{results} = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_lgpPduEntryUsrLabel }, + { oid => $oid_lgpPduRbEntry }, + ], + nothing_quit => 1); + foreach my $oid (keys %{$self->{results}->{$oid_lgpPduRbEntry}}) { + next if ($oid !~ /^$mapping->{lgpPduRbEntryPwr}->{oid}\.(\d+)\.(\d+)/); + my ($pdu_index, $rb_index) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_lgpPduRbEntry}, instance => $pdu_index . '.' . $rb_index); + my $pdu_name = defined($self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index}) && $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} ne '' ? + $self->{results}->{$oid_lgpPduEntryUsrLabel}->{$oid_lgpPduEntryUsrLabel . '.' . $pdu_index} : $pdu_index; + my $rb_name = defined($result->{lgpPduRbEntryUsrLabel}) && $result->{lgpPduRbEntryUsrLabel} ne '' ? + $result->{lgpPduRbEntryUsrLabel} : $rb_index; + my $name = $pdu_name . '/' . $rb_name; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $name !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + + $self->{rb}->{$pdu_index . '.' . $rb_index} = { display => $name, + EnergyAccum => $result->{lgpPduRbEntryEnergyAccum} * 0.1, + EpLNTenths => $result->{lgpPduRbEntryEpLNTenths} * 0.1, + Pwr => $result->{lgpPduRbEntryPwr}, + Ap => $result->{lgpPduRbEntryAp}, + EcHundredths => $result->{lgpPduRbEntryEcHundredths} * 0.01}; + } + + if (scalar(keys %{$self->{rb}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "Cannot found receptacle branches."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check receptacle branch usage. + +=over 8 + +=item B<--filter-name> + +Filter receptacle branch name (can be a regexp). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^(energy)$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'energy', 'power-real-neutral', 'power-apparent-neutral', +'current-neutral', 'potential-neutral'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'energy', 'power-real-neutral', 'power-apparent-neutral', +'current-neutral', 'potential-neutral'. + +=back + +=cut diff --git a/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm b/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm new file mode 100644 index 000000000..f137dae18 --- /dev/null +++ b/centreon-plugins/hardware/pdu/emerson/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# 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 hardware::pdu::emerson::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}} = ( + 'global-status' => 'hardware::pdu::emerson::snmp::mode::globalstatus', + 'ps-usage' => 'hardware::pdu::emerson::snmp::mode::psusage', + 'rb-usage' => 'hardware::pdu::emerson::snmp::mode::rbusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Emerson Liebert PDU in SNMP. + +=cut From 69a0f3b4f74a1bde53b08eb43a1ccb36dca9922b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 10 Feb 2016 10:58:48 +0100 Subject: [PATCH 12/17] + Fix #245 --- .../common/cisco/standard/snmp/mode/components/fan.pm | 2 +- .../common/cisco/standard/snmp/mode/components/module.pm | 3 ++- .../common/cisco/standard/snmp/mode/components/physical.pm | 3 ++- .../common/cisco/standard/snmp/mode/components/psu.pm | 2 +- .../common/cisco/standard/snmp/mode/components/sensor.pm | 6 +++--- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm index d34d81215..a869a541b 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/fan.pm @@ -103,7 +103,7 @@ sub check_fan_entity { my $exit = $self->get_severity(section => 'fan', value => $result->{cefcFanTrayOperStatus}); 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.", $fan_descr, $result->{cefcFanTrayOperStatus})); + short_msg => sprintf("Fan '%s/%s' status is %s", $fan_descr, $instance, $result->{cefcFanTrayOperStatus})); } } } diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm index ba77b43c2..36987ed71 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/module.pm @@ -87,7 +87,8 @@ sub check { my $exit = $self->get_severity(section => 'module', value => $result->{cefcModuleOperStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Module '%s' status is %s", $module_descr, $result->{cefcModuleOperStatus})); + short_msg => sprintf("Module '%s/%s' status is %s", $module_descr, + $instance, $result->{cefcModuleOperStatus})); } } } diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm index 605779c82..debfd9d0f 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/physical.pm @@ -69,7 +69,8 @@ sub check { my $exit = $self->get_severity(section => 'physical', value => $result->{cefcPhysicalStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Physical '%s' status is %s", $physical_descr, $result->{cefcPhysicalStatus})); + short_msg => sprintf("Physical '%s/%s' status is %s", $physical_descr, + $instance, $result->{cefcPhysicalStatus})); } } } diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm index 9903a4a54..f92712a58 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/psu.pm @@ -119,7 +119,7 @@ sub check_psu_entity { my $exit = $self->get_severity(section => 'psu', value => $result->{cefcFRUPowerOperStatus}); 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.", $psu_descr, $result->{cefcFRUPowerOperStatus})); + short_msg => sprintf("Power supply '%s/%s' status is %s", $psu_descr, $instance, $result->{cefcFRUPowerOperStatus})); } } } diff --git a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm index 4aa241d87..8b0c93814 100644 --- a/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm +++ b/centreon-plugins/centreon/common/cisco/standard/snmp/mode/components/sensor.pm @@ -202,8 +202,8 @@ sub check { my $exit = $self->get_severity(section => $result->{entSensorType}, label => 'sensor', value => $result->{entSensorStatus}); if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Sensor '%s' status is '%s'", - $sensor_descr, $result->{entSensorStatus})); + short_msg => sprintf("Sensor '%s/%s' status is '%s'", + $sensor_descr, $instance, $result->{entSensorStatus})); } next if (!defined($result->{entSensorValue}) || $result->{entSensorValue} !~ /[0-9]/); @@ -222,7 +222,7 @@ sub check { } if (!$self->{output}->is_status(value => $exit2, compare => 'ok', litteral => 1)) { $self->{output}->output_add(severity => $exit2, - short_msg => sprintf("Sensor '%s' is %s %s", $sensor_descr, $result->{entSensorValue}, $perfdata_unit{$result->{entSensorType}})); + short_msg => sprintf("Sensor '%s/%s' is %s %s", $sensor_descr, $instance, $result->{entSensorValue}, $perfdata_unit{$result->{entSensorType}})); } $self->{output}->perfdata_add(label => $component . '_' . $sensor_descr, unit => $perfdata_unit{$result->{entSensorType}}, value => $result->{entSensorValue}, From 67407b3e3087a78e33bf062519f7d05853cdf7a4 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 10 Feb 2016 13:56:42 +0100 Subject: [PATCH 13/17] + Fix #15 --- .../apps/protocols/dns/lib/dns.pm | 2 +- .../apps/protocols/dns/mode/request.pm | 54 ++++++++++++++----- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/centreon-plugins/apps/protocols/dns/lib/dns.pm b/centreon-plugins/apps/protocols/dns/lib/dns.pm index 14b2e85c6..9416a313d 100644 --- a/centreon-plugins/apps/protocols/dns/lib/dns.pm +++ b/centreon-plugins/apps/protocols/dns/lib/dns.pm @@ -72,7 +72,7 @@ sub search { } } - return @results; + return sort @results; } sub connect { diff --git a/centreon-plugins/apps/protocols/dns/mode/request.pm b/centreon-plugins/apps/protocols/dns/mode/request.pm index ef27ffad9..f6511037c 100644 --- a/centreon-plugins/apps/protocols/dns/mode/request.pm +++ b/centreon-plugins/apps/protocols/dns/mode/request.pm @@ -26,6 +26,8 @@ use strict; use warnings; use Time::HiRes qw(gettimeofday tv_interval); use apps::protocols::dns::lib::dns; +use centreon::plugins::statefile; +use Digest::MD5 qw(md5_hex); sub new { my ($class, %options) = @_; @@ -40,11 +42,13 @@ sub new { "dns-options:s@" => { name => 'dns_options' }, "search:s" => { name => 'search' }, "search-type:s" => { name => 'search_type' }, - "search-field:s" => { name => 'search_field' }, "expected-answer:s" => { name => 'expected_answer' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, + "memory" => { name => 'memory' }, }); + + $self->{statefile_cache} = centreon::plugins::statefile->new(%options); return $self; } @@ -65,6 +69,21 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please set the search option"); $self->{output}->option_exit(); } + + if (defined($self->{option_results}->{memory})) { + $self->{cache_filename} = $self->{option_results}->{search}; + foreach (('search_type', 'search', 'nameservers')) { + $self->{cache_filename} .= '_'; + if (defined($self->{option_results}->{$_})) { + if (ref($self->{option_results}->{$_}) eq 'ARRAY') { + $self->{cache_filename} .= join('-', @{$self->{option_results}->{$_}}); + } else { + $self->{cache_filename} .= $self->{option_results}->{$_}; + } + } + } + $self->{statefile_cache}->check_options(%options); + } } sub run { @@ -79,7 +98,7 @@ sub run { my $result_str = join(', ', @results); my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, short_msg => sprintf("Response time %.3f second(s) (answer: %s)", $timeelapsed, $result_str)); $self->{output}->perfdata_add(label => "time", unit => 's', @@ -101,6 +120,21 @@ sub run { } } + if (defined($self->{option_results}->{memory})) { + $self->{statefile_cache}->read(statefile => 'cache_dns_' . md5_hex($self->{cache_filename})); + my $datas = { result => $result_str }; + my $old_result = $self->{statefile_cache}->get(name => "result"); + if (defined($old_result)) { + if ($old_result ne $result_str) { + $self->{output}->output_add(severity => 'CRITICAL', + short_msg => sprintf("Result has changed [answer: %s] [old answer: %s]", $result_str, $old_result)); + } + } else { + $self->{output}->output_add(long_msg => 'cache file created.'); + } + $self->{statefile_cache}->write(data => $datas); + } + $self->{output}->display(); $self->{output}->exit(); } @@ -136,14 +170,6 @@ Set the search value (required). Set the search type. Can be: 'MX', 'SOA', 'NS', 'A' or 'PTR'. 'A' or 'PTR' is used by default (depends if an IP or not). -=item B<--search-field> - -Set the search field used for 'expected-answer'. -By default: -'MX' is 'exchange', 'SOA' is 'mname', 'NS' is 'nsdname', -'A' is 'address' and 'PTR' is 'name'. -'A' or 'PTR' is used by default (depends if an IP or not). - =item B<--expected-answer> What the server must answer (can be a regexp). @@ -154,13 +180,17 @@ Add custom dns options. Example: --dns-options='debug=1' --dns-options='retry=2' --dns-options='port=972' --dns-options='recurse=0' ... +=item B<--memory> + +Critical threshold if the answer changed between two checks. + =item B<--warning> -Threshold warning in seconds +Threshold warning in seconds. =item B<--critical> -Threshold critical in seconds +Threshold critical in seconds. =back From 008f030443bee1cbc04daec8b79c08048077f6e1 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Wed, 10 Feb 2016 16:39:50 +0100 Subject: [PATCH 14/17] + Fix #286 --- .../ucopia/wlc/snmp/mode/temperature.pm | 111 ++++++++++++++++++ .../network/ucopia/wlc/snmp/mode/users.pm | 100 ++++++++++++++++ .../network/ucopia/wlc/snmp/plugin.pm | 50 ++++++++ 3 files changed, 261 insertions(+) create mode 100644 centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm create mode 100644 centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm create mode 100644 centreon-plugins/network/ucopia/wlc/snmp/plugin.pm diff --git a/centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm b/centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm new file mode 100644 index 000000000..56c704437 --- /dev/null +++ b/centreon-plugins/network/ucopia/wlc/snmp/mode/temperature.pm @@ -0,0 +1,111 @@ +# +# 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::ucopia::wlc::snmp::mode::temperature; + +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) = @_; + + my $oid_cpuTemperature = '.1.3.6.1.4.1.31218.3.3.0'; + my $oid_diskTemperature = '.1.3.6.1.4.1.31218.3.4.0'; + + my $result = $options{snmp}->get_leef(oids => [$oid_cpuTemperature, $oid_diskTemperature], nothing_quit => 1); + + if ($result->{$oid_cpuTemperature} != 0) { + my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_cpuTemperature}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("CPU Temp: %dC", $result->{$oid_cpuTemperature})); + $self->{output}->perfdata_add(value => $result->{$oid_cpuTemperature}, + label => 'cpu_temp', unit => 'C', + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + } + + if ($result->{$oid_diskTemperature} != 0) { + my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_diskTemperature}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("DISK Temp: %dC", $result->{$oid_diskTemperature})); + $self->{output}->perfdata_add(value => $result->{$oid_diskTemperature}, + label => 'disk_temp', unit => 'C', + 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 temperatures. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut + diff --git a/centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm b/centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm new file mode 100644 index 000000000..2be97c1c8 --- /dev/null +++ b/centreon-plugins/network/ucopia/wlc/snmp/mode/users.pm @@ -0,0 +1,100 @@ +# +# 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::ucopia::wlc::snmp::mode::users; + +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) = @_; + + my $oid_totalConnectedUsers = '.1.3.6.1.4.1.31218.3.1.0'; + my $oid_licenceUsers = '.1.3.6.1.4.1.31218.3.5.0'; + + my $result = $options{snmp}->get_leef(oids => [$oid_totalConnectedUsers, $oid_licenceUsers], nothing_quit => 1); + my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_totalConnectedUsers}, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $result->{$oid_licenceUsers} = undef if ($result->{$oid_licenceUsers} == 0); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("'%d' connected users (Available licence: %s)", + $result->{$oid_totalConnectedUsers}), + defined($result->{$oid_licenceUsers}) ? $result->{$oid_licenceUsers} : '-'); + $self->{output}->perfdata_add(value => $result->{$oid_totalConnectedUsers}, label => 'users', + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0, max => $result->{$oid_licenceUsers}); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check connected users. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=back + +=cut + diff --git a/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm b/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm new file mode 100644 index 000000000..daab7ca41 --- /dev/null +++ b/centreon-plugins/network/ucopia/wlc/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# 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::ucopia::wlc::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; + # $options->{options} = options object + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'temperature' => 'network::ucopia::wlc::snmp::mode::temperature', + 'users' => 'network::ucopia::wlc::snmp::mode::users', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Ucopia Wlc in SNMP. + +=cut From f30fad160b9a31362c6a90379344f6f1bfdb055b Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 11 Feb 2016 11:12:23 +0100 Subject: [PATCH 15/17] + Better memory snmp for freebsd --- .../os/freebsd/snmp/mode/memory.pm | 203 ++++++++++++++++++ centreon-plugins/os/freebsd/snmp/plugin.pm | 2 +- 2 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 centreon-plugins/os/freebsd/snmp/mode/memory.pm diff --git a/centreon-plugins/os/freebsd/snmp/mode/memory.pm b/centreon-plugins/os/freebsd/snmp/mode/memory.pm new file mode 100644 index 000000000..698e5f7be --- /dev/null +++ b/centreon-plugins/os/freebsd/snmp/mode/memory.pm @@ -0,0 +1,203 @@ +# +# 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 os::freebsd::snmp::mode::memory; + +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' }, + "swap" => { name => 'check_swap' }, + "warning-swap:s" => { name => 'warning_swap' }, + "critical-swap:s" => { name => 'critical_swap' }, + "no-swap:s" => { name => 'no_swap' }, + }); + $self->{no_swap} = '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(); + } + if (defined($self->{option_results}->{check_swap})) { + if (($self->{perfdata}->threshold_validate(label => 'warning-swap', value => $self->{option_results}->{warning_swap})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning-swap threshold '" . $self->{option_results}->{warning_swap} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical-swap', value => $self->{option_results}->{critical_swap})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical-swap threshold '" . $self->{option_results}->{critical_swap} . "'."); + $self->{output}->option_exit(); + } + if (defined($self->{option_results}->{no_swap}) && $self->{option_results}->{no_swap} ne '') { + if ($self->{output}->is_litteral_status(status => $self->{option_results}->{no_swap}) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong --no-swap status '" . $self->{option_results}->{no_swap} . "'."); + $self->{output}->option_exit(); + } + $self->{no_swap} = $self->{option_results}->{no_swap}; + } + } +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + # with bsnmpd-ucd 0.4.1 + my $oid_memTotalReal = '.1.3.6.1.4.1.2021.4.5.0'; # hw.physmem + my $oid_memAvailReal = '.1.3.6.1.4.1.2021.4.6.0'; # vm.stats.vm.v_free_count + my $oid_memShared = '.1.3.6.1.4.1.2021.4.13.0'; # not needed + my $oid_memBuffer = '.1.3.6.1.4.1.2021.4.14.0'; # vfs.bufspace (not needed) + my $oid_memCached = '.1.3.6.1.4.1.2021.4.15.0'; # vm.stats.vm.v_cache_count + vm.stats.vm.v_inactive_count + my $oid_memTotalSwap = '.1.3.6.1.4.1.2021.4.3.0'; # KB + my $oid_memAvailSwap = '.1.3.6.1.4.1.2021.4.4.0'; # KB + + my $oids = [$oid_memTotalReal, $oid_memAvailReal, + $oid_memShared, $oid_memBuffer, $oid_memCached]; + if (defined($self->{option_results}->{check_swap})) { + push @$oids, ($oid_memTotalSwap, $oid_memAvailSwap); + } + + my $result = $self->{snmp}->get_leef(oids => $oids, + nothing_quit => 1); + + my $cached_used = $result->{$oid_memCached} * 1024; + my $physical_used = ($result->{$oid_memTotalReal} * 1024) - ($result->{$oid_memAvailReal} * 1024); + # mem_available = total - mem_inactive - mem_cache - mem_free + # Maybe it's will be better to have have total with: total = 'active' + 'wired' + 'cache' + 'inactive' + 'free' + # But i can't have that with values from bsnmpd-ucd + my $nobuf_used = $physical_used - $cached_used; + + my $total_size = $result->{$oid_memTotalReal} * 1024; + + my $prct_used = $nobuf_used * 100 / $total_size; + my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); + my ($nobuf_value, $nobuf_unit) = $self->{perfdata}->change_bytes(value => $nobuf_used); + my ($cached_value, $cached_unit) = $self->{perfdata}->change_bytes(value => $cached_used); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Ram Total: %s, Used (-cache): %s (%.2f%%), Cached: %s", + $total_value . " " . $total_unit, + $nobuf_value . " " . $nobuf_unit, $prct_used, + $cached_value . " " . $cached_unit)); + + $self->{output}->perfdata_add(label => "cached", unit => 'B', + value => $cached_used, + min => 0); + $self->{output}->perfdata_add(label => "used", unit => 'B', + value => $nobuf_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', total => $total_size, cast_int => 1), + min => 0, max => $total_size); + + if (defined($self->{option_results}->{check_swap})) { + if ($result->{$oid_memTotalSwap} == 0) { + $self->{output}->output_add(severity => $self->{no_swap}, + short_msg => 'No active swap.'); + $self->{output}->display(); + $self->{output}->exit(); + } + + $total_size = $result->{$oid_memTotalSwap} * 1024; + my $swap_used = ($result->{$oid_memTotalSwap} - $result->{$oid_memAvailSwap}) * 1024; + + $prct_used = $swap_used * 100 / $total_size; + $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical-swap', 'exit_litteral' => 'critical' }, { label => 'warning-swap', exit_litteral => 'warning' } ]); + + my ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $total_size); + my ($swap_used_value, $swap_used_unit) = $self->{perfdata}->change_bytes(value => $swap_used); + my ($swap_free_value, $swap_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $swap_used)); + + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Swap Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_value . " " . $total_unit, + $swap_used_value . " " . $swap_used_unit, $prct_used, + $swap_free_value . " " . $swap_free_unit, (100 - $prct_used))); + + $self->{output}->perfdata_add(label => "swap", unit => 'B', + value => $swap_used, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-swap', total => $total_size, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-swap', total => $total_size, cast_int => 1), + min => 0, max => $total_size); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check physical memory (UCD-SNMP-MIB). + +=over 8 + +=item B<--warning> + +Threshold warning in percent. + +=item B<--critical> + +Threshold critical in percent. + +=item B<--swap> + +Check swap also. + +=item B<--warning-swap> + +Threshold warning in percent. + +=item B<--critical-swap> + +Threshold critical in percent. + +=item B<--no-swap> + +Threshold if no active swap (default: 'critical'). + +=back + +=cut diff --git a/centreon-plugins/os/freebsd/snmp/plugin.pm b/centreon-plugins/os/freebsd/snmp/plugin.pm index 1b0ac9867..136c4a9ec 100644 --- a/centreon-plugins/os/freebsd/snmp/plugin.pm +++ b/centreon-plugins/os/freebsd/snmp/plugin.pm @@ -42,7 +42,7 @@ sub new { 'list-diskspath' => 'snmp_standard::mode::listdiskspath', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-storages' => 'snmp_standard::mode::liststorages', - 'memory' => 'snmp_standard::mode::memory', + 'memory' => 'os::freebsd::snmp::mode::memory', 'processcount' => 'snmp_standard::mode::processcount', 'storage' => 'snmp_standard::mode::storage', 'swap' => 'snmp_standard::mode::swap', From 0afbb32bd796c6a557d5475e909c368b06ff82d5 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 11 Feb 2016 17:34:52 +0100 Subject: [PATCH 16/17] + Fix list-interfaces warn message --- .../snmp_standard/mode/listinterfaces.pm | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/centreon-plugins/snmp_standard/mode/listinterfaces.pm b/centreon-plugins/snmp_standard/mode/listinterfaces.pm index 511af60c2..c8634f78b 100644 --- a/centreon-plugins/snmp_standard/mode/listinterfaces.pm +++ b/centreon-plugins/snmp_standard/mode/listinterfaces.pm @@ -146,8 +146,10 @@ sub run { my $interface_speed = 0; if ($self->{no_speed} == 0) { - $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0 ? - ($result->{$oid_speed64 . "." . $_}) : (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000))); + $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0) ? + ($result->{$oid_speed64 . "." . $_}) : + (defined($result->{$oid_speed32 . "." . $_}) && $result->{$oid_speed32 . "." . $_} ne '' && $result->{$oid_speed32 . "." . $_} != 0 ? + (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000)) : ''); } if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; @@ -173,7 +175,9 @@ sub run { $extra_display_append = ', '; } - $self->{output}->output_add(long_msg => "'" . $display_value . "' [speed = $interface_speed, status = " . $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} . ', id = ' . $_ . $extra_display . ']'); + $self->{output}->output_add(long_msg => "'" . $display_value . "' [speed = $interface_speed, status = " . + (defined($result->{$self->{oid_opstatus} . "." . $_}) ? $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} : '') . + ', id = ' . $_ . $extra_display . ']'); } $self->{output}->output_add(severity => 'OK', @@ -283,8 +287,10 @@ sub disco_show { my $interface_speed = 0; if ($self->{no_speed} == 0) { - $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0 ? - ($result->{$oid_speed64 . "." . $_}) : (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000))); + $interface_speed = (defined($result->{$oid_speed64 . "." . $_}) && $result->{$oid_speed64 . "." . $_} ne '' && $result->{$oid_speed64 . "." . $_} != 0) ? + ($result->{$oid_speed64 . "." . $_}) : + (defined($result->{$oid_speed32 . "." . $_}) && $result->{$oid_speed32 . "." . $_} ne '' && $result->{$oid_speed32 . "." . $_} != 0 ? + (sprintf("%g", $result->{$oid_speed32 . "." . $_} / 1000 / 1000)) : ''); } if (defined($self->{option_results}->{speed}) && $self->{option_results}->{speed} ne '') { $interface_speed = $self->{option_results}->{speed}; @@ -302,7 +308,7 @@ sub disco_show { $self->{output}->add_disco_entry(name => $display_value, total => $interface_speed, - status => $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}}, + status => defined($result->{$self->{oid_opstatus} . "." . $_}) ? $self->{oid_opstatus_mapping}->{$result->{$self->{oid_opstatus} . "." . $_}} : '', interfaceid => $_, %extra_values); } From c1ee7544ac2be9a4caa4ace09421e85cd321b99e Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Fri, 12 Feb 2016 15:41:47 +0100 Subject: [PATCH 17/17] + Enhance cpu for cisco ironport --- .../network/cisco/ironport/snmp/mode/cpu.pm | 99 +++++++++---------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/centreon-plugins/network/cisco/ironport/snmp/mode/cpu.pm b/centreon-plugins/network/cisco/ironport/snmp/mode/cpu.pm index 78c3887e8..26f49cfa5 100644 --- a/centreon-plugins/network/cisco/ironport/snmp/mode/cpu.pm +++ b/centreon-plugins/network/cisco/ironport/snmp/mode/cpu.pm @@ -20,11 +20,39 @@ package network::cisco::ironport::snmp::mode::cpu; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ', skipped_code => { -10 => 1 } }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'mail', set => { + key_values => [ { name => 'perCentCPUUtilization' } ], + output_template => 'CPU Mail usage is: %.2f%%', + perfdatas => [ + { label => 'cpu_mail', value => 'perCentCPUUtilization_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'websecurity', set => { + key_values => [ { name => 'cacheCpuUsage' } ], + output_template => 'CPU WebSecurity usage is: %.2f%%', + perfdatas => [ + { label => 'cpu_websecurity', value => 'cacheCpuUsage_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -32,62 +60,24 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + { }); return $self; } -sub check_options { +sub manage_selection { 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(); + my %oids = ( + perCentCPUUtilization => '.1.3.6.1.4.1.15497.1.1.1.2.0', + cacheCpuUsage => '.1.3.6.1.4.1.15497.1.2.3.1.2.0', + ); + my $result = $options{snmp}->get_leef(oids => [values %oids], nothing_quit => 1); + $self->{global} = {}; + foreach (keys %oids) { + $self->{global}->{$_} = $result->{$oids{$_}} if (defined($result->{$oids{$_}})); } - 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{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my $oid_perCentCPUUtilization = '.1.3.6.1.4.1.15497.1.1.1.2.0'; - my $oid_cacheCpuUsage = '.1.3.6.1.4.1.15497.1.2.3.1.2.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_perCentCPUUtilization, $oid_cacheCpuUsage], nothing_quit => 1); - - if (defined($result->{$oid_perCentCPUUtilization})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_perCentCPUUtilization}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("CPU Mail usage is: %.2f%%", $result->{$oid_perCentCPUUtilization})); - $self->{output}->perfdata_add(label => 'cpu_mail', unit => '%', - value => sprintf("%.2f", $result->{$oid_perCentCPUUtilization}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - } - if (defined($result->{$oid_cacheCpuUsage})) { - my $exit_code = $self->{perfdata}->threshold_check(value => $result->{$oid_cacheCpuUsage}, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("CPU WebSecurity usage is: %.2f%%", $result->{$oid_cacheCpuUsage})); - $self->{output}->perfdata_add(label => 'cpu_websecurity', unit => '%', - value => sprintf("%.2f", $result->{$oid_cacheCpuUsage}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0, max => 100); - } - - $self->{output}->display(); - $self->{output}->exit(); } 1; @@ -97,16 +87,19 @@ __END__ =head1 MODE Check cpu usage of web security and mail (ASYNCOS-MAIL-MIB, ASYNCOSWEBSECURITYAPPLIANCE-MIB). +Use linux SNMP plugin for global CPU. =over 8 -=item B<--warning> +=item B<--warning-*> -Threshold warning in percent. +Threshold warning. +Can be: 'mail', 'websecurity'. -=item B<--critical> +=item B<--critical-*> -Threshold critical in percent. +Threshold critical. +Can be: 'mail', 'websecurity'. =back