Splunk Search

How can I identify hosts that don't have any events over a 4-hour period and create an alert?

glenngermiathen
Path Finder

I want to identify any host that doesn't have any events over a four hour period and create an alert. Having trouble extracting the individual host.

index=ind1
| timechart span=4h count by host
| where count = 0
| table host count time

0 Karma
1 Solution

justinatpnnl
Communicator

You could use the metadata command for type=hosts. Splunk keeps track of all hosts that have sent data, including the first and last time of the events it has received. I have a similar one I use for this. The query below shows the hosts that have sent data within the last 24 hours, but not within the last 4 hours.

| metadata type=hosts index=ind1
| where recentTime < relative_time(now(), "-4h") AND recentTime > relative_time(now(), "-24h") 

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi blacknight659,
you have to create a lookup containing all the hosts in your perimeter to monitor (e.g. perimeter.csv, with one column called "host") and then run a search like this

index=ind1 earliest=-4h latest=now
| eval host=upper(host)
| stats count BY host
| append [ | inputlookup perimeter.csv | eval count=0, host=upper(host)  | fields host ]
| stats sum(count) AS Total BY host
| where Total=0
| table host

Deleting the row "|where Total=0" you can have a situation of your perimeter to display in a dashboard (also in graphic mode).

Bye.
Giuseppe

0 Karma

lfedak_splunk
Splunk Employee
Splunk Employee

Hey @glenngermiathen, if they solved your problem, remember to "√Accept" an answer to award karma points 🙂

0 Karma

justinatpnnl
Communicator

You could use the metadata command for type=hosts. Splunk keeps track of all hosts that have sent data, including the first and last time of the events it has received. I have a similar one I use for this. The query below shows the hosts that have sent data within the last 24 hours, but not within the last 4 hours.

| metadata type=hosts index=ind1
| where recentTime < relative_time(now(), "-4h") AND recentTime > relative_time(now(), "-24h") 

glenngermiathen
Path Finder

Exactly what I needed, thanks!

0 Karma

blacknight659
Explorer

This is tough, because it is easier to look for something that is there rather than something that is not. Also, showing that over a timechart might not be easy.

I have a solution I would like for you to consider. I am not 100% sure it will work, but it would be worth testing. If your hosts don't change, then you could use a inputlookup and use a subsearch to find only the list of host you care about.

index=ind1 [|inputlookup hosts.csv | fields host]
| transaction host maxspan=4h
| rename linecount as LogCount
| stats count as count sum(LogCount)
| table host linecount
| fillnull value="null"

If this works, then you can make a search at the end of this to find all the "null" hosts.

I hope this helps.

0 Karma

glenngermiathen
Path Finder

Thanks for the suggestion! I thought about using the static lookup, but the challenge that creates is that it must be maintained. If new hosts are added that I am not aware of they will not be monitored.

0 Karma
Get Updates on the Splunk Community!

Index This | Divide 100 by half. What do you get?

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

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

❄️ Celebrate the season with our December lineup of Community Office Hours, Tech Talks, and Webinars! ...

Splunk and Fraud

Watch Now!Watch an insightful webinar where we delve into the innovative approaches to solving fraud using the ...