We have a lookup file that contains host, sourcetype, state, max_delay, and admin. All hosts start with state="up" . The max_delay field allows us to have hosts with varying expected delays between events. (Some hosts are expected to log events every 10 seconds, and others may go 3 hours between events in normal operations.) The admin field defines who gets notified when a given host goes down - again, this is for modularity. Every 10 minutes, we run the following search:
| tstats latest(_time) as latest where index=* OR index=_* by host, sourcetype
| search
[ |inputlookup critical_hosts
| fields host sourcetype ]
| lookup critical_hosts host sourcetype OUTPUT max_delay, severity, admin, state, _key
| eval current_delay=now()-latest
| where max_delay<current_delay
| search state="up"
| eval state="down"
| outputlookup hosts_lookup append=true key_field=_key
| fillnull value="" admin
| eval admin="
[email protected],".admin
| convert ctime(latest)
| map search="| sendemail from=\"
[email protected]\" to=\"$admin$\" subject=\"Splunk Alert: Critical Host Not Logging: $host$\" message=\"Splunk last heard from critical host $host$ with sourcetype $sourcetype$ and severity $severity$ at $latest$. The maximum expected delay from this host is $max_delay$ seconds, while the current delay is $current_delay$ seconds. Please check the host for possible failure. If you believe you received this message in error, please email
[email protected]. Thank you.\" server=\"ip.address\"" maxsearches=1000
We have a similar search that runs every 10 minutes looking for hosts that have resumed reporting. By updating the lookup file with changes in state, we can send alerts only when a host appears to go down and then when it appears to come back up - not every 5 minutes while it remains down.
... View more