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 / instanceof.js
Created May 5, 2023 13:19
Test if a table is derived (i.e. extended) for another table. For CMDB test if a class is part of a parent's class.
//Testing the CMDB Class of some made up hosts on my instance
//Positive Test
var NotThere = 'b69715668326e110b356df647daad3f8';//cmdb_ci_vm_object
var chrisOne = '5f7dfd9cc0a8010e00ab58006f14bdc5';//cmdb_ci_unix_server
var answer = false;
var rec = new GlideRecord('cmdb_ci');
rec.get(chrisOne);
//test = 'manufacturer=b7e7c073c0a801690143e7b7d29eb408'; //Works
//test = 'sys_class_name=cmdb_ci_unix_server'; //Works
//test = 'sys_class_nameINSTANCEOFcmdb_ci_unix_server'; //Works
@cmcdevitt
cmcdevitt / GlideOverlay_example.js
Created April 26, 2023 19:29
GlideOverlay_example.js
/*
GlideOverlay() only works with certin pages like UI Pages(?)
It's not documented so...
Note for the survey part
IMPORTANT:
- The Assessments "Metric type" must match when you build the URL
- The Assessment need to be Ready to take and NOT expired
*/
function pop() {
//GlideDialogWindow.get().destroy();
@cmcdevitt
cmcdevitt / host_map_transfrom.js
Created April 14, 2023 14:55
Configure Host Import Map in coming Vulnerability Response Data
/*
You want to use the 'Host' name in the cmdb_ci 'Name' field for a future SN Discovery match via IRE
Done for each scaner source(Qualys, Tenable, etc)
This ONLY applies to the 'Target Name' Field
Typicaly need to transform FQDN/DNS into just it's Host component
Host Import Map [sn_sec_cmn_src_cmdb_map
Use Script = true
*/
//Expecting an FQDN
answer = value;//Default
@cmcdevitt
cmcdevitt / vit_check_before_open.js
Last active April 7, 2023 23:06
When a Vulnerable Item is reopened check if it is deferred first
/*
A VR scanner may "reopen" a "closed" VIT that has an Active Deferral... so stop that from happening
BR on sn_vul_vulnerable_item
When: Before - Update
Condition: State changes to Open
*/
var date = new GlideDate();
var current_date = date.getByFormat('yyyy-MM-dd');
//This is a 'light' check
@cmcdevitt
cmcdevitt / ui_client_and_server.js
Last active April 7, 2023 21:29
UI Action that runs a Client Script then a Server Script
/*
UI Action
Action name:reopen_incident
Client: True
Onclick: reopen()
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1005843
Note:
- getFormElement() - Returns the HTML element for the form.
- gsftSubmit()
-- Pass a control (button) or a form and action name if the control does not exist.
@cmcdevitt
cmcdevitt / force_ci_lookup_rule_match.js
Created March 24, 2023 21:49
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
@cmcdevitt
cmcdevitt / updateMultiple_.alternates.js
Last active March 24, 2023 16:32
updateMultiple() and Vulnerability Response or Configuration Compliance and some alternates for large data sets
/*
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/server/no-namespace/c_GlideRecordScopedAPI#r_ScopedGlideRecordUpdateMultiple?navFilter=updatem
So... for VR and CC *** DON'T *** use updateMultiple().
Why? Becouse:
(1) On Audited tables it acts more like a glide query and does it one at a time with all the overhead
(2) >5000 records seesm to be hard on the Node, so be nice to your Nodes ;)
3/24/2023 -- True today, but if you are reading this years from now... things might have changed...
*/
@cmcdevitt
cmcdevitt / read_tags_platform.js
Created March 15, 2023 20:30
Read ServiceNow Tags (Platform)
var table = 'incident';
var sys_id = '39e6b9c287c1ad902d0b422e0ebb3581'
var enq = 'table=' + table + '^table_key=' + sys_id;
var tableTags = new GlideRecord('label_entry');
tableTags.addEncodedQuery(enq);
tableTags.query();
while(tableTags.next()){
gs.info(getTag(tableTags.label))
}
@cmcdevitt
cmcdevitt / ui_action_list.js
Last active March 10, 2023 18:49
UI Action List Field Type
/*
There is a Field Type called "UI Action List" which displays a Link in a Field. Clicking on the Link, calls a UI Action.
The is a "complete" example on how to put this together.
*/
//Step One: Unhide the "UI Action List" Field Type
var item = '355be32bbfa00100421cdc2ecf073929';//UI Action List / glide_action_list
var gr = new GlideRecord('sys_glide_object');
gr.get(item);
gr.setValue('visible',true);
@cmcdevitt
cmcdevitt / unclassedHardwareHelper.js
Created February 23, 2023 20:15
Unclassed Hardware Helper
/*
Unclassed Hardware [cmdb_ci_unclassed_hardware]
Transform FQDN to Short Name in CI Name[name] Field
The IRE relies on the Hardware CI Name field for a match
SN Discovery uses the Short Host Name and VR Scanners sometime just use FQDNs
*/
/*
Script One: Host Import Maps [sn_sec_cmn_src_cmdb_map.list]
For records that have a Target Field of 'Name' and a Source Field like DNS,FQDN, etc