SPLK-1002 Macros, Saved Searches and CIM Practice Question
A Splunk admin wants to create a macro named `filter_by_app` that accepts an application name as an argument and returns a search string filtering by that application. The application name may contain spaces. Which of the following correctly defines the macro's arguments and usage?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
Definition: `filter_by_app($app$)` and usage: `index=main app="$app$"`
Macro arguments must be referenced with $arg$ syntax and when the value contains spaces, it must be quoted. Option A defines the argument numerically (1) and uses $1$ without quotes, which fails for spaces. Option B defines the argument with $app$ (invalid syntax for definition) and uses $app$ without quotes. Option D defines 'app' without dollar signs, so the usage treats 'app' as literal text, not a variable. Option E uses $1 without a trailing dollar sign, which is invalid.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Definition: `filter_by_app(1)` and usage: `index=main app=$1$`
Why it's wrong here
Definition uses numeric argument (1) and usage uses $1$ without quotes; fails for spaces.
- ✗
Definition: `filter_by_app($app$)` and usage: `index=main app=$app$`
Why it's wrong here
Definition uses $app$ which is not a valid argument name; usage uses $app$ without quotes.
- ✓
Definition: `filter_by_app($app$)` and usage: `index=main app="$app$"`
Why this is correct
Definition uses $app$ as argument placeholder and usage uses $app$ with quotes, correctly handling spaces.
- ✗
Definition: `filter_by_app(app)` and usage: `index=main app=app`
Why it's wrong here
Definition uses 'app' without dollar signs, so usage treats 'app' as literal, not a variable.
- ✗
Definition: `filter_by_app($1)` and usage: `index=main app=$1`
Why it's wrong here
Definition uses $1 without trailing dollar sign; usage also uses $1, invalid syntax.
Go deeper
Related to this question
About these practice questions
One of 475 original SPLK-1002 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This SPLK-1002 practice question is part of Courseiva's free Splunk certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SPLK-1002 exam.