Skip to content

Instantly share code, notes, and snippets.

@JayH5
Created October 19, 2015 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayH5/7defc91c98babc228cca to your computer and use it in GitHub Desktop.
Save JayH5/7defc91c98babc228cca to your computer and use it in GitHub Desktop.
#! /usr/bin/python
# Check that all the apps in Marathon are stored as services in Consul.
import requests
HOST = '10.1.1.13'
CONSUL_PORT = 8500
MARATHON_PORT = 8080
def get_marathon_app_ids(host, port):
response = requests.get('http://%s:%s/v2/apps' % (host, port))
apps = response.json()['apps']
return sorted([app['id'].lstrip('/') for app in apps])
def is_consular_service(tags):
return any([tag.startswith('consular-') for tag in tags])
def get_consul_services(host, port):
response = requests.get('http://%s:%s/v1/catalog/services' % (host, port))
services = response.json()
return [name for name, tags in services.items()
if is_consular_service(tags)]
def diff(lhs, lhs_name, rhs, rhs_name):
missing = 0
for item in lhs:
if item not in rhs:
missing += 1
print('"%s" is present in %s but not %s' % (
item, lhs_name, rhs_name))
print('%d items found in %s that were not in %s' % (
missing, lhs_name, rhs_name))
print('Fetching Marathon apps...')
marathon = get_marathon_app_ids(HOST, MARATHON_PORT)
print('Found %d Marathon apps' % len(marathon))
print('Fetching Consul services...')
consul = get_consul_services(HOST, CONSUL_PORT)
print('Found %d Consul services started by Consular' % len(consul))
diff(marathon, 'marathon', consul, 'consul')
print
diff(consul, 'consul', marathon, 'marathon')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment