| 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 apps::automation::ansible::cli::custom::cli; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::script_custom::cli); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
use JSON::XS; |
| 28 |
|
| 29 |
sub execute_command { |
| 30 |
my ($self, %options) = @_; |
| 31 |
|
| 32 |
my ($stdout, $exit_code) = $self->SUPER::execute_command( |
| 33 |
%options, |
| 34 |
no_quit => 1 |
| 35 |
); |
| 36 |
if ($exit_code != 0 && $exit_code != 4) { |
| 37 |
$self->{output}->add_option_msg(short_msg => "Command error: $stdout"); |
| 38 |
$self->{output}->option_exit(); |
| 39 |
} |
| 40 |
|
| 41 |
my $raw_results; |
| 42 |
eval { |
| 43 |
$raw_results = JSON::XS->new->utf8->decode($stdout); |
| 44 |
}; |
| 45 |
if ($@) { |
| 46 |
$self->{output}->output_add(long_msg => $stdout, debug => 1); |
| 47 |
$self->{output}->add_option_msg(short_msg => "Cannot decode response (add --debug option to display returned content)"); |
| 48 |
$self->{output}->option_exit(); |
| 49 |
} |
| 50 |
|
| 51 |
return $raw_results; |
| 52 |
} |
| 53 |
|
| 54 |
1; |
| 55 |
|
| 56 |
__END__ |
| 57 |
|
| 58 |
=head1 NAME |
| 59 |
|
| 60 |
Ansible CLI |
| 61 |
|
| 62 |
=head1 CLI OPTIONS |
| 63 |
|
| 64 |
Ansible CLI |
| 65 |
|
| 66 |
=head1 DESCRIPTION |
| 67 |
|
| 68 |
B<custom>. |
| 69 |
|
| 70 |
=cut |