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
| var start = new GlideDateTime(); | |
| /* | |
| Do work here | |
| */ | |
| var end = new GlideDateTime(); | |
| total = GlideDateTime.subtract(start, end);; | |
| gs.info("Timer: " + total.getByFormat('mm:ss')); |
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
| /* | |
| Script Include: global.LocationHierarchy | |
| Source: https://developer.servicenow.com/connect.do#!/event/knowledge2020/LAB1123 | |
| */ | |
| var LocationHierarchy = Class.create(); | |
| LocationHierarchy.prototype = { | |
| initialize: function () | |
| { |
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
| di_sys = ''; | |
| var di = new GlideRecord('sn_sec_cmn_src_ci'); | |
| di.get(di_sys); | |
| di.setValue('source_id', di.source_id + 'junk'); | |
| di.update(); |
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
| //Make this a Fix Script so you can run it multiple times | |
| //In System Logs All: Filter for Message Starts with 'CLRT:' | |
| //Enter the Discoverd Item Number. Example: SDI000000001330 | |
| var DISCOVERED_ITEM = 'SDI000000001270'; | |
| //Enter the Integration Name. Example: Tenable.io | |
| var INTEGRATION_NAME = 'Tenable.io'; | |
| /* | |
| Test Matching Rules | |
| 1. Identify the Integration |
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
| var target = '2dfd7c8437201000deeabfc8bcbe5d56';//ci sys_id | |
| var ci = GlideRecord('cmdb_ci'); | |
| ci.get(target); | |
| ci.setValue('life_cycle_stage', 'End of Life'); | |
| ci.setValue('life_cycle_stage_status', 'Retired'); | |
| ci.update(); |
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
| /* | |
| hostImport: | |
| (1) It trys to match on an existing CI | |
| (2) If no match is found, it transforms the host{} data into an IRE Payload and passes it to the IRE to handle | |
| (3) It returns the Configuration Item (eather the one it matched or the new one the IRE created) | |
| (4) It then creates and entery in the Discovered Items module | |
| Notes: | |
| The "host" Object PLUS the 'Host Import Maps' table is the bridge between the Integration fields and the target CMDB table fields | |
| The Integration 'fields' become properties in the ==> host{} <== and they represent the 'Source' field on Host Import Maps [sn_sec_cmn_src_cmdb_map] | |
| The 'Source Field' [source_field] (String) on Host Import Maps [sn_sec_cmn_src_cmdb_map] table == Integration field/property on "host" Object |
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
| var source = new GlideRecord('u_pentest_import_api'); | |
| source.addEncodedQuery('sys_import_row=0^ORsys_import_row=NULL'); | |
| source.query(); | |
| while(source.next()){ | |
| keys = Object.keys(source); | |
| for (i=0; i < keys.length; i++) { | |
| gs.info(keys[i] + "::" +source[keys[i]]); | |
| } | |
| } |
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
| // Example script to populate 'Internet Facing' field on 'Hardware' table. | |
| // Mark 'Internet Facing' = false only when you are sure about it. Otherwise treat the CI as Internet facing(true) to assume the highest risk | |
| var defaultVal = true; // In case , IP address is not present or is not valid, then use this value for 'Internet Facing' attribute | |
| populateForNonEmptyIP(); | |
| populateForEmptyIP(defaultVal); | |
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
| var table = 'cmdb_ci_unclassed_hardware'; //cmdb_ci_incomplete_ip //cmdb_ci_unclassed_hardware | |
| function wipe_division(table){ | |
| var query = 'u_divisionISNOTEMPTY'; | |
| var gr = new GlideRecord(table); | |
| //gr.addEncodedQuery(query); | |
| gr.query(); | |
| while(gr.next()){ | |
| gr.setValue('u_division', ""); | |
| //gr.u_division = ''; | |
| gr.update(); |
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
| /* | |
| Create a Reconcile unmatched discovered items" by script | |
| */ | |
| var params = '{"limit":"10000","firstDiscoveredItem":""}'; | |
| var jobConfigID = 'sn_sec_cmn.reconcile_unmatched_discovered_items'; | |
| var brj = new sn_sec_cmn.BackgroundJobUtils(); | |
| var job = null; | |
| /* | |
| createBackgroundJob : Parameters | |
| <table> based on Job Configuration |