Dashboards & Visualizations

Using a windows pathname in a searchTemplate in a form.

steveta_uk
Explorer

I have logs from various sources, including windows. I have written a simple form for selecting which directory to analyze, with a dynamically populated radio list to select the directory. It doesn't work on windows due the "\" characters in the directory name.

  .searchTemplate. index=main dir="$dir$" ./searchTemplate.
  .fieldset.
    .input type="radio" token="dir".
    .label.Select directory ./label.
    .choice value="*">Any./choice.
    .populatingSearch 
    fieldForValue="dir" 
    fieldForLabel="dir".
    .![CDATA[index=main sourcetype=syslog | stats count by dir]].
     ./populatingSearch.
      ./input.
    ...

("<" and ">" removed to get this to display at all).

I have no control over the values in "dir" - any windows path including "\" fails the search, and any that ends with "\" (not uncommon) give a PARSER error
"Applying intentions failed unbalanced quotes."

Is there some syntax that will allow the dir="$dir$" clause to pass the value unescaped?

thanks.

Tags (3)
0 Karma

steveta_uk
Explorer

Fixed. The trick was to add a space to the variable in quotes so the final " is not escaped, then trim it in the search.

| where dir=rtrim("$dir$ ")

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...