Splunk Search

SPL Can't do conditional statements after dealing with multi value fields

clozach
Path Finder

My goals is to grab the computer name from the multi-value field: identities. I then want to take that new attribute and check whether it begins with LT or PC to determine if it is a workstation. I've had many searches trying to compose this.

index=opendns_s3 identities=* | eval computer=mvindex(identities, 2) | where computer="lt"

index=opendns_s3 identities=* | eval computer=mvindex(identities, 2) | eval workstation=if(computer == "lt*", "Workstation", "Not Workstation")

If there is a completely different approach that would be better suitable, I would encourage that.

Thank you for your time.

0 Karma
1 Solution

niketn
Legend

@clozach if the identities field in your raw data is already a multi-valued field, your first requirement should work out of the box with the following query:

index=opendns_s3 identities="Lt*" 

For second query if identities is really a multi-valued field and the 2 index (i.e. the third element in the multi-valued identities field as index starts from 0 not 1) is computer name, then the query should work. Is it possible that (1) Either identities is not multi-valued or (2) The value Lt* is not at third index of the multivalued field?

Following is a run anywhere search for the second SPL where commands from makeresults till fields - testdata generate dummy data and mvjoin() evaluation function is used to bring the values together as single value for eval to perform:

| makeresults
| eval testdata="Apple,Banana,Cat;Dog,Emu,Fish"
| makemv testdata delim=";"
| mvexpand testdata
| eval identities=split(testdata,",")
| fields - testdata

| eval identities=mvjoin(identities,",")    
| eval computer=case(match(identities,"(?i)Ca"),"Workstation",
                     true(),"Non Workstation")

PS: match() evaluation function with (?i) performs case insensitive match.
Please try out and confirm!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@clozach if the identities field in your raw data is already a multi-valued field, your first requirement should work out of the box with the following query:

index=opendns_s3 identities="Lt*" 

For second query if identities is really a multi-valued field and the 2 index (i.e. the third element in the multi-valued identities field as index starts from 0 not 1) is computer name, then the query should work. Is it possible that (1) Either identities is not multi-valued or (2) The value Lt* is not at third index of the multivalued field?

Following is a run anywhere search for the second SPL where commands from makeresults till fields - testdata generate dummy data and mvjoin() evaluation function is used to bring the values together as single value for eval to perform:

| makeresults
| eval testdata="Apple,Banana,Cat;Dog,Emu,Fish"
| makemv testdata delim=";"
| mvexpand testdata
| eval identities=split(testdata,",")
| fields - testdata

| eval identities=mvjoin(identities,",")    
| eval computer=case(match(identities,"(?i)Ca"),"Workstation",
                     true(),"Non Workstation")

PS: match() evaluation function with (?i) performs case insensitive match.
Please try out and confirm!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

A Four-Part Event Series: Full Stack Observability For the AI Era

As AI reshapes applications, infrastructure, and the way teams operate, the traditional boundaries of ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...