eventlogmessage
注意
Promtail 已被弃用,并将通过 2026 年 2 月 28 日获得长期支持 (LTS)。Promtail 将于 2026 年 3 月 2 日达到生命周期结束 (EOL)。您可以在此处找到迁移资源。
eventlogmessage
阶段是一个解析阶段,用于从 Windows 事件日志中出现的 Message 字符串中提取数据。
模式
eventlogmessage:
# Name from extracted data to parse, defaulting to the name
# used by the windows_events scraper
[source: <string> | default = message]
# If previously extracted data exists for a key that occurs
# in the Message, when true, the previous value will be
# overwriten by the value in the Message. Otherwise,
# '_extracted' will be appended to the key that is used for
# the value in the Message.
[overwrite_existing: <bool> | default = false]
# When true, keys extracted from the Message that are not
# valid labels will be dropped, otherwise they will be
# automatically converted into valid labels replacing invalid
# characters with underscores
[drop_invalid_labels: <bool> | default = false]
提取的数据可能包含非字符串值,此阶段不执行任何类型转换;下游阶段需要根据需要对这些值进行正确的类型转换。请参阅 template
阶段了解如何执行此操作。
与 json 结合使用的示例
对于给定的流水线
- json:
expressions:
message:
Overwritten:
- eventlogmessage:
source: message
overwrite_existing: true
给定以下日志行
{"event_id": 1, "Overwritten": "old", "message": "Message type:\r\nOverwritten: new\r\nImage: C:\\Users\\User\\promtail.exe"}
第一个阶段将在提取的数据集中创建以下键值对
message
:Message type:\r\nOverwritten: new\r\nImage: C:\Users\User\promtail.exe
Overwritten
:old
第二个阶段将解析提取数据中 message
的值,并将以下键值对附加/覆盖到提取的数据集
Image
:C:\\Users\\User\\promtail.exe
Message_type
:(空字符串)Overwritten
:new