diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 8d6ead2888..92eca676a0 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -812,7 +812,8 @@ class Job(UnifiedJob, JobOptions, SurveyJobMixin, JobNotificationMixin, TaskMana smart_str(host.inventory.name), smart_str(host.name)), extra=dict(inventory_id=host.inventory.id, host_name=host.name, ansible_facts=host.ansible_facts, - ansible_facts_modified=host.ansible_facts_modified.isoformat())) + ansible_facts_modified=host.ansible_facts_modified.isoformat(), + job_id=self.id)) # Add on aliases for the non-related-model fields diff --git a/awx/main/tests/unit/utils/test_handlers.py b/awx/main/tests/unit/utils/test_handlers.py index 7d1de6da7a..693d024281 100644 --- a/awx/main/tests/unit/utils/test_handlers.py +++ b/awx/main/tests/unit/utils/test_handlers.py @@ -162,6 +162,7 @@ def test_base_logging_handler_emit_system_tracking(): ) record.inventory_id = 11 record.host_name = 'my_lucky_host' + record.job_id = 777 record.ansible_facts = { "ansible_kernel": "4.4.66-boot2docker", "ansible_machine": "x86_64", @@ -172,8 +173,12 @@ def test_base_logging_handler_emit_system_tracking(): assert len(sent_payloads) == 1 assert sent_payloads[0]['ansible_facts'] == record.ansible_facts + assert sent_payloads[0]['ansible_facts_modified'] == record.ansible_facts_modified assert sent_payloads[0]['level'] == 'INFO' assert sent_payloads[0]['logger_name'] == 'awx.analytics.system_tracking' + assert sent_payloads[0]['job_id'] == record.job_id + assert sent_payloads[0]['inventory_id'] == record.inventory_id + assert sent_payloads[0]['host_name'] == record.host_name @pytest.mark.parametrize('host, port, normalized, hostname_only', [ diff --git a/awx/main/utils/formatters.py b/awx/main/utils/formatters.py index 380641fdf9..c1eed24a3f 100644 --- a/awx/main/utils/formatters.py +++ b/awx/main/utils/formatters.py @@ -111,6 +111,7 @@ class LogstashFormatter(LogstashFormatterVersion1): data_for_log['ansible_facts_modified'] = raw_data['ansible_facts_modified'] data_for_log['inventory_id'] = raw_data['inventory_id'] data_for_log['host_name'] = raw_data['host_name'] + data_for_log['job_id'] = raw_data['job_id'] elif kind == 'performance': request = raw_data['python_objects']['request'] response = raw_data['python_objects']['response']