mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
added more logging for fact cache receiver
This commit is contained in:
parent
c6e3798259
commit
713f18438c
@ -1,11 +1,15 @@
|
|||||||
# Copyright (c) 2015 Ansible, Inc.
|
# Copyright (c) 2015 Ansible, Inc.
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
|
|
||||||
|
# Python
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
# Django
|
||||||
from django.core.management.base import NoArgsCommand
|
from django.core.management.base import NoArgsCommand
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
# AWX
|
||||||
from awx.fact.models.fact import * # noqa
|
from awx.fact.models.fact import * # noqa
|
||||||
from awx.main.socket import Socket
|
from awx.main.socket import Socket
|
||||||
|
|
||||||
@ -41,13 +45,16 @@ class FactCacheReceiver(object):
|
|||||||
# TODO: in ansible < v2 module_setup is emitted for "smart" fact caching.
|
# TODO: in ansible < v2 module_setup is emitted for "smart" fact caching.
|
||||||
# ansible v2 will not emit this message. Thus, this can be removed at that time.
|
# ansible v2 will not emit this message. Thus, this can be removed at that time.
|
||||||
if 'module_setup' in facts_data and len(facts_data) == 1:
|
if 'module_setup' in facts_data and len(facts_data) == 1:
|
||||||
|
logger.info('Received module_setup message')
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
host = FactHost.objects.get(hostname=hostname, inventory_id=inventory_id)
|
host = FactHost.objects.get(hostname=hostname, inventory_id=inventory_id)
|
||||||
except FactHost.DoesNotExist:
|
except FactHost.DoesNotExist:
|
||||||
|
logger.info('Creating new host <hostname, inventory_id> <%s, %s>' % (hostname, inventory_id))
|
||||||
host = FactHost(hostname=hostname, inventory_id=inventory_id)
|
host = FactHost(hostname=hostname, inventory_id=inventory_id)
|
||||||
host.save()
|
host.save()
|
||||||
|
logger.info('Created new host <%s>' % (host.id))
|
||||||
except FactHost.MultipleObjectsReturned:
|
except FactHost.MultipleObjectsReturned:
|
||||||
query = "db['fact_host'].find(hostname=%s, inventory_id=%s)" % (hostname, inventory_id)
|
query = "db['fact_host'].find(hostname=%s, inventory_id=%s)" % (hostname, inventory_id)
|
||||||
logger.warn('Database inconsistent. Multiple FactHost "%s" exist. Try the query %s to find the records.' % (hostname, query))
|
logger.warn('Database inconsistent. Multiple FactHost "%s" exist. Try the query %s to find the records.' % (hostname, query))
|
||||||
@ -63,15 +70,19 @@ class FactCacheReceiver(object):
|
|||||||
# Update existing Fact entry
|
# Update existing Fact entry
|
||||||
version_obj = FactVersion.objects.get(timestamp=self.timestamp, host=host, module=module)
|
version_obj = FactVersion.objects.get(timestamp=self.timestamp, host=host, module=module)
|
||||||
Fact.objects(id=version_obj.fact.id).update_one(fact=facts)
|
Fact.objects(id=version_obj.fact.id).update_one(fact=facts)
|
||||||
|
logger.info('Updated existing fact <%s>' % (version_obj.fact.id))
|
||||||
except FactVersion.DoesNotExist:
|
except FactVersion.DoesNotExist:
|
||||||
# Create new Fact entry
|
# Create new Fact entry
|
||||||
(fact_obj, version_obj) = Fact.add_fact(self.timestamp, facts, host, module)
|
(fact_obj, version_obj) = Fact.add_fact(self.timestamp, facts, host, module)
|
||||||
|
logger.info('Created new fact <fact, fact_version> <%s, %s>' % (fact_obj.id, version_obj.id))
|
||||||
|
|
||||||
def run_receiver(self):
|
def run_receiver(self):
|
||||||
with Socket('fact_cache', 'r') as facts:
|
with Socket('fact_cache', 'r') as facts:
|
||||||
for message in facts.listen():
|
for message in facts.listen():
|
||||||
if 'host' not in message or 'facts' not in message or 'date_key' not in message:
|
if 'host' not in message or 'facts' not in message or 'date_key' not in message:
|
||||||
|
logger.warn('Received invalid message %s' % message)
|
||||||
continue
|
continue
|
||||||
|
logger.info('Received message %s' % message)
|
||||||
self.process_fact_message(message)
|
self.process_fact_message(message)
|
||||||
|
|
||||||
class Command(NoArgsCommand):
|
class Command(NoArgsCommand):
|
||||||
@ -82,6 +93,8 @@ class Command(NoArgsCommand):
|
|||||||
|
|
||||||
def handle_noargs(self, **options):
|
def handle_noargs(self, **options):
|
||||||
fcr = FactCacheReceiver()
|
fcr = FactCacheReceiver()
|
||||||
|
fact_cache_port = settings.FACT_CACHE_PORT
|
||||||
|
logger.info('Listening on port http://0.0.0.0:' + str(fact_cache_port))
|
||||||
try:
|
try:
|
||||||
fcr.run_receiver()
|
fcr.run_receiver()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
Loading…
Reference in New Issue
Block a user