Skip to content

Commit fc4a1a2

Browse files
author
Phil Rzewski
committed
Example script to list Admin users
1 parent ee61f33 commit fc4a1a2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

examples/list_admins.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python
2+
#
3+
# List all the Admin users in a Sysdig Monitor environment. The token you
4+
# provide must have Admin rights.
5+
# If you're running this script in an On-Premise install of Sysdig Montior,
6+
# the "super" Admin (the first Admin user that was created at initial
7+
# install) will be highlighted.
8+
#
9+
10+
import os
11+
import sys
12+
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), '..'))
13+
from sdcclient import SdcClient
14+
15+
#
16+
# Parse arguments
17+
#
18+
if len(sys.argv) != 2:
19+
print 'usage: %s <sysdig-token>' % sys.argv[0]
20+
print 'You can find your token at https://app.sysdigcloud.com/#/settings/user'
21+
print 'For this script to work, the user for the token must have Admin rights'
22+
sys.exit(1)
23+
24+
sdc_token = sys.argv[1]
25+
26+
#
27+
# Instantiate the SDC client
28+
#
29+
sdclient = SdcClient(sdc_token, 'https://app.sysdigcloud.com')
30+
31+
#
32+
# Get the configuration
33+
#
34+
res = sdclient.get_users()
35+
if res[0]:
36+
admins = []
37+
superadmins = []
38+
for user in res[1]:
39+
if 'ROLE_CUSTOMER' in user['roles']:
40+
admins.append(user['username'])
41+
if 'ROLE_ADMIN' in user['roles']:
42+
superadmins.append(user['username'])
43+
print 'Admin users'
44+
print '-----------'
45+
for username in admins:
46+
print username
47+
print '\nSuper Admins'
48+
print '------------'
49+
for username in superadmins:
50+
print username
51+
else:
52+
print res[1]
53+
sys.exit(1)

0 commit comments

Comments
 (0)