Splunk Search

Why am I getting "Unknown search command ..." when trying to run a macro form the Java SDK?

lattar
Engager

We have a macro set up under 'Advanced search » Search macros', it takes 3 parameters (host, neighborIP, days). To run it from the search box in Splunk I simply put `my_macro(*,*,31)` which works fine. When I try to run this using the Java SDK I get the message "Unknown search command 'host'."
Below is the relevant part of the code

...
jobArgs.setExecutionMode(JobArgs.ExecutionMode.NORMAL);
JobCollection jobs = service.getJobs();
Job job = jobs.create("`my_macro(*,*,31)`", jobArgs);

Needless to say I'm new to Splunk and I may be being a bit dumb but, I can't seem to find information about executing macros with parameters from the SDK in the splunk documentation.

Any help would be very much appreciated

Tags (4)
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

You may need to prepend the search command to your search job. In the web interface this is done implicitly.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

You may need to prepend the search command to your search job. In the web interface this is done implicitly.

lattar
Engager

Thanks very much.

For anyone else with the same issue I changed the command to :

Job job = jobs.create("search `my_macro(*,*,31)`", jobArgs);
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 ...