| 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::tower::mode::inventories; |
| 22 |
|
| 23 |
use base qw(centreon::plugins::templates::counter); |
| 24 |
|
| 25 |
use strict; |
| 26 |
use warnings; |
| 27 |
|
| 28 |
sub prefix_output_global { |
| 29 |
my ($self, %options) = @_; |
| 30 |
|
| 31 |
return 'Inventories '; |
| 32 |
} |
| 33 |
|
| 34 |
sub prefix_output_inventories { |
| 35 |
my ($self, %options) = @_; |
| 36 |
|
| 37 |
return "Inventory '" . $options{instance_value}->{display} . "' "; |
| 38 |
} |
| 39 |
|
| 40 |
sub set_counters { |
| 41 |
my ($self, %options) = @_; |
| 42 |
|
| 43 |
$self->{maps_counters_type} = [ |
| 44 |
{ name => 'global', type => 0, cb_prefix_output => 'prefix_output_global' }, |
| 45 |
{ name => 'inventories', type => 1, cb_prefix_output => 'prefix_output_inventories', message_multiple => 'All inventories are ok', skipped_code => { -10 => 1 } } |
| 46 |
]; |
| 47 |
|
| 48 |
$self->{maps_counters}->{global} = [ |
| 49 |
{ label => 'total', nlabel => 'inventories.total.count', set => { |
| 50 |
key_values => [ { name => 'total' } ], |
| 51 |
output_template => 'total: %d', |
| 52 |
perfdatas => [ |
| 53 |
{ value => 'total', template => '%d', min => 0 } |
| 54 |
] |
| 55 |
} |
| 56 |
}, |
| 57 |
{ label => 'failed', nlabel => 'inventories.failed.count', set => { |
| 58 |
key_values => [ { name => 'failed' }, { name => 'total' } ], |
| 59 |
output_template => 'failed: %d', |
| 60 |
perfdatas => [ |
| 61 |
{ template => '%d', min => 0, max => 'total' } |
| 62 |
] |
| 63 |
} |
| 64 |
} |
| 65 |
]; |
| 66 |
|
| 67 |
$self->{maps_counters}->{inventories} = [ |
| 68 |
{ label => 'hosts-total', nlabel => 'inventory.hosts.total.count', display_ok => 0, set => { |
| 69 |
key_values => [ { name => 'total_hosts' }, { name => 'display' } ], |
| 70 |
output_template => 'hosts total: %d', |
| 71 |
perfdatas => [ |
| 72 |
{ value => 'total_hosts', template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 73 |
] |
| 74 |
} |
| 75 |
}, |
| 76 |
{ label => 'hosts-failed', nlabel => 'inventory.hosts.failed.count', set => { |
| 77 |
key_values => [ |
| 78 |
{ name => 'hosts_with_active_failures' }, { name => 'total_hosts' }, |
| 79 |
{ name => 'display' } |
| 80 |
], |
| 81 |
output_template => 'hosts failed: %d', |
| 82 |
perfdatas => [ |
| 83 |
{ template => '%d', min => 0, max => 'total_hosts', label_extra_instance => 1, instance_use => 'display' } |
| 84 |
] |
| 85 |
} |
| 86 |
}, |
| 87 |
{ label => 'sources-total', nlabel => 'inventory.sources.total.count', display_ok => 0, set => { |
| 88 |
key_values => [ { name => 'total_inventory_sources' }, { name => 'display' } ], |
| 89 |
output_template => 'sources total: %d', |
| 90 |
perfdatas => [ |
| 91 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 92 |
] |
| 93 |
} |
| 94 |
}, |
| 95 |
{ label => 'sources-failed', nlabel => 'inventory.sources.failed.count', set => { |
| 96 |
key_values => [ |
| 97 |
{ name => 'inventory_sources_with_failures' }, { name => 'total_inventory_sources' }, |
| 98 |
{ name => 'display' } |
| 99 |
], |
| 100 |
output_template => 'sources failed: %d', |
| 101 |
perfdatas => [ |
| 102 |
{ template => '%d', min => 0, max => 'total_inventory_sources', label_extra_instance => 1, instance_use => 'display' } |
| 103 |
] |
| 104 |
} |
| 105 |
}, |
| 106 |
{ label => 'groups-total', nlabel => 'inventory.groups.total.count', display_ok => 0, set => { |
| 107 |
key_values => [ { name => 'total_groups' }, { name => 'display' } ], |
| 108 |
output_template => 'groups total: %d', |
| 109 |
perfdatas => [ |
| 110 |
{ template => '%d', min => 0, label_extra_instance => 1, instance_use => 'display' } |
| 111 |
] |
| 112 |
} |
| 113 |
}, |
| 114 |
{ label => 'groups-failed', nlabel => 'inventory.groups.failed.count', set => { |
| 115 |
key_values => [ |
| 116 |
{ name => 'groups_with_active_failures' }, { name => 'total_groups' }, |
| 117 |
{ name => 'display' } |
| 118 |
], |
| 119 |
output_template => 'Groups failed: %d', |
| 120 |
perfdatas => [ |
| 121 |
{ template => '%d', min => 0, max => 'total_groups', label_extra_instance => 1, instance_use => 'display' } |
| 122 |
] |
| 123 |
} |
| 124 |
} |
| 125 |
]; |
| 126 |
} |
| 127 |
|
| 128 |
sub new { |
| 129 |
my ($class, %options) = @_; |
| 130 |
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); |
| 131 |
bless $self, $class; |
| 132 |
|
| 133 |
$options{options}->add_options(arguments => { |
| 134 |
'filter-inventory:s' => { name => 'filter_inventory' } |
| 135 |
}); |
| 136 |
|
| 137 |
return $self; |
| 138 |
} |
| 139 |
|
| 140 |
sub manage_selection { |
| 141 |
my ($self, %options) = @_; |
| 142 |
|
| 143 |
my $inventories = $options{custom}->tower_list_inventories(); |
| 144 |
|
| 145 |
$self->{global} = { total => 0, failed => 0 }; |
| 146 |
$self->{inventories} = {}; |
| 147 |
foreach my $inventory (@$inventories) { |
| 148 |
next if (defined($self->{option_results}->{filter_inventory}) && $self->{option_results}->{filter_inventory} ne '' |
| 149 |
&& $inventory->{name} !~ /$self->{option_results}->{filter_inventory}/); |
| 150 |
|
| 151 |
$self->{inventories}->{ $inventory->{id} } = { |
| 152 |
display => $inventory->{name}, |
| 153 |
total_hosts => $inventory->{total_hosts}, |
| 154 |
hosts_with_active_failures => $inventory->{hosts_with_active_failures}, |
| 155 |
total_inventory_sources => $inventory->{total_inventory_sources}, |
| 156 |
inventory_sources_with_failures => $inventory->{inventory_sources_with_failures}, |
| 157 |
total_groups => $inventory->{total_groups}, |
| 158 |
groups_with_active_failures => $inventory->{groups_with_active_failures} |
| 159 |
}; |
| 160 |
$self->{global}->{total}++; |
| 161 |
|
| 162 |
$self->{global}->{failed}++ if ($inventory->{has_active_failures}); |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
1; |
| 167 |
|
| 168 |
__END__ |
| 169 |
|
| 170 |
=head1 MODE |
| 171 |
|
| 172 |
Check inventories. |
| 173 |
|
| 174 |
=over 8 |
| 175 |
|
| 176 |
=item B<--filter-inventory> |
| 177 |
|
| 178 |
Filter inventory name (can use regexp). |
| 179 |
|
| 180 |
=item B<--warning-*> B<--critical-*> |
| 181 |
|
| 182 |
Thresholds. |
| 183 |
Can be: 'total', 'failed', 'hosts-total', 'hosts-failed', |
| 184 |
'sources-total', 'sources-failed', 'groups-total', 'groups-failed'. |
| 185 |
|
| 186 |
=back |
| 187 |
|
| 188 |
=cut |