Created
January 12, 2016 18:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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