From 949ce9e84c0ea5d18082bbd51dde416c3fd7b1fe Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Mon, 29 Aug 2016 14:25:04 +0200 Subject: [PATCH] + add hp storeonce ssh plugin --- storage/hp/storeonce/ssh/custom/custom.pm | 170 ++++++++++++++++++ .../storeonce/ssh/mode/components/hardware.pm | 97 ++++++++++ .../ssh/mode/components/serviceset.pm | 85 +++++++++ storage/hp/storeonce/ssh/mode/hardware.pm | 126 +++++++++++++ storage/hp/storeonce/ssh/plugin.pm | 49 +++++ 5 files changed, 527 insertions(+) create mode 100644 storage/hp/storeonce/ssh/custom/custom.pm create mode 100644 storage/hp/storeonce/ssh/mode/components/hardware.pm create mode 100644 storage/hp/storeonce/ssh/mode/components/serviceset.pm create mode 100644 storage/hp/storeonce/ssh/mode/hardware.pm create mode 100644 storage/hp/storeonce/ssh/plugin.pm diff --git a/storage/hp/storeonce/ssh/custom/custom.pm b/storage/hp/storeonce/ssh/custom/custom.pm new file mode 100644 index 000000000..8e1f2118a --- /dev/null +++ b/storage/hp/storeonce/ssh/custom/custom.pm @@ -0,0 +1,170 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::hp::storeonce::ssh::custom::custom; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub new { + my ($class, %options) = @_; + my $self = {}; + bless $self, $class; + + if (!defined($options{output})) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if (!defined($options{options})) { + $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); + $options{output}->option_exit(); + } + + if (!defined($options{noptions})) { + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "ssh-option:s@" => { name => 'ssh_option' }, + "ssh-path:s" => { name => 'ssh_path' }, + "ssh-command:s" => { name => 'ssh_command', default => 'ssh' }, + "timeout:s" => { name => 'timeout', default => 45 }, + "command:s" => { name => 'command' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + }); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + + return $self; +} + +sub set_options { + my ($self, %options) = @_; + + $self->{option_results} = $options{option_results}; +} + +sub set_defaults { + my ($self, %options) = @_; + + foreach (keys %{$options{default}}) { + if ($_ eq $self->{mode}) { + for (my $i = 0; $i < scalar(@{$options{default}->{$_}}); $i++) { + foreach my $opt (keys %{$options{default}->{$_}[$i]}) { + if (!defined($self->{option_results}->{$opt}[$i])) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + + $self->{option_results}->{remote} = 1; + if (defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '') { + $self->{option_results}->{remote} = 0; + } elsif (!defined($self->{option_results}->{hostname}) || $self->{option_results}->{hostname} eq '') { + $self->{output}->add_option_msg(short_msg => "Need to set hostname option."); + $self->{output}->option_exit(); + } + + return 0; +} + +############## +# Specific methods +############## +sub execute_command { + my ($self, %options) = @_; + + $self->{ssh_commands} = ''; + foreach (@{$options{commands}}) { + $self->{ssh_commands} .= "$_\n"; + } + return centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + ssh_pipe => 1, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands} . "exit\n", + command_path => $self->{option_results}->{command_path}, + command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef); +} + +1; + +__END__ + +=head1 NAME + +ssh + +=head1 SYNOPSIS + +my ssh + +=head1 SSH OPTIONS + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 45). + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/storage/hp/storeonce/ssh/mode/components/hardware.pm b/storage/hp/storeonce/ssh/mode/components/hardware.pm new file mode 100644 index 000000000..4c86dd885 --- /dev/null +++ b/storage/hp/storeonce/ssh/mode/components/hardware.pm @@ -0,0 +1,97 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::hp::storeonce::ssh::mode::components::hardware; + +use strict; +use warnings; +use centreon::plugins::misc; + +sub load { + my ($self) = @_; + + #Name + #------------------------------------------------------------------ + #hp80239e8624-1 + # Dev-id = 31343337-3338-5A43-3235-323430375631 + # Status = OK + # message = - + # type = server + # model = ProLiant DL380p Gen8 + # serialNumber = CZ252407V1 + # firmwareVersion = P70 07/01/2015 + # location = - + # warrantySerialNumber = CZ35283EK4 + # warrantyPartNumber = BB896A + # SKU = 734183-B21 + # + #hp80239e8624-2 + # Dev-id = 31343337-3338-5A43-3235-323431303648 + # Status = OK + # message = - + # type = server + # model = ProLiant DL380p Gen8 + # serialNumber = CZ2524106H + # firmwareVersion = P70 07/01/2015 + # location = - + # warrantySerialNumber = CZ35283EK4 + # warrantyPartNumber = BB896A + # SKU = 734183-B21 + + push @{$self->{commands}}, "hardware show status details"; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking hardwares"); + $self->{components}->{hardware} = {name => 'hardwares', total => 0, skip => 0}; + return if ($self->check_filter(section => 'hardware')); + + return if ($self->{result} !~ />\s*hardware show status details(.*?)\n>/msi); + my $content = $1; + + while ($content =~ /^(\S+[^\n]*?)\n\s+(.*?)\n\s*?\n/msgi) { + my ($name, $details) = (centreon::plugins::misc::trim($1), $2); + + $details =~ /type.*?=\s*(.*?)\n/msi; + my $type = centreon::plugins::misc::trim($1); + $details =~ /Status.*?=\s*(.*?)\n/msi; + my $status = centreon::plugins::misc::trim($1); + $details =~ /Dev-id.*?=\s*(.*?)\n/msi; + my $dev_id = centreon::plugins::misc::trim($1); + + next if ($self->check_filter(section => 'hardware', instance => $type . '.' . $dev_id)); + $self->{components}->{hardware}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("%s '%s' status is '%s' [instance: %s, name: %s].", + $type, $dev_id, $status, + $type . '.' . $dev_id, $name + )); + my $exit = $self->get_severity(section => 'hardware', instance => $type . '.' . $dev_id, value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%s '%s' status is '%s'", + $type, $dev_id, $status)); + } + } +} + +1; \ No newline at end of file diff --git a/storage/hp/storeonce/ssh/mode/components/serviceset.pm b/storage/hp/storeonce/ssh/mode/components/serviceset.pm new file mode 100644 index 000000000..a6d44aac1 --- /dev/null +++ b/storage/hp/storeonce/ssh/mode/components/serviceset.pm @@ -0,0 +1,85 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::hp::storeonce::ssh::mode::components::serviceset; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + #Service Set 1 Status + #------------- ------- + #Overall : Running + #StoreOnce Subsystem : Running + #Virtual Tape : Running + #NAS : Running + #StoreOnce Catalyst : Running + #Replication : Running + #Housekeeping : Running + # + #Service Set 2 Status + #------------- ------- + #Overall : Running + #StoreOnce Subsystem : Running + #Virtual Tape : Running + #NAS : Running + #StoreOnce Catalyst : Running + #Replication : Running + #Housekeeping : Running + + push @{$self->{commands}}, "serviceset show status"; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking service sets"); + $self->{components}->{serviceset} = {name => 'service sets', total => 0, skip => 0}; + return if ($self->check_filter(section => 'serviceset')); + + return if ($self->{result} !~ />\s*serviceset show status(.*?)\n>/msi); + my $content = $1; + + while ($content =~ /^Service Set (\d+).*?\n(.*?)\n\s*?\n/msgi) { + my ($num, $details) = ($1, $2); + + while ($details =~ /^([^\n]+?):\s*(.*?)\n/msgi) { + my ($instance, $status) = (centreon::plugins::misc::trim($1), centreon::plugins::misc::trim($2)); + + next if ($self->check_filter(section => 'serviceset', instance => $num . '.' . $instance)); + $self->{components}->{serviceset}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("service set '%s' %s status is '%s' [instance: %s].", + $num, $instance, $status, + $num . '.' . $instance + )); + my $exit = $self->get_severity(section => 'serviceset', instance => $num . '.' . $instance, value => $status); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("service set '%s' %s status is '%s'", + $num, $instance, $status)); + } + } + } +} + +1; \ No newline at end of file diff --git a/storage/hp/storeonce/ssh/mode/hardware.pm b/storage/hp/storeonce/ssh/mode/hardware.pm new file mode 100644 index 000000000..428207e54 --- /dev/null +++ b/storage/hp/storeonce/ssh/mode/hardware.pm @@ -0,0 +1,126 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::hp::storeonce::ssh::mode::hardware; + +use base qw(centreon::plugins::templates::hardware); + +use strict; +use warnings; + +sub set_system { + my ($self, %options) = @_; + + $self->{regexp_threshold_overload_check_section_option} = + '^(hardware|serviceset)$'; + + $self->{cb_hook2} = 'ssh_execute'; + + $self->{thresholds} = { + hardware => [ + ['ok', 'OK'], + ['failed', 'CRITICAL'], + ['degraded', 'WARNING'], + ['missing', 'OK'], + ], + serviceset => [ + ['running', 'OK'], + ['fault', 'CRITICAL'], + ], + }; + + $self->{components_path} = 'storage::hp::storeonce::ssh::mode::components'; + $self->{components_module} = ['hardware', 'serviceset']; +} + +sub ssh_execute { + my ($self, %options) = @_; + + ($self->{result}, $self->{exit_code}) = $options{custom}->execute_command(commands => $self->{commands}); +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1, no_performance => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + }); + + $self->{commands} = []; + return $self; +} + +sub get_hasharray { + my ($self, %options) = @_; + + my $result = []; + return $result if ($options{content} eq ''); + my ($header, @lines) = split /\n/, $options{content}; + my @header_names = split /$options{delim}/, $header; + + for (my $i = 0; $i <= $#lines; $i++) { + my @content = split /$options{delim}/, $lines[$i]; + my $data = {}; + for (my $j = 0; $j <= $#header_names; $j++) { + $data->{$header_names[$j]} = $content[$j]; + } + push @$result, $data; + } + + return $result; +} + +1; + +__END__ + +=head1 MODE + +Check components (hardware and service set). + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'hardware', 'serviceset'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=hardware --filter=serviceset) +Can also exclude specific instance: --filter=hardware,storageCluster + +=item B<--no-component> + +Return an error if no compenents are checked. +If total (with skipped) is 0. (Default: 'critical' returns). + +=item B<--threshold-overload> + +Set to overload default threshold values (syntax: section,[instance,]status,regexp) +It used before default thresholds (order stays). +Example: --threshold-overload='hardware,networkSwitch,OK,degraded' + +=back + +=cut diff --git a/storage/hp/storeonce/ssh/plugin.pm b/storage/hp/storeonce/ssh/plugin.pm new file mode 100644 index 000000000..cdd48867e --- /dev/null +++ b/storage/hp/storeonce/ssh/plugin.pm @@ -0,0 +1,49 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::hp::storeonce::ssh::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'components' => 'storage::hp::storeonce::ssh::mode::hardware', + ); + + $self->{custom_modes}{ssh} = 'storage::hp::storeonce::ssh::custom::custom'; + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check HP Storeonce in SSH. + +=cut