Zabbix는 WeChat 알람 기능을 구현합니다.
1. 기업 위챗 계정 신청, 신청 주소 https://qy.weixin.qq.com/
2. 기업 위챗 계정에 로그인하세요
사진 1
사진 2
2. 위챗 계정 추가
사진 1
사진 2
위 단계를 완료하면 WeChat 계정이 추가됩니다
3. 새 애플리케이션 만들기
사진 1
사진 2
사진 3
사진 4
위 4장의 사진이 완성되면 애플리케이션 생성이 완료됩니다
4. 권한 관리 설정
사진 1
사진 2
사진 3
위 3장의 사진을 완성하시면 이제 권한 관리 설정이 완료되었습니다!
5. Zabbix 서버 구성
사진 1
사진 2
사진 3
위 세 그림의 구성을 완료하면 zabbix 서버 구성이 완료됩니다.
7. Weixin.py 프로그램 콘텐츠
#!/usr/bin/env python # encoding: utf-8 # Create time 2016-10-08 #Auth chenpeng import urllib2 import json import sys import time class WebChat(object): def __init__(self,CropID,Secret): self.CropID = CropID self.Secret = Secret def Get_Token(self,info): ''' :param info: 存储执行结果和执行程序状态码code (0代表执行成功,非零表示不成功) :return: ''' self.info = info gurl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s" % (self.CropID,self.Secret) try: #通过Get方式获取token req = urllib2.Request(gurl) response = urllib2.urlopen(req) g_result = json.loads(response.read(),"UTF-8") if g_result .has_key('access_token'): self.info['result']= g_result ['access_token'] self.info['code'] = 0 else: self.info['result'] = g_result self.info['code'] = 1 except Exception,e: self.info['code'] = 1 self.info['result'] = e def Send_Msg(self,touser,toparty,agentid,access_token,content,info,*args,**kwargs): ''' 发送信息到微信 :param touser: 部门成员id,zabbix中定义的微信接收者, 成员ID列表(消息接收者,多个接收者用‘|'分隔,最多支持1000个)。 特殊情况:指定为@all,则向关注该企业应用的全部成员发送 :param toparty: 部门id,定义了范围,组内成员都可接收到消息, 部门ID列表,多个接收者用‘|'分隔,最多支持100个。当touser为@all时忽略本参数 :param agentid: 企业应用的id,整型。可在应用的设置页面查看 :param access_token: 根据CropID,Secret获取的访问token值 :param content: 滤出zabbix传递的第三个参数, 表示发送微信消息的内容消息内容,最长不超过2048个字节, 注意:主页型应用推送的文本消息在微信端最多只显示20个字(包含中英文) :param info: 返回执行结果信息{'result':None,'code':None};'code':0或者非零 ;0表示成功 非零表示失败 :param args: :param kwargs: :return: ''' self.touser = touser self.toparty = toparty self.agentid = agentid self.conntent = content self.access_token = access_token self.info = info purl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % (access_token) data = { "touser": "", "toparty": "", "totag": "", #标签ID列表,多个接收者用‘|'分隔,最多支持100个。当touser为@all时忽略本参数,非必须 "msgtype": "text", #必须 "agentid": "", #必须 "text": { "content": "" #必须 }, "safe": "0" # 表示是否是保密消息,0表示否,1表示是,默认0 } data['touser'] = self.touser data['agentid'] = self.agentid data['toparty'] = self.toparty data['text']['content']=self.conntent data = json.dumps(data,ensure_ascii=False) try: #通过PUT方式获取发送数据 req = urllib2.Request(purl, data) response = urllib2.urlopen(req) res = json.loads(response.read()) self.info['code'] = res['errcode'] self.info['result'] = res['errmsg'] except Exception,e: self.info['result'] = e self.info['code'] = 1 if __name__ == '__main__': reload(sys) sys.setdefaultencoding('utf-8') def log(date, touser, content,info): ''' 发送的日志打印日志 :param date: 时间 :param touser: 发送给谁 :param content: 发送的信息内容 :param info: 发送执行的结果 :return: ''' msg = '%s %s %s 发送结果 - %s\n' % (date, touser, content, info) with open('msg.log', 'a') as f: f.write(msg) agentid = sys.argv[1] #agentid = 1 touser = 'xxxxxxx@qq.com' toparty = '' content = sys.argv[2:] content = '\n'.join(content) #content = '测试' CropID = 'xxxxxxxxxxxxxxxxxxx' Secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' info={'result':None,'code':None} date = time.strftime('%Y-%m-%d %H:%M:%S') res=WebChat(CropID,Secret) res.Get_Token(info) if info['code'] == 0: access_token = info['result'] res.Send_Msg(touser=touser, toparty=toparty, agentid=agentid, access_token=access_token, content=content,info=info) if info['code'] == 0: content = eval(content) log(date, touser, content,info) else: log(date, touser, content, info) else: log(date,touser,content,info)
코드 114, 115행의 CropID와 Secret은 4단계 "권한 관리 설정"의 그림 3에 해당하는 CropID와 Secret에 해당합니다.
코드 63행의 데이터는 WeChat 인터페이스 문서를 참조하세요
주소: http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3% E8%AF%B4%E6%98%8E
위 내용은 편집자가 소개한 Zabbix의 WeChat 알람 기능 구현입니다. 궁금한 점이 있으면 메시지를 남겨주시면 편집자가 시간에 맞춰 답변해 드리겠습니다. 또한 Script House 웹사이트를 지원해 주시는 모든 분들께 감사의 말씀을 전하고 싶습니다!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











Linux 터미널에서 Python 버전을 보려고 할 때 Linux 터미널에서 Python 버전을 볼 때 권한 문제에 대한 솔루션 ... Python을 입력하십시오 ...

10 시간 이내에 컴퓨터 초보자 프로그래밍 기본 사항을 가르치는 방법은 무엇입니까? 컴퓨터 초보자에게 프로그래밍 지식을 가르치는 데 10 시간 밖에 걸리지 않는다면 무엇을 가르치기로 선택 하시겠습니까?

Fiddlerevery Where를 사용할 때 Man-in-the-Middle Reading에 Fiddlereverywhere를 사용할 때 감지되는 방법 ...

Python의 Pandas 라이브러리를 사용할 때는 구조가 다른 두 데이터 프레임 사이에서 전체 열을 복사하는 방법이 일반적인 문제입니다. 두 개의 dats가 있다고 가정 해

Uvicorn은 HTTP 요청을 어떻게 지속적으로 듣습니까? Uvicorn은 ASGI를 기반으로 한 가벼운 웹 서버입니다. 핵심 기능 중 하나는 HTTP 요청을 듣고 진행하는 것입니다 ...

파이썬에서 문자열을 통해 객체를 동적으로 생성하고 메소드를 호출하는 방법은 무엇입니까? 특히 구성 또는 실행 해야하는 경우 일반적인 프로그래밍 요구 사항입니다.

Linux 터미널에서 Python 사용 ...
