【开源】Zeek编程之:日志添加自定义字段

本文详细介绍了如何在Bro脚本中扩展日志字段,通过添加自定义字段如human_readabletime,实现更人性化的日志时间显示。教程覆盖了从源代码修改到最终应用的全过程,适合Bro日志系统的高级定制。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载,可参照文中叙述方法对日志字段扩展添加自己想要的内容,比如本采集器IP等

添加自定字段,如human_readable time字段:

FILE $bro/share/bro/base/protocols/http/human_time_http.bro


@load base/protocols/http

module HTTP;

export {

redef record Info += {

  ## A human-readable timestamp

  human_time: string &log &optional;

  };

}

event http_request(c: connection, method: string, original_URI: string,

                    unescaped_URI: string, version: string)

{

  local format: string = "%Y-%m-%dT%H:%M:%S%z";

  c$http$human_time = strftime(format, c$http$ts);

}

之后修改load文件$bro/share/bro/base/protocols/http/load.bro,添加一行


@load ./human_time_http

最后在$bro/share/bro/base/protocols/http/main.bro中添加新建的字段


type Info: record {       

 ## Timestamp for when the request happened.

        human_time: string &log;

        ...

        ...

另:bro script中字段含义https://www.bro.org/sphinx/script-reference/attributes.html#attr-&log



作者:phaker
链接:https://www.jianshu.com/p/0657fb041393
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值