Can I kick off discovery from script with device name?

Rick54
Tera Expert

Hello,

Is there any way to kick off discovery from JavaScript using just device name.

I am working on vCenter MID extension. I get the device name in the parm fields in the event from vCenter, from there I capture the name and populate it in the CMDB. Once addition is done I wanted to kick off discovery update the CI. I know how to run the discovery from script but not sure about running it without any IP address. Please suggest me any ideas here. Thanks!

1 ACCEPTED SOLUTION

tim_broberg
ServiceNow Employee
ServiceNow Employee

So far so good. You have a probe object. Now you need to stick an address on it and mail it.

I think the values allows you to pass in some parameters, but I honestly don't know. Personally, i would just omit that argument, but if you want to try to work it out by example, by all means, go for it.

So, now you have a probe. Assuming you don't need to fool with other probe parameters, you can just set the ip or hostname in the source field and create the probe.

Here's an example i tried out with a simple Linux probe:

var ipOrHostname = 'timserve';
var mid = 'tims_mid';

var probe = SncProbe.get("Linux - CPU");
probe.setSource(ipOrHostname);
probe.create(mid);

I see an output and then input appear on the ecc_queue as a result of running this script.

If you don't just know which mid to use, that's a little more work.

var source = 'timserve';

var probe = SncProbe.get("Linux - CPU");
probe.setSource(source);
probe.createForAutoSelectMidServer('Discovery', [{'capability': 'ssh'}], null);

The arguments for createForAutoSelectMidServer() are frankly a little baffling. It's SncProbe.createForAutoSelectMidServer(String application, Object[] capabilities, String sensorECCID).

Application is a mid server application such as "Discovery" or "Orchestration".

Capabilities is an array of objects with a capability and a value, but I always wind up ignoring the value. If you poke at your mid server capabilities, you should be able to find what you need. I needed "ssh" for my probe.

sensorECCID is the sysid of the ecc_queue input we're responding to. Ignore it unless you are responding to another probe, which you're not.

Hope it helps,
    - Tim.

View solution in original post

17 REPLIES 17

tim_broberg
ServiceNow Employee
ServiceNow Employee

So far so good. You have a probe object. Now you need to stick an address on it and mail it.

I think the values allows you to pass in some parameters, but I honestly don't know. Personally, i would just omit that argument, but if you want to try to work it out by example, by all means, go for it.

So, now you have a probe. Assuming you don't need to fool with other probe parameters, you can just set the ip or hostname in the source field and create the probe.

Here's an example i tried out with a simple Linux probe:

var ipOrHostname = 'timserve';
var mid = 'tims_mid';

var probe = SncProbe.get("Linux - CPU");
probe.setSource(ipOrHostname);
probe.create(mid);

I see an output and then input appear on the ecc_queue as a result of running this script.

If you don't just know which mid to use, that's a little more work.

var source = 'timserve';

var probe = SncProbe.get("Linux - CPU");
probe.setSource(source);
probe.createForAutoSelectMidServer('Discovery', [{'capability': 'ssh'}], null);

The arguments for createForAutoSelectMidServer() are frankly a little baffling. It's SncProbe.createForAutoSelectMidServer(String application, Object[] capabilities, String sensorECCID).

Application is a mid server application such as "Discovery" or "Orchestration".

Capabilities is an array of objects with a capability and a value, but I always wind up ignoring the value. If you poke at your mid server capabilities, you should be able to find what you need. I needed "ssh" for my probe.

sensorECCID is the sysid of the ecc_queue input we're responding to. Ignore it unless you are responding to another probe, which you're not.

Hope it helps,
    - Tim.

Tim, I wanted to try auto select mid server and i am getting an error while i am doing the below.

For all of our mid servers, capabilities looks like below. Thank you!

find_real_file.png

 

var source = 'L5CG63504MC';
var probe = SncProbe.get("Windows -IP Address");//I created this probe with a WMI command to get the IP address and it works great.
probe.setSource(source);
probe.createForAutoSelectMidServer('Discovery', [{'ALL': ''}], null);

Output:
Javascript compiler exception: Can't find method com.snc.core_automation.Probe.createForAutoSelectMidServer(string,object). (null.null.script; line 5) in:

tim_broberg
ServiceNow Employee
ServiceNow Employee

I can't make any sense of that error with your code. You're calling with (string, object, null). Why would it say you're calling with (string, object)? Are you sure this code gives that error message?

If we're being fastidious, I would think you would want something more like:

probe.createForAutoSelectMidServer('Discovery', [{'capability': 'WMI'}], null);

This does require having Discovery (or All) application on your mids, suitable IP ranges, and your capabilities (ALL should do nicely).

If you're just trying to get the darned thing to work, you might try leaving the application and/or capabilities null.

Tim I actually used the below script and it works great. 

var hostName = 'win7rg8494e4';
var mid = new SNC.MidSelector();
mid = mid.selectAnyMidServer('Discovery', null);
var ms = new GlideRecord('ecc_agent');
ms.get(mid);
ms = ms.getValue('name');

var probe = SncProbe.get("Windows -IP Address");
probe.setSource(hostName);
probe.create(ms);

I created a probe to get the IP of the device, please see the below values on probe. I am getting the IP address of the device but only if I specify the device name in the powershell command. Do you have any idea on parsing device name to the powershell script?

Probe:

Name: Windows - IP Address

Probe Type: Probe

ECC queue topic: Powershell

ECC queue name: Powershell: IP Address

Probe Parameters->ipaddress.ps1->value(see below)

Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter IPEnabled=TRUE -ComputerName -Credential $cred | Format-Table -Property IPAddress

tim_broberg
ServiceNow Employee
ServiceNow Employee

Yeah, my Windows expertise was never that great, and it's atrophied even farther since I moved out of product development.

My ever-so-fuzzy recollection is that WMI probes are run against the target whereas powershell probes are run on the mid server itself.

Perhaps you want to start a separate discussion about how to retrieve the IP address in a Windows probe and hook in the guys that are sharp with Windows? I expect their eyes glazed over a long time ago on this thread.