สอบถามหน่อยครับ พอดีทำตัวเช็ค Server Status ผ่านโปรแกรม PYTHON โดยแจ้งเตือนผ่านไลน์
ถ้าจะมีข้อความกำกับด้วย (ABC) ประมาณนี้ต้องไปเพิ่มตรงไหนเหรอครับ
192.168.0.1 (ABC) ====>UP
192.168.0.2 (DEF) ====>UP
import requests
import os
import schedule
import time
import response
hostname = ['192.168.1.6','192.168.1.7','192.168.1.8','192.168.1.9']
def checkNetwork(hostname):
response = os.popen("ping " + hostname).read()
if (("unreachable") or ("Request time out")) in response:
notifyNetwork(hostname,'=====> Down')
pingstatus = 'Network Down'
else:
notifyNetwork(hostname,'=====> UP')
pingstatus = 'Network UP'
return pingstatus
def notifyNetwork(hostname,status):
token="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
uri="
https://notify-api.line.me/api/notify"
header = {"Authorization":"Bearer "+token}
msg={"message":"SERVER "+hostname+" "+status}
resp= requests.post(uri,headers=header,data=msg)
for TEST in hostname:
print(checkNetwork(TEST))
สอบถามการเขียนโปรแกรมภาษา Python หน่อยครับ
ถ้าจะมีข้อความกำกับด้วย (ABC) ประมาณนี้ต้องไปเพิ่มตรงไหนเหรอครับ
192.168.0.1 (ABC) ====>UP
192.168.0.2 (DEF) ====>UP
import requests
import os
import schedule
import time
import response
hostname = ['192.168.1.6','192.168.1.7','192.168.1.8','192.168.1.9']
def checkNetwork(hostname):
response = os.popen("ping " + hostname).read()
if (("unreachable") or ("Request time out")) in response:
notifyNetwork(hostname,'=====> Down')
pingstatus = 'Network Down'
else:
notifyNetwork(hostname,'=====> UP')
pingstatus = 'Network UP'
return pingstatus
def notifyNetwork(hostname,status):
token="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
uri="https://notify-api.line.me/api/notify"
header = {"Authorization":"Bearer "+token}
msg={"message":"SERVER "+hostname+" "+status}
resp= requests.post(uri,headers=header,data=msg)
for TEST in hostname:
print(checkNetwork(TEST))