Created
May 2, 2011 02:32
-
-
Save wataru420/951120 to your computer and use it in GitHub Desktop.
monの設定の動作確認をするスクリプト
This file contains 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
#!/usr/bin/python | |
# coding: UTF-8 | |
import sys | |
import re | |
import commands | |
#Hostgroupの全IPに対して正常に動いているかチェック | |
def checkHostgroup(line,commandlist): | |
data = line.split() | |
groupname = data[1] | |
del data[1] | |
del data[0] | |
success = [0] | |
success[0] = True | |
for ip in data: | |
mondir = '/usr/local/mon/mon.d/' | |
command = '%(mondir)s%(command)s %(ip)s ; echo $?' % {'ip':ip,'mondir':mondir,'command':commandlist[groupname]} | |
res = commands.getstatusoutput(command) | |
out = res[1] | |
if (out[-1:] != '0'): | |
success[0] = False | |
print command | |
print out | |
#print command | |
if (success[0] != False): | |
print '%s All success' % groupname | |
#チェックするコマンドのリストを生成 | |
def getCommands(f): | |
commands = {} | |
lines = f.readlines() | |
for n in range(len(lines)): | |
if (re.search("^watch",lines[n])): | |
data1 = lines[n].split() | |
data2 = lines[n+3].split(' monitor ') | |
commands[data1[1]] = data2[1].strip() | |
return commands | |
#チェックする対象のファイルを開き、チェックを実行 | |
def readFile(path): | |
f = open(path) | |
commandlist = getCommands(f) | |
f = open(path) | |
line = f.readline() | |
while line: | |
if (re.search("^hostgroup",line)): | |
checkHostgroup(line,commandlist) | |
line = f.readline() | |
f.close | |
def main(): | |
argvs = sys.argv | |
if (len(argvs) != 2): | |
print 'Usage: # python $s filename' % argvs[0] | |
sys.exit() | |
print 'Check %s \'s mon status' % argvs[1] | |
readFile(argvs[1]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment