zabbix 配置wechat告警
生活随笔
收集整理的這篇文章主要介紹了
zabbix 配置wechat告警
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
描述:由于現在移動端的使用已經是一個必備,而且微信的使用更加流行,如下是介紹zabbix實現微信告警的結合
1、注冊免費的企業微信號
企業微信
2、創建企業應用并記錄agentld和secret
?
3、記錄企業信息號
?
4、準備python環境
5、在zabbix告警目錄下提供相應的腳本sendtowechat.py,并賦予執行權限
#!/usr/local/python3/bin/python3 # -*- coding:utf-8 -*- import requests import json import sys # 企業號及應用相關信息 corp_id = 'xxxxxxx' corp_secret = 'xxxxxxx' agent_id = xxxxxx # 存放access_token文件路徑 file_path = '/tmp/access_token.log'def get_access_token_from_file(): try: f = open(file_path,'r+') this_access_token = f.read() print('get success %s' % this_access_token) f.close() return this_access_token except Exception as e: print(e)# 獲取token函數,文本里記錄的token失效時調用 def get_access_token(): get_token_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s' % (corp_id, corp_secret) print(get_token_url) r = requests.get(get_token_url) request_json = r.json() this_access_token = request_json['access_token'] print(this_access_token) r.close() # 把獲取到的access_token寫入文本 try: f = open(file_path,'w+') f.write(this_access_token) f.close() except Exception as e: print(e)# 返回獲取到的access_token值 return this_access_token# sendMessage # 死循環,直到消息成功發送 flag = True while(flag): # 從文本獲取access_token access_token = get_access_token_from_file() try: to_user = '@all' message = sys.argv[3] send_message_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s' % access_token print(send_message_url) message_params = { "touser":to_user, "msgtype":"text", "agentid":agent_id, "text":{ "content" : message }, "safe":0 } r = requests.post(send_message_url, data=json.dumps(message_params)) print('post success %s ' % r.text) # 判斷是否發送成功,如不成功則跑出異常,讓其執行異常處理里的函數 request_json = r.json() errmsg = request_json['errmsg'] if errmsg != 'ok': raise # 消息成功發送,停止死循環 flag = False except Exception as e: print(e) access_token = get_access_token()
6、修改zabbix web的告警設置(create media type)
參數解釋:
{ALTER.SENDTO} # 發送給誰,該參數在郵件告警中有作用,但微信告警中沒有
{ALTER.SUBJECT} # 告警標題,該參數在郵件告警中有作用,但微信告警中沒有
{ALTER.MESSAGE} # 告警內容,在微信告警中有用
7、修改告警內容
8、企業微信號里添加成員
?
9、在zabbix web的管理賬戶中添加相應有media
?
10、在手機端下載“企業微信”的APP,并進行告警測試結果
?
?
?
?
轉載于:https://www.cnblogs.com/reid21/articles/8398953.html
總結
以上是生活随笔為你收集整理的zabbix 配置wechat告警的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: gdb调试caffe工程
- 下一篇: 合成模式(Composite)