Splunk Search

Search an index for two fields with a join

JandrevdM
Path Finder

Good day,

I am trying to figure out how I can join two searches to see if there is a service now ticket open for someone leaving the company and if that person is still signing into some of our platforms.

This is to get the signin details into the platform - as users might have multiple email addresses I want them all.

 

 

 

index=collect_identities sourcetype=ldap:query [ search index=db_mimecast splunkAccountCode=* mcType=auditLog
  |fields user
  | dedup user
  | eval email=user, extensionAttribute10=user, extensionAttribute11=user
  | fields email extensionAttribute10 extensionAttribute11
  | format "(" "(" "OR" ")" "OR" ")" 
  ]
| dedup email
| eval identity=replace(identity, "Adm0", "")
| eval identity=replace(identity, "Adm", "")
| eval identity=lower(identity)
| table email extensionAttribute10 extensionAttribute11 first last identity
| stats 
     values(email) AS email
     values(extensionAttribute10) AS extensionAttribute10
     values(extensionAttribute11) AS extensionAttribute11
     values(first) AS first
     values(last) AS last
     BY identity

 

 

 

 

This is to check all leavers in snow

 

 

 

index=db_service_now sourcetype="snow:incident" affect_dest="STL Leaver" 
| dedup description
| table _time affect_dest active description dv_state number

 

 

 

Unfortunately the Shub does not add the email in the description and only user names and surnames.

So I would need to search the first querys 'first' 'last' against the second query to find leavers.

this is what I tried but it does not work.

 

 

 

index=collect_identities sourcetype=ldap:query 
[ search index=db_mimecast splunkAccountCode=* mcType=auditLog
  | fields user
  | dedup user
  | eval email=user, extensionAttribute10=user, extensionAttribute11=user
  | fields email extensionAttribute10 extensionAttribute11
  | format "(" "(" "OR" ")" "OR" ")" 
]
| dedup email
| eval identity=replace(identity, "Adm0", "")
| eval identity=replace(identity, "Adm", "")
| eval identity=lower(identity)
| table email extensionAttribute10 extensionAttribute11 first last identity
| search "*first*" "*last*" [ search index=db_service_now sourcetype="snow:incident" affect_dest="STL Leaver" 
  | dedup description
  | table _time affect_dest active description dv_state number
]
| stats values(email) AS email values(extensionAttribute10) AS extensionAttribute10 values(extensionAttribute11) AS extensionAttribute11 values(first) AS first values(last) AS last BY identity

 

 

 

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It is not always easy to decipher what your search is trying to do without some sample representative anonymised events and expected results to see what your searches are doing. Please can you provide some events, preferably using the code block </> button to insert them into your reply.

0 Karma

JandrevdM
Path Finder

Sorry for the confusion. So search one gets the result like this.

identityemailextensionattribute10extensionattribute11firstlast
nsurnamename.surname@domain.comnsurnameT1@domain.comname.surname@consultant.comnamesurname


Search two will get all my tickets that was created for people leaving my company and will return results like this

_timeaffect_destactivedescriptiondv_statenumber
2024-10-31 09:46:55STL LeavertrueLeaver Request for Name Surname - 31/10/2024activeINC01



So the only way of searching would by to search the second query's description field where first and last appear

0 Karma

yuanliu
SplunkTrust
SplunkTrust

You didn't illustrate what is the expected results look like.  Based on the last stats in your OP, you only want to filter for first, last of people with a leave ticket, not to add any information about the ticket.  Is this correct?

In that case, just extract first and last in the second search and use it as subsearch, like this.

index=collect_identities sourcetype=ldap:query [ search index=db_mimecast splunkAccountCode=* mcType=auditLog
  |fields user
  | dedup user
  | eval email=user, extensionAttribute10=user, extensionAttribute11=user
  | fields email extensionAttribute10 extensionAttribute11
  | format "(" "(" "OR" ")" "OR" ")" 
  ]
    [search index=db_service_now sourcetype="snow:incident" affect_dest="STL Leaver"
    | dedup description
    | rex field=description "Leaver Request for (?<first>\S+) (?<last>\S+) -"
    | fields first last]
| dedup email
| eval identity=replace(identity, "Adm0", "")
| eval identity=replace(identity, "Adm", "")
| eval identity=lower(identity)
| stats 
     values(email) AS email
     values(extensionAttribute10) AS extensionAttribute10
     values(extensionAttribute11) AS extensionAttribute11
     values(first) AS first
     values(last) AS last
     BY identity

Note the extraction of first and last depends on the precise format in description; additionally, it assumes that first and last contains no white space.

Tags (1)

JandrevdM
Path Finder

Thanks - this is defnitely helping a lot. I would love to join the tables in the results. And what I also noticed is that the description isn't always exactly "Leaver Request for" that is why I added affect_dest="STL Leaver" which checks just for leaver tickets

identityemailextensionattribute10extensionattribute11firstlast_timeaffect_destactivedescriptiondv_statenumber
nsurnamename.surname@domain.comnsurnameT1@domain.comname.surname@consultant.comnamesurname2024-10-31 09:46:55STL LeavertrueLeaver Request for Name Surname - 31/10/2024activeINC01
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 ...