#!/usr/bin/python # -*- coding: utf-8 -*- import requests import json import sys import time reload(sys) sys.setdefaultencoding( "utf-8" ) date_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) tmp_date_time=time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())) tmp_date=time.strftime('%Y-%m-%d',time.localtime(time.time())) tmp_time=time.strftime('%H:%M:%S',time.localtime(time.time())) f=open("/opt/matrix/agent/bin/alert_cmd/send_sms.log", "a+") data1=sys.argv[1] data2=sys.argv[2] #hjson1= json.loads(data1.decode('utf-8')) hjson1= json.loads(data1) ipaddress=hjson1['netgate']['address'] port=hjson1['netgate']['port'] protocol=hjson1['netgate']['protocol'] brNo=hjson1['netgate']['brNo'] chanNo=hjson1['netgate']['chanNo'] srvId=hjson1['netgate']['srvId'] svcId=hjson1['netgate']['svcId'] print(hjson1['jdbc']['driver']) #hjson2= json.loads(data2.decode('utf-8')) hjson2= json.loads(data2) #f.write(date_time+" "+hjson1+" "+hjson2+"\n") for msg in hjson2: message=msg['msg'] for names in msg['to']: touser=names['mobile'] #url=protocol+'://'+ipaddress+':'+port+'/' url=protocol+'://'+str(ipaddress)+':'+str(port)+'/' body='' \ '' \ '' \ ''+tmp_date+'' \ ''+tmp_time+'' \ ''+svcId+'' \ '' \ '' \ ''+srvId+'' \ ''+chanNo+'' \ ''+brNo+'' \ ''+touser+'' \ ''+message+'' \ ''+tmp_date_time+'' \ 'null' \ 'null' \ '' \ '' #r = requests.post(url,data=body.decode("gbk").encode("utf-8")) r = requests.post(url,data=body.encode("utf-8")) #f.write(date_time+" "+url+" "+body+"\n") f.write(date_time+" "+touser+" "+message+r.text+"\n") #f.write(date_time+" "+touser+" "+message+"\n") f.close() #print(hjson1)