Skip to content

Instantly share code, notes, and snippets.

@tete2soja
Last active December 17, 2016 19:37
Show Gist options
  • Save tete2soja/65d789944bbcf01fe4a8f1392384744d to your computer and use it in GitHub Desktop.
Save tete2soja/65d789944bbcf01fe4a8f1392384744d to your computer and use it in GitHub Desktop.
slack_headphones
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