Skip to content

Instantly share code, notes, and snippets.

@ieatkillerbees
Created June 28, 2013 02:21
Show Gist options
  • Select an option

  • Save ieatkillerbees/5881996 to your computer and use it in GitHub Desktop.

Select an option

Save ieatkillerbees/5881996 to your computer and use it in GitHub Desktop.
A simple sample SMTP server to push Bamboo notification emails to Datadog's API
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()
@marriop
Copy link

marriop commented Aug 29, 2013

Thanks, this should help me get started on a project we have in the works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment