Skip to content

Instantly share code, notes, and snippets.

@agramajo
Last active March 23, 2019 03:27
Show Gist options
  • Save agramajo/68b68f96a6188ff68867a4b746a78685 to your computer and use it in GitHub Desktop.
Save agramajo/68b68f96a6188ff68867a4b746a78685 to your computer and use it in GitHub Desktop.
Xymon slack integration
import os
import json
import urllib2
url = 'https://hooks.slack.com/services/COMPLETE_ENDPOINT_HERE'
channel = '#servers'
server = os.environ.get('BBHOSTNAME')
color = os.environ.get('BBCOLORLEVEL')
msg = os.environ.get('BBALPHAMSG')
if color == 'red':
emoji = ':broken_heart:'
elif color == 'yellow':
emoji = ':yellow_heart:'
elif color == 'purple':
emoji = ':purple_heart:'
elif color == 'green':
emoji = ':green_heart:'
else:
emoji = ':ghost:'
msg = server + ' ' + color + '\n' + msg
data = {
'channel': channel,
'username': 'webhookbot',
'text': msg,
'icon_emoji': emoji
}
req = urllib2.Request(url)
response = urllib2.urlopen(req,'payload='+json.dumps(data))
@agramajo
Copy link
Author

agramajo commented May 10, 2016

HOST=* 
  SCRIPT /etc/hobbit/slack_xymon.py blah FORMAT=PLAIN REPEAT=1d RECOVERED

Alerts file config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment