Splunk Search

How to extract fields from events where the field location isn't constant and keeps changing?

VI371887
Path Finder

I want to write a query or rex under field extraction, to extract each value following a string and stopping at coma,

example :
hcyycuvubuv : 45544.466, "cpu percentage" :23.45667, "higghh": 23.345t,

in above string, I am only looking for numbers that come after "cpu_percentage":
, which is 23.45667

problem is, in my events the cpu percentage string is not at the same location in logs.

example :

first event
chhchvhvh: 223. 455, "cpu_percentage":23.45677,gghffvhh:3455

second event
chhchvhvh: 223. 455, tuvjvujjvg:3456.566, "cpu_percentage":23.45677,gghffvhh:3455.788

0 Karma
1 Solution

anjambha
Communicator

Hi VI371887,

Try this run search anywhere..

| makeresults | eval data="\"disk_bytes\":23.10,\"disk_bytes_quota\":23.13t," | rex field=data "disk_bytes\"\:(?<disk_bytes>\d+\.\d*)\,\"disk_bytes_quota\"\:(?<disk_bytes_quota>\d+\.\w+)\,"

in your environment:

base search |  rex field=_raw "disk_bytes\"\:(?<disk_bytes>\d+\.\d*)\,\"disk_bytes_quota\"\:(?<disk_bytes_quota>\d+\.\w+)\,"

OR

base search | rex field=data "disk_bytes\"\:(?<disk_bytes>[^,]+)\,\"disk_bytes_quota\"\:(?<disk_bytes_quota>[^,]+)\,"

View solution in original post

anjambha
Communicator

Hi VI371887,

Try this run search anywhere..

| makeresults | eval data="\"disk_bytes\":23.10,\"disk_bytes_quota\":23.13t," | rex field=data "disk_bytes\"\:(?<disk_bytes>\d+\.\d*)\,\"disk_bytes_quota\"\:(?<disk_bytes_quota>\d+\.\w+)\,"

in your environment:

base search |  rex field=_raw "disk_bytes\"\:(?<disk_bytes>\d+\.\d*)\,\"disk_bytes_quota\"\:(?<disk_bytes_quota>\d+\.\w+)\,"

OR

base search | rex field=data "disk_bytes\"\:(?<disk_bytes>[^,]+)\,\"disk_bytes_quota\"\:(?<disk_bytes_quota>[^,]+)\,"

deepashri_123
Motivator

Hey VI371887,

You can try the following:

base search|rex field=_raw "\"cpu_percentage\"\:(?P<percentage>\d+.\d+[^,])" 

Let me know if this helps!!!

0 Karma

VI371887
Path Finder

hi i am having similar issues,

with msg field

it's has different values can be numbers, strings, path, punctuations, blank space like shown below.

"msg" :"35556"
"msg" :"<<÷] {<} ;;"
"msg" :"ycuvuuu jvbigg buivuv"
"msg" :" "

now problem is, i have written rex as
\msg\":(? \". *\") \,

but it returns value which following msg field.

"msg" :"vjvuv igivc uvviv", "origin" :"abcgc", "time" :23.45677",

0 Karma

somesoni2
Revered Legend

Try like this

your base search 
| rex "\"cpu_percentage\"\:(?<cpu_percentage>[^,]+)"

or

your base search
| extract pairdelim="," kvdelim=":"
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...