diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/array.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/array.pm new file mode 100644 index 000000000..f8c1eb39a --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/array.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::array; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsarray=========="; lsarray -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking arrays"); + $self->{components}->{array} = {name => 'arrays', total => 0, skip => 0}; + return if ($self->check_filter(section => 'array')); + + return if ($self->{results} !~ /==========lsarray==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'array', instance => $_->{mdisk_id})); + $self->{components}->{array}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("array '%s' status is '%s' [instance: %s].", + $_->{mdisk_name}, $_->{status}, + $_->{mdisk_id} + )); + my $exit = $self->get_severity(label => 'default', section => 'array', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Array '%s' status is '%s'", + $_->{mdisk_name}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/drive.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/drive.pm new file mode 100644 index 000000000..e0afd26d8 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/drive.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::drive; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsdrive=========="; lsdrive -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking drives"); + $self->{components}->{drive} = {name => 'drives', total => 0, skip => 0}; + return if ($self->check_filter(section => 'drive')); + + return if ($self->{results} !~ /==========lsdrive==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'drive', instance => $_->{id})); + $self->{components}->{drive}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("drive '%s' status is '%s' [instance: %s].", + $_->{id}, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(label => 'default', section => 'drive', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Drive '%s' status is '%s'", + $_->{id}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosure.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosure.pm new file mode 100644 index 000000000..c581613b0 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosure.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::enclosure; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsenclosure=========="; lsenclosure -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking enclosures"); + $self->{components}->{enclosure} = {name => 'enclosures', total => 0, skip => 0}; + return if ($self->check_filter(section => 'enclosure')); + + return if ($self->{results} !~ /==========lsenclosure==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'enclosure', instance => $_->{id})); + $self->{components}->{enclosure}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("enclosure '%s' status is '%s' [instance: %s].", + $_->{id}, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(label => 'default', section => 'enclosure', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Enclosure '%s' status is '%s'", + $_->{id}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurebattery.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurebattery.pm new file mode 100644 index 000000000..75d38992a --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurebattery.pm @@ -0,0 +1,61 @@ +# +# 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::ibm::storwize::ssh::mode::components::enclosurebattery; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsenclosurebattery=========="; lsenclosurebattery -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking enclosure batteries"); + $self->{components}->{enclosurebattery} = {name => 'enclosure batteries', total => 0, skip => 0}; + return if ($self->check_filter(section => 'enclosurebattery')); + + return if ($self->{results} !~ /==========lsenclosurebattery==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + my $instance = $_->{enclosure_id} . '.' . $_->{battery_id}; + next if ($self->check_filter(section => 'enclosurebattery', instance => $instance)); + $self->{components}->{enclosurebattery}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("enclosure battery '%s' status is '%s' [instance: %s].", + $instance, $_->{status}, + $instance + )); + my $exit = $self->get_severity(label => 'default', section => 'enclosurebattery', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Enclosure battery '%s' status is '%s'", + $instance, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurecanister.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurecanister.pm new file mode 100644 index 000000000..41c78f2a2 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurecanister.pm @@ -0,0 +1,61 @@ +# +# 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::ibm::storwize::ssh::mode::components::enclosurecanister; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsenclosurecanister=========="; lsenclosurecanister -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking enclosure canisters"); + $self->{components}->{enclosurecanister} = {name => 'enclosure canisters', total => 0, skip => 0}; + return if ($self->check_filter(section => 'enclosurecanister')); + + return if ($self->{results} !~ /==========lsenclosurecanister==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + my $instance = $_->{enclosure_id} . '.' . $_->{canister_id}; + next if ($self->check_filter(section => 'enclosurecanister', instance => $instance)); + $self->{components}->{enclosurecanister}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("enclosure canister '%s' status is '%s' [instance: %s].", + $instance, $_->{status}, + $instance + )); + my $exit = $self->get_severity(label => 'default', section => 'enclosurecanister', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Enclosure canister '%s' status is '%s'", + $instance, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurepsu.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurepsu.pm new file mode 100644 index 000000000..6f56b3b03 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/enclosurepsu.pm @@ -0,0 +1,61 @@ +# +# 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::ibm::storwize::ssh::mode::components::enclosurepsu; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsenclosurepsu=========="; lsenclosurepsu -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking enclosure psus"); + $self->{components}->{enclosurepsu} = {name => 'enclosure psus', total => 0, skip => 0}; + return if ($self->check_filter(section => 'enclosurepsu')); + + return if ($self->{results} !~ /==========lsenclosurepsu==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + my $instance = $_->{enclosure_id} . '.' . $_->{PSU_id}; + next if ($self->check_filter(section => 'enclosurepsu', instance => $instance)); + $self->{components}->{enclosurepsu}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("enclosure power supply '%s' status is '%s' [instance: %s].", + $instance, $_->{status}, + $instance + )); + my $exit = $self->get_severity(label => 'default', section => 'enclosurepsu', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Enclosure power supply '%s' status is '%s'", + $instance, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/host.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/host.pm new file mode 100644 index 000000000..d82f3ee8a --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/host.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::host; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lshost=========="; lshost -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking hosts"); + $self->{components}->{host} = {name => 'hosts', total => 0, skip => 0}; + return if ($self->check_filter(section => 'host')); + + return if ($self->{results} !~ /==========lshost==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'host', instance => $_->{id})); + $self->{components}->{host}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("host '%s' status is '%s' [instance: %s].", + $_->{name}, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(label => 'default', section => 'host', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Host '%s' status is '%s'", + $_->{name}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/mdisk.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/mdisk.pm new file mode 100644 index 000000000..fc6423cad --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/mdisk.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::mdisk; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsmdisk=========="; lsmdisk -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking mdisks"); + $self->{components}->{mdisk} = {name => 'mdisks', total => 0, skip => 0}; + return if ($self->check_filter(section => 'mdisk')); + + return if ($self->{results} !~ /==========lsmdisk==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'mdisk', instance => $_->{id})); + $self->{components}->{mdisk}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("mdisk '%s' status is '%s' [instance: %s].", + $_->{name}, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(section => 'mdisk', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("MDisk '%s' status is '%s'", + $_->{name}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/node.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/node.pm new file mode 100644 index 000000000..cfef24c4b --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/node.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::node; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsnode=========="; lsnode -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking nodes"); + $self->{components}->{node} = {name => 'nodes', total => 0, skip => 0}; + return if ($self->check_filter(section => 'node')); + + return if ($self->{results} !~ /==========lsnode==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'node', instance => $_->{id})); + $self->{components}->{node}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("node '%s' status is '%s' [instance: %s].", + $_->{name}, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(label => 'default', section => 'node', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Node '%s' status is '%s'", + $_->{name}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/portfc.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/portfc.pm new file mode 100644 index 000000000..9d7d6c4e1 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/portfc.pm @@ -0,0 +1,61 @@ +# +# 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::ibm::storwize::ssh::mode::components::portfc; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsportfc=========="; lsportfc -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking portfc"); + $self->{components}->{portfc} = {name => 'portfc', total => 0, skip => 0}; + return if ($self->check_filter(section => 'portfc')); + + return if ($self->{results} !~ /==========lsportfc==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'portfc', instance => $_->{id})); + $self->{components}->{portfc}->{total}++; + + my $name = $_->{node_name} . "." . $_->{WWPN}; + $self->{output}->output_add(long_msg => sprintf("portfc '%s' status is '%s' [instance: %s].", + $name, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(section => 'portfc', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("PortFC '%s' status is '%s'", + $name, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/portsas.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/portsas.pm new file mode 100644 index 000000000..34b9f838f --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/portsas.pm @@ -0,0 +1,61 @@ +# +# 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::ibm::storwize::ssh::mode::components::portsas; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsportsas=========="; lsportsas -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking portsas"); + $self->{components}->{portsas} = {name => 'portsas', total => 0, skip => 0}; + return if ($self->check_filter(section => 'portsas')); + + return if ($self->{results} !~ /==========lsportsas==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'portsas', instance => $_->{id})); + $self->{components}->{portsas}->{total}++; + + my $name = $_->{node_name} . "." . $_->{WWPN}; + $self->{output}->output_add(long_msg => sprintf("port sas '%s' status is '%s' [instance: %s].", + $name, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(section => 'portsas', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Port sas '%s' status is '%s'", + $name, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/quorum.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/quorum.pm new file mode 100644 index 000000000..bf01dcf97 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/quorum.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::quorum; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsquorum=========="; lsquorum -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking quorums"); + $self->{components}->{quorum} = {name => 'quorums', total => 0, skip => 0}; + return if ($self->check_filter(section => 'quorum')); + + return if ($self->{results} !~ /==========lsquorum==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'quorum', instance => $_->{quorum_index})); + $self->{components}->{quorum}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("quorum '%s' status is '%s' [instance: %s].", + $_->{controller_name}, $_->{status}, + $_->{quorum_index} + )); + my $exit = $self->get_severity(label => 'default', section => 'quorum', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Quorum '%s' status is '%s'", + $_->{controller_name}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/systemstats.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/systemstats.pm new file mode 100644 index 000000000..180f460e4 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/systemstats.pm @@ -0,0 +1,63 @@ +# +# 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::ibm::storwize::ssh::mode::components::systemstats; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lssystemstats=========="; lssystemstats ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking systemstats"); + $self->{components}->{systemstats} = {name => 'systemstats', total => 0, skip => 0}; + return if ($self->check_filter(section => 'systemstats')); + + return if ($self->{results} !~ /==========lssystemstats==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => '\s+'); + foreach (@$result) { + next if ($self->check_filter(section => 'systemstats', instance => $_->{stat_name})); + $self->{components}->{systemstats}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("system stat '%s' value is '%s' [instance: %s].", + $_->{stat_name}, $_->{stat_current}, + $_->{stat_name} + )); + my ($exit, $warn, $crit, $checked) = $self->get_severity_numeric(section => 'systemstats', instance => $_->{stat_name}, value => $_->{stat_current}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("System stat '%s' value is '%s'", $_->{stat_name}, $_->{stat_current})); + } + $self->{output}->perfdata_add(label => "sstat_" . $_->{stat_name}, + value => $_->{stat_current}, + warning => $warn, + critical => $crit); + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/components/vdisk.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/vdisk.pm new file mode 100644 index 000000000..9fe8c51f3 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/components/vdisk.pm @@ -0,0 +1,60 @@ +# +# 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::ibm::storwize::ssh::mode::components::vdisk; + +use strict; +use warnings; + +sub load { + my ($self) = @_; + + $self->{ssh_commands} .= 'echo "==========lsvdisk=========="; lsvdisk -delim : ; echo "===============";'; +} + +sub check { + my ($self) = @_; + + $self->{output}->output_add(long_msg => "Checking vdisks"); + $self->{components}->{vdisk} = {name => 'vdisks', total => 0, skip => 0}; + return if ($self->check_filter(section => 'vdisk')); + + return if ($self->{results} !~ /==========lsvdisk==.*?\n(.*?)==============/msi); + my $content = $1; + + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + next if ($self->check_filter(section => 'vdisk', instance => $_->{id})); + $self->{components}->{vdisk}->{total}++; + + $self->{output}->output_add(long_msg => sprintf("vdisk '%s' status is '%s' [instance: %s].", + $_->{name}, $_->{status}, + $_->{id} + )); + my $exit = $self->get_severity(label => 'default', section => 'vdisk', value => $_->{status}); + if (!$self->{output}->is_status(value => $exit, compare => 'ok', litteral => 1)) { + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("Vdisk '%s' status is '%s'", + $_->{name}, $_->{status})); + } + } +} + +1; \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm new file mode 100644 index 000000000..2ad93623a --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/eventlog.pm @@ -0,0 +1,219 @@ +# +# 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::ibm::storwize::ssh::mode::eventlog; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use DateTime; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "filter-event-id:s" => { name => 'filter_event_id' }, + "filter-message:s" => { name => 'filter_message' }, + "retention:s" => { name => 'retention' }, + "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 => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } + + my $last_timestamp = ''; + if (defined($self->{option_results}->{retention}) && $self->{option_results}->{retention} =~ /^\d+$/) { + # by default UTC timezone used + my $dt = DateTime->from_epoch(epoch => time() - $self->{option_results}->{retention}); + my $dt_format = sprintf("%d%02d%02d%02d%02d%02d", substr($dt->year(), 2), $dt->month(), $dt->day(), $dt->hour(), $dt->minute(), $dt->second()); + $last_timestamp = 'last_timestamp>=' . $dt_format . ":"; + } + $self->{ls_command} = "lseventlog -message no -alert yes -filtervalue '${last_timestamp}fixed=no' -delim :"; +} + +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; +} + +sub run { + my ($self, %options) = @_; + + my $content = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ls_command} . " ; exit ;", + 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); + my $result = $self->get_hasharray(content => $content, delim => ':'); + + my ($num_eventlog_checked, $num_errors) = (0, 0); + foreach (@$result) { + $num_eventlog_checked++; + if (defined($self->{option_results}->{filter_message}) && $self->{option_results}->{filter_message} ne '' && + $_->{description} !~ /$self->{option_results}->{filter_message}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{description} . "': no matching filter description.", debug => 1); + next; + } + if (defined($self->{option_results}->{filter_event_id}) && $self->{option_results}->{filter_event_id} ne '' && + $_->{event_id} !~ /$self->{option_results}->{filter_event_id}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{event_id} . "': no matching filter event id.", debug => 1); + next; + } + + $self->{output}->output_add(long_msg => sprintf("%s : %s - %s", + scalar(localtime($_->{last_timestamp})), + $_->{event_id}, $_->{description} + ) + ); + $num_errors++; + } + + $self->{output}->output_add(long_msg => sprintf("Number of message checked: %s", $num_eventlog_checked)); + my $exit = $self->{perfdata}->threshold_check(value => $num_errors, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->output_add(severity => $exit, + short_msg => sprintf("%d problem detected (use verbose for more details)", $num_errors) + ); + $self->{output}->perfdata_add(label => 'problems', + value => $num_errors, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check eventlogs. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--filter-event-id> + +Filter on event id. + +=item B<--filter-message> + +Filter on event message. + +=item B<--retention> + +Get eventlog of X last seconds. For the last minutes: --retention=60 + +=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: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=cut + \ No newline at end of file diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm new file mode 100644 index 000000000..89a1bb718 --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/hardware.pm @@ -0,0 +1,214 @@ +# +# 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::ibm::storwize::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} = + '^(array|drive|enclosure|enclosurebattery|enclosurecanister|enclosurepsu|host|portfc|portsas|vdisk|node|quorum|mdisk)$'; + $self->{regexp_threshold_numeric_check_section_option} = '^(systemstats)$'; + + $self->{cb_hook2} = 'ssh_execute'; + + $self->{thresholds} = { + default => [ + ['online', 'OK'], + ['offline', 'CRITICAL'], + ['degraded', 'WARNING'], + ['excluded', 'OK'], # lsarray + ['mask', 'OK'], # lshost + ], + portfc => [ + ['active', 'OK'], + ['inactive_unconfigured', 'OK'], + ['.*', 'CRITICAL'], + ], + portsas => [ + ['online', 'OK'], + ['offline_unconfigured', 'OK'], + ['excluded', 'OK'], + ['offline', 'CRITICAL'], + ['degraded', 'WARNING'], + ], + mdisk => [ + ['online', 'OK'], + ['excluded', 'OK'], + ['offline', 'CRITICAL'], + ['degraded_paths', 'WARNING'], + ['degraded_ports', 'WARNING'], + ['degraded', 'WARNING'], + ], + }; + + $self->{components_path} = 'storage::ibm::storwize::ssh::mode::components'; + $self->{components_module} = ['array', 'drive', 'enclosure', 'enclosurebattery', 'enclosurecanister', + 'enclosurepsu', 'host', 'portfc', 'portsas', 'vdisk', 'node', 'quorum', 'mdisk', 'systemstats']; +} + +sub ssh_execute { + my ($self, %options) = @_; + + $self->{results} = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands} . " exit ;", + 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); +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options, no_absent => 1); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "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 => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + }); + + $self->{ssh_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. + +=over 8 + +=item B<--component> + +Which component to check (Default: '.*'). +Can be: 'array', 'drive'. + +=item B<--filter> + +Exclude some parts (comma seperated list) (Example: --filter=host --filter=enclosurecanister) +Can also exclude specific instance: --filter=host,10 + +=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='host,.*,OK,degraded' + +=item B<--warning> + +Set warning threshold for temperatures (syntax: type,regexp,threshold) +Example: --warning='systemstats,cpu_pc,30' + +=item B<--critical> + +Set critical threshold for temperatures (syntax: type,regexp,threshold) +Example: --critical='systemstats,cpu_pc,40' + +=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: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=cut diff --git a/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm b/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm new file mode 100644 index 000000000..19437b6be --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/mode/poolusage.pm @@ -0,0 +1,349 @@ +# +# 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::ibm::storwize::ssh::mode::poolusage; + +use base qw(centreon::plugins::templates::counter); + +use strict; +use warnings; + +my $instance_mode; + +sub custom_status_threshold { + my ($self, %options) = @_; + my $status = 'ok'; + my $message; + + eval { + local $SIG{__WARN__} = sub { $message = $_[0]; }; + local $SIG{__DIE__} = sub { $message = $_[0]; }; + + if (defined($instance_mode->{option_results}->{critical_status}) && $instance_mode->{option_results}->{critical_status} ne '' && + eval "$instance_mode->{option_results}->{critical_status}") { + $status = 'critical'; + } elsif (defined($instance_mode->{option_results}->{warning_status}) && $instance_mode->{option_results}->{warning_status} ne '' && + eval "$instance_mode->{option_results}->{warning_status}") { + $status = 'warning'; + } + }; + if (defined($message)) { + $self->{output}->output_add(long_msg => 'filter status issue: ' . $message); + } + + return $status; +} + +sub custom_status_output { + my ($self, %options) = @_; + + my $msg = 'status : ' . $self->{result_values}->{status}; + return $msg; +} + +sub custom_status_calc { + my ($self, %options) = @_; + + $self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_status'}; + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + return 0; +} + +sub custom_usage_perfdata { + my ($self, %options) = @_; + + my $label = 'used'; + my $value_perf = $self->{result_values}->{used}; + if (defined($instance_mode->{option_results}->{free})) { + $label = 'free'; + $value_perf = $self->{result_values}->{free}; + } + my $extra_label = ''; + $extra_label = '_' . $self->{result_values}->{display} if (!defined($options{extra_instance}) || $options{extra_instance} != 0); + my %total_options = (); + if ($instance_mode->{option_results}->{units} eq '%') { + $total_options{total} = $self->{result_values}->{total}; + $total_options{cast_int} = 1; + } + + $self->{output}->perfdata_add(label => $label . $extra_label, unit => 'B', + value => $value_perf, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning-' . $self->{label}, %total_options), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical-' . $self->{label}, %total_options), + min => 0, max => $self->{result_values}->{total}); +} + +sub custom_usage_threshold { + my ($self, %options) = @_; + + my ($exit, $threshold_value); + $threshold_value = $self->{result_values}->{used}; + $threshold_value = $self->{result_values}->{free} if (defined($instance_mode->{option_results}->{free})); + if ($instance_mode->{option_results}->{units} eq '%') { + $threshold_value = $self->{result_values}->{prct_used}; + $threshold_value = $self->{result_values}->{prct_free} if (defined($instance_mode->{option_results}->{free})); + } + $exit = $self->{perfdata}->threshold_check(value => $threshold_value, threshold => [ { label => 'critical-' . $self->{label}, exit_litteral => 'critical' }, { label => 'warning-'. $self->{label}, exit_litteral => 'warning' } ]); + return $exit; +} + +sub custom_usage_output { + my ($self, %options) = @_; + + my ($total_size_value, $total_size_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{total}); + my ($total_used_value, $total_used_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{used}); + my ($total_free_value, $total_free_unit) = $self->{perfdata}->change_bytes(value => $self->{result_values}->{free}); + my $msg = sprintf("Usage Total: %s Used: %s (%.2f%%) Free: %s (%.2f%%)", + $total_size_value . " " . $total_size_unit, + $total_used_value . " " . $total_used_unit, $self->{result_values}->{prct_used}, + $total_free_value . " " . $total_free_unit, $self->{result_values}->{prct_free}); + return $msg; +} + +sub custom_usage_calc { + my ($self, %options) = @_; + + $self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; + $self->{result_values}->{total} = $options{new_datas}->{$self->{instance} . '_total'}; + $self->{result_values}->{used} = $options{new_datas}->{$self->{instance} . '_used'}; + $self->{result_values}->{free} = $self->{result_values}->{total} - $self->{result_values}->{used}; + $self->{result_values}->{prct_used} = $self->{result_values}->{used} * 100 / $self->{result_values}->{total}; + $self->{result_values}->{prct_free} = 100 - $self->{result_values}->{prct_used}; + + return 0; +} + +sub set_counters { + my ($self, %options) = @_; + + $self->{maps_counters_type} = [ + { name => 'pool', type => 1, cb_prefix_output => 'prefix_pool_output', message_multiple => 'All pools are ok' } + ]; + + $self->{maps_counters}->{pool} = [ + { label => 'status', threshold => 0, set => { + key_values => [ { name => 'status' }, { name => 'display' } ], + closure_custom_calc => $self->can('custom_status_calc'), + closure_custom_output => $self->can('custom_status_output'), + closure_custom_perfdata => sub { return 0; }, + closure_custom_threshold_check => $self->can('custom_status_threshold'), + } + }, + { label => 'usage', set => { + key_values => [ { name => 'display' }, { name => 'used' }, { name => 'total' } ], + closure_custom_calc => $self->can('custom_usage_calc'), + closure_custom_output => $self->can('custom_usage_output'), + closure_custom_perfdata => $self->can('custom_usage_perfdata'), + closure_custom_threshold_check => $self->can('custom_usage_threshold'), + } + }, + ]; +} + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "filter-name:s" => { name => 'filter_name' }, + "warning-status:s" => { name => 'warning_status', default => '%{status} =~ /degraded/i' }, + "critical-status:s" => { name => 'critical_status', default => '%{status} =~ /offline/i' }, + "units:s" => { name => 'units', default => '%' }, + "free" => { name => 'free' }, + "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 => 30 }, + "sudo" => { name => 'sudo' }, + "command:s" => { name => 'command' }, + "command-path:s" => { name => 'command_path' }, + "command-options:s" => { name => 'command_options' }, + }); + + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::check_options(%options); + + if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { + $self->{option_results}->{remote} = 1; + } + $instance_mode = $self; + $self->change_macros(); +} + +sub prefix_pool_output { + my ($self, %options) = @_; + + return "Pool '" . $options{instance_value}->{display} . "' "; +} + +sub change_macros { + my ($self, %options) = @_; + + foreach (('warning_status', 'critical_status')) { + if (defined($self->{option_results}->{$_})) { + $self->{option_results}->{$_} =~ s/%\{(.*?)\}/\$self->{result_values}->{$1}/g; + } + } +} + +sub manage_selection { + my ($self, %options) = @_; + + $self->{pool} = {}; + my $content = centreon::plugins::misc::execute(output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : "lsmdiskgrp -delim : -bytes ; exit ;", + 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); + my $result = $self->get_hasharray(content => $content, delim => ':'); + foreach (@$result) { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $_->{name} !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "skipping '" . $_->{name} . "': no matching filter.", debug => 1); + next; + } + + $self->{pool}->{$_->{id}} = { display => $_->{name}, + status => $_->{status}, + total => $_->{used_capacity} + $_->{free_capacity}, used => $_->{used_capacity} + }; + } + + if (scalar(keys %{$self->{pool}}) <= 0) { + $self->{output}->add_option_msg(short_msg => "No pool found."); + $self->{output}->option_exit(); + } +} + +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 pool usages. + +=over 8 + +=item B<--filter-counters> + +Only display some counters (regexp can be used). +Example: --filter-counters='^status$' + +=item B<--filter-name> + +Filter pool name (can be a regexp). + +=item B<--warning-status> + +Set warning threshold for status (Default: '%{status} =~ /degraded/i'). +Can used special variables like: %{status}, %{display} + +=item B<--critical-status> + +Set critical threshold for status (Default: '%{status} =~ /offline/i'). +Can used special variables like: %{status}, %{display} + +=item B<--warning-*> + +Threshold warning. +Can be: 'usage'. + +=item B<--critical-*> + +Threshold critical. +Can be: 'usage'. + +=item B<--units> + +Units of thresholds (Default: '%') ('%', 'B'). + +=item B<--free> + +Thresholds are on free space left. + +=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: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information. Used it you have output in a file. + +=item B<--command-path> + +Command path. + +=item B<--command-options> + +Command options. + +=back + +=cut diff --git a/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm b/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm new file mode 100644 index 000000000..59d8ca86a --- /dev/null +++ b/centreon-plugins/storage/ibm/storwize/ssh/plugin.pm @@ -0,0 +1,50 @@ +# +# Copyright 2016 Centreon (http://www.centreon.com/) +# +# Centreon is a full-fledged industry-strength solution that meets +# the needs in IT infrastructure and application monitoring for +# service performance. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package storage::ibm::storwize::ssh::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + %{$self->{modes}} = ( + 'components' => 'storage::ibm::storwize::ssh::mode::hardware', + 'pool-usage' => 'storage::ibm::storwize::ssh::mode::poolusage', + 'eventlog' => 'storage::ibm::storwize::ssh::mode::eventlog', + ); + + return $self; +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check IBM Storwize (v3700, v5000, v7000, SAN Volume Controller) in SSH. + +=cut