Friday, 30 November 2018

IOT Based Smart Parking System -- Integration between ServiceNow and Live Sensors Part 3

Script to created record in MID Server dynamically for Light Sensor: 


var midServerToUse = '',pay = "";

var instance = gs.getProperty('instance_name');

midServerToUse = "mid.server." + gs.getProperty('CreateAThon_MidServer_Name'); //Mid Server Used

if (JSUtil.notNil(midServerToUse)) {
var params = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="used_by_runbook" value="true"/><parameter name="glide.xmlhelper.trim.enable" value="true"/><parameter name="debug" value="true"/><parameter name="workflow" value="a3b5e4a44f915300869e4a318110c721"/><parameter name="skip_simple_parameter_substitution" value="true"/><parameter name="debug_ssh" value="true"/><parameter name="execution_sys_id" value="efb5e4a44f915300869e4a318110c722"/><parameter name="probe_name" value="SSHCommand"/><parameter name="skip_sensor" value="true"/><parameter name="probe" value="e07f03e8c0a800670196a29829b0e452"/><parameter name="credential_id" value="597324644f915300869e4a318110c73e"/></parameters>';
//Input of the curl command to be executed in ECC Queue
var flag = "false";
var outq = new GlideRecord('ecc_queue');
outq.initialize();
outq.agent = midServerToUse;
outq.topic = "SSHCommand";
outq.name = "cd /servicenow/Light_Sensor/;python light_sensor.py";
outq.queue = "output";
outq.payload = params;
outq.source = gs.getProperty('CreateAThon.source.ipaddress');
var s = outq.insert();
gs.sleep(6000);

// Output we Get After Execution is processed
var inqu = new GlideRecord('ecc_queue');
inqu.addEncodedQuery("topicLIKESSHCommand");
inqu.addQuery("response_to", s);
inqu.addQuery("agent", midServerToUse);
inqu.query();
while (inqu.next()) {
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(inqu.payload);
pay = xmlDoc.getNodeText("//output");
}
return pay;
}



Script to created record in MID Server dynamically for Parking Sensor: 



var midServerToUse = '',pay = "";

var instance = gs.getProperty('instance_name');

midServerToUse = "mid.server." + gs.getProperty('CreateAThon_MidServer_Name'); //Mid Server Used

if (JSUtil.notNil(midServerToUse)) {
var params = '<?xml version="1.0" encoding="UTF-8"?><parameters><parameter name="used_by_runbook" value="true"/><parameter name="glide.xmlhelper.trim.enable" value="true"/><parameter name="debug" value="true"/><parameter name="workflow" value="9a44ec644f915300869e4a318110c700"/><parameter name="skip_simple_parameter_substitution" value="true"/><parameter name="debug_ssh" value="true"/><parameter name="execution_sys_id" value="d644ec644f915300869e4a318110c702"/><parameter name="probe_name" value="SSHCommand"/><parameter name="skip_sensor" value="true"/><parameter name="probe" value="e07f03e8c0a800670196a29829b0e452"/><parameter name="credential_id" value="597324644f915300869e4a318110c73e"/></parameters>';
//Input of the curl command to be executed in ECC Queue
var flag = "false";
var outq = new GlideRecord('ecc_queue');
outq.initialize();
outq.agent = midServerToUse;
outq.topic = "SSHCommand";
outq.name = "cd /servicenow/distance_sensor/;python distance.py";
outq.queue = "output";
outq.payload = params;
outq.source = gs.getProperty('CreateAThon.source.ipaddress');
var s = outq.insert();
gs.sleep(6000);

// Output we Get After Execution is processed
var inqu = new GlideRecord('ecc_queue');
inqu.addEncodedQuery("topicLIKESSHCommand");
inqu.addQuery("response_to", s);
inqu.addQuery("agent", midServerToUse);
inqu.query();
while (inqu.next()) {
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(inqu.payload);
pay = xmlDoc.getNodeText("//output");
}
return pay;
}

No comments:

Post a comment