Skip to content

Instantly share code, notes, and snippets.

@jdiverp
Last active November 7, 2023 15:35
Show Gist options
  • Select an option

  • Save jdiverp/d5b2b59dc0acacf282ec531f7c6e181b to your computer and use it in GitHub Desktop.

Select an option

Save jdiverp/d5b2b59dc0acacf282ec531f7c6e181b to your computer and use it in GitHub Desktop.
SOD compliance report
#!/usr/bin/python
import fileinput, string, sys, re, httplib, json
import time, datetime, os
GWS_HOST = 'groups.uw.edu'
GWS_PORT = '443'
GWS_BASE = '/group_sws/v3'
KEY_FILE = '/usr/local/ssl/certs/email-compliance-report.cac.washington.edu.key'
CERT_FILE = '/usr/local/ssl/certs/email-compliance-report.cac.washington.edu.cert'
filename = '/home/iamidregreport/dentistry/sod_uforward.dat' # used for all three customers
sod_group = 'uw_son_people'
sod_group = 'uw_apl_email_users'
sod_group = 'uw_sod_all_users'
# Parse u_forwarding_file
forward_records = {}
for line in fileinput.input ( filename ):
columns = line.split('|')
forward_records[columns[0]] = columns[1].rstrip('\n')
#connect to groups
connection = httplib.HTTPSConnection(GWS_HOST, GWS_PORT, KEY_FILE, CERT_FILE)
METHOD = 'GET'
REQUEST = GWS_BASE + '/group/%s/effective_member' % sod_group
connection.request(METHOD, REQUEST)
response = connection.getresponse()
# print some headers so SON would know the data is fresh and our stuff isn't broken
# print some headers so APL would know the data is fresh and our stuff isn't broken
# print some headers so SOD would know the data is fresh and our stuff isn't broken
print 'From: https://'+GWS_HOST+REQUEST
print 'Group credential: email-compliance-report.cac.washington.edu'
print 'Report time: %s' % datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
print 'Forwarding data: %s' % datetime.datetime.fromtimestamp(os.stat(filename)[8])
print ''
if (response.status != 200):
print "\ncould not read group. response %s" % str(response.status)
sys.exit()
body = response.read()
groupsData = json.loads(body)
group_members = []
for value in groupsData["data"]:
if value["type"] == 'uwnetid':
group_members.append(value["id"])
for value in group_members:
print value+'|'+ forward_records.get(value, '')
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment