Skip to content

Commit

Permalink
Merge pull request #16 from diggyk/master
Browse files Browse the repository at this point in the history
Added support for pinging in the hermes client
  • Loading branch information
gmjosack committed Jun 18, 2015
2 parents ac68afa + b37f08f commit 1e14dfd
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions bin/hermes
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,24 @@ def request_post(path, json):
return response


def ping_server(args):
"""Ping the Hermes API server and ensure it responds. Return output
appropriate for a Nagios-style monitoring service.
"""
try:
response = request_get("/api/v1/eventtypes?limit=1")
except Exception as exc:
print "CRIT: Error in Hermes API server response"
print ""
traceback.print_exc(file=sys.stdout)
sys.exit(2)

print "OK: Hermes server seems ok"
print ""
print "Successfully ran a simple query against the Hermes API"
sys.exit(0)


def print_labor(labor, fates):
"""Print the details of a labor to standard out
Expand All @@ -117,16 +135,18 @@ def print_labor(labor, fates):
else:
target_time_str = ""

print "[{}] {}: \n\tcreated on {} {} \n\tby event {} {} {}".format(
print "[{}] {}: \n\tcreated on {} {} \n\tby event {} {}".format(
labor["id"],
labor["host"]["hostname"],
creation_time,
target_time_str,
labor["creationEvent"]["eventType"]["category"],
labor["creationEvent"]["eventType"]["state"],
labor["creationEvent"]["note"] or ""
labor["creationEvent"]["eventType"]["state"]
)

if labor["creationEvent"]["note"]:
print "\tNote: \"{}\"".format(labor["creationEvent"]["note"])

if labor.get("questId", None):
print "\n\tPart of Quest [{}] created by {}".format(
labor["quest"]["id"],
Expand Down Expand Up @@ -457,6 +477,7 @@ def list_host_labors_monitoring(args):
print "OK: No open labors for this host"
sys.exit(0)


def list_labors(args):
logging.debug("list_labors()")

Expand Down Expand Up @@ -879,6 +900,12 @@ def parse_cli_args():
)
event_create_parser.set_defaults(func=create_event)

# monitoring ping command line parser
ping_parser = subparsers.add_parser(
"ping", help="Perform a ping of the Hermes API server"
)
ping_parser.set_defaults(func=ping_server)

# quest command line parser
quest_parser = subparsers.add_parser(
"quest", help="Create and list Quests"
Expand Down

0 comments on commit 1e14dfd

Please sign in to comment.