-
-
Save bugre/3e85315e329773a5519297ca7d522add to your computer and use it in GitHub Desktop.
A simple sample SMTP server to push Bamboo notification emails to Datadog's API
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
import asyncore | |
import email | |
import socket | |
from dogapi import dog_http_api as api | |
from smtpd import SMTPServer | |
class Server(SMTPServer): | |
def __init__(self, dd_api_keys, host="127.0.0.1", port=1125): | |
self.dd_api_keys = dd_api_keys | |
asyncore.dispatcher.__init__(self) | |
self.create_socket(socket.AF_INET, socket.SOCK_STREAM) | |
self.set_reuse_addr() | |
self.bind((host, port)) | |
self.listen(5) | |
def process_message(self, peer, sender, recipients, body): | |
api_key, app_key = self.dd_api_keys | |
message = email.message_from_string(data) | |
title = " ".join(self.message["subject"].split("\n")) | |
text = message.get_payload(0) | |
api.event(title, text) | |
if __name__ == '__main__': | |
apikey = <datadog api key goes here> | |
appkey = <datadog application key goes here> | |
server = Server((apikey, appkey)) | |
asyncore.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment