diff --git a/apps/proxmox/ve/restapi/mode/storageusage.pm b/apps/proxmox/ve/restapi/mode/storageusage.pm index b8fc18d33..50d152e61 100644 --- a/apps/proxmox/ve/restapi/mode/storageusage.pm +++ b/apps/proxmox/ve/restapi/mode/storageusage.pm @@ -233,6 +233,8 @@ sub manage_selection { 1; +__END__ + =head1 MODE Check storage usage. diff --git a/apps/proxmox/ve/restapi/mode/version.pm b/apps/proxmox/ve/restapi/mode/version.pm index c531d4de0..88d024ddd 100644 --- a/apps/proxmox/ve/restapi/mode/version.pm +++ b/apps/proxmox/ve/restapi/mode/version.pm @@ -53,6 +53,8 @@ sub run { 1; +__END__ + =head1 MODE Get Proxmox VE Version diff --git a/apps/proxmox/ve/restapi/mode/vmusage.pm b/apps/proxmox/ve/restapi/mode/vmusage.pm index b21164b83..90db9861d 100644 --- a/apps/proxmox/ve/restapi/mode/vmusage.pm +++ b/apps/proxmox/ve/restapi/mode/vmusage.pm @@ -315,6 +315,8 @@ sub manage_selection { 1; +__END__ + =head1 MODE Check VM usage on Proxmox VE Cluster. diff --git a/apps/selenium/mode/scenariokatalon.pm b/apps/selenium/mode/scenariokatalon.pm index c187d2a72..a53d73bde 100644 --- a/apps/selenium/mode/scenariokatalon.pm +++ b/apps/selenium/mode/scenariokatalon.pm @@ -1,431 +1,431 @@ -# -# Copyright 2019 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::selenium::mode::scenariokatalon; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -use Time::HiRes qw(gettimeofday); -use XML::XPath; -use WWW::Selenium; - -my $instance_mode; - -my %handlers = (ALRM => {} ); - -sub custom_count_perfdata { - my ($self, %options) = @_; - - $self->{output}->perfdata_add(label => $self->{result_values}->{label}, - value => $self->{result_values}->{value}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1), - min => 0, max => $self->{result_values}->{total}); - - $self->{output}->perfdata_add(label => $self->{result_values}->{label} . '_prct', - value => sprintf('%.2f', $self->{result_values}->{value_prct}), - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label} . '-prct'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label} . '-prct'), - min => 0, max => 100, unit => '%'); -} - -sub custom_count_threshold { - my ($self, %options) = @_; - - my $exit1 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value}, - threshold => [ { label => 'critical-' . $self->{result_values}->{label}, exit_litteral => 'critical' }, - { label => 'warning-' . $self->{result_values}->{label}, exit_litteral => 'warning' } ]); - - my $exit2 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value} . '_prct', - threshold => [ { label => 'critical-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'critical' }, - { label => 'warning-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'warning' } ]); - - my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); - - return $exit; -} - -sub custom_count_output { - my ($self, %options) = @_; - - my $msg = sprintf("%s steps : %s/%s (%.2f%%)", ucfirst($self->{result_values}->{label}), - $self->{result_values}->{value}, $self->{result_values}->{total}, $self->{result_values}->{value_prct}); - - return $msg; -} - -sub custom_count_calc { - my ($self, %options) = @_; - - $self->{result_values}->{label} = $options{extra_options}->{label}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}}; - $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; - $self->{result_values}->{value_prct} = $self->{result_values}->{value} / $self->{result_values}->{total} * 100; - - return 0; -} - -sub custom_state_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_state}) && $instance_mode->{option_results}->{critical_state} ne '' && - eval "$instance_mode->{option_results}->{critical_state}") { - $status = 'critical'; - } elsif (defined($instance_mode->{option_results}->{warning_state}) && $instance_mode->{option_results}->{warning_state} ne '' && - eval "$instance_mode->{option_results}->{warning_state}") { - $status = 'warning'; - } - }; - if (defined($message)) { - $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); - } - - return $status; -} - -sub custom_state_output { - my ($self, %options) = @_; - - my $msg = "state is '" . $self->{result_values}->{state} . "'"; - $msg .= " : " . $self->{result_values}->{comment} if (defined($self->{result_values}->{comment}) && $self->{result_values}->{comment} ne ''); - - return $msg; -} - -sub custom_state_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; - $self->{result_values}->{command} = $options{new_datas}->{$self->{instance} . '_command'}; - $self->{result_values}->{target} = $options{new_datas}->{$self->{instance} . '_target'}; - $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'}; - $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; - $self->{result_values}->{comment} = $options{new_datas}->{$self->{instance} . '_comment'}; - - return 0; -} - -sub prefix_output { - my ($self, %options) = @_; - - my $msg = "Step '" . $options{instance_value}->{display} . "' [command: " . $options{instance_value}->{command}; - $msg .= ", target: " . $options{instance_value}->{target} if (defined($options{instance_value}->{target}) && $options{instance_value}->{target} ne ''); - $msg .= ", value: " . $options{instance_value}->{value} if (defined($options{instance_value}->{value}) && $options{instance_value}->{value} ne ''); - $msg .= "] "; - - return $msg; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0 }, - { name => 'steps', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All steps state are ok' }, - ]; - - $self->{maps_counters}->{global} = [ - { label => 'successful', set => { - key_values => [ { name => 'successful' }, { name => 'total' } ], - closure_custom_calc => $self->can('custom_count_calc'), - closure_custom_calc_extra_options => { label => 'successful' }, - closure_custom_output => $self->can('custom_count_output'), - closure_custom_perfdata => $self->can('custom_count_perfdata'), - closure_custom_threshold_check => $self->can('custom_count_threshold'), - } - }, - { label => 'failed', set => { - key_values => [ { name => 'failed' }, { name => 'total' } ], - closure_custom_calc => $self->can('custom_count_calc'), - closure_custom_calc_extra_options => { label => 'failed' }, - closure_custom_output => $self->can('custom_count_output'), - closure_custom_perfdata => $self->can('custom_count_perfdata'), - closure_custom_threshold_check => $self->can('custom_count_threshold'), - } - }, - { label => 'time-scenario', set => { - key_values => [ { name => 'time_scenario' } ], - output_template => 'Total execution time : %.2f ms', - perfdatas => [ - { label => 'time_scenario', value => 'time_scenario_absolute', template => '%.2f', - min => 0, unit => 'ms' }, - ], - } - }, - ]; - - $self->{maps_counters}->{steps} = [ - { label => 'state', set => { - key_values => [ { name => 'state' }, { name => 'command' }, { name => 'target' }, - { name => 'value' }, { name => 'comment' }, { name => 'display' } ], - closure_custom_calc => $self->can('custom_state_calc'), - closure_custom_output => $self->can('custom_state_output'), - closure_custom_perfdata => sub { return 0; }, - closure_custom_threshold_check => $self->can('custom_state_threshold'), - } - }, - { label => 'time-step', set => { - key_values => [ { name => 'time_step' }, { name => 'display' } ], - output_template => 'Execution time : %.2f ms', - perfdatas => [ - { label => 'time_step', value => 'time_step_absolute', template => '%.2f', - min => 0, unit => 'ms', 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 => - { - "selenium-hostname:s" => { name => 'selenium_hostname', default => 'localhost' }, - "selenium-port:s" => { name => 'selenium_port', default => '4444' }, - "browser:s" => { name => 'browser', default => '*firefox' }, - "directory:s" => { name => 'directory', default => '/var/lib/centreon_waa' }, - "scenario:s" => { name => 'scenario' }, - "force-continue" => { name => 'force_continue' }, - "timeout:s" => { name => 'timeout', default => 50 }, - "action-timeout:s" => { name => 'action_timeout', default => 10 }, - "warning-state:s" => { name => 'warning_state', default => '' }, - "critical-state:s" => { name => 'critical_state', default => '%{state} !~ /OK/i' }, - }); - - $self->set_signal_handlers; - return $self; -} - -sub set_signal_handlers { - my $self = shift; - - $SIG{ALRM} = \&class_handle_ALRM; - $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; -} - -sub class_handle_ALRM { - foreach (keys %{$handlers{ALRM}}) { - &{$handlers{ALRM}->{$_}}(); - } -} - -sub handle_ALRM { - my $self = shift; - - $self->{output}->output_add(severity => 'UNKNOWN', - short_msg => sprintf("Cannot finished scenario execution (timeout received)")); - $self->{output}->display(); - $self->{output}->exit(); -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && - $self->{option_results}->{timeout} > 0) { - alarm($self->{option_results}->{timeout}); - } - if (!defined($self->{option_results}->{scenario})) { - $self->{output}->add_option_msg(short_msg => "Please specify a scenario name."); - $self->{output}->option_exit(); - } - - $instance_mode = $self; - $self->change_macros(); -} - -sub change_macros { - my ($self, %options) = @_; - - foreach (('warning_state', 'critical_state')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{global}->{failed} = 0; - $self->{global}->{successful} = 0; - $self->{global}->{time_scenario} = 0; - - $self->{selenium} = WWW::Selenium->new( - host => $self->{option_results}->{selenium_hostname}, - port => $self->{option_results}->{selenium_port}, - browser => $self->{option_results}->{browser}, - browser_url => "file://localhost" - ); - - my $filename = $self->{option_results}->{directory} . '/' . $self->{option_results}->{scenario} . '.xml'; - my $xp = XML::XPath->new(filename => $filename); - - my $step = 1; - - $self->{selenium}->start; - $self->{selenium}->set_timeout($self->{option_results}->{action_timeout} * 1000); - - my $actions = $xp->find('/TestCase/selenese'); - $self->{global}->{total} = $actions->size; - - my $start = gettimeofday() * 1000; - - foreach my $action ($actions->get_nodelist) { - my $command = centreon::plugins::misc::trim($xp->find('command', $action)->string_value); - my $target = centreon::plugins::misc::trim($xp->find('target', $action)->string_value); - my $value = centreon::plugins::misc::trim($xp->find('value', $action)->string_value); - - $self->{steps}->{$step}->{display} = $step; - $self->{steps}->{$step}->{command} = $command; - $self->{steps}->{$step}->{target} = $target; - $self->{steps}->{$step}->{value} = $value; - $self->{steps}->{$step}->{state} = 'OK'; - $self->{steps}->{$step}->{comment} = ''; - $self->{steps}->{$step}->{time_step} = 0; - - my $result; - my $step_start = gettimeofday() * 1000; - - eval { - if ($command =~ /pause/) { - $result = $self->{selenium}->pause($value); - } else { - $result = $self->{selenium}->do_command($command, $target, $value); - } - }; - - $self->{steps}->{$step}->{time_step} = gettimeofday() * 1000 - $step_start; - - if (!$@) { - $self->{global}->{successful}++; - } else { - $self->{steps}->{$step}->{comment} = $@; - $self->{steps}->{$step}->{comment} =~ s/^(.*\n)//;;; - $self->{steps}->{$step}->{comment} =~ s/\n//;;; - $self->{steps}->{$step}->{state} = 'ERROR'; - $self->{global}->{failed}++; - last unless $self->{option_results}->{force_continue}; - } - - $step++; - } - - $self->{global}->{time_scenario} = gettimeofday() * 1000 - $start; - $self->{selenium}->stop; -} - -1; - -__END__ - -=head1 MODE - -Play scenario based on Katalon Automation Recorder XML export - -=over 8 - -=item B<--selenium-hostname> - -IP Addr/FQDN of the Selenium server. - -=item B<--selenium-port> - -Port used by Selenium server. - -=item B<--browser> - -Browser used by Selenium server (Default : '*firefox'). - -=item B<--directory> - -Directory where scenarii are stored. - -=item B<--scenario> - -Scenario to play (without extension). - -=item B<--force-continue> - -Don't stop if error. - -=item B<--timeout> - -Set scenario execution timeout in second (Default: 50). - -=item B<--action-timeout> - -Set action execution timeout in second (Default: 10). - -=item B<--warning-*> - -Threshold warning for steps state count -(Can be: 'failed', 'successful'). - -=item B<--critical-*> - -Threshold critical for steps state count -(Can be: 'failed', 'successful'). - -=item B<--warning-time-scenario> - -Threshold warning in milliseconds -for scenario execution time. - -=item B<--critical-time-scenario> - -Threshold critical in milliseconds -for scenario execution time. - -=item B<--warning-time-step> - -Threshold warning in milliseconds -for step execution time. - -=item B<--critical-time-step> - -Threshold critical in milliseconds -for step execution time. - -=item B<--warning-state> - -Threshold warning for step state. - -=item B<--critical-state> - -Threshold critical for step state -(Default: '%{state} !~ /OK/i'). - -=back - -=cut +# +# Copyright 2019 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::selenium::mode::scenariokatalon; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +use Time::HiRes qw(gettimeofday); +use XML::XPath; +use WWW::Selenium; + +my $instance_mode; + +my %handlers = (ALRM => {} ); + +sub custom_count_perfdata { + my ($self, %options) = @_; + + $self->{output}->perfdata_add(label => $self->{result_values}->{label}, + value => $self->{result_values}->{value}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label}, total => $self->{result_values}->{total}, cast_int => 1), + min => 0, max => $self->{result_values}->{total}); + + $self->{output}->perfdata_add(label => $self->{result_values}->{label} . '_prct', + value => sprintf('%.2f', $self->{result_values}->{value_prct}), + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label} . '-prct'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label} . '-prct'), + min => 0, max => 100, unit => '%'); +} + +sub custom_count_threshold { + my ($self, %options) = @_; + + my $exit1 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value}, + threshold => [ { label => 'critical-' . $self->{result_values}->{label}, exit_litteral => 'critical' }, + { label => 'warning-' . $self->{result_values}->{label}, exit_litteral => 'warning' } ]); + + my $exit2 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value} . '_prct', + threshold => [ { label => 'critical-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'critical' }, + { label => 'warning-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'warning' } ]); + + my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); + + return $exit; +} + +sub custom_count_output { + my ($self, %options) = @_; + + my $msg = sprintf("%s steps : %s/%s (%.2f%%)", ucfirst($self->{result_values}->{label}), + $self->{result_values}->{value}, $self->{result_values}->{total}, $self->{result_values}->{value_prct}); + + return $msg; +} + +sub custom_count_calc { + my ($self, %options) = @_; + + $self->{result_values}->{label} = $options{extra_options}->{label}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{label}}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{value_prct} = $self->{result_values}->{value} / $self->{result_values}->{total} * 100; + + return 0; +} + +sub custom_state_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_state}) && $instance_mode->{option_results}->{critical_state} ne '' && + eval "$instance_mode->{option_results}->{critical_state}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_state}) && $instance_mode->{option_results}->{warning_state} ne '' && + eval "$instance_mode->{option_results}->{warning_state}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_state_output { + my ($self, %options) = @_; + + my $msg = "state is '" . $self->{result_values}->{state} . "'"; + $msg .= " : " . $self->{result_values}->{comment} if (defined($self->{result_values}->{comment}) && $self->{result_values}->{comment} ne ''); + + return $msg; +} + +sub custom_state_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{command} = $options{new_datas}->{$self->{instance} . '_command'}; + $self->{result_values}->{target} = $options{new_datas}->{$self->{instance} . '_target'}; + $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'}; + $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; + $self->{result_values}->{comment} = $options{new_datas}->{$self->{instance} . '_comment'}; + + return 0; +} + +sub prefix_output { + my ($self, %options) = @_; + + my $msg = "Step '" . $options{instance_value}->{display} . "' [command: " . $options{instance_value}->{command}; + $msg .= ", target: " . $options{instance_value}->{target} if (defined($options{instance_value}->{target}) && $options{instance_value}->{target} ne ''); + $msg .= ", value: " . $options{instance_value}->{value} if (defined($options{instance_value}->{value}) && $options{instance_value}->{value} ne ''); + $msg .= "] "; + + return $msg; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'steps', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All steps state are ok' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'successful', set => { + key_values => [ { name => 'successful' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_count_calc'), + closure_custom_calc_extra_options => { label => 'successful' }, + closure_custom_output => $self->can('custom_count_output'), + closure_custom_perfdata => $self->can('custom_count_perfdata'), + closure_custom_threshold_check => $self->can('custom_count_threshold'), + } + }, + { label => 'failed', set => { + key_values => [ { name => 'failed' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_count_calc'), + closure_custom_calc_extra_options => { label => 'failed' }, + closure_custom_output => $self->can('custom_count_output'), + closure_custom_perfdata => $self->can('custom_count_perfdata'), + closure_custom_threshold_check => $self->can('custom_count_threshold'), + } + }, + { label => 'time-scenario', set => { + key_values => [ { name => 'time_scenario' } ], + output_template => 'Total execution time : %.2f ms', + perfdatas => [ + { label => 'time_scenario', value => 'time_scenario_absolute', template => '%.2f', + min => 0, unit => 'ms' }, + ], + } + }, + ]; + + $self->{maps_counters}->{steps} = [ + { label => 'state', set => { + key_values => [ { name => 'state' }, { name => 'command' }, { name => 'target' }, + { name => 'value' }, { name => 'comment' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_state_calc'), + closure_custom_output => $self->can('custom_state_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_state_threshold'), + } + }, + { label => 'time-step', set => { + key_values => [ { name => 'time_step' }, { name => 'display' } ], + output_template => 'Execution time : %.2f ms', + perfdatas => [ + { label => 'time_step', value => 'time_step_absolute', template => '%.2f', + min => 0, unit => 'ms', 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 => + { + "selenium-hostname:s" => { name => 'selenium_hostname', default => 'localhost' }, + "selenium-port:s" => { name => 'selenium_port', default => '4444' }, + "browser:s" => { name => 'browser', default => '*firefox' }, + "directory:s" => { name => 'directory', default => '/var/lib/centreon_waa' }, + "scenario:s" => { name => 'scenario' }, + "force-continue" => { name => 'force_continue' }, + "timeout:s" => { name => 'timeout', default => 50 }, + "action-timeout:s" => { name => 'action_timeout', default => 10 }, + "warning-state:s" => { name => 'warning_state', default => '' }, + "critical-state:s" => { name => 'critical_state', default => '%{state} !~ /OK/i' }, + }); + + $self->set_signal_handlers; + return $self; +} + +sub set_signal_handlers { + my $self = shift; + + $SIG{ALRM} = \&class_handle_ALRM; + $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; +} + +sub class_handle_ALRM { + foreach (keys %{$handlers{ALRM}}) { + &{$handlers{ALRM}->{$_}}(); + } +} + +sub handle_ALRM { + my $self = shift; + + $self->{output}->output_add(severity => 'UNKNOWN', + short_msg => sprintf("Cannot finished scenario execution (timeout received)")); + $self->{output}->display(); + $self->{output}->exit(); +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && + $self->{option_results}->{timeout} > 0) { + alarm($self->{option_results}->{timeout}); + } + if (!defined($self->{option_results}->{scenario})) { + $self->{output}->add_option_msg(short_msg => "Please specify a scenario name."); + $self->{output}->option_exit(); + } + + $instance_mode = $self; + $self->change_macros(); +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_state', 'critical_state')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global}->{failed} = 0; + $self->{global}->{successful} = 0; + $self->{global}->{time_scenario} = 0; + + $self->{selenium} = WWW::Selenium->new( + host => $self->{option_results}->{selenium_hostname}, + port => $self->{option_results}->{selenium_port}, + browser => $self->{option_results}->{browser}, + browser_url => "file://localhost" + ); + + my $filename = $self->{option_results}->{directory} . '/' . $self->{option_results}->{scenario} . '.xml'; + my $xp = XML::XPath->new(filename => $filename); + + my $step = 1; + + $self->{selenium}->start; + $self->{selenium}->set_timeout($self->{option_results}->{action_timeout} * 1000); + + my $actions = $xp->find('/TestCase/selenese'); + $self->{global}->{total} = $actions->size; + + my $start = gettimeofday() * 1000; + + foreach my $action ($actions->get_nodelist) { + my $command = centreon::plugins::misc::trim($xp->find('command', $action)->string_value); + my $target = centreon::plugins::misc::trim($xp->find('target', $action)->string_value); + my $value = centreon::plugins::misc::trim($xp->find('value', $action)->string_value); + + $self->{steps}->{$step}->{display} = $step; + $self->{steps}->{$step}->{command} = $command; + $self->{steps}->{$step}->{target} = $target; + $self->{steps}->{$step}->{value} = $value; + $self->{steps}->{$step}->{state} = 'OK'; + $self->{steps}->{$step}->{comment} = ''; + $self->{steps}->{$step}->{time_step} = 0; + + my $result; + my $step_start = gettimeofday() * 1000; + + eval { + if ($command =~ /pause/) { + $result = $self->{selenium}->pause($value); + } else { + $result = $self->{selenium}->do_command($command, $target, $value); + } + }; + + $self->{steps}->{$step}->{time_step} = gettimeofday() * 1000 - $step_start; + + if (!$@) { + $self->{global}->{successful}++; + } else { + $self->{steps}->{$step}->{comment} = $@; + $self->{steps}->{$step}->{comment} =~ s/^(.*\n)//;;; + $self->{steps}->{$step}->{comment} =~ s/\n//;;; + $self->{steps}->{$step}->{state} = 'ERROR'; + $self->{global}->{failed}++; + last unless $self->{option_results}->{force_continue}; + } + + $step++; + } + + $self->{global}->{time_scenario} = gettimeofday() * 1000 - $start; + $self->{selenium}->stop; +} + +1; + +__END__ + +=head1 MODE + +Play scenario based on Katalon Automation Recorder XML export + +=over 8 + +=item B<--selenium-hostname> + +IP Addr/FQDN of the Selenium server. + +=item B<--selenium-port> + +Port used by Selenium server. + +=item B<--browser> + +Browser used by Selenium server (Default : '*firefox'). + +=item B<--directory> + +Directory where scenarii are stored. + +=item B<--scenario> + +Scenario to play (without extension). + +=item B<--force-continue> + +Don't stop if error. + +=item B<--timeout> + +Set scenario execution timeout in second (Default: 50). + +=item B<--action-timeout> + +Set action execution timeout in second (Default: 10). + +=item B<--warning-*> + +Threshold warning for steps state count +(Can be: 'failed', 'successful'). + +=item B<--critical-*> + +Threshold critical for steps state count +(Can be: 'failed', 'successful'). + +=item B<--warning-time-scenario> + +Threshold warning in milliseconds +for scenario execution time. + +=item B<--critical-time-scenario> + +Threshold critical in milliseconds +for scenario execution time. + +=item B<--warning-time-step> + +Threshold warning in milliseconds +for step execution time. + +=item B<--critical-time-step> + +Threshold critical in milliseconds +for step execution time. + +=item B<--warning-state> + +Threshold warning for step state. + +=item B<--critical-state> + +Threshold critical for step state +(Default: '%{state} !~ /OK/i'). + +=back + +=cut diff --git a/cloud/aws/billing/mode/estimatedcharges.pm b/cloud/aws/billing/mode/estimatedcharges.pm index 20515608a..3ce776ee1 100644 --- a/cloud/aws/billing/mode/estimatedcharges.pm +++ b/cloud/aws/billing/mode/estimatedcharges.pm @@ -1,139 +1,139 @@ -# -# Copyright 2019 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 cloud::aws::billing::mode::estimatedcharges; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub prefix_charges_output { - my ($self, %options) = @_; - - return "Service '" . $self->{option_results}->{service} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'estimatedcharges', type => 0, cb_prefix_output => 'prefix_charges_output' }, - ]; - - $self->{maps_counters}->{estimatedcharges} = [ - { label => 'billing', set => { - key_values => [ { name => 'estimated_charges' }, { name => 'display' } ], - output_template => 'estimated charges: %.2f USD', - perfdatas => [ - { label => 'billing', value => 'estimated_charges_absolute', template => '%.2f', - unit => 'USD' }, - ], - } - }, - ]; -} - -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 => - { - "service:s" => { name => 'service' }, - "currency:s" => { name => 'currency', default => 'USD' }, - }); - - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::check_options(%options); - - if (!defined($self->{option_results}->{service}) || $self->{option_results}->{service} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --service option."); - $self->{output}->option_exit(); - } - - if (!defined($self->{option_results}->{currency}) || $self->{option_results}->{currency} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --currency option."); - $self->{output}->option_exit(); - } - - $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 86400; - $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; -} - -sub manage_selection { - my ($self, %options) = @_; - - my $metric_results = $options{custom}->cloudwatch_get_metrics( - region => $self->{option_results}->{region}, - namespace => 'AWS/Billing', - dimensions => [ { Name => 'ServiceName', Value => $self->{option_results}->{service} }, { Name => 'Currency', Value => $self->{option_results}->{currency} } ], - metrics => ['EstimatedCharges'], - statistics => ['Maximum'], - timeframe => $self->{aws_timeframe}, - period => $self->{aws_period}, - ); - - $self->{estimatedcharges}->{estimated_charges} = $metric_results->{'EstimatedCharges'}->{'maximum'} if defined($metric_results->{'EstimatedCharges'}->{'maximum'}); - $self->{estimatedcharges}->{display} = $self->{option_results}->{service}; - - if (scalar(keys %{$self->{estimatedcharges}}) <= 0) { - $self->{output}->add_option_msg(short_msg => 'No value.'); - $self->{output}->option_exit(); - } -} - -1; - -__END__ - -=head1 MODE - -Check Billing estimated charges for a service. - -Example: -perl centreon_plugins.pl --plugin=cloud::aws::billing::plugin --custommode=paws --mode=estimated-charges ---region='us-east-1' --service='AWSService' --verbose - -See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/billing-metricscollected.html' for more informations. - -=over 8 - -=item B<--service> - -Set the Amazon service (Required). - -=item B<--warning-billing> - -Thresholds warning. - -=item B<--critical-billing> - -Thresholds critical. - -=back - -=cut +# +# Copyright 2019 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 cloud::aws::billing::mode::estimatedcharges; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub prefix_charges_output { + my ($self, %options) = @_; + + return "Service '" . $self->{option_results}->{service} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'estimatedcharges', type => 0, cb_prefix_output => 'prefix_charges_output' }, + ]; + + $self->{maps_counters}->{estimatedcharges} = [ + { label => 'billing', set => { + key_values => [ { name => 'estimated_charges' }, { name => 'display' } ], + output_template => 'estimated charges: %.2f USD', + perfdatas => [ + { label => 'billing', value => 'estimated_charges_absolute', template => '%.2f', + unit => 'USD' }, + ], + } + }, + ]; +} + +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 => + { + "service:s" => { name => 'service' }, + "currency:s" => { name => 'currency', default => 'USD' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (!defined($self->{option_results}->{service}) || $self->{option_results}->{service} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --service option."); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{currency}) || $self->{option_results}->{currency} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --currency option."); + $self->{output}->option_exit(); + } + + $self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 86400; + $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60; +} + +sub manage_selection { + my ($self, %options) = @_; + + my $metric_results = $options{custom}->cloudwatch_get_metrics( + region => $self->{option_results}->{region}, + namespace => 'AWS/Billing', + dimensions => [ { Name => 'ServiceName', Value => $self->{option_results}->{service} }, { Name => 'Currency', Value => $self->{option_results}->{currency} } ], + metrics => ['EstimatedCharges'], + statistics => ['Maximum'], + timeframe => $self->{aws_timeframe}, + period => $self->{aws_period}, + ); + + $self->{estimatedcharges}->{estimated_charges} = $metric_results->{'EstimatedCharges'}->{'maximum'} if defined($metric_results->{'EstimatedCharges'}->{'maximum'}); + $self->{estimatedcharges}->{display} = $self->{option_results}->{service}; + + if (scalar(keys %{$self->{estimatedcharges}}) <= 0) { + $self->{output}->add_option_msg(short_msg => 'No value.'); + $self->{output}->option_exit(); + } +} + +1; + +__END__ + +=head1 MODE + +Check Billing estimated charges for a service. + +Example: +perl centreon_plugins.pl --plugin=cloud::aws::billing::plugin --custommode=paws --mode=estimated-charges +--region='us-east-1' --service='AWSService' --verbose + +See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/billing-metricscollected.html' for more informations. + +=over 8 + +=item B<--service> + +Set the Amazon service (Required). + +=item B<--warning-billing> + +Thresholds warning. + +=item B<--critical-billing> + +Thresholds critical. + +=back + +=cut diff --git a/cloud/ibm/softlayer/custom/xmlapi.pm b/cloud/ibm/softlayer/custom/xmlapi.pm index c7d8ac337..713dd00b5 100644 --- a/cloud/ibm/softlayer/custom/xmlapi.pm +++ b/cloud/ibm/softlayer/custom/xmlapi.pm @@ -1,259 +1,259 @@ -# -# Copyright 2019 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 cloud::ibm::softlayer::custom::xmlapi; - -use strict; -use warnings; -use centreon::plugins::http; -use XML::Simple; - -sub new { - my ($class, %options) = @_; - my $self = {}; - bless $self, $class; - - if (!defined($options{output})) { - print "Class Custom: Need to specify 'output' argument.\n"; - exit 3; - } - if (!defined($options{options})) { - $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); - $options{output}->option_exit(); - } - - if (!defined($options{noptions})) { - $options{options}->add_options(arguments => - { - "hostname:s" => { name => 'hostname' }, - "url-path:s" => { name => 'url_path' }, - "port:s" => { name => 'port' }, - "proto:s" => { name => 'proto' }, - "proxyurl:s" => { name => 'proxyurl' }, - "timeout:s" => { name => 'timeout' }, - "ssl-opt:s@" => { name => 'ssl_opt' }, - "api-username:s" => { name => 'api_username' }, - "api-key:s" => { name => 'api_key' }, - }); - } - $options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI OPTIONS', once => 1); - - $self->{output} = $options{output}; - $self->{mode} = $options{mode}; - $self->{http} = centreon::plugins::http->new(output => $self->{output}); - - return $self; -} - -sub set_options { - my ($self, %options) = @_; - - $self->{option_results} = $options{option_results}; -} - -sub set_defaults { - my ($self, %options) = @_; - - foreach (keys %{$options{default}}) { - if ($_ eq $self->{mode}) { - for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { - foreach my $opt (keys %{$options{default}->{$_}[$i]}) { - if (!defined($self->{option_results}->{$opt}[$i])) { - $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; - } - } - } - } - } -} - -sub check_options { - my ($self, %options) = @_; - - $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'api.softlayer.com'; - $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; - $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; - $self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/soap/v3'; - $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; - $self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? $self->{option_results}->{proxyurl} : undef; - $self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef; - - if (!defined($self->{option_results}->{api_username}) || $self->{option_results}->{api_username} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); - $self->{output}->option_exit(); - } - if (!defined($self->{option_results}->{api_key}) || $self->{option_results}->{api_key} eq '') { - $self->{output}->add_option_msg(short_msg => "Need to specify --api-key option."); - $self->{output}->option_exit(); - } - - return 0; -} - -sub build_options_for_httplib { - my ($self, %options) = @_; - - $self->{option_results}->{hostname} = $self->{hostname}; - $self->{option_results}->{timeout} = $self->{timeout}; - $self->{option_results}->{port} = $self->{port}; - $self->{option_results}->{proto} = $self->{proto}; - $self->{option_results}->{proxyurl} = $self->{proxyurl}; - $self->{option_results}->{warning_status} = ''; - $self->{option_results}->{critical_status} = ''; -} - -sub settings { - my ($self, %options) = @_; - - $self->build_options_for_httplib(); - - $self->{http}->add_header(key => 'Accept', value => 'text/xml'); - $self->{http}->add_header(key => 'Accept', value => 'multipart/*'); - $self->{http}->add_header(key => 'Accept', value => 'text/xmlapplication/soap'); - $self->{http}->add_header(key => 'Content-Type', value => 'text/xml; charset=utf-8'); - $self->{http}->set_options(%{$self->{option_results}}); -} - -sub get_connection_info { - my ($self, %options) = @_; - - return $self->{hostname} . ":" . $self->{port}; -} - -sub get_hostname { - my ($self, %options) = @_; - - return $self->{hostname}; -} - -sub get_port { - my ($self, %options) = @_; - - return $self->{port}; -} - -sub get_api_username { - my ($self, %options) = @_; - - return $self->{option_results}->{api_username}; -} - -sub get_api_key { - my ($self, %options) = @_; - - return $self->{option_results}->{api_key}; -} - -sub get_endpoint { - my ($self, %options) = @_; - - $self->settings; - - $self->{http}->add_header(key => 'SOAPAction', value => 'http://api.service.softlayer.com/soap/v3/#' . $options{method}); - - my $content = ' - - - - ' . $self->get_api_key() . ' - ' . $self->get_api_username() . ' - ' . - $options{extra_content} - . ' - - - -'; - - my $response = $self->{http}->request(url_path => $self->{url_path} . '/' . $options{service}, method => 'POST', query_form_post => $content); - - my $xml_hash = XMLin($response, ForceArray => ['item']); - - if (defined($xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'})) { - $self->{output}->output_add(long_msg => "Returned message: " . $response, debug => 1); - $self->{output}->add_option_msg(short_msg => "API returned error code '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultcode} . - "' with message '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultstring} . "'"); - $self->{output}->option_exit(); - } - - return $xml_hash->{'SOAP-ENV:Body'}; -} - -1; - -__END__ - -=head1 NAME - -IBM SoftLayer XML API - -=head1 SYNOPSIS - -IBM SoftLayer XML API - -=head1 XMLAPI OPTIONS - -=over 8 - -=item B<--hostname> - -API hostname (Default: 'api.softlayer.com'). - -=item B<--url-path> - -API url path (Default: '/soap/v3') - -=item B<--port> - -API port (Default: 443) - -=item B<--proto> - -Specify https if needed (Default: 'https') - -=item B<--api-username> - -Set API username - -=item B<--api-key> - -Set API Key - -=item B<--proxyurl> - -Proxy URL if any - -=item B<--timeout> - -Set HTTP timeout - -=item B<--ssl-opt> - -Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE"). - -=back - -=head1 DESCRIPTION - -B. - -=cut +# +# Copyright 2019 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 cloud::ibm::softlayer::custom::xmlapi; + +use strict; +use warnings; +use centreon::plugins::http; +use XML::Simple; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "url-path:s" => { name => 'url_path' }, + "port:s" => { name => 'port' }, + "proto:s" => { name => 'proto' }, + "proxyurl:s" => { name => 'proxyurl' }, + "timeout:s" => { name => 'timeout' }, + "ssl-opt:s@" => { name => 'ssl_opt' }, + "api-username:s" => { name => 'api_username' }, + "api-key:s" => { name => 'api_key' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + $self->{http} = centreon::plugins::http->new(output => $self->{output}); + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'api.softlayer.com'; + $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443; + $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; + $self->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/soap/v3'; + $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; + $self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? $self->{option_results}->{proxyurl} : undef; + $self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef; + + if (!defined($self->{option_results}->{api_username}) || $self->{option_results}->{api_username} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-username option."); + $self->{output}->option_exit(); + } + if (!defined($self->{option_results}->{api_key}) || $self->{option_results}->{api_key} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify --api-key option."); + $self->{output}->option_exit(); + } + + return 0; +} + +sub build_options_for_httplib { + my ($self, %options) = @_; + + $self->{option_results}->{hostname} = $self->{hostname}; + $self->{option_results}->{timeout} = $self->{timeout}; + $self->{option_results}->{port} = $self->{port}; + $self->{option_results}->{proto} = $self->{proto}; + $self->{option_results}->{proxyurl} = $self->{proxyurl}; + $self->{option_results}->{warning_status} = ''; + $self->{option_results}->{critical_status} = ''; +} + +sub settings { + my ($self, %options) = @_; + + $self->build_options_for_httplib(); + + $self->{http}->add_header(key => 'Accept', value => 'text/xml'); + $self->{http}->add_header(key => 'Accept', value => 'multipart/*'); + $self->{http}->add_header(key => 'Accept', value => 'text/xmlapplication/soap'); + $self->{http}->add_header(key => 'Content-Type', value => 'text/xml; charset=utf-8'); + $self->{http}->set_options(%{$self->{option_results}}); +} + +sub get_connection_info { + my ($self, %options) = @_; + + return $self->{hostname} . ":" . $self->{port}; +} + +sub get_hostname { + my ($self, %options) = @_; + + return $self->{hostname}; +} + +sub get_port { + my ($self, %options) = @_; + + return $self->{port}; +} + +sub get_api_username { + my ($self, %options) = @_; + + return $self->{option_results}->{api_username}; +} + +sub get_api_key { + my ($self, %options) = @_; + + return $self->{option_results}->{api_key}; +} + +sub get_endpoint { + my ($self, %options) = @_; + + $self->settings; + + $self->{http}->add_header(key => 'SOAPAction', value => 'http://api.service.softlayer.com/soap/v3/#' . $options{method}); + + my $content = ' + + + + ' . $self->get_api_key() . ' + ' . $self->get_api_username() . ' + ' . + $options{extra_content} + . ' + + + +'; + + my $response = $self->{http}->request(url_path => $self->{url_path} . '/' . $options{service}, method => 'POST', query_form_post => $content); + + my $xml_hash = XMLin($response, ForceArray => ['item']); + + if (defined($xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'})) { + $self->{output}->output_add(long_msg => "Returned message: " . $response, debug => 1); + $self->{output}->add_option_msg(short_msg => "API returned error code '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultcode} . + "' with message '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultstring} . "'"); + $self->{output}->option_exit(); + } + + return $xml_hash->{'SOAP-ENV:Body'}; +} + +1; + +__END__ + +=head1 NAME + +IBM SoftLayer XML API + +=head1 SYNOPSIS + +IBM SoftLayer XML API + +=head1 XMLAPI OPTIONS + +=over 8 + +=item B<--hostname> + +API hostname (Default: 'api.softlayer.com'). + +=item B<--url-path> + +API url path (Default: '/soap/v3') + +=item B<--port> + +API port (Default: 443) + +=item B<--proto> + +Specify https if needed (Default: 'https') + +=item B<--api-username> + +Set API username + +=item B<--api-key> + +Set API Key + +=item B<--proxyurl> + +Proxy URL if any + +=item B<--timeout> + +Set HTTP timeout + +=item B<--ssl-opt> + +Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE"). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/cloud/ibm/softlayer/mode/events.pm b/cloud/ibm/softlayer/mode/events.pm index 7eca48e5b..168773eb5 100644 --- a/cloud/ibm/softlayer/mode/events.pm +++ b/cloud/ibm/softlayer/mode/events.pm @@ -1,284 +1,284 @@ -# -# Copyright 2019 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 cloud::ibm::softlayer::mode::events; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -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]; }; - - 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, debug => 1); - } - - return $status; -} - -sub custom_event_output { - my ($self, %options) = @_; - - my $msg = sprintf("Status is '%s', Impacted items: %d, Start date: %s, End date: %s", - $self->{result_values}->{status}, - $self->{result_values}->{items}, - ($self->{result_values}->{start_date} ne "-") ? $self->{result_values}->{start_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_start}) . ' ago)' : '-', - ($self->{result_values}->{end_date} ne "-") ? $self->{result_values}->{end_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_end}) . ' ago)' : '-'); - return $msg; -} - -sub custom_event_calc { - my ($self, %options) = @_; - - $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; - $self->{result_values}->{subject} = $options{new_datas}->{$self->{instance} . '_subject'}; - $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; - $self->{result_values}->{items} = $options{new_datas}->{$self->{instance} . '_items'}; - $self->{result_values}->{start_date} = $options{new_datas}->{$self->{instance} . '_start_date'}; - $self->{result_values}->{since_start} = $options{new_datas}->{$self->{instance} . '_since_start'}; - $self->{result_values}->{end_date} = $options{new_datas}->{$self->{instance} . '_end_date'}; - $self->{result_values}->{since_end} = $options{new_datas}->{$self->{instance} . '_since_end'}; - return 0; -} - -sub prefix_global_output { - my ($self, %options) = @_; - - return "Number of events "; -} - -sub prefix_events_output { - my ($self, %options) = @_; - - return "Event '" . $options{instance_value}->{id} . "' with subject '" . $options{instance_value}->{subject} . "' "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, - { name => 'events', type => 1, cb_prefix_output => 'prefix_events_output' }, - ]; - - $self->{maps_counters}->{global} = [ - { label => 'active', set => { - key_values => [ { name => 'active' } ], - output_template => 'Active : %d', - perfdatas => [ - { label => 'active_events', value => 'active_absolute', template => '%d', - min => 0 }, - ], - } - }, - { label => 'completed', set => { - key_values => [ { name => 'completed' } ], - output_template => 'Completed : %d', - perfdatas => [ - { label => 'completed_events', value => 'completed_absolute', template => '%d', - min => 0 }, - ], - } - }, - { label => 'published', set => { - key_values => [ { name => 'published' } ], - output_template => 'Published : %d', - perfdatas => [ - { label => 'published_events', value => 'published_absolute', template => '%d', - min => 0 }, - ], - } - }, - ]; - $self->{maps_counters}->{events} = [ - { label => 'event', threshold => 0, set => { - key_values => [ { name => 'id' }, { name => 'subject' }, { name => 'status' }, { name => 'items' }, - { name => 'start_date' }, { name => 'since_start' }, { name => 'end_date' }, { name => 'since_end' } ], - closure_custom_calc => $self->can('custom_event_calc'), - closure_custom_output => $self->can('custom_event_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 => - { - "filter-status:s" => { name => 'filter_status', default => 'Active' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Active/ && %{items} > 0' }, - }); - - 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 $current_time = time(); - - my %status_hash; - my $events = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getAllObjects', extra_content => ''); - foreach my $event (@{$events->{'ns1:getAllObjectsResponse'}->{'getAllObjectsReturn'}->{'item'}}) { - my $status; - $status = $event->{statusCode}->{name}->{content} if (defined($event->{statusCode}->{name}->{content})); - $status_hash{'#' . $event->{statusCode}->{id}} = $event->{statusCode}->{name}->{content} if (defined($event->{statusCode}->{name}->{content})); - $status = $status_hash{$event->{statusCode}->{href}} if (!defined($event->{statusCode}->{name}->{content}) && defined($event->{statusCode}->{href})); - - next if (defined($self->{option_results}->{filter_status}) && $status !~ /$self->{option_results}->{filter_status}/); - - my $extra_content = ' - ' . $event->{id}->{content} . ' -'; - - my $ressources = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getImpactedResources', extra_content => $extra_content); - my $items = 0; - if (defined($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'})) { - $items = 1; - $items = scalar(@{$ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}}) if (ref($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}) eq 'ARRAY'); - } - - my $start_epoch = ''; - my $end_epoch = ''; - if (defined($event->{startDate}->{content}) && - $event->{startDate}->{content} =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.*)$/) { # 2018-10-18T15:36:54+00:00 - my $dt = DateTime->new( - year => $1, - month => $2, - day => $3, - hour => $4, - minute => $5, - second => $6, - time_zone => $7 - ); - $start_epoch = $dt->epoch; - } - if (defined($event->{endDate}->{content}) && - $event->{endDate}->{content} =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.*)$/) { # 2018-10-18T15:36:54+00:00 - my $dt = DateTime->new( - year => $1, - month => $2, - day => $3, - hour => $4, - minute => $5, - second => $6, - time_zone => $7 - ); - $end_epoch = $dt->epoch; - } - - $self->{events}->{$event->{id}->{content}} = { - id => $event->{id}->{content}, - subject => $event->{subject}->{content}, - status => $status, - items => $items, - start_date => (defined($event->{startDate}->{content})) ? $event->{startDate}->{content} : "-", - since_start => ($start_epoch ne '') ? $current_time - $start_epoch : "-", - end_date => (defined($event->{endDate}->{content})) ? $event->{endDate}->{content} : "-", - since_end => ($end_epoch ne '') ? $current_time - $end_epoch : "-", - }; - - $self->{global}->{lc($status)}++; - } -} - -1; - -__END__ - -=head1 MODE - -Check events status and number of impacted ressources - -=over 8 - -=item B<--filter-status> - -Filter events status (Default: 'Active') - -=item B<--warning-status> - -Set warning threshold for status (Default: '') -Can used special variables like: %{id}, %{subject}, %{status}, %{items}, -%{start_date}, %{since_start}, %{end_date}, %{since_end}. - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{status} =~ /Active/ && %{items} > 0'). -Can used special variables like: %{id}, %{subject}, %{status}, %{items}, -%{start_date}, %{since_start}, %{end_date}, %{since_end}. - -=item B<--warning-*> - -Threshold warning. -Can be: 'active', 'completed', 'published'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'active', 'completed', 'published'. - -=back - -=cut +# +# Copyright 2019 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 cloud::ibm::softlayer::mode::events; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +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]; }; + + 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, debug => 1); + } + + return $status; +} + +sub custom_event_output { + my ($self, %options) = @_; + + my $msg = sprintf("Status is '%s', Impacted items: %d, Start date: %s, End date: %s", + $self->{result_values}->{status}, + $self->{result_values}->{items}, + ($self->{result_values}->{start_date} ne "-") ? $self->{result_values}->{start_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_start}) . ' ago)' : '-', + ($self->{result_values}->{end_date} ne "-") ? $self->{result_values}->{end_date} . ' (' . centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since_end}) . ' ago)' : '-'); + return $msg; +} + +sub custom_event_calc { + my ($self, %options) = @_; + + $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; + $self->{result_values}->{subject} = $options{new_datas}->{$self->{instance} . '_subject'}; + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{items} = $options{new_datas}->{$self->{instance} . '_items'}; + $self->{result_values}->{start_date} = $options{new_datas}->{$self->{instance} . '_start_date'}; + $self->{result_values}->{since_start} = $options{new_datas}->{$self->{instance} . '_since_start'}; + $self->{result_values}->{end_date} = $options{new_datas}->{$self->{instance} . '_end_date'}; + $self->{result_values}->{since_end} = $options{new_datas}->{$self->{instance} . '_since_end'}; + return 0; +} + +sub prefix_global_output { + my ($self, %options) = @_; + + return "Number of events "; +} + +sub prefix_events_output { + my ($self, %options) = @_; + + return "Event '" . $options{instance_value}->{id} . "' with subject '" . $options{instance_value}->{subject} . "' "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, + { name => 'events', type => 1, cb_prefix_output => 'prefix_events_output' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'active', set => { + key_values => [ { name => 'active' } ], + output_template => 'Active : %d', + perfdatas => [ + { label => 'active_events', value => 'active_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'completed', set => { + key_values => [ { name => 'completed' } ], + output_template => 'Completed : %d', + perfdatas => [ + { label => 'completed_events', value => 'completed_absolute', template => '%d', + min => 0 }, + ], + } + }, + { label => 'published', set => { + key_values => [ { name => 'published' } ], + output_template => 'Published : %d', + perfdatas => [ + { label => 'published_events', value => 'published_absolute', template => '%d', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{events} = [ + { label => 'event', threshold => 0, set => { + key_values => [ { name => 'id' }, { name => 'subject' }, { name => 'status' }, { name => 'items' }, + { name => 'start_date' }, { name => 'since_start' }, { name => 'end_date' }, { name => 'since_end' } ], + closure_custom_calc => $self->can('custom_event_calc'), + closure_custom_output => $self->can('custom_event_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 => + { + "filter-status:s" => { name => 'filter_status', default => 'Active' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Active/ && %{items} > 0' }, + }); + + 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 $current_time = time(); + + my %status_hash; + my $events = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getAllObjects', extra_content => ''); + foreach my $event (@{$events->{'ns1:getAllObjectsResponse'}->{'getAllObjectsReturn'}->{'item'}}) { + my $status; + $status = $event->{statusCode}->{name}->{content} if (defined($event->{statusCode}->{name}->{content})); + $status_hash{'#' . $event->{statusCode}->{id}} = $event->{statusCode}->{name}->{content} if (defined($event->{statusCode}->{name}->{content})); + $status = $status_hash{$event->{statusCode}->{href}} if (!defined($event->{statusCode}->{name}->{content}) && defined($event->{statusCode}->{href})); + + next if (defined($self->{option_results}->{filter_status}) && $status !~ /$self->{option_results}->{filter_status}/); + + my $extra_content = ' + ' . $event->{id}->{content} . ' +'; + + my $ressources = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getImpactedResources', extra_content => $extra_content); + my $items = 0; + if (defined($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'})) { + $items = 1; + $items = scalar(@{$ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}}) if (ref($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}) eq 'ARRAY'); + } + + my $start_epoch = ''; + my $end_epoch = ''; + if (defined($event->{startDate}->{content}) && + $event->{startDate}->{content} =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.*)$/) { # 2018-10-18T15:36:54+00:00 + my $dt = DateTime->new( + year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + second => $6, + time_zone => $7 + ); + $start_epoch = $dt->epoch; + } + if (defined($event->{endDate}->{content}) && + $event->{endDate}->{content} =~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.*)$/) { # 2018-10-18T15:36:54+00:00 + my $dt = DateTime->new( + year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + second => $6, + time_zone => $7 + ); + $end_epoch = $dt->epoch; + } + + $self->{events}->{$event->{id}->{content}} = { + id => $event->{id}->{content}, + subject => $event->{subject}->{content}, + status => $status, + items => $items, + start_date => (defined($event->{startDate}->{content})) ? $event->{startDate}->{content} : "-", + since_start => ($start_epoch ne '') ? $current_time - $start_epoch : "-", + end_date => (defined($event->{endDate}->{content})) ? $event->{endDate}->{content} : "-", + since_end => ($end_epoch ne '') ? $current_time - $end_epoch : "-", + }; + + $self->{global}->{lc($status)}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check events status and number of impacted ressources + +=over 8 + +=item B<--filter-status> + +Filter events status (Default: 'Active') + +=item B<--warning-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{id}, %{subject}, %{status}, %{items}, +%{start_date}, %{since_start}, %{end_date}, %{since_end}. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /Active/ && %{items} > 0'). +Can used special variables like: %{id}, %{subject}, %{status}, %{items}, +%{start_date}, %{since_start}, %{end_date}, %{since_end}. + +=item B<--warning-*> + +Threshold warning. +Can be: 'active', 'completed', 'published'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'active', 'completed', 'published'. + +=back + +=cut diff --git a/cloud/ibm/softlayer/mode/opentickets.pm b/cloud/ibm/softlayer/mode/opentickets.pm index 1dfaf344f..6a95f087d 100644 --- a/cloud/ibm/softlayer/mode/opentickets.pm +++ b/cloud/ibm/softlayer/mode/opentickets.pm @@ -1,240 +1,240 @@ -# -# Copyright 2019 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 cloud::ibm::softlayer::mode::opentickets; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; -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]; }; - - 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_ticket_output { - my ($self, %options) = @_; - - my $msg = sprintf("Title: '%s', Group: '%s', Priority: %s, Create Date: %s (%s ago)", - $self->{result_values}->{title}, - $self->{result_values}->{group}, - $self->{result_values}->{priority}, - $self->{result_values}->{create_date}, - centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since})); - return $msg; -} - -sub custom_ticket_calc { - my ($self, %options) = @_; - - $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; - $self->{result_values}->{title} = $options{new_datas}->{$self->{instance} . '_title'}; - $self->{result_values}->{priority} = $options{new_datas}->{$self->{instance} . '_priority'}; - $self->{result_values}->{create_date} = $options{new_datas}->{$self->{instance} . '_create_date'}; - $self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_group'}; - $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; - return 0; -} - -sub prefix_tickets_output { - my ($self, %options) = @_; - - return "Ticket '" . $options{instance_value}->{id} . "' is open with "; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 0 }, - { name => 'tickets', type => 1, cb_prefix_output => 'prefix_tickets_output' }, - ]; - - $self->{maps_counters}->{global} = [ - { label => 'open', set => { - key_values => [ { name => 'open' } ], - output_template => 'Number of open tickets : %d', - perfdatas => [ - { label => 'open_tickets', value => 'open_absolute', template => '%d', - min => 0 }, - ], - } - }, - ]; - $self->{maps_counters}->{tickets} = [ - { label => 'ticket', threshold => 0, set => { - key_values => [ { name => 'id' }, { name => 'title' }, { name => 'priority' }, { name => 'create_date' }, - { name => 'group' }, { name => 'since' } ], - closure_custom_calc => $self->can('custom_ticket_calc'), - closure_custom_output => $self->can('custom_ticket_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 => - { - "ticket-group:s" => { name => 'ticket_group' }, - "warning-status:s" => { name => 'warning_status', default => '' }, - "critical-status:s" => { name => 'critical_status', 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_status', 'critical_status')) { - if (defined($self->{option_results}->{$_})) { - $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; - } - } -} - -sub manage_selection { - my ($self, %options) = @_; - - $self->{global}->{open} = 0; - $self->{tickets} = {}; - - my $group_id = ''; - my %groups_hash; - my $groups = $options{custom}->get_endpoint(service => 'SoftLayer_Ticket', method => 'getAllTicketGroups', extra_content => ''); - foreach my $group (@{$groups->{'ns1:getAllTicketGroupsResponse'}->{'getAllTicketGroupsReturn'}->{'item'}}) { - $groups_hash{$group->{id}->{content}} = $group->{name}->{content}; - - if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' && - $group->{name}->{content} =~ /^$self->{option_results}->{ticket_group}$/) { - $group_id = $group->{id}->{content}; - } - } - - if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' && $group_id eq '') { - $self->{output}->add_option_msg(short_msg => "Ticket group ID not found from API."); - $self->{output}->option_exit(); - } - - my $current_time = time(); - - my $tickets = $options{custom}->get_endpoint(service => 'SoftLayer_Account', method => 'getOpenTickets', extra_content => ''); - foreach my $ticket (@{$tickets->{'ns1:getOpenTicketsResponse'}->{'getOpenTicketsReturn'}->{'item'}}) { - next if (defined($group_id) && $group_id ne '' && $ticket->{groupId}->{content} ne $group_id); - - next if ($ticket->{createDate}->{content} !~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.*)$/); # 2018-10-18T15:36:54+00:00 - my $dt = DateTime->new( - year => $1, - month => $2, - day => $3, - hour => $4, - minute => $5, - second => $6, - time_zone => $7 - ); - - $self->{tickets}->{$ticket->{id}->{content}} = { - id => $ticket->{id}->{content}, - title => $ticket->{title}->{content}, - priority => $ticket->{priority}->{content}, - create_date => $ticket->{createDate}->{content}, - group => $groups_hash{$ticket->{groupId}->{content}}, - since => $current_time - $dt->epoch, - }; - - $self->{global}->{open}++; - } -} - -1; - -__END__ - -=head1 MODE - -Check if there is open tickets - -=over 8 - -=item B<--ticket-group> - -Name of the ticket group (Can be a regexp). - -=item B<--warning-status> - -Set warning threshold for status (Default: '') -Can used special variables like: %{id}, %{title}, -%{priority}, %{create_date}, %{group}, %{since}. - -=item B<--critical-status> - -Set critical threshold for status (Default: ''). -Can used special variables like: %{id}, %{title}, -%{priority}, %{create_date}, %{group}, %{since}. - -=item B<--warning-open> - -Threshold warning for open tickets. - -=item B<--critical-open> - -Threshold critical for open tickets. - -=back - -=cut +# +# Copyright 2019 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 cloud::ibm::softlayer::mode::opentickets; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; +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]; }; + + 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_ticket_output { + my ($self, %options) = @_; + + my $msg = sprintf("Title: '%s', Group: '%s', Priority: %s, Create Date: %s (%s ago)", + $self->{result_values}->{title}, + $self->{result_values}->{group}, + $self->{result_values}->{priority}, + $self->{result_values}->{create_date}, + centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since})); + return $msg; +} + +sub custom_ticket_calc { + my ($self, %options) = @_; + + $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; + $self->{result_values}->{title} = $options{new_datas}->{$self->{instance} . '_title'}; + $self->{result_values}->{priority} = $options{new_datas}->{$self->{instance} . '_priority'}; + $self->{result_values}->{create_date} = $options{new_datas}->{$self->{instance} . '_create_date'}; + $self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_group'}; + $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; + return 0; +} + +sub prefix_tickets_output { + my ($self, %options) = @_; + + return "Ticket '" . $options{instance_value}->{id} . "' is open with "; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 0 }, + { name => 'tickets', type => 1, cb_prefix_output => 'prefix_tickets_output' }, + ]; + + $self->{maps_counters}->{global} = [ + { label => 'open', set => { + key_values => [ { name => 'open' } ], + output_template => 'Number of open tickets : %d', + perfdatas => [ + { label => 'open_tickets', value => 'open_absolute', template => '%d', + min => 0 }, + ], + } + }, + ]; + $self->{maps_counters}->{tickets} = [ + { label => 'ticket', threshold => 0, set => { + key_values => [ { name => 'id' }, { name => 'title' }, { name => 'priority' }, { name => 'create_date' }, + { name => 'group' }, { name => 'since' } ], + closure_custom_calc => $self->can('custom_ticket_calc'), + closure_custom_output => $self->can('custom_ticket_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 => + { + "ticket-group:s" => { name => 'ticket_group' }, + "warning-status:s" => { name => 'warning_status', default => '' }, + "critical-status:s" => { name => 'critical_status', 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_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{global}->{open} = 0; + $self->{tickets} = {}; + + my $group_id = ''; + my %groups_hash; + my $groups = $options{custom}->get_endpoint(service => 'SoftLayer_Ticket', method => 'getAllTicketGroups', extra_content => ''); + foreach my $group (@{$groups->{'ns1:getAllTicketGroupsResponse'}->{'getAllTicketGroupsReturn'}->{'item'}}) { + $groups_hash{$group->{id}->{content}} = $group->{name}->{content}; + + if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' && + $group->{name}->{content} =~ /^$self->{option_results}->{ticket_group}$/) { + $group_id = $group->{id}->{content}; + } + } + + if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' && $group_id eq '') { + $self->{output}->add_option_msg(short_msg => "Ticket group ID not found from API."); + $self->{output}->option_exit(); + } + + my $current_time = time(); + + my $tickets = $options{custom}->get_endpoint(service => 'SoftLayer_Account', method => 'getOpenTickets', extra_content => ''); + foreach my $ticket (@{$tickets->{'ns1:getOpenTicketsResponse'}->{'getOpenTicketsReturn'}->{'item'}}) { + next if (defined($group_id) && $group_id ne '' && $ticket->{groupId}->{content} ne $group_id); + + next if ($ticket->{createDate}->{content} !~ /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(.*)$/); # 2018-10-18T15:36:54+00:00 + my $dt = DateTime->new( + year => $1, + month => $2, + day => $3, + hour => $4, + minute => $5, + second => $6, + time_zone => $7 + ); + + $self->{tickets}->{$ticket->{id}->{content}} = { + id => $ticket->{id}->{content}, + title => $ticket->{title}->{content}, + priority => $ticket->{priority}->{content}, + create_date => $ticket->{createDate}->{content}, + group => $groups_hash{$ticket->{groupId}->{content}}, + since => $current_time - $dt->epoch, + }; + + $self->{global}->{open}++; + } +} + +1; + +__END__ + +=head1 MODE + +Check if there is open tickets + +=over 8 + +=item B<--ticket-group> + +Name of the ticket group (Can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '') +Can used special variables like: %{id}, %{title}, +%{priority}, %{create_date}, %{group}, %{since}. + +=item B<--critical-status> + +Set critical threshold for status (Default: ''). +Can used special variables like: %{id}, %{title}, +%{priority}, %{create_date}, %{group}, %{since}. + +=item B<--warning-open> + +Threshold warning for open tickets. + +=item B<--critical-open> + +Threshold critical for open tickets. + +=back + +=cut diff --git a/network/barracuda/cloudgen/snmp/mode/components/fan.pm b/network/barracuda/cloudgen/snmp/mode/components/fan.pm index b3e0d54e3..2c9b0e296 100644 --- a/network/barracuda/cloudgen/snmp/mode/components/fan.pm +++ b/network/barracuda/cloudgen/snmp/mode/components/fan.pm @@ -1,74 +1,74 @@ -# -# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::fan; - -use strict; -use warnings; - -my $mapping = { - hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, - hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, - hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, -}; -my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; -} - -sub check { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking fans"); - $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; - return if ($self->check_filter(section => 'fan')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { - next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); - - next if ($self->check_filter(section => 'fan', instance => $instance)); - next if ($result->{hwSensorType} != 1); #Fans - $self->{components}->{fan}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' RPM", - $result->{hwSensorName}, $result->{hwSensorValue})); - - my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{hwSensorValue}); - 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->{hwSensorName}, $result->{hwSensorValue})); - } - - my $perf_label = $result->{hwSensorName}; - $perf_label =~ s/ /_/g; - $self->{output}->perfdata_add(label => 'speed_' . $perf_label, unit => 'rpm', - value => $result->{hwSensorValue}, - warning => $warn, - critical => $crit - ); - } -} - +# +# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::fan; + +use strict; +use warnings; + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking fans"); + $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; + return if ($self->check_filter(section => 'fan')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'fan', instance => $instance)); + next if ($result->{hwSensorType} != 1); #Fans + $self->{components}->{fan}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' RPM", + $result->{hwSensorName}, $result->{hwSensorValue})); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $result->{hwSensorValue}); + 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->{hwSensorName}, $result->{hwSensorValue})); + } + + my $perf_label = $result->{hwSensorName}; + $perf_label =~ s/ /_/g; + $self->{output}->perfdata_add(label => 'speed_' . $perf_label, unit => 'rpm', + value => $result->{hwSensorValue}, + warning => $warn, + critical => $crit + ); + } +} + 1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/components/psu.pm b/network/barracuda/cloudgen/snmp/mode/components/psu.pm index a28aaf8a9..3f398145c 100644 --- a/network/barracuda/cloudgen/snmp/mode/components/psu.pm +++ b/network/barracuda/cloudgen/snmp/mode/components/psu.pm @@ -1,72 +1,72 @@ -# -# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::psu; - -use strict; -use warnings; - -my %map_status = ( - 0 => 'critical', - 1 => 'ok', - 2 => 'critical', -); - -my $mapping = { - hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, - hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, - hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3', map => \%map_status }, -}; -my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; -} - -sub check { - my ($self) = @_; - - $self->{output}->output_add(long_msg => "Checking power supplies"); - $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; - return if ($self->check_filter(section => 'psu')); - - foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { - next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); - - next if ($self->check_filter(section => 'psu', instance => $instance)); - next if ($result->{hwSensorType} != 3); #PSU - $self->{components}->{psu}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", - $result->{hwSensorName}, $result->{hwSensorValue})); - - my $exit = $self->get_severity(label => 'psu', section => 'psu', value => $result->{hwSensorValue}); - 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'", $result->{hwSensorName}, $result->{hwSensorValue})); - } - } -} - +# +# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::psu; + +use strict; +use warnings; + +my %map_status = ( + 0 => 'critical', + 1 => 'ok', + 2 => 'critical', +); + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3', map => \%map_status }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking power supplies"); + $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; + return if ($self->check_filter(section => 'psu')); + + foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'psu', instance => $instance)); + next if ($result->{hwSensorType} != 3); #PSU + $self->{components}->{psu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", + $result->{hwSensorName}, $result->{hwSensorValue})); + + my $exit = $self->get_severity(label => 'psu', section => 'psu', value => $result->{hwSensorValue}); + 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'", $result->{hwSensorName}, $result->{hwSensorValue})); + } + } +} + 1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/components/temperature.pm b/network/barracuda/cloudgen/snmp/mode/components/temperature.pm index a591ba548..60b8b7924 100644 --- a/network/barracuda/cloudgen/snmp/mode/components/temperature.pm +++ b/network/barracuda/cloudgen/snmp/mode/components/temperature.pm @@ -1,74 +1,74 @@ -# -# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::temperature; - -use strict; -use warnings; - -my $mapping = { - hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, - hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, - hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, -}; -my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; -} - -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_HwSensorsEntry}})) { - next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); - - next if ($self->check_filter(section => 'temperature', instance => $instance)); - next if ($result->{hwSensorType} != 2); #Temperatures - $self->{components}->{temperature}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' celsius degrees", - $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); - - my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{hwSensorValue} / 1000); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Temperature '%s' is '%s' celsius degrees", $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); - } - - my $perf_label = $result->{hwSensorName}; - $perf_label =~ s/ /_/g; - $self->{output}->perfdata_add(label => 'temperature_' . $perf_label, unit => 'C', - value => $result->{hwSensorValue} / 1000, - warning => $warn, - critical => $crit - ); - } -} - +# +# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::temperature; + +use strict; +use warnings; + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +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_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'temperature', instance => $instance)); + next if ($result->{hwSensorType} != 2); #Temperatures + $self->{components}->{temperature}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' celsius degrees", + $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $result->{hwSensorValue} / 1000); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Temperature '%s' is '%s' celsius degrees", $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); + } + + my $perf_label = $result->{hwSensorName}; + $perf_label =~ s/ /_/g; + $self->{output}->perfdata_add(label => 'temperature_' . $perf_label, unit => 'C', + value => $result->{hwSensorValue} / 1000, + warning => $warn, + critical => $crit + ); + } +} + 1; \ No newline at end of file diff --git a/network/barracuda/cloudgen/snmp/mode/components/voltage.pm b/network/barracuda/cloudgen/snmp/mode/components/voltage.pm index a56e40711..3262e6422 100644 --- a/network/barracuda/cloudgen/snmp/mode/components/voltage.pm +++ b/network/barracuda/cloudgen/snmp/mode/components/voltage.pm @@ -1,74 +1,74 @@ -# -# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::voltage; - -use strict; -use warnings; - -my $mapping = { - hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, - hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, - hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, -}; -my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; - -sub load { - my ($self) = @_; - - push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; -} - -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_HwSensorsEntry}})) { - next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); - - next if ($self->check_filter(section => 'voltage', instance => $instance)); - next if ($result->{hwSensorType} != 0); #Voltages - $self->{components}->{voltage}->{total}++; - - $self->{output}->output_add(long_msg => sprintf("Voltage '%s' is '%s' mV", - $result->{hwSensorName}, $result->{hwSensorValue})); - - my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{hwSensorValue}); - if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Voltage '%s' is '%s' mV", $result->{hwSensorName}, $result->{hwSensorValue})); - } - - my $perf_label = $result->{hwSensorName}; - $perf_label =~ s/ /_/g; - $self->{output}->perfdata_add(label => 'voltage_' . $perf_label, unit => 'mV', - value => $result->{hwSensorValue}, - warning => $warn, - critical => $crit - ); - } -} - +# +# Copyright 2019 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::barracuda::cloudgen::snmp::mode::components::voltage; + +use strict; +use warnings; + +my $mapping = { + hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, + hwSensorType => { oid => '.1.3.6.1.4.1.10704.1.4.1.2' }, + hwSensorValue => { oid => '.1.3.6.1.4.1.10704.1.4.1.3' }, +}; +my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1'; + +sub load { + my ($self) = @_; + + push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; +} + +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_HwSensorsEntry}})) { + next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); + + next if ($self->check_filter(section => 'voltage', instance => $instance)); + next if ($result->{hwSensorType} != 0); #Voltages + $self->{components}->{voltage}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("Voltage '%s' is '%s' mV", + $result->{hwSensorName}, $result->{hwSensorValue})); + + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $result->{hwSensorValue}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Voltage '%s' is '%s' mV", $result->{hwSensorName}, $result->{hwSensorValue})); + } + + my $perf_label = $result->{hwSensorName}; + $perf_label =~ s/ /_/g; + $self->{output}->perfdata_add(label => 'voltage_' . $perf_label, unit => 'mV', + value => $result->{hwSensorValue}, + warning => $warn, + critical => $crit + ); + } +} + 1; \ No newline at end of file diff --git a/network/juniper/common/screenos/snmp/mode/sessions.pm b/network/juniper/common/screenos/snmp/mode/sessions.pm index 9f6edd6ca..2ce97e010 100644 --- a/network/juniper/common/screenos/snmp/mode/sessions.pm +++ b/network/juniper/common/screenos/snmp/mode/sessions.pm @@ -100,6 +100,8 @@ sub manage_selection { __END__ +=head1 MODE + Check Juniper sessions usage and failed sessions (NETSCREEN-RESOURCE-MIB). =over 8 diff --git a/storage/ibm/fs900/snmp/mode/arraysstatus.pm b/storage/ibm/fs900/snmp/mode/arraysstatus.pm index 4209e150f..fae9e3578 100644 --- a/storage/ibm/fs900/snmp/mode/arraysstatus.pm +++ b/storage/ibm/fs900/snmp/mode/arraysstatus.pm @@ -1,172 +1,172 @@ -# -# Copyright 2019 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::ibm::fs900::snmp::mode::arraysstatus; - -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 = sprintf("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} . '_arrayStatus'}; - return 0; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays metrics are ok", message_separator => ' - ' } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'status', threshold => 0, set => { - key_values => [ { name => 'arrayStatus' } ], - 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 => 'vdisk-count', set => { - key_values => [ { name => 'arrayVDiskCount' }, { name => 'arrayId' } ], - output_template => 'VDisk count: %s', - perfdatas => [ - { label => 'vdisk_count', value => 'arrayVDiskCount_absolute', template => '%s', label_extra_instance => 1, - instance_use => 'arrayId_absolute', min => 0 }, - ], - } - }, - ]; -} - -sub prefix_output { - my ($self, %options) = @_; - - return "Array '" . $options{instance_value}->{arrayId} . "' "; -} - -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 => '%{status} =~ /degraded/i' }, - }); - - return $self; -} - -my $mapping = { - arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, - arrayStatus => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.3' }, - arrayVDiskCount => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.9' }, -}; - -my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1'; - -sub manage_selection { - my ($self, %options) = @_; - - my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, - nothing_quit => 1); - - $self->{global} = {}; - - foreach my $oid (keys %{$snmp_result}) { - next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - - $self->{global}->{$result->{arrayId}} = $result; - } -} - -1; - -__END__ - -=head1 MODE - -Check arrays status. - -=over 8 - -=item B<--warning-status> - -Set warning threshold for status. -'status' can be: 'online', 'offline', 'excluded', 'degraded'. - -=item B<--critical-status> - -Set critical threshold for status (Default: '%{status} =~ /degraded/i'). -'status' can be: 'online', 'offline', 'excluded', 'degraded'. - -=item B<--warning-vdisk-count> - -Threshold warning for VDisks count. - -=item B<--critical-vdisk-count> - -Threshold critical for VDisks count. - -=back - -=cut +# +# Copyright 2019 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::ibm::fs900::snmp::mode::arraysstatus; + +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 = sprintf("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} . '_arrayStatus'}; + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays metrics are ok", message_separator => ' - ' } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'arrayStatus' } ], + 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 => 'vdisk-count', set => { + key_values => [ { name => 'arrayVDiskCount' }, { name => 'arrayId' } ], + output_template => 'VDisk count: %s', + perfdatas => [ + { label => 'vdisk_count', value => 'arrayVDiskCount_absolute', template => '%s', label_extra_instance => 1, + instance_use => 'arrayId_absolute', min => 0 }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Array '" . $options{instance_value}->{arrayId} . "' "; +} + +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 => '%{status} =~ /degraded/i' }, + }); + + return $self; +} + +my $mapping = { + arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, + arrayStatus => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.3' }, + arrayVDiskCount => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.9' }, +}; + +my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, + nothing_quit => 1); + + $self->{global} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{global}->{$result->{arrayId}} = $result; + } +} + +1; + +__END__ + +=head1 MODE + +Check arrays status. + +=over 8 + +=item B<--warning-status> + +Set warning threshold for status. +'status' can be: 'online', 'offline', 'excluded', 'degraded'. + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /degraded/i'). +'status' can be: 'online', 'offline', 'excluded', 'degraded'. + +=item B<--warning-vdisk-count> + +Threshold warning for VDisks count. + +=item B<--critical-vdisk-count> + +Threshold critical for VDisks count. + +=back + +=cut diff --git a/storage/ibm/fs900/snmp/mode/arraysusage.pm b/storage/ibm/fs900/snmp/mode/arraysusage.pm index d6d272624..ea0f6e1ea 100644 --- a/storage/ibm/fs900/snmp/mode/arraysusage.pm +++ b/storage/ibm/fs900/snmp/mode/arraysusage.pm @@ -1,183 +1,183 @@ -# -# Copyright 2019 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::ibm::fs900::snmp::mode::arraysusage; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub custom_usage_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => "used" . $extra_label, - unit => 'B', - value => $self->{result_values}->{used}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-usage'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-usage'), - min => 0, - max => $self->{result_values}->{total}, - ); -} - -sub custom_usage_threshold { - my ($self, %options) = @_; - - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used_prct}, - threshold => [ { label => 'critical-usage', exit_litteral => 'critical' }, - { label => 'warning-usage', exit_litteral => 'warning' } ]); - return $exit; -} - -sub custom_usage_output { - my ($self, %options) = @_; - - my ($total, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); - my ($used, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); - my ($free, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); - - my $msg = sprintf("Usage Total: %s %s, Used: %s %s (%.2f%%), Free: %s %s (%.2f%%)", $total, $total_unit, $used, $used_unit, $self->{result_values}->{used_prct}, $free, $free_unit, $self->{result_values}->{free_prct}); - return $msg; -} - -sub custom_usage_calc { - my ($self, %options) = @_; - - ($self->{result_values}->{total}, $self->{result_values}->{total_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacity'})); - ($self->{result_values}->{used}, $self->{result_values}->{used_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacityUsed'})); - ($self->{result_values}->{free}, $self->{result_values}->{free_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacityFree'})); - - $self->{result_values}->{total} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{total}, unit => $self->{result_values}->{total_unit}); - $self->{result_values}->{used} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{used}, unit => $self->{result_values}->{used_unit}); - $self->{result_values}->{free} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{free}, unit => $self->{result_values}->{free_unit}); - - $self->{result_values}->{used_prct} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; - $self->{result_values}->{free_prct} = 100 - $self->{result_values}->{used_prct}; - - return 0; -} - -sub change_to_bytes { - my ($self, %options) = @_; - - my $value = ''; - - if ($options{unit} =~ /KiB*/i) { - $value = $options{value} * 1024; - } elsif ($options{unit} =~ /MiB*/i) { - $value = $options{value} * 1024 * 1024; - } elsif ($options{unit} =~ /GiB*/i) { - $value = $options{value} * 1024 * 1024 * 1024; - } elsif ($options{unit} =~ /TiB*/i) { - $value = $options{value} * 1024 * 1024 * 1024 * 1024; - } - - return $value -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays usage are ok" } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'usage', set => { - key_values => [ { name => 'arrayCapacity' }, { name => 'arrayCapacityUsed' }, { name => 'arrayCapacityFree' }, { name => 'arrayId' } ], - 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_output { - my ($self, %options) = @_; - - return "Array '" . $options{instance_value}->{arrayId} . "' "; -} - -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 = { - arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, - arrayCapacity => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.4' }, - arrayCapacityUsed => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.5' }, - arrayCapacityFree => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.6' }, -}; - -my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1'; - -sub manage_selection { - my ($self, %options) = @_; - - my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, - nothing_quit => 1); - - $self->{global} = {}; - - foreach my $oid (keys %{$snmp_result}) { - next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - - $self->{global}->{$result->{arrayId}} = $result; - } -} - -1; - -__END__ - -=head1 MODE - -Check arrays usage. - -=over 8 - -=item B<--warning-usage> - -Threshold warning. - -=item B<--critical-usage> - -Threshold critical. - -=back - -=cut +# +# Copyright 2019 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::ibm::fs900::snmp::mode::arraysusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + + $self->{output}->perfdata_add(label => "used" . $extra_label, + unit => 'B', + value => $self->{result_values}->{used}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-usage'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-usage'), + min => 0, + max => $self->{result_values}->{total}, + ); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used_prct}, + threshold => [ { label => 'critical-usage', exit_litteral => 'critical' }, + { label => 'warning-usage', exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($used, $used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($free, $free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + + my $msg = sprintf("Usage Total: %s %s, Used: %s %s (%.2f%%), Free: %s %s (%.2f%%)", $total, $total_unit, $used, $used_unit, $self->{result_values}->{used_prct}, $free, $free_unit, $self->{result_values}->{free_prct}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + ($self->{result_values}->{total}, $self->{result_values}->{total_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacity'})); + ($self->{result_values}->{used}, $self->{result_values}->{used_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacityUsed'})); + ($self->{result_values}->{free}, $self->{result_values}->{free_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacityFree'})); + + $self->{result_values}->{total} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{total}, unit => $self->{result_values}->{total_unit}); + $self->{result_values}->{used} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{used}, unit => $self->{result_values}->{used_unit}); + $self->{result_values}->{free} = storage::ibm::fs900::snmp::mode::arraysusage->change_to_bytes(value => $self->{result_values}->{free}, unit => $self->{result_values}->{free_unit}); + + $self->{result_values}->{used_prct} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{free_prct} = 100 - $self->{result_values}->{used_prct}; + + return 0; +} + +sub change_to_bytes { + my ($self, %options) = @_; + + my $value = ''; + + if ($options{unit} =~ /KiB*/i) { + $value = $options{value} * 1024; + } elsif ($options{unit} =~ /MiB*/i) { + $value = $options{value} * 1024 * 1024; + } elsif ($options{unit} =~ /GiB*/i) { + $value = $options{value} * 1024 * 1024 * 1024; + } elsif ($options{unit} =~ /TiB*/i) { + $value = $options{value} * 1024 * 1024 * 1024 * 1024; + } + + return $value +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays usage are ok" } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'usage', set => { + key_values => [ { name => 'arrayCapacity' }, { name => 'arrayCapacityUsed' }, { name => 'arrayCapacityFree' }, { name => 'arrayId' } ], + 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_output { + my ($self, %options) = @_; + + return "Array '" . $options{instance_value}->{arrayId} . "' "; +} + +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 = { + arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, + arrayCapacity => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.4' }, + arrayCapacityUsed => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.5' }, + arrayCapacityFree => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.6' }, +}; + +my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, + nothing_quit => 1); + + $self->{global} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{global}->{$result->{arrayId}} = $result; + } +} + +1; + +__END__ + +=head1 MODE + +Check arrays usage. + +=over 8 + +=item B<--warning-usage> + +Threshold warning. + +=item B<--critical-usage> + +Threshold critical. + +=back + +=cut diff --git a/storage/ibm/fs900/snmp/mode/fcusage.pm b/storage/ibm/fs900/snmp/mode/fcusage.pm index d9e3e5e4d..8a88a67f1 100644 --- a/storage/ibm/fs900/snmp/mode/fcusage.pm +++ b/storage/ibm/fs900/snmp/mode/fcusage.pm @@ -1,205 +1,205 @@ -# -# Copyright 2019 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::ibm::fs900::snmp::mode::fcusage; - -use base qw(centreon::plugins::templates::counter); - -use strict; -use warnings; - -sub custom_bandwidth_perfdata { - my ($self, %options) = @_; - - my $extra_label = ''; - $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); - - $self->{output}->perfdata_add(label => lc($self->{result_values}->{type}) . "_bandwidth" . $extra_label, - unit => 'B/s', - value => $self->{result_values}->{bandwidth}, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{type}) . '-bandwidth'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth'), - ); -} - -sub custom_bandwidth_threshold { - my ($self, %options) = @_; - - my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{bandwidth}, - threshold => [ { label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'critical' }, - { label => 'warning-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'warning' } ]); - return $exit; -} - -sub custom_bandwidth_output { - my ($self, %options) = @_; - - my ($bandwidth, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{bandwidth}); - - my $msg = sprintf("%s bandwidth: %s %s/s", $self->{result_values}->{type}, $bandwidth, $unit); - return $msg; -} - -sub custom_bandwidth_calc { - my ($self, %options) = @_; - - $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_fcObject'}; - $self->{result_values}->{type} = $options{extra_options}->{type}; - $self->{result_values}->{bandwidth} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{bandwidth}} *1024 * 1024; - - return 0; -} - -sub set_counters { - my ($self, %options) = @_; - - $self->{maps_counters_type} = [ - { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All fibre channels read/write metrics are ok", skipped_code => { -10 => 1 } } - ]; - - $self->{maps_counters}->{global} = [ - { label => 'read-bandwidth', set => { - key_values => [ { name => 'fcReadBW' }, { name => 'fcObject' } ], - closure_custom_calc => $self->can('custom_bandwidth_calc'), - closure_custom_calc_extra_options => { type => 'Read', bandwidth => 'fcReadBW' }, - closure_custom_output => $self->can('custom_bandwidth_output'), - closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'), - closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'), - } - }, - { label => 'write-bandwidth', set => { - key_values => [ { name => 'fcWriteBW' }, { name => 'fcObject' } ], - closure_custom_calc => $self->can('custom_bandwidth_calc'), - closure_custom_calc_extra_options => { type => 'Write', bandwidth => 'fcWriteBW' }, - closure_custom_output => $self->can('custom_bandwidth_output'), - closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'), - closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'), - } - }, - { label => 'read-iops', set => { - key_values => [ { name => 'fcReadIOPS' }, { name => 'fcObject' } ], - output_template => 'Read IOPS: %s iops', - perfdatas => [ - { label => 'read_iops', value => 'fcReadIOPS_absolute', template => '%s', label_extra_instance => 1, - instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, - ], - } - }, - { label => 'write-iops', set => { - key_values => [ { name => 'fcWriteIOPS' }, { name => 'fcObject' } ], - output_template => 'Write IOPS: %s iops', - perfdatas => [ - { label => 'write_iops', value => 'fcWriteIOPS_absolute', template => '%s', label_extra_instance => 1, - instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, - ], - } - }, - { label => 'read-queue-depth', set => { - key_values => [ { name => 'fcReadQueueDepth' }, { name => 'fcObject' } ], - output_template => 'Read queue depth: %s', - perfdatas => [ - { label => 'read_queue_depth', value => 'fcReadQueueDepth_absolute', template => '%s', label_extra_instance => 1, - instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, - ], - } - }, - { label => 'write-queue-depth', set => { - key_values => [ { name => 'fcWriteQueueDepth' }, { name => 'fcObject' } ], - output_template => 'Write queue depth: %s', - perfdatas => [ - { label => 'write_queue_depth', value => 'fcWriteQueueDepth_absolute', template => '%s', label_extra_instance => 1, - instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, - ], - } - }, - ]; -} - -sub prefix_output { - my ($self, %options) = @_; - - return "Fibre channel '" . $options{instance_value}->{fcObject} . "' "; -} - -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 = { - fcObject => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.2' }, - fcReadBW => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.13' }, #MB/s - fcWriteBW => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.14' }, #MB/s - fcReadIOPS => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.16' }, - fcWriteIOPS => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.17' }, - fcReadQueueDepth => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.19' }, - fcWriteQueueDepth => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.20' }, -}; - -my $oid_fcTableEntry = '.1.3.6.1.4.1.2.6.255.1.1.2.1.1'; - -sub manage_selection { - my ($self, %options) = @_; - - my $snmp_result = $options{snmp}->get_table(oid => $oid_fcTableEntry, - nothing_quit => 1); - - $self->{global} = {}; - - foreach my $oid (keys %{$snmp_result}) { - next if ($oid !~ /^$mapping->{fcObject}->{oid}\.(.*)$/); - my $instance = $1; - my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); - - $self->{global}->{$result->{fcObject}} = $result; - } -} - -1; - -__END__ - -=head1 MODE - -Check fibre channels usage. - -=over 8 - -=item B<--warning-*> - -Threshold warning. -Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'. - -=item B<--critical-*> - -Threshold critical. -Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'. - -=back - -=cut +# +# Copyright 2019 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::ibm::fs900::snmp::mode::fcusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +sub custom_bandwidth_perfdata { + my ($self, %options) = @_; + + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + + $self->{output}->perfdata_add(label => lc($self->{result_values}->{type}) . "_bandwidth" . $extra_label, + unit => 'B/s', + value => $self->{result_values}->{bandwidth}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{type}) . '-bandwidth'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth'), + ); +} + +sub custom_bandwidth_threshold { + my ($self, %options) = @_; + + my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{bandwidth}, + threshold => [ { label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'critical' }, + { label => 'warning-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_bandwidth_output { + my ($self, %options) = @_; + + my ($bandwidth, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{bandwidth}); + + my $msg = sprintf("%s bandwidth: %s %s/s", $self->{result_values}->{type}, $bandwidth, $unit); + return $msg; +} + +sub custom_bandwidth_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_fcObject'}; + $self->{result_values}->{type} = $options{extra_options}->{type}; + $self->{result_values}->{bandwidth} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{bandwidth}} *1024 * 1024; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All fibre channels read/write metrics are ok", skipped_code => { -10 => 1 } } + ]; + + $self->{maps_counters}->{global} = [ + { label => 'read-bandwidth', set => { + key_values => [ { name => 'fcReadBW' }, { name => 'fcObject' } ], + closure_custom_calc => $self->can('custom_bandwidth_calc'), + closure_custom_calc_extra_options => { type => 'Read', bandwidth => 'fcReadBW' }, + closure_custom_output => $self->can('custom_bandwidth_output'), + closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'), + closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'), + } + }, + { label => 'write-bandwidth', set => { + key_values => [ { name => 'fcWriteBW' }, { name => 'fcObject' } ], + closure_custom_calc => $self->can('custom_bandwidth_calc'), + closure_custom_calc_extra_options => { type => 'Write', bandwidth => 'fcWriteBW' }, + closure_custom_output => $self->can('custom_bandwidth_output'), + closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'), + closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'), + } + }, + { label => 'read-iops', set => { + key_values => [ { name => 'fcReadIOPS' }, { name => 'fcObject' } ], + output_template => 'Read IOPS: %s iops', + perfdatas => [ + { label => 'read_iops', value => 'fcReadIOPS_absolute', template => '%s', label_extra_instance => 1, + instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, + ], + } + }, + { label => 'write-iops', set => { + key_values => [ { name => 'fcWriteIOPS' }, { name => 'fcObject' } ], + output_template => 'Write IOPS: %s iops', + perfdatas => [ + { label => 'write_iops', value => 'fcWriteIOPS_absolute', template => '%s', label_extra_instance => 1, + instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, + ], + } + }, + { label => 'read-queue-depth', set => { + key_values => [ { name => 'fcReadQueueDepth' }, { name => 'fcObject' } ], + output_template => 'Read queue depth: %s', + perfdatas => [ + { label => 'read_queue_depth', value => 'fcReadQueueDepth_absolute', template => '%s', label_extra_instance => 1, + instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, + ], + } + }, + { label => 'write-queue-depth', set => { + key_values => [ { name => 'fcWriteQueueDepth' }, { name => 'fcObject' } ], + output_template => 'Write queue depth: %s', + perfdatas => [ + { label => 'write_queue_depth', value => 'fcWriteQueueDepth_absolute', template => '%s', label_extra_instance => 1, + instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, + ], + } + }, + ]; +} + +sub prefix_output { + my ($self, %options) = @_; + + return "Fibre channel '" . $options{instance_value}->{fcObject} . "' "; +} + +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 = { + fcObject => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.2' }, + fcReadBW => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.13' }, #MB/s + fcWriteBW => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.14' }, #MB/s + fcReadIOPS => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.16' }, + fcWriteIOPS => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.17' }, + fcReadQueueDepth => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.19' }, + fcWriteQueueDepth => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.20' }, +}; + +my $oid_fcTableEntry = '.1.3.6.1.4.1.2.6.255.1.1.2.1.1'; + +sub manage_selection { + my ($self, %options) = @_; + + my $snmp_result = $options{snmp}->get_table(oid => $oid_fcTableEntry, + nothing_quit => 1); + + $self->{global} = {}; + + foreach my $oid (keys %{$snmp_result}) { + next if ($oid !~ /^$mapping->{fcObject}->{oid}\.(.*)$/); + my $instance = $1; + my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); + + $self->{global}->{$result->{fcObject}} = $result; + } +} + +1; + +__END__ + +=head1 MODE + +Check fibre channels usage. + +=over 8 + +=item B<--warning-*> + +Threshold warning. +Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'. + +=back + +=cut