Splunk Search

What will this query do? (This is a saved search running on cron *****)

muizash
Path Finder

Hi
Please help me understand what will this saved search do?

index=os sourcetype=splunk_health_check |eval value=delay_status |eval message=if(status=="OK","",status) |eval status=if(status=="OK",status,"NG") |eval score=if(value==99,-1,value) |table _time sh status score message |rename sh to searchhead |search score<5 AND status!="OK" message!="*No error" AND message!="Proxy Error"

source is a script.

for HOST in ${HOSTS}
do
URI=http://${HOST}:80
count=99
result=/opt/splunk/bin/splunk search "index=${INDEX} sourcetype=${SOURCETYPE} SPLUNK_HEALTH_CHECK |stats count" -earliest_time ${EARLIEST} -latest_time ${LATEST} -uri ${URI} -auth ${USER}:${PASS} -preview F -output csv -timeout ${TIMEOUT} 2>&1 |grep -v count |tr -d '\n' |sed 's/"//g'
if expr $result : '[0-9]*' > /dev/null 2>&1; then

count=$result
result="OK"

fi
date +"%Y-%m-%d %T sh=${HOST} status=\"${result}\" delay_status=$count"
done

Tags (3)
0 Karma

yannK
Splunk Employee
Splunk Employee

it will

find events

index=os sourcetype=splunk_health_check 

calculate some additional fields, value, message, status and score, drop other fields, and add the search-head name

|eval value=delay_status |eval message=if(status=="OK","",status) |eval status=if(status=="OK",status,"NG") |eval score=if(value==99,-1,value) |table _time sh status score message |rename sh to searchhead

and add a condition to drop all the events that do not meet the condition on score ,status and message

 |search score<5 AND status!="OK" message!="*No error" AND message!="Proxy Error"
0 Karma

muizash
Path Finder

for HOST in ${HOSTS}
do
URI=http://${HOST}:80
count=99
result=/opt/splunk/bin/splunk search "index=${INDEX} sourcetype=${SOURCETYPE} SPLUNK_HEALTH_CHECK |stats count" -earliest_time ${EARLIEST} -latest_time ${LATEST} -uri ${URI} -auth ${USER}:${PASS} -preview F -output csv -timeout ${TIMEOUT} 2>&1 |grep -v count |tr -d '\n' |sed 's/"//g'
if expr $result : '[0-9]*' > /dev/null 2>&1; then

count=$result
result="OK"

fi
date +"%Y-%m-%d %T sh=${HOST} status=\"${result}\" delay_status=$count"
done

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...