资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

获取一周内的告警日志(python|Oracle)

# -*- coding:UTF-8 -*-
#author: Rui Zhang
#date: 2017-08-09
#email: sharpzhang_2008@126.com  
import datetime


def time_check():
    yesterday=datetime.datetime.now() - datetime.timedelta(days=1)
    #yesterday_wk=yesterday.strftime('%a')
    #yesterday_mh=yesterday.strftime('%b')
    #yesterday_dy=yesterday.strftime('%d')
    yesterday_wmd=yesterday.strftime('%a %b %d')
    today=datetime.datetime.now()
    #today_wk=today.strftime('%a')
    #today_mh=today.strftime('%b')
    #today_dy=today.strftime('%d')
    today_wmd=today.strftime('%a %b %d')
    #argv1=yesterday_wmd
    #argv2=today_wmd
    return yesterday_wmd,today_wmd








def chk_db_log(time1,time2):
    count_1=0
    count_2=0
    #with open("D:/alert_test1.log") as f:
    f = open('D:/alert_test1.log','r')
    a = f.readlines()
    for line in a:
        count_1=count_1+1
        if time1 in line:
            #print time
            #print(count)
            break
        elif time2 in line:
            break
    for line in a:
        count_2=count_2+1
        if count_1<=count_2:
            print(line.strip())
            #else:
            #print(line.strip())
    f.close()




def main():
    yday,tday=time_check()
    #yday=time_check(argv1)
    #tday=time_check(argv2)
    #print yday,tday
    #print yday
    #print tday
    print "------当前时间截止到昨天全天的所有数据库告警日志--------"
    print "        当前获取日志时间:"+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S');
    print "------当前时间截止到昨天全天的所有数据库告警日志--------"
    chk_db_log(yday,tday)




if __name__ == "__main__":
    main()


当前文章:获取一周内的告警日志(python|Oracle)
标题网址:http://www.cdkjz.cn/article/pshjcp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220