zabbix微信报警
2016-08-17 18:09
375 查看
zabbix设置报警的方式可以有很多种,比如结合微信的企业号利用脚本报警,email实现报警,下面简单的介绍下微信企业号报警的方式。
1、首先注册账号,微信企业号官网链接: https://qy.weixin.qq.com/
2、选择属性
3、注册之后进行登陆
企业logo必须上传否则会出现错误,企业的相关的信心自己按照自己的情况进行填写。
4、进行联系人的添加
将上述内容进行填写,注意上面的账号就是一会在zabbix里面需要填写的接收人的账号,之后保存。
5、进行组的添加
6、添加好了组之后将刚刚创建的用户添加到组中去。
添加好了之后点解确定。添加好以后会生成一个相应的id和密码,如此图上面的底部位置所示(CorpID:****** Secret:******),此值会在发送信息的脚本中调用。之后就可以利用微信扫描企业号的二维码进行加关注。
7、创建新的应用
选择消息型,之后保存就好。
8、查看刚刚创建应用的ID
9、查看创建的组的管理id。
10、查看之后可以进行zabbix端的设置了。
多余的设置不在提供,如果不清楚报警设置,参考zabbix安装报警设置的博客。
11、weixin.py脚本提供
#!/usr/bin/env python
#coding: utf-8
import time
import urllib,urllib2
import json
import sys
'''
1 空
2 空
3 内容
'''
"""
touser否成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
toparty否部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
totag否标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
msgtype是消息类型,此时固定为:text
agentid是企业应用的id,整型。可在应用的设置页面查看
content是消息内容
safe否表示是否是保密消息,0表示否,1表示是,默认0
"""
# baseurl = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
# securl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s' % access_token
class WeChatMSG(object):
def __init__(self,content):
self.gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
self.gettoken_content = {
'corpid' : '*****',
'corpsecret' : '*********' ,
}
self.main_content = {
"toparty":"1", ------->应用ID号码
"agentid":"1", ------->所属部门ID号码
"msgtype": "text",
"text":{
"content":content,
}
}
def get_access_token(self,string):
token_result = json.loads(string.read())
access_token= token_result['access_token']
return access_token.encode('utf-8')
def geturl(self,url,data):
data = self.encodeurl(data)
response = urllib2.urlopen('%s?%s' % (url,data))
return response.read().decode('utf-8')
def posturl(self,url,data,isjson = True):
if isjson:
data = json.dumps(data)
response = urllib2.urlopen(url,data)
return response.read().decode('utf-8')
def encodeurl(self,dict):
data = ''
for k,v in dict.items():
data += '%s=%s%s' % (k,v,'&')
return data
if __name__ == '__main__':
if len(sys.argv) == 4:
touser,notuse,content = sys.argv[1:]
else:
print 'error segments, now exit'
sys.exit()
msgsender = WeChatMSG(content)
access_token_response = msgsender.geturl(msgsender.gettoken_url, msgsender.gettoken_content)
access_token = json.loads(access_token_response)['access_token']
sendmsg_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s' % access_token
print msgsender.posturl(sendmsg_url,msgsender.main_content)
之后可以进行测试调整了。
1、首先注册账号,微信企业号官网链接: https://qy.weixin.qq.com/
2、选择属性
3、注册之后进行登陆
企业logo必须上传否则会出现错误,企业的相关的信心自己按照自己的情况进行填写。
4、进行联系人的添加
将上述内容进行填写,注意上面的账号就是一会在zabbix里面需要填写的接收人的账号,之后保存。
5、进行组的添加
6、添加好了组之后将刚刚创建的用户添加到组中去。
添加好了之后点解确定。添加好以后会生成一个相应的id和密码,如此图上面的底部位置所示(CorpID:****** Secret:******),此值会在发送信息的脚本中调用。之后就可以利用微信扫描企业号的二维码进行加关注。
7、创建新的应用
选择消息型,之后保存就好。
8、查看刚刚创建应用的ID
9、查看创建的组的管理id。
10、查看之后可以进行zabbix端的设置了。
多余的设置不在提供,如果不清楚报警设置,参考zabbix安装报警设置的博客。
11、weixin.py脚本提供
#!/usr/bin/env python
#coding: utf-8
import time
import urllib,urllib2
import json
import sys
'''
1 空
2 空
3 内容
'''
"""
touser否成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送
toparty否部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
totag否标签ID列表,多个接收者用‘|’分隔。当touser为@all时忽略本参数
msgtype是消息类型,此时固定为:text
agentid是企业应用的id,整型。可在应用的设置页面查看
content是消息内容
safe否表示是否是保密消息,0表示否,1表示是,默认0
"""
# baseurl = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
# securl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s' % access_token
class WeChatMSG(object):
def __init__(self,content):
self.gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken'
self.gettoken_content = {
'corpid' : '*****',
'corpsecret' : '*********' ,
}
self.main_content = {
"toparty":"1", ------->应用ID号码
"agentid":"1", ------->所属部门ID号码
"msgtype": "text",
"text":{
"content":content,
}
}
def get_access_token(self,string):
token_result = json.loads(string.read())
access_token= token_result['access_token']
return access_token.encode('utf-8')
def geturl(self,url,data):
data = self.encodeurl(data)
response = urllib2.urlopen('%s?%s' % (url,data))
return response.read().decode('utf-8')
def posturl(self,url,data,isjson = True):
if isjson:
data = json.dumps(data)
response = urllib2.urlopen(url,data)
return response.read().decode('utf-8')
def encodeurl(self,dict):
data = ''
for k,v in dict.items():
data += '%s=%s%s' % (k,v,'&')
return data
if __name__ == '__main__':
if len(sys.argv) == 4:
touser,notuse,content = sys.argv[1:]
else:
print 'error segments, now exit'
sys.exit()
msgsender = WeChatMSG(content)
access_token_response = msgsender.geturl(msgsender.gettoken_url, msgsender.gettoken_content)
access_token = json.loads(access_token_response)['access_token']
sendmsg_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s' % access_token
print msgsender.posturl(sendmsg_url,msgsender.main_content)
之后可以进行测试调整了。
相关文章推荐
- zabbix配置微信报警
- Zabbix的两种报警方式--微信和E-mail(一)
- Zabbix实现微信报警功能
- Zabbix实现微信平台报警----基于zabbix3.0.4
- 关于Zabbix3版本发送微信报警配置
- zabbix如何实现微信报警
- zabbix微信报警
- zabbix使用微信报警(四)
- Zabbix报警脚本-微信
- Zabbix监控整合OneAlert报警平台实现邮件、短信、微信、电话多方式报警
- Zabbix的两种报警方式--微信和E-mail(二)
- zabbix------关于微信报警的尝试
- 给zabbix添加短信、微信、邮件报警
- zabbix报警媒介------>微信报警
- zabbix 通过微信(团体)企业号报警 简例
- zabbix调用微信报警
- zabbix微信报警(更新2017年6月)
- Linux的企业-Zabbix监控、nginx、邮箱微信报警(1)
- zabbix 3.0.2微信报警
- zabbix设置微信报警的配置过程