Open zking2000 opened 4 weeks ago
processors:
filter/parse:
logs:
# 使用 JQ 表达式解析 JSON 字符串并提取需要的字段
jq: |
.body as $raw |
try (
($raw | fromjson) as $parsed |
{
"attributes": {
"project_id": $parsed.resource.labels.project_id,
"log_name": $parsed.logName,
"severity": $parsed.severity
# 添加其他你需要作为索引的字段
},
"body": $parsed.textPayload # 或者 $parsed.jsonPayload
}
) catch $raw
processors:
filter:
logs:
strict: false
expr: |
# 尝试解析 JSON
body = parse_json(body)
# 设置属性作为索引
attributes["project_id"] = body.resource.labels.project_id
attributes["log_name"] = body.logName
attributes["severity"] = body.severity
# 设置日志内容
body = body.textPayload # 或者 body.jsonPayload