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 / CIListParents.js
Created September 4, 2018 16:51
Script Include (v0.1) to list a CI "Parents" Based on the CI Relationship Table
var CIListParents = Class.create();
CIListParents.prototype = {
initialize : function() {
this.maxDepth = gs.getProperty('glide.relationship.max_depth',10); // how deep to look
this.currentDepth = 0;
//this.services = new Object(); // list of affected services
this.services = {};
@cmcdevitt
cmcdevitt / relateToChildren.js
Created September 4, 2018 16:57
A Business Rule on Application Software (with a List (u_depends_on) point to Application Software) to Add and Removes a CI Relationship.
/*
Business Rule
Name: relateToChildren
Table: Application Software [cmdb_ci_application_software]
When to Run: Before, Insert and Update
Filter Condition: u_depends_onVALCHANGES^EQ
BETA / Prototype / To-do: Code Clean up.
*/
@cmcdevitt
cmcdevitt / GlideRecordOr.js
Created September 7, 2018 14:37
Add an "OR" Condition to a GlideRecord Query in ServiceNow
var myLog = "";
var gr = new GlideRecord("sys_user");
//New object to build OR query
var q1 = gr.addQuery("title", "CONTAINS", "VP");
q1.addOrCondition("title", "CONTAINS", "Vice");
q1.addOrCondition("title", "CONTAINS", "Chief");
//"switch back" to the GR object
gr.query();
while (gr.next()) {
@cmcdevitt
cmcdevitt / CidrUtil.js
Created October 9, 2018 14:28
Check to see if an IPv4 Address is in CIDR Range in a ServiceNow Script Include
var CidrUtil = Class.create();
CidrUtil.prototype = {
initialize: function() {
},
ipIsInCidr : function(ip, cidr) {
var cidrIp = cidr.split('/')[0];
var cidrSm = cidr.split('/')[1];
@cmcdevitt
cmcdevitt / vulnerability_group_count.js
Last active October 31, 2018 16:32
How many Vulnerability Groups
var count = new GlideAggregate('sn_vul_vulnerability');
count.addAggregate('COUNT');
//count.addEncodedQuery('state=2'); //State = Under Investigation
count.query();
var vul_grp = 0;
if (count.next()) {
vul_grp = count.getAggregate('COUNT');
}
gs.info('Number of VulGrps: ' + vul_grp);
@cmcdevitt
cmcdevitt / vits_on_vulgrp.js
Created October 31, 2018 16:46
VIT Count on Vulnerability Group
var count = new GlideAggregate('sn_vul_m2m_vul_group_item');
count.addAggregate('COUNT');
count.addEncodedQuery('sn_vul_vulnerability=003bc720df11120068c32df36bf263a2');
count.query();
var vits = 0;
if (count.next()) {
vits = count.getAggregate('COUNT');
}
gs.info('Number of vits: ' + vits);
@cmcdevitt
cmcdevitt / resolved_vits_on_vulgrp.js
Created October 31, 2018 17:10
Resolved Vulnerabilities Count on a Vulnerability Groups
//Resolved, Defered, Closed
var count = new GlideAggregate('sn_vul_m2m_vul_group_item');
count.addAggregate('COUNT');
count.addEncodedQuery('sn_vul_vulnerable_item.stateIN101,12,3^sn_vul_vulnerability=f52bc720df11120068c32df36bf26384');
count.query();
var vits = 0;
if (count.next()) {
vits = count.getAggregate('COUNT');
}
gs.info('Number of vits: ' + vits);
@cmcdevitt
cmcdevitt / VulnerabilityCountUtils.js
Last active November 1, 2018 15:24
A Set of functions to update a Vulnerability Group with it VIT count
var VulnerabilityCountUtils = Class.create();
VulnerabilityCountUtils.prototype = {
initialize: function() {
},
/*
Usage:
Schedule Job: new VulnerabilityCountUtils().setAllVulGrp();
UI Action:new VulnerabilityCountUtils().setSingleVulGrp(current.sys_id);
@cmcdevitt
cmcdevitt / a_changeOptions.js
Last active December 10, 2018 18:35
review_request UI Page Adjust substate based on desired_state (Close / Defer UI Action / Button)
function removeSelectOptions(elementId,removeNone){
//V3 removeSelectOptions('resolution',true)
//removeNone(true|false) is for: "-- None --" option
var wp = gel(elementId);
var wplen = wp.length;
for(i = 0; i < wplen; i++){
wp.remove(1);
}
if(removeNone){
wp.remove(0);
@cmcdevitt
cmcdevitt / condition.js
Created November 10, 2018 16:41
HealthCheck
answer = (new global.ArrayUtil().contains(before.pluginArr, 'com.snc.vulnerability'));