#!/usr/bin/python
import urllib, urllib2, sys, os, signal, pdb, time, datetime, httplib, commands
import json
def check():
count = 0
alarm = {}
server_list = ['server1', 'server2', 'server3', 'server4', 'server5',]
while 1:
all_right = True
for ser_name in server_list:
ser_path = '%s/%s' % (ser_name, ser_name)
if os.path.exists(ser_path):
cmd = 'ps -ef | grep %s | grep -v "grep" | wc -l' % ser_name
num = int(commands.getoutput(cmd))
if num == 0:
all_right = False
if ser_name not in alarm:
alarm[ser_name] = 1
else:
alarm[ser_name] += 1
try:
os.chdir(ser_name)
commands.getoutput("./%s -d > /dev/null 2>&1" % ser_name)
except:
pass
finally:
os.chdir('..')
if all_right:
if count:
sendAlarm("all servers ok! ")
count = 0
alarm = {}
if alarm:
if not count:
sendAlarm(alarm)
count += 1
if count % 10 == 0:
sendAlarm(alarm)
time.sleep(2)
import urllib, urllib2, sys, os, signal, pdb, time, datetime, httplib, commands
import json
def check():
count = 0
alarm = {}
server_list = ['server1', 'server2', 'server3', 'server4', 'server5',]
while 1:
all_right = True
for ser_name in server_list:
ser_path = '%s/%s' % (ser_name, ser_name)
if os.path.exists(ser_path):
cmd = 'ps -ef | grep %s | grep -v "grep" | wc -l' % ser_name
num = int(commands.getoutput(cmd))
if num == 0:
all_right = False
if ser_name not in alarm:
alarm[ser_name] = 1
else:
alarm[ser_name] += 1
try:
os.chdir(ser_name)
commands.getoutput("./%s -d > /dev/null 2>&1" % ser_name)
except:
pass
finally:
os.chdir('..')
if all_right:
if count:
sendAlarm("all servers ok! ")
count = 0
alarm = {}
if alarm:
if not count:
sendAlarm(alarm)
count += 1
if count % 10 == 0:
sendAlarm(alarm)
time.sleep(2)