Created
July 26, 2023 20:49
-
-
Save mtcoffee/abd617a3bdaa99232c04c8cf4f08424e to your computer and use it in GitHub Desktop.
SN Certmgmt exclude pre processor
This file contains hidden or 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
| function checkIfRecordExists(payloadItem) { | |
| var certGr = new GlideRecord('cmdb_ci_certificate'); | |
| certGr.addQuery('fingerprint', payloadItem.values['fingerprint']); | |
| certGr.query(); | |
| return certGr.next() ? certGr : ""; | |
| } | |
| var rtrn = {}; | |
| //parsing the json string to a json object | |
| var payloadObj = JSON.parse(payload); | |
| //put your business logic here | |
| var ignoreListprop = gs.getProperty('sn_disco_certmgmt.my.msca.ignorelist'); | |
| var ignoreList = ignoreListprop.toString().split(','); | |
| for (var i = 0; i < payloadObj.items.length; i++) { | |
| var payloadItem = payloadObj.items[i]; | |
| var certRecordGr = checkIfRecordExists(payloadItem); | |
| if (!certRecordGr) { //only focus on new records | |
| //TO EXCLUDE SELECT RECORDS FROM TRACKING BASED ON PROPERTY LOOKUP | |
| var ignoreListResponse = false; //set default for ignore list | |
| //check if name is on ignore list | |
| for (var x = 0; x < ignoreList.length; x++) { | |
| if (payloadItem.values.subject_common_name == ignoreList[x]) { | |
| ignoreListResponse = 'true'; | |
| } | |
| } | |
| if (ignoreListResponse == 'true') { | |
| payloadItem.values.renewal_tracking = 'none'; | |
| payloadItem.values.short_description = 'Tracking Disabled by Certificate Ignore List property sn_disco_certmgmt.my.msca.ignorelist'; | |
| } | |
| } | |
| } | |
| //you can return a message and a status, on top of the input variables that you MUST return. | |
| //returning the payload as a Json String is mandatory in case of a pre sensor script, and optional in case of post sensor script. | |
| //if you want to terminate the payload processing due to your business logic - you can set isSuccess to false. | |
| rtrn = { | |
| 'status': { | |
| 'message': 'Enter your message here', | |
| 'isSuccess': true | |
| }, | |
| 'patternId': patternId, | |
| 'payload': JSON.stringify(payloadObj) | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment