- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-02-2018 01:51 PM
I have a need to compare two device output snapshots (call them "before" and "after") in some easily human visible way. The snapshots consist of a series of Cisco IOS "show xxx" commands, where the output is captured before some significant change is made, and then after. Basically, the initiator wants to know if everything resumed to normal or if there were any "surprises".
NetMRI scripts support creating each output sequence via the "PRINT" and "ARCHIVE" script directives. What's missing is some way to compare those side-by-side.
The API includes the "config_diff" function, but of course that's limited to comparing two collected and stored config revisions. Is there a way to exploit the nice side-by-side UI diff function, but for two arbitrary files?
The only alternative that I've come up with is to export the two result files to another platform where some other graphical "diff" program is used to perform the side-by-side comparison.
TIA,
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
08-03-2018 11:58 AM - edited 08-03-2018 12:16 PM
This may take a bit of extra work, but just wanted to mention a possible workaround in 7.3.1 by using the import_custom_config api call.
You can either add a dummy IP address as static entry and once the device viewer is created, manually change the Device Type from "unknown" to "Switch".
You can then upload both snapshot configs to this dummy IP by using the following link format on a new Tab of the browser.
http://<NetMRI-IP-Address>/api/3.3/config_revisions/import_custom_config?DeviceID=<ID>&RunningConfig="<A>"&SavedConfig="<B>"
Where
<NetMRI-IP-Address> - Your Appliance IP-Address or fqdn name
<ID> - DeviceID created for the new device
<A> - Snapshot before
<B> - Snapshot after
Note: There is an easier way to do this. This api call will also work on the existing device's DeviceID, so if you want to upload configs to any existing InfraDevice's Device Viewer, the static entry step can be skipped. However, please make sure, you delete the uploaded configs later, to avoid a confusion in the future and also to avoid triggering of issues like "Config Diff" etc.
This will allow you to use the usual Compare function on the Config Explorer
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-13-2018 10:10 AM
Do you want to do this in the UI or are you looking at doing it externally?
Sif
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-11-2019 05:57 PM
I have a similar issue of wanting to compare "Before the change" and "After the change" show command outputs within a Python script (internal to NetMRI). Then to save the compare in the job Archive as a separate file, which I don't know how to do. I found the following code as a test that creates a nice html output. Not sure of its limitations, but it is interesting.
I ran this Python in the sandbox, I don't see why it wouldn't run as a job as well. This is still a work in progress
Let me know if you've gotten anyplace with this.
import difflib text1 = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer eu lacus accumsan arcu fermentum euismod. Donec pulvinar porttitor tellus. Aliquam venenatis. Donec facilisis pharetra tortor. In nec mauris eget magna consequat convallis. Nam sed sem vitae odio pellentesque interdum. Sed consequat viverra nisl. Suspendisse arcu metus, blandit quis, rhoncus ac, pharetra eget, velit. Mauris urna. Morbi nonummy molestie orci. Praesent nisi elit, fringilla ac, suscipit non, tristique vel, mauris. Curabitur vel lorem id nisl porta adipiscing. Suspendisse eu lectus. In nunc. Duis vulputate tristique enim. Donec quis lectus a justo imperdiet tempus.""" text1_lines = text1.splitlines() text2 = """Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer eu lacus accumsan arcu fermentum euismod. Donec pulvinar, porttitor tellus. Aliquam venenatis. Donec facilisis pharetra tortor. In nec mauris eget magna consequat convallis. Nam cras vitae mi vitae odio pellentesque interdum. Sed consequat viverra nisl. Suspendisse arcu metus, blandit quis, rhoncus ac, pharetra eget, velit. Mauris urna. Morbi nonummy molestie orci. Praesent nisi elit, fringilla ac, suscipit non, tristique vel, mauris. Curabitur vel lorem id nisl porta adipiscing. Duis vulputate tristique enim. Donec quis lectus a justo imperdiet tempus. Suspendisse eu lectus. In nunc. """ text2_lines = text2.splitlines() d = difflib.HtmlDiff() print d.make_file(text1_lines, text2_lines)
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-11-2019 07:14 PM
So, I got the script running now as an internal job and will output the html comparison to the sandbox. I don't see any other way to mimic the CCS Archive method in Python in order to add the file to the All.zip.
Maybe it will help someone, so my code is below. Basically do a show command, then make changes to router (Nexus), then do the show command again, and compare.
# BEGIN-SCRIPT-BLOCK # # Script-Filter: # true # # Script-Variables: # # Script-Timeout: # 300 # # END-SCRIPT-BLOCK import requests, json, re, time, datetime from infoblox_netmri.easy import NetMRIEasy import difflib # This values will be provided by NetMRI before execution defaults = { "api_url": api_url, "http_username": http_username, "http_password": http_password, "job_id": job_id, "device_id": device_id, "batch_id": batch_id } # Create NetMRI context manager. It will close session after execution with NetMRIEasy(**defaults) as easy: # Run these commands one time at the start BeforeChanges = easy.send_command('show ip route vrf all') BeforeChanges_lines = BeforeChanges.splitlines() DoCommand = easy.send_command('config t') DoCommand = easy.send_command('vlan 4') DoCommand = easy.send_command('name Lon-test4') DoCommand = easy.send_command('exit') DoCommand = easy.send_command('vrf context Lon-test4') DoCommand = easy.send_command('exit') DoCommand = easy.send_command('interface Vlan4') DoCommand = easy.send_command('vrf member Lon-test4') DoCommand = easy.send_command('no ip redirects') DoCommand = easy.send_command('ip address 2.2.2.2/30') DoCommand = easy.send_command('no shutdown') DoCommand = easy.send_command('exit') DoCommand = easy.send_command('exit') AfterChanges = easy.send_command('show ip route vrf all') AfterChanges_lines = AfterChanges.splitlines() d = difflib.HtmlDiff() with open('BeforeAfter_Compare.html', 'w') as f: f.write(d.make_file(BeforeChanges_lines, AfterChanges_lines, "BeforeChanges", "AfterChanges", True, 5)) f.close()
The html output will look something like this:
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 08:44 AM
Great Script and thanks for sharing
An option you can use "easy.log_message"
easy.log_message('info', device.DeviceName)
easy.log_message('info', "my message")
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 09:49 AM
Thanks Sif, that gets it part way there at least, by writting to the custom.log. Too bad we can't change the extension on the file to html, or just add a new file as we wish. So, at the end of the script, I changed out writing to a file for the following code:
d = difflib.HtmlDiff() easy.log_message('info', device_devicename) easy.log_message('info', d.make_file(BeforeChanges_lines, AfterChanges_lines, "BeforeChanges", "AfterChanges", True, 5))
You may not want to put the device name at the top if keeping the log as html.
Thanks!
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 12:33 PM
Ok, I forgot about ARCHIVE.
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 12:48 PM
But Sif, this is a Python script. Are you telling me there is a way to ARCHIVE using Python? CCS would have worked for this script except for that we needed the Diff functionality. Or perhaps there is a way to call Python Lib within CCS?
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 12:52 PM
LOL, the beauty of NetMRI you can use that ARCHIVE command in PERL and Python
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 12:54 PM
Okay Sif, I'm feeling you'll need to bust me back down to Techie here, please provide an example of the syntax for Python and Perl with the ARCHIVE statement --
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 01:01 PM
Real simple
CCS Version
ARCHIVE (startup): sh startup-config
PERL or Python
DoCommand = easy.send_command(ARCHIVE (startup): sh startup-config)
or
DoCommand = easy.log(ARCHIVE (startup): sh startup-config)
Should work, I haven't test it, but of course now I will
Twitter: https://twitter.com/sifbaksh
https://sifbaksh.com
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-12-2019 03:53 PM
Well, after some testing, the send_command with the ARCHIVE works great (with quotes, shown below), but no success with the log_message command.
# Creates an ARCHIVE file Perfectly in Pyton and shows in the Files tab: BeforeChanges = easy.send_command('ARCHIVE (BeforeChanges): show ip route vrf all') # This one doesn't work, tried various configurations, just adds to custom.log: easy.log_message('info','ARCHIVE (device_devicename): d.make_file(BeforeChanges_lines, AfterChanges_lines, "BeforeChanges", "AfterChanges", True, 5)')
Ideally, I would like to create the Diff output as it's own ARCHIVE file.
...so close!
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
02-13-2019 08:48 AM
Rajiv - Just discovering that the import_custom_config requires both Running and Saved params to be passed to work
Would have been much more flexible if we could add one at a time.
-Lon.
Re: How to leverage NetMRI internal config comparison function for other than config revisions?
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-19-2019 08:20 AM - edited 10-02-2019 06:52 AM
Everyone is satisfied with the answers given by you. Thanks, for your support.
https://financepolice.com/