Skip to content

Instantly share code, notes, and snippets.

@pravsripad
Created July 24, 2017 11:27
Show Gist options
  • Save pravsripad/461eea62024efeb11240789936b86f8b to your computer and use it in GitHub Desktop.
Save pravsripad/461eea62024efeb11240789936b86f8b to your computer and use it in GitHub Desktop.
Telegram Alert
#!/usr/bin/env python
'''
Script to send alerts/messages to telegram.
e.g. ssh login alerts etc.
'''
import sys
import yaml
import telepot
# config file with telegram TOKEN and chat id.
with open('/home/user/.my_config.yaml', 'r') as myfile:
uconfig = yaml.load(myfile)
# pass message as argument to python script
message = sys.argv[1]
TOKEN = uconfig['TOKEN']
chat_id = uconfig['my_chat_id']
if __name__ == "__main__":
# initialize the bot
bot = telepot.Bot(TOKEN)
# send the alert
bot.sendMessage(chat_id, message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment