Splunk Search

A more efficient query ?

ddebevec
New Member

One of our users has beought forth the following question:

I would like to be able to determine if IP Addresses from China are attempting to hit one or more of our servers. I have a list IP ranges for China in CIDR Notation, to the tune of 3400+, ranges. I have figured out how to make a query using the cidrmatch function, but I am afraid that a query of this nature may cause a severe negative impact on the performance of our Splunk environment.

The basics of the query that I have put together are:

host=myhost AND error_code-12345 | where (cidrmatch("cidrblk1/24", src) OR cidrmatch("cidrblk2/17", src) OR cidrmatch("cidrblk3/19", src) OR...)

Is there a better, more efficient way, "SAFER" way to handle this?

Is there a better way to handle this?

Tags (1)
0 Karma

Ayn
Legend

The search command can handle CIDR blocks directly, so there's no need to use a separate where clause there. That will also speed things up.

host=myhost AND error_code=12345 AND (src=cidrblk1/24 OR src=cidrblk2/17 OR ...)

Note also that the MAXMIND app is pretty good for when you want to perform geolocation searches like this. You'll find it here: http://splunk-base.splunk.com/apps/22282/geo-location-lookup-script-powered-by-maxmind

Ayn
Legend

It will not just shorten it, most of all it will make it faster, because the search command will not have to retrieve as many items from disk just to send them off to where which will just discard lots of them.

If you have that many CIDR blocks, I'd advise you to use a lookup table (they can do CIDR matches as well) - not that I think it'll make any difference performance-wise, but the query will obviously not become two miles long 🙂

cmbarber
New Member

Ayn, Thanks for the reply. I am actually the per who asked this question of ddebevec. That will shortent eh actual text of the query. I am looking to see if this is the mst efficient way to do this, or is there another means? The query would still have 3400+ items. Would something like the following severly impact the performance of the server?

host=myhost AND error_code=12345 AND (src=cidrblk1/24 OR src=cidrblk2/17 OR ... src=cidrblk1142/24 OP ... OR src=cidrblk2237/15 OR ... OR src=cidrblk3447/23)

Is ther ea way to use a table or some other construct?

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