I have a dashboard where the user selects options from a couple of drop downs which are driven by lookups. These drop-downs combine to construct a file path for the search. Menu 1 is a list of location codes ($location$) or a wildcard for All (*), Menu 2 is a list of data types ($dataype$). Unfortunately, two of the data types are at different folder levels, (\server\datatype\location vs \servername\folder\datatype\location), so I haven't been able to work out a consistent way to extract the location folder because it changes depending on data type. I ended up using an erex to extract the location field on the fly like this:
erex jkreceive examples="tx,$location$,al,pa,colorado,ny,stl"
My erex wasn't working 100% of the time, but if I included the $location$ variable in the examples it works great. However, at the end of the search I need to translate the location codes to a descriptive location name using another lookup. This is all fine if the user chooses a location from the menu, but if the user selects "All" from the location menu, which translates to "*", the erex fails and the location to description translations all fail except the locations specified as examples.
I tried doing an eval with an if statement to create a conditional erex, but Splunk keeps terminiating the search saying I'm missing a ). No matter how many )'s I add, it ends the same. Here is the search (in my lookup, 'jkreceive' is the field containing the location codes and 'Site' is the descriptive name):
index="jkr" sourcetype="jkr" file_path="*$datatype$\$location$\\*"
| eval jkreceive=if(jkreceive="*",(erex jkreceive examples="tx,$location$,al,pa,colorado,ny,stl"),(erex jkreceive examples="tx,al,pa,colorado,ny,stl"))
| eval MB=round(filesize/1024/1024, 2)
`convertxfr`
| eval "Creation Date"= strptime(timestamp,"%m/%d/%Y %H:%M:%S")
| convert timeformat="%Y-%m-%d %T" ctime("Creation Date") AS "Creation Date (Local)"
| lookup Locations.csv jkreceive OUTPUT Site
| rename filename as File
| appendpipe [ stats count
| eval Site="There are no results to display"
| where count==0]
| table Site "Transfer Date (CT)" "Creation Date (Local)" File MB
| sort +"Creation Date (Local)"
Is a conditional erex possible? Or am I barking up the wrong tree?
... View more