Splunk Search

How To Use Eval to Capture Inconsistent key:values

mark_groenveld
Path Finder

I am searching for a key:value report app where the values are inconsistent but include a report cluster name consistently.

Example of key:value
APP_Details:{"CLUSTER_VIP":"CLUSTERX.URL.COM","Access":true}

There are over 100 APP_Details values for CLUSTERX.

How can I extract CLUSTERX (there are three different cluster names) to show as a single value by cluster?

Thanks

Labels (3)
0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @mark_groenveld 

Is that the full event or a field in your event? Is the whole event JSON? If possible please give some full examples.

Are the names of the 3 cluster always CLUSTER followed by a single character?

Thanks

Will

0 Karma

mark_groenveld
Path Finder

Here are 2 examples of the values for the events:

 

{"CLUSTER1.COM","viewSiteAsUser.hasAccess":true}

{"CLUSTER_VIP":"CLUSTER1.COM"}

0 Karma

livehybrid
SplunkTrust
SplunkTrust

Hi @mark_groenveld 

As the samples dont look to be valid JSON, I assume we can use the *rex* command on them against the _raw field.

Try this:

| rex field=_raw "(?<ClusterVal>CLUSTER[0-9]+)"

This should give you a field called ClusterVal with your cluster in it.

Please let me know how you get on and consider adding karma to this or any other answer if it has helped.
Regards

Will

mark_groenveld
Path Finder

Thanks for posting livehybrid.  The rex did not work.  Karma points to you for giving it a go 👊

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

@mark_groenveld 

The rex does work with the "events" you shared (as demonstrated below)

| makeresults
| fields - _time
| eval _raw="{\"CLUSTER1.COM\",\"viewSiteAsUser.hasAccess\":true}
{\"CLUSTER_VIP\":\"CLUSTER1.COM\"}"
| multikv noheader=t
| fields _raw
| rex field=_raw "(?<ClusterVal>CLUSTER[0-9]+)"

Please share more events where the rex "did not work"

0 Karma

mark_groenveld
Path Finder

I am looking for a way to pull out CLUSTER1 as a single value as there are two other clusters, CLUSTER2 AND CLUSTER3.

Thanks

0 Karma

PickleRick
SplunkTrust
SplunkTrust

I'm not sure what you mean by "extract" in this context. Do you have your fields extracted already and used it in a different meaning or do you want to extract values from the raw data? Give us a bit more example events and describe what would be the result (based on that example data) and why.

0 Karma

mark_groenveld
Path Finder

Sure.

Here are examples of the values.

{"CLUSTER1.COM","viewSiteAsUser.hasAccess":true}

{"CLUSTER_VIP":"CLUSTER1.COM"}

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI!Discover how Splunk’s agentic AI ...

Splunk Enterprise Security 8.x: The Essential Upgrade for Threat Detection, ...

Watch On Demand the Tech Talk on November 6 at 11AM PT, and empower your SOC to reach new heights! Duration: ...

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...