Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created March 24, 2023 21:49
Show Gist options
  • Select an option

  • Save cmcdevitt/af3f7a6c5dfbe7f4225b08015d5f3d33 to your computer and use it in GitHub Desktop.

Select an option

Save cmcdevitt/af3f7a6c5dfbe7f4225b08015d5f3d33 to your computer and use it in GitHub Desktop.
Force CI Lookup Rule Match for Testing
/*
This CI Lookup Rule is forcing a match for testing.
Set a filter on you System Log -> All: Message Starts with CCLR:
For example, if you want to test CI Promotion.
Setup a CI Lookup Rule:
Name: CUSTOM, Order: 1, Lookup Method: Script, Type: Custom, Active: True
Source: <The Souce needs to match the same source that you will be testing> Example: Tenable.io
Source field: <match a Discovered Item payload field name ***exactly****> Example: IP_ADDRESSES
Test Data: This sample data comes with a Development System
eth1 fad823c77f00000101af5350c6922d9c (Belongs to *JEMPLOYEE-IBM)
*JEMPLOYEE-IBM a9a2d111c611227601fb37542399caa8
IP Address 10.10.10.10 (Set eth1 IP address to whatever you are testing with if it is part of your test)
*/
(function process(rule, sourceValue, sourcePayload) {
var sourceField = {};
//sourceField[rule.source_field] = sourceValue;
/*
This should match the value you are testing with from the:
Discovered Item -> Payload -> <field that matched the 'Source Field' above>
*/
sourceField[rule.source_field] = '10.10.10.10'; //Overiding what is comming in from the 'Source field'
nic = new GlideRecord("cmdb_ci_network_adapter");
//The next row is identifying the CI you want to begin the test with: i.e. the Forced Match
nic.addEncodedQuery("sys_id=fad823c77f00000101af5350c6922d9c"); //eth1 from test data.
nic.query();//Setting this up for _queryMatch()
nic_after = _queryMatch(nic, rule, sourceField);//This is where the "Filter decommissioned CI happens" -> CIIdentify
gs.info("CCLR: rule " + rule.name);//What CI Lookup Rule did this come from
if (nic_after) {
/*
This should come back with your Original CI... unless some duplicat is found....
Additional Processing is done on the returned CI
Example: CIIdentify._autoPromoteCI()
*/
gs.info("CCLR: after: _queryMatch() returned: " + nic.name);
return nic_after.getUniqueValue();
} else {
gs.info("CCLR: after: _queryMatch() returned: nothing");
return nic.getUniqueValue();//Return our Test CI to ensure no other Rules Run
}
/*
Use 'Test CI Lookup Rules V3' to kick this off and see the final Results! (Or look for the latest version of this....)
https://gist.github.com/cmcdevitt/73a72605feb3b6433273b0e95730eead
*/
})(rule, sourceValue, sourcePayload);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment