Merge branch 'master' of https://github.com/centreon/centreon-plugins
This commit is contained in:
commit
6ad3301af9
|
@ -22,7 +22,6 @@ package apps::automation::ansible::cli::custom::cli;
|
|||
|
||||
use strict;
|
||||
use warnings;
|
||||
use DateTime;
|
||||
use JSON::XS;
|
||||
|
||||
sub new {
|
||||
|
@ -51,7 +50,6 @@ sub new {
|
|||
"command:s" => { name => 'command', default => 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible' },
|
||||
"command-path:s" => { name => 'command_path' },
|
||||
"command-options:s" => { name => 'command_options', default => '' },
|
||||
"proxyurl:s" => { name => 'proxyurl' },
|
||||
});
|
||||
}
|
||||
$options{options}->add_help(package => __PACKAGE__, sections => 'CLI OPTIONS', once => 1);
|
||||
|
@ -87,11 +85,6 @@ sub set_defaults {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
if (defined($self->{option_results}->{proxyurl}) && $self->{option_results}->{proxyurl} ne '') {
|
||||
$ENV{HTTP_PROXY} = $self->{option_results}->{proxyurl};
|
||||
$ENV{HTTPS_PROXY} = $self->{option_results}->{proxyurl};
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -106,7 +99,8 @@ sub execute {
|
|||
sudo => $self->{option_results}->{sudo},
|
||||
command => $self->{option_results}->{command},
|
||||
command_path => $self->{option_results}->{command_path},
|
||||
command_options => $options{cmd_options});
|
||||
command_options => $options{cmd_options}
|
||||
);
|
||||
|
||||
my $raw_results;
|
||||
|
||||
|
@ -122,7 +116,7 @@ sub execute {
|
|||
return $raw_results;
|
||||
}
|
||||
|
||||
sub ansible_list_host_set_cmd {
|
||||
sub ansible_list_hosts_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
@ -132,10 +126,10 @@ sub ansible_list_host_set_cmd {
|
|||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub ansible_list_host {
|
||||
sub ansible_list_hosts {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->ansible_list_host_set_cmd(%options);
|
||||
my $cmd_options = $self->ansible_list_hosts_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
|
@ -165,7 +159,7 @@ Use 'sudo' to execute the command.
|
|||
|
||||
=item B<--command>
|
||||
|
||||
Command to get information (Default: 'ansible').
|
||||
Command to get information (Default: 'ANSIBLE_LOAD_CALLBACK_PLUGINS=true ANSIBLE_STDOUT_CALLBACK=json ansible').
|
||||
Can be changed if you have output in a file.
|
||||
|
||||
=item B<--command-path>
|
||||
|
@ -176,10 +170,6 @@ Command path (Default: none).
|
|||
|
||||
Command options (Default: none).
|
||||
|
||||
=item B<--proxyurl>
|
||||
|
||||
Proxy URL if any
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
|
|
@ -53,7 +53,7 @@ sub run {
|
|||
|
||||
$disco_stats->{start_time} = time();
|
||||
|
||||
my $result = $options{custom}->ansible_list_host(host_pattern => $self->{option_results}->{host_pattern});
|
||||
my $result = $options{custom}->ansible_list_hosts(host_pattern => $self->{option_results}->{host_pattern});
|
||||
|
||||
$disco_stats->{end_time} = time();
|
||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||
|
@ -103,6 +103,14 @@ Resources discovery.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--host-pattern>
|
||||
|
||||
Specify host pattern to look for (Default: 'all').
|
||||
|
||||
=item B<--prettify>
|
||||
|
||||
Prettify JSON output.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -124,7 +124,7 @@ sub execute {
|
|||
return $raw_results;
|
||||
}
|
||||
|
||||
sub tower_list_host_set_cmd {
|
||||
sub tower_list_hosts_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
@ -133,14 +133,60 @@ sub tower_list_host_set_cmd {
|
|||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
$cmd_options .= " --group '$options{group}'" if (defined($options{group}) && $options{group} ne '');
|
||||
$cmd_options .= " --inventory '$options{inventory}'" if (defined($options{inventory}) && $options{inventory} ne '');
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub tower_list_host {
|
||||
sub tower_list_hosts {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->tower_list_host_set_cmd(%options);
|
||||
my $cmd_options = $self->tower_list_hosts_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
sub tower_list_inventories_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "inventory list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub tower_list_inventories {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->tower_list_inventories_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
}
|
||||
|
||||
sub tower_list_projects_set_cmd {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');
|
||||
|
||||
my $cmd_options = "project list --insecure --all-pages --format json";
|
||||
$cmd_options .= " --tower-host '$self->{host}'" if (defined($self->{host}) && $self->{host} ne '');
|
||||
$cmd_options .= " --tower-username '$self->{username}'" if (defined($self->{username}) && $self->{username} ne '');
|
||||
$cmd_options .= " --tower-password '$self->{password}'" if (defined($self->{password}) && $self->{password} ne '');
|
||||
|
||||
return $cmd_options;
|
||||
}
|
||||
|
||||
sub tower_list_projects {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
my $cmd_options = $self->tower_list_projects_set_cmd(%options);
|
||||
my $raw_results = $self->execute(cmd_options => $cmd_options);
|
||||
|
||||
return $raw_results;
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
#
|
||||
# Copyright 2019 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 apps::automation::ansible::tower::mode::dashboard;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output'},
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'hosts-total', nlabel => 'hosts.total.count', set => {
|
||||
key_values => [ { name => 'hosts_total' } ],
|
||||
output_template => 'Hosts Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'hosts_total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'hosts-failed', nlabel => 'hosts.failed.count', set => {
|
||||
key_values => [ { name => 'hosts_failed' },{ name => 'hosts_total' } ],
|
||||
output_template => 'Hosts Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'hosts_failed_absolute', template => '%d', min => 0,
|
||||
max => 'hosts_total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'inventories-total', nlabel => 'inventories.total.count', set => {
|
||||
key_values => [ { name => 'inventories_total' } ],
|
||||
output_template => 'Inventories Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'inventories_total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'inventories-sync-failed', nlabel => 'inventories.sync.failed.count', set => {
|
||||
key_values => [ { name => 'inventories_sync_failed' }, { name => 'inventories_total' } ],
|
||||
output_template => 'Inventories Sync Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'inventories_sync_failed_absolute', template => '%d', min => 0,
|
||||
max => 'inventories_total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'projects-total', nlabel => 'projects.total.count', set => {
|
||||
key_values => [ { name => 'projects_total' } ],
|
||||
output_template => 'Projects Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'projects_total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'projects-sync-failed', nlabel => 'projects.sync.failed.count', set => {
|
||||
key_values => [ { name => 'projects_sync_failed' }, { name => 'projects_total' } ],
|
||||
output_template => 'Projects Sync Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'projects_sync_failed_absolute', template => '%d', min => 0,
|
||||
max => 'projects_total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = {
|
||||
hosts_total => 0, hosts_failed => 0,
|
||||
inventories_total => 0, inventories_sync_failed => 0,
|
||||
projects_total => 0, projects_sync_failed => 0
|
||||
};
|
||||
|
||||
my $hosts = $options{custom}->tower_list_hosts();
|
||||
$self->{global}->{hosts_total} = $hosts->{count};
|
||||
foreach my $host (@{$hosts->{results}}) {
|
||||
$self->{global}->{hosts_failed}++ if ($host->{has_active_failures});
|
||||
}
|
||||
|
||||
my $inventories = $options{custom}->tower_list_inventories();
|
||||
$self->{global}->{inventories_total} = $inventories->{count};
|
||||
foreach my $inventory (@{$inventories->{results}}) {
|
||||
$self->{global}->{inventories_sync_failed}++ if ($inventory->{inventory_sources_with_failures} > 0);
|
||||
}
|
||||
|
||||
my $projects = $options{custom}->tower_list_projects();
|
||||
$self->{global}->{projects_total} = $projects->{count};
|
||||
foreach my $project (@{$projects->{results}}) {
|
||||
$self->{global}->{projects_sync_failed}++ if ($project->{status} =~ /failed|canceled/);
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check several counters available through Tower dashboard.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--warning-hosts-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--critical-hosts-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--warning-inventories-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=item B<--critical-inventories-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=item B<--warning-projects-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=item B<--critical-projects-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'sync-failed'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -33,6 +33,8 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"group" => { name => 'group' },
|
||||
"inventory" => { name => 'inventory' },
|
||||
"prettify" => { name => 'prettify' },
|
||||
});
|
||||
|
||||
|
@ -52,7 +54,10 @@ sub run {
|
|||
|
||||
$disco_stats->{start_time} = time();
|
||||
|
||||
my $hosts = $options{custom}->tower_list_host();
|
||||
my $hosts = $options{custom}->tower_list_hosts(
|
||||
group => $self->{option_results}->{group},
|
||||
inventory => $self->{option_results}->{inventory}
|
||||
);
|
||||
|
||||
$disco_stats->{end_time} = time();
|
||||
$disco_stats->{duration} = $disco_stats->{end_time} - $disco_stats->{start_time};
|
||||
|
@ -100,6 +105,18 @@ Resources discovery.
|
|||
|
||||
=over 8
|
||||
|
||||
=item B<--group>
|
||||
|
||||
Specify host group.
|
||||
|
||||
=item B<--inventory>
|
||||
|
||||
Specify host inventory.
|
||||
|
||||
=item B<--prettify>
|
||||
|
||||
Prettify JSON output.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
||||
|
|
|
@ -0,0 +1,220 @@
|
|||
#
|
||||
# Copyright 2019 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 apps::automation::ansible::tower::mode::inventorystatistics;
|
||||
|
||||
use base qw(centreon::plugins::templates::counter);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub set_counters {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{maps_counters_type} = [
|
||||
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output', cb_init => 'skip_global' },
|
||||
{ name => 'inventories', type => 1, cb_prefix_output => 'prefix_output_inventories',
|
||||
message_multiple => 'All inventories statistics are ok' },
|
||||
];
|
||||
|
||||
$self->{maps_counters}->{global} = [
|
||||
{ label => 'total', nlabel => 'inventories.total.count', set => {
|
||||
key_values => [ { name => 'total' } ],
|
||||
output_template => 'Total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_absolute', template => '%d', min => 0 },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'failed', nlabel => 'inventories.failed.count', set => {
|
||||
key_values => [ { name => 'failed' }, { name => 'total' } ],
|
||||
output_template => 'Failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'failed_absolute', template => '%d', min => 0,
|
||||
max => 'total_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
$self->{maps_counters}->{inventories} = [
|
||||
{ label => 'hosts-total', nlabel => 'inventory.hosts.total.count', set => {
|
||||
key_values => [ { name => 'total_hosts' }, { name => 'display' } ],
|
||||
output_template => 'Hosts total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_hosts_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'hosts-failed', nlabel => 'inventory.hosts.failed.count', set => {
|
||||
key_values => [ { name => 'hosts_with_active_failures' }, { name => 'total_hosts' },
|
||||
{ name => 'display' } ],
|
||||
output_template => 'Hosts failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'hosts_with_active_failures_absolute', template => '%d',
|
||||
min => 0, max => 'total_hosts_absolute', label_extra_instance => 1,
|
||||
instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'sources-total', nlabel => 'inventory.sources.total.count', set => {
|
||||
key_values => [ { name => 'total_inventory_sources' }, { name => 'display' } ],
|
||||
output_template => 'Sources total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_inventory_sources_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'sources-failed', nlabel => 'inventory.sources.failed.count', set => {
|
||||
key_values => [ { name => 'inventory_sources_with_failures' }, { name => 'total_inventory_sources' },
|
||||
{ name => 'display' } ],
|
||||
output_template => 'Sources failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'inventory_sources_with_failures_absolute', template => '%d',
|
||||
min => 0, max => 'total_inventory_sources_absolute', label_extra_instance => 1,
|
||||
instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'groups-total', nlabel => 'inventory.groups.total.count', set => {
|
||||
key_values => [ { name => 'total_groups' }, { name => 'display' } ],
|
||||
output_template => 'Groups total: %d',
|
||||
perfdatas => [
|
||||
{ value => 'total_groups_absolute', template => '%d',
|
||||
min => 0, label_extra_instance => 1, instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
{ label => 'groups-failed', nlabel => 'inventory.groups.failed.count', set => {
|
||||
key_values => [ { name => 'groups_with_active_failures' }, { name => 'total_groups' },
|
||||
{ name => 'display' } ],
|
||||
output_template => 'Groups failed: %d',
|
||||
perfdatas => [
|
||||
{ value => 'groups_with_active_failures_absolute', template => '%d',
|
||||
min => 0, max => 'total_groups_absolute', label_extra_instance => 1,
|
||||
instance_use => 'display_absolute' },
|
||||
],
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
sub skip_global {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
scalar(keys %{$self->{inventories}}) > 1 ? return(0) : return(1);
|
||||
}
|
||||
|
||||
sub prefix_output {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Inventories ";
|
||||
}
|
||||
|
||||
sub prefix_output_inventories {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
return "Inventory '" . $options{instance_value}->{display} . "' ";
|
||||
}
|
||||
|
||||
sub new {
|
||||
my ($class, %options) = @_;
|
||||
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
|
||||
bless $self, $class;
|
||||
|
||||
$self->{version} = '1.0';
|
||||
$options{options}->add_options(arguments => {
|
||||
"filter-inventory" => { name => 'filter_inventory' },
|
||||
});
|
||||
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
$self->SUPER::init(%options);
|
||||
}
|
||||
|
||||
sub manage_selection {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{global} = { total => 0, failed => 0 };
|
||||
|
||||
my $inventories = $options{custom}->tower_list_inventories();
|
||||
|
||||
$self->{global}->{total} = $inventories->{count};
|
||||
|
||||
foreach my $inventory (@{$inventories->{results}}) {
|
||||
next if (defined($self->{option_results}->{filter_inventory}) && $self->{option_results}->{filter_inventory} ne ''
|
||||
&& $inventory->{name} !~ /$self->{option_results}->{filter_inventory}/);
|
||||
|
||||
$self->{inventories}->{$inventory->{id}} = {
|
||||
display => $inventory->{name},
|
||||
total_hosts => $inventory->{total_hosts},
|
||||
hosts_with_active_failures => $inventory->{hosts_with_active_failures},
|
||||
total_inventory_sources => $inventory->{total_inventory_sources},
|
||||
inventory_sources_with_failures => $inventory->{inventory_sources_with_failures},
|
||||
total_groups => $inventory->{total_groups},
|
||||
groups_with_active_failures => $inventory->{groups_with_active_failures},
|
||||
};
|
||||
|
||||
$self->{global}->{failed}++ if ($inventory->{has_active_failures});
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 MODE
|
||||
|
||||
Check inventories statistics.
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--filter-inventory>
|
||||
|
||||
Filter inventory name (Can use regexp).
|
||||
|
||||
=item B<--warning-inventories-*-count>
|
||||
|
||||
Threshold warning.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--critical-inventories-*-count>
|
||||
|
||||
Threshold critical.
|
||||
Can be: 'total', 'failed'.
|
||||
|
||||
=item B<--warning-instance-inventory.*.*.count>
|
||||
|
||||
Threshold warning.
|
||||
Can be 'hosts', 'sources', 'groups' and 'total', 'failed'.
|
||||
|
||||
=item B<--critical-instance-inventory.*.*.count>
|
||||
|
||||
Threshold critical.
|
||||
Can be 'hosts', 'sources', 'groups' and 'total', 'failed'
|
||||
'indexes'.
|
||||
|
||||
=back
|
||||
|
||||
=cut
|
|
@ -31,11 +31,12 @@ sub new {
|
|||
|
||||
$self->{version} = '1.0';
|
||||
%{$self->{modes}} = (
|
||||
'discovery' => 'apps::automation::ansible::tower::mode::discovery',
|
||||
'dashboard' => 'apps::automation::ansible::tower::mode::dashboard',
|
||||
'discovery' => 'apps::automation::ansible::tower::mode::discovery',
|
||||
'inventory-statistics' => 'apps::automation::ansible::tower::mode::inventorystatistics',
|
||||
);
|
||||
|
||||
$self->{custom_modes}{towercli} = 'apps::automation::ansible::tower::custom::towercli';
|
||||
$self->{custom_modes}{api} = 'apps::automation::ansible::tower::custom::api';
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,17 +83,13 @@ sub set_defaults {
|
|||
sub check_options {
|
||||
my ($self, %options) = @_;
|
||||
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : undef;
|
||||
$self->{hostname} = (defined($self->{option_results}->{hostname})) ? $self->{option_results}->{hostname} : 'api.openweathermap.org';
|
||||
$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->{url_path} = (defined($self->{option_results}->{url_path})) ? $self->{option_results}->{url_path} : '/data/2.5';
|
||||
$self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10;
|
||||
$self->{api_token} = (defined($self->{option_results}->{api_token})) ? $self->{option_results}->{api_token} : '';
|
||||
|
||||
if (!defined($self->{hostname}) || $self->{hostname} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --hostname option.");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($self->{api_token}) || $self->{api_token} eq '') {
|
||||
$self->{output}->add_option_msg(short_msg => "Need to specify --api-token option.");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -150,7 +146,7 @@ sub request_api {
|
|||
$self->{output}->add_option_msg(short_msg => "Cannot decode json response: $@");
|
||||
$self->{output}->option_exit();
|
||||
}
|
||||
if (!defined($decoded->{cod}) || $decoded->{cod} != 200) {
|
||||
if (!defined($decoded->{code}) || $decoded->{code} != 200) {
|
||||
$self->{output}->output_add(long_msg => "Error message : " . $decoded->{errorDetails}, debug => 1);
|
||||
$self->{output}->add_option_msg(short_msg => "API return error code '" . $decoded->{result} . "' (add --debug option for detailed message)");
|
||||
$self->{output}->option_exit();
|
||||
|
@ -164,21 +160,21 @@ __END__
|
|||
|
||||
=head1 NAME
|
||||
|
||||
Rudder Rest API
|
||||
OpenWeatherMap Rest API
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Rudder Rest API custom mode
|
||||
OpenWeatherMap Rest API custom mode
|
||||
|
||||
=head1 REST API OPTIONS
|
||||
|
||||
Rudder Rest API
|
||||
OpenWeatherMap Rest API
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<--hostname>
|
||||
|
||||
Rudder API hostname (api.openweathermap.org
|
||||
OpenWeatherMap API hostname (Default: 'api.openweathermap.org')
|
||||
|
||||
=item B<--port>
|
||||
|
||||
|
|
Loading…
Reference in New Issue