Created
December 15, 2014 17:52
-
-
Save exit99/72cc78ea735c60fff89e to your computer and use it in GitHub Desktop.
Running python scripts with postfix
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
# Be sure to chmod +x | |
#!/usr/bin/env python | |
import email | |
import json | |
import sys | |
import requests | |
def walk(stdin_data): | |
"""Prepend alert to all parts of the message.""" | |
root_message = email.message_from_string(stdin_data) | |
if root_message.is_multipart(): | |
for payload in root_message.get_payload(): | |
body = payload.get_payload() | |
break | |
else: | |
body = root_message.get_payload() | |
email_header = root_message.walk().next() | |
subject = str(email_header['Subject']) | |
from_email = str(email_header['From']) | |
data = {'subject': subject, 'body': body, 'from': from_email} | |
url = 'http://intranet.hivelocity.net/qa/forwarding/' | |
headers = {'content-type': 'application/json'} | |
r = requests.post(url, data=json.dumps(data), headers=headers) | |
# For debugging | |
f = open('/tmp/ids_logs.txt', 'a') | |
f.write(str(r)) | |
f.close() | |
def main(): | |
stdin_data = sys.stdin.read() | |
walk(stdin_data) | |
if __name__ == '__main__': | |
main() |
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
# See man 5 aliases for format | |
postmaster: root | |
cool: "|/var/scripts/cool_script.py" | |
sweet: "|/var/scripts/sweet_script.py" |
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
[email protected] from_cool | |
[email protected] from_sweet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment