Using NetBrain Data to Populate Other CMDBs

This best practice is recommended for users who use NetBrain as the primary CMDB and would like to populate another vendor's database with NetBrain data.

Workflow

The pseudo-code below describes the main flow in the API script to export all device data from NetBrain database.

1. Login to NetBrain API server and get session
2. Set the current domain
3. Call GetAllDevices
4. For each device 
    i. Call GetAllDeviceAttributes to get all device properties
    ii.Call GetAllInterfaces
    iii.For each interface
        a. Call GetAllInterfaceProperties to get all interface properties
    iv. Call GetAllModules
    iii.For each module
        a. Call GetAllModuledProperties to get all module properties
5. Logout from Netbrain API server

API Script

You can refer to the script below to call relative APIs. This sample script first imports a python library maintained by NetBrain and you need to write your own one in practical use.

import netbrain_restful_lib
import time
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import pprint
   
user = "NetBrain"      
pwd = "Netbrain"      
nb_url = "http(s)://<IP address of NetBrain Web Server>/"           
headers = {'Content-Type''application/json''Accept''application/json'}
tenantName = "Initial Tenant"
domainName = "Use Case"
   
#################################################################
   
# Step 1: Login to NetBrain API server and get session
print("Step 1")
token = netbrain_restful_lib.loginSession(nb_url, user, pwd)
print("Token: "+token)
print(netbrain_restful_lib.getTenants(nb_url, token))
print(netbrain_restful_lib.getDomains(nb_url, token))
#Sample results
# token : adf5b560-8e9c-4114-87bb-2eed24f0faff
# tenantList : [{'tenantId': 'a50af282-fa02-012f-a7f7-e410cc7c29d3', 'tenantName': 'Initial Tenant'}]
# domainList : [{'domainName': 'UseCase', 'domainId': '4f747a8b-71da-404b-a05c-e8505aa14725'}]
    
tenantId = 'cb36f82b-4126-2fef-5310-c3a66f3dae4d'
domainId = '6f9be63d-2290-4121-ae8b-c8fdb53a56ec'
    
  
# Step 2: Set current domain
print("Step 2")
print(netbrain_restful_lib.loginDomain(nb_url, token, tenantId, domainId))
# Sample results
# loginDomain: Login successfully!
    
  
# Step 3: Call GetAllDevices
#print("Step 3")
#devices = netbrain_restful_lib.getDevice(nb_url, token, None)
#print("Get All Devices: "+str(devices))
#devicelist = []
#for i in devices:
#    devicelist.append({"Device": i['hostname']})
# Sample results
# Get All Devices : [{'id': 'ae18acc3-ee91-464d-b1d1-efd6cdecbcc9', 'mgmtIP': '172.16.8.199', 'hostname': 'NBCNBJ-SRX2', 'deviceTypeName': 'Juniper SRX Firewall'}, {'id': 'e1543c3a-d410-453d-b392-4f21e260d391', 'mgmtIP': '172.16.8.199'}]
  
devicelist = [{'Device''NBCNBJ-SRX2'}]
 
 
# Step 4(i): For each device, call GetAllDeviceAttributes to get all device properties
print("Step 4(i)")
for i in devicelist:
    deviceattributes = netbrain_restful_lib.getDeviceAttributes(nb_url, token, i['Device'], None)
    print("Device attributes of "+i['Device']+ " are "str(deviceattributes))
    # Sample results
    # Device attributes of NBCNBJ-SRX2 are {'name': 'NBCNBJ-SRX2', 'mgmtIP': '172.16.8.199', 'mgmtIntf': 'ge-7/0/8.0', 'subTypeName': 'Juniper SRX Firewall', 'vendor': 'Juniper', 'model': 'SRX', 'ver': '12.1X46-D20.5', 'sn': '212787163ef9', 'site': 'My Network\\Asia\\China\\BJ', 'loc': '', 'contact': '', 'mem': '', 'assetTag': '', 'layer': '', 'descr': '', 'oid': '1.3.6.1.4.1.2636.1.1.1.2.96', 'driverName': 'Juniper SRX Firewall', 'assignTags': '', 'hasBGPConfig': False, 'hasOSPFConfig': True, 'hasEIGRPConfig': False, 'has ISISConfig': False, 'hasMulticastConfig': False, 'attributeName': ''}
    i['Device Attributes'] = deviceattributes
 
  
 
# Step 4(ii): For each device, call GetAllInterfaces
print("Step 4(ii)")
for i in devicelist:
    interfaces = netbrain_restful_lib.getInterfaces(nb_url, token, i['Device'])
    print("Interfaces of "+i['Device']+ " are "str(interfaces))
    # Sample results
    # Interfaces of NBCNBJ-SRX2 are ['ge-0/0/2.0', 'ge-0/0/3.0', 'ge-0/0/4.0']
    interfacelist = []
    for j in interfaces:
        interfacelist.append({"Interface Name":j})
 
    # Step 4(iii): For each interface, call GetAllInterfaceProperties to get all interface properties
    print("Step 4(iii)")
    for k in interfacelist:
        interfaceAttributes = netbrain_restful_lib.getInterfaceAttributes(nb_url, token, i['Device'], k["Interface Name"], None)
        print("Interface atributes are: "+str(interfaceAttributes))
        # Sample results
        # Interface atributes are: Interface Attributes :{'hostname': 'NBUSCA-SW7', 'attributes': {'Vlan1': {'name': 'Vlan1', 'ips': '', 'ipv6s': '', 'ipv6LinkLocalAddress': '', 'mibIndex': 10, 'bandwidth': 1000000, 'speed': '', 'duplex': '', 'intfStatus': 'administratively down/down', 'macAddr': 'aabb.cc81.6100', 'moduleSlot': '', 'moduleType': '', 'descr': '', 'routingProtocol': '', 'multicastMode': '', 'mplsVrf': '', 'inAclName': '', 'outAclName': '', 'mode': '', 'vlan': '', 'trunkNativeVlan': '', 'trunkEncapsulation': '', 'ipUnnumberedIp': ''}}, 'statusCode': 790200, 'statusDescription': 'Success.'}
        k['Interface Attributes'] = interfaceAttributes
 
    i['Interfaces'] = interfacelist  
 
pprint.pprint(devicelist)
 
 
 
# Step 10: Logout to NetBrain API server
print("Step 10")
print(netbrain_restful_lib.logoutSession(nb_url, token))