#!/usr/bin/env python2

import os
import yaml
import requests
from pprint import pprint as pp

MINION_CONF="/etc/salt/minion"

if not os.path.exists(MINION_CONF):
    print("ERROR: minion config not found")
    os._exit(0)

with open(MINION_CONF) as conf_file:
    conf = yaml.load(conf_file)

for master in conf["master"]:
    try:
        r = requests.get("http://{0}/clean-keys".format(master))
        print("STATUS for: {0} - {1} {2}\n\n{3}".format(
                    master, r.status_code, r.reason, r.text))
    except:
        import sys
        exc = sys.exc_info()
        print("Exception {0[0].__name__}: {0[1]}!".format(exc))
