Splunk Search

How to search for a series of strings then count and display by host?

skiller1234
Explorer

Hello everybody!

Trying to search for a series of strings - then count and display by host. I got this far:

index=index host=*server* "failover" OR "Whatever" OR "screwup"
| rex "(?<error>failover)"
| rex "(?<error>Whatever)"
| rex "(?<error>screwup)"
| stats count by host,error
| xyseries error,host,count

So I get a chart like so:

error                     server1                       server2                  server3

screwup                10                                      11                            18

Which is what I want - but I only get the last result set (for screwup). I know all 3 have results. What am I doing wrong in creating my new field called error with 3 possible values?

Skiller

0 Karma
1 Solution

xpac
SplunkTrust
SplunkTrust

Change your rex like this:

| rex "(?(?:failover|Whatever|screwup))"

This should check all conditions in one. Else every rex line has the potential to overwrite the result from the line(s) before it. 😉

EDIT: Can there be more than one error in the same event?

In that case, do | rex max_match=0 "(?(?:failover|Whatever|screwup))"

View solution in original post

xpac
SplunkTrust
SplunkTrust

Change your rex like this:

| rex "(?(?:failover|Whatever|screwup))"

This should check all conditions in one. Else every rex line has the potential to overwrite the result from the line(s) before it. 😉

EDIT: Can there be more than one error in the same event?

In that case, do | rex max_match=0 "(?(?:failover|Whatever|screwup))"

richgalloway
SplunkTrust
SplunkTrust

Please share some sample events.

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

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 ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...