Reporting

Help with host not reporting search

SMWickman
Explorer

Looking for assistance with a search -

| metadata type=hosts | rename lastTime as "Last Event"| search host=**** | fieldformat "Last Event"=strftime('Last Event', "%c") | table host "Last Event" | rename host as Host

This search currently provides host and last reported event. I'm hoping to add one more column that essentially gives me a "Host Reporting" or "Host Not Reporting" based on last event time. "If "Last Event" is >10 minutes, show as "Host Not Reporting"

Any help would be appreciated.

Tags (1)
0 Karma
1 Solution

DalJeanis
Legend

General guidelines - 1) eliminate records as early as possible 2) calculations that matter before reformats and renames 3) renames that make the names clumsy to program as LATE as possible.

| metadata type=hosts | search host=* 
| eval HostStatus=if(lastTime<relative_time(now(),"-10m"),"Not Reporting","Reporting") 
| fieldformat lastTime=strftime(lastTime, "%c") 
| rename host as Host, lastTime as "Last Event" 
| table Host "Last Event" HostStatus

Final note = %c format is REALLY clumsy to read or to scan down. Try this instead...

| eval "Last Event"=strftime(lastTime, "%Y-%m-%d %H:%M:%S.%3Q").case(relative_time(lastTime,"@d")=relative_time(now(),"@d")," ... (today)",
    relative_time(lastTime,"@d")>=relative_time(now(),"-1d@d")," ... (yesterday)",
    relative_time(lastTime,"@d")>=relative_time(now(),"-6d@d")," ... (last ".strftime(lastTime, "%A").")",
    relative_time(lastTime,"@d")>=relative_time(now(),"-70d@d")," ... (".round((now()-lastTime)/86400/7)." weeks ago)",
    true()," ... long ago")

View solution in original post

DalJeanis
Legend

General guidelines - 1) eliminate records as early as possible 2) calculations that matter before reformats and renames 3) renames that make the names clumsy to program as LATE as possible.

| metadata type=hosts | search host=* 
| eval HostStatus=if(lastTime<relative_time(now(),"-10m"),"Not Reporting","Reporting") 
| fieldformat lastTime=strftime(lastTime, "%c") 
| rename host as Host, lastTime as "Last Event" 
| table Host "Last Event" HostStatus

Final note = %c format is REALLY clumsy to read or to scan down. Try this instead...

| eval "Last Event"=strftime(lastTime, "%Y-%m-%d %H:%M:%S.%3Q").case(relative_time(lastTime,"@d")=relative_time(now(),"@d")," ... (today)",
    relative_time(lastTime,"@d")>=relative_time(now(),"-1d@d")," ... (yesterday)",
    relative_time(lastTime,"@d")>=relative_time(now(),"-6d@d")," ... (last ".strftime(lastTime, "%A").")",
    relative_time(lastTime,"@d")>=relative_time(now(),"-70d@d")," ... (".round((now()-lastTime)/86400/7)." weeks ago)",
    true()," ... long ago")

adonio
Ultra Champion

up vote for detailed answer,
@SMWickman be careful when using the metadata command as its not always accurate.
read this answer for detailed explanation:
https://answers.splunk.com/answers/294791/accuracy-of-metadata-command-in-large-environments.html

SMWickman
Explorer

Thank you! Appreciate the detailed response!

Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...