Last month was a spirit crusher due to an increased workload. Every once in a while I decide to run into the woods and get lost in something that I've never done. It's been a while since I've had the chance to develop something selfishly. Last year I wrote an intranet site using ruby on rails for what I call "personal enrichment." Rails went OK, but whenever I wanted to achieve something that wasn't textbook I found myself writing code that was like a trick/hack... needless to say it didn't give me a good feeling. About 6 months ago i started to force myself to use Python for all shell script tasks that were thrown my way. I love python. If you are used to scripting or actually enjoy scripting python is great. Now one of my pet peeves is when people say things like "lightweight, efficient, clean, easy to read." Now all of those things are great.. but what does it really mean? Visual Basic is almost like writing english and developers think its the fisher-price of languages (including me). I have no answer to why I like python except a few little things:
- whitespace is used to terminate directives, which forces everyone to use similar formatting
- smtplib is the best email library I've ever worked with
- django doesn't assume as much as rails does, you still have some tedious work but I find it the perfect balance.
So I built my first site in django it's currently running in my dev enviornment. What does the app do? It's an app that uses the power of expect (one of my favorites), diff (another favorite), and a repository model. Simply put, the app connects to a device (via ssh/telnet) logs in and issues a command, stores the output in a database, does a diff between the last retrieved output and does a diff, if there is a diff it emails the system owner. What does this achieve? Automatic change control and a configuration repository. I've used RANCID to do this before and I love the concept. RANCID doesn't have a front end, but it also uses cvs/svn so you can install cvs/svn frontends. I re-invented the wheel, but I like this wheel... it's dead simple... and it helps out those admins that suck at cli. Like I said, I haven't deployed it yet... but I think I may want to release it. So my next problem I'm thinking about is how to package up and release a distribution. I've never used/installed a django driven web app... how do people usually release their django projects to the public? VMs?
Two years ago I wrote a script that you could use to send commands to telnet/ssh enabled devices called tratto. Since then I have changed jobs and with new jobs comes new enviornments. I can no longer send commands like "show run" without sending the enable command (enable is like the 'su' of unix). I re-visited my code... which is always an entertaining. Anyway, I added an "escalateprivileges" command and added a string to the Systems object so you can store what the escalation command is for different operating systems.
You can download it here or via github
def escalateprivileges(self, escalated_password=None):
escalated_password = escalated_password
i = self.connection.expect(r"(?i)password[\s:]+")
i = self.connection.expect(self.operatingsystem.PROMPTLINE)
if("denied" in self.connection.before):
print "***Escalation FAILED***"
print "***Escalation Successful***"
raise SessionError("***Not Connected***")
PROMPTLINE = r'[-\w]+[>#]'
GET_CONFIG ='show running-config'
VERSION ='show version'
DISABLE_PAGINATION = 'terminal length 0'
#telnet to a cisco switch
m = Systems.OperatingSystems['IOS']
s = Connectivity.Session("10.10.1.1",23,"telnet",m)
Spur is a web based network configuration manager. It allows you to ssh or telnet to any device and run commands through a web front-end.The results of these commands are stored and can be diff'd. You can get alerted whenever a diff is found. You can extend Spur's capabilities by writing your own modules for different types of equipment.
Spur is comprised of:
- Tratto - a ssh/telenet framework built on-top of pexpect
- A custom written "cron" which allows you to create and schedule repetitive tasks
- Customized django skin
- Cisco syntax highlighting via syntax-highlighter
This project is in beta, I need people to help test. I have not used spur to configure any network equipment as of right now.
- Django 1.4+
- Sqlite, mysql, posgres
which python # find out if you have python installed
tar xzvf Django-1.4.1.tar.gz
sudo python setup.py install
sudo apt-get install sqlite
sudo easy_install django-mptt
sudo easy_install pexpect
sudo easy_install croniter
sudo easy_install pytz
git clone https://github.com/akonkol/spur.git
#edit this file to match your enviornment
#create an admin user
python manage.py syncdb
python manage.py runserver 0.0.0.0:8000
#Create a cronjob for spur
* * * * * /path/to/spur/manage.py spur-cron
Browse to spur http://your_fqdn_or_ip:8000
Thanks for checking it out.