Error sending PowerShell directly to ECC queue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2015 09:06 AM
I am creating a UI Action for our administrators that will allow remote restart of MID server services that go down. The UI Action will only appear on the MID server form if it is down. It will identify a MID server that is running to use and will send a PowerShell command directly to the ECC queue using this code:
function start_mid_service(){
var start_host = get_stopped_hostname();
var payload = '<parameters><parameter name="skip_sensor" value="true"/><parameter name="script.ps1" value="get-service -name sn_mid_server -computername ' + start_host + ' | set-service -status running"/></parameters>';
// PowerShell directly!
var ecc = new GlideRecord("ecc_queue");
ecc.initialize();
ecc.agent = "mid.server." + get_running_mid(get_stopped_host_domain());
ecc.topic = "Powershell";
ecc.name = "Windows - PowerShell";
ecc.queue = "output";
ecc.state = "ready";
ecc.source = "127.0.0.1";
ecc.payload = payload;
ecc.insert();
action.setRedirectURL(current);
}
function get_stopped_hostname(){
return g_form.getValue('host_name');
}
function get_stopped_host_domain(){
return g_form.getValue('win_domain');
}
function get_running_mid(domain){
var gr = new GlideRecord('ecc_agent');
gr.addQuery('status', 'Up');
gr.addQuery('win_domain', domain);
gr.query();
if(gr.next()){
return gr.name;
}
}
If I include <parameter name="skip_sensor" value="true" /> I receive the error string com.service_now.mid.message_handlers.ProbeHandlingException: Error parsing XML parameters and the PowerShell does not run as expected. I have tried including <?xml version="1.0" encoding="UTF-8"?> at the beginning of the payload but still receive the ProbeHandlingException error.
However, if I do not include <parameter name="skip_sensor" value="true" /> I receive the error No sensors defined but the PowerShell code works as expected and restarts the MID server service on the remote machine. I would prefer to not see the error record in the ECC queue if it is actually successful. Is there another way to get this to skip the sensor?
Regards,
Chad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2015 08:04 AM
Hi Chad,
wouldn't it be easier to use the OOB scripts to restart the MID Server? You can still apply your logic to find the stopped ones.
var msm =new MIDServerManage();
msm.restart('serv1');
OOB Script Includes for MID Servers: MID Server Script Includes Reference - ServiceNow Wiki
Kind regards,
Stijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2015 08:32 AM
Stijn,
The use case he provides is when the server is down. Therefore, the server would never pickup the restart command until it was brought back up.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2015 08:49 AM
Thx Chris! Neat to know... I've thought it was always possible to actually start a MID Server with that command, even when the service is down.