Last active
December 17, 2016 19:37
-
-
Save tete2soja/65d789944bbcf01fe4a8f1392384744d to your computer and use it in GitHub Desktop.
slack_headphones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SLACKER(object): | |
def notify(self, message, status) | |
if not headphones.CONFIG.SLACK_ENABLED: | |
return | |
import requests | |
SLACK_URL = headphones.CONFIG.SLACK_URL | |
channel = headphones.CONFIG.SLACK_CHANNEL | |
emoji = headphones.CONFIG.SLACK_EMOJI | |
payload = { 'channel': channel, 'text': status + ': ' + message} | |
try: | |
response = requests.post(SLACK_URL, json=payload) | |
except Exception, e: | |
logger.info(u'Slack notify failed: ' + str(e)) | |
sent_successfuly = True | |
if not response.status_code == 200 | |
logger.info(u'Could not send notification to Slack. Response: [%s]', (response.text)) | |
sent_successfuly = False | |
logger.info(u"Slack notifications sent.") | |
return sent_successfuly |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment