[sysadmin-bin] Land a script that should help identifying GitLab inactive users



commit eb0e18e9a752322d5e9c6ae56d5b7c32612d5465
Author: Andrea Veri <averi redhat com>
Date:   Wed Mar 20 23:01:53 2019 +0100

    Land a script that should help identifying GitLab inactive users
    
    1. Look for the last_activity_on flag and see whether it's None
    2. Make sure the e-mail address of the user is not part of the whitelisted addresses
    3. Double check whether the created_at and last_sign_in_at fields match (it'd mean the user
       never accessed the account after originally creating it)
    4. Make sure we exclude accounts matching all the 3 conditions but were created during the
       past 3 months

 gitlab/inactive-gitlab-users.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
---
diff --git a/gitlab/inactive-gitlab-users.py b/gitlab/inactive-gitlab-users.py
new file mode 100755
index 0000000..ded6500
--- /dev/null
+++ b/gitlab/inactive-gitlab-users.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+import dateutil.relativedelta as relativedelta
+import datetime as dt
+import gitlab
+
+execfile('/home/admin/secret/gitlab_rw')
+gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RW_TOKEN, api_version=4)
+
+users = gl.users.list(all=True, per_page=100)
+today = dt.date.today()
+timedelta = relativedelta.relativedelta(months=3)
+
+whitelist = ['debian', 'ubuntu', 'redhat',
+             'canonical', 'suse', 'fedoraproject',
+             'gnome']
+
+print 'username,email,id,created_at,last_sign_in_at'
+
+for user in users:
+    for index, _ in enumerate(user.attributes['identities']):
+        if user.attributes['identities'][index]['provider'] != 'ldapmain':
+            if user.attributes['last_activity_on'] == None:
+                if user.attributes['email'].split('@')[1].split('.')[-2] not in whitelist:
+                    if user.attributes['created_at'].split('T')[0] == 
user.attributes['last_sign_in_at'].split('T')[0]:
+                        if dt.datetime.strptime(user.attributes['created_at'].split('T')[0], 
'%Y-%m-%d').date() < (today - timedelta):
+                            print user.attributes['username'] + ',' + user.attributes['email'] + ',' + 
str(user.attributes['id']) + ',' + user.attributes['created_at'].split('T')[0] + ',' + 
user.attributes['last_sign_in_at'].split('T')[0]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]