短信报警、微信报警(小节10)


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 ```

图片.png

图片.png

图片.png

图片.png

图片.png

新建或调用旧的 图片.png

图片.png

图片.png

图片.png

106

停止服务 /apps/nginx/sbin/nginx -s stop

图片.png

微信报警

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 图片.png

{ALERT.SENDTO} #发送给谁

{ALERT.SUBJECT} #发送的标题

{ALERT.MESSAGE} #发送的内容 图片.png

图片.png

图片.png

图片.png

图片.png

图片.png

图片.png

106

/apps/nginx/sbin/nginx -s stop

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值