- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
10-22-2015 04:20 PM
Here is a Python code to run our “Ad Hoc Command Batch” and executing a “show version” on the device.
The other key factor is the device ID, I would cheat right now to find the device ID so the can test it, buy using this method.
Network Explorer -> Discovery -> Find the device you are looking for click on the IP address to bring up the “Device Viewer” and highlighted in Pink below is the device ID for 10.66.21.81
Python Code:
__author__ = 'sbaksh' #!/usr/bin/python # -*- coding: utf-8 -*- import requests import json # Declare the IP Address NetMRI is configured on netmri = "https://netmriIP/api/2.9/" # The SysAdmin user account we are using to login username = "sbaksh" password = "mypassword" requests.packages.urllib3.disable_warnings() def run_adhoc(): object_type = "scripts/run?name=Ad Hoc Command Batch&$commands_to_be_executed=sh version&device_ids=24607" data = requests.get(netmri + object_type, verify=False, auth=(username, password)) json_input = data.text print json_input run_adhoc() print "Completed"
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2018 07:06 AM
Hi Sif -
I was trying out your script and wanted to add the 'wait' parameter in, but the call keeps giving me an error. I've tried it both as an integer and a string for the seconds to wait. I wanted to see what the payload result would look like. The job executes and completes just fine and returns the job id if I exclude the 'wait'.
Could you give it a try, please?
def run_adhoc(): data = client.api_request( 'scripts/run', params={ 'name': "NW - Ad Hoc Command Batch", '$commands_to_be_executed': "sh version", 'device_ids': "290", 'credential_mode': "requestor", 'wait': 30, } ) json_input = data.text print json_input python ad_hoc_command.py Traceback (most recent call last): File "ad_hoc_command.py", line 38, in <module> run_adhoc() File "ad_hoc_command.py", line 32, in run_adhoc 'wait': 30, File "/home/netmrift/lib/python2.7/site-packages/infoblox_netmri-3.2.0.0-py2.7.egg/infoblox_netmri/client.py", line 227, in api_request return self._make_request(url=url, method="post", data=data) File "/home/netmrift/lib/python2.7/site-packages/infoblox_netmri-3.2.0.0-py2.7.egg/infoblox_netmri/client.py", line 103, in _make_request return self._send_request(url, method, data, extra_headers) File "/home/netmrift/lib/python2.7/site-packages/infoblox_netmri-3.2.0.0-py2.7.egg/infoblox_netmri/client.py", line 129, in _send_request raise HTTPError(res.json(), response=res) requests.exceptions.HTTPError: {u'message': u'SQL::Error', u'error': u'general/unexpected-error'}
Thanks,
Lon.
Re: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2018 10:37 AM
This is what I did:
broker_script = myeasy.broker('Script')
save_new = {
"name" : "sif_adhoc",
"device_ids" : device_id,
"job_name" : "Save New Config",
"username" : "seuser",
"password" : "serouter"
}
time.sleep(20)
broker_script.run (**save_new)
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2018 10:42 AM
So are you infering that the 'wait' didn't work for you either? I can open a new case if it doesn't work.
Thanks,
Lon.
Re: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2018 12:19 PM
Re: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-10-2018 12:25 PM
I'm running it from outside of NetMRI as a client. The 'wait' is documented in the NetMRI API, Perl and Python libraries for scripts/run.
Re: Python - External Script to Run the "Ad Hoc Command Batch" on NetMRI
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
05-14-2018 07:16 AM
Since you are getting the error on the "wait", I would grab the user JobID once it runs and then gets the status via another call
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com