Getting Data In

How can I set _time for a json payload that has to first be restructured with SEDCMD?

andrewtrobec
Motivator

Hello!  I realize that the question is a bit particular, so I will try to explain through an example.

I am indexing a json that looks like this with escaped characters and leading/trailing quotes:

"{\"data\": {\"essentials\": {\"monitorCondition\": \"Resolved\",\"firedDateTime\": \"2022-09-26T14:56:41.7862462Z\",\"resolvedDateTime\": \"2022-09-26T15:02:47.9852843Z\"}}}"

I need to associated _time to the following statement:

If monitorCondition=Fired then parse firedDateTime as _time, otherwise parse resolvedDateTime as _time.

Since the json is not understood directly by Splunk due to the escaped quotes I am attempting the following:

  1. format the _raw correctly so that it is interpreted correctly by Splunk.
  2. calculate the value to use as timestamp
  3. associate timestamp to the _time field 

This is my props.conf so far:

[json_test_st]
KV_MODE = json
DATETIME_CONFIG = 
LINE_BREAKER = ([\r\n]+)
MAX_TIMESTAMP_LOOKAHEAD = 500
NO_BINARY_CHECK = true
TZ = GMT
category = Custom
disabled = false
pulldown_type = 1
SEDCMD-formatjson = s/\\|^\"|\"$//g 
TRANSFORMS = gettime
TIMESTAMP_FIELDS = timestamp
TIME_FORMAT = %Y-%m-%dT%H:%M:%S.%7NZ
 
This is my transforms.conf
 
[gettime]
INGEST_EVAL = timestamp=if('data.essentials.monitorCondition' = "Fired",'data.essentials.firedDateTime','data.essentials.resolvedDateTime')

 

The result is that I can get Splunk to parse the json correctly, but it does not extract the timestamp.

Could anybody give me a push in the right direction?

Thank you and best regards,

Andrew

Labels (4)
0 Karma

johnhuang
Motivator

Put this in your transforms.conf instead of INGEST_EVAL.  This regex works off the _raw event example you've provided. Disable the SEDCMD.

REGEX = \x5c\x22monitorCondition\x5c\x22[^\w]*(((Fired)[^\w]*firedDateTime)|(.*resolvedDateTime))[^\w]*(?<timestamp>[\w\d\:\-\.]*)

 

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!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...