Splunk Search

How do we find the first non-zero packet loss event?

mk197m
New Member

example dated newest to oldest :
{ "ip_address": "255.255.255.255","loss_pct": 0, "device_id": "ABC"}
{ "ip_address": "255.255.255.255","loss_pct": 10, "device_id": "ABC"}
{ "ip_address": "255.255.255.255","loss_pct": 20, "device_id": "ABC"}
{ "ip_address": "255.255.255.255","loss_pct": 0, "device_id": "ABC"}

{ "ip_address": "255.255.255.255","loss_pct": 20, "device_id": "XYZ"}
{ "ip_address": "255.255.255.255","loss_pct": 20, "device_id": "XYZ"}
{ "ip_address": "255.255.255.255","loss_pct": 0, "device_id": "XYZ"}
{ "ip_address": "255.255.255.255","loss_pct": 20, "device_id": "XYZ"}

{ "ip_address": "255.255.255.255","loss_pct": 10, "device_id": "PQR"}
{ "ip_address": "255.255.255.255","loss_pct": 10, "device_id": "PQR"}

{ "ip_address": "255.255.255.255","loss_pct": 50, "device_id": "AAA"}
{ "ip_address": "255.255.255.255","loss_pct": 0, "device_id": "AAA"}
{ "ip_address": "255.255.255.255","loss_pct": 20, "device_id": "AAA"}
{ "ip_address": "255.255.255.255","loss_pct": 0, "device_id": "AAA"}
{ "ip_address": "255.255.255.255","loss_pct": 100, "device_id": "AAA"}
{ "ip_address": "255.255.255.255","loss_pct": 0, "device_id": "AAA"}

expected output:
{ "ip_address": "255.255.255.255","loss_pct": 20, "device_id": "XYZ"}
{ "ip_address": "255.255.255.255","loss_pct": 50, "device_id": "AAA"}

Notice : if newest packet loss zero then exclude. if packet loss zero has not seen within the search result then exclude. if packet lost swap few times then take take first newest non zero pack lost

0 Karma
1 Solution

DalJeanis
SplunkTrust
SplunkTrust

Try this.

| fields ip_address device_id loss_pct 
| eventstats min(loss_pct) as minloss max(loss_pct) as maxloss first(loss_pct) as currloss by ip_address device_id  
| streamstats count as firstcount by ip_address device_id 
| where currloss>0 AND minloss=0 AND firstcount=1

Since you have not shown a _time field, I am assuming there is none, and am assuming that the newest event will be first in the order that events are returned.

(I generally prefer to use latest() rather than first() or last().)

View solution in original post

0 Karma

mk197m
New Member

i am interested to get records which as more then 0 pact lost right after zero. four highlighted records is desire output for me.

Any help thanks 🙂

0 Karma

DalJeanis
SplunkTrust
SplunkTrust

Try this.

| fields ip_address device_id loss_pct 
| eventstats min(loss_pct) as minloss max(loss_pct) as maxloss first(loss_pct) as currloss by ip_address device_id  
| streamstats count as firstcount by ip_address device_id 
| where currloss>0 AND minloss=0 AND firstcount=1

Since you have not shown a _time field, I am assuming there is none, and am assuming that the newest event will be first in the order that events are returned.

(I generally prefer to use latest() rather than first() or last().)

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...