Splunk Search

How to edit this search to exclude some servers from the metadata?

kirankotla
New Member
| metadata   index=Test_app  type=hosts | eval age = now()-lastTime | where age > (60) | sort age d | convert ctime(lastTime)  | fields age,host,lastTime

Please provide query for excluding a few servers from this metadata.

0 Karma

sjohnson_splunk
Splunk Employee
Splunk Employee

What do you mean by servers? The splunk indexers that are returning the data or the actual host names returned by the metadata?

If you want to filter by hosts, I like to use a regex statement since often host names have some pattern that can be used (i.e. wxxx for windows, xxxpxxx - production, etc.) This is easy with regex:

| regex host!="^w"
or
| regex host!="np|dev"

Just remember that regex is case sensitive, so you may need to use "(?i)np|dev" to make it case insensitive.

0 Karma

niketn
Legend

You can filter using search command. Ideally you should include the hosts you need rather than excluding the hosts you don't need. You can use AND and OR for adding a list of hosts. Following example will exclude all servers starting with abc like abc01, abc02 etc.

| metadata index=Test_app type=hosts 
| search host!="abc*"
| eval age = now()-lastTime 
| where age > (60) 
| sort age d 
| convert ctime(lastTime)
| fields age,host,lastTime

Following will not include servers abc, def, ghi. Like stated earlier, performance wise, it is better to include required fields values rather than excluding the values not required.

| metadata <Your Base Search>
| search host!="abc" AND host!="def" AND host!="ghi"
| <your remaining search>
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
Get Updates on the Splunk Community!

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 ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...