今日格言:不要質疑你的付出,這些都會是一種累積一種沉澱,它們會默默鋪路,只爲讓你成爲更優秀的人。
在運維過程中經常遇到類似的問題:在局域網沒有互聯網的情況下,如何實現告警?
zabbix監控的目的就是爲了提前預警,如果異常信息無法通知到人,那監控的作用就相當於0
但是實際生產環境中,大多都會提供短信接口,或者短信機,以下是舉例使用python對接短信接口webservice的方法
python中 Suds模塊是一個輕量級的基於SOAP的python客戶端,它基於LGPL許可。
1、引用初始化
>>> from suds.client import Client
>>> url= "http://192.168.142.10:8000/request?wsdl"
>>> headers={'Content-Type':'application/soap+xml;charset="UTF-8"'}
>>> client = Client(url,headers=headers,faults=False,timeout=15)
>>> print client
Suds ( https://fedorahosted.org/suds/ ) version: 0.3.8 GA build: R627-20091217
Service ( RequestImplService ) tns="http://service.test.com/"
Prefixes (1)
ns0 = "http://service.test.com/"
Ports (1):
(RequestImplPort)
Methods (1):
synRequest(xs:string msg, )
Types (2):
synRequest
synRequestResponse
通過打印client信息,可以查看到接口對應的方法以及需要傳入的參數、類型,聲明瞭什麼信息等
2、方法調用
url= "http://192.168.142.10:8000/request?wsdl"
xmlData = '''
<?xml version="1.0" encoding="UTF-8"?>
<Request>
<SenderId>TEST.SEND.ID</SenderId>
<ServiceId>TEST.SEND.DXJK</ServiceId>
<Inputs>
<Input name="phoneNumbers" type="string">15988888888</Input>
<Input name="smsContent" type="string">I Love Python</Input>
</Inputs>
</Request>
'''
headers={'Content-Type':'application/soap+xml;charset="UTF-8"'}
client = Client(url,headers=headers,faults=False,timeout=15)
#print client # 打印接口信息,可查看對應的方法
xml_result=client.service.synRequest(xmlData)
xml報文需根據接口規範進行配置。
如有疑問,歡迎留言交流!