Splunk Cloud Platform

Filter events

kirthika26
Explorer

Device_ID : 1 A.txt

2021-07-06 23:30:34.2379| Started!
2021-07-06 23:30:34.6808|3333|-0.051|0.051|0.008|0.016

Device_ID : 1 E.txt

2021-07-13 18:28:26.7769|**
2021-07-13 18:28:27.1363|aa

Device_ID : 2 E.txt

2016-03-02 13:56:06.9283|**
2016-03-02 13:56:07.3333|ff

Device_ID : 2 A.txt

2020-03-02 13:42:30.0111| Started!
2020-03-02 13:42:30.0111|444|-0.051|0.051|0.008|0.016

Query:

index="xx" source="*A.txt"
| eval Device_ID=mvindex(split(source,"/"),5)
| reverse
| table Device_ID _raw
| rex field=_raw "(?<timestamp>[^|]+)\|(?<Probe_ID>[^|]+)"
| table Device_ID timestamp Probe_ID
| rex mode=sed field=timestamp "s/\\\\x00/ /g"
| table Device_ID timestamp Probe_ID
| eval time=strptime(timestamp,"%F %T.%4N")
| streamstats global=f max(time) as latest_time by Device_ID
| where time >= latest_time
| eval _time=strptime(timestamp,"%Y-%m-%d %H:%M:%S.%4N")
| table Device_ID _time Probe_ID
|join type=left Device_ID [ search index="xx" source="*E.txt"
| eval Device_ID=mvindex(split(source,"/"),5)
| reverse
| rex field=_raw "(?<timestamp>[^|]+)"
| stats first(timestamp) as earliesttime last(timestamp) as latesttime by Device_ID
|table Device_ID earliesttime latesttime
]
|where _time >= strptime(earliesttime, "%Y-%m-%d %H:%M:%S.%4N") AND _time <= strptime(latesttime, "%Y-%m-%d %H:%M:%S.%4N")

|search Device_ID="1"

 

Filtering events based on E.txt earliest timestamp on A.txt.

It is working for Device_ID 1 and not for Device_ID 2.

Both logs are same format.

It is not generating earliest and latest timestamp for device_ID 2. If i run subsearch alone, it is generating.

Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

To dIagnose these problems run the outer search on its own and the inner search on its own.

You are using join, which is not necessary and may be the issue depending on your data size.

You don't need the table commands all the time and you seem to be duplicating your time parsing (time and _time).

Not sure you need reverse either - in the join, you are reversing to get the first timestamp, which in practice without the reverse would be the oldest _time, so you could just to earliest(timestamp) instead without reverse.

 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Event Series: Splunk Observability Metrics Cost Optimization

Balancing Scale and Spend: Gaining Control Over High-Volume Metrics in Splunk Observability Cloud As ...

Kick the Tires Before You Commit: A Hands-On Tour of the Splunk Observability Cloud ...

Evaluating an enterprise observability platform usually goes like this: fill out a form, get a free trial with ...

Deep insights, no barriers: Splunk Observability Cloud Free Edition

As software delivery cycles continue to accelerate, observability shouldn’t be a luxury — it should be a ...