ServiceNow MID Server Connectivity Test
SummaryPermalink
When troubleshooting discovery issues, the typical place to start is “Can we connect to the endpoint on the required port”? This simple background script can be run to skip the need for an interactive login to a Windows MID Server. It can be used to run any command in an adhoc fashion!
The ScriptPermalink
/* | |
A background script to run a command and test MID Server connectivity to an endpoint. | |
Just set the value to your midserver name. | |
*/ | |
//capture start time | |
var now = (new GlideDateTime()); | |
var probe = SncProbe.get("Windows - Powershell"); | |
var midServer = 'winmid06'; | |
var psCommand = 'test-netconnection -port 443 192.168.1.1'; | |
var instance = gs.getProperty('instance_name'); | |
probe.setName("Windows - Powershell"); | |
probe.setSource("127.0.0.1"); | |
probe.addParameter("script.ps1", psCommand); | |
probe.addParameter("skip_sensor", true); | |
probe.create(midServer); | |
//now keep checking the ecc queue input for a new record | |
var i = 0; | |
var maxChecks = 20; //number of times to check the table before we stop. Infinite loop safety kill | |
while (i <= maxChecks) { | |
//keep checking record until it is processed | |
gs.sleep(1000) //check once per second | |
var ecc = new GlideRecord('ecc_queue'); | |
ecc.addQuery('queue', 'input'); | |
ecc.addQuery('source', '127.0.0.1'); | |
ecc.addQuery('name', 'Windows - Powershell'); | |
ecc.addQuery('sys_created_on', '>', now); | |
ecc.orderByDesc('sys_created_on'); | |
ecc.setLimit(1); | |
ecc.query(); | |
if (ecc.next()) { | |
if (ecc.state == 'ready') { | |
gs.info('\nLink to record:\rhttps://' + instance + '.service-now.com/ecc_queue.do?sys_id=' + ecc.sys_id +'\n'); | |
gs.info(ecc.sys_created_on + '\n' + ecc.payload); | |
break; | |
} | |
} | |
i++; //increment so that we don't run this infinitely | |
if (i == maxChecks) { | |
gs.info('Max Check Reached. Check the ecc_queue table for a new input record'); | |
gs.info('\nList View:\nhttps://' + instance + '.service-now.com/ecc_queue_list.do?sysparm_query=source=127.0.0.1^queue=input^ORDERBYDESCsys_created_on') | |
} | |
} |
Sample Result:
Leave a comment