Splunk Enterprise

Looping in SPLUNK Query

Janani_Krish
Path Finder

Hello,

I have a table of IP's and my requirement is to fetch raw data for all the IP's from each and every sourcetype having the IP.

My query is like below,

1.sourcetype="IPs"|dedup ip|table ip

So I want to use below logic,

For each and every IP in the table, run the below query,

2.sourcetype!="IPs"|table sourcetype,_raw

Help me to run the second query for each and every IP in 1st query and merge the tables.

 

Labels (2)
Tags (1)
0 Karma

thambisetty
SplunkTrust
SplunkTrust

there could be many events in a single sourcetype that matches one particular IP, this will create search performance issue and it may take hours/days if you are searching in GBs of data. 

sourcetype!="IPs" 
    [ search sourcetype="IPs" 
    | stats count by IP 
    | table IP 
    | rename IP as search 
    | format] 
| table sourcetype,_raw

The reason for not using IP field in sub search is because your other source types may not have have field IP as I can see you provided only table sourcetype, _raw. The above search will do basic search with just IPs rather than IP and IP_value. we can't group the sourcetype and _raw by IP because IP field could be different in different sourcetypes, if you think IP field is present in all source types, you can add below to the search.

| stats values(sourcetype) as sourcetype values(_raw) as _raw by IP

 

give a thumps up if my answer gives a clue.

————————————
If this helps, give a like below.

ITWhisperer
SplunkTrust
SplunkTrust

Have you tried the join command to link the two queries by ip?

0 Karma

Janani_Krish
Path Finder

Hi @ITWhisperer , 

I cannot use join because I do not have a single meta in my second sub query.

1.In my 1st part of query I have single sourcetpe which is IPs and meta as IP.

2.My second part of query has to search for the ip address in all sourcetype other than sourcetype=IPs.

So since Ip is captured in different metas in rest all sourcetype,this makes it difficult to use join command.

Eg: It is src_ip in sourcetype1, dst_ip in sourcetype 2 etc.,

0 Karma

thambisetty
SplunkTrust
SplunkTrust

can you explain your query with examples?

————————————
If this helps, give a like below.
0 Karma

Janani_Krish
Path Finder

Hello @thambisetty ,

Currently I have my query in 2 parts.
1. sourcetype="IPs"|dedup IP|table IP
2. sourcetype!="IPs"|table sourcetype,_raw

Currently I have the data as below from 1st part of query.
128.0.0.9
234.56.78.98
45.76.89.98

I want these Ips to be mapped with its respective raw logs where the IP may or may not be captured in different/more than one sourcetype as below by combining the second part of query.


128.0.0.9          sourcetype 1 raw log
                             sourcetype 2 raw log
234.56.78.98  sourcetype 2 raw log
45.76.89.98    sourcetype 3 raw log
                             sourcetype n raw log

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...