script to alert when your servers are down via sms and telegram message

This commit is contained in:
prince 2018-10-03 11:31:58 +05:30
parent f28d94eb11
commit 0f0f649a81
2 changed files with 51 additions and 0 deletions

View 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
View 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>