diff --git a/conf/zabbix_agentd.conf b/conf/zabbix_agentd.conf index f5921d5..92bef3d 100644 --- a/conf/zabbix_agentd.conf +++ b/conf/zabbix_agentd.conf @@ -110,7 +110,7 @@ LogFile=/tmp/zabbix_agentd.log # Default: # Server= -Server=127.0.0.1 +#Server=127.0.0.1 ### Option: ListenPort # Agent will listen on this port for connections from the server. @@ -135,7 +135,7 @@ Server=127.0.0.1 # Mandatory: no # Range: 0-100 # Default: -# StartAgents=3 +StartAgents=0 ##### Active checks related @@ -164,7 +164,7 @@ Server=127.0.0.1 # Default: # ServerActive= -ServerActive=127.0.0.1 +ServerActive=192.168.3.24 ### Option: Hostname # List of comma delimited unique, case sensitive hostnames. @@ -235,7 +235,7 @@ Hostname=Zabbix server # Mandatory: no # Range: 1-86400 # Default: -# RefreshActiveChecks=5 +RefreshActiveChecks=120 ### Option: BufferSend # Do not keep data longer than N seconds in buffer. diff --git a/src/wechat.py b/src/wechat.py new file mode 100644 index 0000000..c3dc32e --- /dev/null +++ b/src/wechat.py @@ -0,0 +1,51 @@ +#!/usr/bin/python3 +#_*_coding:utf-8 _*_ +import urllib.request +import json +import sys + +def gettoken(corpid,corpsecret): + gettoken_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + corpid + '&corpsecret=' + corpsecret + print (gettoken_url) + try: + token_file = urllib.request.urlopen(gettoken_url) + except urllib.error.HTTPError as e: + print (e.code) + print (e.read().decode("utf8")) + sys.exit() + token_data = token_file.read().decode('utf-8') + token_json = json.loads(token_data) + token_json.keys() + token = token_json['access_token'] + return token + +def senddata(access_token,user,subject,content): + + send_url = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + access_token + send_values = { + "touser":"$1", + "toparty":"2", + "msgtype":"text", + "agentid":"1000002", + "text":{ + "content":subject + '\n' + content + }, + "safe":"0" + } +# send_data = json.dumps(send_values, ensure_ascii=False) + send_data = json.dumps(send_values, ensure_ascii=False).encode('utf-8') + send_request = urllib.request.Request(send_url, send_data) + response = urllib.request.urlopen(send_request) + msg = response.read() + print ("returned value : " + str(msg)) + + +if __name__ == '__main__': + user = str(sys.argv[1]) + subject = str(sys.argv[2]) + content = str(sys.argv[3]) + + corpid = 'ww07d639f4db857c16' + corpsecret = 'gTBUceozR5SQLStDeEdKN2bWJYLF2jlzk4zoCn_8I34' + accesstoken = gettoken(corpid,corpsecret) + senddata(accesstoken,user,subject,content) \ No newline at end of file