Collect information on inventory sources

Also remove one minor query from smart inventory collection that will
never return anything.
This commit is contained in:
Bill Nottingham
2020-04-08 18:07:01 -04:00
parent 2855be9d26
commit f99a43ffa6
2 changed files with 92 additions and 18 deletions

View File

@@ -122,22 +122,27 @@ def cred_type_counts(since):
return counts
@register('inventory_counts', '1.1')
@register('inventory_counts', '1.2')
def inventory_counts(since):
counts = {}
for inv in models.Inventory.objects.filter(kind='').annotate(num_sources=Count('inventory_sources', distinct=True),
num_hosts=Count('hosts', distinct=True)).only('id', 'name', 'kind'):
source_list = []
for source in inv.inventory_sources.filter().annotate(num_hosts=Count('hosts', distinct=True)).values('name','source', 'num_hosts'):
source_list.append(source)
counts[inv.id] = {'name': inv.name,
'kind': inv.kind,
'hosts': inv.num_hosts,
'sources': inv.num_sources
'sources': inv.num_sources,
'source_list': source_list
}
for smart_inv in models.Inventory.objects.filter(kind='smart'):
counts[smart_inv.id] = {'name': smart_inv.name,
'kind': smart_inv.kind,
'hosts': smart_inv.hosts.count(),
'sources': smart_inv.inventory_sources.count()
'sources': 0,
'source_list': []
}
return counts