python監控介面請求

來源:互聯網
上載者:User

標籤:out   int   env   xxx   ons   pos   python   elf   man   

 1 #!/usr/bin/env python 2 #coding=utf8 3 import time,os,sched,urllib,httplib 4 import smtplib 5 import string 6  7 schedule = sched.scheduler(time.time, time.sleep) 8 def perform_command(self, inc): 9     schedule.enter(inc, 0, perform_command, (self, inc))10     #os.system(cmd)11     monitoring(self)12 def timming_exe(self, inc = 60):13     schedule.enter(inc, 0, perform_command, (self, inc))14     schedule.run()15 16 def monitoring(self):17     print("開始監控...")18     httpClient = None19     try:20         params = urllib.urlencode({‘name‘: ‘tom‘, ‘age‘: 22})21         headers = {"Content-type": "application/x-www-form-urlencoded"22                     , "Accept": "text/plain"}23  24         httpClient = httplib.HTTPConnection("2xx.x9.2x1.x", 8800, timeout=30)25         httpClient.request("POST", "/path/pathxxxxxxx", params, headers)26  27         response = httpClient.getresponse()28         print (response.status)29         print (response.reason)30         #print response.read()31         #print response.getheaders() #擷取頭資訊32         33         if response.status == 200:34             print (u"正常")35         else:36             print (u"異常")37             sendmsg38             print ‘郵件已發送....‘39     except Exception,e:40         print e          41     finally:42         if httpClient:43             httpClient.close()44 45 def sendmsg():    46     FROM="xxx.com"47     TO="xxx.com"48     PASS="xxx"49     HOST="smtp.sina.com"50     PORT="25"51     SUBJECT="Interface alarm "52     TEXT="The alarm information !"53     BODY= string.join((54             "From: %s" % FROM,55             "To: %s" % TO,56             "Subject: %s" % SUBJECT,57             "",58             TEXT59     ), "\r\n")60     server=smtplib.SMTP()61     server.connect(HOST,"25")62     server.login(FROM,PASS)63     server.sendmail(FROM,TO,BODY)64     server.quit()65         66 print("服務監控>>> 一分鐘後開始執行(每10秒):")67 timming_exe("echo %time%", 10)

 

python監控介面請求

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.