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 / set_division_utility.js
Last active April 3, 2022 11:05
Set (Guess) Division on Unmatched or Incomplete Configuration Items
var UnclassedUtil = Class.create();
UnclassedUtil.prototype = {
initialize: function() {},
getRepository: function(ci) {
/*
IN
ci = the Sys_ID of the Configuration Item
OUT
repository = Repository Name String
@cmcdevitt
cmcdevitt / ci_lookup_suffix.js
Last active December 15, 2021 15:58
CI Lookup Rules to strip a Suffix from a FQDN
/*
Name: FQDN HOST Suffix
Source field: FQDN
*/
(function process(rule, sourceValue, sourcePayload) {
var sourceField = {};
var ignore = global.SecProperty.getProperty("sn_sec_cmn.ignoreCIClass", "");
sourceField[rule.source_field] = sourceValue;
/*
@cmcdevitt
cmcdevitt / ci_lookup_ignore_list.txt
Last active March 6, 2023 20:10
CI Lookup Rules - Ignore List sn_sec_cmn.ignoreCIClass
cmdb_ci_dns_name,cmdb_ci_file_system,cmdb_ci_hyper_v_instance,cmdb_ci_hyper_v_server,cmdb_ci
_lb_pool_member,cmdb_ci_lb_service,cmdb_ci_outofband_device,cmdb_ci_print_queue,cmdb_ci_serv
ice_discovered,cmdb_ci_spkg,cmdb_ci_storage_pool,cmdb_ci_vm_instance,cmdb_ci_vm_template,cmd
b_ci_vmware_instance,cmdb_ci_win_cluster,cmdb_ci_windows_cluster,dscy_net_base,dscy_router_int
erface,dscy_swtch_fwd_rule,cmdb_ci_vmware_nic,cmdb_ci_endpoint_tcp,cmdb_ci_lpar_instance,cmd
b_ci_business_app,cmdb_ci_certificate,cmdb_ci_cluster_vm_affinity_rule,cmdb_ci_vcenter_folder,cmd
b_ci_ibm_zos_server,cmdb_ci_vmware_template,cmdb_ci_win_cluster_node,cmdb_ci_db_mssql_data
base
// As a single string
@cmcdevitt
cmcdevitt / set_scan_source.js
Last active April 3, 2022 11:09
Set the Scan Source for Tenable.sc on the Discovered Items module
/*
Business Rule
Before Insert 10000
Source is Tenable.io
*/
(function executeRule(current, previous /*null when async*/ ) {
var sources = null;
var source_scanner = null;
@cmcdevitt
cmcdevitt / adjust_vr_runtime.js
Last active April 3, 2022 11:10
Adjust VR Integration Run Times across multiple Instances
/*
Ensure that the integration do NOT pull data at the same time
Easy deploy
Vulnerability Integration Spread out Fix-Script
Vulnerability Integration: sn_vul_integration
Time [run_time]: 04:00:00
Starting [run_start]: 2020-04-03 00:00:00
*/
var IO_FIXED = {'name':'Tenable.io Fixed Vulnerabilities Integration', 'sys_id':'c7ba646ec77c1010cfb6664703c2605d'};
@cmcdevitt
cmcdevitt / set_dateTime.js
Last active November 19, 2021 20:51
Set Current Date and Time to a Date/Time field
//Set the Current Data/Time in to a Date/Time field
var gr = new GlideRecord('incident');
gr.get('5f9b5eef1bf774d86c18a8e0604bcbec');//INC008236538
gr.setDisplayValue('u_detected', gs.nowDateTime());//Global Scope Only
gr.update();
//new GlideDateTime().getDisplayValue() //for scoped apps
@cmcdevitt
cmcdevitt / reconcile_unmatched.js
Last active April 3, 2022 11:17
Reconcile unmatched discovered items CI Lookup Work Around
/*
This forces the Reconcile job to NOT consider Unclassed Hardware - force a better match -
A better match should be in the Hardware table and below
Then to prevent duplicates CONSIDER Unclass Hardware
This seems to be necessary if the CI does not exist at first, then it exists but the IRE did not reconcile it
*/
//Add this to Your first rule. This prevents the Reconcile job from matching on Unclassified Hardware
var cmdbci = new GlideRecord("cmdb_ci");
cmdbci.addQuery("name", sourceValue);
@cmcdevitt
cmcdevitt / ci_lookup_derived.js
Last active April 3, 2022 11:18
CI Lookup Rules with a Derived Source
//Subset
//CM 9/29/2021 IRE Enhancement. get the Detrived value
if(sourcePayload.derived && sourcePayload.derived[rule.source_field]){
sourceField[rule.source_field] = sourcePayload.derived[rule.source_field];
sourceValue = sourcePayload.derived[rule.source_field];
}else{//Triditional lookup if no "derived" source
//Get host name from fqdn
var host_name = sourceValue.split('.');
sourceValue = host_name[0];
}
@cmcdevitt
cmcdevitt / getCurrentDay.js
Created November 12, 2021 16:41
Get Current Day of the Week (M,T,W,T,F,S,S)
var todayDateTime = new GlideDateTime(gs.nowDateTime());
var integerValForToday = todayDateTime.getDayOfWeekLocalTime();
var jsonObj = '{"1":"Monday","2":"Tuesday","3":"Wednesday","4":"Thursday","5":"Friday","6":"Saturday","7":"Sunday"}';
var parser = new JSONParser();
var parsedData = parser.parse(jsonObj);
var dayOfWeek = parsedData[integerValForToday];
gs.info(dayOfWeek);
@cmcdevitt
cmcdevitt / force_to_update_set_simple.js
Last active April 3, 2022 11:19
Simple Force to update Set
//Single Record
var rec = new GlideRecord('sn_sec_cmn_watchdog'); //*** Pick Correct Table ****
rec.get('429b07aa0b231200263a089b37673a97'); //*** Find the correct item from the above table to extract ***
//Push the record into the current update set
var um = new GlideUpdateManager2();
um.saveRecord(rec);
//Query for the record
var rec = new GlideRecord('sn_sec_cmn_watchdog'); //*** Pick Correct Table ****