theme: cyanosis
highlight: atelier-plateau-dark
短信报警
101
cd /apps/zabbix_server/share/zabbix/alertscripts/
发送短信脚本(需要去注册、如yunpian.com、阿里等等) ``` vim linux01_sms.sh
!/bin/bash
PHONE=$1 MESSAGE=$3
curl -X "POST" "https://sms.yunpian.com/v2/sms/singlesend.json" \ -H "content-type: application/x-www-form-urlencoded" \ -d "apikey=4d6cxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ -d "mobile=${PHONE}" \ -d "text=${MESSAGE}" 添加执行权限
chmod a+x linux01sms.sh ```
新建或调用旧的
106
停止服务 /apps/nginx/sbin/nginx -s stop
微信报警
101
apt install -y python-pip
pip install requests
``` cd /apps/zabbix_server/share/zabbix/alertscripts
vim linux01_weixin.py
!/usr/bin/env python
coding:utf-8
Author:Sun
import requests import sys import os import json import logging
logging.basicConfig(level = logging.DEBUG, format = '%(asctime)s, %(filename)s, %(levelname)s, %(message)s', datefmt = '%a, %d %b %Y %H:%M:%S', filename = os.path.join('/tmp','weixin.log'), filemode = 'a')
corpid='ww70037de833b51f04' <--企业ID(我的企业-企业信息-企业ID) appsecret="YC9NPWG4xGWPoK0YRK5HTNygXnH9IcEdOI5WoWiO6I8" 秘钥<--(应用管理-短信故障通知-Secret) agentid="1000002" <--AgentID(应用管理-短信故障通知-AgentID) tokenurl='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + appsecret req=requests.get(tokenurl) accesstoken=req.json()['access_token']
msgsendurl='https://qyapi.weixin.qq.com/cgi-bin/message/send?accesstoken=' + accesstoken touser=sys.argv[1] subject=sys.argv[2] message=sys.argv[2] + "\n\n" +sys.argv[3]
params={ "touser": touser, "msgtype": "text", "agentid": agentid, "text": { "content": message }, "safe":0 }
req=requests.post(msgsend_url, data=json.dumps(params)) logging.info('sendto:' + touser + ';;subject:' + subject + ';;message:' + message) ```
chmod a+x linux01_weixin.py
{ALERT.SENDTO} #发送给谁
{ALERT.SUBJECT} #发送的标题
{ALERT.MESSAGE} #发送的内容
106
/apps/nginx/sbin/nginx -s stop