Splunk Search

How to add a column to a stats table using rex

harshparikhxlrd
Path Finder

I'm fairly new to splunk and have just learned how to use the rex/regex. I am trying to add a column in my string search to a statistics table to display the name of the workstation. This is my current string.

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi harshparikhxlrd
if the field you want i ComputerName, probably you already have because Splunk recognize by itself the pair field=value.
Anyway the regex to extract Computername is:

| rex "(?ms)ComputerName\=(?<Computername>[^ ]*)Task"

that you can test at https://regex101.com/r/0n0rks/1

So your search will be (sorry I cannot rewrite your regex because I cannot see it, use Code Sample button to share regexes):

index=monitoring sourcetype=PEGA:WinEventLog:Application ( SourceName="RoboticLogging" OR SourceName="Application" ) ("Department=" "HRSS_STL") ("Type=" "Error") 
| rex "Message : (?.+.?)" 
| rex "(?ms)ComputerName\=(?<Computername>[^ ]*)Task"
| stats count by ex 
| rename ex as Exception 

Ciao.
Giuseppe

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi harshparikhxlrd
if the field you want i ComputerName, probably you already have because Splunk recognize by itself the pair field=value.
Anyway the regex to extract Computername is:

| rex "(?ms)ComputerName\=(?<Computername>[^ ]*)Task"

that you can test at https://regex101.com/r/0n0rks/1

So your search will be (sorry I cannot rewrite your regex because I cannot see it, use Code Sample button to share regexes):

index=monitoring sourcetype=PEGA:WinEventLog:Application ( SourceName="RoboticLogging" OR SourceName="Application" ) ("Department=" "HRSS_STL") ("Type=" "Error") 
| rex "Message : (?.+.?)" 
| rex "(?ms)ComputerName\=(?<Computername>[^ ]*)Task"
| stats count by ex 
| rename ex as Exception 

Ciao.
Giuseppe

gcusello
SplunkTrust
SplunkTrust

Hi harshparikhxlrd,
Try now:

index=monitoring sourcetype=PEGA:WinEventLog:Application ( SourceName="RoboticLogging" OR SourceName="Application" ) ("Department=" "HRSS_STL") ("Type=" "Error") 
| rex "(?ms)ComputerName\=(?<Computername>[^ ]*)Task.*Message\=(?<Message>.*)"
| stats stats values(Message) As Message values(Computername) AS Computername count by ex 
| rename ex as Exception 

That you can test at https://regex101.com/r/0n0rks/2 .

Ciao.
Giuseppe

0 Karma

harshparikhxlrd
Path Finder

Adding to previous post:

Message=

0 Karma
Get Updates on the Splunk Community!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...