Created
December 19, 2016 14:34
-
-
Save tcuthbert/b550362f14fa154901b7a27c4e9f52dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from datetime import timedelta | |
from time import asctime, localtime, time | |
from trigger.cmds import Commando | |
class ShowTech(Commando): | |
"""Execute 'show clock' on a list of Cisco devices.""" | |
vendors = ['cisco'] | |
commands = ['show tech-support'] | |
if __name__ == '__main__': | |
start = time() | |
print "Starting time is:", asctime(localtime(start)) | |
device_list = ['pe1.demo.localdomain', 'pe2.demo.localdomain', 'p1.demo.localdomain', 'p2.demo.localdomain', 'p3.demo.localdomain', 'p4.demo.localdomain'] | |
showtech = ShowTech(devices=device_list) | |
showtech.run() # Commando exposes this to start the event loop | |
sys.stdout.write('\nNumber of times I\'ve seen the word Buffer in show tech-support: ') | |
count = 0 | |
for host in showtech.results: | |
for line in showtech.results[host]['show tech-support'].splitlines(): | |
if 'uffer' in line: | |
count += 1 | |
with open('out/{}.txt'.format(host), 'w') as f: | |
f.write(showtech.results[host]['show tech-support']) | |
sys.stdout.write("{}\n".format(count)) | |
finish = time() | |
total_time = finish - start | |
print "Finishing time is:", asctime(localtime(finish)) | |
print "Time taken to retrieve tech support from all devices and dump to disk: {} ({})".format(str(timedelta(seconds=int(total_time))), asctime(localtime(finish))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment