Validate MID Server via API?

Mark Blackburn
Kilo Contributor

Hi,

I'm trying to automate as much as possible the deployment of MID servers to many branch environments. I have figured out how to get the MID server to deploy as a Windows service without requiring end user UI by preconfiguring the config files, but I end up with a new MID server entry in the instance that needs to be manually validated before it will work. Since these new MID servers could be deployed at all hours by a deployment script, I need the validation to happen automatically.

I can't find any mention of how to do this in the API reference. Is this something I'm missing or is there no way to automate this at all and it HAS to be done manually?

Thanks,

Mark.

1 ACCEPTED SOLUTION

codycotulla
Tera Guru

Hi Mark,

To follow-up on what Arnoud wrote. I took a look at the MIDServerAjax script include that is called to validate a Mid Server from the UI.

If you add the code below to a scheduled job and set the job to run on a schedule of your choosing, you can make sure that any unvalidated Mid Servers get validated.

var mm = new MIDServerManage();
var gr = new GlideRecord("ecc_agent");
//search for mid servers that aren't validated
gr.addQuery("validated", false);
gr.query();
while(gr.next()){
    mm.validate(gr.name);
}

Hope this helps.

Let me know if you have any questions.

Thanks,

 

Cody

 

 

View solution in original post

7 REPLIES 7

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

Script Include MIDServerManage has a method validate()

it is not documented on docs, normally its called from the Validate UI Action via a GlideAjax call in ScriptInclude MIDServerAjax

Did not test, but this should work.

(new MIDServerManage()).validate("your_midserver_name");

Mark Blackburn
Kilo Contributor

Thanks Arnoud, it's great to know there is a way to do this.

I'm afraid I'm very new to ServiceNOW and I'm scripting my automation in PowerShell. I'm fairly sure I know how to drive the REST API that way, but I have no idea how to drive the javascript stuff server side. I'm guessing there'll be a .js library exposed somewhere, but I'm a little lost in the documentation and can't find out what he URI for that is.

Any help gratefully received.

Thanks,

Mark.

Will this always be the same pre configured instance?

In theory then you could do it via a Scripted Rest API.

But probably it is a conscious decision not to enable this, to ensure you dont have unwanted mid server connected to your instance, so I would not recommend this.

 

codycotulla
Tera Guru

Hi Mark,

To follow-up on what Arnoud wrote. I took a look at the MIDServerAjax script include that is called to validate a Mid Server from the UI.

If you add the code below to a scheduled job and set the job to run on a schedule of your choosing, you can make sure that any unvalidated Mid Servers get validated.

var mm = new MIDServerManage();
var gr = new GlideRecord("ecc_agent");
//search for mid servers that aren't validated
gr.addQuery("validated", false);
gr.query();
while(gr.next()){
    mm.validate(gr.name);
}

Hope this helps.

Let me know if you have any questions.

Thanks,

 

Cody