[英]Splunk: Return One or True from a search, use that result in another search
[英]SPLUNK use result from first search in second search
假設我有一個查詢,例如
index="example" source="example.log" host="example" "ERROR 1234"
| stats distinct_count by id
這將為我提供每個 ID 帶有該錯誤代碼的所有事件。
然后我想結合這個查詢來搜索同一個日志文件中的另一個字符串,但僅限於第一次搜索返回的唯一 ID。 因為新字符串將出現在一個單獨的事件中,所以我不能只做一個“與”。
有幾種方法可以做到這一點,包括使用子搜索、 join
或append
,但這些方法需要多次遍歷數據。 這是一種通過索引進行單次傳遞的方法。
index=example source="example.log" ("ERROR 1234" OR "ERROR 5678")
``` Check for the presence of each string in the event ```
| eval string1=if(searchmatch("ERROR 1234"), 1, 0)
| eval string2=if(searchmatch("ERROR 5678"), 1, 0)
``` Count string occurrences by id ```
| stats sum(string1) as string1, sum(string2) as string2 by id
``` Keep only the ids that have both strings ```
| where (string1 > 0 AND string2 > 0)
假設您的id
字段相同並且在兩個索引中都可用,則此表單應該有效:
(index=ndxA sourcetype=srctpA id=* source=example.log host=example "ERROR 1234") OR (index=ndxB sourcetype=srctpB id=* "some other string")
| rex field=_raw "(?<first_field>ERROR 1234)"
| rex field=_raw "(?<second_field>some other string)"
| fillnull value="-" first_field second_field
| stats count by id first_string second_string
| search NOT (first_string="-" OR second_string="-")
如果您的id
字段在其他索引中有不同的名稱,請在stats
行之前像這樣rename
:
| rename otherIdFieldName as id
這種格式的優點:
stats
)過濾以確保first_string和first_string
second_string
具有您要查找的值)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.