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 / report_progress.js
Created May 13, 2024 15:05
ServiceNow report progress on a long running script to logs
/*
Some times it is nice to know if you script is still running....
*/
var deleted_count = 0;
// Some GlideRecord stuff herre
while (pgr.next()) {
//Some processing stuff here
deleted_count++;
if (deleted_count % 100 == 0)//Report out every hundredth time
gs.warn("Deleted so far: " + deleted_count);
@cmcdevitt
cmcdevitt / di_without_vi.js
Last active May 10, 2024 20:01
Delete Discovered Items that are not associated with a Vulnerable Item
/*
Use this instead:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1349923
I quickely built this then notices the KB... sight...
This will need to be a FIX Script that will need to be run in the background
*/
var delete_count = 0;
var count = 0;
var table = 'sn_sec_cmn_src_ci';
@cmcdevitt
cmcdevitt / curl_test.txt
Last active February 8, 2024 18:46
CURL Test
curl "https://<your_instance_name>.service-now.com/api/now/table/incident?sysparm_limit=1" \
--request GET \
--header "Accept:application/json" \
--user 'user_name':'password'
curl "https://<your_instance_name>.service-now.com/api/now/table/incident?sysparm_limit=1" --request GET --header "Accept:application/json" --user 'abel.tuter':'xxxxxx'
//Notes
Build your request in REST API Explorer
In the "Code Samples" section select cURL
@cmcdevitt
cmcdevitt / recal_remediation_targets.js
Created January 26, 2024 14:20
Recalculate Remediation Targets
/*
If you need to update your remediation targets, create a Fix Script in the Vulnerability Response scope,
craft your Encoded Query, test, test, and then valideate.
*/
var vit = new GlideRecord("sn_vul_vulnerable_item");
//This Encoded Query is just an example
vit.addEncodedQuery('active=true^risk_rating=2^risk_score>=80^ORrisk_score<=49^NQactive=true^risk_rating=3^risk_score>=50^ORrisk_score<=29^NQactive=true^risk_rating=4^risk_score>=30^ORrisk_score<=0^NQactive=true^risk_rating=5^risk_score>0');
vit.setLimit(1);//Remove before flight, for people who don't read directions
vit.query();
@cmcdevitt
cmcdevitt / recalc_risk_score.js
Last active January 25, 2024 18:40
Recalculate Risk Score for Vulnerable items
/*
If you need to force a recalcuation on a VIT (or set of VITS) then place this script in a Fix Script and execute.
Note: The Fix Script should be in the Vulnerability Response Application Scope
Use Case:
-- Force a change on VIT to test a change in *DEV*
-- Force a change to existing data becouse your model changed
****TEST**** then ****RETEST*** AND ***VALIDATE*** before proceding off your DEV enviroment with this script. There is no undo button.
*/
var vit = new GlideRecord('sn_vul_vulnerable_item');
@cmcdevitt
cmcdevitt / dynamic_filter.js
Created December 13, 2023 18:54
Dynamic Filter Options Example
/*
Use Case: Provide an "Is Dynamic" option for the "Company" field on a Condition Builder
#1
Client Callable Script Include
Global Scope, Accessable All Scopes
Related ACL:
type: client_callable_script_include
operation: Execute
name: DynamicFilters
@cmcdevitt
cmcdevitt / insert_vit_record.js
Created December 12, 2023 17:19
Insert vulnerability without the VR Framework
/*
OnBefore Transform Script to support a Transform Map. (I.E. Fields that need to be transformed before insert)
Use Case
1. Using the ServiceNow Table API insert a "vulnerability finding" into a custom table extened from "Import Set Row"
2. Automaticaly Run the Tranfrom Map on each insert of a record/row and insert the data on the vulnerable item table
Note: This is intended for low volume inserts into the VIT table
*/
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
@cmcdevitt
cmcdevitt / vr_assign_by_script.js
Created December 11, 2023 14:49
VR Assignment Rule assign by script example
/*
Vulnerability Response Assignment Rule -> Assign using Script
current.assignment_group = new global.VRUtil().arSVClookup(current.cmdb_ci); // ***Example Script***
Note:
1. current.assignment_group #Note: If the lookup fails you ***NEED*** to return a default assignment group!
2. current.cmdb_ci you can use any property that "current" knows about, but typically its the CI
*/
//Script Include, Example Method:
arSVClookup: function(current_rule) {
@cmcdevitt
cmcdevitt / attach_csv_.js
Created August 17, 2023 19:09
create and attach csv file from a script
var fileName = 'Incidents.csv';
var csvData = ''; //The variable csvData will contain a string which is used to build the CSV file contents
var Headers = ["Number","Caller","Short Desc","Assignment Group", "Assigned To"];
//Build Header / End First Row
for (var i = 0; i < Headers.length; i++) { //Build the Headers
csvData = csvData + '"' + Headers[i] + '"' + ',';
}
csvData = csvData+"\r\n";//End first row
@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