Skip to content

Commit

Permalink
Merge pull request #97 from diggyk/master
Browse files Browse the repository at this point in the history
Give a critical warning if the due date is within 5 days
  • Loading branch information
jathanism committed Dec 4, 2015
2 parents 7523299 + 58a6433 commit e774323
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions bin/hermes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ from __future__ import division

import argparse
from dateutil import parser, tz
from datetime import datetime
import getpass
import logging
import requests
Expand Down Expand Up @@ -483,6 +484,8 @@ def list_host_labors_monitoring(args):
logging.debug("list_host_labors_monitoring(%s)", args.hostname)

alert = False
critical = False

try:
response = request_get(
"/api/v1/labors/"
Expand All @@ -498,6 +501,15 @@ def list_host_labors_monitoring(args):
for labor in labors:
if labor['creationEvent']['eventType']['state'] == "required":
alert = True
# determin if critical
if labor['quest']['targetTime']:
target_time = parser.parse(labor['quest']['targetTime'], yearfirst=True)
target_time = target_time.replace(tzinfo=tz.tzlocal())
target_time = target_time.astimezone(tz.tzutc())
target_time = target_time.replace(tzinfo=None)
time_left = target_time - datetime.now()
if time_left.days <= 5:
critical = True

except HermesException as exc:
# FIXME -- add error codes to Hermes API and test for that
Expand All @@ -521,7 +533,8 @@ def list_host_labors_monitoring(args):
fates = response.json()["fates"]

if alert:
print "WARNING: {} open labor{} for this host".format(
print "{}: {} open labor{} for this host".format(
"CRIT" if critical else "WARNING",
len(labors),
"s" if len(labors) > 1 else ""
)
Expand All @@ -531,7 +544,10 @@ def list_host_labors_monitoring(args):
print ""
print "For more details, login to shelby and run:"
print "hermes host labors {}".format(args.hostname)
sys.exit(1)
if critical:
sys.exit(2)
else:
sys.exit(1)
else:
print "OK: No open labors for this host"
sys.exit(0)
Expand Down
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6"
__version__ = "0.6.1"

0 comments on commit e774323

Please sign in to comment.