Reply

Issue Getting Output from device CLI via NetMRI API

New Member
Posts: 1
1823     0

Hello,

 

I need to get output from a device CLI via the NetMRI API from an external server. I am testing with the python script below which was posted here by SBaksh 

 

The issue seems to be with dis_sessions. This line just returns None:

cli_connection = client.api_request('dis_sessions/open_session_and_connection', params={'device_id': i.DeviceID})

 Here is the complete script:

# BEGIN-SCRIPT-BLOCK
#
# Script-Filter:
#     true
#
# Script-Login:
#     false
#
# Script-Variables:
#
# Script-Timeout: 
#	3670
#
# END-SCRIPT-BLOCK
import infoblox_netmri
from infoblox_netmri.client import InfobloxNetMRI
client = infoblox_netmri.client.InfobloxNetMRI(
                host='netmri.mydomain.com',
                username=http_username,
                password=http_password,
                api_version='3.7',
                use_ssl='true',
                ssl_verify='true'
                )
# Get brokers for required objects
device_broker = client.get_broker('Device')	
# Search for our 2 devices to get the Id's	
devices = device_broker.search(DeviceName=[
            'nameOfDevice1','nameOfDevice2'
            ])
for i in devices:
    # Open Dis and Cli Session
    print('Opening DIS and Cli Session for device_id: ',i.DeviceID)
    cli_connection = client.api_request('dis_sessions/open_session_and_connection', params={'device_id': i.DeviceID})
    print("Cli Connection: ",cli_connection)
    # Send Command
    response = client.api_request('cli_connections/send_command', params={'SessionID': cli_connection['cli_connection']['SessionID'], 'device_id': i.DeviceID, 'command': 'sh ip int brief'})
    print("Send Response: ",response)
    # Close the Session
    response = client.api_request('dis_sessions/close', params={'SessionID': cli_connection['cli_connection']['SessionID']})
    print("Close response: ",response) 

 

Re: Issue Getting Output from device CLI via NetMRI API

Guru
Posts: 23
1824     0

Hi, Did you ever get this to work? I tested my script again and it is working fine (with show cdp nei).

Rgds

Showing results for 
Search instead for 
Did you mean: 

Recommended for You