Start Discovery via API

mikefountain
Kilo Contributor

Working on network switch discovery.     The plan is to run an external script to do some ping sweeps and other actions in order to make sure the mac and arp tables are current.     Once that script is done doing it's thing, I want it to start an on-demand discovery schedule.

Is there any way an external program could start a discovery schedule via an API call or some other method?

1 ACCEPTED SOLUTION

Alex Mittell
ServiceNow Employee
ServiceNow Employee

You could create a scheduled discovery job then trigger it with a script include, see here for details on StartDiscovery method.



Discovery (Script Include) - ServiceNow Wiki



You could then call it from a client side script using GlideAjax (GlideAjax - ServiceNow Wiki ) or if you're in Geneva you could create a Scripted REST API endpoint (Create a scripted REST API resource) for your external program to call, the nice part about the latter is it's simple to create and provides a nice easy way to pass output back to your external program.


View solution in original post

4 REPLIES 4

Alex Mittell
ServiceNow Employee
ServiceNow Employee

You could create a scheduled discovery job then trigger it with a script include, see here for details on StartDiscovery method.



Discovery (Script Include) - ServiceNow Wiki



You could then call it from a client side script using GlideAjax (GlideAjax - ServiceNow Wiki ) or if you're in Geneva you could create a Scripted REST API endpoint (Create a scripted REST API resource) for your external program to call, the nice part about the latter is it's simple to create and provides a nice easy way to pass output back to your external program.


I did something similar a while back. I used Workflows and several Run Scripts; you can use it in any back-end script. Here is the high level summary.



a. You may create a probe PowerShell or Unix which does the ping sweep


b. Can the cmdb_tcp table be used in lieu of a ping sweep?   Find the unique list of IP addresses found by Discovery


c. Either way the above probe should return an array for the next probe to process


d. You can create and launch probes on demand - I posted a sample here Unable to run remote command through Powershell


e. The above steps are very high level but I think the concept will work



Please let us know your findings, thanks,


Subash Biswas


Hello, 

I need to create a Webservice API where input is: Sys ID of any record and output is: all *related* active records to that sys id. The relationships between the tables is maintained in Relationships under system definition.

Could you please guide me how to implement this? Sample code would be great.

Input: Sys ID of the record 
Output: All *RELATED* active records from *VARIOUS* tables (in the following JSON format):
{
"result": [
{
"Sys ID": "5520267",
"CI Name": "Record 1",
"Table Name": "u_table_a"
},
{
"Sys ID": "5520367",
"CI Name": "Record 2",
"Table Name": "u_table_a"
},
{
"Sys ID": "8331210",
"CI Name": "Record 1",
"Table Name": "u_table_b"
},
{
"Sys ID": "8321210",
"CI Name": "Record 2",
"Table Name": "u_table_b"
},
{
"Sys ID": "3042006",
"CI Name": "Record 3",
"Table Name": "u_table_b"
},
{
"sys_id": "4509847",
"CI Name": "Record 1",
"Table Name": ""u_table_c"
}
{
"sys_id": "4509247",
"CI Name": "Record 2",
"Table Name": ""u_table_c"
}
]
}

mikefountain
Kilo Contributor

We just upgraded to Geneva, so I wound up going with something similar to the scripted call that Alex suggested, although I'm not firing off a probe with it.   I decided to put my external script on a cron job, have it run, and then pass the data/results to a scripted api.



Basically along these lines:


1) External script queries ServiceNow for a list of Cisco switches in a given environment


2) External script does some SSH commands to get MAC and ARP tables from switches


3) If there are any interfaces on those switches that didn't have MAC entry, external script ping-sweeps that network


4) External script re-runs MAC commands against any switches that ping-sweep covered to see if we picked up any new entries


5) External script correlates all the data, formats, and then passes it to a scripted REST API created in the ServiceNow instance


6) The script associated with that API takes that data and creates/deletes/updates any tables and CI relationships as a result of the discovery