Skip to content

Instantly share code, notes, and snippets.

View cmcdevitt's full-sized avatar
🏠
Working from home

Chris McDevitt cmcdevitt

🏠
Working from home
View GitHub Profile
@cmcdevitt
cmcdevitt / timeIt.js
Last active April 3, 2022 10:58
JavaScript Script Timer in Servicenow
var start = new GlideDateTime();
/*
Do work here
*/
var end = new GlideDateTime();
total = GlideDateTime.subtract(start, end);;
gs.info("Timer: " + total.getByFormat('mm:ss'));
@cmcdevitt
cmcdevitt / pahi.js
Last active March 30, 2022 10:48
Performance Analytics Hierarchy Scripts
/*
Script Include: global.LocationHierarchy
Source: https://developer.servicenow.com/connect.do#!/event/knowledge2020/LAB1123
*/
var LocationHierarchy = Class.create();
LocationHierarchy.prototype = {
initialize: function ()
{
@cmcdevitt
cmcdevitt / di_source_is_mask.js
Created March 16, 2022 15:20
Change the Source Id on the Discovered Items table
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();
@cmcdevitt
cmcdevitt / ci_lookup_test_rules_v3.js
Last active March 24, 2023 21:47
Test CI Lookup Rules V3
//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
@cmcdevitt
cmcdevitt / eof.js
Created February 24, 2022 22:01
Set Life Cycle Stage and Life Cycle Stage Status for End of Life / Retired
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();
@cmcdevitt
cmcdevitt / importHost_hostImport.js
Last active April 3, 2022 11:00
How to use sn_vul.ImportHost().hostImport
/*
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
@cmcdevitt
cmcdevitt / gr_keys_array_loop.js
Last active April 3, 2022 11:01
Explore / loop through Gliderecord returned object (keys, array)
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]]);
}
}
@cmcdevitt
cmcdevitt / internet_facing.js
Last active April 3, 2022 11:02
Mark Configuration Item / CI as Internet Facing on CMDB
// 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);
@cmcdevitt
cmcdevitt / wipe_division.js
Last active April 3, 2022 10:47
Wipe Division
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();
@cmcdevitt
cmcdevitt / launch_background_job.js
Created January 20, 2022 20:24
Launch a Background Job - Reconcile unmatched discovered items
/*
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