mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-27 14:01:09 +00:00
script to alert when your servers are down via sms and telegram message
This commit is contained in:
parent
f28d94eb11
commit
0f0f649a81
48
Ping_Server/Ping_server.py
Normal file
48
Ping_Server/Ping_server.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
'''TODOs
|
||||
more reliable and caching alert meethods (eg phone calls or sms)
|
||||
server resourses
|
||||
time taken to respond ping
|
||||
to know wheather gone down for sometime and come up after sometime
|
||||
'''
|
||||
from twilio.rest import Client
|
||||
from telethon import TelegramClient
|
||||
import requests
|
||||
from telethon.tl.types import InputPeerChat
|
||||
from telethon.tl.functions.messages import ImportChatInviteRequest
|
||||
#your telegram api_id & hash
|
||||
#for more details get from telethon
|
||||
def main():
|
||||
j
|
||||
api_id = #####
|
||||
api_hash = '######################'
|
||||
|
||||
# Your Account Sid and Auth Token from twilio.com/console
|
||||
account_sid = '###############'
|
||||
auth_token = '################'
|
||||
clients = Client(account_sid, auth_token)
|
||||
|
||||
|
||||
#telegram_Side
|
||||
client = TelegramClient('session_name', api_id, api_hash)
|
||||
client.start()
|
||||
#print(client.get_me().stringify())
|
||||
#updates = client(ImportChatInviteRequest('FDVzKw8BPHTp2wyhwNqT2Q'))
|
||||
siteList=[site_list]
|
||||
for i in siteList:
|
||||
print(i)
|
||||
r = requests.head(i)
|
||||
if r.status_code == 200:
|
||||
message=i +" returned 200"
|
||||
chat = InputPeerChat(chatID)
|
||||
client.send_message(chat, message)
|
||||
sms= clients.messages.create(to="#####",from_="##########",body="the "+i+" is not responding now ")
|
||||
call = clients.calls.create(url='http://demo.twilio.com/docs/voice.xml',to='############',from_='#############')
|
||||
print(call.sid)
|
||||
else:
|
||||
chat = InputPeerChat(chatID)
|
||||
message="oops " + i + " not available at the moment"
|
||||
client.send_message(chat, message)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
3
Ping_Server/README.md
Normal file
3
Ping_Server/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Ping_server
|
||||
/P>this is a pyhton script to ping your servers automatically and alert you with telegram messages or telephone call when you server are down or you can manipulate this logig based on diffrent http return status </p><br/>
|
||||
<p>you need to liitle configeration in telegram and twillio make it work</p>
|
Loading…
Reference in New Issue
Block a user