Getting Data In

script input not working when parameter is passed as a variable and not the static value in inputs.conf

sara91
Explorer

Hi All,

I am using a script to fetch http response as splunk raw event. For this I am passing parameter as a variable, whose value is in another conf file.
The inputs.conf is as below:

[script:///opt/splunkforwarder/etc/apps/search/bin/scripts/urlhealthcheck.sh HEALTHCHECK_URL ]
sourcetype = healthcheck
disabled = false
interval = 300
index = main

The configuration file where the parameter HEALTHCHECK_URL is stored;example.conf

HEALTHCHECK_URL=https://healthcheckurl.domain.com

The shell script urlhealthcheck.sh;

#!/bin/sh
url=$(cat PRA.conf | grep $1 | awk -F "=" '{print $2}')
responsecode=$(wget -S --spider --no-check-certificate $url 2>&1 | grep "HTTP/" | awk '{print $2}')
response=$(wget -q --no-check-certificate -O - $url 2>&1 )
echo "URL=$url, ResponseCode=$responsecode, Response=$response"

This shell script is running perfectly when run from the terminal as

sh /opt/splunkforwarder/etc/apps/search/bin/scripts/urlhealthcheck.sh HEALTHCHECK_URL

Or run as

./opt/splunkforwarder/etc/apps/search/bin/scripts/urlhealthcheck.sh HEALTHCHECK_URL

giving output as ;
[
{
"code": 200,
"response": "Health Check: Succeeded"
}
]

But in inputs.conf this giving the response as ;
wget: missing URL
Usage: wget [OPTION]... [URL]...
Try `wget --help' for more options.

If I change the parameter from HEALTHCHECK_URL to https://healthcheckurl.domain.com as the http response is coming out correct without an error.

[script:///opt/splunkforwarder/etc/apps/search/bin/scripts/urlhealthcheck.sh https://healthcheckurl.domain.com ]
sourcetype = healthcheck
disabled = false
interval = 300
index = main

What is the reason that I am not able to pass the parameter as a variable through the inputs.conf, though the script is working fine?

0 Karma
1 Solution

nickhills
Ultra Champion

where is "PRA.conf" located.
Scripts do not execute with ./app/bin as the working directory.
Its probable therefore that PRA.conf is not being found, and thus not expanded.

Can you try specifying the path fully in the script?
url=$(cat /opt/splunkforwarder/etc/apps/search/bin/scripts/PRA.conf | grep $1 | awk -F "=" '{print $2}')

If my comment helps, please give it a thumbs up!

View solution in original post

0 Karma

nickhills
Ultra Champion

where is "PRA.conf" located.
Scripts do not execute with ./app/bin as the working directory.
Its probable therefore that PRA.conf is not being found, and thus not expanded.

Can you try specifying the path fully in the script?
url=$(cat /opt/splunkforwarder/etc/apps/search/bin/scripts/PRA.conf | grep $1 | awk -F "=" '{print $2}')

If my comment helps, please give it a thumbs up!
0 Karma

sara91
Explorer

Thankyou. It is working

0 Karma

nickhills
Ultra Champion

Great news!, Please accept my answer so others can see what the solution was in the furture!

If my comment helps, please give it a thumbs up!
0 Karma
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...