Skip to content

Commit

Permalink
Merge pull request #110 from diggyk/host_tags
Browse files Browse the repository at this point in the history
Display host tags on Quests page and CLI quest show
  • Loading branch information
jathanism committed Dec 10, 2015
2 parents 1843f6f + 68dd6cd commit 44de7a6
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 134 deletions.
106 changes: 81 additions & 25 deletions bin/hermes
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ def request_post(path, json):
)

if (
response.status_code != requests.codes.created
response.status_code not in (
requests.codes.created, requests.codes.ok
)
or not response.content
):
try:
data = response.json()["error"]["message"]
except Exception:
data = "Received invalid response: {}".format(response.content)
data = "Received invalid response: {} {}".format(
response.status_code, response.content
)
raise HermesException(
"Error: {}".format(data)
)
Expand Down Expand Up @@ -173,7 +177,7 @@ def ping_server(args):
sys.exit(0)


def print_labor(labor, fates):
def print_labor(labor, fates, verbose=False, tags=None):
"""Print the details of a labor to standard out
Args:
Expand All @@ -183,24 +187,33 @@ def print_labor(labor, fates):
creation_time = parser.parse(labor["creationTime"])
creation_time = creation_time.replace(tzinfo=tz.tzutc())
creation_time = creation_time.astimezone(tz.tzlocal())

print "({}) {}:".format(
labor["id"],
labor["host"]["hostname"]
)

if tags:
print "\tTags: {}\n".format(textwrap.fill(
", ".join(tags), width=30, subsequent_indent="\t "
))

if verbose:
print "\tCreated: {}".format(creation_time)

if labor.get("targetTime", None):
target_time = parser.parse(labor["targetTime"])
target_time = target_time.replace(tzinfo=tz.tzutc())
target_time = target_time.astimezone(tz.tzlocal())
target_time_str = "(due by {})".format(target_time)
else:
target_time_str = ""
print "\tDue by {}".format(target_time)

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"]
)
if verbose:
print "\tCreated by: {} {}".format(
labor["creationEvent"]["eventType"]["category"],
labor["creationEvent"]["eventType"]["state"]
)

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

if labor.get("questId", None):
Expand Down Expand Up @@ -494,28 +507,39 @@ def list_host_events(args):


def list_host_labors(args):
logging.debug("list_host_labors(%s)", args.hostname)
logging.debug(
"list_host_labors(%s, %s, %s)", args.hostname, args.verbose, args.tags
)

response = request_get(
"/api/v1/labors/"
"?open=true&expand=hosts&expand=eventtypes&expand=events"
"&expand=quests&limit={}&hostname={}".format(
args.limit,
args.hostname
)
"/api/v1/labors/"
"?open=true&expand=hosts&expand=eventtypes&expand=events"
"&expand=quests&limit={}&hostname={}".format(
args.limit,
args.hostname
)
)

labors = response.json()["labors"]
total_labors = response.json()["totalLabors"]

response = request_get("/api/v1/fates?limit=all&expand=eventtypes")
fates = response.json()["fates"]

if args.tags:
json = {
"hostnames": [args.hostname],
"operation": "tags"
}

response = request_post("/api/v1/extquery", json)
tags = response.json()["results"][args.hostname]

print "OPEN LABORS FOR {} ({} of {}):".format(
args.hostname, len(labors), total_labors
)
for labor in labors:
print_labor(labor, fates)
print_labor(labor, fates, args.verbose, tags)


def list_host_labors_monitoring(args):
Expand Down Expand Up @@ -610,9 +634,25 @@ def list_labors(args):
response = request_get("/api/v1/fates?limit=all&expand=eventtypes")
fates = response.json()["fates"]

tags = None
if args.tags:
hostnames = []
for labor in labors:
hostnames.append(labor["host"]["hostname"])
json = {
"hostnames": hostnames,
"operation": "tags"
}

response = request_post("/api/v1/extquery", json)
tags = response.json()["results"]

print "OPEN LABORS ({} of {}):".format(len(labors), total_labors)
for labor in labors:
print_labor(labor, fates)
print_labor(
labor, fates, args.verbose,
tags[labor["host"]["hostname"]] if tags else None
)


def create_event(args):
Expand Down Expand Up @@ -922,7 +962,7 @@ def parse_cli_args():
"-s", "--server", dest="hermes_server"
)
parser.add_argument(
"-v", "--verbose", action="count", default=0,
"--debug", action="count", default=0,
help="Increase logging verbosity."
)
parser.add_argument(
Expand Down Expand Up @@ -1038,6 +1078,14 @@ def parse_cli_args():
"-l", "--limit", default=20, type=int,
help="Limit the number of labors displayed"
)
host_labors_parser.add_argument(
"-v", "--verbose", default=False, action="store_true",
help="Display verbose information"
)
host_labors_parser.add_argument(
"--tags", default=False, action="store_true",
help="Show host tags"
)
host_labors_parser.set_defaults(func=list_host_labors)

# Host monitoring plugin output
Expand All @@ -1064,6 +1112,14 @@ def parse_cli_args():
"--user", type=str,
help="Query for hosts by user responsible"
)
labor_list_parser.add_argument(
"-v", "--verbose", default=False, action="store_true",
help="Display verbose information"
)
labor_list_parser.add_argument(
"--tags", default=False, action="store_true",
help="Show host tags"
)
labor_list_parser.set_defaults(func=list_labors)

# EVENTS COMMANDS
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.7.2"
__version__ = "0.7.3"
45 changes: 35 additions & 10 deletions hermes/webapp/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ a {
-webkit-border-radius: 5px;
border-radius: 5px;
cursor: pointer;
margin-bottom: 1px;
margin-bottom: 4px;
padding: 2px 15px;
transition: 0.15s ease-out all;
-webkit-transition: 0.15s ease-out all;
Expand All @@ -476,6 +476,7 @@ a {
-ms-transform: none;
-o-transform: none;
transform: none;
background: @unselected-color;
&:hover {
-webkit-box-shadow: 1px 1px 3px 0px @shadow-color;
-moz-box-shadow: 1px 1px 3px 0px @shadow-color;
Expand All @@ -486,17 +487,41 @@ a {
-o-transform: translate(-1px, -1px);
transform: translate(-1px, -1px);
}
}
.labor-entry.selected {
-moz-transition: 0.15s ease-in all;
-ms-transition: 0.15s ease-in all;
-o-transition: 0.15s ease-in all;
-webkit-transition: 0.15s ease-in all;
background: @selected-color;
transition: 0.15s ease-in all;
.details {
//background: @white;
//-moz-border-radius: 5px;
//-webkit-border-radius: 5px;
//border-radius: 5px;
//border: 1px solid @unselected-color;
//padding: 5px;
opacity: 0.5;
margin: 0 0 5px 0;
overflow: hidden;
ul {
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
display: block;
margin: 0px;
padding: 0px;
}
li {
display: inline-block;
margin-right: 5px;
padding: 0;
}
}
&.selected {
-moz-transition: 0.15s ease-in all;
-ms-transition: 0.15s ease-in all;
-o-transition: 0.15s ease-in all;
-webkit-transition: 0.15s ease-in all;
background: @selected-color;
transition: 0.15s ease-in all;
}
}
.owner-group {
margin-bottom: 5px;
margin-bottom: 10px;
.type-group {
//padding-bottom: 5px;
//padding-left: 15px;
Expand Down

0 comments on commit 44de7a6

Please sign in to comment.