Use Case - Return Map URL of a Calculated Path to Third-party System

In a third-party system, you can trigger NetBrain 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 NetBrain side and third-party system side.

1.In NetBrain:
1.1 Open System Automation Task Manager in NetBrain 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.

API Script

You can refer to the script below to call APIs. This sample script first imports a python library maintained by NetBrain, 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 NetBrain 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 = ""
api.GetGatewayInfo(nb_url, token, sourceIP)
# [{'ip': '', 'devName': 'HSRP', 'intfName': '21'},
# {'ip': '', 'devName': 'NBCNBJ-SW1', 'intfName': 'Vlan2100'},
# {'ip': '', 'devName': 'NBCNBJ-SW2', 'intfName': 'Vlan2100'}]
# Step2.4: Trigger Path and get Map ID.
stub_name = "PathStub"
sourceGwIP = ""
destIP = ""
sourcePort = 80
destPort = 80
TriggerPathInput = {
        'tenant_id': tenantId,
        'domain_id': domainId
    #Trigger Stub information
        'user': user,
        'stub_name': stub_name,      # Name of the stub you created in NetBrain
        'triggered_by':"API Script",
    #Map information (Optional)
        "map_create_mode":3#3 is Path mode
            "source": sourceIP,
            "source_gateway": sourceGwIP,
map_url = api.TriggerPathMap(nb_url, token, TriggerPathInput)
# MapURL:
# &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: