I have not been doing to many interesting projects as of the past year. This is the reason for my lack of updates. I am now starting to do some interesting stuff, so let the updates roll.
For those of you who visit linuxdynasty everyday, you might have notice some subtle changes in the authorization aspect fo the site. I had to enable captch images in the login, and posting parts of the site. Since for the past few weeks, spammers have been hitting the comments and forums section. I’m hoping this does not annoy everyone, but the spamming is starting to really annoy me.
Today I was given a task to have my manager emailed once a day. If any of our Data Stores in ESX 3.5 are over 80% utilized. So I said to my self. What would be the easiest way to do this???? Well I’ve written two scripts in the past, that could help me accomplish that. The first script VMstoragePool.py will list all of the Data Stores in Vmware and its utilization. The 2nd script is check_datastore.py, and this script will return OK, WARNING, or CRITICAL, depending on the thresholds you set. So by effectively combining the 2 scripts I was able to get what I want. Example below…
python VMstoragePool.py -u "https://esxhostA" -a "login passwd" |grep "DataStore Name" |awk {'print $3'} |for line in `xargs`;do python check_datastore.py -u "https://esxhostA" -a "login passwd" -d $line -w 80 -c 90 -m "GB"|grep -P "WARNING|CRITICAL";done|mail user@domain.com
CRITICAL XythosVol2 57GB Avail 94% used |avail=57
WARNING XythosVol1 62GB Avail 87% used |avail=62
WARNING LinuxVol1 57GB Avail 88% used |avail=57
WARNING WinVol1 75GB Avail 84% used |avail=75
WARNING BBSCVOL1 122GB Avail 88% used |avail=122
CRITICAL NSSharedVOL1 46GB Avail 95% used |avail=46
So I can run this script in cron once a day and pipe the output to email him directly. Simple yet effective! On a side note, I fixed both chec_datastore.py and VMstoragePool.py to effectivly parse passwd’s that used characters like !@#$%^.
Both scripts can be downlaoded here..
check_datastore.py == Download
VMstoragePool.py == Download
The current issue is that we have over 400 Cisco Network devices, and they are not all in the Cisco LMS ( Lan Management Solution ). We also have Solarwind, but we do not have all of our Networking devices in there either. There is only one way I know of doing that with out using multiple tools like Cisco LMS or Func. So I figured, I should go ahead and write a Python tool that can update all of our devices ( Cisco, Nortel, Foundry, Linux, BSD, you get the idea.. ).
I wrote a Python tool that utilizes pexpect. The tools is almost complete to release on my site, but I still need to add more functionality. Currently, you can pass a device list and a command list to the script. You can also tell the tool to be verbose and print the output. Also you can tell it to use ssh or telnet or both. The tool is smart enogh to use ssh keys or log into a device you never have logged into before, by accepting the key for you.
I’m currently modifying it so that you can just pass one device and not just a list of devices. Also working on a password changer function. I’ve tested my tool on Linux Servers as well as Cisco devices and so far it works like a charm. I’m thinking about adding threading, but I have not yet decided to do so..
#!/usr/bin/env python# Quick Python script to generate random valid MAC address for XEN Domains#Copyright (C) 2008 Allen Sanabria #This program is free software; you can redistribute it and/or modify#it under the terms of the GNU General Public License as published by#the Free Software Foundation; either version 2 of the License, or#(at your option) any later version. #This program is distributed in the hope that it will be useful,#but WITHOUT ANY WARRANTY; without even the implied warranty of#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the#GNU General Public License for more details. #You should have received a copy of the GNU General Public License along#with this program; if not, write to the Free Software Foundation, Inc.,#51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.# This address range is reserved for use by Xen 00:16:3E# I'm importing the function choice of the random module# The reason for this is so that it will pick a random character from the string I gave it to generate a valid MAC for XEN
from random import choice
from sys import stdin
def x():
X = choice("0123456789ABCDEF")
return str(X)
print "Enter how many MAC Addresses do you want me to generate: "
mac = stdin.readline()
mac_list = []
for i in range(int(mac)):
mac_list.append("00:16:3E"+":"+x()+x()+":"+x()+x()+":"+x()+x())
for con in range(len(mac_list)):
while mac_list.count(mac_list[con]) > 1:
print "OH NOOO DUPPPE "+mac_list[con]
mac_list.pop(con)
mac_list.insert(con, "00:16:3E"+":"+x()+x()+":"+x()+x()+":"+x()+x())
print mac_list[con]
OUTPUT