因为每个公司的电话通知服务的接口规范不一定一致,所有我们提供了一种shell的发送的方式,将告警事件交给可执行文件,这个可执行文件可以将告警信息发送给自己公司的电话通知接口,用法如下
#在uic.yml中 sender.voice.way 设置为 shell
sender:
voice:
# two choice: shell|api
way: shell
worker: 10
api: http://127.0.0.1:8000/voice
在 ecmc-uic 所在的目录创建 script 目录,然后在 script 目录中创建一个名为 send_voice 的可执行文件
uic 在需要发送电话告警的时候,会调用 send_voice ,并将告警接收人的手机号作为第一个参数,告警内容作为第二个参数传给 send_voice,send_voice 要实现的功能是调用自己公司的电话通知接口将告警内容发给告警接收人
send_voice 可以是脚本,也可以是二进制,下面是 send_voice 一个实现举例
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import urllib2
import sys
if len(sys.argv) != 3:
print "args illegal"
exit(0)
tos = sys.argv[1] #第一个参数,告警接收人的手机号,多个告警接收人以逗号分隔
message = sys.argv[2] #告警内容
tos = tos.split(",")
url = "http://xxxxxx.com/api/send/voice"
item = {}
item["app"] = "std"
item["tos"] = tos
item["content"] = {"msg": message}
req = urllib2.Request(url=url, data=json.dumps(item),headers={"Content-Type": "application/json"})
resp = urllib2.urlopen(req)
resp = resp.read()
print resp