Skip to content

Instantly share code, notes, and snippets.

@mattvonrocketstein
Last active August 29, 2015 14:22
Show Gist options
  • Save mattvonrocketstein/6ebfd94b06b25cc74910 to your computer and use it in GitHub Desktop.
Save mattvonrocketstein/6ebfd94b06b25cc74910 to your computer and use it in GitHub Desktop.
a quick utility for writing events to the Datadog events stream
#!/usr/bin/env python
""" dd_event:
a quick utility for writing events to the Datadog events stream.
requires:
pip install dogapi
pip install argparse
"""
import argparse
from dogapi.http import DogHttpApi as DD
API_KEY = 'YOUR JENKINS API KEY HERE'
APP_KEY = 'YOU JENKINS APP KEY HERE'
parser = argparse.ArgumentParser()
tag_help = ("tags to associate with this event. "
"argument should be quoted and "
"space-separated for multiple tags")
title_help = ("title to associate with this event. "
"argument should be quoted if it is"
" more than one word ")
text_help = ("text to associate with this event. "
"argument should be quoted if it is"
" more than one word ")
parser.add_argument("--tags", default='', help=tag_help)
parser.add_argument("--title", default='', help=title_help)
parser.add_argument("--text", default='', help=text_help)
conn_args = dict(
api_key=API_KEY,
application_key=APP_KEY,
api_version='v1',
json_responses=True)
if __name__ == '__main__':
conn = DD(**conn_args)
args = parser.parse_args()
title = args.title
text = args.text
tags = list(set(args.tags.split()))
if not title:
raise SystemExit("datadog event must have title")
if not text:
raise SystemExit("datadog event must have text")
print conn.event(
title=title,
tags=tags,
text=text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment