Using Other CMDB Data to Populate NetBrain

This best practice is recommended for users who maintain another vendor as the primary CMDB and would like to populate NetBrain database with information from the CMDB.

Workflow

The pseudo-code below describes the main flow in the API script to import data from the CMDB to NetBrain.

1. Login to NetBrain API server and get session
2. Set the current domain
3. Create custom device attribute using CreateDeviceAttribute
4. Create custom interface attribute using CreateInterfaceAttribute
5. For every device
    a. Set value of the custom device attribute
    b. For every interface
       1. Set value of the custom interface attribute
6. Logout 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!
    
 
# The data which needs to be imported
data=[{"device":"NBUSMA-R1""DeviceAtt1":"Value of DeviceAtt1""interfaces":[{'interface':  "f3/0 10.30.7.147/29""InterfaceAtt1":"Value of InterfaceAtt1"},{'interface':  "f0/0 172.16.8.192/22""InterfaceAtt1":"Value of InterfaceAtt1"}] }]
 
 
# Step3: Create custom device attribute using CreateDeviceAttribute
print("Step 3")
attributeName= "DeviceAtt1"
attributeDisplayName="DeviceAtt1"
deviceTypeNames="Null"
dataType="string"
isFullSearch=True
print(netbrain_restful_lib.createDeviceAttribute(nb_url, token, attributeName, attributeDisplayName, deviceTypeNames, dataType, isFullSearch))
 
 
# Step4: Create custom interface attribute using CreateInterfaceAttribute
print("Step 4")
interfaceType="intfs"
attributeName= "InterfaceAtt1"
attributeDisplayName="InterfaceAtt1"
deviceTypeNames="Null"
dataType="string"
isFullSearch=True
print(netbrain_restful_lib.createInterfaceAttribute(nb_url, token, interfaceType, attributeName, attributeDisplayName, deviceTypeNames, dataType, isFullSearch))
 
 
# Step 5a: For every device, set value of the custom device attribute
print("Step 5a")
for i in data:
    print(i["device"])
    print(i["DeviceAtt1"])
    print(netbrain_restful_lib.setDeviceAttribute(nb_url, token, i["device"], "DeviceAtt1", i["DeviceAtt1"]))
 
# Step 5b: For every interface, set value of the custom interface attribute
    print("Step 5b")
    for j in i["interfaces"]:
        #print(j["interface"])
        #print(j["InterfaceAtt1"])
        print(netbrain_restful_lib.setInterfaceAttribute(nb_url, token, i["device"], "InterfaceAtt1", j["InterfaceAtt1"], j["interface"]))
 
 
# Step 6: Logout to NetBrain API server
print("Step 6")
print(netbrain_restful_lib.logoutSession(nb_url, token))