enh ansible tower plugin
This commit is contained in:
parent
33ff112c4a
commit
2c9f4bf992
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue