Created
July 24, 2017 11:27
-
-
Save pravsripad/461eea62024efeb11240789936b86f8b to your computer and use it in GitHub Desktop.
Telegram Alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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