1.去官网下载SDK
https://help.aliyun.com/document_detail/55359.html?spm=a2c4g.11186623.2.16.759c6e44LcTbZS
2.解压安装
注意目录
root@XXServer2:/usr/local/lib/python2.7/dist-packages/dysms_python# python setup.py install
3.编写脚本
在原有基础上进行修改即可
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from aliyunsdkdysmsapi.request.v20170525 import SendSmsRequest
from aliyunsdkdysmsapi.request.v20170525 import QuerySendDetailsRequest
from aliyunsdkcore.client import AcsClient
import uuid
from aliyunsdkcore.profile import region_provider
from aliyunsdkcore.http import method_type as MT
from aliyunsdkcore.http import format_type as FT
import json
"""
短信业务调用接口示例,版本号:v20170525
Created on 2017-06-12
"""
try:
reload(sys)
sys.setdefaultencoding('utf8')
except NameError:
pass
except Exception as err:
raise err
# 注意:不要更改
REGION = "cn-hangzhou"
PRODUCT_NAME = "Dysmsapi"
DOMAIN = "dysmsapi.aliyuncs.com"
ACCESS_KEY_ID = "这里写id"
ACCESS_KEY_SECRET = "这里写key"
acs_client = AcsClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET, REGION)
region_provider.add_endpoint(PRODUCT_NAME, REGION, DOMAIN)
def send_sms(business_id, phone_numbers, sign_name, template_code, template_param=None):
smsRequest = SendSmsRequest.SendSmsRequest()
# 申请的短信模板编码,必填
smsRequest.set_TemplateCode(template_code)
# 短信模板变量参数
if template_param is not None:
smsRequest.set_TemplateParam(template_param)
# 设置业务请求流水号,必填。
smsRequest.set_OutId(business_id)
# 短信签名
smsRequest.set_SignName(sign_name)
# 数据提交方式
# smsRequest.set_method(MT.POST)
# 数据提交格式
# smsRequest.set_accept_format(FT.JSON)
# 短信发送的号码列表,必填。
smsRequest.set_PhoneNumbers(phone_numbers)
# 调用短信发送接口,返回json
smsResponse = acs_client.do_action_with_exception(smsRequest)
# TODO 业务处理
return smsResponse
if __name__ == '__main__':
__business_id = uuid.uuid1()
#print(__business_id)
SENDTO = str(sys.argv[1]) #从zabbix传递的手机参数
message = str(sys.argv[2]) #从zabbix传递的报警信息
params = {"message":message}
params = json.dumps(params)
#params = u'{"name":"wqb","code":"12345678","address":"bz","phone":"13000000000"}'
print(send_sms(__business_id, SENDTO, "这里写签名名称", "这里写模板code", params))
3.web配置
报警类型配置
image.png
报警联系人配置,写上手机号
image.png
报警动作配置
image.png
这个参考邮件报警即可
网友评论