Getting Data In

Extract event fields in desired format

rantravee
Path Finder

hi,

I'd need some hints regarding the propertiesI should have in in props.conf and transforms.conf so that I have data in the needed format. So I within my scripted input I print to standard output a json object of the following format

{

"statistics" :[{stats_resource_json_obj_1},....,{stats_resource_json_obj_n}]

}

each stats_resource_json_obj_i has the folowing format
{
"id":value,
............
"stat_i":"val_i"
}
I would like to have an event for each stats-resource-json-obj and to have recognized/extracted as fields (at search time) every pair of key/value within the object .

Thanks a lot

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

In your props.conf, make sure that your KV_MODE is set to JSON. In order to split up the events, since you have control of the script, I'd rework the script to print a new json object on each line, Splunk should handle the rest.

rantravee
Path Finder

The json obj comes in the format described in the question from a network resource :

resp, content = http.request(statistics_url,
method='POST',
headers={'Content-Type': 'application/json', 'charset':'UTF-8','Connection':'keep-alive', 'Host':'theHost'}, body=json_body)

and then I call printResponseToSplunk(), passing the content object to it

0 Karma

rantravee
Path Finder

Thanks for the channel hint. I was unware of that.

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

Can you paste the entire script to pastebin please? I want to see how you are crafting the string that you then dump with the json object. Don't forget we can help you out in Real Time on the IRC #splunk channel on efnet.

0 Karma

rantravee
Path Finder

def printResponseToSplunk(self,s):
jdata = json.loads(s)

# Augment json object with additional information
stats = jdata[JSON_STATS_OBJ_NAME]

for innerOBj in stats
innerOBj[JSON_CHASSIS_KEY]=self.getHost()
print (json.dumps(innerOBj))
sys.stdout.flush()

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

I would need to see a pastebin of you code to see what you are doing to accurately diagnose it.

0 Karma

rantravee
Path Finder

How could I achieve that ? I realize that my question may sound ridiculous , but I just recently crushed Pyhton Programming.

0 Karma

alacercogitatus
SplunkTrust
SplunkTrust

remove the single quotes from the field names.

0 Karma

rantravee
Path Finder

It seems Splunk is incapable of automatically extracting the fields .Only the default fields are extracted . I see a long string ,containing all the key/pair values . Something like

{'stat_1': 0, 'stat_2': 0, 'stat_3': 0, 'stat_4': 0, 'stat_4': 0, ....., 'stat_n': 0 }

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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...