通過日誌關鍵字檢測判斷obb程序是否工作正常
阿新 • • 發佈:2017-06-13
smo pty count echo sleep err pri and lis
C118+Osmocom-bb 多機 gsm sniff環境,經常發生工作一段時間後,某個手機監聽的arfcn就不工作了。
檢查日誌發現,日誌最後有連續的多條:TOA AVG is not 16 qbits, correcting (got 15),然後日誌就一動不動了,無法再繼續抓取sms,只能重啟obb程序。
不清楚這是obb的程序bug,還是基站每天不定時調整( 某些arfcn,並不是一天24小時都工作的,有時會斷那麽一小會兒 )導致的。
重啟obb程序的過程不算復雜,無非是先刷機(我沒試過硬刷),再監聽。
可以在smsweb裏專門寫一個方法,結合Python+shell命令定期(30秒)去檢測日誌(使用tail和diff命令),當判斷obb工作不正常時,重新刷機(全自動刷機硬件改造方法參考置頂文章),起動監聽程序。
參考代碼如下:
def monitor_log(): mysql = Database() while True: print("monitor log:") getusb = subprocess.Popen(["./osmocom-bb/getusb.sh"],stderr=subprocess.PIPE,stdout=subprocess.PIPE) usbResult = getusb.communicate() getusb.wait() device= re.findall(r‘\d‘,usbResult[0])[0] #find arfcn str_sql = "SELECT * FROM sniff limit 0," + str(device) data = mysql.query(str_sql) for row in data: arf = str(row[‘arfcn‘]) power = str(row[‘power‘]) sptype= str(row[‘sptype‘]) tty = str(row[‘tty‘]) counter = 0 command = ‘tail -n3 ./download_‘+ tty +‘.log‘ textlist = os.popen(command).readlines() for line in textlist: if "AVG" in line: print("find got 15 in log! dangerous!") counter = counter + 1 #logger.info("AVG counter:" + str(counter) + " " + str(tty) + " arfcn:" + str(arf) ) if int(counter) == 3: print("found 3 got 15! restart osmocon and sniff!") #cur_time = time.strftime(‘%Y/%m/%d %H:%M:%S‘,time.localtime(time.time())) logger.info("got 15 mon:" + str(tty) + " arfcn:" + str(arf) ) ps1=Process(target=download1,args=(str(tty),)) ps1.start() ps1.join(10) #time.sleep(10) ps2=Process(target=sniff,args=(str(tty),str(arf),)) ps2.start() ps2.join(30) #time.sleep(30) #subprocess.Popen("./osmocom-bb/test.sh",shell = True) # 檢測文件是否有變動 cur_log = "download_" + tty + ".log" old_log = cur_log + ".old" getdiff = subprocess.Popen(["./diff.sh",cur_log,old_log],stderr=subprocess.PIPE,stdout=subprocess.PIPE) diffResult = getdiff.communicate() getdiff.wait() diff_ret = re.findall(r‘\d‘,diffResult[0])[0] #logger.info("logchange mon:" + str(tty) + " arfcn:" + str(arf) + " diff_ret:" + str(diff_ret)) if int(diff_ret) == 0: # print("log not change in 30secs! restart osmocon and sniff!") # #cur_time = time.strftime(‘%Y/%m/%d %H:%M:%S‘,time.localtime(time.time())) logger.info("log diff:" + str(tty) + " arfcn:" + str(arf) ) ps1=Process(target=download1,args=(str(tty),)) ps1.start() ps1.join(10) #time.sleep(10) ps2=Process(target=sniff,args=(str(tty),str(arf),)) ps2.start() ps2.join(30) #time.sleep(30) #subprocess.Popen("./osmocom-bb/test.sh",shell = True) time.sleep(30)
diff.sh:
#!/bin/bash #diff ./download_0.log ./download_0.log.old diff $1 $2 >> diff_$1 #echo $? if [ $? = 0 ];then #echo "沒區別" echo "0" else #echo "文件有變動" rm -fr $2 cp $1 $2 #echo "文件同步成功" echo "1" fi
說明:
1. 當日誌裏連續三行的日誌都出現AVG關鍵字時,就認為obb工作不正常了,果斷重新刷機監聽。
2.當日誌過了30秒後內容還和30秒前一樣時,也是不正常的,重新刷機監聽。
通過日誌關鍵字檢測判斷obb程序是否工作正常