힙챗(Hipchat)과 슬랙(Slack)은 요즘 많이 사용하는 IRC 대체 도구들이다. 이 도구들은 일정량 혹은 기능들들은 무료로 사용가능하다. 특정 프로젝트를 도와주고 있고, 커뮤니케이션 도구의 통합이 필요해보였다. 또한, 서비스 운영상의 알림들을 여기로 통합할 필요가 있었다. Slack 에서는 RESTful APIs 를 공개하고 있고, 이를 구현한 구현체 또한 많다. 이걸 사용하게 되면 Zabbix 에서 알림을 받을 수 있다.
이미 공개된 스크립트(https://github.com/ericoc/zabbix-slack-alertscript)가 있긴한데 인코딩 및 개행문자의 버그가 있어 직접 스크립트를 작성했다. 고작 몇줄…
As you know, many start-ups and people use free services such as HipChat or Slack to communicate with others. Recently I helped some project to integrate their communication channels. They wanted to integrate slack and monitoring systems such as Zabbix as well.
I have discovered that open source script(https://github.com/ericoc/zabbix-slack-alertscript) has some bug include encoding, literal problems. So, I wrote a few codes to alert message to Zabbix. It helps you if you want to integrate slack and Zabbix.
Pre Requirements
* Zabbix
* Python
* Slacker (https://github.com/os/slacker)
Install
1. Get api-key from Slack
1) Move to http://api.slack.com
2) “Create token” That’s it.
2. Save the script
vim /usr/lib/zabbix/alertscripts/zabbix-slack.sh
#!/usr/bin/python # -*- coding: utf-8 -*- """ Zabbix Slack Alert Script """ import sys from slacker import Slacker import datetime if __name__ == '__main__': if len(sys.argv) != 4: exit(1) recipient = sys.argv[1] subject = sys.argv[2] body = sys.argv[3] now = datetime.datetime.now() message = "-----------------------------------------\n\nDate : %s\nSubject: %s\n\n%s" % (now, subject, body) #print message slack = Slacker('slack-api-key') slack.chat.post_message('#general', message)
3. Configure on Zabbix
1) Administrator > Media types > Add
– Name : Slack Notification
– Type : script
– Script name : zabbix-slack.sh
2) Users > user > Media tab > Add
– Type : Slack Notification
– Send to : any
3) Triggers
Results
Image may be NSFW.
Clik here to view.
Clik here to view.
