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