通过日志关键字检测判断obb程序是否工作正常

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秒前一样时,也是不正常的,重新刷机监听。

时间: 2024-08-07 16:22:52

通过日志关键字检测判断obb程序是否工作正常的相关文章

用go实现web日志分析及网页挂马关键字检测

本程序主要实现网页挂马关键字检测,原理是这样的,通过定时分析用户访问的IIS web日志,对日志的里的URL进行访问,然后检索是否包含相关的关键字,有就入库,这只是go实现自动检索及入库,可以加个前端,实现加关键及报警功能 package main import (     "bufio"     "code.google.com/p/mahonia"     "fmt"     "io"     "io/iouti

ubuntu 18.04 检测到系统程序出现问题

检测到系统程序出现问题,想立即报告这个问题吗? 可以暂时先把这个提示关闭掉 $ sudo vi /etc/default/apport 找到第4行 修改为 enabled=0 保存退出 附linux中各个日志文件 /var/log/alternatives.log-更新替代信息都记录在这个文件中 /var/log/apport.log -应用程序崩溃记录 /var/log/apt/ -用apt-get安装卸载软件的信息 /var/log/auth.log -登录认证log /var/log/bo

zabbix 监控日志关键字

1.客户端配置 [[email protected] zabbix_agentd.conf.d]# pwd /usr/local/zabbix-server/etc/zabbix_agentd.conf.d [[email protected] zabbix_agentd.conf.d]# cat custom_parameters.conf UserParameter=masterha_manager,[ `/bin/ps aux | /bin/grep -v grep | /bin/grep

delphi 如何判断应用程序未响应

http://www.cnblogs.com/smallmuda/archive/2009/07/24/1529845.html delphi 如何判断应用程序未响应 今天在MSN的核心讨论组上看到两篇文章.讨论的乃是应用程序是否没有响应.原文如下:           >   How   is   it   possible   to   determine   a   process   is   "not   responding"   like   NT   Task  

如何用js检测判断时间日期的间距

<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>如何用js检测判断日期大于多少天</title> <script> window.onload=function(){ var ul1=document.getElementById("time"); var span1=ul1.getElementsByTag

第二周:If判断语句程序当中的作用简介

1.If语句的作用: 在我们编写程序时经常会遇到内容判断的问题,比如判断内容的真假或者值的大小分别输出内容的问题 这时就会用到我们的If判断语句了,顾名思义,if在英文单词中意思为如果,在Java中他的体现形式和意思 也是代表如果的意思,经常用于判断语句的内容或者用户输入不同的内容判断其输出的结果.If也有固定 的格式. 2.If表达式: if (判断语句) {     执行语句: } 例如: if (S>=90){ System.out.print("优秀"); }else i

C#:判断当前程序是否通过管理员运行

原文:C#:判断当前程序是否通过管理员运行 public bool IsAdministrator() { WindowsIdentity current = WindowsIdentity.GetCurrent(); WindowsPrincipal windowsPrincipal = new WindowsPrincipal(current); return windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator); } 转载声

C#判断某程序是否运行的方法

本文实例讲述了C#判断某程序是否运行的方法,分享给大家供大家参考. 具体实现方法如下: [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); [DllImp

检测你处于程序员的哪个层级

检测你处于程序员的哪个层级 2018-02-15 陈皓 程序员干货站 高中时期 view plaincopy to clipboardprint? 10 PRINT "HELLO WORLD" 20 END 大学新生 view plaincopy to clipboardprint? program Hello(input, output) begin writeln(\'Hello World\') end. 高年级大学生 view plaincopy to clipboardpri