diff --git a/apps/activedirectory/local/mode/netdom.pm b/apps/activedirectory/local/mode/netdom.pm index 636b2554c..6ae59e927 100644 --- a/apps/activedirectory/local/mode/netdom.pm +++ b/apps/activedirectory/local/mode/netdom.pm @@ -54,9 +54,9 @@ sub netdom { my $netdom_cmd = 'netdom verify '; $netdom_cmd .= ' /Domain:' . $self->{option_results}->{domain} if (defined($self->{option_results}->{domain}) && $self->{option_results}->{domain} ne ''); if (defined($self->{option_results}->{workstation})) { - $netdom_cmd .= ' ' . . $self->{option_results}->{workstation}; + $netdom_cmd .= ' ' . $self->{option_results}->{workstation}; } else { - $netdom_cmd .= ' ' . . Win32::NodeName(); + $netdom_cmd .= ' ' . Win32::NodeName(); } my ($stdout, $exit_code) = centreon::plugins::misc::windows_execute(output => $self->{output}, diff --git a/apps/antivirus/clamav/local/mode/updatestatus.pm b/apps/antivirus/clamav/local/mode/updatestatus.pm new file mode 100644 index 000000000..0e66b4891 --- /dev/null +++ b/apps/antivirus/clamav/local/mode/updatestatus.pm @@ -0,0 +1,391 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::antivirus::clamav::local::mode::updatestatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use Net::DNS; +use DateTime; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + my $label = $self->{label}; + $label =~ s/-/_/g; + if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'critical_' . $label}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'warning_' . $label}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_engine_status_output { + my ($self, %options) = @_; + my $msg = "clamav engine version '" . $self->{result_values}->{current_engine_version} . "/" . $self->{result_values}->{last_engine_version} . "'"; + + return $msg; +} + +sub custom_maindb_status_output { + my ($self, %options) = @_; + my $msg = "main.cvd version '" . $self->{result_values}->{current_maindb_version} . "/" . $self->{result_values}->{last_maindb_version} . + "', last update " . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{current_maindb_timediff}); + + return $msg; +} + +sub custom_dailydb_status_output { + my ($self, %options) = @_; + my $msg = "daily.cvd version '" . $self->{result_values}->{current_dailydb_version} . "/" . $self->{result_values}->{last_dailydb_version} . + "', last update " . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{current_dailydb_timediff}); + + return $msg; +} + +sub custom_engine_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{current_engine_version} = $options{new_datas}->{$self->{instance} . '_current_engine_version'}; + $self->{result_values}->{last_engine_version} = $options{new_datas}->{$self->{instance} . '_last_engine_version'}; + return 0; +} + +sub custom_maindb_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{current_maindb_version} = $options{new_datas}->{$self->{instance} . '_current_maindb_version'}; + $self->{result_values}->{last_maindb_version} = $options{new_datas}->{$self->{instance} . '_last_maindb_version'}; + $self->{result_values}->{current_maindb_timediff} = $options{new_datas}->{$self->{instance} . '_current_maindb_timediff'}; + return 0; +} + +sub custom_dailydb_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{current_dailydb_version} = $options{new_datas}->{$self->{instance} . '_current_dailydb_version'}; + $self->{result_values}->{last_dailydb_version} = $options{new_datas}->{$self->{instance} . '_last_dailydb_version'}; + $self->{result_values}->{current_dailydb_timediff} = $options{new_datas}->{$self->{instance} . '_current_dailydb_timediff'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'update', type => 0, message_separator => ' - ' }, + ]; + + $self->{maps_counters}->{update} = [ + { label => 'engine-status', threshold => 0, set => { + key_values => [ { name => 'last_engine_version' }, { name => 'current_engine_version' } ], + closure_custom_calc => $self->can('custom_engine_status_calc'), + closure_custom_output => $self->can('custom_engine_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'maindb-status', threshold => 0, set => { + key_values => [ { name => 'last_maindb_version' }, { name => 'current_maindb_version' }, { name => 'current_maindb_timediff' } ], + closure_custom_calc => $self->can('custom_maindb_status_calc'), + closure_custom_output => $self->can('custom_maindb_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'dailydb-status', threshold => 0, set => { + key_values => [ { name => 'last_dailydb_version' }, { name => 'current_dailydb_version' }, { name => 'current_dailydb_timediff' } ], + closure_custom_calc => $self->can('custom_dailydb_status_calc'), + closure_custom_output => $self->can('custom_dailydb_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "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' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + "warning-engine-status:s" => { name => 'warning_engine_status', default => '' }, + "critical-engine-status:s" => { name => 'critical_engine_status', default => '%{last_engine_version} ne %{current_engine_version}' }, + "warning-maindb-status:s" => { name => 'warning_maindb_status', default => '' }, + "critical-maindb-status:s" => { name => 'critical_maindb_status', default => '%{last_maindb_version} ne %{current_maindb_version}' }, + "warning-dailydb-status:s" => { name => 'warning_dailydb_status', default => '' }, + "critical-dailydb-status:s" => { name => 'critical_dailydb_status', default => '%{last_dailydb_version} ne %{current_dailydb_version} || %{current_dailydb_timediff} > 432000' }, + "nameservers:s@" => { name => 'nameservers' }, + "maindb-file:s" => { name => 'maindb_file', default => '/var/lib/clamav/main.cvd' }, + "dailydb-file:s" => { name => 'dailydb_file', default => '/var/lib/clamav/daily.cvd' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_engine_status', 'critical_engine_status', 'warning_maindb_status', 'critical_maindb_status', 'warning_dailydb_status', 'critical_dailydb_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } + + $self->{clamav_command} = 'echo "==== CLAMD ===" ; clamd -V ; echo "==== DAILY ===="; sigtool --info ' . $self->{option_results}->{dailydb_file} . '; echo "==== MAIN ====" ; sigtool --info ' . $self->{option_results}->{maindb_file}; +} + +sub get_clamav_last_update { + my ($self, %options) = @_; + + #0.99.2:57:23114:1487851834:1:63:45614:290 + # field 2 = main.cvd version number + # field 3 = daily.cvd version number + my $nameservers = []; + if (defined($self->{option_results}->{nameservers})) { + $nameservers = [@{$self->{option_results}->{nameservers}}]; + } + my $handle = Net::DNS::Resolver->new( + nameservers => $nameservers + ); + my $txt_query = $handle->query("current.cvd.clamav.net", "TXT"); + if (!$txt_query) { + $self->{output}->add_option_msg(short_msg => "Unable to get TXT Record : " . $handle->errorstring . "."); + $self->{output}->option_exit(); + } + + my @fields = split /:/, ($txt_query->answer)[0]->txtdata; + ($self->{last_engine_version}, $self->{last_maindb_version}, $self->{last_dailydb_version}) = + ($fields[0], $fields[1], $fields[2]); +} + +sub get_clamav_current_signature_info { + my ($self, %options) = @_; + + if ($options{content} !~ /====\s+$options{label}.*?Build\s+time:\s+(.*?)\n.*?Version:\s+(\d+)/msi) { + return ; + } + + $self->{'current_' . $options{label} . 'db_version'} = $2; + #13 Jun 2016 09:53 -0400 + my $time = $1; + if ($time =~ /^\s*(\d+)\s+(\S+)\s+(\d+)\s+(\d+):(\d+)\s+(\S+)/) { + my %months = ("Jan" => 1, "Feb" => 2, "Mar" => 3, "Apr" => 4, "May" => 5, "Jun" => 6, "Jul" => 7, "Aug" => 8, "Sep" => 9, "Oct" => 10, "Nov" => 11, "Dec" => 12); + my $dt = DateTime->new( + year => $3, + month => $months{$2}, + day => $1, + hour => $4, + minute => $5, + second => 0, + time_zone => $6, + ); + $self->{'current_' . $options{label} . 'db_timediff'} = time() - $dt->epoch; + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->get_clamav_last_update(); + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{clamav_command}, + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef); + #==== CLAMD === + #ClamAV 0.99.2/21723/Mon Jun 13 14:53:00 2016 + #==== DAILY ==== + #File: /var/lib/clamav/daily.cvd + #Build time: 13 Jun 2016 09:53 -0400 + #Version: 21723 + #Signatures: 276682 + #Functionality level: 63 + #Builder: neo + #MD5: 280928f25d175359e6e6a0270d9d4fb2 + #Digital signature: yLfcgb9dbgKO2rWpXGa238252jqH7VDsAjnqQsHc+9cbIwiM9wnz3fqyl33G15S4YsMbRR6CYbSTxccKXBJvvxRhgZQJmpCYiThslUKBPo5QhIFcI1QBMfoHKCpf8riB2/xAgI401UkZVJip+6eWFpUJ9aeaFai+Mvinif5BRzi + #LibClamAV Warning: ************************************************** + #LibClamAV Warning: *** The virus database is older than 7 days! *** + #LibClamAV Warning: *** Please update it as soon as possible. *** + #LibClamAV Warning: ************************************************** + #Verification OK. + #==== MAIN ==== + #File: /var/lib/clamav/main.cvd + #Build time: 16 Mar 2016 23:17 +0000 + #Version: 57 + #Signatures: 4218790 + #Functionality level: 60 + #Builder: amishhammer + #MD5: 06386f34a16ebeea2733ab037f0536be + #Digital signature: AIzk/LYbX8K9OEbR5GMyJ6LWTqSu9ffa5bONcA0FN3+onMlZ2BMRzuyvVURBvAZvOaGPdtMBcgDJSl7fGxDfcxRWhIrQ98f8FPdAQaFPgWu3EX46ufw+IRZnM4irKKYuh1GdCIbsGs6jejWo9iNErsbDqkFSobVBkUJYxBgvqfd + #Verification OK. + + + $self->get_clamav_current_signature_info(label => 'daily', content => $stdout); + $self->get_clamav_current_signature_info(label => 'main', content => $stdout); + if ($stdout =~ /==== CLAMD.*?ClamAV (.*?)\//msi) { + $self->{current_engine_version} = $1; + } + + $self->{update} = { + last_engine_version => $self->{last_engine_version}, last_maindb_version => $self->{last_maindb_version}, last_dailydb_version => $self->{last_dailydb_version}, + current_engine_version => $self->{current_engine_version}, + current_maindb_version => $self->{current_maindb_version}, current_maindb_timediff => $self->{current_maindb_timediff}, + current_dailydb_version => $self->{current_dailydb_version}, current_dailydb_timediff => $self->{current_dailydb_timediff}, + }; +} + +1; + +__END__ + +=head1 MODE + +Check antivirus update status. + +=over 8 + +=item B<--nameservers> + +Set nameserver to query (can be multiple). +The system configuration is used by default. + +=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. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options (Default: '-report -most_columns'). + +=item B<--maindb-file> + +Antivirus main.cvd file (Default: '/var/lib/clamav/main.cvd'). + +=item B<--dailydb-file> + +Antivirus daily.cvd file (Default: '/var/lib/clamav/daily.cvd'). + +=item B<--warning-engine-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{last_engine_version}, %{current_engine_version} + +=item B<--critical-engine-status> + +Set critical threshold for status (Default: '%{last_engine_version} ne %{current_engine_version}'). +Can used special variables like: %{last_engine_version}, %{current_engine_version} + +=item B<--warning-maindb-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{last_maindb_version}, %{current_maindb_version}, %{current_maindb_timediff} + +=item B<--critical-maindb-status> + +Set critical threshold for status (Default: '%{last_maindb_version} ne %{current_maindb_version}'). +Can used special variables like: %{last_maindb_version}, %{current_maindb_version}, %{current_maindb_timediff} + +=item B<--warning-dailydb-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{last_dailydb_version}, %{current_dailydb_version}, %{current_dailydb_timediff} + +=item B<--critical-dailydb-status> + +Set critical threshold for status (Default: '%{last_dailydb_version} ne %{current_dailydb_version} || %{current_dailydb_timediff} > 432000'). +Can used special variables like: %{last_dailydb_version}, %{current_dailydb_version}, %{current_dailydb_timediff} + +=back + +=cut diff --git a/apps/antivirus/clamav/local/plugin.pm b/apps/antivirus/clamav/local/plugin.pm new file mode 100644 index 000000000..5125468ce --- /dev/null +++ b/apps/antivirus/clamav/local/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::antivirus::clamav::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; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'update-status' => 'apps::antivirus::clamav::local::mode::updatestatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check ClamAV Antivirus through local commands (the plugin can use SSH). + +=cut diff --git a/apps/backup/netbackup/local/mode/listpolicies.pm b/apps/backup/netbackup/local/mode/listpolicies.pm index de2e58336..34a87420d 100644 --- a/apps/backup/netbackup/local/mode/listpolicies.pm +++ b/apps/backup/netbackup/local/mode/listpolicies.pm @@ -110,7 +110,7 @@ sub manage_selection { my @lines = split /\n/, $stdout; foreach my $policy_name (@lines) { my $command2 = $self->{option_results}->{command2}; - $command2 =~ s/%{policy_name}/$policy_name/g; + $command2 =~ s/%\{policy_name\}/$policy_name/g; my ($stdout2) = centreon::plugins::misc::execute(output => $self->{output}, options => $self->{option_results}, sudo => $self->{option_results}->{sudo}, diff --git a/apps/centreon/local/mode/retentionbroker.pm b/apps/centreon/local/mode/retentionbroker.pm index d0c0f2003..5f064ca3e 100644 --- a/apps/centreon/local/mode/retentionbroker.pm +++ b/apps/centreon/local/mode/retentionbroker.pm @@ -76,7 +76,7 @@ sub run { my ($self, %options) = @_; $self->{output}->output_add(severity => 'OK', - short_msg => 'centreon-broker failover files and tempory are ok'); + short_msg => 'centreon-broker failover/temporary files are ok'); my $total_size = 0; foreach my $config (@{$self->{option_results}->{broker_config}}) { diff --git a/apps/centreon/sql/mode/dsmqueue.pm b/apps/centreon/sql/mode/dsmqueue.pm new file mode 100644 index 000000000..a1a582b36 --- /dev/null +++ b/apps/centreon/sql/mode/dsmqueue.pm @@ -0,0 +1,165 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::centreon::sql::mode::dsmqueue; + +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 }, + { name => 'host', type => 1, cb_prefix_output => 'prefix_host_output', message_multiple => 'All host queues are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-queue-cache', set => { + key_values => [ { name => 'total_queue_cache' } ], + output_template => 'Total current cache queue : %s', + perfdatas => [ + { label => 'total_queue_cache', value => 'total_queue_cache_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'total-queue-lock', set => { + key_values => [ { name => 'total_queue_lock' } ], + output_template => 'Total current lock queue : %s', + perfdatas => [ + { label => 'total_queue_lock', value => 'total_queue_lock_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{host} = [ + { label => 'host-queue-cache', set => { + key_values => [ { name => 'num' }, { name => 'display' } ], + output_template => 'current cache queue : %s', + perfdatas => [ + { label => 'host_queue_cache', value => 'num_absolute', template => '%s', + min => 0, label_extra_instance => 1 }, + ], + } + }, + ]; +} + +sub prefix_host_output { + my ($self, %options) = @_; + + return "Host '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-host-queue:s" => { name => 'filter_host_queue' }, + "centreon-storage-database:s" => { name => 'centreon_storage_database', default => 'centreon_storage' }, + "centreon-database:s" => { name => 'centreon_database', default => 'centreon' }, + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $options{sql}->connect(); + + $self->{global} = { total_queue_cache => 0, total_queue_lock => 0 }; + my $query = "SELECT COUNT(*) as nb FROM " . $self->{option_results}->{centreon_storage_database} . ".mod_dsm_cache"; + $options{sql}->query(query => $query); + if ((my $row = $options{sql}->fetchrow_hashref())) { + $self->{global}->{total_queue_cache} = $row->{nb}; + } + + $query = "SELECT COUNT(*) as nb FROM " . $self->{option_results}->{centreon_storage_database} . ".mod_dsm_locks"; + $options{sql}->query(query => $query); + if ((my $row = $options{sql}->fetchrow_hashref())) { + $self->{global}->{total_queue_lock} = $row->{nb}; + } + + # check by poller + $self->{host} = {}; + $query = "SELECT mod_dsm_pool.pool_host_id, mod_dsm_pool.pool_prefix, COUNT(*) as nb FROM " . $self->{option_results}->{centreon_database} . ".mod_dsm_pool" . + " LEFT JOIN " . $self->{option_results}->{centreon_storage_database} . ".mod_dsm_cache ON mod_dsm_pool.pool_host_id = mod_dsm_cache.host_id AND mod_dsm_pool.pool_prefix = mod_dsm_cache.pool_prefix" . + " GROUP BY mod_dsm_pool.pool_host_id, mod_dsm_pool.pool_prefix"; + $options{sql}->query(query => $query); + while ((my $row = $options{sql}->fetchrow_hashref())) { + my $name = $row->{pool_host_id} . '/' . $row->{pool_prefix}; + if (defined($self->{option_results}->{filter_host_queue}) && $self->{option_results}->{filter_host_queue} ne '' && + $name !~ /$self->{option_results}->{filter_host_queue}/) { + $self->{output}->output_add(long_msg => "Skipping '" . $row->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{host}->{$name} = { display => $name, num => $row->{nb} }; + } +} + +1; + +__END__ + +=head1 MODE + +Check Centreon DSM queue usage. + +=over 8 + +=item B<--centreon-storage-database> + +Centreon storage database name (default: 'centreon_storage'). + +=item B<--centreon-database> + +Centreon storage database name (default: 'centreon'). + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^total-queue-cache$' + +=item B<--warning-*> + +Threshold warning. +Can be: Can be: 'total-queue-cache', 'total-queue-lock', 'host-queue-cache'. + +=item B<--critical-*> + +Threshold critical. +Can be: Can be: 'total-queue-cache', 'total-queue-lock', 'host-queue-cache'. + +=item B<--filter-host-queue> + +Filter by host and pool prefix name (regexp can be used). +Example: host1.queue1 + +=back + +=cut diff --git a/apps/centreon/sql/mode/virtualservice.pm b/apps/centreon/sql/mode/virtualservice.pm index 0e37b40e3..a84ec2ec4 100644 --- a/apps/centreon/sql/mode/virtualservice.pm +++ b/apps/centreon/sql/mode/virtualservice.pm @@ -92,12 +92,18 @@ sub custom_metric_calc { $self->{result_values}->{min} = $options{new_datas}->{$self->{instance} . '_min'}; $self->{result_values}->{max} = $options{new_datas}->{$self->{instance} . '_max'}; - my $change_bytes_global = ($config_data->{formatting}->{change_bytes} eq 'true'); - my $change_bytes_metric_filter = (defined($config_data->{filters}->{formatting}->{change_bytes}) && $config_data->{filters}->{formatting}->{change_bytes} eq 'true'); - my $change_bytes_metric_selection = (defined($config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{change_bytes}) - && $config_data->{selection}->{$self->{result_values}->{instance}}->{formatting}->{change_bytes} eq 'true'); + my $elem = $self->{result_values}->{type} eq 'unique' ? 'selection' : 'virtualcurve'; + my ($change_bytes_metric_selection, $change_bytes_metric_filter); + if (defined($config_data->{filters}->{formatting}->{change_bytes})) { + $change_bytes_metric_filter = $config_data->{filters}->{formatting}->{change_bytes}; + } + if (defined($config_data->{$elem}->{$self->{result_values}->{instance}}->{formatting}->{change_bytes})) { + $change_bytes_metric_selection = $config_data->{$elem}->{$self->{result_values}->{instance}}->{formatting}->{change_bytes}; + } - if ($change_bytes_global && ($change_bytes_metric_filter || $change_bytes_metric_selection)) { + if ((defined($change_bytes_metric_selection) && $change_bytes_metric_selection) || + (defined($change_bytes_metric_filter) && $change_bytes_metric_filter) || + ($config_data->{formatting}->{change_bytes} && !defined($change_bytes_metric_selection) && !defined($change_bytes_metric_filter))) { ($self->{result_values}->{value}, $self->{result_values}->{unit}) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{value}); } return 0; @@ -138,10 +144,10 @@ sub set_counters { $self->{maps_counters}->{global} = [ { label => 'global', set => { key_values => [ { name => 'value' }, { name => 'display' }, { name => 'type' }, { name => 'unit' }, { name => 'min' }, { name => 'max' } ], - closure_custom_calc => \&custom_metric_calc, - closure_custom_output => \&custom_metric_output, - closure_custom_perfdata => \&custom_metric_perfdata, - closure_custom_threshold_check => \&custom_metric_threshold, + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), } } ]; @@ -149,10 +155,10 @@ sub set_counters { $self->{maps_counters}->{metric} = [ { label => 'metric', set => { key_values => [ { name => 'value' }, { name => 'display' }, { name => 'type' }, { name => 'unit' }, { name => 'min' }, { name => 'max' } ], - closure_custom_calc => \&custom_metric_calc, - closure_custom_output => \&custom_metric_output, - closure_custom_perfdata => \&custom_metric_perfdata, - closure_custom_threshold_check => \&custom_metric_threshold, + closure_custom_calc => $self->can('custom_metric_calc'), + closure_custom_output => $self->can('custom_metric_output'), + closure_custom_perfdata => $self->can('custom_metric_perfdata'), + closure_custom_threshold_check => $self->can('custom_metric_threshold'), } } ]; @@ -199,8 +205,7 @@ sub check_options { $config_data->{formatting}->{custom_message_global} = "Global metrics are OK" if (!exists($config_data->{formatting}->{custom_message_global})); $config_data->{formatting}->{custom_message_metric} = "All metrics are OK" if (!exists($config_data->{formatting}->{custom_message_metric})); $config_data->{formatting}->{cannonical_separator} = "#" if (!exists($config_data->{formatting}->{cannonical_separator})); - $config_data->{formatting}->{change_bytes} = 'false' if (!exists($config_data->{formatting}->{change_bytes})); - + $config_data->{formatting}->{change_bytes} = 0 if (!exists($config_data->{formatting}->{change_bytes})); } sub parse_json_config { @@ -250,19 +255,19 @@ sub manage_selection { foreach my $id (keys %{$config_data->{selection}}) { my $query = "SELECT index_data.host_name, index_data.service_description, metrics.metric_name, metrics.current_value, metrics.unit_name, metrics.min, metrics.max "; $query .= "FROM centreon_storage.index_data, centreon_storage.metrics WHERE index_data.id = metrics.index_id "; - $query .= "AND index_data.service_description = '" . $config_data->{selection}{$id}->{service_name} . "'"; - $query .= "AND index_data.host_name = '" . $config_data->{selection}{$id}->{host_name} . "'" ; - $query .= "AND metrics.metric_name = '" . $config_data->{selection}{$id}->{metric_name} . "'"; + $query .= "AND index_data.service_description = '" . $config_data->{selection}->{$id}->{service_name} . "'"; + $query .= "AND index_data.host_name = '" . $config_data->{selection}->{$id}->{host_name} . "'" ; + $query .= "AND metrics.metric_name = '" . $config_data->{selection}->{$id}->{metric_name} . "'"; $self->{sql}->query(query => $query); while ((my $row = $self->{sql}->fetchrow_hashref())) { my $metric_key = $id; - $self->{metrics}->{$metric_key}{name} = $row->{metric_name}; - $self->{metrics}->{$metric_key}{display_name} = $id; - $self->{metrics}->{$metric_key}{current} = $row->{current_value}; - $self->{metrics}->{$metric_key}{unit} = defined($row->{unit_name}) ? $row->{unit_name} : ''; - $self->{metrics}->{$metric_key}{min} = defined($row->{min}) ? $row->{min} : ''; - $self->{metrics}->{$metric_key}{max} = defined($row->{max}) ? $row->{max} : ''; - $self->{metrics}->{$metric_key}{display} = (defined($config_data->{selection}{$id}->{display}) && $config_data->{selection}{$id}->{display} eq 'true') ? 1 : 0; + $self->{metrics}->{$metric_key} = { name => $row->{metric_name} }; + $self->{metrics}->{$metric_key}->{display_name} = $id; + $self->{metrics}->{$metric_key}->{current} = $row->{current_value}; + $self->{metrics}->{$metric_key}->{unit} = defined($row->{unit_name}) ? $row->{unit_name} : ''; + $self->{metrics}->{$metric_key}->{min} = defined($row->{min}) ? $row->{min} : ''; + $self->{metrics}->{$metric_key}->{max} = defined($row->{max}) ? $row->{max} : ''; + $self->{metrics}->{$metric_key}->{display} = (defined($config_data->{selection}->{$id}->{display}) && $config_data->{selection}->{$id}->{display}) ? 1 : 0; } } } elsif (exists($config_data->{filters})) { @@ -277,70 +282,70 @@ sub manage_selection { $self->{sql}->query(query => $query); while ((my $row = $self->{sql}->fetchrow_hashref())) { my $metric_key = $row->{host_name}.$config_data->{formatting}->{cannonical_separator}.$row->{service_description}.$config_data->{formatting}->{cannonical_separator}.$row->{metric_name}; - $self->{metrics}->{$metric_key}{display_name} = $metric_key; - $self->{metrics}->{$metric_key}{name} = $row->{metric_name}; - $self->{metrics}->{$metric_key}{current} = $row->{current_value}; - $self->{metrics}->{$metric_key}{unit} = defined($row->{unit_name}) ? $row->{unit_name} : ''; - $self->{metrics}->{$metric_key}{min} = defined($row->{min}) ? $row->{min} : ''; - $self->{metrics}->{$metric_key}{max} = defined($row->{max}) ? $row->{max} : ''; - $self->{metrics}->{$metric_key}{display} = (defined($config_data->{filters}->{display})) ? 1 : 0; + $self->{metrics}->{$metric_key} = { display_name => $metric_key}; + $self->{metrics}->{$metric_key}->{name} = $row->{metric_name}; + $self->{metrics}->{$metric_key}->{current} = $row->{current_value}; + $self->{metrics}->{$metric_key}->{unit} = defined($row->{unit_name}) ? $row->{unit_name} : ''; + $self->{metrics}->{$metric_key}->{min} = defined($row->{min}) ? $row->{min} : ''; + $self->{metrics}->{$metric_key}->{max} = defined($row->{max}) ? $row->{max} : ''; + $self->{metrics}->{$metric_key}->{display} = (defined($config_data->{filters}->{display}) && $config_data->{filters}->{display}) ? 1 : 0; } } foreach my $metric (keys %{$self->{metrics}}) { - foreach my $vcurve (keys %{$config_data->{virtualcurve}}) { - if (defined($config_data->{virtualcurve}{$vcurve}->{pattern}) && $config_data->{virtualcurve}{$vcurve}->{pattern} ne '') { - push (@{$self->{vmetrics}->{$vcurve}->{values}}, $self->{metrics}->{$metric}->{current}) if $self->{metrics}->{$metric}->{name} =~ /$config_data->{virtualcurve}{$vcurve}->{pattern}/; - } else { - push (@{$self->{vmetrics}->{$vcurve}->{values}}, $self->{metrics}->{$metric}->{current}); - } + foreach my $vcurve (keys %{$config_data->{virtualcurve}}) { + $self->{vmetrics}->{$vcurve}->{values} = [] if (!defined($self->{vmetrics}->{$vcurve}->{values})); + if (defined($config_data->{virtualcurve}->{$vcurve}->{pattern}) && $config_data->{virtualcurve}->{$vcurve}->{pattern} ne '') { + push (@{$self->{vmetrics}->{$vcurve}->{values}}, $self->{metrics}->{$metric}->{current}) if $self->{metrics}->{$metric}->{name} =~ /$config_data->{virtualcurve}{$vcurve}->{pattern}/; + } else { + push (@{$self->{vmetrics}->{$vcurve}->{values}}, $self->{metrics}->{$metric}->{current}); + } - next if (!defined(@{$self->{vmetrics}->{$vcurve}{values}})); + next if (scalar(@{$self->{vmetrics}->{$vcurve}->{values}}) == 0); - $self->{vmetrics}->{$vcurve}{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - sum(@{$self->{vmetrics}->{$vcurve}{values}})/scalar(@{$self->{vmetrics}->{$vcurve}{values}})) if ($config_data->{virtualcurve}{$vcurve}->{aggregation} eq 'avg'); - $self->{vmetrics}->{$vcurve}{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - sum(@{$self->{vmetrics}->{$vcurve}{values}})) if ($config_data->{virtualcurve}{$vcurve}->{aggregation} eq 'sum'); - $self->{vmetrics}->{$vcurve}{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - min(@{$self->{vmetrics}->{$vcurve}{values}})) if ($config_data->{virtualcurve}{$vcurve}->{aggregation} eq 'min'); - $self->{vmetrics}->{$vcurve}{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, - max(@{$self->{vmetrics}->{$vcurve}{values}})) if ($config_data->{virtualcurve}{$vcurve}->{aggregation} eq 'max'); - $self->{vmetrics}->{$vcurve}{aggregated_value} = eval "$self->{vmetrics}->{$vcurve}{aggregated_value} $config_data->{virtualcurve}->{$vcurve}{custom}" if (defined($config_data->{virtualcurve}->{$vcurve}{custom})); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, + sum(@{$self->{vmetrics}->{$vcurve}->{values}})/scalar(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'avg'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, + sum(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'sum'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, + min(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'min'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = sprintf($config_data->{formatting}->{printf_metric_value}, + max(@{$self->{vmetrics}->{$vcurve}->{values}})) if ($config_data->{virtualcurve}->{$vcurve}->{aggregation} eq 'max'); + $self->{vmetrics}->{$vcurve}->{aggregated_value} = eval "$self->{vmetrics}->{$vcurve}->{aggregated_value} $config_data->{virtualcurve}->{$vcurve}->{custom}" if (defined($config_data->{virtualcurve}->{$vcurve}->{custom})); - $self->{vmetrics}->{$vcurve}{unit} = (defined($config_data->{virtualcurve}{$vcurve}->{unit})) ? $config_data->{virtualcurve}{$vcurve}->{unit} : ''; - $self->{vmetrics}->{$vcurve}{min} = (defined($config_data->{virtualcurve}{$vcurve}->{min})) ? $config_data->{virtualcurve}{$vcurve}->{min} : ''; - $self->{vmetrics}->{$vcurve}{max} = (defined($config_data->{virtualcurve}{$vcurve}->{max})) ? $config_data->{virtualcurve}{$vcurve}->{max} : ''; + $self->{vmetrics}->{$vcurve}->{unit} = (defined($config_data->{virtualcurve}->{$vcurve}->{unit})) ? $config_data->{virtualcurve}->{$vcurve}->{unit} : ''; + $self->{vmetrics}->{$vcurve}->{min} = (defined($config_data->{virtualcurve}->{$vcurve}->{min})) ? $config_data->{virtualcurve}->{$vcurve}->{min} : ''; + $self->{vmetrics}->{$vcurve}->{max} = (defined($config_data->{virtualcurve}->{$vcurve}->{max})) ? $config_data->{virtualcurve}->{$vcurve}->{max} : ''; - if (defined($self->{option_results}->{'warning-global'}) || defined($config_data->{virtualcurve}->{$vcurve}->{warning})) { + if (defined($self->{option_results}->{'warning-global'}) || defined($config_data->{virtualcurve}->{$vcurve}->{warning})) { $self->{perfdata}->threshold_validate(label => 'warning-global-'.$vcurve, value => (defined($self->{option_results}->{'warning-global'})) ? $self->{option_results}->{'warning-global'} : $config_data->{virtualcurve}->{$vcurve}->{warning}); - } - if (defined($self->{option_results}->{'critical-global'}) || defined($config_data->{virtualcurve}->{$vcurve}->{critical})) { + } + if (defined($self->{option_results}->{'critical-global'}) || defined($config_data->{virtualcurve}->{$vcurve}->{critical})) { $self->{perfdata}->threshold_validate(label => 'critical-global-'.$vcurve, value => (defined($self->{option_results}->{'critical-global'})) ? $self->{option_results}->{'critical-global'} : $config_data->{virtualcurve}->{$vcurve}->{critical}); - } + } - $self->{global}->{$vcurve} = {display => $vcurve, - type => 'global', - unit => $self->{vmetrics}->{$vcurve}->{unit}, - value => $self->{vmetrics}->{$vcurve}->{aggregated_value}, - min => $self->{vmetrics}->{$vcurve}->{min}, - max => $self->{vmetrics}->{$vcurve}->{max} }; + $self->{global}->{$vcurve} = {display => $vcurve, + type => 'global', + unit => $self->{vmetrics}->{$vcurve}->{unit}, + value => $self->{vmetrics}->{$vcurve}->{aggregated_value}, + min => $self->{vmetrics}->{$vcurve}->{min}, + max => $self->{vmetrics}->{$vcurve}->{max} }; } - $self->{metric}->{$metric} = {display => $self->{metrics}->{$metric}->{display_name}, - type => 'unique', - unit => $self->{metrics}->{$metric}->{unit}, - value => $self->{metrics}->{$metric}->{current}, - min => $self->{metrics}->{$metric}->{min}, - max => $self->{metrics}->{$metric}->{max} } if ($self->{metrics}->{$metric}->{display} == 1); + $self->{metric}->{$metric} = {display => $self->{metrics}->{$metric}->{display_name}, + type => 'unique', + unit => $self->{metrics}->{$metric}->{unit}, + value => $self->{metrics}->{$metric}->{current}, + min => $self->{metrics}->{$metric}->{min}, + max => $self->{metrics}->{$metric}->{max} } if ($self->{metrics}->{$metric}->{display} == 1); } if (scalar(keys %{$self->{metric}}) <= 0 && scalar(keys %{$self->{vmetrics}}) <= 0) { $self->{output}->add_option_msg(short_msg => "No metrics returned - are your selection/filters correct ?"); $self->{output}->option_exit(); } - } 1 diff --git a/apps/hyperv/2012/local/mode/nodeintegrationservice.pm b/apps/hyperv/2012/local/mode/nodeintegrationservice.pm index 14771f6f0..49042c056 100644 --- a/apps/hyperv/2012/local/mode/nodeintegrationservice.pm +++ b/apps/hyperv/2012/local/mode/nodeintegrationservice.pm @@ -38,11 +38,13 @@ sub custom_status_threshold { 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}") { + my $label = $self->{label}; + $label =~ s/-/_/g; + if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'critical_' . $label}") { $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && - eval "$instance_mode->{option_results}->{warning_status}") { + } elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'warning_' . $label}") { $status = 'warning'; } }; @@ -53,14 +55,14 @@ sub custom_status_threshold { return $status; } -sub custom_status_output { +sub custom_service_status_output { my ($self, %options) = @_; my $msg = 'status : ' . $self->{result_values}->{primary_status} . '/' . $self->{result_values}->{secondary_status}; return $msg; } -sub custom_status_calc { +sub custom_service_status_calc { my ($self, %options) = @_; $self->{result_values}->{primary_status} = $options{new_datas}->{$self->{instance} . '_primary_status'}; @@ -70,20 +72,48 @@ sub custom_status_calc { return 0; } +sub custom_global_status_output { + my ($self, %options) = @_; + my $msg = 'state/version : ' . $self->{result_values}->{integration_service_state} . '/' . $self->{result_values}->{integration_service_version}; + + return $msg; +} + +sub custom_global_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{integration_service_state} = $options{new_datas}->{$self->{instance} . '_integration_service_state'}; + $self->{result_values}->{integration_service_version} = $options{new_datas}->{$self->{instance} . '_integration_service_version'}; + $self->{result_values}->{vm} = $options{new_datas}->{$self->{instance} . '_vm'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + return 0; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ { name => 'vm', type => 2, cb_prefix_output => 'prefix_vm_output', cb_long_output => 'vm_long_output', message_multiple => 'All integration services are ok', - group => [ { name => 'service', cb_prefix_output => 'prefix_service_output' } ] + group => [ { name => 'global', cb_prefix_output => 'prefix_global_output' }, { name => 'service', cb_prefix_output => 'prefix_service_output' } ] } ]; + $self->{maps_counters}->{global} = [ + { label => 'global-status', threshold => 0, set => { + key_values => [ { name => 'integration_service_state' }, { name => 'integration_service_version' }, { name => 'state' }, { name => 'vm' } ], + closure_custom_calc => $self->can('custom_global_status_calc'), + closure_custom_output => $self->can('custom_global_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; + $self->{maps_counters}->{service} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'primary_status' }, { name => 'secondary_status' }, { name => 'vm' }, { name => 'service' } ], - closure_custom_calc => $self->can('custom_status_calc'), - closure_custom_output => $self->can('custom_status_output'), + { label => 'service-status', threshold => 0, set => { + key_values => [ { name => 'primary_status' }, { name => 'secondary_status' }, { name => 'enabled' }, { name => 'vm' }, { name => 'service' } ], + closure_custom_calc => $self->can('custom_service_status_calc'), + closure_custom_output => $self->can('custom_service_status_output'), closure_custom_perfdata => sub { return 0; }, closure_custom_threshold_check => $self->can('custom_status_threshold'), } @@ -94,7 +124,7 @@ sub set_counters { sub vm_long_output { my ($self, %options) = @_; - return "checking policy '" . $options{instance_value}->{display} . "'"; + return "checking virtual machine '" . $options{instance_value}->{display} . "'"; } sub prefix_vm_output { @@ -109,6 +139,12 @@ sub prefix_service_output { return "integration service '" . $options{instance_value}->{service} . "' "; } +sub prefix_global_output { + my ($self, %options) = @_; + + return "global virtual machine '" . $options{instance_value}->{vm} . "' integration service "; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -125,8 +161,10 @@ sub new { "ps-exec-only" => { name => 'ps_exec_only' }, "filter-vm:s" => { name => 'filter_vm' }, "filter-status:s" => { name => 'filter_status', default => 'running' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{primary_status} !~ /Ok/i' }, + "warning-global-status:s" => { name => 'warning_global_status', default => '%{integration_service_state} =~ /Update required/i' }, + "critical-global-status:s" => { name => 'critical_global_status', default => '' }, + "warning-service-status:s" => { name => 'warning_service_status', default => '' }, + "critical-service-status:s" => { name => 'critical_service_status', default => '%{primary_status} !~ /Ok/i' }, }); return $self; } @@ -142,7 +180,7 @@ sub check_options { sub change_macros { my ($self, %options) = @_; - foreach (('warning_status', 'critical_status')) { + foreach (('warning_service_status', 'critical_service_status', 'warning_global_status', 'critical_global_status')) { if (defined($self->{option_results}->{$_})) { $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; } @@ -167,29 +205,23 @@ sub manage_selection { $self->{output}->exit(); } - #[name= test1 ][state= Running ] - #[service= Time Synchronization ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Heartbeat ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Key-Value Pair Exchange ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Shutdown ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= VSS ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Guest Service Interface ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] - #[service= Time Synchronization ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] - #[service= Heartbeat ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= Ok ] - #[service= Key-Value Pair Exchange ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] - #[service= Shutdown ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] - #[service= VSS ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] - #[service= Guest Service Interface ][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] - #[name= test2 ][state= Running ] - #[service= Time Synchronization ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Heartbeat ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Key-Value Pair Exchange ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] - #[service= Shutdown ][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[name= test1 ][state= Running ][IntegrationServicesState= Update required ][IntegrationServicesVersion= 3.1 ] + #[service= Time Synchronization ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Heartbeat ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Key-Value Pair Exchange ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Shutdown ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= VSS ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Guest Service Interface ][enabled= False][primaryOperationalStatus= Ok ][secondaryOperationalStatus= ] + #[name= test2 ][state= Running ][IntegrationServicesState= ][IntegrationServicesVersion= ] + #[service= Time Synchronization ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Heartbeat ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Key-Value Pair Exchange ][enabled= True][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] + #[service= Shutdown ][enabled= False][primaryOperationalStatus= NoContact ][secondaryOperationalStatus= ] $self->{vm} = {}; my $id = 1; - while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) { - my ($name, $status, $content) = ($1, $2, $3); + while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[IntegrationServicesState=\s*(.*?)\s*\]\[IntegrationServicesVersion=\s*(.*?)\s*\](.*?)(?=\[name=|\z)/msig) { + my ($name, $status, $integration_service_state, $integration_service_version, $content) = ($1, $2, $3, $4, $5); if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' && $name !~ /$self->{option_results}->{filter_vm}/i) { @@ -202,10 +234,13 @@ sub manage_selection { next; } - $self->{vm}->{$id} = { display => $name, service => {} }; + $self->{vm}->{$id} = { display => $name, vm => $name, service => {} }; + $self->{vm}->{$id}->{global} = { + $name => { vm => $name, integration_service_state => $integration_service_state, integration_service_version => $integration_service_version, state => $status } + }; my $id2 = 1; - while ($content =~ /^\[service=\s*(.*?)\s*\]\[primaryOperationalStatus=\s*(.*?)\s*\]\[secondaryOperationalStatus=\s*(.*?)\s*\]/msig) { - $self->{vm}->{$id}->{service}->{$id2} = { vm => $name, service => $1, primary_status => $2, secondary_status => $3 }; + while ($content =~ /^\[service=\s*(.*?)\s*\]\[enabled=\s*(.*?)\s*\]\[primaryOperationalStatus=\s*(.*?)\s*\]\[secondaryOperationalStatus=\s*(.*?)\s*\]/msig) { + $self->{vm}->{$id}->{service}->{$id2} = { vm => $name, service => $1, enabled => $2, primary_status => $3, secondary_status => $4 }; $id2++; } @@ -256,15 +291,27 @@ Filter virtual machine status (can be a regexp) (Default: 'running'). Filter virtual machines (can be a regexp). -=item B<--warning-status> +=item B<--warning-global-status> + +Set warning threshold for status (Default: '%{integration_service_state} =~ /Update required/i'). +Can used special variables like: %{vm}, %{integration_service_state}, +%{integration_service_version}, %{state} + +=item B<--critical-global-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{vm}, %{integration_service_state}, +%{integration_service_version}, %{state} + +=item B<--warning-service-status> Set warning threshold for status (Default: ''). -Can used special variables like: %{vm}, %{service}, %{primary_status}, %{secondary_status} +Can used special variables like: %{vm}, %{service}, %{primary_status}, %{secondary_status}, %{enabled} -=item B<--critical-status> +=item B<--critical-service-status> Set critical threshold for status (Default: '%{primary_status} !~ /Ok/i'). -Can used special variables like: %{vm}, %{service}, %{primary_status}, %{secondary_status} +Can used special variables like: %{vm}, %{service}, %{primary_status}, %{secondary_status}, %{enabled} =back diff --git a/apps/hyperv/2012/local/mode/nodereplication.pm b/apps/hyperv/2012/local/mode/nodereplication.pm new file mode 100644 index 000000000..53ebe6f9f --- /dev/null +++ b/apps/hyperv/2012/local/mode/nodereplication.pm @@ -0,0 +1,224 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::hyperv::2012::local::mode::nodereplication; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::common::powershell::hyperv::2012::nodereplication; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'replication health : ' . $self->{result_values}->{health}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{vm} = $options{new_datas}->{$self->{instance} . '_vm'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{health} = $options{new_datas}->{$self->{instance} . '_health'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' }, + ]; + $self->{maps_counters}->{vm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'vm' }, { name => 'state' }, { name => 'health' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_vm_output { + my ($self, %options) = @_; + + return "VM '" . $options{instance_value}->{vm} . "' "; +} + +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 => + { + "timeout:s" => { name => 'timeout', default => 50 }, + "command:s" => { name => 'command', default => 'powershell.exe' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + "no-ps" => { name => 'no_ps' }, + "ps-exec-only" => { name => 'ps_exec_only' }, + "filter-vm:s" => { name => 'filter_vm' }, + "warning-status:s" => { name => 'warning_status', default => '%{health} =~ /Warning/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{health} =~ /Critical/i' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $ps = centreon::common::powershell::hyperv::2012::nodereplication::get_powershell(no_ps => $self->{option_results}->{no_ps}); + + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + if (defined($self->{option_results}->{ps_exec_only})) { + $self->{output}->output_add(severity => 'OK', + short_msg => $stdout); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + #[name= XXXX1 ][state= Running ][health= Critical ] + #[name= XXXX2 ][state= Running ][health= Normal ] + #[name= XXXX3 ][state= Running ][health= Warning ] + $self->{vm} = {}; + + my $id = 1; + while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[health=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) { + my ($name, $status, $health) = ($1, $2, $3); + + if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' && + $name !~ /$self->{option_results}->{filter_vm}/i) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + + $self->{vm}->{$id} = { display => $name, vm => $name, state => $status, health => $health }; + $id++; + } +} + +1; + +__END__ + +=head1 MODE + +Check virtual machine replication on hyper-v node. + +=over 8 + +=item B<--timeout> + +Set timeout time for command execution (Default: 50 sec) + +=item B<--no-ps> + +Don't encode powershell. To be used with --command and 'type' command. + +=item B<--command> + +Command to get information (Default: 'powershell.exe'). +Can be changed if you have output in a file. To be used with --no-ps option!!! + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). + +=item B<--ps-exec-only> + +Print powershell output. + +=item B<--filter-vm> + +Filter virtual machines (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{health} =~ /Warning/i'). +Can used special variables like: %{vm}, %{state}, %{health} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{health} =~ /Critical/i'). +Can used special variables like: %{vm}, %{state}, %{health} + +=back + +=cut \ No newline at end of file diff --git a/apps/hyperv/2012/local/mode/nodevmstatus.pm b/apps/hyperv/2012/local/mode/nodevmstatus.pm new file mode 100644 index 000000000..4749f4cfe --- /dev/null +++ b/apps/hyperv/2012/local/mode/nodevmstatus.pm @@ -0,0 +1,225 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::hyperv::2012::local::mode::nodevmstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::common::powershell::hyperv::2012::nodevmstatus; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status} . " (state: " . $self->{result_values}->{state} . ", is clustered: " . $self->{result_values}->{is_clustered} . ")"; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{vm} = $options{new_datas}->{$self->{instance} . '_vm'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{is_clustered} = $options{new_datas}->{$self->{instance} . '_is_clustered'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' }, + ]; + $self->{maps_counters}->{vm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'vm' }, { name => 'state' }, { name => 'status' }, { name => 'is_clustered' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_vm_output { + my ($self, %options) = @_; + + return "VM '" . $options{instance_value}->{vm} . "' "; +} + +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 => + { + "timeout:s" => { name => 'timeout', default => 50 }, + "command:s" => { name => 'command', default => 'powershell.exe' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + "no-ps" => { name => 'no_ps' }, + "ps-exec-only" => { name => 'ps_exec_only' }, + "filter-vm:s" => { name => 'filter_vm' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Operating normally/i' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $ps = centreon::common::powershell::hyperv::2012::nodevmstatus::get_powershell(no_ps => $self->{option_results}->{no_ps}); + + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + if (defined($self->{option_results}->{ps_exec_only})) { + $self->{output}->output_add(severity => 'OK', + short_msg => $stdout); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + #[name= XXXX1 ][state= Running ][status= Operating normally ][IsClustered= True ] + #[name= XXXX2 ][state= Running ][status= Operating normally ][IsClustered= False ] + #[name= XXXX3 ][state= Running ][status= Operating normally ][IsClustered= False ] + $self->{vm} = {}; + + my $id = 1; + while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[state=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[IsClustered=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) { + my ($name, $state, $status, $is_clustered) = ($1, $2, $3, $4); + + if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' && + $name !~ /$self->{option_results}->{filter_vm}/i) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + + $self->{vm}->{$id} = { display => $name, vm => $name, status => $status, state => $state, is_clustered => $is_clustered }; + $id++; + } +} + +1; + +__END__ + +=head1 MODE + +Check virtual machine status on hyper-v node. + +=over 8 + +=item B<--timeout> + +Set timeout time for command execution (Default: 50 sec) + +=item B<--no-ps> + +Don't encode powershell. To be used with --command and 'type' command. + +=item B<--command> + +Command to get information (Default: 'powershell.exe'). +Can be changed if you have output in a file. To be used with --no-ps option!!! + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). + +=item B<--ps-exec-only> + +Print powershell output. + +=item B<--filter-vm> + +Filter virtual machines (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{vm}, %{state}, %{status}, %{is_clustered} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Operating normally/i'). +Can used special variables like: %{vm}, %{state}, %{status}, %{is_clustered} + +=back + +=cut \ No newline at end of file diff --git a/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm b/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm index 7528386b6..fbaf574c5 100644 --- a/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm +++ b/apps/hyperv/2012/local/mode/scvmmintegrationservice.pm @@ -181,15 +181,18 @@ sub manage_selection { while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[description=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\]\[VMAddition=\s*(.*?)\s*\]/msig) { my %values = (vm => $1, description => $2, status => $3, cloud => $4, hostgroup => $5, vmaddition => $6); + $values{hostgroup} =~ s/\\/\//g; + my $filtered = 0; foreach (('name', 'description', 'status', 'hostgroup')) { if (defined($self->{option_results}->{'filter_' . $_}) && $self->{option_results}->{'filter_' . $_} ne '' && $values{$_} !~ /$self->{option_results}->{'filter_' . $_}/i) { $self->{output}->output_add(long_msg => "skipping '" . $values{$_} . "': no matching filter.", debug => 1); - next; + $filtered = 1; + last; } } - $self->{vm}->{$id} = { %values }; + $self->{vm}->{$id} = { %values } if ($filtered == 0); $id++; } } diff --git a/apps/hyperv/2012/local/mode/scvmmsnapshot.pm b/apps/hyperv/2012/local/mode/scvmmsnapshot.pm index 7e2b7f2bc..16db4947b 100644 --- a/apps/hyperv/2012/local/mode/scvmmsnapshot.pm +++ b/apps/hyperv/2012/local/mode/scvmmsnapshot.pm @@ -92,7 +92,7 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Need to specify --" . $label_opt . " option."); $self->{output}->option_exit(); } - } + } } sub manage_selection { @@ -131,6 +131,7 @@ sub manage_selection { } next if ($chkpt == -1); + $hg =~ s/\\/\//g; if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' && $name !~ /$self->{option_results}->{filter_vm}/i) { $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); diff --git a/apps/hyperv/2012/local/mode/scvmmvmstatus.pm b/apps/hyperv/2012/local/mode/scvmmvmstatus.pm new file mode 100644 index 000000000..bcfa068ec --- /dev/null +++ b/apps/hyperv/2012/local/mode/scvmmvmstatus.pm @@ -0,0 +1,267 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::hyperv::2012::local::mode::scvmmvmstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use centreon::plugins::misc; +use centreon::common::powershell::hyperv::2012::scvmmvmstatus; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{vm} = $options{new_datas}->{$self->{instance} . '_vm'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{hostgroup} = $options{new_datas}->{$self->{instance} . '_hostgroup'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vm', type => 1, cb_prefix_output => 'prefix_vm_output', message_multiple => 'All virtual machines are ok' }, + ]; + $self->{maps_counters}->{vm} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'vm' }, { name => 'hostgroup' }, { name => 'status' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_vm_output { + my ($self, %options) = @_; + + return "VM '" . $options{instance_value}->{vm} . "' "; +} + +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 => + { + "scvmm-hostname:s" => { name => 'scvmm_hostname' }, + "scvmm-username:s" => { name => 'scvmm_username' }, + "scvmm-password:s" => { name => 'scvmm_password' }, + "scvmm-port:s" => { name => 'scvmm_port', default => 8100 }, + "timeout:s" => { name => 'timeout', default => 50 }, + "command:s" => { name => 'command', default => 'powershell.exe' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-InputFormat none -NoLogo -EncodedCommand' }, + "no-ps" => { name => 'no_ps' }, + "ps-exec-only" => { name => 'ps_exec_only' }, + "filter-vm:s" => { name => 'filter_vm' }, + "filter-hostgroup:s" => { name => 'filter_hostgroup' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /Running|Stopped/i' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + foreach my $label (('scvmm_hostname', 'scvmm_username', 'scvmm_password', 'scvmm_port')) { + if (!defined($self->{option_results}->{$label}) || $self->{option_results}->{$label} eq '') { + my ($label_opt) = $label; + $label_opt =~ tr/_/-/; + $self->{output}->add_option_msg(short_msg => "Need to specify --" . $label_opt . " option."); + $self->{output}->option_exit(); + } + } + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + my $ps = centreon::common::powershell::hyperv::2012::scvmmvmstatus::get_powershell( + scvmm_hostname => $self->{option_results}->{scvmm_hostname}, + scvmm_username => $self->{option_results}->{scvmm_username}, + scvmm_password => $self->{option_results}->{scvmm_password}, + scvmm_port => $self->{option_results}->{scvmm_port}, + no_ps => $self->{option_results}->{no_ps}); + + $self->{option_results}->{command_options} .= " " . $ps; + my ($stdout) = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $self->{option_results}->{command_options}); + if (defined($self->{option_results}->{ps_exec_only})) { + $self->{output}->output_add(severity => 'OK', + short_msg => $stdout); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); + } + + #[name= test-server ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server ] + #[name= test-server2 ][status= Running ][cloud= ][hostgrouppath= All Hosts\CORP\Test\test-server2 ] + $self->{vm} = {}; + + my $id = 1; + while ($stdout =~ /^\[name=\s*(.*?)\s*\]\[status=\s*(.*?)\s*\]\[cloud=\s*(.*?)\s*\]\[hostgrouppath=\s*(.*?)\s*\].*?(?=\[name=|\z)/msig) { + my ($name, $status, $cloud, $hg) = ($1, $2, $3, $4); + + $hg =~ s/\\/\//g; + if (defined($self->{option_results}->{filter_vm}) && $self->{option_results}->{filter_vm} ne '' && + $name !~ /$self->{option_results}->{filter_vm}/i) { + $self->{output}->output_add(long_msg => "skipping '" . $name . "': no matching filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_hostgroup}) && $self->{option_results}->{filter_hostgroup} ne '' && + $hg !~ /$self->{option_results}->{filter_hostgroup}/i) { + $self->{output}->output_add(long_msg => "skipping '" . $hg . "': no matching filter.", debug => 1); + next; + } + + $self->{vm}->{$id} = { display => $name, vm => $name, status => $status, hostgroup => $hg }; + $id++; + } +} + +1; + +__END__ + +=head1 MODE + +Check virtual machine status on SCVMM. + +=over 8 + +=item B<--scvmm-hostname> + +SCVMM hostname (Required). + +=item B<--scvmm-username> + +SCVMM username (Required). + +=item B<--scvmm-password> + +SCVMM password (Required). + +=item B<--scvmm-port> + +SCVMM port (Default: 8100). + +=item B<--timeout> + +Set timeout time for command execution (Default: 50 sec) + +=item B<--no-ps> + +Don't encode powershell. To be used with --command and 'type' command. + +=item B<--command> + +Command to get information (Default: 'powershell.exe'). +Can be changed if you have output in a file. To be used with --no-ps option!!! + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '-InputFormat none -NoLogo -EncodedCommand'). + +=item B<--ps-exec-only> + +Print powershell output. + +=item B<--filter-vm> + +Filter virtual machines (can be a regexp). + +=item B<--filter-hostgroup> + +Filter hostgroup (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{vm}, %{status}, %{hostgroup} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /Running|Stopped/i'). +Can used special variables like: %{vm}, %{status}, %{hostgroup} + +=back + +=cut \ No newline at end of file diff --git a/apps/hyperv/2012/local/plugin.pm b/apps/hyperv/2012/local/plugin.pm index be7e389ed..31eb8492c 100644 --- a/apps/hyperv/2012/local/plugin.pm +++ b/apps/hyperv/2012/local/plugin.pm @@ -33,8 +33,11 @@ sub new { %{$self->{modes}} = ( 'scvmm-integration-service' => 'apps::hyperv::2012::local::mode::scvmmintegrationservice', 'scvmm-snapshot' => 'apps::hyperv::2012::local::mode::scvmmsnapshot', + 'scvmm-vm-status' => 'apps::hyperv::2012::local::mode::scvmmvmstatus', 'node-integration-service' => 'apps::hyperv::2012::local::mode::nodeintegrationservice', + 'node-replication' => 'apps::hyperv::2012::local::mode::nodereplication', 'node-snapshot' => 'apps::hyperv::2012::local::mode::nodesnapshot', + 'node-vm-status' => 'apps::hyperv::2012::local::mode::nodevmstatus', ); return $self; diff --git a/apps/inin/mediaserver/snmp/mode/audioengineusage.pm b/apps/inin/mediaserver/snmp/mode/audioengineusage.pm new file mode 100644 index 000000000..23a47056d --- /dev/null +++ b/apps/inin/mediaserver/snmp/mode/audioengineusage.pm @@ -0,0 +1,146 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::inin::mediaserver::snmp::mode::audioengineusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'engine', type => 1, cb_prefix_output => 'prefix_engine_output', message_multiple => 'All audio engines are ok' } + ]; + + $self->{maps_counters}->{engine} = [ + { label => 'avg-load', set => { + key_values => [ { name => 'i3MsAudioEngineAverageLoad' }, { name => 'display' } ], + output_template => 'Average Load : %s', + perfdatas => [ + { label => 'load_avg', value => 'i3MsAudioEngineAverageLoad_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'elem-count', set => { + key_values => [ { name => 'i3MsAudioEngineElementCount' }, { name => 'display' } ], + output_template => 'Total active graph elements : %s', + perfdatas => [ + { label => 'elem_count', value => 'i3MsAudioEngineElementCount_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_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 => + { + "filter-location:s" => { name => 'filter_location' }, + }); + + return $self; +} + +sub prefix_engine_output { + my ($self, %options) = @_; + + return "Audio Engine '" . $options{instance_value}->{display} . "' "; +} + +my $mapping = { + i3MsAudioEngineLocation => { oid => '.1.3.6.1.4.1.2793.8227.2.1.1.4' }, + i3MsAudioEngineAverageLoad => { oid => '.1.3.6.1.4.1.2793.8227.2.1.1.6' }, + i3MsAudioEngineElementCount => { oid => '.1.3.6.1.4.1.2793.8227.2.1.1.8' }, +}; + +my $oid_i3MsAudioEngineInfoTableEntry = '.1.3.6.1.4.1.2793.8227.2.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{engine} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_i3MsAudioEngineInfoTableEntry, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{i3MsAudioEngineLocation}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_location}) && $self->{option_results}->{filter_location} ne '' && + $result->{i3MsAudioEngineLocation} !~ /$self->{option_results}->{filter_location}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{i3MsAudioEngineLocation} . "': no matching filter.", debug => 1); + next; + } + + $self->{engine}->{$instance} = { display => $result->{i3MsAudioEngineLocation}, + %$result + }; + } + + if (scalar(keys %{$self->{engine}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No audio engine found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check audio engine usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^elem-count$' + +=item B<--filter-location> + +Filter location name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'elem-count', 'avg-load'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'elem-count', 'avg-load'. + +=back + +=cut diff --git a/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm b/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm new file mode 100644 index 000000000..f1491ff7c --- /dev/null +++ b/apps/inin/mediaserver/snmp/mode/cmdsrvusage.pm @@ -0,0 +1,307 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::inin::mediaserver::snmp::mode::cmdsrvusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_i3MsCmdSrvStatus'}; + $self->{result_values}->{accept_sessions} = $options{new_datas}->{$self->{instance} . '_i3MsCmdSrvAcceptSessions'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Disk Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'cmd', type => 1, cb_prefix_output => 'prefix_cmd_output', message_multiple => 'All command servers are ok' } + ]; + + $self->{maps_counters}->{cmd} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'i3MsCmdSrvStatus' }, { name => 'i3MsCmdSrvAcceptSessions' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'free' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + { label => 'resource-count', set => { + key_values => [ { name => 'i3MsCmdSrvResourceCount' }, { name => 'display' } ], + output_template => 'Resource Count : %s', + perfdatas => [ + { label => 'resource_count', value => 'i3MsCmdSrvResourceCount_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_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 => + { + "filter-client:s" => { name => 'filter_client' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /^ready/i' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_cmd_output { + my ($self, %options) = @_; + + return "Command Server '" . $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 %map_status = (1 => 'unknown', 1 => 'ready', 2 => 'notready', 3 => 'error'); +my %map_truth = (1 => 'true', 2 => 'false'); +my $mapping = { + i3MsCmdSrvAcceptSessions => { oid => '.1.3.6.1.4.1.2793.8227.2.2.1.8', map => \%map_truth }, + i3MsCmdSrvStatus => { oid => '.1.3.6.1.4.1.2793.8227.2.2.1.2', map => \%map_status }, + i3MsCmdSrvClient => { oid => '.1.3.6.1.4.1.2793.8227.2.2.1.6' }, + i3MsCmdSrvResourceCount => { oid => '.1.3.6.1.4.1.2793.8227.2.2.1.9' }, + i3MsCmdSrvRecFreeDiskSpace => { oid => '.1.3.6.1.4.1.2793.8227.2.2.1.12' }, + i3MsCmdSrvRecTotalDiskSpace => { oid => '.1.3.6.1.4.1.2793.8227.2.2.1.13' }, +}; + +my $oid_i3MsCommandServerInfoTableEntry = '.1.3.6.1.4.1.2793.8227.2.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{cmd} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_i3MsCommandServerInfoTableEntry, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{i3MsCmdSrvStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_client}) && $self->{option_results}->{filter_client} ne '' && + $result->{i3MsCmdSrvClient} !~ /$self->{option_results}->{filter_client}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{i3MsCmdSrvClient} . "': no matching filter.", debug => 1); + next; + } + + $self->{cmd}->{$instance} = { + display => $result->{i3MsCmdSrvClient}, + total => $result->{i3MsCmdSrvRecTotalDiskSpace} * 1024 * 1024, + free => $result->{i3MsCmdSrvRecFreeDiskSpace} * 1024 * 1024, + %$result + }; + } + + if (scalar(keys %{$self->{cmd}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No command server found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check command servers usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--filter-client> + +Filter client name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{accept_sessions}, %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /^ready/i'). +Can used special variables like: %{accept_sessions}, %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage', 'resource-count'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage', 'resource-count'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/apps/inin/mediaserver/snmp/mode/component.pm b/apps/inin/mediaserver/snmp/mode/component.pm new file mode 100644 index 000000000..a1c7d6438 --- /dev/null +++ b/apps/inin/mediaserver/snmp/mode/component.pm @@ -0,0 +1,138 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::inin::mediaserver::snmp::mode::component; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(device)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + device => [ + ['unknown', 'UNKNOWN'], + ['up', 'OK'], + ['down', 'CRITICAL'], + ['congested', 'WARNING'], + ['restarting', 'OK'], + ['quiescing', 'OK'], + ['testing', 'OK'], + ], + }; + + $self->{components_path} = 'apps::inin::mediaserver::snmp::mode::components'; + $self->{components_module} = ['device']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check hardware devices. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'device'. + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='device,WARNING,restarting' + +=back + +=cut + +package apps::inin::mediaserver::snmp::mode::components::device; + +use strict; +use warnings; + +my %map_status = (1 => 'unknown', 2 => 'up', 3 => 'down', 4 => 'congested', + 5 => 'restarting', 6 => 'quiescing', 7 => 'testing' +); + +my $mapping = { + i3MsGeneralInfoOperStatus => { oid => '.1.3.6.1.4.1.2793.8227.1.2', map => \%map_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{i3MsGeneralInfoOperStatus}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking devices"); + $self->{components}->{device} = {name => 'devices', total => 0, skip => 0}; + return if ($self->check_filter(section => 'device')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$mapping->{i3MsGeneralInfoOperStatus}->{oid}}, instance => '0'); + + return if (!defined($result->{i3MsGeneralInfoOperStatus})); + $self->{components}->{device}->{total}++; + $self->{output}->output_add(long_msg => sprintf("device status is '%s' [instance = %s]", + $result->{i3MsGeneralInfoOperStatus}, '0')); + my $exit = $self->get_severity(section => 'device', value => $result->{i3MsGeneralInfoOperStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Device status is '%s'", $result->{i3MsGeneralInfoOperStatus})); + } +} + +1; diff --git a/apps/inin/mediaserver/snmp/mode/diskusage.pm b/apps/inin/mediaserver/snmp/mode/diskusage.pm new file mode 100644 index 000000000..7fdd0929a --- /dev/null +++ b/apps/inin/mediaserver/snmp/mode/diskusage.pm @@ -0,0 +1,200 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::inin::mediaserver::snmp::mode::diskusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disktracelog', type => 0 }, + { name => 'diskhttpcache', type => 0 }, + ]; + + $self->{maps_counters}->{disktracelog} = [ + { label => 'tracelog-usage', set => { + key_values => [ { name => 'free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; + $self->{maps_counters}->{diskhttpcache} = [ + { label => 'httpcache-usage', set => { + key_values => [ { name => 'free' }, { name => 'total' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used_' . $self->{result_values}->{display}; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free_' . $self->{result_values}->{display}; + $value_perf = $self->{result_values}->{free}; + } + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Disk '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $self->{result_values}->{display}, + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{free} = $options{new_datas}->{$self->{instance} . '_free'}; + $self->{result_values}->{used} = $self->{result_values}->{total} - $self->{result_values}->{free}; + + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_i3MsGeneralInfoTracelogFreeDiskSpace = '.1.3.6.1.4.1.2793.8227.1.12.0'; # MiB + my $oid_i3MsGeneralInfoTracelogTotalDiskSpace = '.1.3.6.1.4.1.2793.8227.1.13.0'; # MiB + my $oid_i3MsGeneralInfoHttpCacheFreeDiskSpace = '.1.3.6.1.4.1.2793.8227.1.15.0'; # MiB + my $oid_i3MsGeneralInfoHttpCacheTotalDiskSpace = '.1.3.6.1.4.1.2793.8227.1.16.0'; # MiB + + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_i3MsGeneralInfoTracelogFreeDiskSpace, $oid_i3MsGeneralInfoTracelogTotalDiskSpace, + $oid_i3MsGeneralInfoHttpCacheFreeDiskSpace, $oid_i3MsGeneralInfoHttpCacheTotalDiskSpace + ], nothing_quit => 1); + + $self->{disktracelog} = { + free => $snmp_result->{$oid_i3MsGeneralInfoTracelogFreeDiskSpace} * 1024 * 1024, + total => $snmp_result->{$oid_i3MsGeneralInfoTracelogTotalDiskSpace} * 1024 * 1024, + display => 'tracelog' + }; + $self->{diskhttpcache} = { + free => $snmp_result->{$oid_i3MsGeneralInfoHttpCacheFreeDiskSpace} * 1024 * 1024, + total => $snmp_result->{$oid_i3MsGeneralInfoHttpCacheTotalDiskSpace} * 1024 * 1024, + display => 'httpcache' + }; +} + +1; + +__END__ + +=head1 MODE + +Check disk usages. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'httpcache-usage', 'tracelog-usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'httpcache-usage', 'tracelog-usage'. + +=item B<--units> + +Default is '%', can be 'B' + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/apps/inin/mediaserver/snmp/mode/memoryusage.pm b/apps/inin/mediaserver/snmp/mode/memoryusage.pm new file mode 100644 index 000000000..fcee9f83a --- /dev/null +++ b/apps/inin/mediaserver/snmp/mode/memoryusage.pm @@ -0,0 +1,95 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::inin::mediaserver::snmp::mode::memoryusage; + +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 => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', set => { + key_values => [ { name => 'used' } ], + output_template => 'Memory Used : %s %s', + output_change_bytes => 1, + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%s', + unit => 'B', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_i3MsGeneralInfoMemoryUsage = '.1.3.6.1.4.1.2793.8227.1.10.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_i3MsGeneralInfoMemoryUsage + ], nothing_quit => 1); + + $self->{global} = { used => $snmp_result->{$oid_i3MsGeneralInfoMemoryUsage} }; +} + +1; + +__END__ + +=head1 MODE + +Check memory. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage' (B). + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage' (B). + +=back + +=cut diff --git a/apps/inin/mediaserver/snmp/plugin.pm b/apps/inin/mediaserver/snmp/plugin.pm new file mode 100644 index 000000000..6617e9a3f --- /dev/null +++ b/apps/inin/mediaserver/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::inin::mediaserver::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}} = ( + 'audioengine-usage' => 'apps::inin::mediaserver::snmp::mode::audioengineusage', + 'cmdsrv-usage' => 'apps::inin::mediaserver::snmp::mode::cmdsrvusage', + 'disk-usage' => 'apps::inin::mediaserver::snmp::mode::diskusage', + 'component' => 'apps::inin::mediaserver::snmp::mode::component', + 'memory-usage' => 'apps::inin::mediaserver::snmp::mode::memoryusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Interactive Intelligence Media Server in SNMP. + +=cut diff --git a/apps/protocols/dhcp/mode/connection.pm b/apps/protocols/dhcp/mode/connection.pm index 7bdfb6140..9462b746c 100644 --- a/apps/protocols/dhcp/mode/connection.pm +++ b/apps/protocols/dhcp/mode/connection.pm @@ -206,8 +206,7 @@ sub result { $self->check_results(); $self->{output}->perfdata_add(label => "time", unit => 'ms', - value => sprintf('%.3f', $self->{timeelapsed})); - + value => sprintf('%.3f', $self->{timeelapsed})) if (defined($self->{timeelapsed})); } sub run { diff --git a/apps/protocols/http/mode/jsoncontent.pm b/apps/protocols/http/mode/jsoncontent.pm index 9e9122b8c..196ef980f 100644 --- a/apps/protocols/http/mode/jsoncontent.pm +++ b/apps/protocols/http/mode/jsoncontent.pm @@ -273,7 +273,7 @@ __END__ Check JSON webservice. Can send the json request with option '--data'. Example: centreon_plugins.pl --plugin=apps::protocols::http::plugin --mode=json-content --data='/home/user/request.json' --hostname='myws.site.com' --urlpath='/get/payment' ---lookup='$..expiration' +--lookup='$..expiration' --header='Content-Type: application/json' JSON OPTIONS: diff --git a/apps/protocols/tcp/mode/responsetime.pm b/apps/protocols/tcp/mode/responsetime.pm index 1997681e8..47308c807 100644 --- a/apps/protocols/tcp/mode/responsetime.pm +++ b/apps/protocols/tcp/mode/responsetime.pm @@ -90,15 +90,15 @@ sub run { if (!defined($connection)) { if (!defined($!) || ($! eq '')) { $self->{output}->output_add(severity => 'CRITICAL', - short_msg => "Connection failed : SSL error"); + short_msg => sprintf("Connection failed on port %s : SSL error", $self->{option_results}->{port})); } else { $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Connection failed : %s", $!)); + short_msg => sprintf("Connection failed on port %s : %s", $self->{option_results}->{port}, $!)); } } else { - my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + my $exit = $self->{perfdata}->threshold_check(value => $timeelapsed, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Response time %.3fs", $timeelapsed)); + short_msg => sprintf("Response time on port %s is %.3fs", $self->{option_results}->{port}, $timeelapsed)); $self->{output}->perfdata_add(label => 'time', value => sprintf('%.3f', $timeelapsed), unit => 's', diff --git a/apps/sendmail/snmp/plugin.pm b/apps/sendmail/snmp/plugin.pm new file mode 100644 index 000000000..47ada3585 --- /dev/null +++ b/apps/sendmail/snmp/plugin.pm @@ -0,0 +1,48 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::sendmail::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'mta-usage' => 'snmp_standard::mode::mtausage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Sendmail MTA server in SNMP. + +=cut diff --git a/apps/tomcat/jmx/plugin.pm b/apps/tomcat/jmx/plugin.pm index 9f55d917b..150596b90 100644 --- a/apps/tomcat/jmx/plugin.pm +++ b/apps/tomcat/jmx/plugin.pm @@ -31,12 +31,13 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', - 'memory' => 'centreon::common::jvm::mode::memory', - 'fd-usage' => 'centreon::common::jvm::mode::fdusage', - 'load-average' => 'centreon::common::jvm::mode::loadaverage', - 'cpu-load' => 'centreon::common::jvm::mode::cpuload', 'class-count' => 'centreon::common::jvm::mode::classcount', + 'cpu-load' => 'centreon::common::jvm::mode::cpuload', + 'fd-usage' => 'centreon::common::jvm::mode::fdusage', + 'gc-usage' => 'centreon::common::jvm::mode::gcusage', + 'load-average' => 'centreon::common::jvm::mode::loadaverage', + 'memory' => 'centreon::common::jvm::mode::memory', + 'memory-detailed' => 'centreon::common::jvm::mode::memorydetailed', 'threads' => 'centreon::common::jvm::mode::threads', ); diff --git a/apps/vmware/connector/mode/listclusters.pm b/apps/vmware/connector/mode/listclusters.pm new file mode 100644 index 000000000..8ca4bf352 --- /dev/null +++ b/apps/vmware/connector/mode/listclusters.pm @@ -0,0 +1,94 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package apps::vmware::connector::mode::listclusters; + +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 => + { + "cluster:s" => { name => 'cluster' }, + "filter" => { name => 'filter' }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + + +sub run { + my ($self, %options) = @_; + $self->{connector} = $options{custom}; + + $self->{connector}->set_discovery(); + $self->{connector}->add_params(params => $self->{option_results}, + command => 'listclusters'); + $self->{connector}->run(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name']); +} + +sub disco_show { + my ($self, %options) = @_; + $self->{connector} = $options{custom}; + + # We ask to use XML output from the connector + $self->{connector}->add_params(params => { disco_show => 1 }); + $self->run(custom => $self->{connector}); +} + +1; + +__END__ + +=head1 MODE + +List clusters. + +=over 8 + +=item B<--cluster> + +Cluster to check. +If not set, we check all clusters. + +=item B<--filter> + +Cluster is a regexp. + +=back + +=cut diff --git a/apps/vmware/connector/plugin.pm b/apps/vmware/connector/plugin.pm index 76312fd58..96f78c16d 100644 --- a/apps/vmware/connector/plugin.pm +++ b/apps/vmware/connector/plugin.pm @@ -47,6 +47,7 @@ sub new { 'getmap' => 'apps::vmware::connector::mode::getmap', 'health-host' => 'apps::vmware::connector::mode::healthhost', 'limit-vm' => 'apps::vmware::connector::mode::limitvm', + 'list-clusters' => 'apps::vmware::connector::mode::listclusters', 'list-datacenters' => 'apps::vmware::connector::mode::listdatacenters', 'list-datastores' => 'apps::vmware::connector::mode::listdatastores', 'list-nichost' => 'apps::vmware::connector::mode::listnichost', diff --git a/centreon/common/airespace/snmp/mode/apstatus.pm b/centreon/common/airespace/snmp/mode/apstatus.pm index 4e3690c80..09b697323 100644 --- a/centreon/common/airespace/snmp/mode/apstatus.pm +++ b/centreon/common/airespace/snmp/mode/apstatus.pm @@ -199,7 +199,8 @@ sub manage_selection { { oid => $mapping3->{bsnAPAdminStatus}->{oid} }, ], nothing_quit => 1); - $self->{output}->output_add(long_msg => "Model: " . $self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'}); + $self->{output}->output_add(long_msg => "Model: " . + (defined($self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'}) ? $self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'} : 'unknown')); foreach my $oid (keys %{$self->{results}->{ $mapping->{bsnAPName}->{oid} }}) { $oid =~ /^$mapping->{bsnAPName}->{oid}\.(.*)$/; my $instance = $1; diff --git a/centreon/common/airespace/snmp/mode/apusers.pm b/centreon/common/airespace/snmp/mode/apusers.pm index 345360ba7..5e82930bc 100644 --- a/centreon/common/airespace/snmp/mode/apusers.pm +++ b/centreon/common/airespace/snmp/mode/apusers.pm @@ -219,7 +219,8 @@ sub manage_selection { { oid => $oid_bsnAPIfLoadNumOfClients }, ], nothing_quit => 1); - $self->{output}->output_add(long_msg => "Model: " . $self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'}); + $self->{output}->output_add(long_msg => "Model: " . + (defined($self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'}) ? $self->{results}->{$oid_agentInventoryMachineModel}->{$oid_agentInventoryMachineModel . '.0'} : 'unknown')); foreach my $oid (keys %{$self->{results}->{ $mapping->{bsnMobileStationStatus}->{oid} }}) { $oid =~ /^$mapping->{bsnMobileStationStatus}->{oid}\.(.*)$/; my $instance = $1; diff --git a/centreon/common/aruba/snmp/mode/apusers.pm b/centreon/common/aruba/snmp/mode/apusers.pm index 691061d46..35f4d6ab7 100644 --- a/centreon/common/aruba/snmp/mode/apusers.pm +++ b/centreon/common/aruba/snmp/mode/apusers.pm @@ -188,7 +188,7 @@ my $oid_wlsxUserEntry = '.1.3.6.1.4.1.14823.2.2.1.4.1.2.1'; my $oid_wlsxSwitchRole = '.1.3.6.1.4.1.14823.2.2.1.1.1.4'; my $oid_apESSID = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.2'; my $oid_apIpAddress = '.1.3.6.1.4.1.14823.2.2.1.1.3.3.1.5'; -my $oid_wlanAPName = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3'; +#my $oid_wlanAPName = '.1.3.6.1.4.1.14823.2.2.1.5.2.1.4.1.3'; sub manage_selection { my ($self, %options) = @_; @@ -205,7 +205,7 @@ sub manage_selection { { oid => $mapping2->{nUserApBSSID}->{oid} }, { oid => $oid_apESSID }, { oid => $oid_apIpAddress }, - { oid => $oid_wlanAPName }, + #{ oid => $oid_wlanAPName }, ], nothing_quit => 1); @@ -241,8 +241,8 @@ sub manage_selection { $bssid !~ /$self->{option_results}->{filter_bssid}/); my $ap_id = $bssid; - $ap_id = $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} - if (defined($self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid}) && $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} ne ''); + #$ap_id = $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} + # if (defined($self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid}) && $self->{results}->{$oid_wlanAPName}->{$oid_wlanAPName . '.' . $bssid} ne ''); $self->{ap}->{$bssid} = { users => 0, ap_id => $ap_id } if (!defined($self->{ap}->{$bssid})); $self->{ap}->{$bssid}->{users}++; diff --git a/centreon/common/ingrian/snmp/mode/connections.pm b/centreon/common/ingrian/snmp/mode/connections.pm new file mode 100644 index 000000000..934149e2b --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/connections.pm @@ -0,0 +1,119 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::ingrian::snmp::mode::connections; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'naeTotalTotalConnections', diff => 1 } ], + output_template => 'Total Connections : %s', + perfdatas => [ + { label => 'total', value => 'naeTotalTotalConnections_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'ssl', set => { + key_values => [ { name => 'naeTotalSSLConnections', diff => 1 } ], + output_template => 'Total SSL Connections : %s', + perfdatas => [ + { label => 'total_ssl', value => 'naeTotalSSLConnections_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'non-ssl', set => { + key_values => [ { name => 'naeTotalNonSSLConnections', diff => 1 } ], + output_template => 'Total non-SSL Connections : %s', + perfdatas => [ + { label => 'total_non_ssl', value => 'naeTotalNonSSLConnections_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $mapping = { + naeTotalTotalConnections => { oid => '.1.3.6.1.4.1.5595.3.5.1.4' }, + naeTotalNonSSLConnections => { oid => '.1.3.6.1.4.1.5595.3.5.1.5.4' }, + naeTotalSSLConnections => { oid => '.1.3.6.1.4.1.5595.3.5.1.6.4' }, +}; +my $oid_naeConnectionStats = '.1.3.6.1.4.1.5595.3.5'; + +sub manage_selection { + my ($self, %options) = @_; + + + my $snmp_result = $options{snmp}->get_table(oid => $oid_naeConnectionStats, + nothing_quit => 1); + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + $self->{global} = { %$result }; + + $self->{cache_name} = "ingrian_" . $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')); +} + +1; + +__END__ + +=head1 MODE + +Check connections. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'ssl', 'non-ssl'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'ssl', 'non-ssl'. + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/cpu.pm b/centreon/common/ingrian/snmp/mode/cpu.pm new file mode 100644 index 000000000..db5058bcf --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/cpu.pm @@ -0,0 +1,138 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::ingrian::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_init => 'skip_global', }, + { name => 'cpu', type => 1, cb_prefix_output => 'prefix_cpu_output', message_multiple => 'All CPU usages are ok' } + ]; + $self->{maps_counters}->{global} = [ + { label => 'total', set => { + key_values => [ { name => 'total' } ], + output_template => 'Total CPU Usage : %.2f %%', + perfdatas => [ + { label => 'total_cpu_avg', value => 'total_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; + + $self->{maps_counters}->{cpu} = [ + { label => 'usage', set => { + key_values => [ { name => 'usage' }, { name => 'display' }, ], + output_template => 'Usage : %.2f %%', + perfdatas => [ + { label => 'cpu', value => 'usage_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub skip_global { + my ($self, %options) = @_; + + scalar(keys %{$self->{cpu}}) > 1 ? return(0) : return(1); +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $mapping = { + naeSystemCPUDescr => { oid => '.1.3.6.1.4.1.5595.3.2.4.1.2' }, + naeSystemCPUUtilization => { oid => '.1.3.6.1.4.1.5595.3.2.4.1.3' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_naeSystemStatCPUEntry = '.1.3.6.1.4.1.5595.3.2.4.1'; + my $oid_naeSystemStatCPU = '.1.3.6.1.4.1.5595.3.2.2'; # without .0 + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $oid_naeSystemStatCPU }, + { oid => $oid_naeSystemStatCPUEntry }, + ], nothing_quit => 1); + + $self->{cpu} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_naeSystemStatCPUEntry}}) { + next if ($oid !~ /^$mapping->{naeSystemCPUUtilization}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_naeSystemStatCPUEntry}, instance => $instance); + + $self->{cpu}->{$instance} = { display => $instance - 1, usage => $result->{naeSystemCPUUtilization} }; + } + + $self->{global} = { total => $snmp_result->{$oid_naeSystemStatCPU}->{$oid_naeSystemStatCPU . '.0'} }; +} + +1; + +__END__ + +=head1 MODE + +Check CPU usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^total$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'total', 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total', 'usage'. + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/disk.pm b/centreon/common/ingrian/snmp/mode/disk.pm new file mode 100644 index 000000000..a49265598 --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/disk.pm @@ -0,0 +1,109 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::ingrian::snmp::mode::disk; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disk', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All disk usages are ok' } + ]; + + $self->{maps_counters}->{disk} = [ + { label => 'usage', set => { + key_values => [ { name => 'used' }, { name => 'display' } ], + output_template => 'Used : %.2f %%', + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%.2f', min => 0, max => 100, unit => '%', + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "Disk '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +my $mapping = { + naeSystemDiskDescr => { oid => '.1.3.6.1.4.1.5595.3.2.7.1.2' }, + naeSystemDiskUtilization => { oid => '.1.3.6.1.4.1.5595.3.2.7.1.3' }, +}; +my $oid_naeSystemStatDiskEntry = '.1.3.6.1.4.1.5595.3.2.7.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{disk} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_naeSystemStatDiskEntry, + nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{naeSystemDiskUtilization}->{oid}\.(.*)/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{disk}->{$instance} = { display => $result->{naeSystemDiskDescr}, + used => $result->{naeSystemDiskUtilization}}; + } +} + +1; + +__END__ + +=head1 MODE + +Check disk usages. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/memory.pm b/centreon/common/ingrian/snmp/mode/memory.pm new file mode 100644 index 000000000..649d26669 --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/memory.pm @@ -0,0 +1,135 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::ingrian::snmp::mode::memory; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => 'used', unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{prct_used}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Memory Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{prct_used} = $options{new_datas}->{$self->{instance} . '_prct_used'}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + $self->{result_values}->{used} = $self->{result_values}->{total} * $self->{result_values}->{prct_used} / 100; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'memory', type => 0 } + ]; + + $self->{maps_counters}->{memory} = [ + { label => 'usage', set => { + key_values => [ { name => 'prct_used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_naeSystemStatUsedMem = '.1.3.6.1.4.1.5595.3.2.5.0'; + my $oid_naeSystemStatTotalMem = '.1.3.6.1.4.1.5595.3.2.6.0'; # in Bytes + my $snmp_result = $options{snmp}->get_leef(oids => [$oid_naeSystemStatUsedMem, $oid_naeSystemStatTotalMem], + nothing_quit => 1); + + $self->{memory} = { prct_used => $snmp_result->{$oid_naeSystemStatUsedMem}, total => $snmp_result->{$oid_naeSystemStatTotalMem} }; + +} + +1; + +__END__ + +=head1 MODE + +Check memory usages. + +=over 8 + +=item B<--warning-usage> + +Threshold warning (in percent). + +=item B<--critical-usage> + +Threshold critical (in percent). + +=back + +=cut diff --git a/centreon/common/ingrian/snmp/mode/requeststats.pm b/centreon/common/ingrian/snmp/mode/requeststats.pm new file mode 100644 index 000000000..0c8983424 --- /dev/null +++ b/centreon/common/ingrian/snmp/mode/requeststats.pm @@ -0,0 +1,152 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::ingrian::snmp::mode::requeststats; + +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 => 'rq', type => 1, cb_prefix_output => 'prefix_disk_output', message_multiple => 'All request statistics are ok' } + ]; + + $self->{maps_counters}->{rq} = [ + { label => 'success', set => { + key_values => [ { name => 'success', diff => 1 }, { name => 'display' } ], + output_template => 'Success : %s', + perfdatas => [ + { label => 'success', value => 'success_absolute', template => '%s', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'fail', set => { + key_values => [ { name => 'fail', diff => 1 }, { name => 'display' } ], + output_template => 'Fail : %s', + perfdatas => [ + { label => 'fail', value => 'fail_absolute', template => '%s', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_disk_output { + my ($self, %options) = @_; + + return "'" . $options{instance_value}->{display} . "' requests "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +my @map = ( + { label => 'Total', suffix => 1 }, + { label => 'KeyGen', suffix => 2 }, + { label => 'KeyInfo', suffix => 3 }, + { label => 'KeyDel', suffix => 4 }, + { label => 'KeyQuery', suffix => 5 }, + { label => 'KeyImport', suffix => 6 }, + { label => 'KeyExport', suffix => 7 }, + { label => 'RandomGen', suffix => 8 }, + { label => 'Cryptographic', suffix => 9 }, + { label => 'Authenticate', suffix => 10 }, + { label => 'KeyModify', suffix => 11 }, + { label => 'KeyClone', suffix => 12 }, + { label => 'CertificateExport', suffix => 13 }, + { label => 'KeyVersionGenerate', suffix => 14 }, + { label => 'KeyVersionModify', suffix => 15 }, + { label => 'KeyCertificateExport', suffix => 16 }, + { label => 'RecordEvent', suffix => 17 }, + { label => 'PublicKeyExport', suffix => 18 }, + { label => 'CAExport', suffix => 19 }, +); +my $oid_naeServerStats = '.1.3.6.1.4.1.5595.3.3'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{rq} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_naeServerStats, + nothing_quit => 1); + foreach (@map) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{label} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{label} . "': no matching filter.", debug => 1); + next; + } + + $self->{rq}->{$_->{suffix}} = { + display => $_->{label}, + success => $snmp_result->{$oid_naeServerStats . '.' . $_->{suffix} . '.3.0'}, + fail => $snmp_result->{$oid_naeServerStats . '.' . $_->{suffix} . '.4.0'} + }; + } + + $self->{cache_name} = "ingrian_" . $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')) . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check request statistics. + +=over 8 + +=item B<--filter-name> + +Filter by name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'success', 'fail'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'success', 'fail'. + +=back + +=cut diff --git a/centreon/common/jvm/mode/gcusage.pm b/centreon/common/jvm/mode/gcusage.pm new file mode 100644 index 000000000..129f2f2f3 --- /dev/null +++ b/centreon/common/jvm/mode/gcusage.pm @@ -0,0 +1,139 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::jvm::mode::gcusage; + +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 => 'gc', type => 1, cb_prefix_output => 'prefix_gc_output', message_multiple => 'All garbage collectors are ok' } + ]; + + $self->{maps_counters}->{gc} = [ + { label => 'time', set => { + key_values => [ { name => 'time', diff => 1 }, { name => 'display' } ], + output_template => 'Collection Time : %s ms', + perfdatas => [ + { label => 'time', value => 'time_absolute', template => '%s', + unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'count', set => { + key_values => [ { name => 'count', diff => 1 }, { name => 'display' } ], + output_template => 'Collection Count : %s', + perfdatas => [ + { label => 'count', value => 'count_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_gc_output { + my ($self, %options) = @_; + + return "Garbage collector '" . $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; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{request} = [ + { mbean => "java.lang:type=GarbageCollector,name=*", attributes => [ { name => 'CollectionCount' }, { name => 'CollectionTime' } ] } + ]; + + $self->{gc} = {}; + my $result = $options{custom}->get_attributes(request => $self->{request}, nothing_quit => 1); + + foreach my $key (keys %$result) { + $key =~ /name=(.*?)(?:,|$)/; + my $name = $1; + + $self->{gc}->{$name} = { + display => $name, + time => $result->{$key}->{CollectionTime}, + count => $result->{$key}->{CollectionCount} + } + } + + if (scalar(keys %{$self->{gc}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No garbage collector found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "jvm_standard_" . $self->{mode} . '_' . md5_hex($options{custom}->{url}) . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check garbage collectors. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^count$' + +=item B<--filter-name> + +Filter garbage collector name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'count', 'time' (ms). + +=item B<--critical-*> + +Threshold critical. +Can be: 'count', 'time' (ms). + +=back + +=cut \ No newline at end of file diff --git a/centreon/common/jvm/mode/memorydetailed.pm b/centreon/common/jvm/mode/memorydetailed.pm index 025570144..162a19524 100644 --- a/centreon/common/jvm/mode/memorydetailed.pm +++ b/centreon/common/jvm/mode/memorydetailed.pm @@ -35,13 +35,13 @@ my %mapping_memory = ( 'CMS Perm Gen' => 'permanent', 'PS Perm Gen' => 'permanent', 'Perm Gen' => 'permanent', + 'Metaspace' => 'permanent', 'Code Cache' => 'code', 'CMS Old Gen' => 'tenured', 'PS Old Gen' => 'tenured', 'Tenured Gen' => 'tenured', ); - sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -94,6 +94,12 @@ sub run { foreach my $key (keys %$result) { $key =~ /name=(.*?),type/; my $memtype = $1; + + if (!defined($mapping_memory{$memtype})) { + $self->{output}->output_add(long_msg => "unknown memory type: " . $memtype, debug => 1); + next; + } + my $prct = $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{used} / $result->{"java.lang:name=".$memtype.",type=MemoryPool"}->{Usage}->{max} * 100; $self->{output}->perfdata_add(label => $mapping_memory{$memtype}, unit => 'B', diff --git a/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm b/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm index cc9686751..e6fcaf461 100644 --- a/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm +++ b/centreon/common/powershell/hyperv/2012/nodeintegrationservice.pm @@ -33,23 +33,16 @@ sub get_powershell { my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" $vms = Get-VM - $services = Get-VMIntegrationService -VMName * - Foreach ($vm in $vms) { - $i = 0 - Foreach ($service in $services) { - if ($services.VMName -eq $vm.VMName) { - if ($i -eq 0) { - Write-Host "[name=" $vm.VMName "][state=" $vm.State "]" - } - Write-Host "[service=" $service.Name "][primaryOperationalStatus=" $service.PrimaryOperationalStatus "][secondaryOperationalStatus=" $service.SecondaryOperationalStatus "]" - $i=1 - } + Write-Host "[name=" $vm.VMName "][state=" $vm.State "][IntegrationServicesState=" $vm.IntegrationServicesState "][IntegrationServicesVersion=" $vm.IntegrationServicesVersion "]" + Foreach ($service in $VM.VMIntegrationService) { + Write-Host "[service=" $service.Name "][enabled=" $service.Enabled "][primaryOperationalStatus=" $service.PrimaryOperationalStatus "][secondaryOperationalStatus=" $service.SecondaryOperationalStatus "]" } } } Catch { diff --git a/centreon/common/powershell/hyperv/2012/nodereplication.pm b/centreon/common/powershell/hyperv/2012/nodereplication.pm new file mode 100644 index 000000000..f7e4a068c --- /dev/null +++ b/centreon/common/powershell/hyperv/2012/nodereplication.pm @@ -0,0 +1,64 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::powershell::hyperv::2012::nodereplication; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub get_powershell { + my (%options) = @_; + my $no_ps = (defined($options{no_ps})) ? 1 : 0; + + return '' if ($no_ps == 1); + + my $ps = ' +$culture = new-object "System.Globalization.CultureInfo" "en-us" +[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" + +Try { + $ErrorActionPreference = "Stop" + $vms = Get-VMReplication + + Foreach ($vm in $vms) { + Write-Host "[name=" $vm.Name "][state=" $vm.State "][health=" $vm.Health "]" + } +} Catch { + Write-Host $Error[0].Exception + exit 1 +} + +exit 0 +'; + + return centreon::plugins::misc::powershell_encoded($ps); +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to get hyper-v informations. + +=cut \ No newline at end of file diff --git a/centreon/common/powershell/hyperv/2012/nodesnapshot.pm b/centreon/common/powershell/hyperv/2012/nodesnapshot.pm index 656f91a27..805d4a77a 100644 --- a/centreon/common/powershell/hyperv/2012/nodesnapshot.pm +++ b/centreon/common/powershell/hyperv/2012/nodesnapshot.pm @@ -33,12 +33,15 @@ sub get_powershell { my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" $vms = Get-VM - $snapshots = Get-VMSnapshot -VMName * - + if ($vms.Length -gt 0) { + $snapshots = Get-VMSnapshot -VMName * + } + Foreach ($vm in $vms) { $i=0 Foreach ($snap in $snapshots) { diff --git a/centreon/common/powershell/hyperv/2012/nodevmstatus.pm b/centreon/common/powershell/hyperv/2012/nodevmstatus.pm new file mode 100644 index 000000000..7c0c39abc --- /dev/null +++ b/centreon/common/powershell/hyperv/2012/nodevmstatus.pm @@ -0,0 +1,64 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::powershell::hyperv::2012::nodevmstatus; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub get_powershell { + my (%options) = @_; + my $no_ps = (defined($options{no_ps})) ? 1 : 0; + + return '' if ($no_ps == 1); + + my $ps = ' +$culture = new-object "System.Globalization.CultureInfo" "en-us" +[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" + +Try { + $ErrorActionPreference = "Stop" + $vms = Get-VM + + Foreach ($vm in $vms) { + Write-Host "[name=" $vm.VMName "][state=" $vm.State "][status=" $vm.Status "][IsClustered=" $vm.IsClustered "]" + } +} Catch { + Write-Host $Error[0].Exception + exit 1 +} + +exit 0 +'; + + return centreon::plugins::misc::powershell_encoded($ps); +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to get hyper-v informations. + +=cut \ No newline at end of file diff --git a/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm b/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm index b94ba2f0a..ee35b6557 100644 --- a/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm +++ b/centreon/common/powershell/hyperv/2012/scvmmintegrationservice.pm @@ -33,6 +33,7 @@ sub get_powershell { my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" diff --git a/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm b/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm index a28b2e9c0..be9017857 100644 --- a/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm +++ b/centreon/common/powershell/hyperv/2012/scvmmsnapshot.pm @@ -33,6 +33,7 @@ sub get_powershell { my $ps = ' $culture = new-object "System.Globalization.CultureInfo" "en-us" [System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" Try { $ErrorActionPreference = "Stop" diff --git a/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm b/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm new file mode 100644 index 000000000..be9ec4c6a --- /dev/null +++ b/centreon/common/powershell/hyperv/2012/scvmmvmstatus.pm @@ -0,0 +1,71 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::powershell::hyperv::2012::scvmmvmstatus; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub get_powershell { + my (%options) = @_; + my $no_ps = (defined($options{no_ps})) ? 1 : 0; + + return '' if ($no_ps == 1); + + my $ps = ' +$culture = new-object "System.Globalization.CultureInfo" "en-us" +[System.Threading.Thread]::CurrentThread.CurrentUICulture = $culture +$ProgressPreference = "SilentlyContinue" + +Try { + $ErrorActionPreference = "Stop" + Import-Module -Name "virtualmachinemanager" + + $username = "' . $options{scvmm_username} . '" + $password = ConvertTo-SecureString "' . $options{scvmm_password} . '" -AsPlainText -Force + $UserCredential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username,$password + + $connection = Get-VMMServer -ComputerName "' . $options{scvmm_hostname} . '" -TCPPort ' . $options{scvmm_port} . ' -Credential $UserCredential + $vms = Get-SCVirtualMachine -VMMServer $connection + + Foreach ($vm in $vms) { + Write-Host "[name=" $vm.Name "][status=" $vm.Status "][cloud=" $vm.Cloud "][hostgrouppath=" $vm.HostGroupPath "]" + } +} Catch { + Write-Host $Error[0].Exception + exit 1 +} + +exit 0 +'; + + return centreon::plugins::misc::powershell_encoded($ps); +} + +1; + +__END__ + +=head1 DESCRIPTION + +Method to get hyper-v informations. + +=cut \ No newline at end of file diff --git a/centreon/common/protocols/jmx/custom/jolokia.pm b/centreon/common/protocols/jmx/custom/jolokia.pm index 5ba544456..d2dfaca51 100644 --- a/centreon/common/protocols/jmx/custom/jolokia.pm +++ b/centreon/common/protocols/jmx/custom/jolokia.pm @@ -125,20 +125,17 @@ sub check_options { $self->{connect_params}->{password} = $self->{password}; } if (defined($self->{proxy_url}) && $self->{proxy_url} ne '') { - $self->{connect_params}->{username}->{proxy} = { http => undef, https => undef }; - if ($self->{proxy_url} =~ /^(.*?):/) { - $self->{connect_params}->{username}->{proxy}->{$1} = $self->{proxy_url}; - if (defined($self->{proxy_username}) && $self->{proxy_username} ne '') { - $self->{connect_params}->{proxy_user} = $self->{proxy_username}; - $self->{connect_params}->{proxy_password} = $self->{proxy_password}; - } + $self->{connect_params}->{proxy} = { url => $self->{proxy_url} }; + if (defined($self->{proxy_username}) && $self->{proxy_username} ne '') { + $self->{connect_params}->{proxy}->{'proxy-user'} = $self->{proxy_username}; + $self->{connect_params}->{proxy}->{'proxy-password'} = $self->{proxy_password}; } } if (defined($self->{target_url}) && $self->{target_url} ne '') { - $self->{connect_params}->{username}->{target} = { url => $self->{target_url}, user => undef, password => undef }; + $self->{connect_params}->{target} = { url => $self->{target_url}, user => undef, password => undef }; if (defined($self->{target_username}) && $self->{target_username} ne '') { - $self->{connect_params}->{username}->{target}->{user} = $self->{target_username}; - $self->{connect_params}->{username}->{target}->{password} = $self->{target_password}; + $self->{connect_params}->{target}->{user} = $self->{target_username}; + $self->{connect_params}->{target}->{password} = $self->{target_password}; } } @@ -168,6 +165,16 @@ sub _add_request { return $request; } +sub check_error { + my ($self, %options) = @_; + + # 500-599 an error. 400 is an attribute not present + if ($options{response}->status() >= 500 || $options{response}->status() == 401 || $options{response}->status() == 408) { + $self->{output}->add_option_msg(short_msg => "protocol issue: " . $options{response}->error_text()); + $self->{output}->option_exit(); + } +} + sub get_attributes { my ($self, %options) = @_; my $nothing_quit = defined($options{nothing_quit}) && $options{nothing_quit} == 1 ? 1 : 0; @@ -200,13 +207,9 @@ sub get_attributes { my @responses = $self->{jmx4perl}->request(@requests); for (my $i = 0, my $pos = 0; defined($options{request}) && $i < scalar(@{$options{request}}); $i++) { for (my $j = 0; defined($options{request}->[$i]->{attributes}) && - $j < scalar(@{$options{request}->[$i]->{attributes}}); $j++, $pos++) { + defined($responses[$pos]) && $j < scalar(@{$options{request}->[$i]->{attributes}}); $j++, $pos++) { if ($responses[$pos]->is_error()) { - # 500-599 an error. 400 is an attribute not present - if ($responses[$pos]->status() >= 500 || $responses[$pos]->status() == 401) { - $self->{output}->add_option_msg(short_msg => "protocol issue: " . $responses[$pos]->error_text()); - $self->{output}->option_exit(); - } + $self->check_error(response => $responses[$pos]); next; } @@ -225,10 +228,14 @@ sub get_attributes { } if (!defined($options{request}->[$i]->{attributes}) || scalar(@{$options{request}->[$i]->{attributes}}) == 0) { - my $mbean = $responses[$pos]->{request}->{mbean}; - $response->{$mbean} = {} if (!defined($response->{$mbean})); - foreach (keys %{$responses[$pos]->{value}}) { - $response->{$mbean}->{$_} = $responses[$pos]->{value}->{$_}; + if ($responses[$pos]->is_error()) { + $self->check_error(response => $responses[$pos]); + } else { + my $mbean = $responses[$pos]->{request}->{mbean}; + $response->{$mbean} = {} if (!defined($response->{$mbean})); + foreach (keys %{$responses[$pos]->{value}}) { + $response->{$mbean}->{$_} = $responses[$pos]->{value}->{$_}; + } } $pos++; } @@ -332,7 +339,7 @@ Credentials to use for the HTTP request =item B<--proxy-url> -Optional proxy to use. +Optional HTTP proxy to use. =item B<--proxy-username> @@ -344,7 +351,7 @@ Credentials to use for the proxy =item B<--target-url> -Target to use (if you use jolokia agent as a proxy) +Target to use (if you use jolokia agent as a proxy in --url option). =item B<--target-username> diff --git a/centreon/common/sun/snmp/mode/components/entity.pm b/centreon/common/sun/snmp/mode/components/entity.pm new file mode 100644 index 000000000..215de6e6f --- /dev/null +++ b/centreon/common/sun/snmp/mode/components/entity.pm @@ -0,0 +1,141 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::sun::snmp::mode::components::entity; + +use strict; +use warnings; + +my %map_class = ( + 1 => 'other', 2 => 'unknown', 3 => 'chassis', + 4 => 'backplane', 5 => 'container', 6 => 'powerSupply', + 7 => 'fan', 8 => 'sensor', 9 => 'module', + 10 => 'port', 11 => 'stack', +); +my %map_oper_state = (1 => 'disabled', 2 => 'enabled'); +my %map_alarm = ( + 1 => 'critical', 2 => 'major', 3 => 'minor', 4 => 'indeterminate', + 5 => 'warning', 6 => 'pending', 7 => 'cleared' +); +my %map_sensor_type = (1 => 'other', + 2 => 'unknown', 3 => 'temperature', 4 => 'voltage', 5 => 'current', 6 => 'tachometer', + 7 => 'counter', 8 => 'switch', 9 => 'lock', 10 => 'humidity', + 11 => 'smokeDetection', 12 => 'presence', 13 => 'airFlow'); +my %mapping_units = ( + 1 => '', 2 => '', + 3 => 'C', # Degrees C + 4 => 'F', # Degrees F + 5 => 'K', # Degrees K + 6 => 'V', # Volts + 7 => 'A', # Amps, + 8 => 'W', # Watts + 9 => 'Joules', 10 => 'Coulombs', 11 => 'VA', 12 => 'Nits', + 13 => 'Lumens', 14 => 'Lux', 15 => 'Candelas', + 16 => 'kPa', 17 => 'PSI', 18 => 'Newtons', + 19 => 'CFM', 20 => 'rpm', + 21 => 'Hz', # Hertz + 22 => 'Seconds', 23 => 'Minutes', 24 => 'Hours', + 25 => 'Days', 26 => 'Weeks', 27 => 'Mils', + 28 => 'Inches', 29 => 'Feet', 30 => 'Cubic_Inches', + 31 => 'Cubic_Feet', 32 => 'Meters', 33 => 'Cubic_Centimeters', + 34 => 'Cubic_Meters', 35 => 'Liters', 36 => 'Fluid_Ounces', + 37 => 'Radians', 38 => 'Steradians', 39 => 'Revolutions', + 40 => 'Cycles', 41 => 'Gravities', 42 => 'Ounces', + 43 => 'Pounds', 44 => 'Foot_Pounds', 45 => 'Ounce_Inches', + 46 => 'Gauss', 47 => 'Gilberts', 48 => 'Henries', + 49 => 'Farads', 50 => 'Ohms', 51 => 'Siemens', + 52 => 'Moles', 53 => 'Becquerels', 54 => 'PPM', + 55 => 'Decibels', 56 => 'DbA', 57 => 'DbC', + 58 => 'Grays', 59 => 'Sieverts', 60 => 'Color_Temperature_Degrees_K', + 61 => 'b', # bits + 62 => 'B', # Bytes + 63 => 'Words', 64 => 'DoubleWords', 65 => 'QuadWords', + 66 => '%', # Percentage, + 67 => 'Pascals', +); + +my $mapping = { + entPhysicalClass => { oid => '.1.3.6.1.2.1.47.1.1.1.1.5', map => \%map_class }, + entPhysicalName => { oid => '.1.3.6.1.2.1.47.1.1.1.1.7' }, + sunPlatEquipmentOperationalState => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.2.1.2', map => \%map_oper_state }, + sunPlatEquipmentAlarmStatus => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.2.1.3', map => \%map_alarm }, + sunPlatSensorType => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.6.1.2', map => \%map_sensor_type }, + sunPlatNumericSensorBaseUnits => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.8.1.1', map => \%mapping_units }, + sunPlatNumericSensorExponent => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.8.1.2' }, + sunPlatNumericSensorCurrent => { oid => '.1.3.6.1.4.1.42.2.70.101.1.1.8.1.4' }, +}; +my $oid_sunPlatEquipmentEntry = '.1.3.6.1.4.1.42.2.70.101.1.1.2.1'; +my $oid_sunPlatNumericSensorEntry = '.1.3.6.1.4.1.42.2.70.101.1.1.8.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $mapping->{entPhysicalName}->{oid} }, { oid => $mapping->{entPhysicalClass}->{oid} }, + { oid => $oid_sunPlatEquipmentEntry }, { oid => $oid_sunPlatNumericSensorEntry }, + { oid => $mapping->{sunPlatSensorType}->{oid} }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking entities"); + $self->{components}->{entity} = {name => 'entity', total => 0, skip => 0}; + return if ($self->check_filter(section => 'entity')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}})) { + next if ($oid !~ /^$mapping->{entPhysicalName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => $instance); + + next if ($self->check_filter(section => 'entity', instance => $result->{entPhysicalClass} . '.' . $instance)); + next if ($result->{sunPlatEquipmentOperationalState} eq 'disabled'); + + if (defined($result->{sunPlatNumericSensorCurrent})) { + $result->{sunPlatNumericSensorCurrent} *= 10 ** $result->{sunPlatNumericSensorExponent} + } + + $self->{components}->{entity}->{total}++; + $self->{output}->output_add(long_msg => sprintf("%s '%s' status is '%s' [instance = %s, value = %s]", + $result->{entPhysicalClass}, $result->{entPhysicalName}, + $result->{sunPlatEquipmentAlarmStatus}, $result->{entPhysicalClass} . '.' . $instance, + defined($result->{sunPlatNumericSensorCurrent}) ? $result->{sunPlatNumericSensorCurrent} : '-')); + $exit = $self->get_severity(label => 'default', section => 'entity', instance => $result->{entPhysicalClass} . '.' . $instance, value => $result->{sunPlatEquipmentAlarmStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s '%s' status is '%s'", $result->{entPhysicalClass}, $result->{entPhysicalName}, $result->{sunPlatEquipmentAlarmStatus})); + } + + next if (!defined($result->{sunPlatNumericSensorCurrent})); + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => $result->{sunPlatSensorType}, instance => $result->{entPhysicalClass} . '.' . $instance,, value => $result->{sunPlatNumericSensorCurrent}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s '%s' is '%s' %s", $result->{sunPlatSensorType}, + $result->{entPhysicalName}, $result->{sunPlatNumericSensorCurrent}, $result->{sunPlatNumericSensorBaseUnits})); + } + $self->{output}->perfdata_add(label => $result->{sunPlatSensorType} . '_' . $result->{entPhysicalName},, unit => $result->{sunPlatNumericSensorBaseUnits}, + value => $result->{sunPlatNumericSensorCurrent}, + warning => $warn, + critical => $crit + ); + } +} + +1; \ No newline at end of file diff --git a/centreon/common/sun/snmp/mode/hardware.pm b/centreon/common/sun/snmp/mode/hardware.pm new file mode 100644 index 000000000..25a8a59da --- /dev/null +++ b/centreon/common/sun/snmp/mode/hardware.pm @@ -0,0 +1,117 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package centreon::common::sun::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(entity)$'; + + $self->{regexp_threshold_numeric_check_section_option} = + '^(other|unknown|temperature|voltage|current|tachometer|counter|switch|lock|humidity|smokeDetection|presence|airFlow)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['critical', 'CRITICAL'], + ['major', 'CRITICAL'], + ['minor', 'WARNING'], + ['indeterminate', 'OK'], + ['warning', 'WARNING'], + ['pending', 'OK'], + ['cleared', 'OK'], + ], + }; + + $self->{components_path} = 'centreon::common::sun::snmp::mode::components'; + $self->{components_module} = ['entity']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}, return_type => 1); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'entity'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=entity,sensor.18 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='entity,sensor..*,CRITICAL,minor' + +=item B<--warning> + +Set warning threshold (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,20' + +=item B<--critical> + +Set critical threshold (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,30' + +=back + +=cut \ No newline at end of file diff --git a/centreon/plugins/alternative/Getopt.pm b/centreon/plugins/alternative/Getopt.pm index f0c31da54..1d39cb448 100644 --- a/centreon/plugins/alternative/Getopt.pm +++ b/centreon/plugins/alternative/Getopt.pm @@ -40,7 +40,8 @@ sub get_assigned_value { my (%options) = @_; if (!defined($options{val}) || $options{val} eq '') { - if ($options{pos} + 1 < $options{num_args} && $ARGV[$options{pos} + 1] !~ /^--/) { + # Add defined also. Hardened code: already see: $ARGV[6] = undef for example + if ($options{pos} + 1 < $options{num_args} && defined($ARGV[$options{pos} + 1]) && $ARGV[$options{pos} + 1] !~ /^--/) { my $val = $ARGV[$options{pos} + 1]; splice @ARGV, $options{pos} + 1, 1; return ($options{num_args} - 1, $val); diff --git a/centreon/plugins/script.pm b/centreon/plugins/script.pm index 8a2cb53c7..3ddd9f9e8 100644 --- a/centreon/plugins/script.pm +++ b/centreon/plugins/script.pm @@ -30,7 +30,7 @@ use Pod::Find qw(pod_where); my %handlers = (DIE => {}); -my $global_version = 20170120; +my $global_version = 20170329; my $alternative_fatpacker = 0; sub new { @@ -102,6 +102,7 @@ sub get_plugin { 'version' => { name => 'version' }, 'runas:s' => { name => 'runas' }, 'environment:s%' => { name => 'environment' }, + 'convert-args:s' => { name => 'convert_args' }, } ); $self->{options}->parse_options(); @@ -113,6 +114,7 @@ sub get_plugin { $self->{runas} = $self->{options}->get_option(argument => 'runas' ); $self->{environment} = $self->{options}->get_option(argument => 'environment' ); $self->{ignore_warn_msg} = $self->{options}->get_option(argument => 'ignore_warn_msg' ); + $self->{convert_args} = $self->{options}->get_option(argument => 'convert_args' ); $self->{output}->mode(name => $self->{mode}); $self->{output}->plugin(name => $self->{plugin}); @@ -121,6 +123,17 @@ sub get_plugin { $self->{options}->clean(); } +sub convert_args { + my ($self) = @_; + + if ($self->{convert_args} =~ /^(.+?),(.*)/) { + my ($search, $replace) = ($1, $2); + for (my $i = 0; $i < $#ARGV; $i++) { + $ARGV[$i] =~ s/$search/$replace/g; + } + } +} + sub display_local_help { my ($self) = @_; @@ -325,12 +338,11 @@ sub run { $self->display_list_plugin(); $self->{output}->option_exit(); } - if (!defined($self->{plugin}) || $self->{plugin} eq '') { - $self->check_plugin_option(); - } + $self->check_plugin_option() if (!defined($self->{plugin}) || $self->{plugin} eq ''); if (defined($self->{ignore_warn_msg})) { $SIG{__WARN__} = sub {}; } + $self->convert_args() if (defined($self->{convert_args})); $self->check_relaunch(); @@ -387,6 +399,11 @@ Run the script as a different user (prefer to use directly the good user). Set environment variables for the script (prefer to set it before running it for better performance). +=item B<--convert-args> + +Change strings of arguments. Useful to use '!' in nrpe protocol. +Example: --convert-args='##,!' + =back =head1 DESCRIPTION diff --git a/centreon/plugins/script_simple.pm b/centreon/plugins/script_simple.pm index 0875639cc..c9332b65d 100644 --- a/centreon/plugins/script_simple.pm +++ b/centreon/plugins/script_simple.pm @@ -140,7 +140,7 @@ sub is_mode { # $options->{mode} = mode if (!defined($self->{modes}{$options{mode}})) { - $self->{output}->add_option_msg(short_msg => "mode '" . $options{mode} . "' doesn't exist (use --list option to show available modes)."); + $self->{output}->add_option_msg(short_msg => "mode '" . $options{mode} . "' doesn't exist (use --list-mode option to show available modes)."); $self->{output}->option_exit(); } } diff --git a/centreon/plugins/snmp.pm b/centreon/plugins/snmp.pm index 91aaee97d..1f825da95 100644 --- a/centreon/plugins/snmp.pm +++ b/centreon/plugins/snmp.pm @@ -52,6 +52,7 @@ sub new { "snmp-retries:s" => { name => 'snmp_retries', default => 5 }, "maxrepetitions:s" => { name => 'maxrepetitions', default => 50 }, "subsetleef:s" => { name => 'subsetleef', default => 50 }, + "subsettable:s" => { name => 'subsettable', default => 100 }, "snmp-force-getnext" => { name => 'snmp_force_getnext' }, "snmp-username:s" => { name => 'snmp_security_name' }, "authpassphrase:s" => { name => 'snmp_auth_passphrase' }, @@ -68,7 +69,6 @@ sub new { ##### $self->{session} = undef; $self->{output} = $options{output}; - $self->{maxrepetitions} = undef; $self->{snmp_params} = {}; # Dont load MIB @@ -348,6 +348,7 @@ sub get_multiple_table { push @bases, $key; $current_oids++; + last if ($current_oids > $self->{subsettable}); } # Nothing more to check. We quit @@ -358,7 +359,7 @@ sub get_multiple_table { if ($self->is_snmpv1() || defined($self->{snmp_force_getnext})) { $self->{session}->getnext($vb); } else { - my $current_repeat_count = floor($repeat_count / (scalar(keys %{$working_oids}))); + my $current_repeat_count = floor($repeat_count / $current_oids); $current_repeat_count = 1 if ($current_repeat_count == 0); $self->{session}->getbulk(0, $current_repeat_count, $vb); } @@ -433,7 +434,6 @@ sub get_multiple_table { if ($nothing_quit == 1) { if ($return_type == 1) { $total = scalar(keys %{$results}); - } else { foreach (keys %{$results}) { $total += scalar(keys %{$results->{$_}}); @@ -646,6 +646,7 @@ sub check_options { $self->{snmp_force_getnext} = $options{option_results}->{snmp_force_getnext}; $self->{maxrepetitions} = $options{option_results}->{maxrepetitions}; $self->{subsetleef} = (defined($options{option_results}->{subsetleef}) && $options{option_results}->{subsetleef} =~ /^[0-9]+$/) ? $options{option_results}->{subsetleef} : 50; + $self->{subsettable} = (defined($options{option_results}->{subsettable}) && $options{option_results}->{subsettable} =~ /^[0-9]+$/) ? $options{option_results}->{subsettable} : 100; $self->{snmp_errors_exit} = $options{option_results}->{snmp_errors_exit}; %{$self->{snmp_params}} = (DestHost => $options{option_results}->{host}, diff --git a/centreon/plugins/templates/hardware.pm b/centreon/plugins/templates/hardware.pm index 333940ecf..3223b5d27 100644 --- a/centreon/plugins/templates/hardware.pm +++ b/centreon/plugins/templates/hardware.pm @@ -110,6 +110,8 @@ sub new { }); } + $self->{load_components} = (defined($options{no_load_components}) && $options{no_load_components} == 1) ? + 0 : 1; $self->{components} = {}; $self->{no_components} = undef; @@ -223,7 +225,7 @@ sub load_components { if (/$self->{option_results}->{component}/) { my $mod_name = $self->{components_path} . "::$_"; centreon::plugins::misc::mymodule_load(output => $self->{output}, module => $mod_name, - error_msg => "Cannot load module '$mod_name'."); + error_msg => "Cannot load module '$mod_name'.") if ($self->{load_components} == 1); $self->{loaded} = 1; if ($self->{components_exec_load} == 1) { my $func = $mod_name->can('load'); diff --git a/changelog b/changelog index 6dcf468d1..66556790a 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,34 @@ +2017-03-29 Quentin Garnier + * Plugin added: Watchguard SNMP + * Plugin added: Intelligence Interactive SNMP + * Plugin added: Oracle Infiniband SNMP + * Plugin added: Beeware SNMP + * Plugin added: Oracle ZFS Storage ZS SNMP + * Plugin added: Safenet Keysecure SNMP + * Plugin added: Oracle OTD SNMP + * Break: path change for Alteon SNMP + +2017-03-10 Quentin Garnier + * Plugin added: Dell FluidFS SNMP + * Plugin added: Clamav + * Plugin added: Sendmail SNMP + * Plugin added: Centreon DSM + * Plugin added: Audiocodes SNMP + * Mode added: [snmp_standard] 'vrrp-status' + * Mode added: [centreon] 'virtualservice' + * Break: path change for Netscaler SNMP + * Fix: perl connector issue + +2017-02-16 Quentin Garnier + * Plugin added: Hyper-v 2012 + * Plugin added: Avocent ACS 6000 SNMP + * Plugin added: Alcatel PSS 1830 + * Mode added:: [hp lefthand] 'volume-usage' + * Mode added:: [checkpoint] 'vpn-status' + * Mode added:: [f-5 bigip] 'tmm-usage' + * Break: path change for F-5 BigIp + * Break: path change for Checkpoint + 2017-01-20 Quentin Garnier * Plugin added: SAP Hana DB * Plugin added: Efficient IP diff --git a/database/oracle/mode/rmanbackupage.pm b/database/oracle/mode/rmanbackupage.pm index c949ea44a..df6e53076 100644 --- a/database/oracle/mode/rmanbackupage.pm +++ b/database/oracle/mode/rmanbackupage.pm @@ -85,12 +85,12 @@ sub run { $self->{sql}->connect(); my $query; if (defined($self->{option_results}->{incremental_level})) { - $query = q{SELECT v$rman_status.object_type, + $query = q{SELECT v$rman_status.object_type, ((max(v$rman_status.start_time) - date '1970-01-01')*24*60*60) as last_time, - NVL(v$backup_set_details.incremental_level, 0) + SUM(v$backup_set_details.incremental_level) FROM v$rman_status LEFT JOIN v$backup_set_details ON v$rman_status.session_recid = v$backup_set_details.session_recid WHERE operation='BACKUP' - GROUP BY object_type, incremental_level ORDER BY last_time DESC + GROUP BY object_type, v$backup_set_details.session_recid ORDER BY last_time DESC }; } else { $query = q{SELECT object_type, @@ -114,13 +114,12 @@ sub run { foreach my $row (@$result) { if (defined($self->{option_results}->{incremental_level})) { # db incr with incremental level 0 = DB FULL - if (/db full/ && $$row[0] =~ /db incr/i && defined($$row[2]) && $$row[2] == 0) { # it's a full. we get + if (/db full/ && $$row[0] =~ /db incr/i && (!defined($$row[2]) || $$row[2] == 0)) { # it's a full. we get $$row[0] = 'DB FULL'; } else { - next if (/db incr/ && $$row[0] =~ /db incr/i && defined($$row[2]) && $$row[2] == 0); # it's a full. we skip. + next if (/db incr/ && $$row[0] =~ /db incr/i && (!defined($$row[2]) || $$row[2] == 0)); # it's a full. we skip. next if ($$row[0] !~ /$_/i); } - } else { next if ($$row[0] !~ /$_/i); } diff --git a/database/sybase/mode/databasessize.pm b/database/sybase/mode/databasessize.pm index 87efcca60..6811f3162 100644 --- a/database/sybase/mode/databasessize.pm +++ b/database/sybase/mode/databasessize.pm @@ -157,8 +157,8 @@ sub manage_selection { select db_name(d.dbid) as db_name, ceiling(sum(case when u.segmap != 4 then u.size/1.*@@maxpagesize end )) as data_size, ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1.*@@maxpagesize) as data_used, -ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end)) as log_size, -ceiling(sum(case when u.segmap = 4 then u.size/1.*@@maxpagesize end) - lct_admin("logsegment_freepages",d.dbid)/1.*@@maxpagesize) as log_used +ceiling(sum(case when u.segmap in (4, 7) then u.size/1.*@@maxpagesize end)) as log_size, +ceiling(sum(case when u.segmap in (4, 7) then u.size/1.*@@maxpagesize end) - lct_admin("logsegment_freepages",d.dbid)/1.*@@maxpagesize) as log_used from master..sysdatabases d, master..sysusages u where u.dbid = d.dbid and d.status not in (256,4096) group by d.dbid diff --git a/hardware/devices/safenet/keysecure/snmp/plugin.pm b/hardware/devices/safenet/keysecure/snmp/plugin.pm new file mode 100644 index 000000000..c732bb01b --- /dev/null +++ b/hardware/devices/safenet/keysecure/snmp/plugin.pm @@ -0,0 +1,54 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::devices::safenet::keysecure::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'connections' => 'centreon::common::ingrian::snmp::mode::connections', + 'cpu' => 'centreon::common::ingrian::snmp::mode::cpu', + 'disk' => 'centreon::common::ingrian::snmp::mode::disk', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'centreon::common::ingrian::snmp::mode::memory', + 'request-stats' => 'centreon::common::ingrian::snmp::mode::requeststats', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Safenet Keysecure in SNMP. + +=cut diff --git a/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm b/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm new file mode 100644 index 000000000..9eda2fdf1 --- /dev/null +++ b/hardware/kvm/avocent/acs/6000/snmp/mode/components/psu.pm @@ -0,0 +1,71 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::kvm::avocent::acs::6000::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_states = (1 => 'statePowerOn', 2 => 'statePowerOff', 9999 => 'powerNotInstalled'); + +my $mapping = { + acsPowerSupplyStatePw1 => { oid => '.1.3.6.1.4.1.10418.16.2.1.8.2', map => \%map_states }, + acsPowerSupplyStatePw2 => { oid => '.1.3.6.1.4.1.10418.16.2.1.8.3', map => \%map_states }, +}; +my $oid_acsPowerSupply = '.1.3.6.1.4.1.10418.16.2.1.8'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acsPowerSupply }; +} + +sub check_psu { + my ($self, %options) = @_; + + return if ($self->check_filter(section => 'psu', instance => $options{instance})); + return if ($options{state} eq 'powerNotInstalled' && + $self->absent_problem(section => 'psu', instance => $options{instance})); + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is %s.", + $options{instance}, $options{state} + )); + my $exit = $self->get_severity(section => 'psu', value => $options{state}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply '%s' status is %s", + $options{instance}, $options{state})); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acsPowerSupply}, instance => '0'); + check_psu($self, state => $result->{acsPowerSupplyStatePw1}, instance => '1'); + check_psu($self, state => $result->{acsPowerSupplyStatePw2}, instance => '2'); +} + +1; \ No newline at end of file diff --git a/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm b/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm new file mode 100644 index 000000000..d3ec43144 --- /dev/null +++ b/hardware/kvm/avocent/acs/6000/snmp/mode/hardware.pm @@ -0,0 +1,105 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::kvm::avocent::acs::6000::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['statePowerOn', 'OK'], + ['statePowerOff', 'CRITICAL'], + ['powerNotInstalled', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::kvm::avocent::acs::6000::snmp::mode::components'; + $self->{components_module} = ['psu']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=psu,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,^(?!(statePowerOn)$)' + +=back + +=cut \ No newline at end of file diff --git a/hardware/kvm/avocent/acs/6000/snmp/plugin.pm b/hardware/kvm/avocent/acs/6000/snmp/plugin.pm new file mode 100644 index 000000000..f74152c40 --- /dev/null +++ b/hardware/kvm/avocent/acs/6000/snmp/plugin.pm @@ -0,0 +1,51 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::kvm::avocent::acs::6000::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'hardware::kvm::avocent::acs::6000::snmp::mode::hardware', + 'load' => 'snmp_standard::mode::loadaverage', + 'memory' => 'snmp_standard::mode::memory', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Avocent ACS 6000 series in SNMP. + +=cut diff --git a/hardware/server/dell/cmc/snmp/plugin.pm b/hardware/server/dell/cmc/snmp/plugin.pm index 2e2ff25d2..ac3824726 100644 --- a/hardware/server/dell/cmc/snmp/plugin.pm +++ b/hardware/server/dell/cmc/snmp/plugin.pm @@ -44,6 +44,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Dell Chassis Management Controller (CMC) in SNMP (Dell m1000e). +Check Dell Chassis Management Controller (CMC) in SNMP (Dell m1000e, VRTX, FX2). =cut diff --git a/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm b/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm index eecb03e0d..5ca6b78d5 100644 --- a/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm +++ b/hardware/server/hp/ilo/xmlapi/mode/components/cpu.pm @@ -33,6 +33,8 @@ sub check { return if ($self->check_filter(section => 'cpu')); return if (!defined($self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{PROCESSORS}->{PROCESSOR})); + # STATUS can be missing + # # # # foreach my $result (@{$self->{xml_result}->{GET_EMBEDDED_HEALTH_DATA}->{PROCESSORS}->{PROCESSOR}}) { + next if (!defined($result->{STATUS})); my $instance = $result->{LABEL}->{VALUE}; next if ($self->check_filter(section => 'cpu', instance => $instance)); diff --git a/hardware/ups/apc/snmp/mode/outputlines.pm b/hardware/ups/apc/snmp/mode/outputlines.pm new file mode 100644 index 000000000..a0fef8274 --- /dev/null +++ b/hardware/ups/apc/snmp/mode/outputlines.pm @@ -0,0 +1,232 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::ups::apc::snmp::mode::outputlines; + +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'; + } elsif (defined($instance_mode->{option_results}->{unknown_status}) && $instance_mode->{option_results}->{unknown_status} ne '' && + eval "$instance_mode->{option_results}->{unknown_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 = sprintf("Output status is '%s'", $self->{result_values}->{status}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_upsBasicOutputStatus'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'upsBasicOutputStatus' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'load', set => { + key_values => [ { name => 'upsAdvOutputLoad' } ], + output_template => 'Load : %s %%', + perfdatas => [ + { label => 'load', value => 'upsAdvOutputLoad_absolute', template => '%s', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'current', set => { + key_values => [ { name => 'upsAdvOutputCurrent' } ], + output_template => 'Current : %s A', + perfdatas => [ + { label => 'current', value => 'upsAdvOutputCurrent_absolute', template => '%s', + min => 0, unit => 'A' }, + ], + } + }, + { label => 'voltage', set => { + key_values => [ { name => 'upsAdvOutputVoltage' } ], + output_template => 'Voltage : %s V', + perfdatas => [ + { label => 'voltage', value => 'upsAdvOutputVoltage_absolute', template => '%s', + unit => 'V' }, + ], + } + }, + { label => 'frequence', set => { + key_values => [ { name => 'upsAdvOutputFrequency' } ], + output_template => 'Frequence : %s Hz', + perfdatas => [ + { label => 'frequence', value => 'upsAdvOutputFrequency_absolute', template => '%s', + unit => 'Hz' }, + ], + } + }, + ]; +} + +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 => + { + "unknown-status:s" => { name => 'unknown_status', default => '%{status} =~ /unknown/i' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /onLine|rebooting/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status', 'unknown_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_status = ( + 1 => 'unknown', 2 => 'onLine', 3 => 'onBattery', 4 => 'onSmartBoost', + 5 => 'timedSleeping', 6 => 'softwareBypass', 7 => 'off', + 8 => 'rebooting', 9 => 'switchedBypass', 10 => 'hardwareFailureBypass', + 11 => 'sleepingUntilPowerReturn', 12 => 'onSmartTrim', +); + +my $mapping = { + upsBasicOutputStatus => { oid => '.1.3.6.1.4.1.318.1.1.1.4.1.1', map => \%map_status }, + upsAdvOutputVoltage => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.1' }, + upsAdvOutputFrequency => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.2' }, + upsAdvOutputLoad => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.3' }, + upsAdvOutputCurrent => { oid => '.1.3.6.1.4.1.318.1.1.1.4.2.4' }, +}; +my $oid_upsOutput = '.1.3.6.1.4.1.318.1.1.1.4'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_upsOutput, + nothing_quit => 1); + + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => '0'); + + foreach my $name (keys %{$mapping}) { + $self->{global}->{$name} = $result->{$name}; + } +} + +1; + +__END__ + +=head1 MODE + +Check output lines. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status|load$' + +=item B<--unknown-status> + +Set warning threshold for status (Default: '%{status} =~ /unknown/i'). +Can used special variables like: %{status} + +=item B<--warning-status> + +Set warning threshold for status (Default: ''). +Can used special variables like: %{status} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} !~ /onLine|rebooting/i'). +Can used special variables like: %{status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'load', 'voltage', 'current', 'frequence'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'load', 'voltage', 'current', 'frequence'. + +=back + +=cut diff --git a/hardware/ups/apc/snmp/mode/sensors.pm b/hardware/ups/apc/snmp/mode/sensors.pm new file mode 100644 index 000000000..7d7cc8a1e --- /dev/null +++ b/hardware/ups/apc/snmp/mode/sensors.pm @@ -0,0 +1,180 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package hardware::ups::apc::snmp::mode::sensors; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(sensor)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|humidity)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + sensor => [ + ['uioNormal', 'OK'], + ['uioWarning', 'WARNING'], + ['uioCritical', 'OK'], + ['sensorStatusNotApplicable', 'OK'], + ], + }; + + $self->{components_path} = 'hardware::ups::apc::snmp::mode::components'; + $self->{components_module} = ['sensor']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check sensors. + +=over 8 + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=sensor,1.1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='sensor,CRITICAL,sensorStatusNotApplicable' + +=item B<--warning> + +Set warning threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) +Example: --warning='temperature,.*,40' + +=item B<--critical> + +Set critical threshold for 'temperature', 'humidity' (syntax: type,regexp,threshold) +Example: --critical='temperature,.*,50' + +=back + +=cut + +package hardware::ups::apc::snmp::mode::components::sensor; + +use strict; +use warnings; + +my %map_status = (1 => 'uioNormal', 2 => 'uioWarning', 3 => 'uioCritical', 4 => 'sensorStatusNotApplicable'); + +my $mapping = { + uioSensorStatusSensorName => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.3' }, + uioSensorStatusTemperatureDegC => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.6' }, + uioSensorStatusHumidity => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.7' }, + uioSensorStatusAlarmStatus => { oid => '.1.3.6.1.4.1.318.1.1.25.1.2.1.9', map => \%map_status }, +}; +my $oid_uioSensorStatusEntry = '.1.3.6.1.4.1.318.1.1.25.1.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_uioSensorStatusEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking sensors"); + $self->{components}->{sensor} = {name => 'sensors', total => 0, skip => 0}; + return if ($self->check_filter(section => 'sensor')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_uioSensorStatusEntry}})) { + next if ($oid !~ /^$mapping->{uioSensorStatusAlarmStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_uioSensorStatusEntry}, instance => $instance); + + next if ($self->check_filter(section => 'sensor', instance => $instance)); + + $self->{components}->{sensor}->{total}++; + $self->{output}->output_add(long_msg => sprintf("sensor '%s' status is '%s' [instance = %s]", + $result->{uioSensorStatusSensorName}, $result->{uioSensorStatusAlarmStatus}, $instance)); + $exit = $self->get_severity(section => 'sensor', value => $result->{uioSensorStatusAlarmStatus}); + 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'", $result->{uioSensorStatusSensorName}, $result->{uioSensorStatusAlarmStatus})); + } + + if ($result->{uioSensorStatusTemperatureDegC} != -1) { + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{uioSensorStatusTemperatureDegC}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor temperature '%s' is %s C", $result->{uioSensorStatusSensorName}, $result->{uioSensorStatusTemperatureDegC})); + } + $self->{output}->perfdata_add(label => 'temp_' . $result->{uioSensorStatusSensorName}, unit => 'C', + value => $result->{uioSensorStatusTemperatureDegC}, + warning => $warn, + critical => $crit + ); + } + + if ($result->{uioSensorStatusHumidity} != -1) { + ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'humidity', instance => $instance, value => $result->{uioSensorStatusHumidity}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Sensor humidity '%s' is %s %%", $result->{uioSensorStatusSensorName}, $result->{uioSensorStatusHumidity})); + } + $self->{output}->perfdata_add(label => 'humidity_' . $result->{uioSensorStatusSensorName}, unit => '%', + value => $result->{uioSensorStatusHumidity}, + warning => $warn, + critical => $crit, min => 0, max => 100 + ); + } + } +} + +1; diff --git a/hardware/ups/apc/snmp/plugin.pm b/hardware/ups/apc/snmp/plugin.pm index 5ecaf6988..9683ee0e4 100644 --- a/hardware/ups/apc/snmp/plugin.pm +++ b/hardware/ups/apc/snmp/plugin.pm @@ -30,6 +30,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( 'battery-status' => 'hardware::ups::apc::snmp::mode::batterystatus', + 'output-lines' => 'hardware::ups::apc::snmp::mode::outputlines', + 'sensors' => 'hardware::ups::apc::snmp::mode::sensors', ); return $self; diff --git a/network/alcatel/pss/1830/snmp/mode/listsap.pm b/network/alcatel/pss/1830/snmp/mode/listsap.pm new file mode 100644 index 000000000..8e4223f1e --- /dev/null +++ b/network/alcatel/pss/1830/snmp/mode/listsap.pm @@ -0,0 +1,123 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::alcatel::pss::1830::snmp::mode::listsap; + +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 => + { + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $oid_tnSapDescription = '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.5'; +my $oid_tnSvcName = '.1.3.6.1.4.1.7483.6.1.2.4.2.2.1.28'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{sap} = {}; + my $snmp_result = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_tnSapDescription }, { oid => $oid_tnSvcName } ], + nothing_quit => 1); + foreach my $oid (keys %{$snmp_result->{$oid_tnSapDescription}}) { + next if ($oid !~ /^$oid_tnSapDescription\.(.*?)\.(.*?)\.(.*?)\.(.*?)$/); + my ($SysSwitchId, $SvcId, $SapPortId, $SapEncapValue) = ($1, $2, $3, $4); + + $self->{sap}->{$SysSwitchId . '.' . $SvcId . '.' . $SapPortId . '.' . $SapEncapValue} = { + SysSwitchId => $SysSwitchId, + SvcId => $SvcId, + SapPortId => $SapPortId, + SapEncapValue => $SapEncapValue, + SapDescription => $snmp_result->{$oid_tnSapDescription}->{$oid}, + SvcName => defined($snmp_result->{$oid_tnSvcName}->{$oid_tnSvcName . '.' . $SysSwitchId . '.' . $SvcId}) ? + $snmp_result->{$oid_tnSvcName}->{$oid_tnSvcName . '.' . $SysSwitchId . '.' . $SvcId} : '' + }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->manage_selection(); + foreach my $instance (sort keys %{$self->{sap}}) { + my $msg = ''; + $self->{output}->output_add(long_msg => + "[SysSwitchId = " . $self->{sap}->{$instance}->{SysSwitchId} . "]" . + "[SvcId = " . $self->{sap}->{$instance}->{SvcId} . "]" . + "[SapPortId = " . $self->{sap}->{$instance}->{SapPortId} . "]" . + "[SapEncapValue = " . $self->{sap}->{$instance}->{SapEncapValue} . "]" . + "[SapDescription = " . $self->{sap}->{$instance}->{SapDescription} . "]" . + "[SvcName = " . $self->{sap}->{$instance}->{SvcName} . "]" + ); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List SAP:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['SysSwitchId', 'SvcId', 'SapPortId', 'SapEncapValue', 'SapDescription', 'SvcName']); +} + +sub disco_show { + my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; + + $self->manage_selection(disco => 1); + foreach my $instance (sort keys %{$self->{sap}}) { + $self->{output}->add_disco_entry(%{$self->{sap}->{$instance}}); + } +} + +1; + +__END__ + +=head1 MODE + +List SAP. + +=over 8 + +=back + +=cut + \ No newline at end of file diff --git a/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm b/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm new file mode 100644 index 000000000..7b6ef96dd --- /dev/null +++ b/network/alcatel/pss/1830/snmp/mode/sapqosstats.pm @@ -0,0 +1,381 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::alcatel::pss::1830::snmp::mode::sapqosstats; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'sap', type => 1, cb_prefix_output => 'prefix_sap_output', message_multiple => 'All SAP QoS are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{sap} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'admin' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'in-traffic', set => { + key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_qos_output'), + closure_custom_perfdata => $self->can('custom_qos_perfdata'), + closure_custom_threshold_check => $self->can('custom_qos_threshold'), + } + }, + { label => 'out-traffic', set => { + key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_qos_output'), + closure_custom_perfdata => $self->can('custom_qos_perfdata'), + closure_custom_threshold_check => $self->can('custom_qos_threshold'), + } + }, + { label => 'in-drop-packets', set => { + key_values => [ { name => 'in_dropped_packets', diff => 1 }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_qos_drop_calc'), + output_template => 'In Dropped Packets : %s', + perfdatas => [ + { label => 'in_drop_packets', value => 'in_dropped_packets_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display' }, + ], + } + }, + ]; +} + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + my $label = $self->{label}; + $label =~ s/-/_/g; + if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'critical_' . $label}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'warning_' . $label}") { + $status = 'warning'; + } + + $instance_mode->{last_status} = 0; + if ($self->{result_values}->{admin} eq 'up') { + $instance_mode->{last_status} = 1; + } + }; + 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} . ' (admin: ' . $self->{result_values}->{admin} . ')'; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{admin} = $options{new_datas}->{$self->{instance} . '_admin'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_qos_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { + $extra_label .= '_' . $self->{result_values}->{display}; + } + + my ($warning, $critical); + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + } + + $self->{output}->perfdata_add(label => 'traffic_' . $self->{result_values}->{label} . $extra_label, unit => 'b/s', + value => sprintf("%.2f", $self->{result_values}->{traffic}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed}); +} + +sub custom_qos_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } + return $exit; +} + +sub custom_qos_output { + my ($self, %options) = @_; + + my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1); + my ($total_value, $total_unit); + if (defined($self->{result_values}->{speed}) && $self->{result_values}->{speed} =~ /[0-9]/) { + ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{speed}, network => 1); + } + + my $msg = sprintf("Traffic %s : %s/s (%s on %s)", + ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-', + defined($total_value) ? $total_value . $total_unit : '-'); + return $msg; +} + +sub custom_qos_calc { + my ($self, %options) = @_; + + return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{traffic} = ($options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}} - $options{old_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}}) / $options{delta_time}; + if (defined($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000); + $self->{result_values}->{speed} = $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000; + } + return 0; +} + +sub custom_qos_drop_calc { + my ($self, %options) = @_; + + return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{in_dropped_packets_absolute} = $options{new_datas}->{$self->{instance} . '_in_dropped_packets'} - $options{old_datas}->{$self->{instance} . '_in_dropped_packets'}; + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "display-name:s" => { name => 'display_name', default => '%{SysSwitchId}.%{SvcId}.%{SapPortId}.%{SapEncapValue}' }, + "filter-name:s" => { name => 'filter_name' }, + "speed-in:s" => { name => 'speed_in' }, + "speed-out:s" => { name => 'speed_out' }, + "units-traffic:s" => { name => 'units_traffic', default => '%' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{admin} =~ /up/i and %{status} !~ /up/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub prefix_sap_output { + my ($self, %options) = @_; + + return "SAP '" . $options{instance_value}->{display} . "' "; +} + +sub get_display_name { + my ($self, %options) = @_; + + my $display_name = $self->{option_results}->{display_name}; + $display_name =~ s/%\{(.*?)\}/$options{$1}/ge; + return $display_name; +} + +my %map_admin = (1 => 'up', 2 => 'down'); +my %map_oper = (1 => 'up', 2 => 'down', 3 => 'ingressQosMismatch', + 4 => 'egressQosMismatch', 5 => 'portMtuTooSmall', 6 => 'svcAdminDown', + 7 => 'iesIfAdminDown' +); + +my $mapping = { + tnSapAdminStatus => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.6', map => \%map_admin }, + tnSapOperStatus => { oid => '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.7', map => \%map_oper }, + tnSapBaseStatsIngressForwardedOctets => { oid => '.1.3.6.1.4.1.7483.7.2.2.2.8.1.1.1.4' }, + tnSapBaseStatsEgressForwardedOctets => { oid => '.1.3.6.1.4.1.7483.7.2.2.2.8.1.1.1.6' }, + tnSapBaseStatsIngressDroppedPackets => { oid => '.1.3.6.1.4.1.7483.7.2.2.2.8.1.1.1.9' }, +}; + +my $oid_tnSapDescription = '.1.3.6.1.4.1.7483.6.1.2.4.3.2.1.5'; +my $oid_tnSvcName = '.1.3.6.1.4.1.7483.6.1.2.4.2.2.1.28'; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + # SNMP Get is slow for Dropped, Ingress, Egress. So we are doing in 2 times. + $self->{sap} = {}; + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $oid_tnSapDescription }, + { oid => $oid_tnSvcName }, + ], + nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result->{$oid_tnSapDescription}}) { + next if ($oid !~ /^$oid_tnSapDescription\.(.*?)\.(.*?)\.(.*?)\.(.*?)$/); + my ($SysSwitchId, $SvcId, $SapPortId, $SapEncapValue) = ($1, $2, $3, $4); + my $instance = $SysSwitchId . '.' . $SvcId . '.' . $SapPortId . '.' . $SapEncapValue; + + my $SapDescription = $snmp_result->{$oid_tnSapDescription}->{$oid}; + my $SvcName = defined($snmp_result->{$oid_tnSvcName}->{$oid_tnSvcName . '.' . $SysSwitchId . '.' . $SvcId}) ? + $snmp_result->{$oid_tnSvcName}->{$oid_tnSvcName . '.' . $SysSwitchId . '.' . $SvcId} : ''; + + my $name = $self->get_display_name(SapDescription => $SapDescription, SvcName => $SvcName, SysSwitchId => $SysSwitchId, SvcId => $SvcId, SapPortId => $SapPortId, SapEncapValue => $SapEncapValue); + 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->{sap}->{$instance} = { display => $name }; + } + + $options{snmp}->load(oids => [$mapping->{tnSapBaseStatsIngressForwardedOctets}->{oid}, + $mapping->{tnSapBaseStatsEgressForwardedOctets}->{oid}, $mapping->{tnSapBaseStatsIngressDroppedPackets}->{oid}, + $mapping->{tnSapAdminStatus}->{oid}, $mapping->{tnSapOperStatus}->{oid}], + instances => [keys %{$self->{sap}}], instance_regexp => '(\d+\.\d+\.\d+\.\d+)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + foreach (keys %{$self->{sap}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $_); + $self->{sap}->{$_}->{in} = $result->{tnSapBaseStatsIngressForwardedOctets} * 8; + $self->{sap}->{$_}->{out} = $result->{tnSapBaseStatsEgressForwardedOctets} * 8; + $self->{sap}->{$_}->{in_dropped_packets} = $result->{tnSapBaseStatsIngressDroppedPackets}; + $self->{sap}->{$_}->{status} = $result->{tnSapAdminStatus}; + $self->{sap}->{$_}->{admin} = $result->{tnSapOperStatus}; + } + + if (scalar(keys %{$self->{sap}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No SAP found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "alcatel_pss_1830_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check SAP QoS usage. + +=over 8 + +=item B<--display-name> + +Display name (Default: '%{SysSwitchId}.%{SvcId}.%{SapPortId}.%{SapEncapValue}'). +Can also be: %{SapDescription}, %{SvcName} + +=item B<--filter-name> + +Filter by SAP name (can be a regexp). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--warning-status> + +Set warning threshold for ib status. +Can used special variables like: %{admin}, %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for ib status (Default: '%{admin} =~ /up/i and %{status} !~ /up/i'). +Can used special variables like: %{admin}, %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'in-traffic', 'out-traffic', 'in-drop-packets'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'in-traffic', 'out-traffic', 'in-drop-packets'. + +=back + +=cut diff --git a/network/alcatel/pss/1830/snmp/plugin.pm b/network/alcatel/pss/1830/snmp/plugin.pm new file mode 100644 index 000000000..54ab95e29 --- /dev/null +++ b/network/alcatel/pss/1830/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::alcatel::pss::1830::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}} = ( + 'sap-qos-stats' => 'network::alcatel::pss::1830::snmp::mode::sapqosstats', + 'list-sap' => 'network::alcatel::pss::1830::snmp::mode::listsap', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Alcatel 1830 Photonic Service Switch (PSS) in SNMP. + +=cut diff --git a/network/audiocodes/snmp/mode/components/fantray.pm b/network/audiocodes/snmp/mode/components/fantray.pm new file mode 100644 index 000000000..984ba78c2 --- /dev/null +++ b/network/audiocodes/snmp/mode/components/fantray.pm @@ -0,0 +1,78 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::components::fantray; + +use strict; +use warnings; + +my %map_status = ( + 0 => 'cleared', + 1 => 'indeterminate', + 2 => 'warning', + 3 => 'minor', + 4 => 'major', + 5 => 'critical', +); +my %map_existence = ( + 1 => 'present', + 2 => 'missing', +); + +my $mapping = { + acSysFanTrayExistence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.22.1.3', map => \%map_existence }, + acSysFanTraySeverity => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.22.1.6', map => \%map_status }, +}; +my $oid_acSysFanTrayEntry = '.1.3.6.1.4.1.5003.9.10.10.4.22.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acSysFanTrayEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fantray"); + $self->{components}->{fantray} = {name => 'fantray', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fantray')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_acSysFanTrayEntry}})) { + next if ($oid !~ /^$mapping->{acSysFanTraySeverity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysFanTrayEntry}, instance => $instance); + + next if ($result->{acSysFanTrayExistence} eq 'missing' && + $self->absent_problem(section => 'fantray', instance => $instance)); + next if ($self->check_filter(section => 'fantray', instance => $instance)); + + $self->{components}->{fantray}->{total}++; + $self->{output}->output_add(long_msg => sprintf("Fan tray '%s' status is '%s' [instance = %s]", + $instance, $result->{acSysFanTraySeverity}, $instance)); + my $exit = $self->get_severity(label => 'default', section => 'fantray', value => $result->{acSysFanTraySeverity}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan tray '%s' status is '%s'", $instance, $result->{acSysFanTraySeverity})); + } + } +} + +1; \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/components/module.pm b/network/audiocodes/snmp/mode/components/module.pm new file mode 100644 index 000000000..72a9be9fe --- /dev/null +++ b/network/audiocodes/snmp/mode/components/module.pm @@ -0,0 +1,79 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::components::module; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'moduleNotExist', + 2 => 'moduleExistOk', + 3 => 'moduleOutOfService', + 4 => 'moduleBackToServiceStart', + 5 => 'moduleMismatch', + 6 => 'moduleFaulty', + 7 => 'notApplicable', +); +my %map_existence = ( + 1 => 'present', + 2 => 'missing', +); + +my $mapping = { + acSysModulePresence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.4', map => \%map_existence }, + acSysModuleFRUstatus => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.21.1.14', map => \%map_status }, +}; +my $oid_acSysModuleEntry = '.1.3.6.1.4.1.5003.9.10.10.4.21.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acSysModuleEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking modules"); + $self->{components}->{module} = {name => 'modules', total => 0, skip => 0}; + return if ($self->check_filter(section => 'module')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_acSysModuleEntry}})) { + next if ($oid !~ /^$mapping->{acSysModuleFRUstatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysModuleEntry}, instance => $instance); + + next if ($result->{acSysModulePresence} eq 'missing' && + $self->absent_problem(section => 'module', instance => $instance)); + next if ($self->check_filter(section => 'module', instance => $instance)); + + $self->{components}->{module}->{total}++; + $self->{output}->output_add(long_msg => sprintf("module '%s' status is '%s' [instance = %s]", + $instance, $result->{acSysModuleFRUstatus}, $instance)); + my $exit = $self->get_severity(section => 'module', value => $result->{acSysModuleFRUstatus}); + 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'", $instance, $result->{acSysModuleFRUstatus})); + } + } +} + +1; \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/components/psu.pm b/network/audiocodes/snmp/mode/components/psu.pm new file mode 100644 index 000000000..02870b9cd --- /dev/null +++ b/network/audiocodes/snmp/mode/components/psu.pm @@ -0,0 +1,78 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 1 => 'cleared', + 2 => 'indeterminate', + 3 => 'warning', + 4 => 'minor', + 5 => 'major', + 6 => 'critical', +); +my %map_existence = ( + 1 => 'present', + 2 => 'missing', +); + +my $mapping = { + acSysPowerSupplyExistence => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.3', map => \%map_existence }, + acSysPowerSupplySeverity => { oid => '.1.3.6.1.4.1.5003.9.10.10.4.23.1.6', map => \%map_status }, +}; +my $oid_acSysPowerSupplyEntry = '.1.3.6.1.4.1.5003.9.10.10.4.23.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_acSysPowerSupplyEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_acSysPowerSupplyEntry}})) { + next if ($oid !~ /^$mapping->{acSysPowerSupplySeverity}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_acSysPowerSupplyEntry}, instance => $instance); + + next if ($result->{acSysPowerSupplyExistence} eq 'missing' && + $self->absent_problem(section => 'psu', instance => $instance)); + next if ($self->check_filter(section => 'psu', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", + $instance, $result->{acSysPowerSupplySeverity}, $instance)); + my $exit = $self->get_severity(label => 'default', section => 'psu', value => $result->{acSysPowerSupplySeverity}); + 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'", $instance, $result->{acSysPowerSupplySeverity})); + } + } +} + +1; \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/cpu.pm b/network/audiocodes/snmp/mode/cpu.pm new file mode 100644 index 000000000..86475ae57 --- /dev/null +++ b/network/audiocodes/snmp/mode/cpu.pm @@ -0,0 +1,106 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'voip', set => { + key_values => [ { name => 'voip' } ], + output_template => 'CPU VoIp Usage : %.2f %%', + perfdatas => [ + { label => 'cpu_voip', value => 'voip_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'data', set => { + key_values => [ { name => 'data' } ], + output_template => 'CPU Data Usage : %.2f %%', + perfdatas => [ + { label => 'cpu_data', value => 'data_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_acSysStateVoIpCpuUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.10.0'; + my $oid_acSysStateDataCpuUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.8.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_acSysStateVoIpCpuUtilization, $oid_acSysStateDataCpuUtilization + ], nothing_quit => 1); + + $self->{global} = { data => $snmp_result->{$oid_acSysStateDataCpuUtilization}, voip => $snmp_result->{$oid_acSysStateVoIpCpuUtilization} }; +} + +1; + +__END__ + +=head1 MODE + +Check CPU usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^voip$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'voip', 'data'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'voip', 'data'. + +=back + +=cut diff --git a/network/audiocodes/snmp/mode/hardware.pm b/network/audiocodes/snmp/mode/hardware.pm new file mode 100644 index 000000000..cd029440b --- /dev/null +++ b/network/audiocodes/snmp/mode/hardware.pm @@ -0,0 +1,117 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(module|fantray|psu)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['cleared', 'OK'], + ['indeterminate', 'UNKNOWN'], + ['warning', 'WARNING'], + ['minor', 'WARNING'], + ['major', 'CRITICAL'], + ['critical', 'CRITICAL'], + ], + module => [ + ['moduleNotExist', 'OK'], + ['moduleExistOk', 'OK'], + ['moduleOutOfService', 'CRITICAL'], + ['moduleBackToServiceStart', 'WARNING'], + ['moduleMismatch', 'WARNING'], + ['moduleFaulty', 'CRITICAL'], + ['notApplicable', 'OK'], + ], + }; + + $self->{components_path} = 'network::audiocodes::snmp::mode::components'; + $self->{components_module} = ['module', 'fantray', 'psu']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'fantray', 'module', 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=fan --filter=psu) +Can also exclude specific instance: --filter=fantray,1 + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,^(?!(cleared)$)' + +=back + +=cut \ No newline at end of file diff --git a/network/audiocodes/snmp/mode/memory.pm b/network/audiocodes/snmp/mode/memory.pm new file mode 100644 index 000000000..bcea3b8da --- /dev/null +++ b/network/audiocodes/snmp/mode/memory.pm @@ -0,0 +1,106 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::memory; + +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 => ' - ' }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'voip', set => { + key_values => [ { name => 'voip' } ], + output_template => 'Memory VoIp Usage : %.2f %%', + perfdatas => [ + { label => 'used_voip', value => 'voip_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => 'data', set => { + key_values => [ { name => 'data' } ], + output_template => 'Memory Data Usage : %.2f %%', + perfdatas => [ + { label => 'used_data', value => 'data_absolute', template => '%.2f', min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_acSysStateVoIpMemoryUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.11.0'; + my $oid_acSysStateDataMemoryUtilization = '.1.3.6.1.4.1.5003.9.10.10.2.5.9.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_acSysStateVoIpMemoryUtilization, $oid_acSysStateDataMemoryUtilization + ], nothing_quit => 1); + + $self->{global} = { data => $snmp_result->{$oid_acSysStateDataMemoryUtilization}, voip => $snmp_result->{$oid_acSysStateVoIpMemoryUtilization} }; +} + +1; + +__END__ + +=head1 MODE + +Check memory usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^voip$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'voip', 'data'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'voip', 'data'. + +=back + +=cut diff --git a/network/audiocodes/snmp/mode/trunkstatus.pm b/network/audiocodes/snmp/mode/trunkstatus.pm new file mode 100644 index 000000000..547cac179 --- /dev/null +++ b/network/audiocodes/snmp/mode/trunkstatus.pm @@ -0,0 +1,192 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::mode::trunkstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'alarm status : ' . $self->{result_values}->{alarm} . ' [state: ' . $self->{result_values}->{state} . ']'; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{alarm} = $options{new_datas}->{$self->{instance} . '_alarm'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{dchannel} = $options{new_datas}->{$self->{instance} . '_dchannel'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'trunk', type => 1, cb_prefix_output => 'prefix_vpn_output', message_multiple => 'All trunks are ok' } + ]; + + $self->{maps_counters}->{trunk} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'display' }, { name => 'dchannel' }, { name => 'alarm' }, { name => 'state' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +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-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_vpn_output { + my ($self, %options) = @_; + + return "Trunk '" . $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 %map_alarm = (0 => 'greyDisabled', 1 => 'greenActive', 2 => 'redLosLof', +3 => 'blueAis', 4 => 'yellowRai', 5 => 'orangeDChannel', 6 => 'purpleLowerLayerDown', 7 => 'darkOrangeNFASAlarm'); +my %map_dchannel = (0 => 'dChannelEstablished', 1 => 'dChannelNotEstablished', 10 => 'dChannelNotApplicable'); +my %map_deactivate = (0 => 'notAvailable', 1 => 'deActivated', 2 => 'activated'); + +my $mapping = { + acTrunkStatusDChannel => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.6', map => \%map_dchannel }, + acTrunkStatusAlarm => { oid => '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1.7', map => \%map_alarm }, + acTrunkDeactivate => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.11', map => \%map_deactivate }, + acTrunkName => { oid => '.1.3.6.1.4.1.5003.9.10.9.1.1.1.1.1.13' }, +}; +my $oid_acTrunkStatusEntry = '.1.3.6.1.4.1.5003.9.10.9.2.1.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{trunk} = {}; + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $mapping->{acTrunkName}->{oid} }, + { oid => $mapping->{acTrunkDeactivate}->{oid} }, + { oid => $oid_acTrunkStatusEntry }, + ], nothing_quit => 1, return_type => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{acTrunkStatusAlarm}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{trunk}->{$instance} = { + display => defined($result->{acTrunkName}) && $result->{acTrunkName} ne '' ? $result->{acTrunkName} : $instance, + alarm => $result->{acTrunkStatusAlarm}, + state => $result->{acTrunkDeactivate}, + dchannel => $result->{acTrunkStatusDChannel} }; + } + + if (scalar(keys %{$self->{trunk}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No trunk found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check vpn status. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{display}, %{alarm}, %{dchannel}, %{state} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{state} =~ /activated/ and %{alarm} !~ /greenActive/i'). +Can used special variables like: %{display}, %{alarm}, %{dchannel}, %{state} + +=back + +=cut diff --git a/network/audiocodes/snmp/plugin.pm b/network/audiocodes/snmp/plugin.pm new file mode 100644 index 000000000..d77abafc2 --- /dev/null +++ b/network/audiocodes/snmp/plugin.pm @@ -0,0 +1,53 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::audiocodes::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::audiocodes::snmp::mode::cpu', + 'hardware' => 'network::audiocodes::snmp::mode::hardware', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::audiocodes::snmp::mode::memory', + 'trunk-status' => 'network::audiocodes::snmp::mode::trunkstatus', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Audiocodes equipments (Mediant) in SNMP. + +=cut diff --git a/network/beeware/snmp/mode/listreverseproxy.pm b/network/beeware/snmp/mode/listreverseproxy.pm new file mode 100644 index 000000000..cbe53b19e --- /dev/null +++ b/network/beeware/snmp/mode/listreverseproxy.pm @@ -0,0 +1,124 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::beeware::snmp::mode::listreverseproxy; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +my %mapping_running = ( + 0 => 'down', + 1 => 'running', +); + +my $oid_rp = '.1.3.6.1.4.1.30800.132'; +my $oid_running_suffix = '133.57'; # 1 seems running + +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-status:s" => { name => 'filter_status' }, + }); + $self->{rp} = {}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_rp, + nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$oid_rp\.(.*?)\.$oid_running_suffix$/ || defined($self->{rp}->{$1})); + my $instance = $1; + + my $status = defined($mapping_running{$snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_running_suffix}}) ? + $mapping_running{$snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_running_suffix}} : 'unknown'; + if (defined($self->{option_results}->{filter_status}) && $self->{option_results}->{filter_status} ne '' && + $status !~ /$self->{option_results}->{filter_status}/) { + $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter.", debug => 1); + next; + } + + $self->{rp}->{$instance} = { status => $status }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{rp}}) { + $self->{output}->output_add(long_msg => '[instance = ' . $instance . "] [status = '" . $self->{rp}->{$instance}->{status} . "']"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List reverse proxies:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['instance', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{rp}}) { + $self->{output}->add_disco_entry(instance => $instance, status => $self->{rp}->{$instance}->{status}); + } +} + +1; + +__END__ + +=head1 MODE + +List reverse proxies. + +=over 8 + +=item B<--filter-status> + +Filter which status (can be a regexp). + +=back + +=cut + \ No newline at end of file diff --git a/network/beeware/snmp/mode/reverseproxyusage.pm b/network/beeware/snmp/mode/reverseproxyusage.pm new file mode 100644 index 000000000..bf5eb71ac --- /dev/null +++ b/network/beeware/snmp/mode/reverseproxyusage.pm @@ -0,0 +1,241 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::beeware::snmp::mode::reverseproxyusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'rp', type => 1, cb_prefix_output => 'prefix_rp_output', message_multiple => 'All reverse proxy are ok' } + ]; + + $self->{maps_counters}->{rp} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'display' }, { name => 'status' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'cpu', set => { + key_values => [ { name => 'cpu' }, { name => 'display' } ], + output_template => 'CPU Usage : %.2f %%', + perfdatas => [ + { label => 'cpu', value => 'cpu_absolute', template => '%.2f', + min => 0, max => 100, unit => '%', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'memory', set => { + key_values => [ { name => 'memory' }, { name => 'display' } ], + output_template => 'Memory Usage : %s %s', + output_change_bytes => 1, + perfdatas => [ + { label => 'memory', value => 'memory_absolute', template => '%s', + min => 0, unit => 'B', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'nbchilds', set => { + key_values => [ { name => 'nbchilds' }, { name => 'display' } ], + output_template => 'Num childs : %s', + perfdatas => [ + { label => 'nbchilds', value => 'nbchilds_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_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 => + { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} !~ /running/i' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub prefix_rp_output { + my ($self, %options) = @_; + + return "Reverse proxy '" . $options{instance_value}->{display} . "' "; +} + +my %mapping_running = ( + 0 => 'down', + 1 => 'running', +); + +my $oid_rp = '.1.3.6.1.4.1.30800.132'; +my $oid_cpu_suffix = '31.57'; +my $oid_memory_suffix = '117.57'; # MB +my $oid_nbchils_suffix = '119.57'; +my $oid_running_suffix = '133.57'; # 1 seems running + +sub manage_selection { + my ($self, %options) = @_; + + $self->{rp} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_rp, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$oid_rp\.(.*?)\.$oid_running_suffix$/ || defined($self->{rp}->{$1})); + my $instance = $1; + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $instance !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $instance . "': no matching filter.", debug => 1); + next; + } + + $self->{rp}->{$instance} = { display => $instance, + cpu => $snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_cpu_suffix}, + memory => $snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_memory_suffix} * 1024 * 1024, + nbchilds => $snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_nbchils_suffix}, + status => defined($mapping_running{$snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_running_suffix}}) ? + $mapping_running{$snmp_result->{$oid_rp . '.' . $instance . '.' . $oid_running_suffix}} : 'unknown', + }; + } + + if (scalar(keys %{$self->{rp}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No reverse proxy found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check reverse proxy usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^cpu|memory$' + +=item B<--filter-name> + +Filter reverse proxy (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} !~ /running/i'). +Can used special variables like: %{display}, %{status} + +=item B<--warning-*> + +Threshold warning. +Can be: 'cpu', 'memory' (B), 'nbchilds'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'cpu', 'memory' (B), 'nbchilds'. + +=back + +=cut diff --git a/network/beeware/snmp/plugin.pm b/network/beeware/snmp/plugin.pm new file mode 100644 index 000000000..0b63c0a10 --- /dev/null +++ b/network/beeware/snmp/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::beeware::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}} = ( + 'list-reverse-proxy' => 'network::beeware::snmp::mode::listreverseproxy', + 'reverse-proxy-usage' => 'network::beeware::snmp::mode::reverseproxyusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Beeware equipments in SNMP. +Please use plugin SNMP Linux for system checks ('cpu', 'memory', 'traffic',...). + +=cut diff --git a/network/brocade/mode/cpu.pm b/network/brocade/snmp/mode/cpu.pm similarity index 86% rename from network/brocade/mode/cpu.pm rename to network/brocade/snmp/mode/cpu.pm index 12e66fa6a..b58e36880 100644 --- a/network/brocade/mode/cpu.pm +++ b/network/brocade/snmp/mode/cpu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::brocade::mode::cpu; +package network::brocade::snmp::mode::cpu; use base qw(centreon::plugins::mode); @@ -62,13 +62,17 @@ sub run { my $oid_swCpuUsage = '.1.3.6.1.4.1.1588.2.1.1.1.26.1.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_swFwFabricWatchLicense, $oid_swCpuUsage], nothing_quit => 1); - if ($result->{$oid_swFwFabricWatchLicense} == 2) { - $self->{output}->add_option_msg(short_msg => "Need Fabric Watch License to get information."); + if (!defined($result->{$oid_swCpuUsage})) { + if ($result->{$oid_swFwFabricWatchLicense} == 2) { + $self->{output}->add_option_msg(short_msg => "Need Fabric Watch License to get information."); + $self->{output}->option_exit(); + } + $self->{output}->add_option_msg(short_msg => "Cannot get information."); $self->{output}->option_exit(); } my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_swCpuUsage}, - 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("CPU Usage: %.2f%%", $result->{$oid_swCpuUsage})); $self->{output}->perfdata_add(label => "cpu", unit => '%', diff --git a/network/brocade/mode/hardware.pm b/network/brocade/snmp/mode/hardware.pm similarity index 98% rename from network/brocade/mode/hardware.pm rename to network/brocade/snmp/mode/hardware.pm index 5b30a71e2..755d2e8e6 100644 --- a/network/brocade/mode/hardware.pm +++ b/network/brocade/snmp/mode/hardware.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::brocade::mode::hardware; +package network::brocade::snmp::mode::hardware; use base qw(centreon::plugins::mode); diff --git a/network/brocade/mode/memory.pm b/network/brocade/snmp/mode/memory.pm similarity index 86% rename from network/brocade/mode/memory.pm rename to network/brocade/snmp/mode/memory.pm index 9ae0a41ed..6ebf64077 100644 --- a/network/brocade/mode/memory.pm +++ b/network/brocade/snmp/mode/memory.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::brocade::mode::memory; +package network::brocade::snmp::mode::memory; use base qw(centreon::plugins::mode); @@ -62,13 +62,17 @@ sub run { my $oid_swMemUsage = '.1.3.6.1.4.1.1588.2.1.1.1.26.6.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_swFwFabricWatchLicense, $oid_swMemUsage], nothing_quit => 1); - if ($result->{$oid_swFwFabricWatchLicense} == 2) { - $self->{output}->add_option_msg(short_msg => "Need Fabric Watch License to get information."); + if (!defined($result->{$oid_swMemUsage})) { + if ($result->{$oid_swFwFabricWatchLicense} == 2) { + $self->{output}->add_option_msg(short_msg => "Need Fabric Watch License to get information."); + $self->{output}->option_exit(); + } + $self->{output}->add_option_msg(short_msg => "Cannot get information."); $self->{output}->option_exit(); } my $exit = $self->{perfdata}->threshold_check(value => $result->{$oid_swMemUsage}, - 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("Memory Usage: %.2f%% used", $result->{$oid_swMemUsage})); $self->{output}->perfdata_add(label => "used", unit => '%', diff --git a/network/brocade/plugin.pm b/network/brocade/snmp/plugin.pm similarity index 93% rename from network/brocade/plugin.pm rename to network/brocade/snmp/plugin.pm index bbf7ea36c..d445cd74f 100644 --- a/network/brocade/plugin.pm +++ b/network/brocade/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::brocade::plugin; +package network::brocade::snmp::plugin; use strict; use warnings; @@ -31,11 +31,11 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::brocade::mode::cpu', - 'hardware' => 'network::brocade::mode::hardware', + 'cpu' => 'network::brocade::snmp::mode::cpu', + 'hardware' => 'network::brocade::snmp::mode::hardware', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'memory' => 'network::brocade::mode::memory', + 'memory' => 'network::brocade::snmp::mode::memory', ); return $self; diff --git a/network/checkpoint/snmp/plugin.pm b/network/checkpoint/snmp/plugin.pm index 687e62f5f..b580c7f29 100644 --- a/network/checkpoint/snmp/plugin.pm +++ b/network/checkpoint/snmp/plugin.pm @@ -31,12 +31,15 @@ sub new { $self->{version} = '0.5'; %{$self->{modes}} = ( - 'connections' => 'network::checkpoint::snmp::mode::connections', - 'cpu' => 'network::checkpoint::snmp::mode::cpu', - 'hardware' => 'network::checkpoint::snmp::mode::hardware', - 'hastate' => 'network::checkpoint::snmp::mode::hastate', - 'memory' => 'network::checkpoint::snmp::mode::memory', - 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', + 'connections' => 'network::checkpoint::snmp::mode::connections', + 'cpu' => 'network::checkpoint::snmp::mode::cpu', + 'hardware' => 'network::checkpoint::snmp::mode::hardware', + 'hastate' => 'network::checkpoint::snmp::mode::hastate', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'network::checkpoint::snmp::mode::memory', + 'vpn-status' => 'network::checkpoint::snmp::mode::vpnstatus', + 'vrrp-status' => 'snmp_standard::mode::vrrp', ); return $self; diff --git a/network/citrix/netscaler/common/mode/certificatesexpire.pm b/network/citrix/netscaler/common/mode/certificatesexpire.pm deleted file mode 100644 index 7720ef181..000000000 --- a/network/citrix/netscaler/common/mode/certificatesexpire.pm +++ /dev/null @@ -1,109 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::citrix::netscaler::common::mode::certificatesexpire; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_sslCertKeyName = '.1.3.6.1.4.1.5951.4.1.1.56.1.1.1'; - my $oid_sslDaysToExpire = '.1.3.6.1.4.1.5951.4.1.1.56.1.1.5'; - my $result = $self->{snmp}->get_multiple_table(oids => [ { oid => $oid_sslCertKeyName }, { oid => $oid_sslDaysToExpire } ], nothing_quit => 1); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All certificates are ok.'); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$result->{$oid_sslCertKeyName}})) { - $oid =~ /^$oid_sslCertKeyName\.(.*)$/; - my $name = $result->{$oid_sslCertKeyName}->{$oid}; - my $days = $result->{$oid_sslDaysToExpire}->{$oid_sslDaysToExpire . '.' . $1}; - - my $exit = $self->{perfdata}->threshold_check(value => $days, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("Certificate '%s': %d days remaining before expiration", - $name, $days)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Certificate '%s': %d days remaining before expiration", - $name, $days)); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check number of days remaining before the expiration of certificates (NS-MIB-smiv2). - -=over 8 - -=item B<--warning> - -Threshold warning in days. - -=item B<--critical> - -Threshold critical in days. - -=back - -=cut - diff --git a/network/citrix/netscaler/common/mode/connections.pm b/network/citrix/netscaler/common/mode/connections.pm deleted file mode 100644 index 2ea6e3872..000000000 --- a/network/citrix/netscaler/common/mode/connections.pm +++ /dev/null @@ -1,189 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::citrix::netscaler::common::mode::connections; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::values; - -my $maps_counters = { - global => { - '000_active' => { set => { - key_values => [ { name => 'active' } ], - output_template => 'Active Server TCP connections : %s', - perfdatas => [ - { label => 'active_server', value => 'active_absolute', template => '%s', - unit => 'con', min => 0 }, - ], - } - }, - '001_server' => { set => { - key_values => [ { name => 'server' } ], - output_template => 'Server TCP connections : %s', - perfdatas => [ - { label => 'server', value => 'server_absolute', template => '%s', - unit => 'con', min => 0 }, - ], - } - }, - '002_client' => { set => { - key_values => [ { name => 'client' } ], - output_template => 'Client TCP connections : %s', - perfdatas => [ - { label => 'client', value => 'client_absolute', template => '%s', - unit => 'con', min => 0 }, - ], - } - }, - }, -}; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); - - foreach my $key (('global')) { - foreach (keys %{$maps_counters->{$key}}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, - perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); - } - } - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach my $key (('global')) { - foreach (keys %{$maps_counters->{$key}}) { - $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); - } - } -} - -sub run_global { - my ($self, %options) = @_; - - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters->{global}}) { - my $obj = $maps_counters->{global}->{$_}->{obj}; - - $obj->set(instance => 'global'); - - my ($value_check) = $obj->execute(values => $self->{global}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $obj->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $obj->threshold_check(); - push @exits, $exit2; - - my $output = $obj->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $obj->perfdata(); - } - - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "$short_msg" - ); - } else { - $self->{output}->output_add(short_msg => "$long_msg"); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - $self->run_global(); - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{global} = { client => 0, server => 0, active => 0 }; - my $oid_tcpCurServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.1.0'; - my $oid_tcpCurClientConn = '.1.3.6.1.4.1.5951.4.1.1.46.2.0'; - my $oid_tcpActiveServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.8.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_tcpCurServerConn, $oid_tcpCurClientConn, $oid_tcpActiveServerConn ], nothing_quit => 1); - $self->{global}->{client} = $result->{$oid_tcpCurClientConn}; - $self->{global}->{server} = $result->{$oid_tcpCurServerConn}; - $self->{global}->{active} = $result->{$oid_tcpActiveServerConn}; -} - -1; - -__END__ - -=head1 MODE - -Check connections usage (Client, Server, ActiveServer) (NS-ROOT-MIBv2). - -=over 8 - -=item B<--warning-*> - -Threshold warning. -Can be: 'server', 'active', 'client'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'server', 'active', 'client'. - -=back - -=cut \ No newline at end of file diff --git a/network/citrix/netscaler/common/mode/health.pm b/network/citrix/netscaler/common/mode/health.pm deleted file mode 100644 index e684a6286..000000000 --- a/network/citrix/netscaler/common/mode/health.pm +++ /dev/null @@ -1,358 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::citrix::netscaler::common::mode::health; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my $oid_nsSysHealthEntry = '.1.3.6.1.4.1.5951.4.1.1.41.7.1'; -my $oid_sysHealthCounterName = '.1.3.6.1.4.1.5951.4.1.1.41.7.1.1'; -my $oid_sysHealthCounterValue = '.1.3.6.1.4.1.5951.4.1.1.41.7.1.2'; - -my $thresholds = { - psu => [ - ['normal', 'OK'], - ['not present', 'OK'], - ['failed', 'CRITICAL'], - ['not supported', 'UNKNOWN'], - ], -}; - -my %map_psu_status = ( - 0 => 'normal', - 1 => 'not present', - 2 => 'failed', - 3 => 'not supported', -); - -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 => - { - "exclude:s" => { name => 'exclude' }, - "component:s" => { name => 'component', default => 'all' }, - "no-component:s" => { name => 'no_component' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - $self->{components} = {}; - $self->{no_components} = undef; - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (defined($self->{option_results}->{no_component})) { - if ($self->{option_results}->{no_component} ne '') { - $self->{no_components} = $self->{option_results}->{no_component}; - } else { - $self->{no_components} = 'critical'; - } - } - - $self->{overload_th} = {}; - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ('psu', $1, $2); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $self->{overload_th}->{$section} = [] if (!defined($self->{overload_th}->{$section})); - push @{$self->{overload_th}->{$section}}, {filter => $filter, status => $status}; - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->{result} = $self->{snmp}->get_table(oid => $oid_nsSysHealthEntry); - - if ($self->{option_results}->{component} eq 'all') { - $self->check_psu(); - $self->check_fanspeed(); - $self->check_temperature(); - $self->check_voltage(); - } elsif ($self->{option_results}->{component} eq 'psu') { - $self->check_psu(); - } elsif ($self->{option_results}->{component} eq 'fanspeed') { - $self->check_fanspeed(); - } elsif ($self->{option_results}->{component} eq 'temperature') { - $self->check_temperature(); - } elsif ($self->{option_results}->{component} eq 'voltage') { - $self->check_voltage(); - } else { - $self->{output}->add_option_msg(short_msg => "Wrong option. Cannot find component '" . $self->{option_results}->{component} . "'."); - $self->{output}->option_exit(); - } - - my $total_components = 0; - my $display_by_component = ''; - my $display_by_component_append = ''; - foreach my $comp (sort(keys %{$self->{components}})) { - # Skipping short msg when no components - next if ($self->{components}->{$comp}->{total} == 0 && $self->{components}->{$comp}->{skip} == 0); - $total_components += $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - my $count_by_components = $self->{components}->{$comp}->{total} + $self->{components}->{$comp}->{skip}; - $display_by_component .= $display_by_component_append . $self->{components}->{$comp}->{total} . '/' . $count_by_components . ' ' . $self->{components}->{$comp}->{name}; - $display_by_component_append = ', '; - } - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %s components are ok [%s].", - $total_components, - $display_by_component, - ) - ); - - if (defined($self->{option_results}->{no_component}) && $total_components == 0) { - $self->{output}->output_add(severity => $self->{no_components}, - short_msg => 'No components are checked.'); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_exclude { - my ($self, %options) = @_; - - if (defined($options{instance})) { - if (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)${options{section}}[^,]*#\Q$options{instance}\E#/) { - $self->{components}->{$options{section}}->{skip}++; - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section $options{instance} instance.")); - return 1; - } - } elsif (defined($self->{option_results}->{exclude}) && $self->{option_results}->{exclude} =~ /(^|\s|,)$options{section}(\s|,|$)/) { - $self->{output}->output_add(long_msg => sprintf("Skipping $options{section} section.")); - return 1; - } - return 0; -} - -sub get_severity { - my ($self, %options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($self->{overload_th}->{$options{section}})) { - foreach (@{$self->{overload_th}->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - - -sub absent_problem { - my ($self, %options) = @_; - - if (defined($self->{option_results}->{absent}) && - $self->{option_results}->{absent} =~ /(^|\s|,)($options{section}(\s*,|$)|${options{section}}[^,]*#\Q$options{instance}\E#)/) { - $self->{output}->output_add(severity => 'CRITICAL', - short_msg => sprintf("Component '%s' instance '%s' is not present", - $options{section}, $options{instance})); - return 1; - } - - return 0; -} - -sub check_fanspeed { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fanspeed"); - $self->{components}->{fanspeed} = {name => 'fanspeed', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'fanspeed')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result}})) { - next if ($oid !~ /^$oid_sysHealthCounterName\.(.*)$/ || $self->{result}->{$oid} !~ /Speed|Fan/i); - my $name = $self->{result}->{$oid}; - $oid =~ /^$oid_sysHealthCounterName\.(.*)$/; - my $value = $self->{result}->{$oid_sysHealthCounterValue . '.' . $1}; - - if ($value == 0) { - $self->{output}->output_add(long_msg => sprintf("Skipping Fanspeed '%s' (counter is 0)", - $name)); - next; - } - - next if ($self->check_exclude(section => 'fanspeed', instance => $name)); - $self->{components}->{fanspeed}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is %s (rpm)", - $name, $value)); - - $self->{output}->perfdata_add(label => "speed_" . $name, unit => 'rpm', - value => $value, - min => 0); - } -} - -sub check_psu { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'psu')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result}})) { - next if ($oid !~ /^$oid_sysHealthCounterName\.(.*)$/ || $self->{result}->{$oid} !~ /PowerSupply(.)FailureStatus/i); - my $instance = $1; - my $name = $self->{result}->{$oid}; - $oid =~ /^$oid_sysHealthCounterName\.(.*)$/; - my $value = $self->{result}->{$oid_sysHealthCounterValue . '.' . $1}; - - next if ($map_psu_status{$value} eq 'not present' && - $self->absent_problem(section => 'psu', instance => $instance)); - - next if ($self->check_exclude(section => 'psu', instance => $instance)); - $self->{components}->{psu}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Power Supply '%s' status is %s", - $instance, $map_psu_status{$value})); - my $exit = $self->get_severity(section => 'psu', value => $map_psu_status{$value}); - 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", - $instance, $map_psu_status{$value})); - } - } -} - -sub check_voltage { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking voltages"); - $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'voltage')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result}})) { - next if ($oid !~ /^$oid_sysHealthCounterName\.(.*)$/ || $self->{result}->{$oid} !~ /Voltage|IntelCPUVttPower/i); - my $name = $self->{result}->{$oid}; - $oid =~ /^$oid_sysHealthCounterName\.(.*)$/; - my $value = $self->{result}->{$oid_sysHealthCounterValue . '.' . $1} / 1000; # in mv - - if ($value == 0) { - $self->{output}->output_add(long_msg => sprintf("Skipping voltage '%s' (counter is 0)", - $name)); - next; - } - - next if ($self->check_exclude(section => 'voltage', instance => $name)); - $self->{components}->{voltage}->{total}++; - $self->{output}->output_add(long_msg => sprintf("Voltage '%s' is %.2f V", - $name, $value)); - - $self->{output}->perfdata_add(label => "volt_" . $name, unit => 'V', - value => sprintf("%.2f", $value), - min => 0); - } -} - -sub check_temperature { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures"); - $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; - return if ($self->check_exclude(section => 'temperature')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{result}})) { - next if ($oid !~ /^$oid_sysHealthCounterName\.(.*)$/ || $self->{result}->{$oid} !~ /temperature/i); - my $name = $self->{result}->{$oid}; - $oid =~ /^$oid_sysHealthCounterName\.(.*)$/; - my $value = $self->{result}->{$oid_sysHealthCounterValue . '.' . $1}; # in C - - if ($value == 0) { - $self->{output}->output_add(long_msg => sprintf("Skipping temperature '%s' (counter is 0)", - $name)); - next; - } - - next if ($self->check_exclude(section => 'temperature', instance => $name)); - $self->{components}->{temperature}->{total}++; - $self->{output}->output_add(long_msg => sprintf("temperature '%s' is %s C", - $name, $value)); - - $self->{output}->perfdata_add(label => "temp_" . $name, unit => 'C', - value => $value, - min => 0); - } -} - -1; - -__END__ - -=head1 MODE - -Check System Health Status (temperatures, voltages, power supplies, fanspeed). - -=over 8 - -=item B<--component> - -Which component to check (Default: 'all'). -Can be: 'temperature', 'voltage', 'fanspeed', 'psu'. - -=item B<--exclude> - -Exclude some parts (comma seperated list) (Example: --exclude=psu) -Can also exclude specific instance: --exclude='psu#1#' - -=item B<--no-component> - -Return an error if no compenents are checked. -If total (with skipped) is 0. (Default: 'critical' returns). - -=item B<--absent-problem> - -Return an error if an entity is not 'present' (default is 'ok') (only for psu) -Can be specific or global: --exclude=psu#1# - -=item B<--threshold-overload> - -Set to overload default threshold values (syntax: status,regexp). -It used before default thresholds (order stays) (only for psu). -Example: --threshold-overload='CRITICAL,^(?!(normal)$)' - -=back - -=cut diff --git a/network/citrix/netscaler/common/mode/storage.pm b/network/citrix/netscaler/common/mode/storage.pm deleted file mode 100644 index 4e9c8f1db..000000000 --- a/network/citrix/netscaler/common/mode/storage.pm +++ /dev/null @@ -1,127 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::citrix::netscaler::common::mode::storage; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_nsSysHealthDiskEntry = '.1.3.6.1.4.1.5951.4.1.1.41.8.1'; - my $oid_sysHealthDiskName = '.1.3.6.1.4.1.5951.4.1.1.41.8.1.1'; - my $oid_sysHealthDiskSize = '.1.3.6.1.4.1.5951.4.1.1.41.8.1.2'; # in MB - my $oid_sysHealthDiskUsed = '.1.3.6.1.4.1.5951.4.1.1.41.8.1.4'; # in MB - my $result = $self->{snmp}->get_table(oid => $oid_nsSysHealthDiskEntry, nothing_quit => 1); - - $self->{output}->output_add(severity => 'OK', - short_msg => 'All storages are ok.'); - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($oid !~ /^$oid_sysHealthDiskName\.(.*)$/); - my $name = $result->{$oid}; - my $total_used = $result->{$oid_sysHealthDiskUsed . '.' . $1} * 1024 * 1024; - my $total_size = $result->{$oid_sysHealthDiskSize . '.' . $1} * 1024 * 1024; - my $total_free = $total_size - $total_used; - my $prct_used = $total_used * 100 / $total_size; - my $prct_free = 100 - $prct_used; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $total_free); - - $self->{output}->output_add(long_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); - } - - $self->{output}->perfdata_add(label => 'used_' . $name, unit => 'B', - value => $total_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); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check disk usages (NS-MIB-smiv2). - -=over 8 - -=item B<--warning> - -Threshold warning in percent. - -=item B<--critical> - -Threshold critical in percent. - -=back - -=cut - diff --git a/network/citrix/netscaler/common/mode/vserverstatus.pm b/network/citrix/netscaler/common/mode/vserverstatus.pm deleted file mode 100644 index c790d9c48..000000000 --- a/network/citrix/netscaler/common/mode/vserverstatus.pm +++ /dev/null @@ -1,335 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::citrix::netscaler::common::mode::vserverstatus; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::values; - -my $maps_counters = { - status => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'state' }, - ], - closure_custom_calc => \&custom_status_calc, - closure_custom_output => \&custom_status_output, - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => \&custom_threshold_output, - } - }, - health => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'health' }, { name => 'display' }, - ], - output_template => 'Health: %.2f %%', output_error_template => 'Health: %s', - output_use => 'health_absolute', threshold_use => 'health_absolute', - perfdatas => [ - { value => 'health_absolute', label => 'health', template => '%.2f', - unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, - ], - } - }, -}; - -my $overload_th = {}; -my $oid_vsvrName = '.1.3.6.1.4.1.5951.4.1.3.1.1.1'; -my $oid_vsvrState = '.1.3.6.1.4.1.5951.4.1.3.1.1.5'; -my $oid_vsvrHealth = '.1.3.6.1.4.1.5951.4.1.3.1.1.62'; -my $oid_vsvrEntityType = '.1.3.6.1.4.1.5951.4.1.3.1.1.64'; - -my $thresholds = { - vs => [ - ['unknown', 'UNKNOWN'], - ['down|outOfService|transitionToOutOfService|transitionToOutOfServiceDown', 'CRITICAL'], - ['up', 'OK'], - ], -}; - -my %map_vs_type = ( - 0 => 'unknown', - 1 => 'loadbalancing', - 2 => 'loadbalancinggroup', - 3 => 'sslvpn', - 4 => 'contentswitching', - 5 => 'cacheredirection', -); - -my %map_vs_status = ( - 1 => 'down', - 2 => 'unknown', - 3 => 'busy', - 4 => 'outOfService', - 5 => 'transitionToOutOfService', - 7 => 'up', - 8 => 'transitionToOutOfServiceDown', -); - -sub get_severity { - my (%options) = @_; - my $status = 'UNKNOWN'; # default - - if (defined($overload_th->{$options{section}})) { - foreach (@{$overload_th->{$options{section}}}) { - if ($options{value} =~ /$_->{filter}/i) { - $status = $_->{status}; - return $status; - } - } - } - foreach (@{$thresholds->{$options{section}}}) { - if ($options{value} =~ /$$_[0]/i) { - $status = $$_[1]; - return $status; - } - } - - return $status; -} - -sub custom_threshold_output { - my ($self, %options) = @_; - - return get_severity(section => 'vs', value => $map_vs_status{$self->{result_values}->{state}}); -} - -sub custom_status_output { - my ($self, %options) = @_; - my $msg = 'State : ' . $map_vs_status{$self->{result_values}->{state}}; - - return $msg; -} - -sub custom_status_calc { - my ($self, %options) = @_; - - $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; - return 0; -} - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "name:s" => { name => 'name' }, - "regexp" => { name => 'use_regexp' }, - "filter-type:s" => { name => 'filter_type' }, - "threshold-overload:s@" => { name => 'threshold_overload' }, - }); - - $self->{vs_id_selected} = {}; - - foreach (keys %{$maps_counters}) { - $options{options}->add_options(arguments => { - 'warning-' . $_ . ':s' => { name => 'warning-' . $_ }, - 'critical-' . $_ . ':s' => { name => 'critical-' . $_ }, - }); - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $_); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } - foreach my $val (@{$self->{option_results}->{threshold_overload}}) { - if ($val !~ /^(.*?),(.*)$/) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); - $self->{output}->option_exit(); - } - my ($section, $status, $filter) = ('vs', $1, $2); - if ($self->{output}->is_litteral_status(status => $status) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); - $self->{output}->option_exit(); - } - $overload_th->{$section} = [] if (!defined($overload_th->{$section})); - push @{$overload_th->{$section}}, {filter => $filter, status => $status}; - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - - my $multiple = 1; - if (scalar(keys %{$self->{vs_id_selected}}) == 1) { - $multiple = 0; - } - - if ($multiple == 1) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All Virtual Servers are ok.'); - } - - foreach my $id (sort keys %{$self->{vs_id_selected}}) { - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => $id); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{vs_id_selected}->{$id}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(extra_instance => $multiple); - } - - $self->{output}->output_add(long_msg => "Virtual Server '" . $self->{vs_id_selected}->{$id}->{display} . "' $long_msg"); - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Virtual Server '" . $self->{vs_id_selected}->{$id}->{display} . "' $short_msg" - ); - } - - if ($multiple == 0) { - $self->{output}->output_add(short_msg => "Virtual Server '" . $self->{vs_id_selected}->{$id}->{display} . "' $long_msg"); - } - } - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub add_result { - my ($self, %options) = @_; - - $self->{vs_id_selected}->{$options{instance}} = {}; - $self->{vs_id_selected}->{$options{instance}}->{display} = $self->{results}->{$oid_vsvrName}->{$oid_vsvrName . '.' . $options{instance}}; - $self->{vs_id_selected}->{$options{instance}}->{health} = $self->{results}->{$oid_vsvrHealth}->{$oid_vsvrHealth . '.' . $options{instance}}; - $self->{vs_id_selected}->{$options{instance}}->{state} = $self->{results}->{$oid_vsvrState}->{$oid_vsvrState . '.' . $options{instance}}; -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{results} = $self->{snmp}->get_multiple_table(oids => [ - { oid => $oid_vsvrName }, - { oid => $oid_vsvrState }, - { oid => $oid_vsvrHealth }, - { oid => $oid_vsvrEntityType }, - ], - , nothing_quit => 1); - - foreach my $oid (keys %{$self->{results}->{$oid_vsvrName}}) { - $oid =~ /^$oid_vsvrName\.(.*)$/; - my $instance = $1; - my $filter_name = $self->{results}->{$oid_vsvrName}->{$oid}; - my $filter_type = $self->{results}->{$oid_vsvrEntityType}->{$oid_vsvrEntityType . '.' . $instance}; - - if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && - $map_vs_type{$filter_type} !~ /$self->{option_results}->{filter_type}/) { - $self->{output}->output_add(long_msg => "Skipping Virtual Server '" . $filter_name . "'."); - next; - } - if (!defined($self->{option_results}->{name})) { - $self->add_result(instance => $instance); - next; - } - if (!defined($self->{option_results}->{use_regexp}) && $filter_name eq $self->{option_results}->{name}) { - $self->add_result(instance => $instance); - } - if (defined($self->{option_results}->{use_regexp}) && $filter_name =~ /$self->{option_results}->{name}/) { - $self->add_result(instance => $instance); - } - } - - if (scalar(keys %{$self->{vs_id_selected}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No Virtual Server found '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No Virtual Server found."); - } - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check vservers status and health. - -=over 8 - -=item B<--warning-health> - -Threshold warning in percent. - -=item B<--critical-health> - -Threshold critical in percent. - -=item B<--name> - -Set the virtual server name. - -=item B<--regexp> - -Allows to use regexp to filter virtual server name (with option --name). - -=item B<--filter-type> - -Filter which type of vserver (can be a regexp). - -=item B<--threshold-overload> - -Set to overload default threshold values (syntax: status,regexp) -It used before default thresholds (order stays). -Example: --threshold-overload='CRITICAL,^(?!(green)$)' - -=back - -=cut diff --git a/network/citrix/netscaler/snmp/mode/certificatesexpire.pm b/network/citrix/netscaler/snmp/mode/certificatesexpire.pm new file mode 100644 index 000000000..1b650e39c --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/certificatesexpire.pm @@ -0,0 +1,125 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::certificatesexpire; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'certificates', type => 1, cb_prefix_output => 'prefix_certificates_output', message_multiple => 'All certificates are ok' } + ]; + + $self->{maps_counters}->{certificates} = [ + { label => 'days', set => { + key_values => [ { name => 'days' }, { name => 'display' } ], + output_template => '%d days remaining before expiration', + closure_custom_perfdata => sub { return 0; }, + } + }, + ]; +} + +sub prefix_certificates_output { + my ($self, %options) = @_; + + return "Certificate '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + + return $self; +} + +my $mapping = { + sslCertKeyName => { oid => '.1.3.6.1.4.1.5951.4.1.1.56.1.1.1' }, + sslDaysToExpire => { oid => '.1.3.6.1.4.1.5951.4.1.1.56.1.1.5' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{certificates} = {}; + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{sslCertKeyName}->{oid} }, { oid => $mapping->{sslDaysToExpire}->{oid} } ], + return_type => 1, nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sslCertKeyName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{sslCertKeyName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sslCertKeyName} . "': no matching filter.", debug => 1); + next; + } + + $self->{certificates}->{$instance} = { + display => $result->{sslCertKeyName}, + days => $result->{sslDaysToExpire}, + }; + } + + if (scalar(keys %{$self->{certificates}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No certificate found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check number of days remaining before the expiration of certificates (NS-MIB-smiv2). + +=over 8 + +=item B<--filter-name> + +Filter by name (can be a regexp). + +=item B<--warning-days> + +Threshold warning in days. + +=item B<--critical-days> + +Threshold critical in days. + +=back + +=cut + diff --git a/network/citrix/netscaler/snmp/mode/components/fanspeed.pm b/network/citrix/netscaler/snmp/mode/components/fanspeed.pm new file mode 100644 index 000000000..4ca5567f4 --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/components/fanspeed.pm @@ -0,0 +1,71 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::components::fanspeed; + +use strict; +use warnings; + +my $mapping = { + sysHealthCounterName => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.1' }, + sysHealthCounterValue => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.2' }, +}; +my $oid_nsSysHealthEntry = '.1.3.6.1.4.1.5951.4.1.1.41.7.1'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fanspeed} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fanspeed')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsSysHealthEntry}})) { + next if ($oid !~ /^$mapping->{sysHealthCounterName}->{oid}\.(.*)$/); + my $instance = $1; + next if ($self->{results}->{$oid_nsSysHealthEntry}->{$oid} !~ /Speed|Fan/i); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsSysHealthEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fanspeed', instance => $instance)); + if ($result->{sysHealthCounterValue} == 0) { + $self->{output}->output_add(long_msg => sprintf("skipping fan '%s' (counter is 0)", + $result->{sysHealthCounterName})); + next; + } + + $self->{components}->{fanspeed}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan '%s' speed is %s C [instance = %s]", + $result->{sysHealthCounterName}, $result->{sysHealthCounterValue}, $instance)); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fanspeed', instance => $instance, value => $result->{sysHealthCounterValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan '%s' speed is %s rpm", $result->{sysHealthCounterName}, $result->{sysHealthCounterValue})); + } + $self->{output}->perfdata_add(label => 'speed_' . $result->{sysHealthCounterName}, unit => 'rpm', + value => $result->{sysHealthCounterValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; \ No newline at end of file diff --git a/network/citrix/netscaler/snmp/mode/components/psu.pm b/network/citrix/netscaler/snmp/mode/components/psu.pm new file mode 100644 index 000000000..761cc134c --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/components/psu.pm @@ -0,0 +1,71 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_psu_status = ( + 0 => 'normal', + 1 => 'not present', + 2 => 'failed', + 3 => 'not supported', +); + +my $mapping = { + sysHealthCounterName => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.1' }, + sysHealthCounterValue => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.2', map => \%map_psu_status }, +}; +my $oid_nsSysHealthEntry = '.1.3.6.1.4.1.5951.4.1.1.41.7.1'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my ($exit, $warn, $crit, $checked); + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsSysHealthEntry}})) { + next if ($oid !~ /^$mapping->{sysHealthCounterName}->{oid}\.(.*)$/); + my $instance = $1; + next if ($self->{results}->{$oid_nsSysHealthEntry}->{$oid} !~ /PowerSupply(.)(?:Status|FailureStatus)/i); + my $power_num = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsSysHealthEntry}, instance => $instance); + + next if ($result->{sysHealthCounterValue} eq 'not present' && + $self->absent_problem(section => 'psu', instance => $power_num)); + next if ($self->check_filter(section => 'psu', instance => $instance)); + + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply '%s' status is '%s' [instance = %s]", + $power_num, $result->{sysHealthCounterValue}, $power_num)); + $exit = $self->get_severity(section => 'psu', value => $result->{sysHealthCounterValue}); + 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'", $power_num, $result->{sysHealthCounterValue})); + } + } +} + +1; \ No newline at end of file diff --git a/network/citrix/netscaler/snmp/mode/components/temperature.pm b/network/citrix/netscaler/snmp/mode/components/temperature.pm new file mode 100644 index 000000000..268f45a7a --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/components/temperature.pm @@ -0,0 +1,71 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + sysHealthCounterName => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.1' }, + sysHealthCounterValue => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.2' }, +}; +my $oid_nsSysHealthEntry = '.1.3.6.1.4.1.5951.4.1.1.41.7.1'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperatures"); + $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsSysHealthEntry}})) { + next if ($oid !~ /^$mapping->{sysHealthCounterName}->{oid}\.(.*)$/); + my $instance = $1; + next if ($self->{results}->{$oid_nsSysHealthEntry}->{$oid} !~ /temperature/i); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsSysHealthEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + if ($result->{sysHealthCounterValue} == 0) { + $self->{output}->output_add(long_msg => sprintf("skipping temperature '%s' (counter is 0)", + $result->{sysHealthCounterName})); + next; + } + + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("temperature '%s' is %s C [instance = %s]", + $result->{sysHealthCounterName}, $result->{sysHealthCounterValue}, $instance)); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{sysHealthCounterValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is %s C", $result->{sysHealthCounterName}, $result->{sysHealthCounterValue})); + } + $self->{output}->perfdata_add(label => 'temp_' . $result->{sysHealthCounterName}, unit => 'C', + value => $result->{sysHealthCounterValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; \ No newline at end of file diff --git a/network/citrix/netscaler/snmp/mode/components/voltage.pm b/network/citrix/netscaler/snmp/mode/components/voltage.pm new file mode 100644 index 000000000..f5b72228e --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/components/voltage.pm @@ -0,0 +1,72 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::components::voltage; + +use strict; +use warnings; + +my $mapping = { + sysHealthCounterName => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.1' }, + sysHealthCounterValue => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.7.1.2' }, +}; +my $oid_nsSysHealthEntry = '.1.3.6.1.4.1.5951.4.1.1.41.7.1'; + +sub load {} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking voltages"); + $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; + return if ($self->check_filter(section => 'voltage')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_nsSysHealthEntry}})) { + next if ($oid !~ /^$mapping->{sysHealthCounterName}->{oid}\.(.*)$/); + my $instance = $1; + next if ($self->{results}->{$oid_nsSysHealthEntry}->{$oid} !~ /Voltage|IntelCPUVttPower/i); + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_nsSysHealthEntry}, instance => $instance); + + next if ($self->check_filter(section => 'voltage', instance => $instance)); + if ($result->{sysHealthCounterValue} == 0) { + $self->{output}->output_add(long_msg => sprintf("skipping voltage '%s' (counter is 0)", + $result->{sysHealthCounterName})); + next; + } + + $result->{sysHealthCounterValue} = $result->{sysHealthCounterValue} / 1000; # in mv + $self->{components}->{voltage}->{total}++; + $self->{output}->output_add(long_msg => sprintf("voltage '%s' is %s V [instance = %s]", + $result->{sysHealthCounterName}, $result->{sysHealthCounterValue}, $instance)); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{sysHealthCounterValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Voltage '%s' is %s V", $result->{sysHealthCounterName}, $result->{sysHealthCounterValue})); + } + $self->{output}->perfdata_add(label => 'volt_' . $result->{sysHealthCounterName}, unit => 'V', + value => $result->{sysHealthCounterValue}, + warning => $warn, + critical => $crit, min => 0 + ); + } +} + +1; \ No newline at end of file diff --git a/network/citrix/netscaler/snmp/mode/connections.pm b/network/citrix/netscaler/snmp/mode/connections.pm new file mode 100644 index 000000000..75718c11d --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/connections.pm @@ -0,0 +1,114 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::connections; + +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 => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'active', set => { + key_values => [ { name => 'active' } ], + output_template => 'Active Server TCP connections : %s', + perfdatas => [ + { label => 'active_server', value => 'active_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + { label => 'server', set => { + key_values => [ { name => 'server' } ], + output_template => 'Server TCP connections : %s', + perfdatas => [ + { label => 'server', value => 'server_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + { label => 'client', set => { + key_values => [ { name => 'client' } ], + output_template => 'Client TCP connections : %s', + perfdatas => [ + { label => 'client', value => 'client_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { client => 0, server => 0, active => 0 }; + my $oid_tcpCurServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.1.0'; + my $oid_tcpCurClientConn = '.1.3.6.1.4.1.5951.4.1.1.46.2.0'; + my $oid_tcpActiveServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.8.0'; + my $result = $options{snmp}->get_leef(oids => [$oid_tcpCurServerConn, $oid_tcpCurClientConn, $oid_tcpActiveServerConn ], nothing_quit => 1); + $self->{global}->{client} = $result->{$oid_tcpCurClientConn}; + $self->{global}->{server} = $result->{$oid_tcpCurServerConn}; + $self->{global}->{active} = $result->{$oid_tcpActiveServerConn}; +} + +1; + +__END__ + +=head1 MODE + +Check connections usage (Client, Server, ActiveServer) (NS-ROOT-MIBv2). + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'server', 'active', 'client'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'server', 'active', 'client'. + +=back + +=cut \ No newline at end of file diff --git a/network/citrix/netscaler/common/mode/cpu.pm b/network/citrix/netscaler/snmp/mode/cpu.pm similarity index 98% rename from network/citrix/netscaler/common/mode/cpu.pm rename to network/citrix/netscaler/snmp/mode/cpu.pm index a523883f1..86dd9b2ad 100644 --- a/network/citrix/netscaler/common/mode/cpu.pm +++ b/network/citrix/netscaler/snmp/mode/cpu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::citrix::netscaler::common::mode::cpu; +package network::citrix::netscaler::snmp::mode::cpu; use base qw(centreon::plugins::mode); diff --git a/network/citrix/netscaler/common/mode/hastate.pm b/network/citrix/netscaler/snmp/mode/hastate.pm similarity index 98% rename from network/citrix/netscaler/common/mode/hastate.pm rename to network/citrix/netscaler/snmp/mode/hastate.pm index 36d261b75..f624abfcc 100644 --- a/network/citrix/netscaler/common/mode/hastate.pm +++ b/network/citrix/netscaler/snmp/mode/hastate.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::citrix::netscaler::common::mode::hastate; +package network::citrix::netscaler::snmp::mode::hastate; use base qw(centreon::plugins::mode); diff --git a/network/citrix/netscaler/snmp/mode/health.pm b/network/citrix/netscaler/snmp/mode/health.pm new file mode 100644 index 000000000..ef052a3d3 --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/health.pm @@ -0,0 +1,129 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::health; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(psu)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(temperature|fanspeed|voltage)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + psu => [ + ['normal', 'OK'], + ['not present', 'OK'], + ['failed', 'CRITICAL'], + ['not supported', 'UNKNOWN'], + ], + }; + + $self->{components_path} = 'network::citrix::netscaler::snmp::mode::components'; + $self->{components_module} = ['psu', 'fanspeed', 'temperature', 'voltage']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + my $oid_nsSysHealthEntry = '.1.3.6.1.4.1.5951.4.1.1.41.7.1'; + push @{$self->{request}}, { oid => $oid_nsSysHealthEntry }; + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +my $oid_sysHealthCounterName = '.1.3.6.1.4.1.5951.4.1.1.41.7.1.1'; +my $oid_sysHealthCounterValue = '.1.3.6.1.4.1.5951.4.1.1.41.7.1.2'; + +my %map_psu_status = ( + 0 => 'normal', + 1 => 'not present', + 2 => 'failed', + 3 => 'not supported', +); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check System Health Status. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'temperature', 'voltage', 'fanspeed', 'psu'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=psu) +Can also exclude specific instance: --filter=fan,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--absent-problem> + +Return an error if an entity is not 'present' (default is skipping) (comma seperated list) +Can be specific or global: --absent-problem=psu,1 + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,CRITICAL,^(?!(normal)$)' + +=item B<--warning> + +Set warning threshold for 'temperature', 'fanspeed', 'voltage' (syntax: type,regexp,threshold) +Example: --warning='temperature,.,30' + +=item B<--critical> + +Set critical threshold for 'temperature', 'fanspeed', 'voltage'(syntax: type,regexp,threshold) +Example: --critical='temperature,.*,40' + +=back + +=cut diff --git a/network/citrix/netscaler/common/mode/listvservers.pm b/network/citrix/netscaler/snmp/mode/listvservers.pm similarity index 98% rename from network/citrix/netscaler/common/mode/listvservers.pm rename to network/citrix/netscaler/snmp/mode/listvservers.pm index 25d9c4767..32e00a915 100644 --- a/network/citrix/netscaler/common/mode/listvservers.pm +++ b/network/citrix/netscaler/snmp/mode/listvservers.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::citrix::netscaler::common::mode::listvservers; +package network::citrix::netscaler::snmp::mode::listvservers; use base qw(centreon::plugins::mode); diff --git a/network/citrix/netscaler/common/mode/memory.pm b/network/citrix/netscaler/snmp/mode/memory.pm similarity index 98% rename from network/citrix/netscaler/common/mode/memory.pm rename to network/citrix/netscaler/snmp/mode/memory.pm index 79e53917f..6988f8ff8 100644 --- a/network/citrix/netscaler/common/mode/memory.pm +++ b/network/citrix/netscaler/snmp/mode/memory.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::citrix::netscaler::common::mode::memory; +package network::citrix::netscaler::snmp::mode::memory; use base qw(centreon::plugins::mode); diff --git a/network/citrix/netscaler/snmp/mode/storage.pm b/network/citrix/netscaler/snmp/mode/storage.pm new file mode 100644 index 000000000..cb8dd5bde --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/storage.pm @@ -0,0 +1,216 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::storage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'storage', type => 1, cb_prefix_output => 'prefix_storage_output', message_multiple => 'All storages are ok' } + ]; + + $self->{maps_counters}->{storage} = [ + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub prefix_volume_output { + my ($self, %options) = @_; + + return "Storage '" . $options{instance_value}->{display} . "' "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +my $mapping = { + sysHealthDiskName => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.8.1.1' }, + sysHealthDiskSize => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.8.1.2' }, # in MB + sysHealthDiskUsed => { oid => '.1.3.6.1.4.1.5951.4.1.1.41.8.1.4' }, # in MB +}; +my $oid_nsSysHealthDiskEntry = '.1.3.6.1.4.1.5951.4.1.1.41.8.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{storage} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_nsSysHealthDiskEntry, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sysHealthDiskName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{sysHealthDiskName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sysHealthDiskName} . "': no matching filter.", debug => 1); + next; + } + + $result->{sysHealthDiskSize} *= 1024 * 1024; + $result->{sysHealthDiskUsed} *= 1024 * 1024; + $self->{storage}->{$instance} = { + display => $result->{sysHealthDiskName}, + total => $result->{sysHealthDiskSize}, + used => $result->{sysHealthDiskUsed} + }; + } + + if (scalar(keys %{$self->{storage}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No storage found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check disk usages (NS-MIB-smiv2). + +=over 8 + +=item B<--filter-name> + +Filter storage name (can be a regexp). + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut + diff --git a/network/citrix/netscaler/snmp/mode/vserverstatus.pm b/network/citrix/netscaler/snmp/mode/vserverstatus.pm new file mode 100644 index 000000000..16be3b63c --- /dev/null +++ b/network/citrix/netscaler/snmp/mode/vserverstatus.pm @@ -0,0 +1,323 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::citrix::netscaler::snmp::mode::vserverstatus; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vservers', type => 1, cb_prefix_output => 'prefix_vservers_output', message_multiple => 'All Virtual Servers are ok' } + ]; + + $self->{maps_counters}->{vservers} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'state' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_threshold_output'), + } + }, + { label => 'health', set => { + key_values => [ { name => 'health' }, { name => 'display' } ], + output_template => 'Health: %.2f %%', output_error_template => 'Health: %s', + perfdatas => [ + { value => 'health_absolute', label => 'health', template => '%.2f', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'in-traffic', set => { + key_values => [ { name => 'in', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In: %s %s/s', + perfdatas => [ + { label => 'traffic_in', value => 'in_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'out-traffic', set => { + key_values => [ { name => 'out', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out: %s %s/s', + perfdatas => [ + { label => 'traffic_out', value => 'out_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'clients', set => { + key_values => [ { name => 'clients', diff => 1 }, { name => 'display' } ], + output_template => 'Total Client Connections : %s', + perfdatas => [ + { label => 'clients', value => 'clients_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'servers', set => { + key_values => [ { name => 'servers', diff => 1 }, { name => 'display' } ], + output_template => 'Total Server Connections : %s', + perfdatas => [ + { label => 'servers', value => 'servers_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_vservers_output { + my ($self, %options) = @_; + + return "Virtual Server '" . $options{instance_value}->{display} . "' "; +} + +my $overload_th = {}; + +my $thresholds = { + vs => [ + ['unknown', 'UNKNOWN'], + ['down|outOfService|transitionToOutOfService|transitionToOutOfServiceDown', 'CRITICAL'], + ['up', 'OK'], + ], +}; + +sub get_severity { + my (%options) = @_; + my $status = 'UNKNOWN'; # default + + if (defined($overload_th->{$options{section}})) { + foreach (@{$overload_th->{$options{section}}}) { + if ($options{value} =~ /$_->{filter}/i) { + $status = $_->{status}; + return $status; + } + } + } + foreach (@{$thresholds->{$options{section}}}) { + if ($options{value} =~ /$$_[0]/i) { + $status = $$_[1]; + return $status; + } + } + + return $status; +} + +sub custom_threshold_output { + my ($self, %options) = @_; + + return get_severity(section => 'vs', value => $self->{result_values}->{state}); +} + +sub custom_status_output { + my ($self, %options) = @_; + my $msg = 'State : ' . $self->{result_values}->{state}; + + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "filter-type:s" => { name => 'filter_type' }, + "threshold-overload:s@" => { name => 'threshold_overload' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + foreach my $val (@{$self->{option_results}->{threshold_overload}}) { + if ($val !~ /^(.*?),(.*)$/) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload option '" . $val . "'."); + $self->{output}->option_exit(); + } + my ($section, $status, $filter) = ('vs', $1, $2); + if ($self->{output}->is_litteral_status(status => $status) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong threshold-overload status '" . $val . "'."); + $self->{output}->option_exit(); + } + $overload_th->{$section} = [] if (!defined($overload_th->{$section})); + push @{$overload_th->{$section}}, {filter => $filter, status => $status}; + } +} + +my %map_vs_type = ( + 0 => 'unknown', + 1 => 'loadbalancing', + 2 => 'loadbalancinggroup', + 3 => 'sslvpn', + 4 => 'contentswitching', + 5 => 'cacheredirection', +); + +my %map_vs_status = ( + 1 => 'down', + 2 => 'unknown', + 3 => 'busy', + 4 => 'outOfService', + 5 => 'transitionToOutOfService', + 7 => 'up', + 8 => 'transitionToOutOfServiceDown', +); + +my $mapping = { + vsvrName => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.1' }, + vsvrState => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.5', map => \%map_vs_status }, + vsvrEntityType => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.64', map => \%map_vs_type }, +}; +my $mapping2 = { + vsvrTotalRequestBytesLow => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.13' }, + vsvrTotalRequestBytesHigh => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.14' }, + vsvrTotalResponseBytesLow => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.17' }, + vsvrTotalResponseBytesHigh => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.18' }, + vsvrTotalRequestBytes => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.31' }, + vsvrTotalResponseBytes => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.33' }, + vsvrTotalClients => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.56' }, + vsvrHealth => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.62' }, + vsvrTotalServers => { oid => '.1.3.6.1.4.1.5951.4.1.3.1.1.65' }, +}; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $mapping->{vsvrName}->{oid} }, + { oid => $mapping->{vsvrState}->{oid} }, + { oid => $mapping->{vsvrEntityType}->{oid} }, + ], return_type => 1, nothing_quit => 1); + $self->{vservers} = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{vsvrName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_type}) && $self->{option_results}->{filter_type} ne '' && + $result->{vsvrEntityType} !~ /$self->{option_results}->{filter_type}/) { + $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{vsvrName} . "'.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{vsvrName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{vsvrName} . "'.", debug => 1); + next; + } + + $self->{vservers}->{$instance} = { display => $result->{vsvrName}, state => $result->{vsvrState} }; + } + + $options{snmp}->load(oids => [$mapping2->{vsvrTotalRequestBytesLow}->{oid}, $mapping2->{vsvrTotalRequestBytesHigh}->{oid}, + $mapping2->{vsvrTotalResponseBytesLow}->{oid}, $mapping2->{vsvrTotalResponseBytesHigh}->{oid}, + $mapping2->{vsvrTotalRequestBytes}->{oid}, $mapping2->{vsvrTotalResponseBytes}->{oid}, + $mapping2->{vsvrTotalClients}->{oid}, $mapping2->{vsvrHealth}->{oid}, $mapping2->{vsvrTotalServers}->{oid} + ], + instances => [keys %{$self->{vservers}}], instance_regexp => '^(.*)$'); + $snmp_result = $options{snmp}->get_leef(nothing_quit => 1); + + foreach (keys %{$self->{vservers}}) { + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result, instance => $_); + + $self->{vservers}->{$_}->{in} = (defined($result->{vsvrTotalResponseBytes}) ? $result->{vsvrTotalResponseBytes} : + (($result->{vsvrTotalResponseBytesHigh} << 32) + $result->{vsvrTotalResponseBytesLow})) * 8; + $self->{vservers}->{$_}->{out} = (defined($result->{vsvrTotalRequestBytes}) ? $result->{vsvrTotalRequestBytes} : + (($result->{vsvrTotalRequestBytesHigh} << 32) + $result->{vsvrTotalRequestBytesLow})) * 8; + $self->{vservers}->{$_}->{health} = $result->{vsvrHealth}; + $self->{vservers}->{$_}->{clients} = $result->{vsvrTotalClients}; + $self->{vservers}->{$_}->{servers} = $result->{vsvrTotalServers}; + } + + if (scalar(keys %{$self->{vservers}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtual server found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "citrix_netscaler_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_type}) ? md5_hex($self->{option_results}->{filter_type}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check vservers status and health. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'in-traffic', 'out-traffic', 'health' (%), +'clients', 'servers'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'in-traffic', 'out-traffic', 'health' (%), +'clients', 'servers'. + +=item B<--filter-name> + +Filter by virtual server name (can be a regexp). + +=item B<--filter-type> + +Filter which type of vserver (can be a regexp). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='CRITICAL,^(?!(green)$)' + +=back + +=cut diff --git a/network/citrix/netscaler/mpx8000/plugin.pm b/network/citrix/netscaler/snmp/plugin.pm similarity index 81% rename from network/citrix/netscaler/mpx8000/plugin.pm rename to network/citrix/netscaler/snmp/plugin.pm index 45562411c..833f5fcde 100644 --- a/network/citrix/netscaler/mpx8000/plugin.pm +++ b/network/citrix/netscaler/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::citrix::netscaler::mpx8000::plugin; +package network::citrix::netscaler::snmp::plugin; use strict; use warnings; @@ -29,19 +29,19 @@ sub new { my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; - $self->{version} = '0.5'; + $self->{version} = '0.6'; %{$self->{modes}} = ( - 'certificates-expire' => 'network::citrix::netscaler::common::mode::certificatesexpire', - 'cpu' => 'network::citrix::netscaler::common::mode::cpu', - 'storage' => 'network::citrix::netscaler::common::mode::storage', - 'health' => 'network::citrix::netscaler::common::mode::health', - 'ha-state' => 'network::citrix::netscaler::common::mode::hastate', + 'certificates-expire' => 'network::citrix::netscaler::snmp::mode::certificatesexpire', + 'cpu' => 'network::citrix::netscaler::snmp::mode::cpu', + 'storage' => 'network::citrix::netscaler::snmp::mode::storage', + 'health' => 'network::citrix::netscaler::snmp::mode::health', + 'ha-state' => 'network::citrix::netscaler::snmp::mode::hastate', 'interfaces' => 'snmp_standard::mode::interfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces', - 'list-vservers' => 'network::citrix::netscaler::common::mode::listvservers', - 'vserver-status' => 'network::citrix::netscaler::common::mode::vserverstatus', - 'memory' => 'network::citrix::netscaler::common::mode::memory', - 'connections' => 'network::citrix::netscaler::common::mode::connections', + 'list-vservers' => 'network::citrix::netscaler::snmp::mode::listvservers', + 'vserver-status' => 'network::citrix::netscaler::snmp::mode::vserverstatus', + 'memory' => 'network::citrix::netscaler::snmp::mode::memory', + 'connections' => 'network::citrix::netscaler::snmp::mode::connections', ); return $self; @@ -53,6 +53,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Citrix NetScaler MPX 8000 Series in SNMP. +Check Citrix NetScaler Series in SNMP. =cut diff --git a/network/f5/bigip/snmp/mode/components/fan.pm b/network/f5/bigip/snmp/mode/components/fan.pm index d3be38bfb..60b21728b 100644 --- a/network/f5/bigip/snmp/mode/components/fan.pm +++ b/network/f5/bigip/snmp/mode/components/fan.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::f5::bigip::mode::components::fan; +package network::f5::bigip::snmp::mode::components::fan; use strict; use warnings; diff --git a/network/f5/bigip/snmp/mode/components/psu.pm b/network/f5/bigip/snmp/mode/components/psu.pm index bf94c0a11..fb3ac1224 100644 --- a/network/f5/bigip/snmp/mode/components/psu.pm +++ b/network/f5/bigip/snmp/mode/components/psu.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::f5::bigip::mode::components::psu; +package network::f5::bigip::snmp::mode::components::psu; use strict; use warnings; diff --git a/network/f5/bigip/snmp/mode/components/temperature.pm b/network/f5/bigip/snmp/mode/components/temperature.pm index ffe245e54..ebd2cac2c 100644 --- a/network/f5/bigip/snmp/mode/components/temperature.pm +++ b/network/f5/bigip/snmp/mode/components/temperature.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::f5::bigip::mode::components::temperature; +package network::f5::bigip::snmp::mode::components::temperature; use strict; use warnings; diff --git a/network/fortinet/fortigate/plugin.pm b/network/fortinet/fortigate/plugin.pm index e0a9815c6..9af09f4d8 100644 --- a/network/fortinet/fortigate/plugin.pm +++ b/network/fortinet/fortigate/plugin.pm @@ -37,6 +37,7 @@ sub new { 'hardware' => 'centreon::common::fortinet::fortigate::mode::hardware', 'interfaces' => 'snmp_standard::mode::interfaces', 'ips-stats' => 'centreon::common::fortinet::fortigate::mode::ipsstats', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-virtualdomains' => 'centreon::common::fortinet::fortigate::mode::listvirtualdomains', 'memory' => 'centreon::common::fortinet::fortigate::mode::memory', 'sessions' => 'centreon::common::fortinet::fortigate::mode::sessions', diff --git a/network/netasq/local/mode/qosusage.pm b/network/netasq/local/mode/qosusage.pm index ee4e9d3d5..a8e80e8c9 100644 --- a/network/netasq/local/mode/qosusage.pm +++ b/network/netasq/local/mode/qosusage.pm @@ -36,7 +36,7 @@ sub set_counters { $self->{maps_counters}->{qos} = [ { label => 'in', set => { - key_values => [ { name => 'in' }, { name => 'display' } ], + key_values => [ { name => 'in' }, { name => 'display' }, { name => 'speed_in' } ], closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, closure_custom_output => $self->can('custom_qos_output'), closure_custom_perfdata => $self->can('custom_qos_perfdata'), @@ -54,7 +54,7 @@ sub set_counters { } }, { label => 'out', set => { - key_values => [ { name => 'out' }, { name => 'display' } ], + key_values => [ { name => 'out' }, { name => 'display' }, { name => 'speed_out' } ], closure_custom_calc => $self->can('custom_qos_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, closure_custom_output => $self->can('custom_qos_output'), closure_custom_perfdata => $self->can('custom_qos_perfdata'), @@ -132,7 +132,10 @@ sub custom_qos_calc { $self->{result_values}->{label} = $options{extra_options}->{label_ref}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{traffic} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}}; - if (defined($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { + if ($options{new_datas}->{$self->{instance} . '_speed_' . $self->{result_values}->{label}} > 0) { + $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $self->{result_values}->{label}} * 1000 * 1000; + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / $self->{result_values}->{speed}; + } elsif (defined($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000); $self->{result_values}->{speed} = $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000; } @@ -157,10 +160,11 @@ sub new { "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 => 'tail' }, - "command-path:s" => { name => 'command_path' }, - "command-options:s" => { name => 'command_options', default => '-1 /log/l_monitor' }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command', default => 'tail' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options', default => '-1 /log/l_monitor' }, + "config-speed-file:s" => { name => 'config_speed_file' }, }); return $self; @@ -187,6 +191,36 @@ sub prefix_qos_output { return "QoS '" . $options{instance_value}->{display} . "' "; } +sub load_speed_config { + my ($self, %options) = @_; + + $self->{config_speeds} = {}; + return if (!defined($self->{option_results}->{config_speed_file}) || $self->{option_results}->{config_speed_file} eq ''); + $self->{content} = do { + local $/ = undef; + if (open my $fh, "<", $self->{option_results}->{config_speed_file}) { + <$fh>; + } + }; + return if (!defined($self->{content})); + #[TEST] + #Type=CBQ + #Min=0 + #Max=5000 + #Min_Rev=0 + #Max_Rev=5000 + #QLength=0 + #PrioritizeAck=1 + #PrioritizeLowDelay=1 + #Color=000000 + #Comment= + # + # Units: Kb + while ($self->{content} =~ /\[(.*?)\].*?Max=(.*?)\n.*?Max_Rev=(.*?)\n/msg) { + $self->{config_speeds}->{$1} = { speed_in => $3 / 1000, speed_out => $2 / 1000 } + } +} + sub manage_selection { my ($self, %options) = @_; @@ -198,6 +232,7 @@ sub manage_selection { command_path => $self->{option_results}->{command_path}, command_options => $self->{option_results}->{command_options}); + $self->load_speed_config(); $self->{qos} = {}; while ($content =~ /(\S+?)=([^,]+?),(\d+),(\d+),(\d+),(\d+)(?:\s|\Z)/msg) { @@ -216,7 +251,9 @@ sub manage_selection { $self->{qos}->{$name} = { display => $name, in => $in, in_peak => $in_max, - out => $out, out_peak => $out_max }; + out => $out, out_peak => $out_max, + speed_in => defined($self->{config_speeds}->{$name}->{speed_in}) ? $self->{config_speeds}->{$name}->{speed_in} : 0, + speed_out => defined($self->{config_speeds}->{$name}->{speed_out}) ? $self->{config_speeds}->{$name}->{speed_out} : 0}; } if (scalar(keys %{$self->{qos}}) <= 0) { @@ -288,6 +325,10 @@ Set interface speed for incoming traffic (in Mb). Set interface speed for outgoing traffic (in Mb). +=item B<--config-speed-file> + +File with speed configurations. + =item B<--units-traffic> Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). diff --git a/network/oracle/infiniband/snmp/mode/infinibandusage.pm b/network/oracle/infiniband/snmp/mode/infinibandusage.pm new file mode 100644 index 000000000..52aea1cdb --- /dev/null +++ b/network/oracle/infiniband/snmp/mode/infinibandusage.pm @@ -0,0 +1,428 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::oracle::infiniband::snmp::mode::infinibandusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'ib', type => 1, cb_prefix_output => 'prefix_ib_output', message_multiple => 'All infiniband interfaces are ok', cb_init => 'skip_empty_ib', skipped_code => { -10 => 1 } }, + { name => 'ibgw', type => 1, cb_prefix_output => 'prefix_ibgw_output', message_multiple => 'All gateway infiniband interfaces are ok', cb_init => 'skip_empty_ibgw', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{ib} = [ + { label => 'ib-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_status_threshold'), + } + }, + { label => 'in', set => { + key_values => [ { name => 'in', diff => 1 }, { name => 'display' }, { name => 'speed_in' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_ib_output'), + closure_custom_perfdata => $self->can('custom_ib_perfdata'), + closure_custom_threshold_check => $self->can('custom_ib_threshold'), + } + }, + { label => 'out', set => { + key_values => [ { name => 'out', diff => 1 }, { name => 'display' }, { name => 'speed_out' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_ib_output'), + closure_custom_perfdata => $self->can('custom_ib_perfdata'), + closure_custom_threshold_check => $self->can('custom_ib_threshold'), + } + }, + ]; + $self->{maps_counters}->{ibgw} = [ + { label => 'ibgw-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_status_threshold'), + } + }, + { label => 'in', set => { + key_values => [ { name => 'in', diff => 1 }, { name => 'display' }, { name => 'speed_in' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'in' }, + closure_custom_output => $self->can('custom_ib_output'), + closure_custom_perfdata => $self->can('custom_ib_perfdata'), + closure_custom_threshold_check => $self->can('custom_ib_threshold'), + } + }, + { label => 'out', set => { + key_values => [ { name => 'out', diff => 1 }, { name => 'display' }, { name => 'speed_out' } ], + per_second => 1, + closure_custom_calc => $self->can('custom_ib_calc'), closure_custom_calc_extra_options => { label_ref => 'out' }, + closure_custom_output => $self->can('custom_ib_output'), + closure_custom_perfdata => $self->can('custom_ib_perfdata'), + closure_custom_threshold_check => $self->can('custom_ib_threshold'), + } + }, + ]; +} + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + my $label = $self->{label}; + $label =~ s/-/_/g; + if (defined($instance_mode->{option_results}->{'critical_' . $label}) && $instance_mode->{option_results}->{'critical_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'critical_' . $label}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{'warning_' . $label}) && $instance_mode->{option_results}->{'warning_' . $label} ne '' && + eval "$instance_mode->{option_results}->{'warning_' . $label}") { + $status = 'warning'; + } + + $instance_mode->{last_status} = 0; + if ($self->{result_values}->{status} ne 'down') { + $instance_mode->{last_status} = 1; + } + }; + 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 custom_ib_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + if (!defined($options{extra_instance}) || $options{extra_instance} != 0) { + $extra_label .= '_' . $self->{result_values}->{display}; + } + + my ($warning, $critical); + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, total => $self->{result_values}->{speed}, cast_int => 1); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $warning = $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}); + $critical = $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}); + } + + $self->{output}->perfdata_add(label => 'traffic_' . $self->{result_values}->{label} . $extra_label, unit => 'b/s', + value => sprintf("%.2f", $self->{result_values}->{traffic}), + warning => $warning, + critical => $critical, + min => 0, max => $self->{result_values}->{speed}); +} + +sub custom_ib_threshold { + my ($self, %options) = @_; + + my $exit = 'ok'; + if ($instance_mode->{option_results}->{units_traffic} eq '%' && defined($self->{result_values}->{speed})) { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic_prct}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } elsif ($instance_mode->{option_results}->{units_traffic} eq 'b/s') { + $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{traffic}, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-' . $self->{label}, exit_litteral => 'warning' } ]); + } + return $exit; +} + +sub custom_ib_output { + my ($self, %options) = @_; + + my ($traffic_value, $traffic_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{traffic}, network => 1); + my ($total_value, $total_unit); + if (defined($self->{result_values}->{speed}) && $self->{result_values}->{speed} =~ /[0-9]/) { + ($total_value, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{speed}, network => 1); + } + + my $msg = sprintf("Traffic %s : %s/s (%s on %s)", + ucfirst($self->{result_values}->{label}), $traffic_value . $traffic_unit, + defined($self->{result_values}->{traffic_prct}) ? sprintf("%.2f%%", $self->{result_values}->{traffic_prct}) : '-', + defined($total_value) ? $total_value . $total_unit : '-'); + return $msg; +} + +sub custom_ib_calc { + my ($self, %options) = @_; + + return -10 if (defined($instance_mode->{last_status}) && $instance_mode->{last_status} == 0); + + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + my $diff_traffic = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}} - $options{old_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}}; + $self->{result_values}->{traffic} = $diff_traffic / $options{delta_time}; + if ($options{new_datas}->{$self->{instance} . '_speed_' . $self->{result_values}->{label}} > 0) { + $self->{result_values}->{speed} = $options{new_datas}->{$self->{instance} . '_speed_' . $self->{result_values}->{label}} * 1000 * 1000; + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / $self->{result_values}->{speed}; + } elsif (defined($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}}) && $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} =~ /[0-9]/) { + $self->{result_values}->{traffic_prct} = $self->{result_values}->{traffic} * 100 / ($instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000); + $self->{result_values}->{speed} = $instance_mode->{option_results}->{'speed_' . $self->{result_values}->{label}} * 1000 * 1000; + } + return 0; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-ib-name:s" => { name => 'filter_ib_name' }, + "filter-ibgw-name:s" => { name => 'filter_ibgw_name' }, + "warning-ib-status:s" => { name => 'warning_ib_status', default => '' }, + "critical-ib-status:s" => { name => 'critical_ib_status', default => '%{status} !~ /active/i' }, + "warning-ibgw-status:s" => { name => 'warning_ibgw_status', default => '' }, + "critical-ibgw-status:s" => { name => 'critical_ibgw_status', default => '%{status} !~ /up/i' }, + "speed-in:s" => { name => 'speed_in' }, + "speed-out:s" => { name => 'speed_out' }, + "units-traffic:s" => { name => 'units_traffic', default => '%' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_ib_status', 'critical_ib_status', 'warning_ibgw_status', 'critical_ibgw_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub prefix_ib_output { + my ($self, %options) = @_; + + return "Infiniband '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_ibgw_output { + my ($self, %options) = @_; + + return "Infiniband gateway '" . $options{instance_value}->{display} . "' "; +} + +sub skip_empty_ib { + my ($self, %options) = @_; + + scalar(keys %{$self->{ib}}) > 0 ? return(0) : return(1); +} + +sub skip_empty_ibgw { + my ($self, %options) = @_; + + scalar(keys %{$self->{ibgw}}) > 0 ? return(0) : return(1); +} + +my %map_link_state = (1 => 'down', 2 => 'init', 3 => 'armed', 4 => 'active', 5 => 'other'); +my %map_gw_link_state = (0 => 'down', 1 => 'up'); +my %map_link_speed = ( +1 => 5000, # sdr-2point5Gbps +2 => 5000, # ddr-5Gbps', +4 => 10000, # qdr-10Gbps +5 => '', # other +); +my $mapping = { + ibSmaPortLinkState => { oid => '.1.3.6.1.4.1.42.2.135.2.2.5.1.1.6', map => \%map_link_state }, + ibSmaPortLinkSpeedActive => { oid => '.1.3.6.1.4.1.42.2.135.2.2.5.1.1.10', map => \%map_link_speed }, +}; +my $mapping2 = { + ibPmaPortXmitData => { oid => '.1.3.6.1.4.1.42.2.135.2.6.1.2.1.3' }, + ibPmaPortRcvData => { oid => '.1.3.6.1.4.1.42.2.135.2.6.1.2.1.4' }, + ibPmaExtPortConnector => { oid => '.1.3.6.1.4.1.42.2.135.2.6.1.2.1.11' }, +}; +my $mapping3 = { + gwPortLongName => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.1.1.3' }, + gwPortLinkState => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.1.1.5', map => \%map_gw_link_state }, +}; +my $mapping4 = { + gwEthRxBytes => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.2.1.4' }, + gwEthTxBytes => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.2.1.13' }, +}; + +my $oid_ibSmaPortInfoEntry = '.1.3.6.1.4.1.42.2.135.2.2.5.1.1'; +my $oid_ibPmaExtPortCntrsEntry = '.1.3.6.1.4.1.42.2.135.2.6.1.2.1'; +my $oid_gwPortStateEntry = '.1.3.6.1.4.1.42.2.135.2.8.1.1.1'; +my $oid_gwEthPortCntrsEntry = '.1.3.6.1.4.1.42.2.135.2.8.1.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $oid_ibSmaPortInfoEntry, end => $mapping->{ibSmaPortLinkSpeedActive}->{oid} }, + { oid => $oid_ibPmaExtPortCntrsEntry }, + { oid => $oid_gwPortStateEntry, end => $mapping3->{gwPortLinkState}->{oid} }, + { oid => $oid_gwEthPortCntrsEntry }, + ], + nothing_quit => 1); + $self->{ib} = {}; + foreach my $oid (keys %{$snmp_result->{ $oid_ibSmaPortInfoEntry }}) { + next if ($oid !~ /^$mapping->{ibSmaPortLinkState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $oid_ibSmaPortInfoEntry }, instance => $instance); + my $result2 = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{ $oid_ibPmaExtPortCntrsEntry }, instance => $instance); + $result2->{ibPmaExtPortConnector} =~ s/\x00//g; + if (defined($self->{option_results}->{filter_ib_name}) && $self->{option_results}->{filter_ib_name} ne '' && + $result2->{ibPmaExtPortConnector} !~ /$self->{option_results}->{filter_ib_name}/) { + $self->{output}->output_add(long_msg => "Skipping '" . $result2->{ibPmaExtPortConnector} . "': no matching filter.", debug => 1); + next; + } + + $self->{ib}->{'ib_' . $instance} = { + display => $result2->{ibPmaExtPortConnector}, + status => $result->{ibSmaPortLinkState}, + in => $result2->{ibPmaPortRcvData} * 4 * 8, out => $result2->{ibPmaPortXmitData} * 4 * 8, + speed_in => $result->{ibSmaPortLinkSpeedActive}, + speed_out => $result->{ibSmaPortLinkSpeedActive}}; + } + + $self->{ibgw} = {}; + foreach my $oid (keys %{$snmp_result->{ $oid_gwPortStateEntry }}) { + next if ($oid !~ /^$mapping3->{gwPortLinkState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping3, results => $snmp_result->{ $oid_gwPortStateEntry }, instance => $instance); + my $result2 = $options{snmp}->map_instance(mapping => $mapping4, results => $snmp_result->{ $oid_gwEthPortCntrsEntry }, instance => $instance); + $result->{gwPortLongName} =~ s/\x00//g; + if (defined($self->{option_results}->{filter_ibgw_name}) && $self->{option_results}->{filter_ibgw_name} ne '' && + $result->{gwPortLongName} !~ /$self->{option_results}->{filter_ibgw_name}/) { + $self->{output}->output_add(long_msg => "Skipping '" . $result->{gwPortLongName} . "': no matching filter.", debug => 1); + next; + } + + $self->{ibgw}->{'ibgw_' . $instance} = { + display => $result->{gwPortLongName}, + status => $result->{gwPortLinkState}, + in => $result2->{gwEthRxBytes} * 8, out => $result2->{gwEthTxBytes} * 8, + speed_in => 10000, + speed_out => 10000}; + } + + if (scalar(keys %{$self->{ibgw}}) <= 0 && scalar(keys %{$self->{ib}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No interfaces found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "oracle_infiniband_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_ib_name}) ? md5_hex($self->{option_results}->{filter_ib_name}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_ibgw_name}) ? md5_hex($self->{option_results}->{filter_ibgw_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check infiniband interfaces usage. + +=over 8 + +=item B<--filter-ib-name> + +Filter by infiniband name (can be a regexp). + +=item B<--filter-ibgw-name> + +Filter by infiniband gateway name (can be a regexp). + +=item B<--speed-in> + +Set interface speed for incoming traffic (in Mb). + +=item B<--speed-out> + +Set interface speed for outgoing traffic (in Mb). + +=item B<--units-traffic> + +Units of thresholds for the traffic (Default: '%') ('%', 'b/s'). + +=item B<--warning-ib-status> + +Set warning threshold for ib status. +Can used special variables like: %{status}, %{display} + +=item B<--critical-ib-status> + +Set critical threshold for ib status (Default: '%{status} !~ /up/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'in', 'out'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'in', 'out'. + +=back + +=cut diff --git a/network/oracle/infiniband/snmp/mode/listinfinibands.pm b/network/oracle/infiniband/snmp/mode/listinfinibands.pm new file mode 100644 index 000000000..16dc3c657 --- /dev/null +++ b/network/oracle/infiniband/snmp/mode/listinfinibands.pm @@ -0,0 +1,155 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::oracle::infiniband::snmp::mode::listinfinibands; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-ib-name:s" => { name => 'filter_ib_name' }, + "filter-ibgw-:s" => { name => 'filter_ibgw_name' }, + }); + $self->{shares} = {}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my %map_link_state = (1 => 'down', 2 => 'init', 3 => 'armed', 4 => 'active', 5 => 'other'); +my %map_gw_link_state = (0 => 'down', 1 => 'up'); +my $mapping = { + ibSmaPortLinkState => { oid => '.1.3.6.1.4.1.42.2.135.2.2.5.1.1.6', map => \%map_link_state }, +}; +my $mapping2 = { + gwPortLongName => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.1.1.3' }, + gwPortLinkState => { oid => '.1.3.6.1.4.1.42.2.135.2.8.1.1.1.5', map => \%map_gw_link_state }, +}; +my $oid_ibPmaExtPortConnector = '.1.3.6.1.4.1.42.2.135.2.6.1.2.1.11'; +my $oid_gwPortStateEntry = '.1.3.6.1.4.1.42.2.135.2.8.1.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ { oid => $mapping->{ibSmaPortLinkState}->{oid} }, + { oid => $oid_ibPmaExtPortConnector }, + { oid => $oid_gwPortStateEntry, end => $mapping2->{gwPortLinkState}->{oid} }, + ], + nothing_quit => 1); + foreach my $oid (keys %{$snmp_result->{ $oid_ibPmaExtPortConnector }}) { + next if ($oid !~ /^$oid_ibPmaExtPortConnector\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{ $mapping->{ibSmaPortLinkState}->{oid} }, instance => $instance); + + $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid} =~ s/\x00//g; + if (defined($self->{option_results}->{filter_ib_name}) && $self->{option_results}->{filter_ib_name} ne '' && + $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid} !~ /$self->{option_results}->{filter_ib_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid} . "': no matching filter.", debug => 1); + next; + } + + $self->{infinibands}->{'ib_' . $instance} = { + name => $snmp_result->{ $oid_ibPmaExtPortConnector }->{$oid}, type => 'ib', status => $result->{ibSmaPortLinkState} }; + } + + foreach my $oid (keys %{$snmp_result->{ $oid_gwPortStateEntry }}) { + next if ($oid !~ /^$mapping2->{gwPortLongName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{ $oid_gwPortStateEntry }, instance => $instance); + + $result->{gwPortLongName} =~ s/\x00//g; + if (defined($self->{option_results}->{filter_ibgw_name}) && $self->{option_results}->{filter_ibgw_name} ne '' && + $result->{gwPortLongName} !~ /$self->{option_results}->{filter_ibgw_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{gwPortLongName} . "': no matching filter.", debug => 1); + next; + } + + $self->{infinibands}->{'ibgw_' . $instance} = { + name => $result->{gwPortLongName}, type => 'ibgw', status => $result->{gwPortLinkState} }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{infinibands}}) { + $self->{output}->output_add(long_msg => '[name = ' . $self->{infinibands}->{$instance}->{name} . + "] [status = " . $self->{infinibands}->{$instance}->{status} . '] [type = ' . $self->{infinibands}->{$instance}->{type} . ']' + ); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List infinibands:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'type', 'status']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{infinibands}}) { + $self->{output}->add_disco_entry(name => $self->{infinibands}->{$instance}->{name}, + status => $self->{infinibands}->{$instance}->{status}, type => $self->{infinibands}->{$instance}->{type}); + } +} + +1; + +__END__ + +=head1 MODE + +List infiniband interfaces. + +=over 8 + +=item B<--filter-ib-name> + +Filter by infiniband name (can be a regexp). + +=item B<--filter-ibgw-name> + +Filter by infiniband gateway name (can be a regexp). + +=back + +=cut + \ No newline at end of file diff --git a/network/oracle/infiniband/snmp/plugin.pm b/network/oracle/infiniband/snmp/plugin.pm new file mode 100644 index 000000000..bb8e8ee86 --- /dev/null +++ b/network/oracle/infiniband/snmp/plugin.pm @@ -0,0 +1,56 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::oracle::infiniband::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu-detailed' => 'snmp_standard::mode::cpudetailed', + 'hardware' => 'centreon::common::sun::snmp::mode::hardware', + 'load' => 'snmp_standard::mode::loadaverage', + 'infiniband-usage' => 'network::oracle::infiniband::snmp::mode::infinibandusage', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-infinibands' => 'network::oracle::infiniband::snmp::mode::listinfinibands', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'memory' => 'snmp_standard::mode::memory', + 'swap' => 'snmp_standard::mode::swap', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Oracle Infiniband Switches in SNMP. + +=cut diff --git a/network/oracle/otd/snmp/mode/listvservers.pm b/network/oracle/otd/snmp/mode/listvservers.pm new file mode 100644 index 000000000..c73e83437 --- /dev/null +++ b/network/oracle/otd/snmp/mode/listvservers.pm @@ -0,0 +1,117 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::oracle::otd::snmp::mode::listvservers; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + }); + $self->{vs} = {}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $oid_vsId = '.1.3.6.1.4.1.111.19.190.1.30.1.2'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_vsId, + nothing_quit => 1); + foreach my $oid (keys %{$snmp_result}) { + my $name = $snmp_result->{$oid}; + 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->{vs}->{$name} = { name => $name }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{vs}}) { + $self->{output}->output_add(long_msg => '[name = ' . $self->{vs}->{$instance}->{name} . "]"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List virtual servers:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{vs}}) { + $self->{output}->add_disco_entry(name => $self->{vs}->{$instance}->{name}); + } +} + +1; + +__END__ + +=head1 MODE + +List infiniband interfaces. + +=over 8 + +=item B<--filter-ib-name> + +Filter by infiniband name (can be a regexp). + +=item B<--filter-ibgw-name> + +Filter by infiniband gateway name (can be a regexp). + +=back + +=cut + \ No newline at end of file diff --git a/network/oracle/otd/snmp/mode/vserverusage.pm b/network/oracle/otd/snmp/mode/vserverusage.pm new file mode 100644 index 000000000..414989a9d --- /dev/null +++ b/network/oracle/otd/snmp/mode/vserverusage.pm @@ -0,0 +1,176 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::oracle::otd::snmp::mode::vserverusage; + +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 => 'vs', type => 1, cb_prefix_output => 'prefix_vs_output', message_multiple => 'All Virtual Servers are ok', skipped_code => { -10 => 1 } }, + ]; + + $self->{maps_counters}->{vs} = [ + { label => 'in', set => { + key_values => [ { name => 'vsInOctets', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic In: %s %s/s', + perfdatas => [ + { label => 'traffic_in', value => 'vsInOctets_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'out', set => { + key_values => [ { name => 'vsOutOctets', diff => 1 }, { name => 'display' } ], + per_second => 1, output_change_bytes => 2, + output_template => 'Traffic Out: %s %s/s', + perfdatas => [ + { label => 'traffic_out', value => 'vsOutOctets_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + } + ]; + my @map = ( + 'count-request', 'Count Requests : %s', 'vsCountRequests', 'count_request', + 'count-2xx', 'Count 2xx Responses : %s', 'vsCount2xx', 'count_2xx', + 'count-3xx', 'Count 3xx Responses : %s', 'vsCount3xx', 'count_3xx', + 'count-4xx', 'Count 4xx Responses : %s', 'vsCount4xx', 'count_4xx', + 'count-5xx', 'Count 5xx Responses : %s', 'vsCount5xx', 'count_5xx', + ); + for (my $i = 0; $i < scalar(@map); $i += 4) { + push @{$self->{maps_counters}->{vs}}, { label => $map[$i], set => { + key_values => [ { name => $map[$i + 2], diff => 1 }, { name => 'display' } ], + output_template => $map[$i + 1], + perfdatas => [ + { label => $map[$i + 3], value => $map[$i + 2] . '_absolute', template => '%s', min => 0, + label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }; + } +} + +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; +} + +sub prefix_vs_output { + my ($self, %options) = @_; + + return "Virtual Server '" . $options{instance_value}->{display} . "' "; +} + +my $mapping = { + vsId => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.2' }, + vsCountRequests => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.3' }, + vsInOctets => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.4' }, + vsOutOctets => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.5' }, + vsCount2xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.6' }, + vsCount3xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.7' }, + vsCount4xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.8' }, + vsCount5xx => { oid => '.1.3.6.1.4.1.111.19.190.1.30.1.9' }, +}; +my $oid_vsEntry = '.1.3.6.1.4.1.111.19.190.1.30.1'; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + my $snmp_result = $options{snmp}->get_table(oid => $oid_vsEntry, end => $mapping->{vsCount5xx}->{oid}, nothing_quit => 1); + $self->{vs} = {}; + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{vsId}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{vsId} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping Virtual Server '" . $result->{vsId} . "'.", debug => 1); + next; + } + + $result->{vsInOctets} *= 8; + $result->{vsOutOctets} *= 8; + $self->{vs}->{$instance} = { + display => $result->{vsId}, + %$result + }; + } + + if (scalar(keys %{$self->{vs}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No virtual server found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "oracle_otd_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check virtual server usage. + +=over 8 + +=item B<--filter-name> + +Filter by vserver name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'in', 'out', 'count-request', +'count-2xx', 'count-3xx', 'count-4xx', 'count-5xx'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'in', 'out', 'count-request', +'count-2xx', 'count-3xx', 'count-4xx', 'count-5xx'. + +=back + +=cut diff --git a/network/oracle/otd/snmp/plugin.pm b/network/oracle/otd/snmp/plugin.pm new file mode 100644 index 000000000..855ecbf50 --- /dev/null +++ b/network/oracle/otd/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::oracle::otd::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}} = ( + 'list-vservers' => 'network::oracle::otd::snmp::mode::listvservers', + 'vserver-usage' => 'network::oracle::otd::snmp::mode::vserverusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Oracle Traffic Director in SNMP. + +=cut diff --git a/network/paloalto/snmp/mode/sessions.pm b/network/paloalto/snmp/mode/sessions.pm index dfa4df0ba..33e2578b9 100644 --- a/network/paloalto/snmp/mode/sessions.pm +++ b/network/paloalto/snmp/mode/sessions.pm @@ -20,167 +20,120 @@ package network::paloalto::snmp::mode::sessions; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; -use centreon::plugins::values; -my $maps_counters = { - '001_active' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'panSessionActive' }, { name => 'panSessionMax' }, - ], - output_template => 'Active : %.2f %%', threshold_use => 'active_prct', output_use => 'active_prct', - closure_custom_calc => \&custom_active_calc, - perfdatas => [ - { label => 'active', value => 'panSessionActive_absolute', template => '%s', - min => 0, max => 'panSessionMax_absolute' }, - ], - } - }, - '002_active-ssl-proxy' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'panSessionSslProxyUtilization' }, - ], - output_template => 'Active SSL Proxy : %.2f %%', - perfdatas => [ - { label => 'active_ssl_proxy', value => 'panSessionSslProxyUtilization_absolute', template => '%.2f', unit => '%', - min => 0, max => 100 }, - ], - } - }, - '003_active-tcp' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'panSessionActiveTcp' }, - ], - output_template => 'Active TCP : %s', - perfdatas => [ - { label => 'active_tcp', value => 'panSessionActiveTcp_absolute', template => '%s', min => 0 }, - ], - } - }, - '004_active-udp' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'panSessionActiveUdp' }, - ], - output_template => 'Active UDP : %s', - perfdatas => [ - { label => 'active_udp', value => 'panSessionActiveUdp_absolute', template => '%s', min => 0 }, - ], - } - }, - '005_active-icmp' => { class => 'centreon::plugins::values', obj => undef, - set => { - key_values => [ - { name => 'panSessionActiveICMP' }, - ], - output_template => 'Active ICMP : %s', - perfdatas => [ - { label => 'active_icmp', value => 'panSessionActiveICMP_absolute', template => '%s', min => 0 }, - ], - } - }, -}; +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + ]; + $self->{maps_counters}->{global} = [ + { label => 'active', set => { + key_values => [ { name => 'panSessionActive' }, { name => 'panSessionMax' } ], + closure_custom_calc => $self->can('custom_active_calc'), + closure_custom_output => $self->can('custom_active_output'), + closure_custom_perfdata => $self->can('custom_active_perfdata'), + closure_custom_threshold_check => $self->can('custom_active_threshold'), + + } + }, + { label => 'active-ssl-proxy', set => { + key_values => [ { name => 'panSessionSslProxyUtilization' } ], + output_template => 'Active SSL Proxy : %.2f %%', + perfdatas => [ + { label => 'active_ssl_proxy', value => 'panSessionSslProxyUtilization_absolute', template => '%.2f', unit => '%', + min => 0, max => 100 }, + ], + } + }, + { label => 'active-tcp', set => { + key_values => [ { name => 'panSessionActiveTcp' } ], + output_template => 'Active TCP : %s', + perfdatas => [ + { label => 'active_tcp', value => 'panSessionActiveTcp_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'active-udp', set => { + key_values => [ { name => 'panSessionActiveUdp' } ], + output_template => 'Active UDP : %s', + perfdatas => [ + { label => 'active_udp', value => 'panSessionActiveUdp_absolute', template => '%s', min => 0 }, + ], + } + }, + { label => 'active-icmp', set => { + key_values => [ { name => 'panSessionActiveICMP' } ], + output_template => 'Active ICMP : %s', + perfdatas => [ + { label => 'active_icmp', value => 'panSessionActiveICMP_absolute', template => '%s', min => 0 }, + ], + } + }, + ]; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Sessions "; +} + +sub custom_active_perfdata { + my ($self, %options) = @_; + + my $label = 'active'; + my %total_options = (); + if ($self->{result_values}->{panSessionMax} != 0) { + $total_options{total} = $self->{result_values}->{panSessionMax}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label, + value => $self->{result_values}->{panSessionActive}, + warning => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options) : undef, + critical => defined($total_options{total}) ? $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options) : undef, + min => 0, max => $self->{result_values}->{panSessionMax}); +} + +sub custom_active_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value) = ('ok'); + if ($self->{result_values}->{panSessionMax} != 0) { + $threshold_value = $self->{result_values}->{active_prct}; + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => + [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]) if (defined($threshold_value)); + return $exit; +} + +sub custom_active_output { + my ($self, %options) = @_; + + my $msg = sprintf("Active : %s (%s)", + $self->{result_values}->{panSessionActive}, + $self->{result_values}->{panSessionMax} != 0 ? $self->{result_values}->{active_prct} . " %" : + '-'); + return $msg; +} sub custom_active_calc { my ($self, %options) = @_; - $self->{result_values}->{panSessionActive_absolute} = $options{new_datas}->{$self->{instance} . '_panSessionActive'}; - $self->{result_values}->{panSessionMax_absolute} = $options{new_datas}->{$self->{instance} . '_panSessionMax'}; + $self->{result_values}->{panSessionActive} = $options{new_datas}->{$self->{instance} . '_panSessionActive'}; + $self->{result_values}->{panSessionMax} = $options{new_datas}->{$self->{instance} . '_panSessionMax'}; $self->{result_values}->{active_prct} = 0; - if ($self->{result_values}->{panSessionMax_absolute} != 0) { - $self->{result_values}->{active_prct} = $self->{result_values}->{panSessionActive_absolute} * 100 / $self->{result_values}->{panSessionMax_absolute}; + if ($self->{result_values}->{panSessionMax} != 0) { + $self->{result_values}->{active_prct} = $self->{result_values}->{panSessionActive} * 100 / $self->{result_values}->{panSessionMax}; } return 0; } -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); - - foreach (keys %{$maps_counters}) { - my ($id, $name) = split /_/; - if (!defined($maps_counters->{$_}->{threshold}) || $maps_counters->{$_}->{threshold} != 0) { - $options{options}->add_options(arguments => { - 'warning-' . $name . ':s' => { name => 'warning-' . $name }, - 'critical-' . $name . ':s' => { name => 'critical-' . $name }, - }); - } - my $class = $maps_counters->{$_}->{class}; - $maps_counters->{$_}->{obj} = $class->new(output => $self->{output}, perfdata => $self->{perfdata}, - label => $name); - $maps_counters->{$_}->{obj}->set(%{$maps_counters->{$_}->{set}}); - } - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - foreach (keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->init(option_results => $self->{option_results}); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->manage_selection(); - - my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); - my @exits; - foreach (sort keys %{$maps_counters}) { - $maps_counters->{$_}->{obj}->set(instance => 'global'); - - my ($value_check) = $maps_counters->{$_}->{obj}->execute(values => $self->{global}); - - if ($value_check != 0) { - $long_msg .= $long_msg_append . $maps_counters->{$_}->{obj}->output_error(); - $long_msg_append = ', '; - next; - } - my $exit2 = $maps_counters->{$_}->{obj}->threshold_check(); - push @exits, $exit2; - - my $output = $maps_counters->{$_}->{obj}->output(); - $long_msg .= $long_msg_append . $output; - $long_msg_append = ', '; - - if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { - $short_msg .= $short_msg_append . $output; - $short_msg_append = ', '; - } - - $maps_counters->{$_}->{obj}->perfdata(); - } - - my $exit = $self->{output}->get_most_critical(status => [ @exits ]); - if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { - $self->{output}->output_add(severity => $exit, - short_msg => "Sessions $short_msg" - ); - } else { - $self->{output}->output_add(short_msg => "Sessions $long_msg"); - } - - $self->{output}->display(); - $self->{output}->exit(); -} - my $mapping = { panSessionMax => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.2' }, panSessionActive => { oid => '.1.3.6.1.4.1.25461.2.1.2.3.3' }, @@ -195,9 +148,10 @@ sub manage_selection { my ($self, %options) = @_; my $oid_panSession = '.1.3.6.1.4.1.25461.2.1.2.3'; - $self->{results} = $self->{snmp}->get_table(oid => $oid_panSession, + $self->{results} = $options{snmp}->get_table(oid => $oid_panSession, nothing_quit => 1); - $self->{global} = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => '0'); + $self->{global} = $options{snmp}->map_instance(mapping => $mapping, results => $self->{results}, instance => '0'); + $self->{global}->{panSessionMax} = 0 if (!defined($self->{global}->{panSessionMax})); } 1; diff --git a/network/radware/alteon/common/mode/cpu.pm b/network/radware/alteon/common/mode/cpu.pm deleted file mode 100644 index b749bcc7b..000000000 --- a/network/radware/alteon/common/mode/cpu.pm +++ /dev/null @@ -1,143 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::radware::alteon::common::mode::cpu; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "warning:s" => { name => 'warning', default => '' }, - "critical:s" => { name => 'critical', default => '' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - ($self->{warn1s}, $self->{warn4s}, $self->{warn64s}) = split /,/, $self->{option_results}->{warning}; - ($self->{crit1s}, $self->{crit4s}, $self->{crit64s}) = split /,/, $self->{option_results}->{critical}; - - if (($self->{perfdata}->threshold_validate(label => 'warn1s', value => $self->{warn1s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (1sec) threshold '" . $self->{warn1s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn4s', value => $self->{warn4s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (4sec) threshold '" . $self->{warn4s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warn64s', value => $self->{warn64s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning (64sec) threshold '" . $self->{warn64s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit1s', value => $self->{crit1s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (1sec) threshold '" . $self->{crit1s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit4s', value => $self->{crit4s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (4sec) threshold '" . $self->{crit4s} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'crit64s', value => $self->{crit64s})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical (64sec) threshold '" . $self->{crit64s} . "'."); - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - my $oid_mpCpuStatsUtil1Second = '.1.3.6.1.4.1.1872.2.5.1.2.2.1.0'; - my $oid_mpCpuStatsUtil4Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.2.0'; - my $oid_mpCpuStatsUtil64Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.3.0'; - my $result = $self->{snmp}->get_leef(oids => [$oid_mpCpuStatsUtil1Second, $oid_mpCpuStatsUtil4Seconds, - $oid_mpCpuStatsUtil64Seconds], nothing_quit => 1); - - my $cpu1sec = $result->{$oid_mpCpuStatsUtil1Second}; - my $cpu4sec = $result->{$oid_mpCpuStatsUtil4Seconds}; - my $cpu64sec = $result->{$oid_mpCpuStatsUtil64Seconds}; - - my $exit1 = $self->{perfdata}->threshold_check(value => $cpu1sec, - threshold => [ { label => 'crit1s', 'exit_litteral' => 'critical' }, { label => 'warn1s', exit_litteral => 'warning' } ]); - my $exit2 = $self->{perfdata}->threshold_check(value => $cpu4sec, - threshold => [ { label => 'crit4s', 'exit_litteral' => 'critical' }, { label => 'warn4s', exit_litteral => 'warning' } ]); - my $exit3 = $self->{perfdata}->threshold_check(value => $cpu64sec, - threshold => [ { label => 'crit64s', 'exit_litteral' => 'critical' }, { label => 'warn64s', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2, $exit3 ]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("MP CPU Usage: %.2f%% (1sec), %.2f%% (4sec), %.2f%% (64sec)", - $cpu1sec, $cpu4sec, $cpu64sec)); - - $self->{output}->perfdata_add(label => "cpu_1s", unit => '%', - value => $cpu1sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1s'), - min => 0, max => 100); - $self->{output}->perfdata_add(label => "cpu_4s", unit => '%', - value => $cpu4sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn4s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit4s'), - min => 0, max => 100); - $self->{output}->perfdata_add(label => "cpu_64s", unit => '%', - value => $cpu64sec, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn64s'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit64s'), - min => 0, max => 100); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check MP cpu usage (ALTEON-CHEETAH-SWITCH-MIB). - -=over 8 - -=item B<--warning> - -Threshold warning in percent (1s,4s,64s). - -=item B<--critical> - -Threshold critical in percent (1s,4s,64s). - -=back - -=cut - \ No newline at end of file diff --git a/network/radware/alteon/common/mode/hardware.pm b/network/radware/alteon/common/mode/hardware.pm deleted file mode 100644 index bbd9c74ef..000000000 --- a/network/radware/alteon/common/mode/hardware.pm +++ /dev/null @@ -1,179 +0,0 @@ -# -# Copyright 2017 Centreon (http://www.centreon.com/) -# -# Centreon is a full-fledged industry-strength solution that meets -# the needs in IT infrastructure and application monitoring for -# service performance. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -package network::radware::alteon::common::mode::hardware; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; - -my %states_temp_cpu = ( - 1 => ['normal', 'OK'], - 2 => ['warning', 'WARNING'], - 3 => ['critical', 'CRITICAL'], -); -my %states_temp = ( - 1 => ['ok', 'OK'], - 2 => ['exceed', 'WARNING'], -); -my %states_psu = ( - 1 => ['single power supply ok', 'WARNING'], - 2 => ['first powerSupply failed', 'CRITICAL'], - 3 => ['second power supply failed', 'CRITICAL'], - 4 => ['double power supply ok', 'OK'], - 5 => ['unknown power supply failed', 'UNKNOWN'], -); -my %states_fan = ( - 1 => ['ok', 'OK'], - 2 => ['fail', 'CRITICAL'], -); -my $oid_hwTemperatureStatus = '.1.3.6.1.4.1.1872.2.5.1.3.1.3.0'; -my $oid_hwFanStatus = '.1.3.6.1.4.1.1872.2.5.1.3.1.4.0'; -my $oid_hwTemperatureThresholdStatusCPU1Get = '.1.3.6.1.4.1.1872.2.5.1.3.1.28.3.0'; -my $oid_hwTemperatureThresholdStatusCPU2Get = '.1.3.6.1.4.1.1872.2.5.1.3.1.28.4.0'; -my $oid_hwPowerSupplyStatus = '.1.3.6.1.4.1.1872.2.5.1.3.1.29.2.0'; - -sub new { - my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); - bless $self, $class; - - $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub run { - my ($self, %options) = @_; - $self->{snmp} = $options{snmp}; - - $self->{components_fans} = 0; - $self->{components_psus} = 0; - $self->{components_temperatures} = 0; - - $self->{global_result} = $self->{snmp}->get_leef(oids => [$oid_hwTemperatureStatus, $oid_hwFanStatus, - $oid_hwTemperatureThresholdStatusCPU1Get, $oid_hwTemperatureThresholdStatusCPU2Get, - $oid_hwPowerSupplyStatus], - nothing_quit => 1); - - $self->check_fans(); - $self->check_psus(); - $self->check_temperatures(); - - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("All %d components [%d fans, %d power supplies, %d temperatures] are ok", - ($self->{components_fans} + $self->{components_psus} + $self->{components_temperatures}), - $self->{components_fans}, $self->{components_psus}, $self->{components_temperatures})); - - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_fans { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fans"); - return if (!defined($self->{global_result}->{$oid_hwFanStatus})); - - $self->{components_fans}++; - my $fan_state = $self->{global_result}->{$oid_hwFanStatus}; - - $self->{output}->output_add(long_msg => sprintf("Fan status is %s.", ${$states_fan{$fan_state}}[0])); - if (${$states_fan{$fan_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_fan{$fan_state}}[1], - short_msg => sprintf("Fan status is %s.", ${$states_fan{$fan_state}}[0])); - } -} - -sub check_psus { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - return if (!defined($self->{global_result}->{$oid_hwPowerSupplyStatus})); - - $self->{components_psus}++; - my $psu_state = $self->{global_result}->{$oid_hwPowerSupplyStatus}; - - $self->{output}->output_add(long_msg => sprintf("Power supplies status is %s.", ${$states_psu{$psu_state}}[0])); - if (${$states_psu{$psu_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_psu{$psu_state}}[1], - short_msg => sprintf("Power supplies status is %s.", ${$states_psu{$psu_state}}[0])); - } -} - -sub check_temperatures { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking temperatures global"); - return if (!defined($self->{global_result}->{$oid_hwTemperatureStatus})); - - $self->{components_temperatures}++; - my $temp_state = $self->{global_result}->{$oid_hwTemperatureStatus}; - - $self->{output}->output_add(long_msg => sprintf("Global temperature sensor status is %s.", ${$states_temp{$temp_state}}[0])); - if (${$states_temp{$temp_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_temp{$temp_state}}[1], - short_msg => sprintf("Global temperature sensor status is %s.", ${$states_temp{$temp_state}}[0])); - } - - $self->{output}->output_add(long_msg => "Checking temperatures cpus"); - return if (!defined($self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU1Get}) && - !defined($self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU2Get})); - - $self->{components_temperatures} += 2; - my $temp_cpu1_state = $self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU1Get}; - my $temp_cpu2_state = $self->{global_result}->{$oid_hwTemperatureThresholdStatusCPU2Get}; - - $self->{output}->output_add(long_msg => sprintf("Temperature cpu 1 status is %s.", ${$states_temp_cpu{$temp_cpu1_state}}[0])); - if (${$states_temp_cpu{$temp_cpu1_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_temp_cpu{$temp_cpu1_state}}[1], - short_msg => sprintf("Temperature cpu 1 status is %s.", ${$states_temp_cpu{$temp_cpu1_state}}[0])); - } - - $self->{output}->output_add(long_msg => sprintf("Temperature cpu 2 status is %s.", ${$states_temp_cpu{$temp_cpu2_state}}[0])); - if (${$states_temp_cpu{$temp_cpu2_state}}[1] ne 'OK') { - $self->{output}->output_add(severity => ${$states_temp_cpu{$temp_cpu2_state}}[1], - short_msg => sprintf("Temperature cpu 2 status is %s.", ${$states_temp_cpu{$temp_cpu2_state}}[0])); - } -} - -1; - -__END__ - -=head1 MODE - -Check Hardware (ALTEON-CHEETAH-SWITCH-MIB) (Fans, Power Supplies, Temperatures). - -=over 8 - -=back - -=cut - \ No newline at end of file diff --git a/network/radware/alteon/snmp/mode/cpu.pm b/network/radware/alteon/snmp/mode/cpu.pm new file mode 100644 index 000000000..17952b101 --- /dev/null +++ b/network/radware/alteon/snmp/mode/cpu.pm @@ -0,0 +1,127 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::radware::alteon::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' } + ]; + + $self->{maps_counters}->{global} = [ + { label => '1s', set => { + key_values => [ { name => '1s' } ], + output_template => '%.2f%% (1sec)', + perfdatas => [ + { label => 'cpu_1s', value => '1s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => '4s', set => { + key_values => [ { name => '4s' } ], + output_template => '%.2f%% (4sec)', + perfdatas => [ + { label => 'cpu_4s', value => '4s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => '64s', set => { + key_values => [ { name => '64s' } ], + output_template => '%.2f%% (64sec)', + perfdatas => [ + { label => 'cpu_64s', value => '64s_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "MP CPU Usage: "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $oid_mpCpuStatsUtil1Second = '.1.3.6.1.4.1.1872.2.5.1.2.2.1.0'; + my $oid_mpCpuStatsUtil4Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.2.0'; + my $oid_mpCpuStatsUtil64Seconds = '.1.3.6.1.4.1.1872.2.5.1.2.2.3.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_mpCpuStatsUtil1Second, $oid_mpCpuStatsUtil4Seconds, + $oid_mpCpuStatsUtil64Seconds], nothing_quit => 1); + + $self->{global} = { '1s' => $snmp_result->{$oid_mpCpuStatsUtil1Second}, '4s' => $snmp_result->{$oid_mpCpuStatsUtil4Seconds}, + '64s' => $snmp_result->{$oid_mpCpuStatsUtil64Seconds} }; +} + +1; + +__END__ + +=head1 MODE + +Check MP cpu usage (ALTEON-CHEETAH-SWITCH-MIB). + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^(64s)$' + +=item B<--warning-*> + +Threshold warning. +Can be: '1s', '4s', '64s'. + +=item B<--critical-*> + +Threshold critical. +Can be: '1s', '4s', '64s'. + +=back + +=cut + \ No newline at end of file diff --git a/network/radware/alteon/snmp/mode/hardware.pm b/network/radware/alteon/snmp/mode/hardware.pm new file mode 100644 index 000000000..dfa3bee60 --- /dev/null +++ b/network/radware/alteon/snmp/mode/hardware.pm @@ -0,0 +1,280 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::radware::alteon::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(cpu|temperature|psu|fan)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + cpu => [ + ['normal', 'OK'], + ['warning', 'WARNING'], + ['critical', 'CRITICAL'], + ], + psu => [ + ['singlePowerSupplyOk', 'OK'], + ['firstPowerSupplyFailed', 'CRITICAL'], + ['secondPowerSupplyFailed', 'CRITICAL'], + ['doublePowerSupplyOk', 'OK'], + ['unknownPowerSupplyFailed', 'UNKNOWN'], + ], + temperature => [ + ['ok', 'OK'], + ['exceed', 'WARNING'], + ], + fan => [ + ['ok', 'OK'], + ['fail', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'network::radware::alteon::snmp::mode::components'; + $self->{components_module} = ['cpu', 'temperature', 'psu', 'fan']; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_leef(oids => $self->{request}); +} + +1; + +=head1 MODE + +Check hardware (ALTEON-CHEETAH-SWITCH-MIB). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'cpu', 'temperature', 'psu', 'fan'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=cpu,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='psu,OK,unknownPowerSupplyFailed' + +=back + +=cut + +package network::radware::alteon::snmp::mode::components::cpu; + +use strict; +use warnings; + +my %map_cpu_status = (1 => 'normal', 2 => 'warning', 3 => 'critical'); + +my $mapping_cpu = { + hwTemperatureThresholdStatusCPU1Get => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.28.3', map => \%map_cpu_status }, + hwTemperatureThresholdStatusCPU2Get => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.28.4', map => \%map_cpu_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, $mapping_cpu->{hwTemperatureThresholdStatusCPU1Get}->{oid} . '.0', $mapping_cpu->{hwTemperatureThresholdStatusCPU2Get}->{oid} . '.0'; +} + +sub check_cpu { + my ($self, %options) = @_; + + return if (!defined($options{status})); + return if ($self->check_filter(section => 'cpu', instance => $options{instance})); + + $self->{components}->{cpu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("cpu '%s' status is '%s' [instance = %s]", + $options{instance}, $options{status}, $options{instance})); + my $exit = $self->get_severity(section => 'cpu', value => $options{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Cpu '%s' status is '%s'", $options{instance}, $options{status})); + } +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking cpu"); + $self->{components}->{cpu} = {name => 'cpu', total => 0, skip => 0}; + return if ($self->check_filter(section => 'cpu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_cpu, results => $self->{results}, instance => '0'); + + check_cpu($self, status => $result->{hwTemperatureThresholdStatusCPU1Get}, instance => 1); + check_cpu($self, status => $result->{hwTemperatureThresholdStatusCPU2Get}, instance => 2); +} + +1; + +package network::radware::alteon::snmp::mode::components::fan; + +use strict; +use warnings; + +my %map_fan_status = (1 => 'ok', 2 => 'fail'); + +my $mapping_fan = { + hwFanStatus => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.4', map => \%map_fan_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, $mapping_fan->{hwFanStatus}->{oid} . '.0'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fan')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_fan, results => $self->{results}, instance => '0'); + + return if (!defined($result->{hwFanStatus})); + $self->{components}->{fan}->{total}++; + $self->{output}->output_add(long_msg => sprintf("fan status is '%s' [instance = %s]", + $result->{hwFanStatus}, '0')); + my $exit = $self->get_severity(section => 'fan', value => $result->{hwFanStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Fan status is '%s'", $result->{hwFanStatus})); + } +} + +1; + +package network::radware::alteon::snmp::mode::components::temperature; + +use strict; +use warnings; + +my %map_temp_status = (1 => 'ok', 2 => 'exceed'); + +my $mapping_temp = { + hwTemperatureStatus => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.3', map => \%map_temp_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, $mapping_temp->{hwTemperatureStatus}->{oid} . '.0'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking temperature"); + $self->{components}->{temperature} = {name => 'temperature', total => 0, skip => 0}; + return if ($self->check_filter(section => 'temperature')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_temp, results => $self->{results}, instance => '0'); + + return if (!defined($result->{hwTemperatureStatus})); + $self->{components}->{temperature}->{total}++; + $self->{output}->output_add(long_msg => sprintf("temperature status is '%s' [instance = %s]", + $result->{hwTemperatureStatus}, '0')); + my $exit = $self->get_severity(section => 'temperature', value => $result->{hwTemperatureStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature status is '%s'", $result->{hwTemperatureStatus})); + } +} + +1; + +package network::radware::alteon::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_psu_status = (1 => 'singlePowerSupplyOk', + 2 => 'firstPowerSupplyFailed', 3 => 'secondPowerSupplyFailed', 4 => 'doublePowerSupplyOk', + 5 => 'unknownPowerSupplyFailed' +); + +my $mapping_psu = { + hwPowerSupplyStatus => { oid => '.1.3.6.1.4.1.1872.2.5.1.3.1.29.2', map => \%map_psu_status }, +}; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, $mapping_psu->{hwPowerSupplyStatus}->{oid} . '.0'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking psus"); + $self->{components}->{psu} = {name => 'psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + my $result = $self->{snmp}->map_instance(mapping => $mapping_psu, results => $self->{results}, instance => '0'); + + return if (!defined($result->{hwPowerSupplyStatus})); + $self->{components}->{psu}->{total}++; + $self->{output}->output_add(long_msg => sprintf("power supply status is '%s' [instance = %s]", + $result->{hwPowerSupplyStatus}, '0')); + my $exit = $self->get_severity(section => 'psu', value => $result->{hwPowerSupplyStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Power supply status is '%s'", $result->{hwPowerSupplyStatus})); + } +} + +1; + \ No newline at end of file diff --git a/network/radware/alteon/common/mode/memory.pm b/network/radware/alteon/snmp/mode/memory.pm similarity index 95% rename from network/radware/alteon/common/mode/memory.pm rename to network/radware/alteon/snmp/mode/memory.pm index e998585b2..5798cd1c4 100644 --- a/network/radware/alteon/common/mode/memory.pm +++ b/network/radware/alteon/snmp/mode/memory.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::radware::alteon::common::mode::memory; +package network::radware::alteon::snmp::mode::memory; use base qw(centreon::plugins::mode); @@ -69,7 +69,7 @@ sub run { my $prct_used = $memory_used * 100 / $total_size; my $prct_free = 100 - $prct_used; - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + 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 ($used_value, $used_unit) = $self->{perfdata}->change_bytes(value => $memory_used); my ($free_value, $free_unit) = $self->{perfdata}->change_bytes(value => $memory_free); diff --git a/network/radware/alteon/5224/plugin.pm b/network/radware/alteon/snmp/plugin.pm similarity index 89% rename from network/radware/alteon/5224/plugin.pm rename to network/radware/alteon/snmp/plugin.pm index 7fc2f838d..e2da10efe 100644 --- a/network/radware/alteon/5224/plugin.pm +++ b/network/radware/alteon/snmp/plugin.pm @@ -18,7 +18,7 @@ # limitations under the License. # -package network::radware::alteon::5224::plugin; +package network::radware::alteon::snmp::plugin; use strict; use warnings; @@ -31,9 +31,9 @@ sub new { $self->{version} = '1.0'; %{$self->{modes}} = ( - 'cpu' => 'network::radware::alteon::common::mode::cpu', - 'hardware' => 'network::radware::alteon::common::mode::hardware', - 'memory' => 'network::radware::alteon::common::mode::memory', + 'cpu' => 'network::radware::alteon::snmp::mode::cpu', + 'hardware' => 'network::radware::alteon::snmp::mode::hardware', + 'memory' => 'network::radware::alteon::snmp::mode::memory', ); return $self; @@ -45,6 +45,6 @@ __END__ =head1 PLUGIN DESCRIPTION -Check Alteon 5224 in SNMP. +Check Radware Alteon in SNMP. =cut diff --git a/network/watchguard/snmp/mode/cpu.pm b/network/watchguard/snmp/mode/cpu.pm new file mode 100644 index 000000000..3094fb576 --- /dev/null +++ b/network/watchguard/snmp/mode/cpu.pm @@ -0,0 +1,130 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::watchguard::snmp::mode::cpu; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_cpu_output' } + ]; + + $self->{maps_counters}->{global} = [ + { label => '1min', set => { + key_values => [ { name => '1min' } ], + output_template => '1 minute : %.2f %%', + perfdatas => [ + { label => 'cpu_1min', value => '1min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => '5min', set => { + key_values => [ { name => '5min' } ], + output_template => '5 minutes : %.2f %%', + perfdatas => [ + { label => 'cpu_5min', value => '5min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + { label => '15min', set => { + key_values => [ { name => '15min' } ], + output_template => '5 minutes : %.2f %%', + perfdatas => [ + { label => 'cpu_5min', value => '15min_absolute', template => '%.2f', + min => 0, max => 100, unit => '%' }, + ], + } + }, + ]; +} + +sub prefix_cpu_output { + my ($self, %options) = @_; + + return "CPU "; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $oid_wgSystemCpuUtil1 = '.1.3.6.1.4.1.3097.6.3.77.0'; + my $oid_wgSystemCpuUtil5 = '.1.3.6.1.4.1.3097.6.3.78.0'; + my $oid_wgSystemCpuUtil15 = '.1.3.6.1.4.1.3097.6.3.79.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_wgSystemCpuUtil1, $oid_wgSystemCpuUtil5, $oid_wgSystemCpuUtil15 + ], nothing_quit => 1); + + $self->{global} = { '1min' => $snmp_result->{$oid_wgSystemCpuUtil1}, '5min' => $snmp_result->{$oid_wgSystemCpuUtil5}, '15min' => $snmp_result->{$oid_wgSystemCpuUtil15} }; +} + +1; + +__END__ + +=head1 MODE + +Check CPU usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^(1min|5min)$' + +=item B<--warning-*> + +Threshold warning. +Can be: '1min', '5min', '15min'. + +=item B<--critical-*> + +Threshold critical. +Can be: '1min', '5min', '15min'. + +=back + +=cut diff --git a/network/watchguard/snmp/mode/policyusage.pm b/network/watchguard/snmp/mode/policyusage.pm new file mode 100644 index 000000000..8876f555a --- /dev/null +++ b/network/watchguard/snmp/mode/policyusage.pm @@ -0,0 +1,180 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::watchguard::snmp::mode::policyusage; + +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 => 'policy', type => 1, cb_prefix_output => 'prefix_policy_output', message_multiple => 'All policies are ok' } + ]; + + $self->{maps_counters}->{policy} = [ + { label => 'current-connections', set => { + key_values => [ { name => 'wgPolicyCurrActiveConns' }, { name => 'display' } ], + output_template => 'Current connections : %s', + perfdatas => [ + { label => 'current_connections', value => 'wgPolicyCurrActiveConns_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-connections', set => { + key_values => [ { name => 'wgPolicyActiveStreams', diff => 1 }, { name => 'display' } ], + output_template => 'Total connections : %s', + perfdatas => [ + { label => 'total_connections', value => 'wgPolicyActiveStreams_absolute', template => '%s', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'l3-traffic', set => { + key_values => [ { name => 'wgPolicyL3PackageBytes', diff => 1 }, { name => 'display' } ], + output_template => 'L3 Traffic : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'traffic_l3', value => 'wgPolicyL3PackageBytes_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'l2-traffic', set => { + key_values => [ { name => 'wgPolicyL2PackageBytes', diff => 1 }, { name => 'display' } ], + output_template => 'L2 Traffic : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'traffic_l2', value => 'wgPolicyL2PackageBytes_per_second', template => '%.2f', + min => 0, unit => 'b/s', label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +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; +} + +sub prefix_policy_output { + my ($self, %options) = @_; + + return "Policy '" . $options{instance_value}->{display} . "' "; +} + +my $mapping = { + wgPolicyName => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.2' }, + wgPolicyL3PackageBytes => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.3' }, + wgPolicyActiveStreams => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.12' }, + wgPolicyCurrActiveConns => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.18' }, + wgPolicyL2PackageBytes => { oid => '.1.3.6.1.4.1.3097.4.2.2.1.19' }, +}; + +my $oid_wgPolicyEntry = '.1.3.6.1.4.1.3097.4.2.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + $self->{policy} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_wgPolicyEntry, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{wgPolicyName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{wgPolicyName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{wgPolicyName} . "': no matching filter.", debug => 1); + next; + } + + $self->{policy}->{$instance} = { display => $result->{wgPolicyName}, + %$result + }; + } + + if (scalar(keys %{$self->{policy}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No policy found."); + $self->{output}->option_exit(); + } + + $self->{cache_name} = "watchguard_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{wgPolicyName}) ? md5_hex($self->{option_results}->{wgPolicyName}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check policy usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^total-connections$' + +=item B<--filter-name> + +Filter policy name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-connections', 'current-connections' +'l3-traffic' (b/s), 'l2-traffic' (b/s). + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-connections', 'current-connections' +'l3-traffic' (b/s), 'l2-traffic' (b/s). + +=back + +=cut diff --git a/network/watchguard/snmp/mode/system.pm b/network/watchguard/snmp/mode/system.pm new file mode 100644 index 000000000..6d02c1514 --- /dev/null +++ b/network/watchguard/snmp/mode/system.pm @@ -0,0 +1,130 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::watchguard::snmp::mode::system; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, message_separator => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'connections', set => { + key_values => [ { name => 'connections' } ], + output_template => 'Current connections : %s', + perfdatas => [ + { label => 'current_connections', value => 'connections_absolute', template => '%s', + min => 0 }, + ], + } + }, + { label => 'in-traffic', set => { + key_values => [ { name => 'in_traffic', diff => 1 } ], + output_template => 'Traffic In : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'traffic_in', value => 'in_traffic_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + { label => 'out-traffic', set => { + key_values => [ { name => 'out_traffic', diff => 1 } ], + output_template => 'Traffic Out : %s %s/s', + per_second => 1, output_change_bytes => 2, + perfdatas => [ + { label => 'traffic_out', value => 'out_traffic_per_second', template => '%s', + min => 0, unit => 'b/s' }, + ], + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, statefile => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + my $oid_wgSystemTotalSendBytes = '.1.3.6.1.4.1.3097.6.3.8.0'; + my $oid_wgSystemTotalRecvBytes = '.1.3.6.1.4.1.3097.6.3.9.0'; + my $oid_wgSystemCurrActiveConns = '.1.3.6.1.4.1.3097.6.3.80.0'; + my $snmp_result = $options{snmp}->get_leef(oids => [ + $oid_wgSystemTotalSendBytes, $oid_wgSystemTotalRecvBytes, $oid_wgSystemCurrActiveConns + ], nothing_quit => 1); + + $self->{global} = { out_traffic => $snmp_result->{$oid_wgSystemTotalSendBytes}, + in_traffic => $snmp_result->{$oid_wgSystemTotalRecvBytes}, connections => $snmp_result->{$oid_wgSystemCurrActiveConns} }; + $self->{cache_name} = "watchguard_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check system statistics. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^(connections)$' + +=item B<--warning-*> + +Threshold warning. +Can be: 'in-traffic', 'out-traffic', 'connections'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'in-traffic', 'out-traffic', 'connections'. + +=back + +=cut diff --git a/network/watchguard/snmp/plugin.pm b/network/watchguard/snmp/plugin.pm new file mode 100644 index 000000000..7e7de9cd7 --- /dev/null +++ b/network/watchguard/snmp/plugin.pm @@ -0,0 +1,55 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package network::watchguard::snmp::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'cpu' => 'network::watchguard::snmp::mode::cpu', + 'hardware' => 'snmp_standard::mode::hardwaredevice', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-storages' => 'snmp_standard::mode::liststorages', + 'policy-usage' => 'network::watchguard::snmp::mode::policyusage', + 'storage' => 'snmp_standard::mode::storage', + 'system' => 'network::watchguard::snmp::mode::system', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Watchguard equipments in SNMP. + +=cut diff --git a/os/linux/local/mode/inodes.pm b/os/linux/local/mode/inodes.pm index 042929bc4..21a905365 100644 --- a/os/linux/local/mode/inodes.pm +++ b/os/linux/local/mode/inodes.pm @@ -20,12 +20,38 @@ package os::linux::local::mode::inodes; -use base qw(centreon::plugins::mode); +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 => 'inodes', type => 1, cb_prefix_output => 'prefix_inodes_output', message_multiple => 'All inode partitions are ok' } + ]; + + $self->{maps_counters}->{inodes} = [ + { label => 'usage', set => { + key_values => [ { name => 'used' }, { name => 'display' } ], + output_template => 'Used: %s %%', + perfdatas => [ + { label => 'used', value => 'used_absolute', template => '%d', + unit => '%', min => 0, max => 100, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_inodes_output { + my ($self, %options) = @_; + + return "Inodes partition '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -46,8 +72,6 @@ sub new { "command-options:s" => { name => 'command_options', default => '-P -i -T 2>&1' }, "filter-type:s" => { name => 'filter_type', }, "filter-fs:s" => { name => 'filter_fs', }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, "name:s" => { name => 'name' }, "regexp" => { name => 'use_regexp' }, "regexp-isensitive" => { name => 'use_regexpi' }, @@ -56,33 +80,22 @@ sub new { 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 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}); + my ($stdout, $exit_code) = 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}, + no_quit => 1 + ); + $self->{inodes} = {}; my @lines = split /\n/, $stdout; - # Header not needed - shift @lines; foreach my $line (@lines) { - next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); + next if ($line !~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/); my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7); next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && @@ -98,56 +111,18 @@ sub manage_selection { && $mount ne $self->{option_results}->{name}); $percent =~ s/%//g; - $self->{result}->{$mount} = {fs => $fs, type => $type, total => $size, percent => $percent}; + $self->{inodes}->{$mount} = { display => $mount, fs => $fs, type => $type, total => $size, used => $percent }; } - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No storage found for mount point '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No storage found."); + if (scalar(keys %{$self->{inodes}}) <= 0) { + if ($exit_code != 0) { + $self->{output}->output_add(long_msg => "command output:" . $stdout); } + $self->{output}->add_option_msg(short_msg => "No storage found (filters or command issue)"); $self->{output}->option_exit(); } } -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All inode partitions are ok.'); - } - - foreach my $name (sort(keys %{$self->{result}})) { - my $prct_used = $self->{result}->{$name}->{percent}; - my $prct_free = 100 - $prct_used; - - my $exit = $self->{perfdata}->threshold_check(value => $prct_used, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(long_msg => sprintf("Inodes partition '%s' Used: %s %% Free: %s %%", - $name, $prct_used, $prct_free)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Inodes partition '%s' Used: %s %% Free: %s %%", - $name, $prct_used, $prct_free)); - } - - my $label = 'used'; - my $extra_label = ''; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - $self->{output}->perfdata_add(label => $label . $extra_label, unit => '%', - value => $prct_used, - 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; __END__ @@ -199,11 +174,11 @@ Command path (Default: none). Command options (Default: '-P -i -T 2>&1'). -=item B<--warning> +=item B<--warning-usage> Threshold warning in percent. -=item B<--critical> +=item B<--critical-usage> Threshold critical in percent. diff --git a/os/linux/local/mode/listinterfaces.pm b/os/linux/local/mode/listinterfaces.pm index 9db239574..c5078176c 100644 --- a/os/linux/local/mode/listinterfaces.pm +++ b/os/linux/local/mode/listinterfaces.pm @@ -69,6 +69,7 @@ sub manage_selection { command_options => $self->{option_results}->{command_options}); while ($stdout =~ /^(\S+)(.*?)(\n\n|\n$)/msg) { my ($interface_name, $values) = ($1, $2); + $interface_name =~ s/:$//; my $states = ''; $states .= 'R' if ($values =~ /RUNNING/ms); $states .= 'U' if ($values =~ /UP/ms); diff --git a/os/linux/local/mode/liststorages.pm b/os/linux/local/mode/liststorages.pm index 8e596056a..c3f5540f7 100644 --- a/os/linux/local/mode/liststorages.pm +++ b/os/linux/local/mode/liststorages.pm @@ -60,17 +60,18 @@ sub check_options { 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}); + my ($stdout, $exit_code) = 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}, + no_quit => 1 + ); my @lines = split /\n/, $stdout; - # Header not needed - shift @lines; foreach my $line (@lines) { - next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); + next if ($line !~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/); my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7); if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && diff --git a/os/linux/local/mode/storage.pm b/os/linux/local/mode/storage.pm index e7d2b2b5c..fefff5d98 100644 --- a/os/linux/local/mode/storage.pm +++ b/os/linux/local/mode/storage.pm @@ -20,12 +20,107 @@ package os::linux::local::mode::storage; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::counter); use strict; use warnings; use centreon::plugins::misc; +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + if ($options{new_datas}->{$self->{instance} . '_total'} == 0) { + $self->{error_msg} = "total size is 0"; + return -2; + } + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'disks', type => 1, cb_prefix_output => 'prefix_disks_output', message_multiple => 'All storages are ok' } + ]; + + $self->{maps_counters}->{disks} = [ + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub prefix_disks_output { + my ($self, %options) = @_; + + return "Storage '" . $options{instance_value}->{display} . "' "; +} + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); @@ -46,8 +141,6 @@ sub new { "command-options:s" => { name => 'command_options', default => '-P -k -T 2>&1' }, "filter-type:s" => { name => 'filter_type', }, "filter-fs:s" => { name => 'filter_fs', }, - "warning:s" => { name => 'warning' }, - "critical:s" => { name => 'critical' }, "units:s" => { name => 'units', default => '%' }, "free" => { name => 'free' }, "name:s" => { name => 'name' }, @@ -61,31 +154,27 @@ sub new { 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(); - } + $self->SUPER::check_options(%options); + + $instance_mode = $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}); + my ($stdout, $exit_code) = 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}, + no_quit => 1 + ); + $self->{disks} = {}; my @lines = split /\n/, $stdout; - # Header not needed - shift @lines; foreach my $line (@lines) { - next if ($line !~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*)/); + next if ($line !~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(.*)/); my ($fs, $type, $size, $used, $available, $percent, $mount) = ($1, $2, $3, $4, $5, $6, $7); next if (defined($self->{option_results}->{filter_fs}) && $self->{option_results}->{filter_fs} ne '' && @@ -100,95 +189,20 @@ sub manage_selection { next if (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}) && !defined($self->{option_results}->{use_regexpi}) && $mount ne $self->{option_results}->{name}); - $self->{result}->{$mount} = {fs => $fs, type => $type, total => $size, used => $used, free => $available}; - } - - if (scalar(keys %{$self->{result}}) <= 0) { - if (defined($self->{option_results}->{name})) { - $self->{output}->add_option_msg(short_msg => "No storage found for mount point '" . $self->{option_results}->{name} . "'."); - } else { - $self->{output}->add_option_msg(short_msg => "No storage found."); - } - $self->{output}->option_exit(); - } -} - -sub run { - my ($self, %options) = @_; - - $self->manage_selection(); - if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})) { - $self->{output}->output_add(severity => 'OK', - short_msg => 'All storages are ok.'); - } - - my $num_disk_check = 0; - foreach my $name (sort(keys %{$self->{result}})) { - my $total_size = $self->{result}->{$name}->{total} * 1024; + $size *= 1024; if (defined($self->{option_results}->{space_reservation})) { - $total_size = $total_size - ($self->{option_results}->{space_reservation} * $total_size / 100); + $size = int($size - ($self->{option_results}->{space_reservation} * $size / 100)); } - next if ($total_size == 0); - - $num_disk_check++; - my $total_used = $self->{result}->{$name}->{used} * 1024; - my $total_free = $self->{result}->{$name}->{free} * 1024; - my $prct_used = $total_used * 100 / $total_size; - my $prct_free = 100 - $prct_used; - - my ($exit, $threshold_value); - - $threshold_value = $total_used; - $threshold_value = $total_free if (defined($self->{option_results}->{free})); - if ($self->{option_results}->{units} eq '%') { - $threshold_value = $prct_used; - $threshold_value = $prct_free if (defined($self->{option_results}->{free})); - } - $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $total_size); - my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $total_used); - my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => ($total_size - $total_used)); - - $self->{output}->output_add(long_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1) || (defined($self->{option_results}->{name}) && !defined($self->{option_results}->{use_regexp}))) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Storage '%s' Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", $name, - $total_size_value . " " . $total_size_unit, - $total_used_value . " " . $total_used_unit, $prct_used, - $total_free_value . " " . $total_free_unit, $prct_free)); - } - - my $label = 'used'; - my $value_perf = $total_used; - if (defined($self->{option_results}->{free})) { - $label = 'free'; - $value_perf = $total_free; - } - my $extra_label = ''; - $extra_label = '_' . $name if (!defined($self->{option_results}->{name}) || defined($self->{option_results}->{use_regexp})); - my %total_options = (); - if ($self->{option_results}->{units} eq '%') { - $total_options{total} = $total_size; - $total_options{cast_int} = 1; - } - $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', - value => $value_perf, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning', %total_options), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical', %total_options), - min => 0, max => $total_size); - } - - if ($num_disk_check == 0) { - $self->{output}->add_option_msg(short_msg => "No storage checked."); - $self->{output}->option_exit(); + $self->{disks}->{$mount} = { display => $mount, fs => $fs, type => $type, total => $size, used => $used * 1024 }; } - $self->{output}->display(); - $self->{output}->exit(); + if (scalar(keys %{$self->{disks}}) <= 0) { + if ($exit_code != 0) { + $self->{output}->output_add(long_msg => "command output:" . $stdout); + } + $self->{output}->add_option_msg(short_msg => "No storage found (filters or command issue)"); + $self->{output}->option_exit(); + } } 1; @@ -242,11 +256,11 @@ Command path (Default: none). Command options (Default: '-P -k -T 2>&1'). -=item B<--warning> +=item B<--warning-usage> Threshold warning. -=item B<--critical> +=item B<--critical-usage> Threshold critical. diff --git a/os/windows/local/mode/ntp.pm b/os/windows/local/mode/ntp.pm index ee64d1783..efb2fd6e6 100644 --- a/os/windows/local/mode/ntp.pm +++ b/os/windows/local/mode/ntp.pm @@ -101,6 +101,8 @@ sub run { my %ntp; # Need to set following patch: https://rt.cpan.org/Public/Bug/Display.html?id=59607 eval { + local $SIG{__WARN__} = sub { die $_[0] }; + %ntp = Net::NTP::get_ntp_response($ntp_hostname, $self->{option_results}->{ntp_port}); }; if ($@) { diff --git a/snmp_standard/mode/cpu.pm b/snmp_standard/mode/cpu.pm index db3b47ab9..99181f6d3 100644 --- a/snmp_standard/mode/cpu.pm +++ b/snmp_standard/mode/cpu.pm @@ -80,7 +80,7 @@ sub run { my $exit_code = $self->{perfdata}->threshold_check(value => $avg_cpu, threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("CPU(s) average usage is: %.2f%%", $avg_cpu)); + short_msg => sprintf("%s CPU(s) average usage is: %.2f%%", $i, $avg_cpu)); $self->{output}->perfdata_add(label => 'total_cpu_avg', unit => '%', value => sprintf("%.2f", $avg_cpu), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), diff --git a/snmp_standard/mode/hardwaredevice.pm b/snmp_standard/mode/hardwaredevice.pm index f78dec1dd..a7b35bf74 100644 --- a/snmp_standard/mode/hardwaredevice.pm +++ b/snmp_standard/mode/hardwaredevice.pm @@ -20,23 +20,35 @@ package snmp_standard::mode::hardwaredevice; -use base qw(centreon::plugins::mode); +use base qw(centreon::plugins::templates::hardware); use strict; use warnings; -use centreon::plugins::misc; -my %device_status = ( - 1 => ["Device '%s' status is unknown", 'UNKNOWN'], - 2 => ["Device '%s' status is running", 'OK'], - 3 => ["Device '%s' status is warning", 'WARNING'], - 4 => ["Device '%s' status is testing", 'OK'], - 5 => ["Device '%s' status is down", 'CRITICAL'], -); +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(device\..*)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + default => [ + ['unknown', 'UNKNOWN'], + ['running', 'OK'], + ['warning', 'WARNING'], + ['testing', 'OK'], + ['down', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'snmp_standard::mode::components'; + $self->{components_module} = ['device']; +} sub new { my ($class, %options) = @_; - my $self = $class->SUPER::new(package => __PACKAGE__, %options); + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1, no_load_components => 1); bless $self, $class; $self->{version} = '1.0'; @@ -47,50 +59,111 @@ sub new { return $self; } -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); -} - -sub run { +sub snmp_execute { my ($self, %options) = @_; + $self->{snmp} = $options{snmp}; - - $self->{output}->output_add(severity => 'OK', - short_msg => "All devices are ok."); - - my $oid_hrDeviceEntry = '.1.3.6.1.2.1.25.3.2.1'; - my $oid_hrDeviceDescr = '.1.3.6.1.2.1.25.3.2.1.3'; - my $oid_hrDeviceStatus = '.1.3.6.1.2.1.25.3.2.1.5'; - my $result = $self->{snmp}->get_table(oid => $oid_hrDeviceEntry, nothing_quit => 1); - - foreach my $key ($self->{snmp}->oid_lex_sort(keys %$result)) { - next if ($key !~ /^$oid_hrDeviceStatus\.(.*)/); - my $index = $1; - my $status = $result->{$oid_hrDeviceStatus . '.' . $index}; - my $descr = centreon::plugins::misc::trim($result->{$oid_hrDeviceDescr . '.' . $index}); - - $self->{output}->output_add(long_msg => sprintf(${$device_status{$status}}[0], $descr)); - if (!$self->{output}->is_status(value => ${$device_status{$status}}[1], compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => ${$device_status{$status}}[1], - short_msg => sprintf(${$device_status{$status}}[0], $descr)); - } - } - - $self->{output}->display(); - $self->{output}->exit(); + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); } 1; -__END__ - =head1 MODE Check hardware devices (HOST-RESOURCES-MIB). =over 8 +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'device'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=device,network.* + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='device.network,OK,down' + =back =cut + +package snmp_standard::mode::components::device; + +use strict; +use warnings; +use centreon::plugins::misc; + +my %map_status = (1 => 'unknown', 2 => 'running', 3 => 'warning', 4 => 'testing', 5 => 'down'); +my %map_type = ( + '.1.3.6.1.2.1.25.3.1.1' => 'other', + '.1.3.6.1.2.1.25.3.1.2' => 'unknown', + '.1.3.6.1.2.1.25.3.1.3' => 'processor', + '.1.3.6.1.2.1.25.3.1.4' => 'network', + '.1.3.6.1.2.1.25.3.1.5' => 'printer', + '.1.3.6.1.2.1.25.3.1.6' => 'diskStorage', + '.1.3.6.1.2.1.25.3.1.10', => 'video', + '.1.3.6.1.2.1.25.3.1.11' => 'audio', + '.1.3.6.1.2.1.25.3.1.12' => 'coprocessor', + '.1.3.6.1.2.1.25.3.1.13' => 'keyboard', + '.1.3.6.1.2.1.25.3.1.14' => 'modem', + '.1.3.6.1.2.1.25.3.1.15' => 'parallelPort', + '.1.3.6.1.2.1.25.3.1.16' => 'pointing', + '.1.3.6.1.2.1.25.3.1.17' => 'serialPort', + '.1.3.6.1.2.1.25.3.1.18' => 'tape', + '.1.3.6.1.2.1.25.3.1.19' => 'clock', + '.1.3.6.1.2.1.25.3.1.20' => 'volatileMemory', + '.1.3.6.1.2.1.25.3.1.21' => 'nonVolatileMemory', +); + +my $mapping = { + hrDeviceType => { oid => '.1.3.6.1.2.1.25.3.2.1.2', map => \%map_type }, + hrDeviceDescr => { oid => '.1.3.6.1.2.1.25.3.2.1.3' }, + hrDeviceStatus => { oid => '.1.3.6.1.2.1.25.3.2.1.5', map => \%map_status }, +}; +my $oid_hrDeviceEntry = '.1.3.6.1.2.1.25.3.2.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_hrDeviceEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking devices"); + $self->{components}->{device} = {name => 'devices', total => 0, skip => 0}; + return if ($self->check_filter(section => 'device')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_hrDeviceEntry}})) { + next if ($oid !~ /^$mapping->{hrDeviceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_hrDeviceEntry}, instance => $instance); + + next if ($self->check_filter(section => 'device', instance => $result->{hrDeviceType} . '.' . $instance)); + + $result->{hrDeviceDescr} = centreon::plugins::misc::trim($result->{hrDeviceDescr}); + $self->{components}->{device}->{total}++; + $self->{output}->output_add(long_msg => sprintf("device '%s' status is '%s' [instance = %s]", + $result->{hrDeviceDescr}, $result->{hrDeviceStatus}, $result->{hrDeviceType} . '.' . $instance)); + my $exit = $self->get_severity(label => 'default', section => 'device.' . $result->{hrDeviceType}, value => $result->{hrDeviceStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Device '%s' status is '%s'", $result->{hrDeviceDescr}, $result->{hrDeviceStatus})); + } + } +} + +1; diff --git a/snmp_standard/mode/interfaces.pm b/snmp_standard/mode/interfaces.pm index 63d1505c0..5793948d2 100644 --- a/snmp_standard/mode/interfaces.pm +++ b/snmp_standard/mode/interfaces.pm @@ -74,6 +74,7 @@ sub custom_status_calc { $self->{result_values}->{opstatus} = $options{new_datas}->{$self->{instance} . '_opstatus'}; $self->{result_values}->{admstatus} = $options{new_datas}->{$self->{instance} . '_admstatus'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; return 0; } @@ -112,7 +113,7 @@ sub custom_traffic_perfdata { } if (defined($instance_mode->{option_results}->{nagvis_perfdata})) { $self->{result_values}->{traffic_per_seconds} /= 8; - $self->{result_values}->{speed} /= 8; + $self->{result_values}->{speed} /= 8 if (defined($self->{result_values}->{speed})); } my ($warning, $critical); @@ -457,7 +458,7 @@ sub set_counters { $self->{maps_counters}->{int}->{'065_out-mcast'} = { filter => 'add_cast', set => { key_values => [ { name => 'oucast', diff => 1 }, { name => 'omcast', diff => 1 }, { name => 'obcast', diff => 1 }, { name => 'display' }, { name => 'mode_cast' } ], - closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'oucast', total_ref1 => 'omcast', total_ref2 => 'obcast' }, + closure_custom_calc => \&custom_cast_calc, closure_custom_calc_extra_options => { label_ref => 'omcast', total_ref1 => 'oucast', total_ref2 => 'obcast' }, output_template => 'Out Mcast : %.2f %%', output_error_template => 'Out Mcast : %s', output_use => 'omcast_prct', threshold_use => 'omcast_prct', perfdatas => [ @@ -472,7 +473,7 @@ sub set_counters { sub set_key_values_status { my ($self, %options) = @_; - return [ { name => 'opstatus' }, { name => 'admstatus' } ]; + return [ { name => 'opstatus' }, { name => 'admstatus' }, { name => 'display' } ]; } sub set_key_values_in_traffic { diff --git a/snmp_standard/mode/mtausage.pm b/snmp_standard/mode/mtausage.pm new file mode 100644 index 000000000..0c702398c --- /dev/null +++ b/snmp_standard/mode/mtausage.pm @@ -0,0 +1,300 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package snmp_standard::mode::mtausage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_global_output', message_multiple => 'All MTA are ok', skipped_code => { -10 => 1 } }, + { name => 'mtagrp', type => 1, cb_prefix_output => 'prefix_mtagrp_output', message_multiple => 'All MTA groups are ok', skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'total-received-messages', set => { + key_values => [ { name => 'mtaReceivedMessages', diff => 1 }, { name => 'display' } ], + output_template => 'Total Received Messages : %s', output_error_template => "Total Received Messages : %s", + perfdatas => [ + { label => 'total_received_messages', value => 'mtaReceivedMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-received-volume', set => { + key_values => [ { name => 'mtaReceivedVolume', diff => 1 }, { name => 'display' } ], + output_template => 'Total Received Volume : %s %s', output_error_template => "Total Received Volume : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'total_received_volume', value => 'mtaReceivedVolume_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-stored-messages', set => { + key_values => [ { name => 'mtaStoredMessages' }, { name => 'display' } ], + output_template => 'Total Stored Messages : %s', output_error_template => "Total Stored Messages : %s", + perfdatas => [ + { label => 'total_stored_messages', value => 'mtaStoredMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-stored-volume', set => { + key_values => [ { name => 'mtaStoredVolume' }, { name => 'display' } ], + output_template => 'Total Stored Volume : %s %s', output_error_template => "Total Stored Volume : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'total_stored_volume', value => 'mtaStoredVolume_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-transmitted-messages', set => { + key_values => [ { name => 'mtaTransmittedMessages', diff => 1 }, { name => 'display' } ], + output_template => 'Total Transmitted Messages : %s', output_error_template => "Total Transmitted Messages : %s", + perfdatas => [ + { label => 'total_transmitted_messages', value => 'mtaTransmittedMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'total-transmitted-volume', set => { + key_values => [ { name => 'mtaTransmittedVolume', diff => 1 }, { name => 'display' } ], + output_template => 'Total Transmitted Volume : %s %s', output_error_template => "Total Transmitted Volume : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'total_transmitted_volume', value => 'mtaTransmittedVolume_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; + + $self->{maps_counters}->{mtagrp} = [ + { label => 'received-messages', set => { + key_values => [ { name => 'mtaGroupReceivedMessages', diff => 1 }, { name => 'display' } ], + output_template => 'Received Messages : %s', output_error_template => "Received Messages : %s", + perfdatas => [ + { label => 'received_messages', value => 'mtaGroupReceivedMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'received-volume', set => { + key_values => [ { name => 'mtaGroupReceivedVolume', diff => 1 }, { name => 'display' } ], + output_template => 'Received Volume : %s %s', output_error_template => "Received Volume : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'received_volume', value => 'mtaGroupReceivedVolume_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'stored-messages', set => { + key_values => [ { name => 'mtaGroupStoredMessages' }, { name => 'display' } ], + output_template => 'Stored Messages : %s', output_error_template => "Stored Messages : %s", + perfdatas => [ + { label => 'stored_messages', value => 'mtaGroupStoredMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'stored-volume', set => { + key_values => [ { name => 'mtaGroupStoredVolume' }, { name => 'display' } ], + output_template => 'Stored Volume : %s %s', output_error_template => "Stored Volume : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'stored_volume', value => 'mtaGroupStoredVolume_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'transmitted-messages', set => { + key_values => [ { name => 'mtaGroupTransmittedMessages', diff => 1 }, { name => 'display' } ], + output_template => 'Transmitted Messages : %s', output_error_template => "Transmitted Messages : %s", + perfdatas => [ + { label => 'transmitted_messages', value => 'mtaGroupTransmittedMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'transmitted-volume', set => { + key_values => [ { name => 'mtaGroupTransmittedVolume', diff => 1 }, { name => 'display' } ], + output_template => 'Transmitted Volume : %s %s', output_error_template => "Transmitted Volume : %s", + output_change_bytes => 1, + perfdatas => [ + { label => 'transmitted_volume', value => 'mtaGroupTransmittedVolume_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + { label => 'rejected-messages', set => { + key_values => [ { name => 'mtaGroupRejectedMessages', diff => 1 }, { name => 'display' } ], + output_template => 'Rejected Messages : %s', output_error_template => "Rejected Messages : %s", + perfdatas => [ + { label => 'rejected_messages', value => 'mtaGroupRejectedMessages_absolute', template => '%d', + min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, + ], + } + }, + ]; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "MTA '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_mtagrp_output { + my ($self, %options) = @_; + + return "MTA group '" . $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 = { + mtaReceivedMessages => { oid => '.1.3.6.1.2.1.28.1.1.1' }, + mtaStoredMessages => { oid => '.1.3.6.1.2.1.28.1.1.2' }, + mtaTransmittedMessages => { oid => '.1.3.6.1.2.1.28.1.1.3' }, + mtaReceivedVolume => { oid => '.1.3.6.1.2.1.28.1.1.4' }, + mtaStoredVolume => { oid => '.1.3.6.1.2.1.28.1.1.5' }, + mtaTransmittedVolume => { oid => '.1.3.6.1.2.1.28.1.1.6' }, +}; +my $mapping2 = { + mtaGroupReceivedMessages => { oid => '.1.3.6.1.2.1.28.2.1.2' }, + mtaGroupRejectedMessages => { oid => '.1.3.6.1.2.1.28.2.1.3' }, + mtaGroupStoredMessages => { oid => '.1.3.6.1.2.1.28.2.1.4' }, + mtaGroupTransmittedMessages => { oid => '.1.3.6.1.2.1.28.2.1.5' }, + mtaGroupReceivedVolume => { oid => '.1.3.6.1.2.1.28.2.1.6' }, + mtaGroupStoredVolume => { oid => '.1.3.6.1.2.1.28.2.1.7' }, + mtaGroupTransmittedVolume => { oid => '.1.3.6.1.2.1.28.2.1.8' }, + mtaGroupName => { oid => '.1.3.6.1.2.1.28.2.1.25' }, +}; + +my $oid_mtaEntry = '.1.3.6.1.2.1.28.1.1'; +my $oid_mtaGroupEntry = '.1.3.6.1.2.1.28.2.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_multiple_table(oids => [ + { oid => $oid_mtaEntry }, + { oid => $oid_mtaGroupEntry }, + ], nothing_quit => 1); + + $self->{global} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_mtaEntry}}) { + next if ($oid !~ /^$mapping->{mtaReceivedMessages}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result->{$oid_mtaEntry}, instance => $instance); + + foreach (('mtaReceivedVolume', 'mtaStoredVolume', 'mtaTransmittedVolume')) { + $result->{$_} *= 1024 if (defined($result->{$_})); + } + + $self->{global}->{$instance} = { display => $instance, + %$result + }; + } + + $self->{mtagrp} = {}; + foreach my $oid (keys %{$snmp_result->{$oid_mtaGroupEntry}}) { + next if ($oid !~ /^$mapping2->{mtaGroupName}->{oid}\.(.*?)\.(.*?)$/); + my ($applIndex, $mtaGroupIndex) = ($1, $2); + my $result = $options{snmp}->map_instance(mapping => $mapping2, results => $snmp_result->{$oid_mtaGroupEntry}, instance => $applIndex . '.' . $mtaGroupIndex); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{mtaGroupName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{mtaGroupName} . "': no matching filter.", debug => 1); + next; + } + + foreach (('mtaGroupReceivedVolume', 'mtaGroupStoredVolume', 'mtaGroupTransmittedVolume')) { + $result->{$_} *= 1024 if (defined($result->{$_})); + } + + $self->{mtagrp}->{$applIndex . '.' . $result->{mtaGroupName}} = { display => $applIndex . '.' . $result->{mtaGroupName}, + %$result + }; + } + + $self->{cache_name} = $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')) . '_' . + (defined($self->{option_results}->{filter_name}) ? md5_hex($self->{option_results}->{filter_name}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check MTA usage. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='received' + +=item B<--filter-name> + +Filter MTA group name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'total-received-messages', 'total-received-volume', 'total-stored-messages', 'total-stored-volume', +'total-transmitted-messages', 'total-transmitted-volume', +'received-messages', 'received-volume', 'stored-messages', 'stored-volume', 'transmitted-messages', +'transmitted-volume', 'rejected-messages'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'total-received-messages', 'total-received-volume', 'total-stored-messages', 'total-stored-volume', +'total-transmitted-messages', 'total-transmitted-volume', +'received-messages', 'received-volume', 'stored-messages', 'stored-volume', 'transmitted-messages', +'transmitted-volume', 'rejected-messages'. + +=back + +=cut diff --git a/snmp_standard/mode/vrrp.pm b/snmp_standard/mode/vrrp.pm new file mode 100644 index 000000000..f992608f1 --- /dev/null +++ b/snmp_standard/mode/vrrp.pm @@ -0,0 +1,192 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package snmp_standard::mode::vrrp; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Digest::MD5 qw(md5_hex); + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = sprintf("state : %s [admin state : '%s']", + $self->{result_values}->{operState}, $self->{result_values}->{adminState}); + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{adminState} = $options{new_datas}->{$self->{instance} . '_admin_state'}; + $self->{result_values}->{operStateLast} = $options{old_datas}->{$self->{instance} . '_oper_state'}; + $self->{result_values}->{operState} = $options{new_datas}->{$self->{instance} . '_oper_state'}; + $self->{result_values}->{masterIpAddr} = $options{new_datas}->{$self->{instance} . '_master_ip_addr'}; + if (!defined($options{old_datas}->{$self->{instance} . '_oper_state'})) { + $self->{error_msg} = "buffer creation"; + return -2; + } + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'vrrp', type => 1, cb_prefix_output => 'prefix_vrrp_output', message_multiple => 'All VRRP are ok' }, + ]; + + $self->{maps_counters}->{vrrp} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'master_ip_addr' }, { name => 'admin_state' }, { name => 'oper_state' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + ]; +} + +sub prefix_vrrp_output { + my ($self, %options) = @_; + + return "VRRP '" . $options{instance_value}->{master_ip_addr} . "' "; +} + +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 => + { + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{adminState} eq "up" and %{operState} ne %{operStateLast}' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +my %map_admin_state = (1 => 'up', 2 => 'down'); +my %map_oper_state = (1 => 'initialize', 2 => 'backup', 3 => 'master'); +my $mapping = { + vrrpOperState => { oid => '.1.3.6.1.2.1.68.1.3.1.3', map => \%map_oper_state }, + vrrpOperAdminState => { oid => '.1.3.6.1.2.1.68.1.3.1.4', map => \%map_admin_state }, + vrrpOperMasterIpAddr => { oid => '.1.3.6.1.2.1.68.1.3.1.7' }, +}; + +my $oid_vrrpOperEntry = '.1.3.6.1.2.1.68.1.3.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{vrrp} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_vrrpOperEntry, end => $mapping->{vrrpOperMasterIpAddr}->{oid}, + nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{vrrpOperState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{vrrp}->{$instance} = { + master_ip_addr => $result->{vrrpOperMasterIpAddr}, + admin_state => $result->{vrrpOperAdminState}, + oper_state => $result->{vrrpOperState}, + }; + } + + $self->{cache_name} = "vrrp_" . $self->{mode} . '_' . $options{snmp}->get_hostname() . '_' . $options{snmp}->get_port() . '_' . + (defined($self->{option_results}->{filter_counters}) ? md5_hex($self->{option_results}->{filter_counters}) : md5_hex('all')); +} + +1; + +__END__ + +=head1 MODE + +Check VRRP status (VRRP-MIB). + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +Can used special variables like: %{adminState}, %{operStateLast}, %{operState}, %{masterIpAddr} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{adminState} eq "up" and %{operState} ne %{operStateLast}'). +Can used special variables like: %{adminState}, %{operStateLast}, %{operState}, %{masterIpAddr} + +=back + +=cut + \ No newline at end of file diff --git a/storage/dell/fluidfs/snmp/mode/components/ad.pm b/storage/dell/fluidfs/snmp/mode/components/ad.pm new file mode 100644 index 000000000..5f159a89d --- /dev/null +++ b/storage/dell/fluidfs/snmp/mode/components/ad.pm @@ -0,0 +1,72 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::snmp::mode::components::ad; + +use strict; +use warnings; + +my $mapping = { + fluidFSActiveDirectoryStatusConfigured => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.1.1' }, + fluidFSActiveDirectoryStatusStatus => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.1.2' }, +}; +my $oid_fluidFSActiveDirectoryStatus = '.1.3.6.1.4.1.674.11000.2000.200.1.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_fluidFSActiveDirectoryStatus }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking active directory"); + $self->{components}->{ad} = {name => 'ad', total => 0, skip => 0}; + return if ($self->check_filter(section => 'ad')); + + my $result = {}; + my $instance = '0'; + if (defined($self->{results}->{$oid_fluidFSActiveDirectoryStatus}->{$mapping->{fluidFSActiveDirectoryStatusConfigured}->{oid}})) { + $result->{fluidFSActiveDirectoryStatusConfigured} = $self->{results}->{$oid_fluidFSActiveDirectoryStatus}->{$mapping->{fluidFSActiveDirectoryStatusConfigured}->{oid}}; + $result->{fluidFSActiveDirectoryStatusStatus} = $self->{results}->{$oid_fluidFSActiveDirectoryStatus}->{$mapping->{fluidFSActiveDirectoryStatusStatus}->{oid}}; + } else { + $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fluidFSActiveDirectoryStatus}, instance => $instance); + } + if (!defined($result->{fluidFSActiveDirectoryStatusConfigured}) || $result->{fluidFSActiveDirectoryStatusConfigured} !~ /Yes/i) { + $self->{output}->output_add(long_msg => "skipping: active directory not configured."); + return ; + } + + return if ($self->check_filter(section => 'ad', instance => $instance)); + $self->{components}->{ad}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("active directory status is '%s' [instance: %s].", + $result->{fluidFSActiveDirectoryStatusStatus}, $instance + )); + my $exit = $self->get_severity(section => 'ad', value => $result->{fluidFSActiveDirectoryStatusStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Active directory status is '%s'", + $result->{fluidFSActiveDirectoryStatusStatus})); + } +} + +1; \ No newline at end of file diff --git a/storage/dell/fluidfs/snmp/mode/components/extservers.pm b/storage/dell/fluidfs/snmp/mode/components/extservers.pm new file mode 100644 index 000000000..8aad88709 --- /dev/null +++ b/storage/dell/fluidfs/snmp/mode/components/extservers.pm @@ -0,0 +1,70 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::snmp::mode::components::extservers; + +use strict; +use warnings; + +my $mapping = { + fluidFSExternalServerStateHost => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.12.1.2' }, + fluidFSExternalServerStateType => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.12.1.3' }, + fluidFSExternalServerStateState => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.12.1.4' }, +}; +my $oid_fluidFSExternalServerStateEntry = '.1.3.6.1.4.1.674.11000.2000.200.1.12.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_fluidFSExternalServerStateEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking external servers"); + $self->{components}->{extservers} = {name => 'extservers', total => 0, skip => 0}; + return if ($self->check_filter(section => 'extservers')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fluidFSExternalServerStateEntry}})) { + next if ($oid !~ /^$mapping->{fluidFSExternalServerStateState}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fluidFSExternalServerStateEntry}, instance => $instance); + + next if ($self->check_filter(section => 'extservers', instance => $instance)); + $self->{components}->{extservers}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("external server '%s/%s' status is '%s' [instance = %s]", + $result->{fluidFSExternalServerStateHost}, $result->{fluidFSExternalServerStateType}, + $result->{fluidFSExternalServerStateState}, $instance + )); + + my $exit = $self->get_severity(section => 'extservers', value => $result->{fluidFSExternalServerStateState}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("External server '%s/%s' status is '%s'", + $result->{fluidFSExternalServerStateHost}, $result->{fluidFSExternalServerStateType}, + $result->{fluidFSExternalServerStateState} + )); + } + } +} + +1; \ No newline at end of file diff --git a/storage/dell/fluidfs/snmp/mode/components/overall.pm b/storage/dell/fluidfs/snmp/mode/components/overall.pm new file mode 100644 index 000000000..8ee1c6481 --- /dev/null +++ b/storage/dell/fluidfs/snmp/mode/components/overall.pm @@ -0,0 +1,70 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::snmp::mode::components::overall; + +use strict; +use warnings; + +my $mapping = { + fluidFSNASApplianceApplianceServiceTag => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.16.1.3' }, + fluidFSNASApplianceStatus => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.16.1.5' }, + fluidFSNASApplianceModel => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.16.1.6' }, +}; +my $oid_fluidFSNASApplianceEntry = '.1.3.6.1.4.1.674.11000.2000.200.1.16.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_fluidFSNASApplianceEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking nas overall"); + $self->{components}->{overall} = {name => 'overall', total => 0, skip => 0}; + return if ($self->check_filter(section => 'overall')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fluidFSNASApplianceEntry}})) { + next if ($oid !~ /^$mapping->{fluidFSNASApplianceStatus}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fluidFSNASApplianceEntry}, instance => $instance); + + next if ($self->check_filter(section => 'overall', instance => $instance)); + $self->{components}->{overall}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("nas '%s/%s' overall status is '%s' [instance = %s]", + $result->{fluidFSNASApplianceApplianceServiceTag}, $result->{fluidFSNASApplianceModel}, + $result->{fluidFSNASApplianceStatus}, $instance + )); + + my $exit = $self->get_severity(label => 'default', section => 'overall', value => $result->{fluidFSNASApplianceStatus}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("nas '%s/%s' overall status is '%s'", + $result->{fluidFSNASApplianceApplianceServiceTag}, $result->{fluidFSNASApplianceModel}, + $result->{fluidFSNASApplianceStatus} + )); + } + } +} + +1; \ No newline at end of file diff --git a/storage/dell/fluidfs/snmp/mode/components/substorage.pm b/storage/dell/fluidfs/snmp/mode/components/substorage.pm new file mode 100644 index 000000000..99459afd9 --- /dev/null +++ b/storage/dell/fluidfs/snmp/mode/components/substorage.pm @@ -0,0 +1,69 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::snmp::mode::components::substorage; + +use strict; +use warnings; + +my $mapping = { + fluidFSStorageSubsystemType => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.32.1.2' }, + fluidFSStorageSubsystemLunsAccessibility => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.32.1.3' }, +}; +my $oid_fluidFSStorageSubsystemEntry = '.1.3.6.1.4.1.674.11000.2000.200.1.32.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_fluidFSStorageSubsystemEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking storage subsystem"); + $self->{components}->{substorage} = {name => 'substorage', total => 0, skip => 0}; + return if ($self->check_filter(section => 'substorage')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_fluidFSStorageSubsystemEntry}})) { + next if ($oid !~ /^$mapping->{fluidFSStorageSubsystemLunsAccessibility}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_fluidFSStorageSubsystemEntry}, instance => $instance); + + next if ($self->check_filter(section => 'substorage', instance => $instance)); + $self->{components}->{substorage}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("storage subsystem '%s' status is '%s' [instance = %s]", + $result->{fluidFSStorageSubsystemType}, + $result->{fluidFSStorageSubsystemLunsAccessibility}, $instance + )); + + my $exit = $self->get_severity(label => 'default', section => 'substorage', value => $result->{fluidFSStorageSubsystemLunsAccessibility}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Storage subsystem '%s' status is '%s'", + $result->{fluidFSStorageSubsystemType}, + $result->{fluidFSStorageSubsystemLunsAccessibility} + )); + } + } +} + +1; \ No newline at end of file diff --git a/storage/dell/fluidfs/snmp/mode/hardware.pm b/storage/dell/fluidfs/snmp/mode/hardware.pm new file mode 100644 index 000000000..a12d0b443 --- /dev/null +++ b/storage/dell/fluidfs/snmp/mode/hardware.pm @@ -0,0 +1,107 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(ad|extservers|overall|substorage)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + ad => [ + ['Yes', 'OK'], + ['.*', 'CRITICAL'], + ], + extservers => [ + ['AVAILABLE', 'OK'], + ['.*', 'CRITICAL'], + ], + default => [ + ['Optimal', 'OK'], + ['.*', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'storage::dell::fluidfs::snmp::mode::components'; + $self->{components_module} = ['overall', 'ad', 'extservers', 'substorage']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check Hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'overall', 'ad', 'extservers', 'substorage'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=substorage) +Can also exclude specific instance: --filter=substorage,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='overall,WARNING,^(?!(optimal))' + +=back + +=cut \ No newline at end of file diff --git a/storage/dell/fluidfs/snmp/mode/volumeusage.pm b/storage/dell/fluidfs/snmp/mode/volumeusage.pm new file mode 100644 index 000000000..e9d092b16 --- /dev/null +++ b/storage/dell/fluidfs/snmp/mode/volumeusage.pm @@ -0,0 +1,217 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::snmp::mode::volumeusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'volume', type => 1, cb_prefix_output => 'prefix_volume_output', message_multiple => 'All volumes are ok' } + ]; + + $self->{maps_counters}->{volume} = [ + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub prefix_volume_output { + my ($self, %options) = @_; + + return "Volume '" . $options{instance_value}->{display} . "' "; +} + +my $mapping = { + fluidFSNASVolumeVolumeName => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.41.1.2' }, + fluidFSNASVolumeSizeMB => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.41.1.3' }, + fluidFSNASVolumeUsedSpaceMB => { oid => '.1.3.6.1.4.1.674.11000.2000.200.1.41.1.4' }, +}; + +my $oid_fluidFSNASVolumeEntry = '.1.3.6.1.4.1.674.11000.2000.200.1.41.1'; + +sub manage_selection { + my ($self, %options) = @_; + + $self->{volume} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_fluidFSNASVolumeEntry, + nothing_quit => 1); + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{fluidFSNASVolumeVolumeName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{fluidFSNASVolumeVolumeName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{fluidFSNASVolumeVolumeName} . "': no matching filter.", debug => 1); + next; + } + + $self->{volume}->{$instance} = { + display => $result->{fluidFSNASVolumeVolumeName}, + total => $result->{fluidFSNASVolumeSizeMB} * 1024 * 1024, + used => $result->{fluidFSNASVolumeUsedSpaceMB} * 1024 * 1024, + }; + } + + if (scalar(keys %{$self->{volume}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No volume found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check volumes. + +=over 8 + +=item B<--filter-name> + +Filter volume name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + + +=back + +=cut diff --git a/storage/dell/fluidfs/snmp/plugin.pm b/storage/dell/fluidfs/snmp/plugin.pm new file mode 100644 index 000000000..9388c09fb --- /dev/null +++ b/storage/dell/fluidfs/snmp/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::dell::fluidfs::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}} = ( + 'components' => 'storage::dell::fluidfs::snmp::mode::hardware', + 'volume-usage' => 'storage::dell::fluidfs::snmp::mode::volumeusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Dell FluidFS (Dell FS8600) in SNMP. + +=cut diff --git a/storage/hp/lefthand/snmp/mode/volumeusage.pm b/storage/hp/lefthand/snmp/mode/volumeusage.pm index 795d690e4..a61f6604b 100644 --- a/storage/hp/lefthand/snmp/mode/volumeusage.pm +++ b/storage/hp/lefthand/snmp/mode/volumeusage.pm @@ -131,7 +131,6 @@ sub custom_usage_calc { return 0; } - sub set_counters { my ($self, %options) = @_; @@ -173,7 +172,7 @@ sub set_counters { per_second => 1, output_template => 'Read IOPs : %.2f', output_error_template => "Read IOPs : %s", perfdatas => [ - { label => 'read_iops', value => 'clusVolumeStatsIOsRead_per_second', template => '%.2f', + { label => 'read_iops', value => 'clusVolumeStatsIOsRead_per_second', template => '%.2f', unit => 'iops', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } @@ -190,20 +189,18 @@ sub set_counters { }, { label => 'read-latency', set => { key_values => [ { name => 'clusVolumeStatsIoLatencyRead', diff => 1 }, { name => 'display' } ], - per_second => 1, - output_template => 'Read Latency : %s ms', output_error_template => "Read Latency : %s", + output_template => 'Read Latency : %.2f ms', output_error_template => "Read Latency : %s", perfdatas => [ - { label => 'read_latency', value => 'clusVolumeStatsIoLatencyRead_absolute', template => '%s', + { label => 'read_latency', value => 'clusVolumeStatsIoLatencyRead_absolute', template => '%.2f', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } }, { label => 'write-latency', set => { key_values => [ { name => 'clusVolumeStatsIoLatencyWrite', diff => 1 }, { name => 'display' } ], - per_second => 1, - output_template => 'Write Latency : %s ms', output_error_template => "Write Latency : %s", + output_template => 'Write Latency : %.2f ms', output_error_template => "Write Latency : %s", perfdatas => [ - { label => 'write_latency', value => 'clusVolumeStatsIoLatencyWrite_absolute', template => '%s', + { label => 'write_latency', value => 'clusVolumeStatsIoLatencyWrite_absolute', template => '%.2f', unit => 'ms', min => 0, label_extra_instance => 1, instance_use => 'display_absolute' }, ], } @@ -370,7 +367,6 @@ Units of thresholds (Default: '%') ('%', 'B'). Thresholds are on free space left. - =back =cut diff --git a/storage/oracle/zs/snmp/mode/components/module.pm b/storage/oracle/zs/snmp/mode/components/module.pm new file mode 100644 index 000000000..448567ac9 --- /dev/null +++ b/storage/oracle/zs/snmp/mode/components/module.pm @@ -0,0 +1,68 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::oracle::zs::snmp::mode::components::module; + +use strict; +use warnings; + +my $map_status = { 1 => 'other', 2 => 'active', 3 => 'failed'}; + +my $mapping = { + sunFmModuleName => { oid => '.1.3.6.1.4.1.42.2.195.1.3.1.2' }, + sunFmModuleStatus => { oid => '.1.3.6.1.4.1.42.2.195.1.3.1.4', map => $map_status }, +}; +my $oid_sunFmModuleEntry = '.1.3.6.1.4.1.42.2.195.1.3.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_sunFmModuleEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking modules"); + $self->{components}->{module} = {name => 'module', total => 0, skip => 0}; + return if ($self->check_filter(section => 'module')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_sunFmModuleEntry}})) { + next if ($oid !~ /^$mapping->{sunFmModuleName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_sunFmModuleEntry}, instance => $instance); + + next if ($self->check_filter(section => 'module', instance => $instance)); + $self->{components}->{module}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("module '%s' status is '%s' [instance: %s].", + $result->{sunFmModuleName}, $result->{sunFmModuleStatus}, + $instance + )); + my $exit = $self->get_severity(section => 'module', value => $result->{sunFmModuleStatus}); + 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'", + $result->{sunFmModuleName}, $result->{sunFmModuleStatus})); + } + } +} + +1; \ No newline at end of file diff --git a/storage/oracle/zs/snmp/mode/hardware.pm b/storage/oracle/zs/snmp/mode/hardware.pm new file mode 100644 index 000000000..094d89bf2 --- /dev/null +++ b/storage/oracle/zs/snmp/mode/hardware.pm @@ -0,0 +1,101 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::oracle::zs::snmp::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = '^(module)$'; + + $self->{cb_hook2} = 'snmp_execute'; + + $self->{thresholds} = { + module => [ + ['other', 'UNKNOWN'], + ['active', 'OK'], + ['failed', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'storage::oracle::zs::snmp::mode::components'; + $self->{components_module} = ['module']; +} + +sub snmp_execute { + my ($self, %options) = @_; + + $self->{snmp} = $options{snmp}; + $self->{results} = $self->{snmp}->get_multiple_table(oids => $self->{request}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + return $self; +} + +1; + +__END__ + +=head1 MODE + +Check hardware. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'module'. + +=item B<--filter> + +Exclude some parts (comma seperated list) +Can also exclude specific instance: --filter=module,1 + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='module,OK,other' + +=back + +=cut + \ No newline at end of file diff --git a/storage/oracle/zs/snmp/mode/listshares.pm b/storage/oracle/zs/snmp/mode/listshares.pm new file mode 100644 index 000000000..52d394167 --- /dev/null +++ b/storage/oracle/zs/snmp/mode/listshares.pm @@ -0,0 +1,133 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::oracle::zs::snmp::mode::listshares; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "filter-project:s" => { name => 'filter_project' }, + }); + $self->{shares} = {}; + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +my $mapping = { + sunAkShareName => { oid => '.1.3.6.1.4.1.42.2.225.1.6.1.2' }, + sunAkShareProject => { oid => '.1.3.6.1.4.1.42.2.225.1.6.1.4' }, +}; + +my $oid_sunAkShareEntry = '.1.3.6.1.4.1.42.2.225.1.6.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_sunAkShareEntry, end => $mapping->{sunAkShareProject}->{oid}, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sunAkShareName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{sunAkShareName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sunAkShareName} . "': no matching filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_project}) && $self->{option_results}->{filter_project} ne '' && + $result->{sunAkShareProject} !~ /$self->{option_results}->{filter_project}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sunAkShareName} . "': no matching filter.", debug => 1); + next; + } + + $self->{shares}->{$instance} = { name => $result->{sunAkShareName}, project => $result->{sunAkShareProject} }; + } +} + +sub run { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{shares}}) { + $self->{output}->output_add(long_msg => '[name = ' . $self->{shares}->{$instance}->{name} . "] [project = '" . $self->{shares}->{$instance}->{project} . "']"); + } + + $self->{output}->output_add(severity => 'OK', + short_msg => 'List shares:'); + $self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1); + $self->{output}->exit(); +} + +sub disco_format { + my ($self, %options) = @_; + + $self->{output}->add_disco_format(elements => ['name', 'project']); +} + +sub disco_show { + my ($self, %options) = @_; + + $self->manage_selection(%options); + foreach my $instance (sort keys %{$self->{shares}}) { + $self->{output}->add_disco_entry(name => $self->{shares}->{$instance}->{name}, project => $self->{shares}->{$instance}->{project}); + } +} + +1; + +__END__ + +=head1 MODE + +List shares. + +=over 8 + +=item B<--filter-name> + +Filter by share name (can be a regexp). + +=item B<--filter-project> + +Filter by project (can be a regexp). + +=back + +=cut + \ No newline at end of file diff --git a/storage/oracle/zs/snmp/mode/shareusage.pm b/storage/oracle/zs/snmp/mode/shareusage.pm new file mode 100644 index 000000000..c89fe20d9 --- /dev/null +++ b/storage/oracle/zs/snmp/mode/shareusage.pm @@ -0,0 +1,255 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::oracle::zs::snmp::mode::shareusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = $self->{result_values}->{label} . '_used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = $self->{result_values}->{label} . '_free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{label} = $options{extra_options}->{label_ref}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'project', type => 1, cb_prefix_output => 'prefix_project_output', message_multiple => 'All projects are ok' }, + { name => 'share', type => 1, cb_prefix_output => 'prefix_share_output', message_multiple => 'All shares are ok' } + ]; + + $self->{maps_counters}->{share} = [ + { label => 'share-usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'share' }, + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; + $self->{maps_counters}->{project} = [ + { label => 'project-usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc_extra_options => { label_ref => 'project' }, + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "filter-project:s" => { name => 'filter_project' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + $instance_mode = $self; +} + +sub prefix_share_output { + my ($self, %options) = @_; + + return "Share '" . $options{instance_value}->{display} . "' "; +} + +sub prefix_project_output { + my ($self, %options) = @_; + + return "Project '" . $options{instance_value}->{display} . "' "; +} + +my $mapping = { + sunAkShareName => { oid => '.1.3.6.1.4.1.42.2.225.1.6.1.2' }, + sunAkShareProject => { oid => '.1.3.6.1.4.1.42.2.225.1.6.1.4' }, + sunAkShareSizeB => { oid => '.1.3.6.1.4.1.42.2.225.1.6.1.10' }, + sunAkShareUsedB => { oid => '.1.3.6.1.4.1.42.2.225.1.6.1.11' }, +}; + +my $oid_sunAkShareEntry = '.1.3.6.1.4.1.42.2.225.1.6.1'; + +sub manage_selection { + my ($self, %options) = @_; + + if ($options{snmp}->is_snmpv1()) { + $self->{output}->add_option_msg(short_msg => "Need to use SNMP v2c or v3."); + $self->{output}->option_exit(); + } + + $self->{share} = {}; + $self->{project} = {}; + my $snmp_result = $options{snmp}->get_table(oid => $oid_sunAkShareEntry, + nothing_quit => 1); + + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{sunAkShareName}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $result->{sunAkShareName} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sunAkShareName} . "': no matching filter.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_project}) && $self->{option_results}->{filter_project} ne '' && + $result->{sunAkShareProject} !~ /$self->{option_results}->{filter_project}/) { + $self->{output}->output_add(long_msg => "skipping '" . $result->{sunAkShareName} . "': no matching filter.", debug => 1); + next; + } + + $self->{project}->{$result->{sunAkShareProject}} = { total => 0, used => 0, display => $result->{sunAkShareProject} } + if (!defined($self->{project}->{$result->{sunAkShareProject}})); + $self->{share}->{$instance} = { + display => $result->{sunAkShareName}, + total => $result->{sunAkShareSizeB}, + used => $result->{sunAkShareUsedB}, + }; + $self->{project}->{$result->{sunAkShareProject}}->{total} += $result->{sunAkShareSizeB}; + $self->{project}->{$result->{sunAkShareProject}}->{used} += $result->{sunAkShareUsedB}; + } + + if (scalar(keys %{$self->{share}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No share found."); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check shares. + +=over 8 + +=item B<--filter-name> + +Filter share name (can be a regexp). + +=item B<--filter-project> + +Filter project name (can be a regexp). + +=item B<--warning-*> + +Threshold warning. +Can be: 'share-usage', 'project-usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'share-usage', 'project-usage'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=back + +=cut diff --git a/storage/oracle/zs/snmp/plugin.pm b/storage/oracle/zs/snmp/plugin.pm new file mode 100644 index 000000000..bd3c0d31f --- /dev/null +++ b/storage/oracle/zs/snmp/plugin.pm @@ -0,0 +1,52 @@ +# +# Copyright 2017 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::oracle::zs::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}} = ( + 'hardware' => 'storage::oracle::zs::snmp::mode::hardware', + 'list-interfaces' => 'snmp_standard::mode::listinterfaces', + 'list-shares' => 'storage::oracle::zs::snmp::mode::listshares', + 'interfaces' => 'snmp_standard::mode::interfaces', + 'share-usage' => 'storage::oracle::zs::snmp::mode::shareusage', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Oracle ZFS Storage ZS in SNMP. + +=cut