#!/usr/bin/python

import socket
import requests

try:
    result = requests.get('http://localhost:5050/master/redirect', timeout=10)
except:
    print 'CRITICAL: Unable to query the local Mesos master /master/redirect'
    exit(2)

if socket.gethostname() in result.url:
    try:
        result = requests.get('http://localhost:5050/roles.json', timeout=10)
    except:
        print 'Unable to get data from /roles.json endpoint'
        sys.exit(1)

    for role in result.json()['roles']:
        name = role['name']
        if name == "*":
            name = 'other'
        print 'role,name=%s weight=%f,cpus=%d,memory=%d,disk=%d' % (name, role['weight'], role['resources']['cpus'], role['resources']['mem'], role['resources']['disk'])
