Getting Data In

Set a field to a value when it may or may not exist exist

markwymer
Path Finder

Hi,
We have a specific logon event message that only has the word 'errorcode' if the logon fails - there is nothing to indicate a successful logon. A logon failure event looks something like |HDR+1|TIME+2015-09-22 22:14:57.646 GMT|DATA++LOGON:111.111.111.11:app name:deviceType-iPhone,deviceVersion-8.3,,,,connection-2,,membershipNumber-username@domain.com,,,,errorcode-MOB21038

A successful logon would be the same but without the last "error code" message.
If I was doing this in a shell script, I would do something like:-

if [ echo $event | grep -c "errorcode" -eq 1 ] ; then
Logon_Status="Failed"
else
Logon_Status="Successful"
fi

My question is, what would the FIELD EXTRACT look like in the props.con file to set Logon_Status to either "Successful" or "Failed"

(n.b. I can get the Logon_Status=Failed quite happily - it's just the other bit that has me stumped!)

Many thanks for any and all help,
Mark.

0 Karma

markwymer
Path Finder

Hi Rich,
Thanks for the rapid response. In the short term I will use your solution but I was hoping that I could add it to my props.conf file e.g. "EXTRACT-Logon_Status = (some_convoluted_reg_expression).

Appreciate your help,
Mark.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Something like this should get you started.

<your event search> | eval Logon_Status=if(isnull(errorcode),"Successful","Failed") | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma

markwymer
Path Finder

Hi Rich,
Thanks for the rapid response. In the short term I will use your solution but I was hoping that I could add it to my props.conf file e.g. "EXTRACT-Logon_Status = (some_convoluted_reg_expression).

Appreciate your help,
Mark.

0 Karma

somesoni2
Revered Legend

You should be able to add this eval statement in your props.conf as calculated fields, like this

EVAL-Logon_Status=if(isnull(errorcode),"Successful","Failed") 

richgalloway
SplunkTrust
SplunkTrust

I forgot about calculated fields. Good suggestion!

---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

I forgot about calculated fields. Good suggestion!

---
If this reply helps you, Karma would be appreciated.
0 Karma

richgalloway
SplunkTrust
SplunkTrust

I'm not aware of any convoluted regexes that can find something that isn't there.

---
If this reply helps you, Karma would be appreciated.
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 ...