Last active
May 1, 2019 13:47
-
-
Save sudipidus/ca3eecf79ba1c6718a7728c614c1ef60 to your computer and use it in GitHub Desktop.
This is a simple python script to trigger a slack web hook. It can be triggerred by piping linux commands or by passing arguments. (Messages are delivered to the configured slack channel)
This file contains hidden or 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/python | |
import requests as r | |
import json | |
import sys | |
web_hook='' # slack web hook url | |
def send_message(msg): | |
payload={'text':msg} | |
one_man_army_hook=webhook | |
headers= {'Content-type': 'application/json'} | |
response=r.post(one_man_army_hook, data=json.dumps(payload), headers=headers) | |
print(response.text) | |
if __name__ == "__main__": | |
message = sys.argv[1:] | |
print("console message is {}".format(message)) | |
if not message: | |
message=sys.stdin.readlines() | |
print("stdin message is {}".format(message)) | |
send_message(' '.join(message)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment