Splunk Search

Can you help me with the following search using a lookup?

a212830
Champion

Hi,

We are frequently required to validate that data is being received by Splunk from multiple servers. The lists of IPs/hosts can be quite long. I am trying to come up with a search that will make this easier, like putting the entries into lookup files and then running a search against the entries in the lookups. So far, I have a lookup with a hostname, IP, and potentially, a wildcard for that host (sometimes the hosts are fully qualified and sometimes they are not). The IPs are reported as hosts, not as a separate "ip" field.

By using this search, I can retrieve data for hosts:

index=* [|inputlookup testSVB2.csv|table host ]

Is there anyway to expand this so it it will run a search against matching hosts OR IPs OR wildcards? When I table out host or IP, it seems to be running an "AND", rather than an "OR".

Finally, is there anyway to limit the number of events returned per host?

0 Karma
1 Solution

woodcock
Esteemed Legend

You need the format command; here is a run-anywhere example:

|makeresults | eval raw="host1,ip1 host2,ip2 host3,ip3"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?<host>\w+),(?<ip>\w+)$"
| table host ip
| format "(" "(" "OR" ")" "OR" ")"

In your case, like this:

 index=* [|inputlookup testSVB2.csv | table host ip | format "(" "(" "OR" ")" "OR" ")"]

To limit the number of events per host just do this (I have chosen to limit to 10):

 index=* [|inputlookup testSVB2.csv | table host ip | format "(" "(" "OR" ")" "OR" ")"]
| dedup 10 host

View solution in original post

0 Karma

sloshburch
Splunk Employee
Splunk Employee

"We are frequently required to validate that data is being received by Splunk from multiple servers."
What about the Monitoring Console's page for Forwarders?

I use the alerts in MC as well to let me know of missing forwarders

0 Karma

woodcock
Esteemed Legend

You need the format command; here is a run-anywhere example:

|makeresults | eval raw="host1,ip1 host2,ip2 host3,ip3"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?<host>\w+),(?<ip>\w+)$"
| table host ip
| format "(" "(" "OR" ")" "OR" ")"

In your case, like this:

 index=* [|inputlookup testSVB2.csv | table host ip | format "(" "(" "OR" ")" "OR" ")"]

To limit the number of events per host just do this (I have chosen to limit to 10):

 index=* [|inputlookup testSVB2.csv | table host ip | format "(" "(" "OR" ")" "OR" ")"]
| dedup 10 host
0 Karma

a212830
Champion

Thanks. These are both very good, it looks like woodcock's is more what I'm looking to implement. Is there anyway to limit the results per host? I tried "top limit=x", but that didn't work.

0 Karma

a212830
Champion

Figured it out. Add a "top limit=x host" to the end.

Also came up with a way to do the same thing via tstats, which is much faster.

Thanks!

0 Karma

Vijeta
Influencer

You can achieve that using map command
|inputlookup estSVB2.csv|fields host ip| map search="index=* host=$host$ OR ip=$ip$| table host ip"

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...