1

我们有 Splunk 日志,例如:

ts=20:10:01 id=1 state=first foo=bar
ts=20:10:05 id=1 state=second foo=bar
ts=20:10:06 id=1 state=third foo=bar

ts=20:10:03 id=2 state=first foo=bar

ts=20:11:01 id=3 state=first foo=bar
ts=20:11:03 id=3 state=second foo=bar
ts=20:11:05 id=3 state=third foo=bar

我想找到所有id没有其他两个状态的东西。在这个例子中,所有id=2记录的第一个状态,但没有记录其他 2。我正在阅读 JOIN 并发现它只能查看两个事件发生的事件,但我们不能排除这些事件。

index=my-idx foo=bar 
| join id type=outer
  [search index=my-idx foo=bar NOT (state=second OR state=third) | table id]
| table id

我正在考虑的 Query 应该返回一个不具有state=secondorstate=third在上面的示例中应该返回的 id 列表id=2

4

2 回答 2

1

这是应该执行此操作的随处运行示例查询。查询中的注释解释了它的作用。它假定任何 id 的第一个状态总是“第一”。

| makeresults 
| eval data="ts=20:10:01 id=1 state=first foo=bar;
ts=20:10:05 id=1 state=second foo=bar;
ts=20:10:06 id=1 state=third foo=bar;
ts=20:10:03 id=2 state=first foo=bar;
ts=20:11:01 id=3 state=first foo=bar;
ts=20:11:03 id=3 state=second foo=bar;
ts=20:11:05 id=3 state=third foo=bar"
| eval data=split(data,";")
| mvexpand data
| eval _raw=data
| extract kvdelim=" ", pairdelim="="
| fields ts,id,state,foo
```Above just sets up test data```
```Count how many different states each id has```
| streamstats dc(state) as count by id
```Find the highest count for each id```
| eventstats max(count) as max by id
```Select only those with a single state```
| where max=1
| table ts id state foo
于 2021-01-27T01:47:24.787 回答
1
stats values(state) as all_states dc(state) as state_count by id
| search all_states="first" AND state_count=1
| table id
于 2021-01-27T02:44:30.423 回答