Fix some windows carriage return and pod doc (#1330)

This commit is contained in:
garnier-quentin 2019-01-11 16:56:18 +01:00
parent 19bff42565
commit c9bf84d279
16 changed files with 2211 additions and 2203 deletions

View File

@ -233,6 +233,8 @@ sub manage_selection {
1; 1;
__END__
=head1 MODE =head1 MODE
Check storage usage. Check storage usage.

View File

@ -53,6 +53,8 @@ sub run {
1; 1;
__END__
=head1 MODE =head1 MODE
Get Proxmox VE Version Get Proxmox VE Version

View File

@ -315,6 +315,8 @@ sub manage_selection {
1; 1;
__END__
=head1 MODE =head1 MODE
Check VM usage on Proxmox VE Cluster. Check VM usage on Proxmox VE Cluster.

View File

@ -1,431 +1,431 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package apps::selenium::mode::scenariokatalon; package apps::selenium::mode::scenariokatalon;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use XML::XPath; use XML::XPath;
use WWW::Selenium; use WWW::Selenium;
my $instance_mode; my $instance_mode;
my %handlers = (ALRM => {} ); my %handlers = (ALRM => {} );
sub custom_count_perfdata { sub custom_count_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{output}->perfdata_add(label => $self->{result_values}->{label}, $self->{output}->perfdata_add(label => $self->{result_values}->{label},
value => $self->{result_values}->{value}, 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), 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), 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}); min => 0, max => $self->{result_values}->{total});
$self->{output}->perfdata_add(label => $self->{result_values}->{label} . '_prct', $self->{output}->perfdata_add(label => $self->{result_values}->{label} . '_prct',
value => sprintf('%.2f', $self->{result_values}->{value_prct}), value => sprintf('%.2f', $self->{result_values}->{value_prct}),
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{result_values}->{label} . '-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'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{result_values}->{label} . '-prct'),
min => 0, max => 100, unit => '%'); min => 0, max => 100, unit => '%');
} }
sub custom_count_threshold { sub custom_count_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit1 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value}, my $exit1 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value},
threshold => [ { label => 'critical-' . $self->{result_values}->{label}, exit_litteral => 'critical' }, threshold => [ { label => 'critical-' . $self->{result_values}->{label}, exit_litteral => 'critical' },
{ label => 'warning-' . $self->{result_values}->{label}, exit_litteral => 'warning' } ]); { label => 'warning-' . $self->{result_values}->{label}, exit_litteral => 'warning' } ]);
my $exit2 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value} . '_prct', my $exit2 = $self->{perfdata}->threshold_check(value => $self->{result_values}->{value} . '_prct',
threshold => [ { label => 'critical-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'critical' }, threshold => [ { label => 'critical-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'critical' },
{ label => 'warning-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'warning' } ]); { label => 'warning-' . $self->{result_values}->{label} . '-prct', exit_litteral => 'warning' } ]);
my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]); my $exit = $self->{output}->get_most_critical(status => [ $exit1, $exit2 ]);
return $exit; return $exit;
} }
sub custom_count_output { sub custom_count_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("%s steps : %s/%s (%.2f%%)", ucfirst($self->{result_values}->{label}), 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}); $self->{result_values}->{value}, $self->{result_values}->{total}, $self->{result_values}->{value_prct});
return $msg; return $msg;
} }
sub custom_count_calc { sub custom_count_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{label} = $options{extra_options}->{label}; $self->{result_values}->{label} = $options{extra_options}->{label};
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_' . $self->{result_values}->{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}->{total} = $options{new_datas}->{$self->{instance} . '_total'};
$self->{result_values}->{value_prct} = $self->{result_values}->{value} / $self->{result_values}->{total} * 100; $self->{result_values}->{value_prct} = $self->{result_values}->{value} / $self->{result_values}->{total} * 100;
return 0; return 0;
} }
sub custom_state_threshold { sub custom_state_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $status = 'ok'; my $status = 'ok';
my $message; my $message;
eval { eval {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_state}) && $instance_mode->{option_results}->{critical_state} ne '' && if (defined($instance_mode->{option_results}->{critical_state}) && $instance_mode->{option_results}->{critical_state} ne '' &&
eval "$instance_mode->{option_results}->{critical_state}") { eval "$instance_mode->{option_results}->{critical_state}") {
$status = 'critical'; $status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_state}) && $instance_mode->{option_results}->{warning_state} ne '' && } elsif (defined($instance_mode->{option_results}->{warning_state}) && $instance_mode->{option_results}->{warning_state} ne '' &&
eval "$instance_mode->{option_results}->{warning_state}") { eval "$instance_mode->{option_results}->{warning_state}") {
$status = 'warning'; $status = 'warning';
} }
}; };
if (defined($message)) { if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message); $self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
} }
return $status; return $status;
} }
sub custom_state_output { sub custom_state_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = "state is '" . $self->{result_values}->{state} . "'"; my $msg = "state is '" . $self->{result_values}->{state} . "'";
$msg .= " : " . $self->{result_values}->{comment} if (defined($self->{result_values}->{comment}) && $self->{result_values}->{comment} ne ''); $msg .= " : " . $self->{result_values}->{comment} if (defined($self->{result_values}->{comment}) && $self->{result_values}->{comment} ne '');
return $msg; return $msg;
} }
sub custom_state_calc { sub custom_state_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'};
$self->{result_values}->{command} = $options{new_datas}->{$self->{instance} . '_command'}; $self->{result_values}->{command} = $options{new_datas}->{$self->{instance} . '_command'};
$self->{result_values}->{target} = $options{new_datas}->{$self->{instance} . '_target'}; $self->{result_values}->{target} = $options{new_datas}->{$self->{instance} . '_target'};
$self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'}; $self->{result_values}->{value} = $options{new_datas}->{$self->{instance} . '_value'};
$self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'}; $self->{result_values}->{state} = $options{new_datas}->{$self->{instance} . '_state'};
$self->{result_values}->{comment} = $options{new_datas}->{$self->{instance} . '_comment'}; $self->{result_values}->{comment} = $options{new_datas}->{$self->{instance} . '_comment'};
return 0; return 0;
} }
sub prefix_output { sub prefix_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = "Step '" . $options{instance_value}->{display} . "' [command: " . $options{instance_value}->{command}; 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 .= ", 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 .= ", value: " . $options{instance_value}->{value} if (defined($options{instance_value}->{value}) && $options{instance_value}->{value} ne '');
$msg .= "] "; $msg .= "] ";
return $msg; return $msg;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
{ name => 'steps', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All steps state are ok' }, { name => 'steps', type => 1, cb_prefix_output => 'prefix_output', message_multiple => 'All steps state are ok' },
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'successful', set => { { label => 'successful', set => {
key_values => [ { name => 'successful' }, { name => 'total' } ], key_values => [ { name => 'successful' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_count_calc'), closure_custom_calc => $self->can('custom_count_calc'),
closure_custom_calc_extra_options => { label => 'successful' }, closure_custom_calc_extra_options => { label => 'successful' },
closure_custom_output => $self->can('custom_count_output'), closure_custom_output => $self->can('custom_count_output'),
closure_custom_perfdata => $self->can('custom_count_perfdata'), closure_custom_perfdata => $self->can('custom_count_perfdata'),
closure_custom_threshold_check => $self->can('custom_count_threshold'), closure_custom_threshold_check => $self->can('custom_count_threshold'),
} }
}, },
{ label => 'failed', set => { { label => 'failed', set => {
key_values => [ { name => 'failed' }, { name => 'total' } ], key_values => [ { name => 'failed' }, { name => 'total' } ],
closure_custom_calc => $self->can('custom_count_calc'), closure_custom_calc => $self->can('custom_count_calc'),
closure_custom_calc_extra_options => { label => 'failed' }, closure_custom_calc_extra_options => { label => 'failed' },
closure_custom_output => $self->can('custom_count_output'), closure_custom_output => $self->can('custom_count_output'),
closure_custom_perfdata => $self->can('custom_count_perfdata'), closure_custom_perfdata => $self->can('custom_count_perfdata'),
closure_custom_threshold_check => $self->can('custom_count_threshold'), closure_custom_threshold_check => $self->can('custom_count_threshold'),
} }
}, },
{ label => 'time-scenario', set => { { label => 'time-scenario', set => {
key_values => [ { name => 'time_scenario' } ], key_values => [ { name => 'time_scenario' } ],
output_template => 'Total execution time : %.2f ms', output_template => 'Total execution time : %.2f ms',
perfdatas => [ perfdatas => [
{ label => 'time_scenario', value => 'time_scenario_absolute', template => '%.2f', { label => 'time_scenario', value => 'time_scenario_absolute', template => '%.2f',
min => 0, unit => 'ms' }, min => 0, unit => 'ms' },
], ],
} }
}, },
]; ];
$self->{maps_counters}->{steps} = [ $self->{maps_counters}->{steps} = [
{ label => 'state', set => { { label => 'state', set => {
key_values => [ { name => 'state' }, { name => 'command' }, { name => 'target' }, key_values => [ { name => 'state' }, { name => 'command' }, { name => 'target' },
{ name => 'value' }, { name => 'comment' }, { name => 'display' } ], { name => 'value' }, { name => 'comment' }, { name => 'display' } ],
closure_custom_calc => $self->can('custom_state_calc'), closure_custom_calc => $self->can('custom_state_calc'),
closure_custom_output => $self->can('custom_state_output'), closure_custom_output => $self->can('custom_state_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_state_threshold'), closure_custom_threshold_check => $self->can('custom_state_threshold'),
} }
}, },
{ label => 'time-step', set => { { label => 'time-step', set => {
key_values => [ { name => 'time_step' }, { name => 'display' } ], key_values => [ { name => 'time_step' }, { name => 'display' } ],
output_template => 'Execution time : %.2f ms', output_template => 'Execution time : %.2f ms',
perfdatas => [ perfdatas => [
{ label => 'time_step', value => 'time_step_absolute', template => '%.2f', { label => 'time_step', value => 'time_step_absolute', template => '%.2f',
min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display_absolute' }, min => 0, unit => 'ms', label_extra_instance => 1, instance_use => 'display_absolute' },
], ],
} }
}, },
]; ];
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"selenium-hostname:s" => { name => 'selenium_hostname', default => 'localhost' }, "selenium-hostname:s" => { name => 'selenium_hostname', default => 'localhost' },
"selenium-port:s" => { name => 'selenium_port', default => '4444' }, "selenium-port:s" => { name => 'selenium_port', default => '4444' },
"browser:s" => { name => 'browser', default => '*firefox' }, "browser:s" => { name => 'browser', default => '*firefox' },
"directory:s" => { name => 'directory', default => '/var/lib/centreon_waa' }, "directory:s" => { name => 'directory', default => '/var/lib/centreon_waa' },
"scenario:s" => { name => 'scenario' }, "scenario:s" => { name => 'scenario' },
"force-continue" => { name => 'force_continue' }, "force-continue" => { name => 'force_continue' },
"timeout:s" => { name => 'timeout', default => 50 }, "timeout:s" => { name => 'timeout', default => 50 },
"action-timeout:s" => { name => 'action_timeout', default => 10 }, "action-timeout:s" => { name => 'action_timeout', default => 10 },
"warning-state:s" => { name => 'warning_state', default => '' }, "warning-state:s" => { name => 'warning_state', default => '' },
"critical-state:s" => { name => 'critical_state', default => '%{state} !~ /OK/i' }, "critical-state:s" => { name => 'critical_state', default => '%{state} !~ /OK/i' },
}); });
$self->set_signal_handlers; $self->set_signal_handlers;
return $self; return $self;
} }
sub set_signal_handlers { sub set_signal_handlers {
my $self = shift; my $self = shift;
$SIG{ALRM} = \&class_handle_ALRM; $SIG{ALRM} = \&class_handle_ALRM;
$handlers{ALRM}->{$self} = sub { $self->handle_ALRM() }; $handlers{ALRM}->{$self} = sub { $self->handle_ALRM() };
} }
sub class_handle_ALRM { sub class_handle_ALRM {
foreach (keys %{$handlers{ALRM}}) { foreach (keys %{$handlers{ALRM}}) {
&{$handlers{ALRM}->{$_}}(); &{$handlers{ALRM}->{$_}}();
} }
} }
sub handle_ALRM { sub handle_ALRM {
my $self = shift; my $self = shift;
$self->{output}->output_add(severity => 'UNKNOWN', $self->{output}->output_add(severity => 'UNKNOWN',
short_msg => sprintf("Cannot finished scenario execution (timeout received)")); short_msg => sprintf("Cannot finished scenario execution (timeout received)"));
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ && if (defined($self->{option_results}->{timeout}) && $self->{option_results}->{timeout} =~ /^\d+$/ &&
$self->{option_results}->{timeout} > 0) { $self->{option_results}->{timeout} > 0) {
alarm($self->{option_results}->{timeout}); alarm($self->{option_results}->{timeout});
} }
if (!defined($self->{option_results}->{scenario})) { if (!defined($self->{option_results}->{scenario})) {
$self->{output}->add_option_msg(short_msg => "Please specify a scenario name."); $self->{output}->add_option_msg(short_msg => "Please specify a scenario name.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$instance_mode = $self; $instance_mode = $self;
$self->change_macros(); $self->change_macros();
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning_state', 'critical_state')) { foreach (('warning_state', 'critical_state')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
} }
} }
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{global}->{failed} = 0; $self->{global}->{failed} = 0;
$self->{global}->{successful} = 0; $self->{global}->{successful} = 0;
$self->{global}->{time_scenario} = 0; $self->{global}->{time_scenario} = 0;
$self->{selenium} = WWW::Selenium->new( $self->{selenium} = WWW::Selenium->new(
host => $self->{option_results}->{selenium_hostname}, host => $self->{option_results}->{selenium_hostname},
port => $self->{option_results}->{selenium_port}, port => $self->{option_results}->{selenium_port},
browser => $self->{option_results}->{browser}, browser => $self->{option_results}->{browser},
browser_url => "file://localhost" browser_url => "file://localhost"
); );
my $filename = $self->{option_results}->{directory} . '/' . $self->{option_results}->{scenario} . '.xml'; my $filename = $self->{option_results}->{directory} . '/' . $self->{option_results}->{scenario} . '.xml';
my $xp = XML::XPath->new(filename => $filename); my $xp = XML::XPath->new(filename => $filename);
my $step = 1; my $step = 1;
$self->{selenium}->start; $self->{selenium}->start;
$self->{selenium}->set_timeout($self->{option_results}->{action_timeout} * 1000); $self->{selenium}->set_timeout($self->{option_results}->{action_timeout} * 1000);
my $actions = $xp->find('/TestCase/selenese'); my $actions = $xp->find('/TestCase/selenese');
$self->{global}->{total} = $actions->size; $self->{global}->{total} = $actions->size;
my $start = gettimeofday() * 1000; my $start = gettimeofday() * 1000;
foreach my $action ($actions->get_nodelist) { foreach my $action ($actions->get_nodelist) {
my $command = centreon::plugins::misc::trim($xp->find('command', $action)->string_value); 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 $target = centreon::plugins::misc::trim($xp->find('target', $action)->string_value);
my $value = centreon::plugins::misc::trim($xp->find('value', $action)->string_value); my $value = centreon::plugins::misc::trim($xp->find('value', $action)->string_value);
$self->{steps}->{$step}->{display} = $step; $self->{steps}->{$step}->{display} = $step;
$self->{steps}->{$step}->{command} = $command; $self->{steps}->{$step}->{command} = $command;
$self->{steps}->{$step}->{target} = $target; $self->{steps}->{$step}->{target} = $target;
$self->{steps}->{$step}->{value} = $value; $self->{steps}->{$step}->{value} = $value;
$self->{steps}->{$step}->{state} = 'OK'; $self->{steps}->{$step}->{state} = 'OK';
$self->{steps}->{$step}->{comment} = ''; $self->{steps}->{$step}->{comment} = '';
$self->{steps}->{$step}->{time_step} = 0; $self->{steps}->{$step}->{time_step} = 0;
my $result; my $result;
my $step_start = gettimeofday() * 1000; my $step_start = gettimeofday() * 1000;
eval { eval {
if ($command =~ /pause/) { if ($command =~ /pause/) {
$result = $self->{selenium}->pause($value); $result = $self->{selenium}->pause($value);
} else { } else {
$result = $self->{selenium}->do_command($command, $target, $value); $result = $self->{selenium}->do_command($command, $target, $value);
} }
}; };
$self->{steps}->{$step}->{time_step} = gettimeofday() * 1000 - $step_start; $self->{steps}->{$step}->{time_step} = gettimeofday() * 1000 - $step_start;
if (!$@) { if (!$@) {
$self->{global}->{successful}++; $self->{global}->{successful}++;
} else { } else {
$self->{steps}->{$step}->{comment} = $@; $self->{steps}->{$step}->{comment} = $@;
$self->{steps}->{$step}->{comment} =~ s/^(.*\n)//;;; $self->{steps}->{$step}->{comment} =~ s/^(.*\n)//;;;
$self->{steps}->{$step}->{comment} =~ s/\n//;;; $self->{steps}->{$step}->{comment} =~ s/\n//;;;
$self->{steps}->{$step}->{state} = 'ERROR'; $self->{steps}->{$step}->{state} = 'ERROR';
$self->{global}->{failed}++; $self->{global}->{failed}++;
last unless $self->{option_results}->{force_continue}; last unless $self->{option_results}->{force_continue};
} }
$step++; $step++;
} }
$self->{global}->{time_scenario} = gettimeofday() * 1000 - $start; $self->{global}->{time_scenario} = gettimeofday() * 1000 - $start;
$self->{selenium}->stop; $self->{selenium}->stop;
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Play scenario based on Katalon Automation Recorder XML export Play scenario based on Katalon Automation Recorder XML export
=over 8 =over 8
=item B<--selenium-hostname> =item B<--selenium-hostname>
IP Addr/FQDN of the Selenium server. IP Addr/FQDN of the Selenium server.
=item B<--selenium-port> =item B<--selenium-port>
Port used by Selenium server. Port used by Selenium server.
=item B<--browser> =item B<--browser>
Browser used by Selenium server (Default : '*firefox'). Browser used by Selenium server (Default : '*firefox').
=item B<--directory> =item B<--directory>
Directory where scenarii are stored. Directory where scenarii are stored.
=item B<--scenario> =item B<--scenario>
Scenario to play (without extension). Scenario to play (without extension).
=item B<--force-continue> =item B<--force-continue>
Don't stop if error. Don't stop if error.
=item B<--timeout> =item B<--timeout>
Set scenario execution timeout in second (Default: 50). Set scenario execution timeout in second (Default: 50).
=item B<--action-timeout> =item B<--action-timeout>
Set action execution timeout in second (Default: 10). Set action execution timeout in second (Default: 10).
=item B<--warning-*> =item B<--warning-*>
Threshold warning for steps state count Threshold warning for steps state count
(Can be: 'failed', 'successful'). (Can be: 'failed', 'successful').
=item B<--critical-*> =item B<--critical-*>
Threshold critical for steps state count Threshold critical for steps state count
(Can be: 'failed', 'successful'). (Can be: 'failed', 'successful').
=item B<--warning-time-scenario> =item B<--warning-time-scenario>
Threshold warning in milliseconds Threshold warning in milliseconds
for scenario execution time. for scenario execution time.
=item B<--critical-time-scenario> =item B<--critical-time-scenario>
Threshold critical in milliseconds Threshold critical in milliseconds
for scenario execution time. for scenario execution time.
=item B<--warning-time-step> =item B<--warning-time-step>
Threshold warning in milliseconds Threshold warning in milliseconds
for step execution time. for step execution time.
=item B<--critical-time-step> =item B<--critical-time-step>
Threshold critical in milliseconds Threshold critical in milliseconds
for step execution time. for step execution time.
=item B<--warning-state> =item B<--warning-state>
Threshold warning for step state. Threshold warning for step state.
=item B<--critical-state> =item B<--critical-state>
Threshold critical for step state Threshold critical for step state
(Default: '%{state} !~ /OK/i'). (Default: '%{state} !~ /OK/i').
=back =back
=cut =cut

View File

@ -1,139 +1,139 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package cloud::aws::billing::mode::estimatedcharges; package cloud::aws::billing::mode::estimatedcharges;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub prefix_charges_output { sub prefix_charges_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Service '" . $self->{option_results}->{service} . "' "; return "Service '" . $self->{option_results}->{service} . "' ";
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'estimatedcharges', type => 0, cb_prefix_output => 'prefix_charges_output' }, { name => 'estimatedcharges', type => 0, cb_prefix_output => 'prefix_charges_output' },
]; ];
$self->{maps_counters}->{estimatedcharges} = [ $self->{maps_counters}->{estimatedcharges} = [
{ label => 'billing', set => { { label => 'billing', set => {
key_values => [ { name => 'estimated_charges' }, { name => 'display' } ], key_values => [ { name => 'estimated_charges' }, { name => 'display' } ],
output_template => 'estimated charges: %.2f USD', output_template => 'estimated charges: %.2f USD',
perfdatas => [ perfdatas => [
{ label => 'billing', value => 'estimated_charges_absolute', template => '%.2f', { label => 'billing', value => 'estimated_charges_absolute', template => '%.2f',
unit => 'USD' }, unit => 'USD' },
], ],
} }
}, },
]; ];
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"service:s" => { name => 'service' }, "service:s" => { name => 'service' },
"currency:s" => { name => 'currency', default => 'USD' }, "currency:s" => { name => 'currency', default => 'USD' },
}); });
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
if (!defined($self->{option_results}->{service}) || $self->{option_results}->{service} eq '') { 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}->add_option_msg(short_msg => "Need to specify --service option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (!defined($self->{option_results}->{currency}) || $self->{option_results}->{currency} eq '') { 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}->add_option_msg(short_msg => "Need to specify --currency option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
$self->{aws_timeframe} = defined($self->{option_results}->{timeframe}) ? $self->{option_results}->{timeframe} : 86400; $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; $self->{aws_period} = defined($self->{option_results}->{period}) ? $self->{option_results}->{period} : 60;
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $metric_results = $options{custom}->cloudwatch_get_metrics( my $metric_results = $options{custom}->cloudwatch_get_metrics(
region => $self->{option_results}->{region}, region => $self->{option_results}->{region},
namespace => 'AWS/Billing', namespace => 'AWS/Billing',
dimensions => [ { Name => 'ServiceName', Value => $self->{option_results}->{service} }, { Name => 'Currency', Value => $self->{option_results}->{currency} } ], dimensions => [ { Name => 'ServiceName', Value => $self->{option_results}->{service} }, { Name => 'Currency', Value => $self->{option_results}->{currency} } ],
metrics => ['EstimatedCharges'], metrics => ['EstimatedCharges'],
statistics => ['Maximum'], statistics => ['Maximum'],
timeframe => $self->{aws_timeframe}, timeframe => $self->{aws_timeframe},
period => $self->{aws_period}, period => $self->{aws_period},
); );
$self->{estimatedcharges}->{estimated_charges} = $metric_results->{'EstimatedCharges'}->{'maximum'} if defined($metric_results->{'EstimatedCharges'}->{'maximum'}); $self->{estimatedcharges}->{estimated_charges} = $metric_results->{'EstimatedCharges'}->{'maximum'} if defined($metric_results->{'EstimatedCharges'}->{'maximum'});
$self->{estimatedcharges}->{display} = $self->{option_results}->{service}; $self->{estimatedcharges}->{display} = $self->{option_results}->{service};
if (scalar(keys %{$self->{estimatedcharges}}) <= 0) { if (scalar(keys %{$self->{estimatedcharges}}) <= 0) {
$self->{output}->add_option_msg(short_msg => 'No value.'); $self->{output}->add_option_msg(short_msg => 'No value.');
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Check Billing estimated charges for a service. Check Billing estimated charges for a service.
Example: Example:
perl centreon_plugins.pl --plugin=cloud::aws::billing::plugin --custommode=paws --mode=estimated-charges perl centreon_plugins.pl --plugin=cloud::aws::billing::plugin --custommode=paws --mode=estimated-charges
--region='us-east-1' --service='AWSService' --verbose --region='us-east-1' --service='AWSService' --verbose
See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/billing-metricscollected.html' for more informations. See 'https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/billing-metricscollected.html' for more informations.
=over 8 =over 8
=item B<--service> =item B<--service>
Set the Amazon service (Required). Set the Amazon service (Required).
=item B<--warning-billing> =item B<--warning-billing>
Thresholds warning. Thresholds warning.
=item B<--critical-billing> =item B<--critical-billing>
Thresholds critical. Thresholds critical.
=back =back
=cut =cut

View File

@ -1,259 +1,259 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package cloud::ibm::softlayer::custom::xmlapi; package cloud::ibm::softlayer::custom::xmlapi;
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::http; use centreon::plugins::http;
use XML::Simple; use XML::Simple;
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = {}; my $self = {};
bless $self, $class; bless $self, $class;
if (!defined($options{output})) { if (!defined($options{output})) {
print "Class Custom: Need to specify 'output' argument.\n"; print "Class Custom: Need to specify 'output' argument.\n";
exit 3; exit 3;
} }
if (!defined($options{options})) { if (!defined($options{options})) {
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument.");
$options{output}->option_exit(); $options{output}->option_exit();
} }
if (!defined($options{noptions})) { if (!defined($options{noptions})) {
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"hostname:s" => { name => 'hostname' }, "hostname:s" => { name => 'hostname' },
"url-path:s" => { name => 'url_path' }, "url-path:s" => { name => 'url_path' },
"port:s" => { name => 'port' }, "port:s" => { name => 'port' },
"proto:s" => { name => 'proto' }, "proto:s" => { name => 'proto' },
"proxyurl:s" => { name => 'proxyurl' }, "proxyurl:s" => { name => 'proxyurl' },
"timeout:s" => { name => 'timeout' }, "timeout:s" => { name => 'timeout' },
"ssl-opt:s@" => { name => 'ssl_opt' }, "ssl-opt:s@" => { name => 'ssl_opt' },
"api-username:s" => { name => 'api_username' }, "api-username:s" => { name => 'api_username' },
"api-key:s" => { name => 'api_key' }, "api-key:s" => { name => 'api_key' },
}); });
} }
$options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI OPTIONS', once => 1); $options{options}->add_help(package => __PACKAGE__, sections => 'XMLAPI OPTIONS', once => 1);
$self->{output} = $options{output}; $self->{output} = $options{output};
$self->{mode} = $options{mode}; $self->{mode} = $options{mode};
$self->{http} = centreon::plugins::http->new(output => $self->{output}); $self->{http} = centreon::plugins::http->new(output => $self->{output});
return $self; return $self;
} }
sub set_options { sub set_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{option_results} = $options{option_results}; $self->{option_results} = $options{option_results};
} }
sub set_defaults { sub set_defaults {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (keys %{$options{default}}) { foreach (keys %{$options{default}}) {
if ($_ eq $self->{mode}) { if ($_ eq $self->{mode}) {
for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) {
foreach my $opt (keys %{$options{default}->{$_}[$i]}) { foreach my $opt (keys %{$options{default}->{$_}[$i]}) {
if (!defined($self->{option_results}->{$opt}[$i])) { if (!defined($self->{option_results}->{$opt}[$i])) {
$self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt};
} }
} }
} }
} }
} }
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'api.softlayer.com'; $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->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 443;
$self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $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->{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->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
$self->{proxyurl} = (defined($self->{option_results}->{proxyurl})) ? $self->{option_results}->{proxyurl} : undef; $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; $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 '') { 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}->add_option_msg(short_msg => "Need to specify --api-username option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
if (!defined($self->{option_results}->{api_key}) || $self->{option_results}->{api_key} eq '') { 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}->add_option_msg(short_msg => "Need to specify --api-key option.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
return 0; return 0;
} }
sub build_options_for_httplib { sub build_options_for_httplib {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{option_results}->{hostname} = $self->{hostname}; $self->{option_results}->{hostname} = $self->{hostname};
$self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{timeout} = $self->{timeout};
$self->{option_results}->{port} = $self->{port}; $self->{option_results}->{port} = $self->{port};
$self->{option_results}->{proto} = $self->{proto}; $self->{option_results}->{proto} = $self->{proto};
$self->{option_results}->{proxyurl} = $self->{proxyurl}; $self->{option_results}->{proxyurl} = $self->{proxyurl};
$self->{option_results}->{warning_status} = ''; $self->{option_results}->{warning_status} = '';
$self->{option_results}->{critical_status} = ''; $self->{option_results}->{critical_status} = '';
} }
sub settings { sub settings {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->build_options_for_httplib(); $self->build_options_for_httplib();
$self->{http}->add_header(key => 'Accept', value => 'text/xml'); $self->{http}->add_header(key => 'Accept', value => 'text/xml');
$self->{http}->add_header(key => 'Accept', value => 'multipart/*'); $self->{http}->add_header(key => 'Accept', value => 'multipart/*');
$self->{http}->add_header(key => 'Accept', value => 'text/xmlapplication/soap'); $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}->add_header(key => 'Content-Type', value => 'text/xml; charset=utf-8');
$self->{http}->set_options(%{$self->{option_results}}); $self->{http}->set_options(%{$self->{option_results}});
} }
sub get_connection_info { sub get_connection_info {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{hostname} . ":" . $self->{port}; return $self->{hostname} . ":" . $self->{port};
} }
sub get_hostname { sub get_hostname {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{hostname}; return $self->{hostname};
} }
sub get_port { sub get_port {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{port}; return $self->{port};
} }
sub get_api_username { sub get_api_username {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{option_results}->{api_username}; return $self->{option_results}->{api_username};
} }
sub get_api_key { sub get_api_key {
my ($self, %options) = @_; my ($self, %options) = @_;
return $self->{option_results}->{api_key}; return $self->{option_results}->{api_key};
} }
sub get_endpoint { sub get_endpoint {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->settings; $self->settings;
$self->{http}->add_header(key => 'SOAPAction', value => 'http://api.service.softlayer.com/soap/v3/#' . $options{method}); $self->{http}->add_header(key => 'SOAPAction', value => 'http://api.service.softlayer.com/soap/v3/#' . $options{method});
my $content = '<?xml version="1.0" encoding="UTF-8"?> my $content = '<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:slapi="http://api.service.softlayer.com/soap/v3/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" <soap:Envelope xmlns:slapi="http://api.service.softlayer.com/soap/v3/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<soap:Header> <soap:Header>
<slapi:authenticate> <slapi:authenticate>
<apiKey>' . $self->get_api_key() . '</apiKey> <apiKey>' . $self->get_api_key() . '</apiKey>
<username>' . $self->get_api_username() . '</username> <username>' . $self->get_api_username() . '</username>
</slapi:authenticate>' . </slapi:authenticate>' .
$options{extra_content} $options{extra_content}
. '</soap:Header> . '</soap:Header>
<soap:Body> <soap:Body>
<slapi:' . $options{method} . ' xsi:nil="true"/> <slapi:' . $options{method} . ' xsi:nil="true"/>
</soap:Body> </soap:Body>
</soap:Envelope>'; </soap:Envelope>';
my $response = $self->{http}->request(url_path => $self->{url_path} . '/' . $options{service}, method => 'POST', query_form_post => $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']); my $xml_hash = XMLin($response, ForceArray => ['item']);
if (defined($xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'})) { if (defined($xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'})) {
$self->{output}->output_add(long_msg => "Returned message: " . $response, debug => 1); $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} . $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} . "'"); "' with message '" . $xml_hash->{'SOAP-ENV:Body'}->{'SOAP-ENV:Fault'}->{faultstring} . "'");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
return $xml_hash->{'SOAP-ENV:Body'}; return $xml_hash->{'SOAP-ENV:Body'};
} }
1; 1;
__END__ __END__
=head1 NAME =head1 NAME
IBM SoftLayer XML API IBM SoftLayer XML API
=head1 SYNOPSIS =head1 SYNOPSIS
IBM SoftLayer XML API IBM SoftLayer XML API
=head1 XMLAPI OPTIONS =head1 XMLAPI OPTIONS
=over 8 =over 8
=item B<--hostname> =item B<--hostname>
API hostname (Default: 'api.softlayer.com'). API hostname (Default: 'api.softlayer.com').
=item B<--url-path> =item B<--url-path>
API url path (Default: '/soap/v3') API url path (Default: '/soap/v3')
=item B<--port> =item B<--port>
API port (Default: 443) API port (Default: 443)
=item B<--proto> =item B<--proto>
Specify https if needed (Default: 'https') Specify https if needed (Default: 'https')
=item B<--api-username> =item B<--api-username>
Set API username Set API username
=item B<--api-key> =item B<--api-key>
Set API Key Set API Key
=item B<--proxyurl> =item B<--proxyurl>
Proxy URL if any Proxy URL if any
=item B<--timeout> =item B<--timeout>
Set HTTP timeout Set HTTP timeout
=item B<--ssl-opt> =item B<--ssl-opt>
Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE"). Set SSL Options (--ssl-opt="SSL_version => TLSv1" --ssl-opt="SSL_verify_mode => SSL_VERIFY_NONE").
=back =back
=head1 DESCRIPTION =head1 DESCRIPTION
B<custom>. B<custom>.
=cut =cut

View File

@ -1,284 +1,284 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package cloud::ibm::softlayer::mode::events; package cloud::ibm::softlayer::mode::events;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use DateTime; use DateTime;
my $instance_mode; my $instance_mode;
sub custom_status_threshold { sub custom_status_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $status = 'ok'; my $status = 'ok';
my $message; my $message;
eval { eval {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") { eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical'; $status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") { eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning'; $status = 'warning';
} }
}; };
if (defined($message)) { if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message, debug => 1); $self->{output}->output_add(long_msg => 'filter status issue: ' . $message, debug => 1);
} }
return $status; return $status;
} }
sub custom_event_output { sub custom_event_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Status is '%s', Impacted items: %d, Start date: %s, End date: %s", my $msg = sprintf("Status is '%s', Impacted items: %d, Start date: %s, End date: %s",
$self->{result_values}->{status}, $self->{result_values}->{status},
$self->{result_values}->{items}, $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}->{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)' : '-'); ($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; return $msg;
} }
sub custom_event_calc { sub custom_event_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'};
$self->{result_values}->{subject} = $options{new_datas}->{$self->{instance} . '_subject'}; $self->{result_values}->{subject} = $options{new_datas}->{$self->{instance} . '_subject'};
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'};
$self->{result_values}->{items} = $options{new_datas}->{$self->{instance} . '_items'}; $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}->{start_date} = $options{new_datas}->{$self->{instance} . '_start_date'};
$self->{result_values}->{since_start} = $options{new_datas}->{$self->{instance} . '_since_start'}; $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}->{end_date} = $options{new_datas}->{$self->{instance} . '_end_date'};
$self->{result_values}->{since_end} = $options{new_datas}->{$self->{instance} . '_since_end'}; $self->{result_values}->{since_end} = $options{new_datas}->{$self->{instance} . '_since_end'};
return 0; return 0;
} }
sub prefix_global_output { sub prefix_global_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Number of events "; return "Number of events ";
} }
sub prefix_events_output { sub prefix_events_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Event '" . $options{instance_value}->{id} . "' with subject '" . $options{instance_value}->{subject} . "' "; return "Event '" . $options{instance_value}->{id} . "' with subject '" . $options{instance_value}->{subject} . "' ";
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } }, { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output', skipped_code => { -10 => 1 } },
{ name => 'events', type => 1, cb_prefix_output => 'prefix_events_output' }, { name => 'events', type => 1, cb_prefix_output => 'prefix_events_output' },
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'active', set => { { label => 'active', set => {
key_values => [ { name => 'active' } ], key_values => [ { name => 'active' } ],
output_template => 'Active : %d', output_template => 'Active : %d',
perfdatas => [ perfdatas => [
{ label => 'active_events', value => 'active_absolute', template => '%d', { label => 'active_events', value => 'active_absolute', template => '%d',
min => 0 }, min => 0 },
], ],
} }
}, },
{ label => 'completed', set => { { label => 'completed', set => {
key_values => [ { name => 'completed' } ], key_values => [ { name => 'completed' } ],
output_template => 'Completed : %d', output_template => 'Completed : %d',
perfdatas => [ perfdatas => [
{ label => 'completed_events', value => 'completed_absolute', template => '%d', { label => 'completed_events', value => 'completed_absolute', template => '%d',
min => 0 }, min => 0 },
], ],
} }
}, },
{ label => 'published', set => { { label => 'published', set => {
key_values => [ { name => 'published' } ], key_values => [ { name => 'published' } ],
output_template => 'Published : %d', output_template => 'Published : %d',
perfdatas => [ perfdatas => [
{ label => 'published_events', value => 'published_absolute', template => '%d', { label => 'published_events', value => 'published_absolute', template => '%d',
min => 0 }, min => 0 },
], ],
} }
}, },
]; ];
$self->{maps_counters}->{events} = [ $self->{maps_counters}->{events} = [
{ label => 'event', threshold => 0, set => { { label => 'event', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'subject' }, { name => 'status' }, { name => 'items' }, key_values => [ { name => 'id' }, { name => 'subject' }, { name => 'status' }, { name => 'items' },
{ name => 'start_date' }, { name => 'since_start' }, { name => 'end_date' }, { name => 'since_end' } ], { name => 'start_date' }, { name => 'since_start' }, { name => 'end_date' }, { name => 'since_end' } ],
closure_custom_calc => $self->can('custom_event_calc'), closure_custom_calc => $self->can('custom_event_calc'),
closure_custom_output => $self->can('custom_event_output'), closure_custom_output => $self->can('custom_event_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'), closure_custom_threshold_check => $self->can('custom_status_threshold'),
} }
}, },
]; ];
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"filter-status:s" => { name => 'filter_status', default => 'Active' }, "filter-status:s" => { name => 'filter_status', default => 'Active' },
"warning-status:s" => { name => 'warning_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Active/ && %{items} > 0' }, "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /Active/ && %{items} > 0' },
}); });
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$instance_mode = $self; $instance_mode = $self;
$self->change_macros(); $self->change_macros();
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) { foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
} }
} }
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $current_time = time(); my $current_time = time();
my %status_hash; my %status_hash;
my $events = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getAllObjects', extra_content => ''); my $events = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getAllObjects', extra_content => '');
foreach my $event (@{$events->{'ns1:getAllObjectsResponse'}->{'getAllObjectsReturn'}->{'item'}}) { foreach my $event (@{$events->{'ns1:getAllObjectsResponse'}->{'getAllObjectsReturn'}->{'item'}}) {
my $status; my $status;
$status = $event->{statusCode}->{name}->{content} if (defined($event->{statusCode}->{name}->{content})); $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_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})); $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}/); next if (defined($self->{option_results}->{filter_status}) && $status !~ /$self->{option_results}->{filter_status}/);
my $extra_content = '<slapi:SoftLayer_Notification_Occurrence_EventInitParameters> my $extra_content = '<slapi:SoftLayer_Notification_Occurrence_EventInitParameters>
<id>' . $event->{id}->{content} . '</id> <id>' . $event->{id}->{content} . '</id>
</slapi:SoftLayer_Notification_Occurrence_EventInitParameters>'; </slapi:SoftLayer_Notification_Occurrence_EventInitParameters>';
my $ressources = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getImpactedResources', extra_content => $extra_content); my $ressources = $options{custom}->get_endpoint(service => 'SoftLayer_Notification_Occurrence_Event', method => 'getImpactedResources', extra_content => $extra_content);
my $items = 0; my $items = 0;
if (defined($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'})) { if (defined($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'})) {
$items = 1; $items = 1;
$items = scalar(@{$ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}}) if (ref($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}) eq 'ARRAY'); $items = scalar(@{$ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}}) if (ref($ressources->{'ns1:getImpactedResourcesResponse'}->{'getImpactedResourcesReturn'}->{'item'}) eq 'ARRAY');
} }
my $start_epoch = ''; my $start_epoch = '';
my $end_epoch = ''; my $end_epoch = '';
if (defined($event->{startDate}->{content}) && 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 $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( my $dt = DateTime->new(
year => $1, year => $1,
month => $2, month => $2,
day => $3, day => $3,
hour => $4, hour => $4,
minute => $5, minute => $5,
second => $6, second => $6,
time_zone => $7 time_zone => $7
); );
$start_epoch = $dt->epoch; $start_epoch = $dt->epoch;
} }
if (defined($event->{endDate}->{content}) && 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 $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( my $dt = DateTime->new(
year => $1, year => $1,
month => $2, month => $2,
day => $3, day => $3,
hour => $4, hour => $4,
minute => $5, minute => $5,
second => $6, second => $6,
time_zone => $7 time_zone => $7
); );
$end_epoch = $dt->epoch; $end_epoch = $dt->epoch;
} }
$self->{events}->{$event->{id}->{content}} = { $self->{events}->{$event->{id}->{content}} = {
id => $event->{id}->{content}, id => $event->{id}->{content},
subject => $event->{subject}->{content}, subject => $event->{subject}->{content},
status => $status, status => $status,
items => $items, items => $items,
start_date => (defined($event->{startDate}->{content})) ? $event->{startDate}->{content} : "-", start_date => (defined($event->{startDate}->{content})) ? $event->{startDate}->{content} : "-",
since_start => ($start_epoch ne '') ? $current_time - $start_epoch : "-", since_start => ($start_epoch ne '') ? $current_time - $start_epoch : "-",
end_date => (defined($event->{endDate}->{content})) ? $event->{endDate}->{content} : "-", end_date => (defined($event->{endDate}->{content})) ? $event->{endDate}->{content} : "-",
since_end => ($end_epoch ne '') ? $current_time - $end_epoch : "-", since_end => ($end_epoch ne '') ? $current_time - $end_epoch : "-",
}; };
$self->{global}->{lc($status)}++; $self->{global}->{lc($status)}++;
} }
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Check events status and number of impacted ressources Check events status and number of impacted ressources
=over 8 =over 8
=item B<--filter-status> =item B<--filter-status>
Filter events status (Default: 'Active') Filter events status (Default: 'Active')
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status (Default: '') Set warning threshold for status (Default: '')
Can used special variables like: %{id}, %{subject}, %{status}, %{items}, Can used special variables like: %{id}, %{subject}, %{status}, %{items},
%{start_date}, %{since_start}, %{end_date}, %{since_end}. %{start_date}, %{since_start}, %{end_date}, %{since_end}.
=item B<--critical-status> =item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /Active/ && %{items} > 0'). Set critical threshold for status (Default: '%{status} =~ /Active/ && %{items} > 0').
Can used special variables like: %{id}, %{subject}, %{status}, %{items}, Can used special variables like: %{id}, %{subject}, %{status}, %{items},
%{start_date}, %{since_start}, %{end_date}, %{since_end}. %{start_date}, %{since_start}, %{end_date}, %{since_end}.
=item B<--warning-*> =item B<--warning-*>
Threshold warning. Threshold warning.
Can be: 'active', 'completed', 'published'. Can be: 'active', 'completed', 'published'.
=item B<--critical-*> =item B<--critical-*>
Threshold critical. Threshold critical.
Can be: 'active', 'completed', 'published'. Can be: 'active', 'completed', 'published'.
=back =back
=cut =cut

View File

@ -1,240 +1,240 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package cloud::ibm::softlayer::mode::opentickets; package cloud::ibm::softlayer::mode::opentickets;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use DateTime; use DateTime;
my $instance_mode; my $instance_mode;
sub custom_status_threshold { sub custom_status_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $status = 'ok'; my $status = 'ok';
my $message; my $message;
eval { eval {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") { eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical'; $status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") { eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning'; $status = 'warning';
} }
}; };
if (defined($message)) { if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message); $self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
} }
return $status; return $status;
} }
sub custom_ticket_output { sub custom_ticket_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Title: '%s', Group: '%s', Priority: %s, Create Date: %s (%s ago)", my $msg = sprintf("Title: '%s', Group: '%s', Priority: %s, Create Date: %s (%s ago)",
$self->{result_values}->{title}, $self->{result_values}->{title},
$self->{result_values}->{group}, $self->{result_values}->{group},
$self->{result_values}->{priority}, $self->{result_values}->{priority},
$self->{result_values}->{create_date}, $self->{result_values}->{create_date},
centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since})); centreon::plugins::misc::change_seconds(value => $self->{result_values}->{since}));
return $msg; return $msg;
} }
sub custom_ticket_calc { sub custom_ticket_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'}; $self->{result_values}->{id} = $options{new_datas}->{$self->{instance} . '_id'};
$self->{result_values}->{title} = $options{new_datas}->{$self->{instance} . '_title'}; $self->{result_values}->{title} = $options{new_datas}->{$self->{instance} . '_title'};
$self->{result_values}->{priority} = $options{new_datas}->{$self->{instance} . '_priority'}; $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}->{create_date} = $options{new_datas}->{$self->{instance} . '_create_date'};
$self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_group'}; $self->{result_values}->{group} = $options{new_datas}->{$self->{instance} . '_group'};
$self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'}; $self->{result_values}->{since} = $options{new_datas}->{$self->{instance} . '_since'};
return 0; return 0;
} }
sub prefix_tickets_output { sub prefix_tickets_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Ticket '" . $options{instance_value}->{id} . "' is open with "; return "Ticket '" . $options{instance_value}->{id} . "' is open with ";
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0 }, { name => 'global', type => 0 },
{ name => 'tickets', type => 1, cb_prefix_output => 'prefix_tickets_output' }, { name => 'tickets', type => 1, cb_prefix_output => 'prefix_tickets_output' },
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'open', set => { { label => 'open', set => {
key_values => [ { name => 'open' } ], key_values => [ { name => 'open' } ],
output_template => 'Number of open tickets : %d', output_template => 'Number of open tickets : %d',
perfdatas => [ perfdatas => [
{ label => 'open_tickets', value => 'open_absolute', template => '%d', { label => 'open_tickets', value => 'open_absolute', template => '%d',
min => 0 }, min => 0 },
], ],
} }
}, },
]; ];
$self->{maps_counters}->{tickets} = [ $self->{maps_counters}->{tickets} = [
{ label => 'ticket', threshold => 0, set => { { label => 'ticket', threshold => 0, set => {
key_values => [ { name => 'id' }, { name => 'title' }, { name => 'priority' }, { name => 'create_date' }, key_values => [ { name => 'id' }, { name => 'title' }, { name => 'priority' }, { name => 'create_date' },
{ name => 'group' }, { name => 'since' } ], { name => 'group' }, { name => 'since' } ],
closure_custom_calc => $self->can('custom_ticket_calc'), closure_custom_calc => $self->can('custom_ticket_calc'),
closure_custom_output => $self->can('custom_ticket_output'), closure_custom_output => $self->can('custom_ticket_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'), closure_custom_threshold_check => $self->can('custom_status_threshold'),
} }
}, },
]; ];
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"ticket-group:s" => { name => 'ticket_group' }, "ticket-group:s" => { name => 'ticket_group' },
"warning-status:s" => { name => 'warning_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '' }, "critical-status:s" => { name => 'critical_status', default => '' },
}); });
return $self; return $self;
} }
sub check_options { sub check_options {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->SUPER::check_options(%options); $self->SUPER::check_options(%options);
$instance_mode = $self; $instance_mode = $self;
$self->change_macros(); $self->change_macros();
} }
sub change_macros { sub change_macros {
my ($self, %options) = @_; my ($self, %options) = @_;
foreach (('warning_status', 'critical_status')) { foreach (('warning_status', 'critical_status')) {
if (defined($self->{option_results}->{$_})) { if (defined($self->{option_results}->{$_})) {
$self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g;
} }
} }
} }
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{global}->{open} = 0; $self->{global}->{open} = 0;
$self->{tickets} = {}; $self->{tickets} = {};
my $group_id = ''; my $group_id = '';
my %groups_hash; my %groups_hash;
my $groups = $options{custom}->get_endpoint(service => 'SoftLayer_Ticket', method => 'getAllTicketGroups', extra_content => ''); my $groups = $options{custom}->get_endpoint(service => 'SoftLayer_Ticket', method => 'getAllTicketGroups', extra_content => '');
foreach my $group (@{$groups->{'ns1:getAllTicketGroupsResponse'}->{'getAllTicketGroupsReturn'}->{'item'}}) { foreach my $group (@{$groups->{'ns1:getAllTicketGroupsResponse'}->{'getAllTicketGroupsReturn'}->{'item'}}) {
$groups_hash{$group->{id}->{content}} = $group->{name}->{content}; $groups_hash{$group->{id}->{content}} = $group->{name}->{content};
if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' && if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' &&
$group->{name}->{content} =~ /^$self->{option_results}->{ticket_group}$/) { $group->{name}->{content} =~ /^$self->{option_results}->{ticket_group}$/) {
$group_id = $group->{id}->{content}; $group_id = $group->{id}->{content};
} }
} }
if (defined($self->{option_results}->{ticket_group}) && $self->{option_results}->{ticket_group} ne '' && $group_id eq '') { 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}->add_option_msg(short_msg => "Ticket group ID not found from API.");
$self->{output}->option_exit(); $self->{output}->option_exit();
} }
my $current_time = time(); my $current_time = time();
my $tickets = $options{custom}->get_endpoint(service => 'SoftLayer_Account', method => 'getOpenTickets', extra_content => ''); my $tickets = $options{custom}->get_endpoint(service => 'SoftLayer_Account', method => 'getOpenTickets', extra_content => '');
foreach my $ticket (@{$tickets->{'ns1:getOpenTicketsResponse'}->{'getOpenTicketsReturn'}->{'item'}}) { foreach my $ticket (@{$tickets->{'ns1:getOpenTicketsResponse'}->{'getOpenTicketsReturn'}->{'item'}}) {
next if (defined($group_id) && $group_id ne '' && $ticket->{groupId}->{content} ne $group_id); 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 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( my $dt = DateTime->new(
year => $1, year => $1,
month => $2, month => $2,
day => $3, day => $3,
hour => $4, hour => $4,
minute => $5, minute => $5,
second => $6, second => $6,
time_zone => $7 time_zone => $7
); );
$self->{tickets}->{$ticket->{id}->{content}} = { $self->{tickets}->{$ticket->{id}->{content}} = {
id => $ticket->{id}->{content}, id => $ticket->{id}->{content},
title => $ticket->{title}->{content}, title => $ticket->{title}->{content},
priority => $ticket->{priority}->{content}, priority => $ticket->{priority}->{content},
create_date => $ticket->{createDate}->{content}, create_date => $ticket->{createDate}->{content},
group => $groups_hash{$ticket->{groupId}->{content}}, group => $groups_hash{$ticket->{groupId}->{content}},
since => $current_time - $dt->epoch, since => $current_time - $dt->epoch,
}; };
$self->{global}->{open}++; $self->{global}->{open}++;
} }
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Check if there is open tickets Check if there is open tickets
=over 8 =over 8
=item B<--ticket-group> =item B<--ticket-group>
Name of the ticket group (Can be a regexp). Name of the ticket group (Can be a regexp).
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status (Default: '') Set warning threshold for status (Default: '')
Can used special variables like: %{id}, %{title}, Can used special variables like: %{id}, %{title},
%{priority}, %{create_date}, %{group}, %{since}. %{priority}, %{create_date}, %{group}, %{since}.
=item B<--critical-status> =item B<--critical-status>
Set critical threshold for status (Default: ''). Set critical threshold for status (Default: '').
Can used special variables like: %{id}, %{title}, Can used special variables like: %{id}, %{title},
%{priority}, %{create_date}, %{group}, %{since}. %{priority}, %{create_date}, %{group}, %{since}.
=item B<--warning-open> =item B<--warning-open>
Threshold warning for open tickets. Threshold warning for open tickets.
=item B<--critical-open> =item B<--critical-open>
Threshold critical for open tickets. Threshold critical for open tickets.
=back =back
=cut =cut

View File

@ -1,74 +1,74 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package network::barracuda::cloudgen::snmp::mode::components::fan; package network::barracuda::cloudgen::snmp::mode::components::fan;
use strict; use strict;
use warnings; use warnings;
my $mapping = { my $mapping = {
hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, 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' }, 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' }, 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'; my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; push @{$self->{request}}, { oid => $oid_HwSensorsEntry };
} }
sub check { sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking fans"); $self->{output}->output_add(long_msg => "Checking fans");
$self->{components}->{fan} = {name => 'fans', total => 0, skip => 0}; $self->{components}->{fan} = {name => 'fans', total => 0, skip => 0};
return if ($self->check_filter(section => 'fan')); return if ($self->check_filter(section => 'fan'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) {
next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); 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 ($self->check_filter(section => 'fan', instance => $instance));
next if ($result->{hwSensorType} != 1); #Fans next if ($result->{hwSensorType} != 1); #Fans
$self->{components}->{fan}->{total}++; $self->{components}->{fan}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' RPM", $self->{output}->output_add(long_msg => sprintf("Fan '%s' speed is '%s' RPM",
$result->{hwSensorName}, $result->{hwSensorValue})); $result->{hwSensorName}, $result->{hwSensorValue}));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'fan', instance => $instance, value => $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)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Fan '%s' speed is '%s' RPM", $result->{hwSensorName}, $result->{hwSensorValue})); short_msg => sprintf("Fan '%s' speed is '%s' RPM", $result->{hwSensorName}, $result->{hwSensorValue}));
} }
my $perf_label = $result->{hwSensorName}; my $perf_label = $result->{hwSensorName};
$perf_label =~ s/ /_/g; $perf_label =~ s/ /_/g;
$self->{output}->perfdata_add(label => 'speed_' . $perf_label, unit => 'rpm', $self->{output}->perfdata_add(label => 'speed_' . $perf_label, unit => 'rpm',
value => $result->{hwSensorValue}, value => $result->{hwSensorValue},
warning => $warn, warning => $warn,
critical => $crit critical => $crit
); );
} }
} }
1; 1;

View File

@ -1,72 +1,72 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package network::barracuda::cloudgen::snmp::mode::components::psu; package network::barracuda::cloudgen::snmp::mode::components::psu;
use strict; use strict;
use warnings; use warnings;
my %map_status = ( my %map_status = (
0 => 'critical', 0 => 'critical',
1 => 'ok', 1 => 'ok',
2 => 'critical', 2 => 'critical',
); );
my $mapping = { my $mapping = {
hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, 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' }, 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 }, 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'; my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; push @{$self->{request}}, { oid => $oid_HwSensorsEntry };
} }
sub check { sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking power supplies"); $self->{output}->output_add(long_msg => "Checking power supplies");
$self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0}; $self->{components}->{psu} = {name => 'power supplies', total => 0, skip => 0};
return if ($self->check_filter(section => 'psu')); return if ($self->check_filter(section => 'psu'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) {
next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); 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 ($self->check_filter(section => 'psu', instance => $instance));
next if ($result->{hwSensorType} != 3); #PSU next if ($result->{hwSensorType} != 3); #PSU
$self->{components}->{psu}->{total}++; $self->{components}->{psu}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'", $self->{output}->output_add(long_msg => sprintf("Power supply '%s' status is '%s'",
$result->{hwSensorName}, $result->{hwSensorValue})); $result->{hwSensorName}, $result->{hwSensorValue}));
my $exit = $self->get_severity(label => 'psu', section => 'psu', value => $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)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Power supply '%s' status is '%s'", $result->{hwSensorName}, $result->{hwSensorValue})); short_msg => sprintf("Power supply '%s' status is '%s'", $result->{hwSensorName}, $result->{hwSensorValue}));
} }
} }
} }
1; 1;

View File

@ -1,74 +1,74 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package network::barracuda::cloudgen::snmp::mode::components::temperature; package network::barracuda::cloudgen::snmp::mode::components::temperature;
use strict; use strict;
use warnings; use warnings;
my $mapping = { my $mapping = {
hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, 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' }, 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' }, 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'; my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; push @{$self->{request}}, { oid => $oid_HwSensorsEntry };
} }
sub check { sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking temperatures"); $self->{output}->output_add(long_msg => "Checking temperatures");
$self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0}; $self->{components}->{temperature} = {name => 'temperatures', total => 0, skip => 0};
return if ($self->check_filter(section => 'temperature')); return if ($self->check_filter(section => 'temperature'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) {
next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); 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 ($self->check_filter(section => 'temperature', instance => $instance));
next if ($result->{hwSensorType} != 2); #Temperatures next if ($result->{hwSensorType} != 2); #Temperatures
$self->{components}->{temperature}->{total}++; $self->{components}->{temperature}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' celsius degrees", $self->{output}->output_add(long_msg => sprintf("Temperature '%s' is '%s' celsius degrees",
$result->{hwSensorName}, $result->{hwSensorValue} / 1000)); $result->{hwSensorName}, $result->{hwSensorValue} / 1000));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'temperature', instance => $instance, value => $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)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Temperature '%s' is '%s' celsius degrees", $result->{hwSensorName}, $result->{hwSensorValue} / 1000)); short_msg => sprintf("Temperature '%s' is '%s' celsius degrees", $result->{hwSensorName}, $result->{hwSensorValue} / 1000));
} }
my $perf_label = $result->{hwSensorName}; my $perf_label = $result->{hwSensorName};
$perf_label =~ s/ /_/g; $perf_label =~ s/ /_/g;
$self->{output}->perfdata_add(label => 'temperature_' . $perf_label, unit => 'C', $self->{output}->perfdata_add(label => 'temperature_' . $perf_label, unit => 'C',
value => $result->{hwSensorValue} / 1000, value => $result->{hwSensorValue} / 1000,
warning => $warn, warning => $warn,
critical => $crit critical => $crit
); );
} }
} }
1; 1;

View File

@ -1,74 +1,74 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package network::barracuda::cloudgen::snmp::mode::components::voltage; package network::barracuda::cloudgen::snmp::mode::components::voltage;
use strict; use strict;
use warnings; use warnings;
my $mapping = { my $mapping = {
hwSensorName => { oid => '.1.3.6.1.4.1.10704.1.4.1.1' }, 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' }, 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' }, 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'; my $oid_HwSensorsEntry = '.1.3.6.1.4.1.10704.1.4.1';
sub load { sub load {
my ($self) = @_; my ($self) = @_;
push @{$self->{request}}, { oid => $oid_HwSensorsEntry }; push @{$self->{request}}, { oid => $oid_HwSensorsEntry };
} }
sub check { sub check {
my ($self) = @_; my ($self) = @_;
$self->{output}->output_add(long_msg => "Checking voltages"); $self->{output}->output_add(long_msg => "Checking voltages");
$self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0}; $self->{components}->{voltage} = {name => 'voltages', total => 0, skip => 0};
return if ($self->check_filter(section => 'voltage')); return if ($self->check_filter(section => 'voltage'));
foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) { foreach my $oid ($self->{snmp}->oid_lex_sort(keys %{$self->{results}->{$oid_HwSensorsEntry}})) {
next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{hwSensorType}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $self->{snmp}->map_instance(mapping => $mapping, results => $self->{results}->{$oid_HwSensorsEntry}, instance => $instance); 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 ($self->check_filter(section => 'voltage', instance => $instance));
next if ($result->{hwSensorType} != 0); #Voltages next if ($result->{hwSensorType} != 0); #Voltages
$self->{components}->{voltage}->{total}++; $self->{components}->{voltage}->{total}++;
$self->{output}->output_add(long_msg => sprintf("Voltage '%s' is '%s' mV", $self->{output}->output_add(long_msg => sprintf("Voltage '%s' is '%s' mV",
$result->{hwSensorName}, $result->{hwSensorValue})); $result->{hwSensorName}, $result->{hwSensorValue}));
my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'voltage', instance => $instance, value => $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)) { if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) {
$self->{output}->output_add(severity => $exit, $self->{output}->output_add(severity => $exit,
short_msg => sprintf("Voltage '%s' is '%s' mV", $result->{hwSensorName}, $result->{hwSensorValue})); short_msg => sprintf("Voltage '%s' is '%s' mV", $result->{hwSensorName}, $result->{hwSensorValue}));
} }
my $perf_label = $result->{hwSensorName}; my $perf_label = $result->{hwSensorName};
$perf_label =~ s/ /_/g; $perf_label =~ s/ /_/g;
$self->{output}->perfdata_add(label => 'voltage_' . $perf_label, unit => 'mV', $self->{output}->perfdata_add(label => 'voltage_' . $perf_label, unit => 'mV',
value => $result->{hwSensorValue}, value => $result->{hwSensorValue},
warning => $warn, warning => $warn,
critical => $crit critical => $crit
); );
} }
} }
1; 1;

View File

@ -100,6 +100,8 @@ sub manage_selection {
__END__ __END__
=head1 MODE
Check Juniper sessions usage and failed sessions (NETSCREEN-RESOURCE-MIB). Check Juniper sessions usage and failed sessions (NETSCREEN-RESOURCE-MIB).
=over 8 =over 8

View File

@ -1,172 +1,172 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package storage::ibm::fs900::snmp::mode::arraysstatus; package storage::ibm::fs900::snmp::mode::arraysstatus;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
my $instance_mode; my $instance_mode;
sub custom_status_threshold { sub custom_status_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $status = 'ok'; my $status = 'ok';
my $message; my $message;
eval { eval {
local $SIG{__WARN__} = sub { $message = $_[0]; }; local $SIG{__WARN__} = sub { $message = $_[0]; };
local $SIG{__DIE__} = sub { $message = $_[0]; }; local $SIG{__DIE__} = sub { $message = $_[0]; };
if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' &&
eval "$instance_mode->{option_results}->{critical_status}") { eval "$instance_mode->{option_results}->{critical_status}") {
$status = 'critical'; $status = 'critical';
} elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' &&
eval "$instance_mode->{option_results}->{warning_status}") { eval "$instance_mode->{option_results}->{warning_status}") {
$status = 'warning'; $status = 'warning';
} }
}; };
if (defined($message)) { if (defined($message)) {
$self->{output}->output_add(long_msg => 'filter status issue: ' . $message); $self->{output}->output_add(long_msg => 'filter status issue: ' . $message);
} }
return $status; return $status;
} }
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = sprintf("Status is '%s'", $self->{result_values}->{status}); my $msg = sprintf("Status is '%s'", $self->{result_values}->{status});
return $msg; return $msg;
} }
sub custom_status_calc { sub custom_status_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_arrayStatus'}; $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_arrayStatus'};
return 0; return 0;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays metrics are ok", message_separator => ' - ' } { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays metrics are ok", message_separator => ' - ' }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'arrayStatus' } ], key_values => [ { name => 'arrayStatus' } ],
closure_custom_calc => $self->can('custom_status_calc'), closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => $self->can('custom_status_threshold'), closure_custom_threshold_check => $self->can('custom_status_threshold'),
} }
}, },
{ label => 'vdisk-count', set => { { label => 'vdisk-count', set => {
key_values => [ { name => 'arrayVDiskCount' }, { name => 'arrayId' } ], key_values => [ { name => 'arrayVDiskCount' }, { name => 'arrayId' } ],
output_template => 'VDisk count: %s', output_template => 'VDisk count: %s',
perfdatas => [ perfdatas => [
{ label => 'vdisk_count', value => 'arrayVDiskCount_absolute', template => '%s', label_extra_instance => 1, { label => 'vdisk_count', value => 'arrayVDiskCount_absolute', template => '%s', label_extra_instance => 1,
instance_use => 'arrayId_absolute', min => 0 }, instance_use => 'arrayId_absolute', min => 0 },
], ],
} }
}, },
]; ];
} }
sub prefix_output { sub prefix_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Array '" . $options{instance_value}->{arrayId} . "' "; return "Array '" . $options{instance_value}->{arrayId} . "' ";
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
"warning-status:s" => { name => 'warning_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{status} =~ /degraded/i' }, "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /degraded/i' },
}); });
return $self; return $self;
} }
my $mapping = { my $mapping = {
arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, 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' }, 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' }, 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'; my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex,
nothing_quit => 1); nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
$self->{global}->{$result->{arrayId}} = $result; $self->{global}->{$result->{arrayId}} = $result;
} }
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Check arrays status. Check arrays status.
=over 8 =over 8
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.
'status' can be: 'online', 'offline', 'excluded', 'degraded'. 'status' can be: 'online', 'offline', 'excluded', 'degraded'.
=item B<--critical-status> =item B<--critical-status>
Set critical threshold for status (Default: '%{status} =~ /degraded/i'). Set critical threshold for status (Default: '%{status} =~ /degraded/i').
'status' can be: 'online', 'offline', 'excluded', 'degraded'. 'status' can be: 'online', 'offline', 'excluded', 'degraded'.
=item B<--warning-vdisk-count> =item B<--warning-vdisk-count>
Threshold warning for VDisks count. Threshold warning for VDisks count.
=item B<--critical-vdisk-count> =item B<--critical-vdisk-count>
Threshold critical for VDisks count. Threshold critical for VDisks count.
=back =back
=cut =cut

View File

@ -1,183 +1,183 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package storage::ibm::fs900::snmp::mode::arraysusage; package storage::ibm::fs900::snmp::mode::arraysusage;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub custom_usage_perfdata { sub custom_usage_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
my $extra_label = ''; my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0);
$self->{output}->perfdata_add(label => "used" . $extra_label, $self->{output}->perfdata_add(label => "used" . $extra_label,
unit => 'B', unit => 'B',
value => $self->{result_values}->{used}, value => $self->{result_values}->{used},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-usage'), warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-usage'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-usage'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-usage'),
min => 0, min => 0,
max => $self->{result_values}->{total}, max => $self->{result_values}->{total},
); );
} }
sub custom_usage_threshold { sub custom_usage_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used_prct}, my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{used_prct},
threshold => [ { label => 'critical-usage', exit_litteral => 'critical' }, threshold => [ { label => 'critical-usage', exit_litteral => 'critical' },
{ label => 'warning-usage', exit_litteral => 'warning' } ]); { label => 'warning-usage', exit_litteral => 'warning' } ]);
return $exit; return $exit;
} }
sub custom_usage_output { sub custom_usage_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($total, $total_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); 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 ($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 ($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}); 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; return $msg;
} }
sub custom_usage_calc { sub custom_usage_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
($self->{result_values}->{total}, $self->{result_values}->{total_unit}) = (split(' ', $options{new_datas}->{$self->{instance} . '_arrayCapacity'})); ($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}->{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}->{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}->{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}->{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}->{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}->{used_prct} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total};
$self->{result_values}->{free_prct} = 100 - $self->{result_values}->{used_prct}; $self->{result_values}->{free_prct} = 100 - $self->{result_values}->{used_prct};
return 0; return 0;
} }
sub change_to_bytes { sub change_to_bytes {
my ($self, %options) = @_; my ($self, %options) = @_;
my $value = ''; my $value = '';
if ($options{unit} =~ /KiB*/i) { if ($options{unit} =~ /KiB*/i) {
$value = $options{value} * 1024; $value = $options{value} * 1024;
} elsif ($options{unit} =~ /MiB*/i) { } elsif ($options{unit} =~ /MiB*/i) {
$value = $options{value} * 1024 * 1024; $value = $options{value} * 1024 * 1024;
} elsif ($options{unit} =~ /GiB*/i) { } elsif ($options{unit} =~ /GiB*/i) {
$value = $options{value} * 1024 * 1024 * 1024; $value = $options{value} * 1024 * 1024 * 1024;
} elsif ($options{unit} =~ /TiB*/i) { } elsif ($options{unit} =~ /TiB*/i) {
$value = $options{value} * 1024 * 1024 * 1024 * 1024; $value = $options{value} * 1024 * 1024 * 1024 * 1024;
} }
return $value return $value
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays usage are ok" } { name => 'global', type => 1, cb_prefix_output => 'prefix_output', message_multiple => "All arrays usage are ok" }
]; ];
$self->{maps_counters}->{global} = [ $self->{maps_counters}->{global} = [
{ label => 'usage', set => { { label => 'usage', set => {
key_values => [ { name => 'arrayCapacity' }, { name => 'arrayCapacityUsed' }, { name => 'arrayCapacityFree' }, { name => 'arrayId' } ], key_values => [ { name => 'arrayCapacity' }, { name => 'arrayCapacityUsed' }, { name => 'arrayCapacityFree' }, { name => 'arrayId' } ],
closure_custom_calc => $self->can('custom_usage_calc'), closure_custom_calc => $self->can('custom_usage_calc'),
closure_custom_output => $self->can('custom_usage_output'), closure_custom_output => $self->can('custom_usage_output'),
closure_custom_perfdata => $self->can('custom_usage_perfdata'), closure_custom_perfdata => $self->can('custom_usage_perfdata'),
closure_custom_threshold_check => $self->can('custom_usage_threshold'), closure_custom_threshold_check => $self->can('custom_usage_threshold'),
} }
}, },
]; ];
} }
sub prefix_output { sub prefix_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Array '" . $options{instance_value}->{arrayId} . "' "; return "Array '" . $options{instance_value}->{arrayId} . "' ";
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
}); });
return $self; return $self;
} }
my $mapping = { my $mapping = {
arrayId => { oid => '.1.3.6.1.4.1.2.6.255.1.1.1.52.1.2' }, 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' }, 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' }, 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' }, 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'; my $oid_arrayIndex = '.1.3.6.1.4.1.2.6.255.1.1.1.52.1';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex, my $snmp_result = $options{snmp}->get_table(oid => $oid_arrayIndex,
nothing_quit => 1); nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{arrayId}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
$self->{global}->{$result->{arrayId}} = $result; $self->{global}->{$result->{arrayId}} = $result;
} }
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Check arrays usage. Check arrays usage.
=over 8 =over 8
=item B<--warning-usage> =item B<--warning-usage>
Threshold warning. Threshold warning.
=item B<--critical-usage> =item B<--critical-usage>
Threshold critical. Threshold critical.
=back =back
=cut =cut

View File

@ -1,205 +1,205 @@
# #
# Copyright 2019 Centreon (http://www.centreon.com/) # Copyright 2019 Centreon (http://www.centreon.com/)
# #
# Centreon is a full-fledged industry-strength solution that meets # Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for # the needs in IT infrastructure and application monitoring for
# service performance. # service performance.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
# You may obtain a copy of the License at # You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, # distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
package storage::ibm::fs900::snmp::mode::fcusage; package storage::ibm::fs900::snmp::mode::fcusage;
use base qw(centreon::plugins::templates::counter); use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
sub custom_bandwidth_perfdata { sub custom_bandwidth_perfdata {
my ($self, %options) = @_; my ($self, %options) = @_;
my $extra_label = ''; my $extra_label = '';
$extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); $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, $self->{output}->perfdata_add(label => lc($self->{result_values}->{type}) . "_bandwidth" . $extra_label,
unit => 'B/s', unit => 'B/s',
value => $self->{result_values}->{bandwidth}, value => $self->{result_values}->{bandwidth},
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . lc($self->{result_values}->{type}) . '-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'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth'),
); );
} }
sub custom_bandwidth_threshold { sub custom_bandwidth_threshold {
my ($self, %options) = @_; my ($self, %options) = @_;
my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{bandwidth}, my $exit = $self->{perfdata}->threshold_check(value => $self->{result_values}->{bandwidth},
threshold => [ { label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'critical' }, threshold => [ { label => 'critical-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'critical' },
{ label => 'warning-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'warning' } ]); { label => 'warning-' . lc($self->{result_values}->{type}) . '-bandwidth', exit_litteral => 'warning' } ]);
return $exit; return $exit;
} }
sub custom_bandwidth_output { sub custom_bandwidth_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my ($bandwidth, $unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{bandwidth}); 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); my $msg = sprintf("%s bandwidth: %s %s/s", $self->{result_values}->{type}, $bandwidth, $unit);
return $msg; return $msg;
} }
sub custom_bandwidth_calc { sub custom_bandwidth_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_fcObject'}; $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_fcObject'};
$self->{result_values}->{type} = $options{extra_options}->{type}; $self->{result_values}->{type} = $options{extra_options}->{type};
$self->{result_values}->{bandwidth} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{bandwidth}} *1024 * 1024; $self->{result_values}->{bandwidth} = $options{new_datas}->{$self->{instance} . '_' . $options{extra_options}->{bandwidth}} *1024 * 1024;
return 0; return 0;
} }
sub set_counters { sub set_counters {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{maps_counters_type} = [ $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 } } { 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} = [ $self->{maps_counters}->{global} = [
{ label => 'read-bandwidth', set => { { label => 'read-bandwidth', set => {
key_values => [ { name => 'fcReadBW' }, { name => 'fcObject' } ], key_values => [ { name => 'fcReadBW' }, { name => 'fcObject' } ],
closure_custom_calc => $self->can('custom_bandwidth_calc'), closure_custom_calc => $self->can('custom_bandwidth_calc'),
closure_custom_calc_extra_options => { type => 'Read', bandwidth => 'fcReadBW' }, closure_custom_calc_extra_options => { type => 'Read', bandwidth => 'fcReadBW' },
closure_custom_output => $self->can('custom_bandwidth_output'), closure_custom_output => $self->can('custom_bandwidth_output'),
closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'), closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'),
closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'), closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'),
} }
}, },
{ label => 'write-bandwidth', set => { { label => 'write-bandwidth', set => {
key_values => [ { name => 'fcWriteBW' }, { name => 'fcObject' } ], key_values => [ { name => 'fcWriteBW' }, { name => 'fcObject' } ],
closure_custom_calc => $self->can('custom_bandwidth_calc'), closure_custom_calc => $self->can('custom_bandwidth_calc'),
closure_custom_calc_extra_options => { type => 'Write', bandwidth => 'fcWriteBW' }, closure_custom_calc_extra_options => { type => 'Write', bandwidth => 'fcWriteBW' },
closure_custom_output => $self->can('custom_bandwidth_output'), closure_custom_output => $self->can('custom_bandwidth_output'),
closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'), closure_custom_perfdata => $self->can('custom_bandwidth_perfdata'),
closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'), closure_custom_threshold_check => $self->can('custom_bandwidth_threshold'),
} }
}, },
{ label => 'read-iops', set => { { label => 'read-iops', set => {
key_values => [ { name => 'fcReadIOPS' }, { name => 'fcObject' } ], key_values => [ { name => 'fcReadIOPS' }, { name => 'fcObject' } ],
output_template => 'Read IOPS: %s iops', output_template => 'Read IOPS: %s iops',
perfdatas => [ perfdatas => [
{ label => 'read_iops', value => 'fcReadIOPS_absolute', template => '%s', label_extra_instance => 1, { label => 'read_iops', value => 'fcReadIOPS_absolute', template => '%s', label_extra_instance => 1,
instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, instance_use => 'fcObject_absolute', min => 0, unit => 'iops' },
], ],
} }
}, },
{ label => 'write-iops', set => { { label => 'write-iops', set => {
key_values => [ { name => 'fcWriteIOPS' }, { name => 'fcObject' } ], key_values => [ { name => 'fcWriteIOPS' }, { name => 'fcObject' } ],
output_template => 'Write IOPS: %s iops', output_template => 'Write IOPS: %s iops',
perfdatas => [ perfdatas => [
{ label => 'write_iops', value => 'fcWriteIOPS_absolute', template => '%s', label_extra_instance => 1, { label => 'write_iops', value => 'fcWriteIOPS_absolute', template => '%s', label_extra_instance => 1,
instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, instance_use => 'fcObject_absolute', min => 0, unit => 'iops' },
], ],
} }
}, },
{ label => 'read-queue-depth', set => { { label => 'read-queue-depth', set => {
key_values => [ { name => 'fcReadQueueDepth' }, { name => 'fcObject' } ], key_values => [ { name => 'fcReadQueueDepth' }, { name => 'fcObject' } ],
output_template => 'Read queue depth: %s', output_template => 'Read queue depth: %s',
perfdatas => [ perfdatas => [
{ label => 'read_queue_depth', value => 'fcReadQueueDepth_absolute', template => '%s', label_extra_instance => 1, { label => 'read_queue_depth', value => 'fcReadQueueDepth_absolute', template => '%s', label_extra_instance => 1,
instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, instance_use => 'fcObject_absolute', min => 0, unit => 'iops' },
], ],
} }
}, },
{ label => 'write-queue-depth', set => { { label => 'write-queue-depth', set => {
key_values => [ { name => 'fcWriteQueueDepth' }, { name => 'fcObject' } ], key_values => [ { name => 'fcWriteQueueDepth' }, { name => 'fcObject' } ],
output_template => 'Write queue depth: %s', output_template => 'Write queue depth: %s',
perfdatas => [ perfdatas => [
{ label => 'write_queue_depth', value => 'fcWriteQueueDepth_absolute', template => '%s', label_extra_instance => 1, { label => 'write_queue_depth', value => 'fcWriteQueueDepth_absolute', template => '%s', label_extra_instance => 1,
instance_use => 'fcObject_absolute', min => 0, unit => 'iops' }, instance_use => 'fcObject_absolute', min => 0, unit => 'iops' },
], ],
} }
}, },
]; ];
} }
sub prefix_output { sub prefix_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Fibre channel '" . $options{instance_value}->{fcObject} . "' "; return "Fibre channel '" . $options{instance_value}->{fcObject} . "' ";
} }
sub new { sub new {
my ($class, %options) = @_; my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options); my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0'; $self->{version} = '1.0';
$options{options}->add_options(arguments => $options{options}->add_options(arguments =>
{ {
}); });
return $self; return $self;
} }
my $mapping = { my $mapping = {
fcObject => { oid => '.1.3.6.1.4.1.2.6.255.1.1.2.1.1.2' }, 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 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 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' }, 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' }, 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' }, 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' }, 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'; my $oid_fcTableEntry = '.1.3.6.1.4.1.2.6.255.1.1.2.1.1';
sub manage_selection { sub manage_selection {
my ($self, %options) = @_; my ($self, %options) = @_;
my $snmp_result = $options{snmp}->get_table(oid => $oid_fcTableEntry, my $snmp_result = $options{snmp}->get_table(oid => $oid_fcTableEntry,
nothing_quit => 1); nothing_quit => 1);
$self->{global} = {}; $self->{global} = {};
foreach my $oid (keys %{$snmp_result}) { foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{fcObject}->{oid}\.(.*)$/); next if ($oid !~ /^$mapping->{fcObject}->{oid}\.(.*)$/);
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
$self->{global}->{$result->{fcObject}} = $result; $self->{global}->{$result->{fcObject}} = $result;
} }
} }
1; 1;
__END__ __END__
=head1 MODE =head1 MODE
Check fibre channels usage. Check fibre channels usage.
=over 8 =over 8
=item B<--warning-*> =item B<--warning-*>
Threshold warning. Threshold warning.
Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'. Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'.
=item B<--critical-*> =item B<--critical-*>
Threshold critical. Threshold critical.
Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'. Can be: 'read-bandwidth', 'write-bandwidth', 'read-iops', 'write-iops', 'read-queue-depth', 'write-queue-depth'.
=back =back
=cut =cut