# -*- coding: gb2312 -*- #author: donghuali #email : donghuali@baidu.com #date : 2009-11-09 from noahauto.framework.ulibLog import * from noahauto.framework.noah import * from noahauto.util.espParser import * from noahauto.util.op_mysql import * from noahauto.framework.proxy import * from noahauto.util.system import * from noahauto.util.logParser import * from noahauto.framework.stub.hera import * from noahauto.framework.stub.web import * import time import unittest class testAlarm(unittest.TestCase): def test_smon_req(self): """ 223412,,, """ match=LogParser('/tmp/espproxy.out.0') #self.alarmdb=op_mysql(host="db-testing-ps2022.db01",db="noah",user="root",passwd="") #self.alarmdb.executes("delete from moni_rule_receiver where id=6666"); #self.alarmdb.executes("(6666, 375, 1, 11671, 0, 'donghuali@baidu.com',0,'2009-11-29 18:17:43');") espproxy().run("espsender.tcl /w 1000 /l 1 /listen 0.0.0.0:2005:1 /t 0.0.0.0:18033:2 /rep stub/smon/smon_req_S2A.tcl"); time.sleep(6) #self.alarmdb.executes("delete from moni_rule_receiver where id=6666;") match.read() result=match.is_text_present('')#alarm ?????? self.failIf(result==True,"send msg error to alarm ") def test_gsm_notcon_smon_req(self): """ 223411 """ match=LogParser('/tmp/espproxy.out.0') match.read() system.run('killall -9 gsm') self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01",db="noah",user="root",passwd="") self.alarmdb.executes("delete from moni_rule_receiver where id=6666"); self.alarmdb.executes("INSERT INTO `moni_rule_receiver` VALUE(6666, 375, 1, 11671, 0, 'donghuali@baidu.com',0,'2009-11-29 11:11:11');") espproxy().run("./espsender.tcl /listen 0.0.0.0:2005:1 /t 0.0.0.0:18033:2 /l 1 /rep stub/smon/smon_req_S2A.tcl 1>null 2>null"); self.alarmdb.executes("delete from moni_rule_receiver where id=6666;") match.read() result=match.is_text_present('12 bytes') self.failIf(result==True,"send msg error to alarm") def test_log_exist_fatal(self): """ 114019 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() espproxy().run("./espsender.tcl /listen 0.0.0.0:2005:1 /t 0.0.0.0:18033:2 /l 1 /rep stub/alarm/smon2alarm.tcl 1>null 2>null") match.read() result=match.is_text_present("FATAL") self.failIf(result==True,"send msg error to alarm by case 114019") def test_mail_one_person(self): """ 223375,,, """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_mail values(356,'donghuali@baidu.com','~!@#$','this is a alarm mail');") match.read() result=match.is_text_present('receiver: donghuali@baidu.com') self.failIf(result==True,"send msg error to alarm by case 223375") def test_phone_person(self): """ 223285 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_phone values(6666,'15110035806',1,'phone alarm',1252403896,598,375,'db-testing-ps2022');") time.sleep(6) match.read() self.alarmdb.execute("delete form alarm_info_phone where id=6666;") result=match.is_text_present('15110035806') self.failIf(result==False,"send msg error to alarm by case 223285") def test_phone_content_null(self): """ 223288 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_phone values(6666,'15110035806',1,'',598,375,'db-testing-ps2022');") time.sleep(6) match.read() self.alarmdb.execute("delete from alarm_info_phone where id=6666;") result=match.is_text_present('15110035806') self.failIf(result==False,"send msg error to alarm by case 223288") def test_phone_content_special(self): """ 223287 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_phone values(6666,'15110035806',1,'!@#',1252403896,598,375,'db-testing-ps2022');") time.sleep(6) match.read() self.alarmdb.execute("delete from alarm_info_phone where id=6666;") result=match.is_text_present("15110035806") self.failIf(result==False,"send msg error to alarm by case 223278") def test_phone_content_try_another(self): """ 223363 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() time.sleep(6) match.read() result1=match.is_text_present("connect to gsm server: 127.0.0.1:15008 failed") result2=match.is_text_present("connect to gsm server: 127.0.0.1:15001 failed") self.failIf(result1==False,"send msg to alarm error by case 223363") self.failIf(result2==False,"send msg to alarm error by case 223363") def test_mail_content_special(self): """ 223378 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_mail values(333,'donghuali@baidu.com','~!@#$','this is a alarm mail');") time.sleep(5) match.read() result=match.is_text_present("send mail success") self.failIf(result==True,"send msg to alarm error by case 223378") def test_mail_success_delete(self): """ 223392 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_mail values(1,'donghuali@baidu.com','~!@#$','this is a alarm mail');") time.sleep(5) match.read() result=match.is_text_present("delete id") self.failIf(result==False,"send msg to alarm error by case 223392") def test_mail_content_exception(self): """ 223401 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("insert into alarm_info_mail values(1,'donghuali@baidu.com','','this is a alarm mail');") time.sleep(5) match.read() result=match.is_text_present("") self.failIf(result==False,"send msg to alarm error by case 223401") def test_start_alarm(self): """ 223281 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() system.run("killall -9 supervise.alarm alarm") system.run("/home/work/noah/monitor/alarm/bin/alarm_control start") match.read() result=match.is_text_present("heart_beat_send_thread start") self.failIf(result==False,"send msg to alarm error by case 223281") def test_mail_abled(self): """ 223282 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() system.run("killall -9 supervise.alarm alarm") system.run("/home/work/noah/monitor/alarm/bin/alarm_control start") match.read() result=match.is_text_present("send_mail_thread start") self.failIf(result==False,"send msg to alarm error by case 223282") def test_gsmmsg_abled(self): """ 223283 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() system.run("killall -9 supervise.alarm alarm") system.run("/home/work/noah/monitor/alarm/bin/alarm_control start") match.read() result=match.is_text_present("send_gsmmsg_thread start") self.failIf(result==False,"send msg to alarm error by case 223283") def test_gsm_too_long(self): """ 223317 """ match=LogParser('/home/work/noah/monitor/alarm/log/alarm.log') match.read() self.alarmdb=op_mysql(host="db-testing-ps2001-vm1.db01.baidu.com",db="noah",user="root",passwd="") self.alarmdb.execute("delete from alarm_info_phone where id=6666;") self.alarmdb.execute("insert into alarm_info_phone values(6666,'15110035806',1,'phone alarm12123434eretrggredfdfsdfsdfdsfdsfdsfdethythytjuyjukikinhnsdewrewsddazxcdfrttyyuyggffdsfewr4',1252403896,598,375,'db-testing-ps2022');") time.sleep(6) match.read() self.alarmdb.execute("delete form alarm_info_phone where id=6666;") result=match.is_text_present('15110035806') self.failIf(result==False,"send msg error to alarm by case 223317") def suite(): tests=['test_mail_one_person'] return unittest.TestSuite(map(testAlarm,tests)) if __name__ == "__main__": mysuite = unittest.TestLoader().loadTestsFromTestCase(testAlarm) mysuite=[] if mysuite == [] : mysuite=suite() unittest.TextTestRunner(verbosity=2).run(suite()) #unittest.TextTestRunner(verbosity=2).run(mysuite) unittest.main(module='testAlarm')