我能够在splunk仪表板中获取多个事件(api的日志(,如下所示
事件-1:
{ "corrId":"12345", "traceId":"srh-1", "apiName":"api1" }
事件-2:
{ "corrId":"69863", "traceId":"srh-2", "apiName":"api2" }
事件-3:
{ "corrId":"12345", "traceId":"srh-3", "apiName":"api3" }
我想通过提供apiName从一个事件(api日志(中动态检索corrId
(例如:-"corrId":"12345"(,并基于检索到的corrId
值构建splink搜索查询,这意味着它将提取包含相同corrId
("corrId":"12345"
(的所有事件日志。
输出
在上述情况下,预期结果将低于
事件-1:
{ "corrId":"12345", "traceId":"srh-1", "apiName":"api1" }
事件-3:
{ "corrId":"12345", "traceId":"srh-3", "apiName":"api3" }
我是splunk的新手,请在这里帮助我,如何通过提供apiName
等其他字段来动态获取"corrId":"12345"
,并在此基础上构建splunk搜索查询。
我已经试过了,但没有成功。
index = "test_srh source=policy.log [ search index = "test_srh source=policy.log | rex field=_raw "apiName":|s+"(?[^"]+)" | search name="api1" | table corrId]
此查询只提供事件1日志,但我们需要包含相同corrId
("corrId":"12345"
(的所有其他事件。感谢您的快速帮助。
如果您显式提取apiName
字段,我假设corrId
字段也不会自动提取。这意味着将corrId="12345"
放在基本查询中是行不通的。请尝试index=test_srh source=policy.log corrId="12345"
进行验证。
如果corrId字段需要提取,请尝试此查询。
index=test_srh source=policy.log
| rex "corrId\":\"(?<corrId>[^\"]+)"
| where [ search index = "test_srh source=policy.log
| rex "apiName":"(?<name>[^"]+)"
| search name="api1"
| rex "corrId\":\"(?<corrId>[^\"]+)"
| fields corrId | format ]
注意:我还更正了regex以正确提取apiName字段。