Splunk Dev

How to list users with a specific role with Python SDK?

asimagu
Builder

Hi

I am trying to pull a list a users using Python SDK, but only the ones with a specific role.

I read this documentation http://dev.splunk.com/view/python-sdk/SP-CAAAEJ6#listusers

However, I can only get all the users of my system. I was wondering if I could use the component "roles"

I would only like to list users that have roles=teamA

thanks

Tags (4)
0 Karma
1 Solution

asimagu
Builder

i think i just found my own answer 😉

users = service.users
filtered_users = [x for x in users if 'admin' in x.roles ]
for user in filtered_users: print "%s (%s)" % (user.realname, user.roles)

View solution in original post

0 Karma

asimagu
Builder

i think i just found my own answer 😉

users = service.users
filtered_users = [x for x in users if 'admin' in x.roles ]
for user in filtered_users: print "%s (%s)" % (user.realname, user.roles)

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Don't see an option in the class definition to filter by role while requesting it. Could you do a filter based on a role after you retrieve all users?? It does return the role (user.role_entities).

0 Karma

asimagu
Builder

i have this.

for user in service.users: print "%s (%s)" % (user.realname, user.roles)

and this is the oupput:

Administrator (['admin'])
Amparo Pozi (['power', 'splunk-system-role', 'user'])
Amparo Ponno (['admin', 'splunk-system-role', 'user'])
Ampario Alaca (['admin', 'power', 'user'])

How can I filter only the admin users??

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...