Exemplo n.º 1
0
def monitoring(f_items, s_items):
    print(s_items.keys())
    b_line = int(s_items['beforeline'])
    a_line = int(s_items['afterline'])
    search_word = s_items['searchword']

    logData = getFileToBuffer(f_items['filepath'])
    index = logData.find(search_word)
    isFind = True
    if index == -1:
        isFind = False
        index = len(logData)
    else:
        isFind = True

    while True:
        if isFind:
            while True:
                alert()
                result = mylog.get_log_data(logData, index, b_line, a_line)
                print('{}'.format(result))
                (index, isFind) = searching(search_word, index, logData)
                if isFind == False: break

        time.sleep(10)
        logData = getFileToBuffer(f_items['filepath'])
        (index, isFind) = searching(search_word, index, logData)
Exemplo n.º 2
0
def check(file_name, search_word) :
    if os.path.exists(file_name):
        print "모니터링 시작 :", file_name
        print "대상 : ", search_word
        print "-" * 70
    else :
        print "찾으려는 파일이 없습니다 :", file_name
        
    index = 0
    while os.path.exists(file_name) :
        fp = open(file_name)
        file_data =fp.read()
        index = file_data.find(search_word, index)
        fp.close() 
        
        if index >= 0 :
            alert(search_word)    # 코드 수정
            (data, count) = get_log_data(file_data, search_word, index, 2, 2)
            print data
        else :
            sys.stdout.write("...")
            sys.stdout.flush()

        index = len(file_data)
        sleep(5)
Exemplo n.º 3
0
def check(file_name, search_word):
    if os.path.exists(file_name):
        print "모니터링 시작 :", file_name
        print "대상 : ", search_word
        print "-" * 70
    else:
        print "찾으려는 파일이 없습니다 :", file_name

    index = 0
    while os.path.exists(file_name):
        # 파일에 찾을 단어('FATAL')가 있는지 확인
        fp = open(file_name)
        file_data = fp.read()
        index = file_data.find(search_word, index)
        fp.close()

        # 찾았다면 alert 함수로 메시지를 출력하고, 관련 로그의 앞으로 1줄, 뒤로 2줄을 출력
        # 찾지 못했다면 ...을 출력
        if index >= 0:
            alert()
            (data, count) = get_log_data(file_data, search_word, index, 2, 2)
            print data
        else:
            sys.stdout.write("...")
            sys.stdout.flush()

        index = len(file_data)
        sleep(5)  # 5초 동안 쉬기
Exemplo n.º 4
0
def check(file_name, search_word, out_file_name):
    if os.path.exists(file_name):
        print(f"모니터링 시작 : {file_name}")
        print(f"대상 : {search_word}")
        print("-" * 70)
    else:
        print(f"찾으려는 파일이 없습니다 : {file_name}")
        sys.exit(1)

    index = 0
    while os.path.exists(file_name):
        fp = open(file_name)
        file_data = fp.read()
        index = file_data.find(search_word, index)
        fp.close()

        if index >= 0:
            alert(search_word)
            data, _ = get_log_data(file_data, search_word, index, 2, 2)

            out_file = open(out_file_name, "a")
            out_file.write("\n" + ("*" * 70))
            out_file.write(
                f"\n문제({search_word})가 모니터링 된 시각 : {datetime.datetime.now()}")
            out_file.write("\n" + ("*" * 70))
            out_file.write(data)
            out_file.close()
            print(f"로그가 기록된 파일을 확인하세요: {out_file_name}")
        else:
            print("...", end="", flush=True)

        index = len(file_data)
        sleep(5)
Exemplo n.º 5
0
def check(file_name, search_word, out_file_name):
    if os.path.exists(file_name):
        print "모니터링 시작 :", file_name
        print "대상 : ", search_word
        print "-" * 70
    else:
        print "찾으려는 파일이 없습니다 :", file_name

    index = 0
    while os.path.exists(file_name):
        fp = open(file_name)
        file_data = fp.read()
        index = file_data.find(search_word, index)
        fp.close()

        if index >= 0:
            alert(search_word)
            (data, count) = get_log_data(file_data, search_word, index, 2, 2)

            # 코드 수정 시작
            out_file = open(out_file_name, "a")
            out_file.write("\n" + ("*" * 70))
            out_file.write("\n문제(" + search_word + ")가 모니터링된 시각 : ")
            out_file.write(str(datetime.datetime.now()))
            out_file.write("\n" + ("-" * 70) + "\n")
            out_file.write(data)
            print "로그가 기록된 파일을 확인하세요 :", out_file_name
            out_file.close()
            # 코드 수정 완료
        else:
            sys.stdout.write("...")
            sys.stdout.flush()

        index = len(file_data)
        sleep(5)