美文网首页
Drain3作日志模板解析

Drain3作日志模板解析

作者: 万州客 | 来源:发表于2022-05-23 10:18 被阅读0次

    这是IBM基于原生的drain进行的升级,测试一下,很简单的提取日志模板

    代码

    from drain3.drain import Drain, LogCluster
    
    model = Drain()
    entries = str.splitlines(
        """
        Dec 10 07:07:38 LabSZ sshd[24206]: input_userauth_request: invalid user test9 [preauth]
        Dec 10 07:08:28 LabSZ sshd[24208]: input_userauth_request: invalid user webmaster [preauth]
        Dec 10 09:12:32 LabSZ sshd[24490]: Failed password for invalid user ftpuser from 0.0.0.0 port 62891 ssh2
        Dec 10 09:12:35 LabSZ sshd[24492]: Failed password for invalid user pi from 0.0.0.0 port 49289 ssh2
        Dec 10 09:12:44 LabSZ sshd[24501]: Failed password for invalid user ftpuser from 0.0.0.0 port 60836 ssh2
        Dec 10 07:28:03 LabSZ sshd[24245]: input_userauth_request: invalid user pgadmin [preauth]
        """
    )
    
    for entry in entries:
        cluster, change_type = model.add_log_message(entry)
        print(cluster.get_template())
    
    
    

    输出

    C:\Users\ccc\AppData\Local\Programs\Python\Python38\python.exe D:/Code/Metis-Org/app/service/time_series_detector/feature/drain_test.py
    
    Dec 10 07:07:38 LabSZ sshd[24206]: input_userauth_request: invalid user test9 [preauth]
    Dec 10 <*> LabSZ <*> input_userauth_request: invalid user <*> [preauth]
    Dec 10 09:12:32 LabSZ sshd[24490]: Failed password for invalid user ftpuser from 0.0.0.0 port 62891 ssh2
    Dec 10 <*> LabSZ <*> Failed password for invalid user <*> from 0.0.0.0 port <*> ssh2
    Dec 10 <*> LabSZ <*> Failed password for invalid user <*> from 0.0.0.0 port <*> ssh2
    Dec 10 <*> LabSZ <*> input_userauth_request: invalid user <*> [preauth]
    
    image.png

    相关文章

      网友评论

          本文标题:Drain3作日志模板解析

          本文链接:https://www.haomeiwen.com/subject/cgkrprtx.html