Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import os
- import sys
- from optparse import OptionParser
- import subprocess
- def match_users(marathon_url, auth_user, auth_pass, app_type):
- print('\nUsing URL {} cross check app - {} for active users\n'.format(marathon_url, app_type))
- apps = requests.get(marathon_url, auth=(auth_user, auth_pass)).json()["apps"]
- for app in apps:
- labels = app.get('labels')
- id = app.get('id')
- if id and app_type in id:
- if labels and labels.get('user'):
- user = labels['user']
- env_user = subprocess.check_output(["sudo getent passwd {0} | cut -d ':' -f 5".format(user)],
- shell=True)
- if env_user:
- print("{} - {}".format(user, env_user))
- else:
- print("{0} - Not Found\n".format(user))
- if __name__ == '__main__':
- usage = "usage: python sandbox_users_check.py --marathon_url=marathon_url_for_apps --auth_user=man_username --auth_pass=password --app_type=sandbox"
- parser = OptionParser(usage=usage)
- parser.add_option("--marathon_url",
- dest="url",
- action="store",
- help="path the the marathon (sandbox) applications")
- parser.add_option("-u", "--auth_user",
- dest="auth_user",
- action="store",
- help="username to authenticate with")
- parser.add_option("-p", "--auth_pass",
- dest="auth_pass",
- action="store",
- help="password to authenticate with")
- parser.add_option("--app_type",
- dest="app_type",
- action="store",
- help="type of app to check for; example and default: sandbox")
- (options, args) = parser.parse_args()
- marathon_url = options.url
- auth_user = options.auth_user
- auth_pass = options.auth_pass
- app_type = options.app_type
- if not marathon_url:
- print "MARATHON url is mandatory"
- sys.exit(1)
- elif not auth_user:
- print "authentication username is mandatory"
- sys.exit(1)
- elif not auth_pass:
- print "authentication password is mandatory"
- sys.exit(1)
- elif not app_type:
- app_type = 'sandbox' # default app to look for
- match_users(marathon_url, auth_user, auth_pass, app_type)
- sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement