Skip to content

Commit f80035b

Browse files
Create Pre README.md
1 parent e989d77 commit f80035b

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ServiceNow Discovery Pre Sensor Script: IP Router Association
2+
3+
This script is a **ServiceNow Discovery Pre Sensor Script** designed to enrich discovery payload data before it reaches the **Identification and Reconciliation Engine (IRE)**.
4+
5+
It focuses on linking **Interface Cards (`cmdb_ci_interface_card`)** to their parent **IP Routers (`cmdb_ci_ip_router`)** by resolving the router name to its corresponding `sys_id` in the CMDB.
6+
7+
8+
## Overview
9+
10+
When ServiceNow Discovery runs a pattern that identifies multiple components (e.g., routers and their interface cards), some payload items may contain **router names instead of sys_ids**.
11+
The IRE requires sys_ids for accurate relationship building.
12+
13+
This script ensures that:
14+
- The `u_configuration_item` field on interface cards is replaced with the actual `sys_id` of the corresponding router.
15+
- The router’s `managed_by_group` field is also copied to the interface card record.
16+
- Payload is properly formatted and ready for IRE ingestion.
17+
18+
## Script Logic
19+
20+
### Step-by-step Flow
21+
1. **Parse Payload:**
22+
Converts the input payload JSON string into an object for processing.
23+
24+
2. **Iterate Items:**
25+
Loops through each payload item and filters those with `className = cmdb_ci_interface_card`.
26+
27+
3. **Router Resolution:**
28+
For each interface card:
29+
- Reads the router name from `u_configuration_item`.
30+
- Searches for a matching router record in `cmdb_ci_ip_router`.
31+
- If found:
32+
- Replaces the router name with its `sys_id`.
33+
- Copies the router’s `managed_by_group` value.
34+
35+
4. **Return Updated Payload:**
36+
Returns the modified payload back to Discovery for further processing by the IRE.
37+
38+
---
39+
40+
## Example Behavior
41+
42+
### **Before Script Execution**
43+
```json
44+
{
45+
"items": [
46+
{
47+
"className": "cmdb_ci_interface_card",
48+
"values": {
49+
"name": "Router-1/Gigabit0/1",
50+
"u_configuration_item": "Router-1"
51+
}
52+
}
53+
]
54+
}
55+
56+
### **After Script Execution**
57+
{
58+
"items": [
59+
{
60+
"className": "cmdb_ci_interface_card",
61+
"values": {
62+
"name": "Router-1/Gigabit0/1",
63+
"u_configuration_item": "1b23cdef6f3123006a12ff3b8b3ee490",
64+
"managed_by_group": "287ebd7da9fe198100f92cc8d1d2154e"
65+
}
66+
}
67+
]
68+
}
69+

0 commit comments

Comments
 (0)