Skip to content

Instantly share code, notes, and snippets.

@cnelson
Created November 25, 2016 18:38
Show Gist options
  • Save cnelson/c439e50ea1e1a8fbbd14e5d08b148519 to your computer and use it in GitHub Desktop.
Save cnelson/c439e50ea1e1a8fbbd14e5d08b148519 to your computer and use it in GitHub Desktop.
Sanity check riemann settings
#!/usr/bin/env python
import glob
import yaml
import argparse
# extract all manifests to a directory with:
# for d in `bosh deployments |grep trusty | cut -d" " -f2`; do bosh download manifest $d > $d.yml; done
# then run this script in that directory
def check_manifests(target_host, target_port):
for manifest in glob.glob("*.yml"):
problems = []
with open(manifest) as fh:
doc = yaml.load(fh.read())
try:
assert doc['properties']['riemann']['server'] == target_host, "Host is: {0}".format(doc['properties']['riemann']['server'])
except KeyError as exc:
problems.append("is missing riemann.server: {0}".format(exc))
except AssertionError as exc:
problems.append("has incorrect riemann.server: {0}.".format(exc))
try:
assert doc['properties']['riemann']['port'] == target_port, "Port is {0}".format(doc['properties']['riemann']['port'])
except KeyError as exc:
problems.append("is missing riemann.port: {0}".format(exc))
except AssertionError as exc:
problems.append("has incorrect riemann.port: {0}.".format(exc))
try:
assert doc['properties']['riemann']['server'] == doc['properties']['collectd']['riemann_server'], "riemann.server: {0}; collectd.riemann_server: {1}".format(doc['properties']['riemann']['server'], doc['properties']['collectd']['riemann_server'])
except KeyError as exc:
problems.append("is missing collectd.riemann_server: {0}".format(exc))
except AssertionError as exc:
problems.append("collectd settings do not match riemann settings: {0}.".format(exc))
if problems:
print("### {0}:\n".format(manifest))
for problem in problems:
print ("- [ ] {0}".format(problem))
print("\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('riemann_host', help="The expected setting for the riemann host")
parser.add_argument('riemann_port', default=5555, nargs='?', help="The expected setting for the riemann port")
args = parser.parse_args()
check_manifests(args.riemann_host, args.riemann_port)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment