Getting Data In

Can I Assign to Host The Value From A Variable?

attoriozi
Explorer

I would like to assign to "host" a variable initiated in the input script.

For instance, is it possible something like this:

[script://./bin/hostrandom.sh]

interval = 10

host = $RHOST

sourcetype = hostrandom

disabled = 0

where

cat ../bin/hostrandom.sh

export RHOST=HOST$RANDOM

echo "This is the Event for $RHOST "

Tags (2)

gkanapathy
Splunk Employee
Splunk Employee

You can't do this based on a value that is set in the scripted input, though you can use a variable that is set in the environment in which the Splunk process runs. However, if you have a scripted input, there are other ways to set the host by having the script itself output a field that can be transformed at index time, or by using dynamic metadata assignment

gkanapathy
Splunk Employee
Splunk Employee

Don't use should_linemerge = true. Use SHOULD_LINEMERGE = false and a unique LINE_BREAKER pattern between events.

0 Karma

attoriozi
Explorer

still not good: in my case the input script generates an event that needs to be split in multiple events (SHOULD_LINEMERGE=true). In this case only one of those events is going to be associated to the extracted host, all the other are going to be associated to default host.

0 Karma

attoriozi
Explorer

basically doing the above and then use a index time extraction. Ok thanks

0 Karma

attoriozi
Explorer

Documentation is not very clear. I think it just suggests a script like: << echo "This is the Event for host=RHOST$RANDOM " >>

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...