Splunk Search

How do I write a regex command that extracts the username and replaces the appending -*a with @company.com?

sjcoluccio67
Explorer

I have a search query that finds users whose accounts have been locked out and then sends them an email saying so. These event records do not contain email addresses, but they do contain user names. Each user name is appended with either -fa, -da, or -na at the end (e.g. csteve-pa). If you take the user name and chop off the appendage and add @company.com (e.g. csteve@company.com), it will be a valid email address. I have tried to write a regex command that extracts the username and replaces the appending -*a with @company.com. The regex looks right to me, but splunk is not extracting the email address properly. below is my query and the error that I am getting.

 index=wineventlog sourcetype=WinEventLog:Security EventCode=4740 | eval user_new=user | **rex field=user_new mode=sed "s/\S+(-*a)/@company.com/g"** | sendemail to=$result.user_new$ server=mail.company.com subject="Your account has been locked out!" message="Splunk has detected that the account shown below has been locked out. Please contact Access Admins for assistance." sendresults=true inline=true format=raw **error** command="sendemail", {u'@company.com': (501, '5.1.3 Invalid address')} while sending mail to: @company.com

Any help would be greatly appreciated!

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

This worked for me:

| makeresults | eval user_new="csteve-pa" 
| rex field=user_new mode=sed "s/(\S+)-.a$/\\1@company.com/g"

If I understand the naming that you get, this should work for you.

0 Karma
Get Updates on the Splunk Community!

Dashboards: Hiding charts while search is being executed and other uses for tokens

There are a couple of features of SimpleXML / Classic dashboards that can be used to enhance the user ...

Splunk Observability Cloud's AI Assistant in Action Series: Explaining Metrics and ...

This is the fourth post in the Splunk Observability Cloud’s AI Assistant in Action series that digs into how ...

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...