Splunk Search

Searching on consecutive lines

Sphere991
New Member

My logs output two consecutive lines in the case of a connection timeout:

... CONNECTION-x.x.x.x:y: connect() timeout
... [service_name] tearing down tcp connection [x.x.x.x.y]

Where x.x.x.x:y is the ip:port and service_name is some string. How do I put together a splunk query to basically end up with a table of the # of timeouts for each service_name?

Tags (1)
0 Karma

P_vandereerden
Splunk Employee
Splunk Employee

In the "better late than never" category of answers (and I realize this answer might not have been available in previous versions of Splunk)...

It's unclear, from the original question, if the "ip:port" belongs to the service, or the client.

If it belongs to the service, then every timeout uniquely identifies the service, and all that needs to be done is to count the timeouts, and then map in the service name:

| makeresults | eval data="CONNECTION-1.1.1.1:1: connect() timeout,[service_with_2_timeouts] tearing down tcp connection [1.1.1.1.1],CONNECTION-1.1.1.2:2: connect() timeout,[service_with_1_timeout] tearing down tcp connection [1.1.1.2.2],[service_with_no_timeouts] tearing down tcp connection [1.1.1.3.3],CONNECTION-1.1.1.1:1: connect() timeout,[service_with_2_timeouts] tearing down tcp connection [1.1.1.1.1]"
| eval mvdata=split(data,",")
| mvexpand mvdata
``` Everything above this is to generate sample data ```
| eval is_timeout=if(like(mvdata,"%connect() timeout%"),1,0)
| rex field=mvdata "CONNECTION-(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(?<port>\d+): connect\(\) timeout"
| rex field=mvdata "\[(?<service_name>[^\]]+)\] tearing down tcp connection \[(?<ip>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\.(?<port>\d+)\]"
| stats first(service_name) as service_name, sum(is_timeout) as timeout_count by ip, port

 

If, on the other hand, the "ip:port" belong to the client accessing the service, this is a bit more complicated, with too many potential solutions depending on details not available here.

Paul van der Eerden,
Breaking software for over 20 years.
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!

Casting Call: Compete in Cyber Games

Lights, Camera, SecOps: Apply to Compete in Cyber Games     Think you have what it takes to beat the clock? ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

How Edge Processor's Durable Queue Works

Edge Processor sits in one of the most consequential places in any Splunk pipeline: between your data sources ...