Skip to content

Instantly share code, notes, and snippets.

@mapledyne
Created January 12, 2016 18:14
Show Gist options
  • Select an option

  • Save mapledyne/9acf8761a9ce182922ad to your computer and use it in GitHub Desktop.

Select an option

Save mapledyne/9acf8761a9ce182922ad to your computer and use it in GitHub Desktop.
Nagios check file to check for MFA use with users in our org
#!/usr/bin/python
import sys
import commands
import json
def update():
"""Return list of users without MFA, or an OK status."""
status, data = commands.getstatusoutput("curl -s -H \"Authorization: token YOUR_GITHUB_TOKEN\" https://api.github.com/orgs/ORG_NAME/members?filter=2fa_disabled")
# Data indexes can now be accessed
data = json.loads(data)
user_number = 0
user_list = ""
for i in data:
if (i["login"] != "EXCLUDED_USER1" and
i["login"] != "EXCLUDED_USER2" and
i["login"] != "EXCLUDED_USER3"):
user_number += 1
user_list += i["login"]
user_list += ", "
# Get rid of that last comma
user_list = user_list[:-2]
user_list = str(user_number) + ": " + user_list
if user_number == 0:
return 0, "All is right with the world! All users have MFA."
else:
if len(user_list) < 145:
return 1, user_list
else:
user_list = user_list[:145] + "..."
return 1, user_list
ret, ret_msg = update()
print ret_msg
sys.exit(ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment