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!

Deep Dive into Federated Analytics: Unlocking the Full Power of Your Security Data

In today’s complex digital landscape, security teams face increasing pressure to protect sprawling data across ...

Your summer travels continue with new course releases

Summer in the Northern hemisphere is in full swing, and is often a time to travel and explore. If your summer ...

From Alert to Resolution: How Splunk Observability Helps SREs Navigate Critical ...

It's 3:17 AM, and your phone buzzes with an urgent alert. Wire transfer processing times have spiked, and ...