zabbix使用短信告警高效、快捷,本次做个记录
一、zabbix服务器安装
https://blog.csdn.net/oToyix/article/details/106853849
二、zabbix服务器安装“阿里短信SDK核心库”
这里要先安装python3.6,及配置pip3
yum install python3
pip3 install --default-timeout=1000 aliyun-python-sdk-core-v3
三、阿里云申请“短信签名”名“短信模板”
异常通知模板
恢复通知模板
四、创建异常告警及恢复通知脚本
1、告警脚本
[root@ecs-a71b ~]# cd /usr/local/zabbix/share/zabbix/alertscripts/
[root@ecs-a71b alertscripts]# vim sendSMS.py
#!/usr/bin/python3
#coding=utf-8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import sys
client = AcsClient('accessKeyId ', 'accessKeySecret ', 'cn-hangzhou') 改这里
request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dysmsapi.aliyuncs.com')
request.set_method('POST')
request.set_protocol_type('https') # https | http
request.set_version('2017-05-25')
request.set_action_name('SendSms')
string = sys.argv[2]
phone_number = sys.argv[1]
message = string.split(";")
print(message)
dict1 = { }
dict1['host'] = message[0]
dict1['time'] = message[1]
dict1['item'] = message[2][0:18]
request.add_query_param('RegionId', 'cn-hangzhou')
request.add_query_param('PhoneNumbers', phone_number)
request.add_query_param('SignName', '短信签名名称') 改这里
request.add_query_param('TemplateCode', '短信模板Code') 改这里,共3个位置即可
request.add_query_param('TemplateParam', dict1)
response = client.do_action(request)
# python2: print(response)
print(str(response, encoding='utf-8'))
2、恢复通知脚本
同上
[root@ecs-a71b alertscripts]# vim sendSMS_retore.py
#!/usr/bin/python3
#coding=utf-8
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
import sys
client = AcsClient('accessKeyId', 'accessKeySecret', 'cn-hangzhou') 改这里
request = CommonRequest()
request.set_accept_format('json')
request.set_domain('dysmsapi.aliyuncs.com')
request.set_method('POST')
request.set_protocol_type('https') # https | http
request.set_version('2017-05-25')
request.set_action_name('SendSms')
string = sys.argv[2]
phone_number = sys.argv[1]
message = string.split(";")
print(message)
dict1 = { }
dict1['host'] = message[0]
dict1['time'] = message[1]
dict1['item'] = message[2][0:18]
request.add_query_param('RegionId', 'cn-hangzhou')
request.add_query_param('PhoneNumbers', phone_number)
request.add_query_param('SignName', '短信签名名称') 改这里
request.add_query_param('TemplateCode', '短信模板Code') 改这里
request.add_query_param('TemplateParam', dict1)
response = client.do_action(request)
# python2: print(response)
print(str(response, encoding='utf-8'))
五、服务器短信配置
1、报警媒介类型
2、管理-用户 (异常告警用户)
3、管理-用户 (恢复告警用户)
新建一个群组adminsy
管理-用户(新建一个用户)
如果就有了两个报警媒介
4、创建触发器
省略。。。。。。
5、创建动作
省略。。。。。。
六、短信测试
------------------------------------end