Skip to content

Commit

Permalink
Merge pull request #141 from kelseyfix/strong
Browse files Browse the repository at this point in the history
Adding StrongPOC integration for hermes-notify
  • Loading branch information
diggyk committed Feb 17, 2016
2 parents 9bfa7f9 + 2b085ae commit 4ed8672
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 10 deletions.
31 changes: 28 additions & 3 deletions bin/hermes-notify
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ def main():
except Exception as e:
logging.error("Failed to get host owners: " + e.message)

strongpoc_contacts = None
if settings.strongpoc_server:
# get the contact information
try:
results = PluginHelper.request_get(
path = "/api/pocs/?expand=teams&expand=service_providers&expand=contact_types&service_provider__name=hermes&contact_type__name=email",
server = settings.strongpoc_server
)
strongpoc_results = results.json()
strongpoc_contacts = {}
for result in strongpoc_results:
strongpoc_contacts[result['team']['name']] = result['value']
except Exception as e:
logging.error("Failed to get strongpoc contacts: " + e.message)

# get the tags for hosts
try:
results = PluginHelper.request_post(
Expand Down Expand Up @@ -118,9 +133,19 @@ def main():
plain_msg = generate_plain_mesg(info, open_quests, owner, tags)
html_msg = generate_html_mesg(info, open_quests, owner, tags)

recipient = args.send_to if args.send_to else "{}@{}".format(
owner, settings.domain
)
# send to strongPOC specified email, otherwise send to owner@domainname
if strongpoc_contacts and owner in strongpoc_contacts:
recipient = strongpoc_contacts[owner]
else:
recipient = "{}@{}".format(
owner, settings.domain
)

# always send email to args.send_to if defined
if args.send_to:
logging.debug('Overriding {} recipient for owner {}'.format(recipient, owner))
recipient = args.send_to
logging.debug('Sending email to {}'.format(recipient))

email_message(
recipient,
Expand Down
12 changes: 11 additions & 1 deletion config/dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ auth_token_expiry: 600
# plugin_dir:

# Specify the org identifier for FullStory integration
# fullstory_id:
# fullstory_id:

# StrongPOC integration (optional)
# strongpoc_server:

# Specify the environment - dev is default, set to prod for production
# environment: "dev"

# if environment is dev, send emails to the following email address instead
# of actual recipients
# dev_email_recipient:
1 change: 1 addition & 0 deletions hermes/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,5 @@ def __getattr__(self, name):
"environment": "dev",
"dev_email_recipient": "",
"fullstory_id": None,
"strongpoc_server": None,
})
19 changes: 15 additions & 4 deletions hermes/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def email_message(recipients, subject, message, html_message=None, cc=None):
message: the content of the email we wish to send
recipients: the email address to whom we wish to send the email
"""

if not settings.email_notifications:
return

Expand Down Expand Up @@ -149,32 +150,42 @@ def email_message(recipients, subject, message, html_message=None, cc=None):

class PluginHelper(object):
@classmethod
def request_get(cls, path="", params={}):
def request_get(cls, path="", params={}, server=None):
"""Make an HTTP GET request for the given path
Args:
path: the full path to the resource
params: the query parameters to send
server: the server to talk to, default is query_server
Returns:
the http response
"""
response = requests.get(settings.query_server + path, params=params)

if not server:
server = settings.query_server

response = requests.get(server + path, params=params)

return response

@classmethod
def request_post(cls, path="", params={}, json_body={}):
def request_post(cls, path="", params={}, json_body={}, server=None):
"""Make an HTTP POST request for the given path
Args:
path: the full path to the resource
params: the query params to send
json_body: the body of the message in JSON format
server: the server to talk to, default is query_server
Returns:
the http response
"""

if not server:
server = settings.query_server

response = requests.post(
settings.query_server + path, params=params, json=json_body
server + path, params=params, json=json_body
)

return response
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.13"
__version__ = "0.7.18"
3 changes: 2 additions & 1 deletion hermes/webapp/src/css/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -1196,4 +1196,5 @@ a {
-moz-box-shadow: 0 0 5px 5px @med-gray;
box-shadow: 0 0 5px 5px @med-gray;
}
}
}

0 comments on commit 4ed8672

Please sign in to comment.