Documentation – Playing with SecureCRT – Log to File and Simple Automation Python Script

Being clear from the beginning of the post here are some disclaimers I have:

  • I’m not an expert, I just like messing around with stuff that saves me time
  • The automation piece is a simple script in Python that is created from SecureCRT automatically

Now, as I document my projects, I have to find a way to provide my clients with meaningful information on what was what I did in their environment. I know engineers out there that hate documentation… me too, but when I do Documentation I just think like my client will think

  • Did I just pay all this $$$ to get a Word/Excel Document that only has meaningless screenshots and Configuration?
  • Ok, I just got a bunch of running configs… couldn’t I just get that from the device itself?

So cases may be that your client cares little or none about Documentation, but even if that is the case, I find Documentation fun (Sometimes) –> But I do procrastinate when I have to do it, is a ceremony πŸ™‚

Playing with Secure CRT, create a button and a script

So I want to record information from routers that will be meaningful for me, and that could be used to troubleshoot, maybe spot few issues here and there. I went ahead and created a quick .txt document with all the commands I thought will be useful


show run | sec vrf definition
sh ip vrf interface | ex down
sh ip interface brief | ex una
show dmvpn detail
show dmvpn inter tu100
show dmvpn inter tu200
show ip nhrp nhs
show run inter tu100
show run inter tu200
show run | inc ip route vrf
show run | sec router eigrp
show ip eigrp interfaces
show ip eigrp topology
sh run | sec route-map
show run | sec ip access-list
show run | sec crypto ikev2
show run | sec crypto ipsec
show run | sec crypto isakmp
show run | sec crypto key
sh ip flow interface
sh ip flow export
show flow interface
show flow exporter

 

Now when looking at a way to do it in just one shot, easy, just copy and paste right? – well that works, but what if I don’t want to do that πŸ™‚ –> I then remembered that there are things on SecureCRT that called Buttons and Scripts
** Have used them before and had some already on my Buttons bar
NewImage

To create a button you can use it for many things, in my case is just a .py script, how can the script be created? –> easy, just login to the session, Select Script on the Top Menu –> Select Start Recording Script, this will prompt you for a file to save all the action –> do your thing on the session (running commands) –> Go to the Script Menu again and select Stop Recording Script –> Now check your file.

If you notice and do it like that the .py or .vbs (Windows) script will have so much stuff that you don’t need, so to save time I did the following

Create a .py file like this


# $language = "python"
# $interface = "1.0"

# This automatically generated script may need to be
# edited in order to work correctly.

def Main():
	crt.Screen.Synchronous = True


Main()

Now I added to the beginning of the strings, or my commands

 crt.Screen.Send(" 

and at the end of it

 " + chr(13)) 

which will then make it look like this all completed


# $language = "python"
# $interface = "1.0"

# This automatically generated script may need to be
# edited in order to work correctly.

def Main():
	crt.Screen.Synchronous = True

	crt.Screen.Send("show run | sec vrf definition" + chr(13))
	crt.Screen.Send("sh ip vrf interface | ex down" + chr(13))
	crt.Screen.Send("sh ip interface brief | ex una" + chr(13))
	crt.Screen.Send("show dmvpn detail" + chr(13))
	crt.Screen.Send("show dmvpn inter tu100" + chr(13))
	crt.Screen.Send("show dmvpn inter tu200" + chr(13))
	crt.Screen.Send("show ip nhrp nhs" + chr(13))
	crt.Screen.Send("show run inter tu100" + chr(13))
	crt.Screen.Send("show run inter tu200" + chr(13))
	crt.Screen.Send("show run | inc ip route vrf" + chr(13))
	crt.Screen.Send("show run | sec router eigrp" + chr(13))
	crt.Screen.Send("show ip eigrp interfaces" + chr(13))
	crt.Screen.Send("show ip eigrp topology" + chr(13))
	crt.Screen.Send("sh run | sec route-map" + chr(13))
	crt.Screen.Send("show run | sec ip access-list" + chr(13))
	crt.Screen.Send("show run | sec crypto ikev2" + chr(13))
	crt.Screen.Send("show run | sec crypto ipsec" + chr(13))
	crt.Screen.Send("show run | sec crypto isakmp" + chr(13))
	crt.Screen.Send("show run | sec crypto key" + chr(13))
	crt.Screen.Send("sh ip flow interface" + chr(13))
	crt.Screen.Send("sh ip flow export" + chr(13))
	crt.Screen.Send("show flow interface" + chr(13))
	crt.Screen.Send("show flow exporter" + chr(13))

Main()

All terminal results to a file

Now to the next issue… I want to log everything to a file, but I really don’t want to Go to File, Log Session on SecureCRT.

My requirements

I want the name of the Router/Switch, the IP, and the Date I got that config file

So you have few options, you can apply a logging configuration to all the sessions your work with, or just the folder you need, I just like to do the folder I’m working on, just because I don’t want to log and record how I mess stuff on my other sessions… Maybe I should… πŸ™‚

NewImage

Once you go to the Properties of the Folder, just go to Log File
NewImage

Now I will explain that screenshot
Log File Name –> /folder/%S (%H) %M-%D.log
Upon Connect –> Start –> %S (%H) %M-%D-%Y ***This is some text that will be entered once the sessions starts
Upon Disconnect –> End –>%S (%H) %M-%D-%Y ***This is some text that will be entered as soon as the session ends
On each Line –> %h:%m:%s –> | This one is the time per line + some more cool characters to make it look very professional πŸ™‚

%S — The name of the session or the router/switch hostname
%H — The HOST or IP address in my case, since I entered all the connections by IP, I added Parenthesis to make it look cool πŸ™‚
%M — Month
%D — Day

The rest is self-explanatory. Last but not least, I found this information on this page –> http://www.ciscozine.com/how-to-log-securecrt/ Credit where credit is due

What to Look Forward to?

One of my tools and one of the things I wanted to record and share –> Feel free to contact me if you have any question like always, also feel free to share

About the Author:

Andres Sarmiento, CCIE # 53520 (Collaboration)
With more than 13 years of experience, Andres is specialized in the Unified Communications and Collaboration technologies. Consulted for several companies in South Florida, also Financial Institutions on behalf of Cisco Systems. Andres has been involved in high-profile implementations including Cisco technologies; such as Data Center, UC & Collaboration, Contact Center Express, Routing & Switching, Security and Hosted IPT Service provider infrastructures.

You can follow Andres using Twitter, LinkedIn or Facebook

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s