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 [email protected] 
| eval days = round((now() - _time)/86400)
| table Role, user, _time, days
| sort - days

Sample Data Below

RoleUserName_timedays
Global Reader[email protected]2021-09-19T08:35:06.99829
Global Reader[email protected]2021-09-19T08:35:05.51429
Systems Administrator[email protected]2021-09-23T05:55:51.17725
Systems Administrator[email protected]2021-09-23T05:55:49.03625
Global Reader[email protected]2021-09-24T00:48:20.25424
Storage Operator[email protected]2021-09-24T00:48:18.94224
Systems Administrator[email protected]2021-09-27T07:22:23.97121
Systems Administrator[email protected]2021-09-27T07:22:22.97121
Global Reader[email protected]2021-09-27T07:19:40.56921
Global Reader[email protected]2021-09-27T07:19:39.46021

 

Desired results only show the most recent events 

RoleUserName_timedays
Global Reader[email protected]2021-09-24T00:48:20.25424
Storage Operator[email protected]2021-09-24T00:48:18.94224
Systems Administrator[email protected]2021-09-27T07:22:22.97121
Global Reader[email protected]2021-09-27T07:19:39.46021
Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=audit [email protected] 
| 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 [email protected] 
| 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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...