Splunk Search

How do I obtain data from a search based on matching field values from multiple source types?

nixlim
New Member

Dear All,

I have just started using Splunk and I have a question:

I have one index and two source types. The structure is as follows:

index: servers

sourcetypes: server and gateway

The record structure (fields) is as follows:

sourcetype=gateway
|
->OriginID: (this is an alphanumeric ID - eg 12345)
->ClientType: (can be either BACKEND or FRONTEND)

sourcetype=server
|
->TransactionID: (this is an alphanumeric ID - eg 12345)

I was trying to build a query that would give me a number of all BACKEND(or FRONTEND) transactions where OriginID equals TransactionID. I basically need to know how many are hitting the server from BACKEND and how many from FRONTEND.

So, I tried this:

index=servers sourcetype=gateway AND sourcetype=server| search *| where TransactionID==OriginID| stats by count

This does not work. Could I please ask what would be the best way to get the details that I want to see?

Thank you.

Tags (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

There are a few reasons why your search didn't work.

index=servers sourcetype=gateway AND sourcetype=server| search *

An event can have only one sourcetype, which will have only one value so it's not possible for sourcetype to be 'gateway' and 'server' at the same time. The search command is not needed since that is implied.

where TransactionID==OriginID

Again, each event will have either OriginID or TransactionID, but not both so it's impossible to compare these fields to each other.

stats by count

There is no field called 'count' so one cannot group by that field. You probably meant stats count by, but then you'd need a field by which to group the counts.

To find the number of backend and frontend transactions, try this query.

index=servers (sourcetype=gateway OR sourcetype=server) | stats count by ClientType
---
If this reply helps you, Karma would be appreciated.

View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

There are a few reasons why your search didn't work.

index=servers sourcetype=gateway AND sourcetype=server| search *

An event can have only one sourcetype, which will have only one value so it's not possible for sourcetype to be 'gateway' and 'server' at the same time. The search command is not needed since that is implied.

where TransactionID==OriginID

Again, each event will have either OriginID or TransactionID, but not both so it's impossible to compare these fields to each other.

stats by count

There is no field called 'count' so one cannot group by that field. You probably meant stats count by, but then you'd need a field by which to group the counts.

To find the number of backend and frontend transactions, try this query.

index=servers (sourcetype=gateway OR sourcetype=server) | stats count by ClientType
---
If this reply helps you, Karma would be appreciated.
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...