In a third-party system, you can trigger NetworkBrain to calculate an end-to-end path and then return the map URL of the calculated path to the third-party system.
The pseudo-code below describes the main flow at both the NetworkBrain side and third-party system side.
1.In NetBrain:
1.1 Open System Automation Task Manager in NetworkBrain Desktop.
1.2 Under API Stub Manager, create a Stub and choose "Map a Path". Check online help for more setting detail.
1.3 [Optional] Add pre-defined Runbook into the Stub if needed.
1.4 Save and enable the Stub.
2.In Script (third-party system):
2.1 Login into NetBrain session and get system token.
2.2 Set the operation tenant and domain.
2.3 Get the default gateway information of Source IP.
2.4 Trigger Path and get Map ID.
2.5.0 Back to NetBrain API Stub Manager, check trigger history under API Triggered Tasks, and open the Map.
2.5.1 [Optional] Export the Map Visio or Xmap.
2.6 Logout the session.
Note: Step 2.5.0 is a must if step 2.5.1 is defined, because the system will not create map record until you open the map task id.
You can refer to the script below to call APIs. This sample script first imports a python library maintained by NetworkBrain, and you need to write your own ones in practical use.
import netbrain_restful_lib as api
import base64
##########
nb_url = "http(s)://<IP address of NetworkBrain Web Server>/"
user = "NetBtain"
pwd = "Netbrain"
tenantName ='Initial Tenant'
domainName = 'Integration'
##########
# Step2.1: Login into NetBrain session and get system token.
token = api.loginSession(nb_url, user, pwd)
print(api.getTenants(nb_url, token))
print(api.getDomains(nb_url, token))
# [{'tenantId': 'cb36f82b-4126-2fef-5310-c3a66f3dae4d', 'tenantName': 'Initial Tenant'},
# {'tenantId': '1aae7b92-520f-4d22-96ed-9ccc77ab5678', 'tenantName': 'TenantName'}]
# [{'domainId': '6f9be63d-2290-4121-ae8b-c8fdb53a56ec', 'domainName': 'Integration'}]
tenantId = "cb36f82b-4126-2fef-5310-c3a66f3dae4d"
domainId = "6f9be63d-2290-4121-ae8b-c8fdb53a56ec"
# Step2.2: Set the operation tenant and domain.
print(api.loginDomain(nb_url, token, tenantId, domainId))
# loginDomain: Login successfully!
# Step2.3: Get the default gateway information of Source IP.
sourceIP = "10.30.8.108"
api.GetGatewayInfo(nb_url, token, sourceIP)
# [{'ip': '10.30.8.105', 'devName': 'HSRP', 'intfName': '21'},
# {'ip': '10.30.8.106', 'devName': 'NBCNBJ-SW1', 'intfName': 'Vlan2100'},
# {'ip': '10.30.8.107', 'devName': 'NBCNBJ-SW2', 'intfName': 'Vlan2100'}]
# Step2.4: Trigger Path and get Map ID.
stub_name = "PathStub"
sourceGwIP = "10.30.8.105"
destIP = "10.30.7.108"
sourcePort = 80
destPort = 80
TriggerPathInput = {
'domain_setting':
{
'tenant_id': tenantId,
'domain_id': domainId
},
#Trigger Stub information
'basic_setting':
{
'user': user,
'stub_name': stub_name, # Name of the stub you created in NetBrain
'triggered_by':"API Script",
},
#Map information (Optional)
"map_setting":
{
"map_create_mode":3, #3 is Path mode
"map_path_para":
{
"source": sourceIP,
"source_gateway": sourceGwIP,
"destination":destIP,
"source_port":sourcePort,
"destination_port":destPort
}
}
}
map_url = api.TriggerPathMap(nb_url, token, TriggerPathInput)
print(map_url)
# MapURL: https://integrationlabv71.netbraintech.com/map.html?t=cb36f82b-4126-2fef-5310-c3a66f3dae4d
# &d=6f9be63d-2290-4121-ae8b-c8fdb53a56ec&id=145f86ad-de4e-4b7b-9ea9-48c52c20319f&maptype=1
# Step2.5.0: Open Map in API Triggered Tasks.
# Step2.5.1: [Optional] Export the Map Visio or Xmap.
map_format = "visio" # visio or xmap
pages = None # Specify the Map page. If None, all pages will be exported.
map_data = api.ExportMap(nb_url, token, map_url, map_format, pages)
if map_data:
folder = r"D:\\path.vsdx"
with open(folder, "wb") as ff:
ff.write(base64.b64decode(map_data))