-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
-----BEGIN PGP SIGNATURE----- | ||
|
||
iQGzBAABCAAdFiEE/bJvyFHKKJdaZDOLTiIiIXrUDNEFAmc8lpAACgkQTiIiIXrU | ||
DNFlHAv/eLejbJh4nP8fJXY/3Je3M3w1aFt+BJ229wibPmwRm9xQXmJysX8JLD9t | ||
LGtMOaGTWF5gpauqHimSTh5+F6zxO8PLW5qn0JszWSBhqpSpDzry0KLraYzSyHhA | ||
3LMoHeZ5+Yt/T/Ii/TiEL1AvX5MEMCEXvLF11nwBMVxxOl/bTCv+koDmsjEUJXv7 | ||
JqcFMYvNoLJFPc+Bnhk7bjL5Dr5kXBtc4aRx37k83Q03uEa0un0mFtw1pRA76Yl3 | ||
pcLIgdYaQsJ0BeHT07/5sXfrjXIypscKQmPg3jSc1qVJ+aeVmACsXx7E+zLPRzgj | ||
6bESBDVqyobLkaOUBq+mlYTCqJbiJbz18JezcqpeuUROcrQYgW7kXukr2XXoHXY0 | ||
pSYL/OARIwc6ZzsG8OQwZpx7H5+geGmRm2iGWY4laCnaTuEZne3gG3Ge78krVTlC | ||
Tn529wL4Kdx8hAebV6hcJuAQwdUCz6jAqwlR2eY19tk2oQkHhKWH6S697eiG7M82 | ||
ltLVumG8 | ||
=FL1O | ||
iQGzBAABCAAdFiEE/bJvyFHKKJdaZDOLTiIiIXrUDNEFAmdAp+4ACgkQTiIiIXrU | ||
DNE9aQwAjTXum+scQ1eCRUIo0KZAd8XK2/3tL2fRJgqshkf0T8Nu8Gcb6V2rcpNw | ||
9lDmTyIUyfI/S/IibjnlRsCqMRWIzzN1iqJHZjdYj8JwRJERgvYSi3A7j1/0NgpJ | ||
VXMn2Bp7G13h/E7mhjjQCpLyEdeL4wmdZsWygkhVNQouKgUNLILJaWbtL7u+3eHh | ||
zvuhL0hNbMmn1zw6ozT2lkmiKEtSpwl4wB/pInM0I/DLF945vAU7Em04AZqbsrpi | ||
w+iOa/LjDYc8spV/ir11n4lP354fqlugLpPyNsQXiuw0eRcFkzuzLYDbtQBXXcXj | ||
PJcEdud/Xz9Pb7e9F50wGQeqHy+wrDC3zC5WooB2722Z09lMpJkjW0Ho49IFdqwy | ||
83v+feLNm33QXhz9R6+ZTsD/F0keKWq1lPHob3bXFQfxl4utVqFo1ZkWHWo+XJCF | ||
5FZt89FPdJUb4q17hfpyulrJJyx0kHq/Klbo6Zf4EOtKbKb+ch+8xr/EJwQlDI44 | ||
X+UiqARM | ||
=gyCW | ||
-----END PGP SIGNATURE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Retrieve RITM from EDA Trigger | ||
hosts: localhost | ||
gather_facts: false | ||
|
||
roles: | ||
- servicenow_ritm_retrieve_eda |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
|
||
- name: Retrieve RITM details with retries | ||
servicenow.itsm.api_info: | ||
resource: sc_req_item | ||
sysparm_query: request={{ req_sys_id }} | ||
display_value: all | ||
columns: [sys_id, number, description, short_description, cat_item] | ||
register: ritms | ||
until: ritms.record is defined and ritms.record | length > 0 | ||
retries: 3 | ||
delay: 5 | ||
|
||
- name: Set RITM details fact | ||
ansible.builtin.set_fact: | ||
ritm_details: "{{ ritms.record }}" | ||
cacheable: true | ||
|
||
- name: Retrieve variable mappings with retries | ||
servicenow.itsm.api_info: | ||
resource: sc_item_option_mtom | ||
sysparm_query: request_itemIN{{ ritm_details | map(attribute='sys_id.value') | join(',') }} | ||
columns: [sc_item_option, request_item] | ||
register: variable_mappings | ||
when: ritm_details | length > 0 | ||
until: variable_mappings.record is defined and variable_mappings.record | length > 0 | ||
retries: 3 | ||
delay: 5 | ||
|
||
- name: Retrieve variable details in one query | ||
servicenow.itsm.api_info: | ||
resource: sc_item_option | ||
sysparm_query: "sys_idIN{{ variable_mappings.record | map(attribute='sc_item_option.value') | join(',') }}" | ||
columns: [item_option_new, value, sys_id] | ||
register: variable_details | ||
when: variable_mappings.record | length > 0 | ||
|
||
- name: Retrieve variable names using item_option_new IDs | ||
servicenow.itsm.api_info: | ||
resource: item_option_new | ||
sysparm_query: "sys_idIN{{ variable_details.record | map(attribute='item_option_new.value') | join(',') }}" | ||
columns: [sys_id, name] | ||
register: variable_names | ||
when: variable_details.record | length > 0 | ||
|
||
- name: Create dictionary of variable names by sys_id | ||
ansible.builtin.set_fact: | ||
variable_name_dict: "{{ dict(variable_names.record | map(attribute='sys_id') | zip(variable_names.record | map(attribute='name'))) }}" | ||
cacheable: true | ||
when: variable_names.record | length > 0 | ||
|
||
- name: Combine mappings with variable details | ||
ansible.builtin.set_fact: | ||
variable_combined: >- | ||
{{ | ||
variable_details.record | map( | ||
'combine', { | ||
'request_item': (variable_mappings.record | selectattr('sc_item_option.value', 'equalto', item.sys_id) | map(attribute='request_item.value') | first) | ||
} | ||
) | list | ||
}} | ||
loop: "{{ variable_details.record }}" | ||
loop_control: | ||
label: "{{ item.sys_id }}" | ||
when: variable_details.record | length > 0 | ||
|
||
- name: Combine variable names and values grouped by RITM | ||
ansible.builtin.set_fact: | ||
ritm_variables: >- | ||
{{ | ||
ritm_variables | default({}) | combine({ | ||
item.request_item: (ritm_variables[item.request_item] | default([])) + [{ | ||
'name': variable_name_dict[item.item_option_new.value], | ||
'value': item.value | ||
}] | ||
}) | ||
}} | ||
loop: "{{ variable_combined }}" | ||
loop_control: | ||
label: "{{ item.item_option_new.value }}" | ||
when: variable_combined | length > 0 | ||
|
||
- name: Build enriched_event structure with initial data | ||
ansible.builtin.set_fact: | ||
enriched_event: >- | ||
{{ | ||
{ | ||
'req_sys_id': req_sys_id | default('Unknown Request ID'), | ||
'ritm_details': ritm_details | default([]), | ||
'ritm_variables': ritm_variables | default({}), | ||
} | ||
}} | ||
- name: Nest RITM variables into RITM details | ||
ansible.builtin.set_fact: | ||
enriched_event: >- | ||
{{ | ||
enriched_event | combine({ | ||
'ritm_details': enriched_event.ritm_details | map( | ||
'combine', { | ||
'variables': enriched_event.ritm_variables[item.sys_id.value] | default([]) | ||
} | ||
) | list | ||
}) | ||
}} | ||
loop: "{{ enriched_event.ritm_details }}" | ||
loop_control: | ||
label: "{{ item.sys_id.value }}" | ||
|
||
- name: Consolidate all facts and original event into set_stats | ||
ansible.builtin.set_stats: | ||
data: | ||
enriched_event: "{{ enriched_event }}" | ||
original_event: "{{ ansible_eda.event | default({}) }}" | ||
|
||
- name: Display consolidated enriched_event | ||
ansible.builtin.debug: | ||
var: enriched_event |