Splunk Search

lookup value based on current search results

lbrhyne
Path Finder

New to Splunk and having a difficult time returning the correct results. The below query works... meaning that it converts the email address to user from the identities index and successfully looks up the value of user in the wineventlog index that contain either EventCode 4624 or 4625 based on the provide critera. However, when the stats are listed in the table after the query has completed, the values(user) as "Login ID" does not line up with values(fullname) as "Full Name", values(department) as Department and the device name does not show. Example: Login ID = tJones Full Name = Sammy Smith The goal is to have all the fields line up simular to Tjone | Tom Jones | Department Name | Device. Thanks in advance for any assistance provided.

index=identities sourcetype="Vantage" ee_status=* earliest=-1d@d latest=-0d@d
| eval user = trim(replace(email, "@domain.com", ""))
| search  [ | search index="wineventlog"  sourcetype="WinEventLog:Security" (EventCode=4624 AND Logon_Type=2) OR EventCode=4625 earliest=-10m latest=now()| fields user| format]
| table user,department,ad_fname,ad_last_name, Workstation_Name
| eval fullname = toString(ad_fname) + " " + toString(ad_last_name)
| stats values(user) as "Login ID", values(fullname) as "Full Name", values(department) as Department, values(Workstation_Name) as Device
Tags (1)
0 Karma
1 Solution

jawaharas
Motivator

To rename a field use 'rename' command not 'stats' which is to categorize data based on a particular field.

index=identities sourcetype="Vantage" ee_status=* earliest=-1d@d latest=-0d@d 
| eval user = trim(replace(email, "@domain.com", "")) 
| search 
    [| search index="wineventlog" sourcetype="WinEventLog:Security" (EventCode=4624 AND Logon_Type=2) OR EventCode=4625 earliest=-10m latest=now() 
    | table user ] 
| eval fullname = toString(ad_fname) + " " + toString(ad_last_name) 
| table user,department,ad_fname,ad_last_name, Workstation_Name
| rename user as "Login ID", fullname as "Full Name", department as Department, Workstation_Name as Device

Reference:
https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Stats
https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Rename

View solution in original post

0 Karma

jawaharas
Motivator

To rename a field use 'rename' command not 'stats' which is to categorize data based on a particular field.

index=identities sourcetype="Vantage" ee_status=* earliest=-1d@d latest=-0d@d 
| eval user = trim(replace(email, "@domain.com", "")) 
| search 
    [| search index="wineventlog" sourcetype="WinEventLog:Security" (EventCode=4624 AND Logon_Type=2) OR EventCode=4625 earliest=-10m latest=now() 
    | table user ] 
| eval fullname = toString(ad_fname) + " " + toString(ad_last_name) 
| table user,department,ad_fname,ad_last_name, Workstation_Name
| rename user as "Login ID", fullname as "Full Name", department as Department, Workstation_Name as Device

Reference:
https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Stats
https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/Rename

0 Karma

lbrhyne
Path Finder

Thank you Jawaharas, that worked! The last thing I'm still not able to pull into the report is the Device name from the wineventlog, as it remains to be blank.

0 Karma

woodcock
Esteemed Legend

You should click Accept to close this question and if you have something different (even if related), ask another.

0 Karma

jawaharas
Motivator

Kindly accept the answer it it helped you, so others can refer it.

The field names are case sensitive. Verify the field name 'Workstation_Name'

0 Karma
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...