Splunk Search

Display days passed between current time and most recent activation - User Role Auditing

dmbr
Explorer

The answer to this probably stupid simple. Banging my head on this.

Help and patience please.
 
I am writing a query which audits user role activations.

A user can have many roles, i.e. Network Admin, Security Reader, User Admin, Storage Operator, etc.

Specifically, I want to view how many days has passed since a user activated a specific role.
 
Today - Last Activation = Days Since Last Activation

 

Questions:
  1. How can I most efficiently subtract the time of the most recent role activation event from the current time?
  2. How can I then only show the most recent results?
  3. How to then audit all users who have not activated a role in the past 30 days?

 

Base query for a single user search over 30 days and sample results are below.

 

 index=audit user=bob@example.com 
| eval days = round((now() - _time)/86400)
| table Role, user, _time, days
| sort - days

Sample Data Below

RoleUserName_timedays
Global Readerbob@example.com2021-09-19T08:35:06.99829
Global Readerbob@example.com2021-09-19T08:35:05.51429
Systems Administratorbob@example.com2021-09-23T05:55:51.17725
Systems Administratorbob@example.com2021-09-23T05:55:49.03625
Global Readerbob@example.com2021-09-24T00:48:20.25424
Storage Operatorbob@example.com2021-09-24T00:48:18.94224
Systems Administratorbob@example.com2021-09-27T07:22:23.97121
Systems Administratorbob@example.com2021-09-27T07:22:22.97121
Global Readerbob@example.com2021-09-27T07:19:40.56921
Global Readerbob@example.com2021-09-27T07:19:39.46021

 

Desired results only show the most recent events 

RoleUserName_timedays
Global Readerbob@example.com2021-09-24T00:48:20.25424
Storage Operatorbob@example.com2021-09-24T00:48:18.94224
Systems Administratorbob@example.com2021-09-27T07:22:22.97121
Global Readerbob@example.com2021-09-27T07:19:39.46021
Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=audit user=bob@example.com 
| stats latest(_time) as _time by user, Role
| eval days = round((now() - _time)/86400) 
| table Role, user, _time, days 
| sort - days

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
index=audit user=bob@example.com 
| stats latest(_time) as _time by user, Role
| eval days = round((now() - _time)/86400) 
| table Role, user, _time, days 
| sort - days

dmbr
Explorer

Sincere Thank you ITWhisperer for the reply, much appreciated.

As expected, the solution was much stupid simple. 😂

0 Karma
Get Updates on the Splunk Community!

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...