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 (3)
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!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...