<< Click to Display Table of Contents >> Raynet One > 1.1 > User Guide > Technical overview > API Use case: discovery with REST API |
Keeping an up-to-date representation of your IT landscape inside of your Raynet One environment is important. During important events such as network maintenance or asset expansion the actual list of devices may change greatly. It may be difficult to schedule the event's duration. Using the discovery functionality of the API, the device discovery job can be requested just after an event's completion, leaving no room for inaccuracy.
This sample introduces the concept of inventory instrument identifiers to select a distinct inventory execution strategy. Raynet One consists of many components, some of them loaded as plugins. You can explore the available identifiers by visiting the Plugins page of the Configuration workspace. Open the plugin, switch to the Instruments tab and expand all instrument sections to find the identifier strings. The instrument type field decides the instrument's applicability. For this use case, the instruments of type NetworkDiscoveryInstrument are applicable.
This use case shows you two ways to trigger device discovery: full and specific. In the case of large IT landscape asset change, it is a good idea to rescan the entire reachable IT network. If the scope of device change can be reduced to a well defined network region, the IT administration may optimize inventory execution by advanced IT landscape scope selection (single networks, sites, ...).
•Python 3+
•Requests library (https://docs.python-requests.org/en/latest/)
•API key
•frontend URL
import requests
APIKEY = "PUT API KEY HERE"
FRONTEND = "PUT FRONTEND URL HERE"
HEADERS = { "ApiKey": APIKEY }
def main():
req_sites = requests.get(FRONTEND + "/api/v1/Site", headers=HEADERS)
if req_sites.ok == False:
print("failed to request list of sites from the frontend (" + FRONTEND + ")")
return
sites = req_sites.json()
if sites == None:
print("failed to get sites from the frontend (" + FRONTEND + ")")
return
site_id_list = []
for S in sites:
if "id" in S:
site_id_list.append( S["id"] )
postdata = {
"type": "network",
"useCustomSettings": False,
"networkDiscoveryData": {
"targetType": "sites",
"instrumentIdentifier": "PingSweepNetworkDiscoveryInstrument",
"selectedSiteIds": site_id_list
}
}
R = requests.post(FRONTEND + "/api/v1/Operations/discovery", headers=HEADERS, json=postdata)
if R.ok:
print("triggered IT landscape discovery")
else:
print("failed to trigger discovery (" + str(R.status_code) + ", " + R.reason + ")" )
error_details = R.json()
if error_details != None and "details" in error_details:
print( "error details: " + error_details["details"] )
•Python 3+
•Requests library (https://docs.python-requests.org/en/latest/)
•API key
•frontend URL
•manually created network inside of the web interface
import requests
APIKEY = "PUT API KEY HERE"
FRONTEND = "PUT FRONTEND URL HERE"
HEADERS = { "ApiKey": APIKEY }
NETWORK_IP = "192.168.1.0"
NETWORK_CIDR = 24
def obtain_paged(EP):
P = {}
P["count"] = 1000
items = []
while True:
result = requests.get(EP, params=P, headers=HEADERS)
if result.ok == False:
break
objs = result.json()
if objs == None:
return
if len(objs) == 0:
return
items.extend(objs)
lastobj = objs[len(objs)-1]
P["LastId"] = lastobj["id"]
return items
def main():
networks = obtain_paged(FRONTEND + "/api/v1/Networks")
if networks == None:
print( "failed to request networks from frontend (" + FRONTEND + ")" )
return
network = None
for N in networks:
if "network" in N and "cidr" in N:
if NETWORK_IP == N["network"] and NETWORK_CIDR == N["cidr"]:
network = N["id"]
break
if network == None:
print( "network not found (" + FRONTEND + ")" )
return
postdata = {
"type": "network",
"useCustomSettings": True,
"networkDiscoveryData": {
"targetType": "networks",
"instrumentIdentifier": "PingSweepNetworkDiscoveryInstrument",
"selectedNetworkIds": [network]
},
"customSettings": {
"isDefault": False,
"newDeviceBehaviour": "ignore",
"newNetworkBehaviour": "ignore",
"newOracleDbFoundBehaviour": "autoDiscovery"
}
}
R = requests.post(FRONTEND + "/api/v1/Operations/discovery", headers=HEADERS, json=postdata)
if R.ok:
print("triggered single network discovery (" + NETWORK_IP + ":" + str(NETWORK_CIDR) + ")")
else:
print("failed to trigger discovery (" + str(R.status_code) + ", " + R.reason + ")" )
error_details = R.json()
if error_details != None and "details" in error_details:
print( "error details: " + error_details["details"] )