แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python
Moderator: mindphp , ผู้ดูแลกระดาน
saovarott159
PHP Newbie
โพสต์: 4 ลงทะเบียนเมื่อ: 23/04/2015 3:19 pm
โพสต์ที่ยังไม่ได้อ่าน
โดย saovarott159 » 29/03/2023 9:47 am
สวัสดีครับ ขออนุญาติสอบถาม 2 เรื่อง หน่อยครับ
1. พอดีทำตัวเช็ค Server Status ผ่านโปรแกรม PYTHON
อยากทราบว่า อยากให้แจ้งเตือน Server Status ทุกตัว (ในข้อความเดียวถ้าทำได้ ณ.ตอนนี้แจ้งเตือน IP ละบรรทัด)
2. อยากให้ถ้าสถานะแจ้งเตือนเป็น DOWN ให้ตัวอักษรเป็นสีแดงได้ไหมครับ
ตัวอย่างประมาณนี้ครับ ให้แสดง server ทุกตัวในข้อความเดียว
ServerStatus: ORGANIZE
192.168.1.6 =====> UP
192.168.1.7 =====> UP
192.168.1.8 =====> UP
192.168.1.9 =====>
DOWN
--------------------------------------------------------
โค้ด: เลือกทั้งหมด
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))
nuattawoot
PHP VIP Members
โพสต์: 2561 ลงทะเบียนเมื่อ: 05/06/2017 9:34 am
โพสต์ที่ยังไม่ได้อ่าน
โดย nuattawoot » 29/03/2023 1:44 pm
1. checkNetwork แล้วเก็บค่าใส่ตัวแปลให้เสร็จก่อน แล้วค้อยส่งครั้งเดียว
loop ข้อมูลออกมาแล้วจัดชุดข้อความ แล้วใส่ \n ต่อท้ายข้อความที่ต้องการขึ้นบรรทัดใหม่
payload = {'message' : 'My message\nTest1\nTest2' ,'notificationDisabled' : True}
'192.168.1.6 =====> UP\n192.168.1.7 =====> UP\n192.168.1.8 =====> UP\n192.168.1.9 =====> DOWN'
First Bug Love you
saovarott159
PHP Newbie
โพสต์: 4 ลงทะเบียนเมื่อ: 23/04/2015 3:19 pm
โพสต์ที่ยังไม่ได้อ่าน
โดย saovarott159 » 29/03/2023 2:08 pm
nuattawoot เขียน: ↑ 29/03/2023 1:44 pm
1. checkNetwork แล้วเก็บค่าใส่ตัวแปลให้เสร็จก่อน แล้วค้อยส่งครั้งเดียว
loop ข้อมูลออกมาแล้วจัดชุดข้อความ แล้วใส่ \n ต่อท้ายข้อความที่ต้องการขึ้นบรรทัดใหม่
payload = {'message' : 'My message\nTest1\nTest2' ,'notificationDisabled' : True}
'192.168.1.6 =====> UP\n192.168.1.7 =====> UP\n192.168.1.8 =====> UP\n192.168.1.9 =====> DOWN'
ขอบคุณมากๆครับผม
รบกวนขอ code เลยได้ไหมครับพี่ เดี๋ยวได้แล้วจะมาศึกษาต่อ
พอดีความรู้เรื่องภาษาของโปรแกรมเมอร์ไม่เกิน10% เลยครับผม
nuattawoot
PHP VIP Members
โพสต์: 2561 ลงทะเบียนเมื่อ: 05/06/2017 9:34 am
โพสต์ที่ยังไม่ได้อ่าน
โดย nuattawoot » 29/03/2023 2:40 pm
โค้ด: เลือกทั้งหมด
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 = hostname+' =====> Network Down\n'
else:
# notifyNetwork(hostname,'=====> UP')
pingstatus = hostname+' =====> Network UP\n'
return pingstatus
def notifyNetwork(msgs):
token="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
uri="https://notify-api.line.me/api/notify"
header = {"Authorization":"Bearer "+token}
msg={"message":"\nSERVER Status \n"+msgs}
resp= requests.post(uri,headers=header,data=msg)
message = ''
for TEST in hostname:
print(TEST)
message += checkNetwork(TEST)
notifyNetwork(message)
2023-03-29 14_38_46-.png (7.35 KiB) Viewed 2304 times
First Bug Love you
saovarott159
PHP Newbie
โพสต์: 4 ลงทะเบียนเมื่อ: 23/04/2015 3:19 pm
โพสต์ที่ยังไม่ได้อ่าน
โดย saovarott159 » 29/03/2023 2:57 pm
nuattawoot เขียน: ↑ 29/03/2023 2:40 pm
โค้ด: เลือกทั้งหมด
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 = hostname+' =====> Network Down\n'
else:
# notifyNetwork(hostname,'=====> UP')
pingstatus = hostname+' =====> Network UP\n'
return pingstatus
def notifyNetwork(msgs):
token="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
uri="https://notify-api.line.me/api/notify"
header = {"Authorization":"Bearer "+token}
msg={"message":"\nSERVER Status \n"+msgs}
resp= requests.post(uri,headers=header,data=msg)
message = ''
for TEST in hostname:
print(TEST)
message += checkNetwork(TEST)
notifyNetwork(message)
2023-03-29 14_38_46-.png
ขอบคุณครับผม
0 ตอบกลับ
4282 แสดง
โพสต์ล่าสุด โดย Jom07
06/03/2018 3:17 pm
9 ตอบกลับ
6250 แสดง
โพสต์ล่าสุด โดย jirawoot
21/06/2019 10:07 am
สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 35