今日格言:不要质疑你的付出,这些都会是一种累积一种沉淀,它们会默默铺路,只为让你成为更优秀的人。
在运维过程中经常遇到类似的问题:在局域网没有互联网的情况下,如何实现告警?
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报文需根据接口规范进行配置。
如有疑问,欢迎留言交流!