Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hipchat support #324

Merged
merged 6 commits into from
Dec 6, 2017
Merged

hipchat support #324

merged 6 commits into from
Dec 6, 2017

Conversation

wleese
Copy link
Contributor

@wleese wleese commented Dec 1, 2017

Messages will be posted to the provided room id.
Users will be 'mentioned', enabling them to receive their alerts.

#321

Known issue: currently the iris username is used as the hipchat username when sending alerts. I'll make this configurable once I understand how the hipchat username field can be stored in Oncall.

Copy link
Member

@jrgp jrgp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks solid. Just a few changes and it should be good to merge. Thanks for adding tests.

self.notification_url = '{0}/v2/room/{1}/notification'.format(self.endpoint_url, self.room_id)
self.headers = {
'Content-type': 'application/json',
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slight nitpick: can you put the closing brace on the same level of indention as self.headers?

def send_message(self, message):
start = time.time()
payload = ujson.dumps(self.get_message_payload(message))
logger.info('tmpdebug msg: %s', ujson.dumps(message))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove or move this logger.info to the if self.debug section, or take it out of the PR and just leave it uncommitted for local testing (what we do in this situation)

'notify': 'true',
'message_format': "text",
}
return self.message_dict
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably should avoid setting message_dict as a property of the class, and just return it.

that way the function becomes pure and doesn't modify external state (makes testing cleaner and more reproducible) and won't ever cause problems if we decide to call the same vendor object more than once concurrently

response = requests.post(self.notification_url,
headers=self.headers,
params=self.params,
data=payload,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can avoid manually making the json string and passing it to data= and instead just do json=payload and it will encode in json for you

# -*- coding:utf-8 -*-

from iris.vendors.iris_hipchat import iris_hipchat
import ujson as json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this json import probably can be removed as it isn't used anywhere in this file

wleese and others added 2 commits December 1, 2017 21:16
- do json handling in request call
- make message_dict local
- cleanups
start = time.time()
payload = self.get_message_payload(message)
if self.debug:
logger.info('debug: %s', self.message_dict)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think self.message_dict here should be payload?



class iris_hipchat(object):
supports = frozenset(['hipchat'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a HIPCHAT_SUPPORT = 'hipchat' to constants.py and use that here and in the iris.constants import above?

fix flake8 tests

Change-Id: Iee64ccf07aee39a7b0aa72d5e6e89e1ae643eb1b
@wleese
Copy link
Contributor Author

wleese commented Dec 6, 2017

All comments addressed and tests fixed.

@jrgp jrgp merged commit a73b8c8 into linkedin:master Dec 6, 2017
@jrgp
Copy link
Member

jrgp commented Dec 6, 2017

Thanks!

@jrgp
Copy link
Member

jrgp commented Dec 6, 2017

Whoops meant to squash rather than rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants