Splunk Search

Last time a forwarder sent a log until now.

My
Engager

Hi there,

I am new to splunk. I and was wondering how to find the difference in time from the last time a forwarder sent a log until now and if the host has not sent a log in 5 min, set status to offline?

I am trying to achieve  this Expected outcome of time comparison:

My_0-1637599658385.png

 

Thank you 

Labels (3)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

There is also another issue. And this is a general issue with splunk's event processing. Whereas some siem and log management solutions store various additional timestamps, splunk only stores _time (which is supposed to represent something called "event time" in some systems) and _indextime which is the timestamp at which the event was written do index. There is no information whatsoever about other stages of processing pipeline - you don't have the timestamp when it was received or read from the source, you don't know if it was queued on the forwarder or simply if the source has unsynchronized clock. You don't have this detailed info.

Therefore you might query for the _time but it might (and in general - should) be the timestamp parsed from the event itself. It might have nothing to do with when it was read/received and forwarded by forwarder. Especially with sources that do either batch log writing or inputs that do batch reading. For example - some configurations of WEC subscriptions can have up to 30 minutes synchronization delay. So your event might be half an hour old but still might have just been recently sent by the forwarder.

 

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi @My,

you could run something like this:

index=your_index
| stats latest(_time) AS latest count BY host
| eval 
     diff=now()-latest, 
     status=if(diff>300,"Offline","Online"),
latest=strftime(latest,"%Y-%m-%D %H:%M:%S")
| table host status latest diff

there's only one problem: in this way you can find only hosts that sent in the monitoring period, but if an host never sent an event, you haven't it in the above report.

To solve this problem, you have to create a llokup (called e.g. perimeter.csv) containing the hostname (field host) all the hosts to monitor and then run a search like this:

index=your_index
| eval host=lower(host)
| stats latest(_time) AS latest count BY host
| append [ | inputlookup perimeter.csv | eval host=lower(host), count=0 | fields host count ]
| stats values(_time) AS latest sum(count) AS total BY host
| eval 
     diff=now()-latest, 
     status=if(total=0,"never sent events",if(diff>300,"Offline","Online")),
     latest=strftime(latest,"%Y-%m-%D %H:%M:%S")
| table host status latest diff

Ciao.

Giuseppe

My
Engager

Thank you!

I was able to get the desired results with this,

My_0-1637612580444.png

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

There is also another issue. And this is a general issue with splunk's event processing. Whereas some siem and log management solutions store various additional timestamps, splunk only stores _time (which is supposed to represent something called "event time" in some systems) and _indextime which is the timestamp at which the event was written do index. There is no information whatsoever about other stages of processing pipeline - you don't have the timestamp when it was received or read from the source, you don't know if it was queued on the forwarder or simply if the source has unsynchronized clock. You don't have this detailed info.

Therefore you might query for the _time but it might (and in general - should) be the timestamp parsed from the event itself. It might have nothing to do with when it was read/received and forwarded by forwarder. Especially with sources that do either batch log writing or inputs that do batch reading. For example - some configurations of WEC subscriptions can have up to 30 minutes synchronization delay. So your event might be half an hour old but still might have just been recently sent by the forwarder.

 

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...