Dashboards & Visualizations

How to compare events and show if there is any difference?

vrmandadi
Builder

I am trying to write a search that will compare data for the latest event with its previous event and show the difference if any for each host .I am trying to use earliest and latest event but I earliest doesnt take the immediate  preceding event 

Following is the search I have tried but I dont think its right

index=abc host=xyz
| stats latest(id) as id  latest(SN) as SN latest(PN) as PN  latest(_time) as time by host
|stats earliest(id) as eid   earliest(SN) as eSN  earliest(PN) as ePN   earliest(_time) as etime by host

 

Thanks in Advance Splunkers

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

index=abc host=xyz
| sort 0 _time
| streamstats window=1 current=f global=f latest(id) as pid latest(SN) as pSN latest(PN) as pPN  latest(_time) as ptime by host
| reverse
| dedup host

You can now compare id with pid, SN with pSN etc.

0 Karma

vrmandadi
Builder

@ITWhisperer  I tried your search but It did not result in any results...I am not sure how your search shows the difference if you only have latest in it

 

| streamstats window=1 current=f global=f latest(id) as pid latest(SN) as pSN latest(PN) as pPN latest(_time) as ptime by GPU

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Are you using host, GU or GPU?

index=abc host=xyz
| sort 0 _time
| streamstats window=1 current=f global=f latest(id) as pid latest(SN) as pSN latest(PN) as pPN  latest(_time) as ptime by GPU
| reverse
| dedup GPU

Streamstats add the fields to each event, the reverse then dedup keeps the first event for each GPU (GU / host / whatever)

0 Karma

vrmandadi
Builder

@ITWhisperer  raw data coming in but no statistical data for that search

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Perhaps you could share some events so we can see what it is you are dealing with. Obviously, you should anonymise any personal or sensitive values. Please share them in a code block </>. Also if you could identify which fields you already have extracted, that would be helpful.

0 Karma

inventsekar
SplunkTrust
SplunkTrust

Hi @vrmandadi ...

>> I am trying to write a search that will compare data for the latest event with its previous event and show the difference if any for each host.

your search query does not include any compare options.. bit confusing actually.. 


Maybe, please try this... 

index=abc host=xyz 
| stats latest(id) as id, earliest(id) as eid, latest(SN) as SN, earliest(SN) as eSN, latest(PN) as PN, earliest(PN) as ePN, earliest(_time) as etime, latest(_time) as time by host

 

thanks and best regards,
Sekar

PS - If this or any post helped you in any way, pls consider upvoting, thanks for reading !
0 Karma

vrmandadi
Builder

hello @inventsekar  .Sorry if my question is bit confusing...I am basically trying to compare events and show the difference if any but I dont know how to do it...so I dont have any comparison operators ..Your search gives earliest and latest data for a particular time range..but it doesnt exactly compare the successive events .

I am trying to the search by using a by clause on field "GU" which has 8 values  ..I am not sure how to compare 

 

| stats latest(id) as id, earliest(id) as eid, latest(SN) as SN, earliest(SN) as eSN, latest(PN) as PN, earliest(PN) as ePN, earliest(_time) as etime, latest(_time) as time by GU

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...