Splunk Search

Search for an adjacent IP address

logginz85
Explorer

Hi.

I have an alert that'll tell me if a host is down, and it runs for both Active and Standby hosts.

The issue is that when the standby host hasn't received a log,  I'd like to run a search to see if the active host has received a log in the last 24 hours, and if so to ignore it.

I can run a search for all IPs, but what I cant seem to do is see if 198.0.0.2 is down, to check for 198.0.0.1 (the Active is always -1 from Standby)

I thought something like this might work, but no.

index=* host=*
[search index="*" host=198.0.0.2

|rex field=host "(?<Net>\d+\.\d+\.\d+)\.(?<Host>\d+)"
|eval Host2 = (Host-1)
|eval newhost= Net. "." .Host2
|fields newhost]
|where host=newhost

any and all help appreciated

Labels (4)
0 Karma
1 Solution

logginz85
Explorer

Hi, that makes sense, and |format helped me realise it wasn't pulling through right. 

That lead me onto this.

index="*" host = *
| eval standbyhost = "198.0.0.2"
| rex field=standbyhost "(?<Net>\d+\.\d+\.\d+)\.(?<Host>\d+)"
| eval Host2 = (Host-1)
| eval newhost= Net. "." .Host2
| where host = newhost

I create a new field "standbyhost" that is the value of the standby host I already know. I apply this to all results.
Then I do maths to lower this IP by 1, and create the new field newhost.

Now every rsult has their host as their own host IP, but the field newvalue of the target I'm looking for.

Then its just a where host=newhost to find it.

Seeing as this will actually pull the value of standbyhost from a field in an alert, I think this'll work.



View solution in original post

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Splunk has a hard time finding things that aren't there.  In this case, if host 198.0.0.2 isn't found then there will be no host field from which to extract sub-fields and, so, no newhost field.  

If you run the subsearch by itself with "| format" added then you'll see what it returns to the main search.

---
If this reply helps you, Karma would be appreciated.

logginz85
Explorer

Hi, that makes sense, and |format helped me realise it wasn't pulling through right. 

That lead me onto this.

index="*" host = *
| eval standbyhost = "198.0.0.2"
| rex field=standbyhost "(?<Net>\d+\.\d+\.\d+)\.(?<Host>\d+)"
| eval Host2 = (Host-1)
| eval newhost= Net. "." .Host2
| where host = newhost

I create a new field "standbyhost" that is the value of the standby host I already know. I apply this to all results.
Then I do maths to lower this IP by 1, and create the new field newhost.

Now every rsult has their host as their own host IP, but the field newvalue of the target I'm looking for.

Then its just a where host=newhost to find it.

Seeing as this will actually pull the value of standbyhost from a field in an alert, I think this'll work.



0 Karma

richgalloway
SplunkTrust
SplunkTrust

If your problem is resolved, then please click the "Accept as Solution" button to help future readers.

---
If this reply helps you, Karma would be appreciated.
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...