Splunk:查找没有记录为不同日志行的特定属性的事件

Splunk: Find events that don't have a certain attribute logged as different log lines

我们的 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

我想找到没有其他 2 个状态的所有 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

我正在考虑的查询应该 return 没有 state=secondstate=third 的 id 列表,在上面的示例中应该 return id=2

这是一个 运行-anywhere 示例查询,应该这样做。查询中的注释解释了它的作用。它假设任何 id 的第一个状态总是“first”。

| 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
stats values(state) as all_states dc(state) as state_count by id
| search all_states="first" AND state_count=1
| table id