| 1 |
# |
| 2 |
# Copyright 2024 Centreon (http://www.centreon.com/) |
| 3 |
# |
| 4 |
# Centreon is a full-fledged industry-strength solution that meets |
| 5 |
# the needs in IT infrastructure and application monitoring for |
| 6 |
# service performance. |
| 7 |
# |
| 8 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 |
# you may not use this file except in compliance with the License. |
| 10 |
# You may obtain a copy of the License at |
| 11 |
# |
| 12 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 13 |
# |
| 14 |
# Unless required by applicable law or agreed to in writing, software |
| 15 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 16 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 |
# See the License for the specific language governing permissions and |
| 18 |
# limitations under the License. |
| 19 |
# |
| 20 |
|
| 21 |
package storage::hp::3par::ssh::custom::custom; |
| 22 |
|
| 23 |
use strict; |
| 24 |
use warnings; |
| 25 |
use centreon::plugins::ssh; |
| 26 |
use centreon::plugins::misc; |
| 27 |
|
| 28 |
sub new { |
| 29 |
my ($class, %options) = @_; |
| 30 |
my $self = {}; |
| 31 |
bless $self, $class; |
| 32 |
|
| 33 |
if (!defined($options{output})) { |
| 34 |
print "Class Custom: Need to specify 'output' argument.\n"; |
| 35 |
exit 3; |
| 36 |
} |
| 37 |
if (!defined($options{options})) { |
| 38 |
$options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); |
| 39 |
$options{output}->option_exit(); |
| 40 |
} |
| 41 |
|
| 42 |
if (!defined($options{noptions})) { |
| 43 |
$options{options}->add_options(arguments => { |
| 44 |
'hostname:s' => { name => 'hostname' }, |
| 45 |
'timeout:s' => { name => 'timeout', default => 45 }, |
| 46 |
'command:s' => { name => 'command' }, |
| 47 |
'command-path:s' => { name => 'command_path' }, |
| 48 |
'command-options:s' => { name => 'command_options' } |
| 49 |
}); |
| 50 |
} |
| 51 |
$options{options}->add_help(package => __PACKAGE__, sections => 'SSH OPTIONS', once => 1); |
| 52 |
|
| 53 |
$self->{output} = $options{output}; |
| 54 |
$self->{ssh} = centreon::plugins::ssh->new(%options); |
| 55 |
|
| 56 |
return $self; |
| 57 |
} |
| 58 |
|
| 59 |
sub set_options { |
| 60 |
my ($self, %options) = @_; |
| 61 |
|
| 62 |
$self->{option_results} = $options{option_results}; |
| 63 |
} |
| 64 |
|
| 65 |
sub set_defaults {} |
| 66 |
|
| 67 |
sub check_options { |
| 68 |
my ($self, %options) = @_; |
| 69 |
|
| 70 |
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { |
| 71 |
$self->{ssh}->check_options(option_results => $self->{option_results}); |
| 72 |
} |
| 73 |
|
| 74 |
centreon::plugins::misc::check_security_command( |
| 75 |
output => $self->{output}, |
| 76 |
command => $self->{option_results}->{command}, |
| 77 |
command_options => $self->{option_results}->{command_options}, |
| 78 |
command_path => $self->{option_results}->{command_path} |
| 79 |
); |
| 80 |
|
| 81 |
return 0; |
| 82 |
} |
| 83 |
|
| 84 |
############## |
| 85 |
# Specific methods |
| 86 |
############## |
| 87 |
sub execute_command { |
| 88 |
my ($self, %options) = @_; |
| 89 |
|
| 90 |
$self->{ssh_commands} = ''; |
| 91 |
my $append = ''; |
| 92 |
foreach (@{$options{commands}}) { |
| 93 |
$self->{ssh_commands} .= $append . " $_"; |
| 94 |
$append = ';'; |
| 95 |
} |
| 96 |
|
| 97 |
my $content; |
| 98 |
if (defined($self->{option_results}->{hostname}) && $self->{option_results}->{hostname} ne '') { |
| 99 |
($content) = $self->{ssh}->execute( |
| 100 |
ssh_pipe => 1, |
| 101 |
hostname => $self->{option_results}->{hostname}, |
| 102 |
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $self->{ssh_commands}, |
| 103 |
command_path => $self->{option_results}->{command_path}, |
| 104 |
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef, |
| 105 |
timeout => $self->{option_results}->{timeout} |
| 106 |
); |
| 107 |
} else { |
| 108 |
if (!defined($self->{option_results}->{command}) || $self->{option_results}->{command} eq '') { |
| 109 |
$self->{output}->add_option_msg(short_msg => 'please set --hostname option for ssh connection (or --command for local)'); |
| 110 |
$self->{output}->option_exit(); |
| 111 |
} |
| 112 |
($content) = centreon::plugins::misc::execute( |
| 113 |
ssh_pipe => 1, |
| 114 |
output => $self->{output}, |
| 115 |
options => { timeout => $self->{option_results}->{timeout} }, |
| 116 |
command => $self->{option_results}->{command}, |
| 117 |
command_path => $self->{option_results}->{command_path}, |
| 118 |
command_options => defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '' ? $self->{option_results}->{command_options} : undef |
| 119 |
); |
| 120 |
} |
| 121 |
|
| 122 |
return $content; |
| 123 |
} |
| 124 |
|
| 125 |
1; |
| 126 |
|
| 127 |
__END__ |
| 128 |
|
| 129 |
=head1 NAME |
| 130 |
|
| 131 |
ssh |
| 132 |
|
| 133 |
=head1 SYNOPSIS |
| 134 |
|
| 135 |
my ssh |
| 136 |
|
| 137 |
=head1 SSH OPTIONS |
| 138 |
|
| 139 |
=over 8 |
| 140 |
|
| 141 |
=item B<--hostname> |
| 142 |
|
| 143 |
Hostname to query. |
| 144 |
|
| 145 |
=item B<--timeout> |
| 146 |
|
| 147 |
Timeout in seconds for the command (default: 45). |
| 148 |
|
| 149 |
=item B<--command> |
| 150 |
|
| 151 |
Command to get information. Used it you have output in a file. |
| 152 |
|
| 153 |
=item B<--command-path> |
| 154 |
|
| 155 |
Command path. |
| 156 |
|
| 157 |
=item B<--command-options> |
| 158 |
|
| 159 |
Command options. |
| 160 |
|
| 161 |
=back |
| 162 |
|
| 163 |
=head1 DESCRIPTION |
| 164 |
|
| 165 |
B<custom>. |
| 166 |
|
| 167 |
=cut |