Splunk Search

How to use "original" search value if map has no result?

norbertt911
Communicator

Hi Splunkers,

I use many alerts where the result contains the username. Then a map search looks for this user, in the user list index, checks the group memberships, and will send the alert to the corresponding IT department. (there are many countries and there is a lookup that tells the support email by the user's country group). If the user is not a member of any country-group support email eval to the central one.

That is working fine... until the user is in the user's index. If the user cannot be found there, the whole search is not working.

Example:

index=logons action=failure | stats dc(action) as failures by username | where failures > 20
| map maxsearches=50 search=" search index=users user=\"$username$\" | spath memberOf{}.displayName output=groupName
| eval username=\"$usernam$\", failures=\"$failures$\"
| lookup support.csv group as groupName output support"
| eval support = if(isnull(support) OR support="", "central@example.com", support)
| table username, failures, support

So if a user failed to log in more than 20 times the alert triggers and sends an email to support - assigned by the group membership, if there is no membership, it will send to central IT.

If the user cannot be found in index=users for some reason, the alert will not trigger at all. I would like it if the alert triggers and send to central@example.com (since a not existing user, has no group ...) with the username from the base search included.

Labels (2)
0 Karma
1 Solution

norbertt911
Communicator

Figured out! Thanks for the tip!

index=logons action=failure
| stats dc(action) as failures by username
| where failures > 20
| map maxsearches=50 search=" search index=users user=\"$username$\"
| appendpipe [ stats count | eval user=\"$username$\" | where count=0 | fields - count ]
| spath memberOf{}.displayName output=groupName
| eval username=\"$username$\", failures=\"$failures$\"
| lookup support.csv group as groupName output support"
| eval support = if(isnull(support) OR support="", "central@example.com", support)
| table username, failures, support

View solution in original post

norbertt911
Communicator

Figured out! Thanks for the tip!

index=logons action=failure
| stats dc(action) as failures by username
| where failures > 20
| map maxsearches=50 search=" search index=users user=\"$username$\"
| appendpipe [ stats count | eval user=\"$username$\" | where count=0 | fields - count ]
| spath memberOf{}.displayName output=groupName
| eval username=\"$username$\", failures=\"$failures$\"
| lookup support.csv group as groupName output support"
| eval support = if(isnull(support) OR support="", "central@example.com", support)
| table username, failures, support

richgalloway
SplunkTrust
SplunkTrust

Use the appendpipe command to ensure there is a value for the groupName field after searching index=users.

index=logons action=failure 
| stats dc(action) as failures by username 
| where failures > 20 
| map maxsearches=50 search=" search index=users user=\"$username$\" 
  | spath memberOf{}.displayName output=groupName 
  | eval username=\"$usernam$\", failures=\"$failures$\"
  | appendpipe [ stats count | eval username="foo", groupName="bar" | where count=0 | fields - count ] 
  | lookup support.csv group as groupName output support" 
| eval support = if(isnull(support) OR support="", "central@example.com", support) 
| table username, failures, support
---
If this reply helps you, Karma would be appreciated.

norbertt911
Communicator

Maybe I was misunderstood. The groupName part is fine (there are many values). There is a problem if Username does not exist. If the index=users search returns with no result...

In this case, how I can tell Splunk: "Okay, forget the map part, take the base search result and add central@example.com as value to support field"

0 Karma
Get Updates on the Splunk Community!

Strengthen Your Future: A Look Back at Splunk 10 Innovations and .conf25 Highlights!

The Big One: Splunk 10 is Here!  The moment many of you have been waiting for has arrived! We are thrilled to ...

Now Offering the AI Assistant Usage Dashboard in Cloud Monitoring Console

Today, we’re excited to announce the release of a brand new AI assistant usage dashboard in Cloud Monitoring ...

Stay Connected: Your Guide to October Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...