Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
b86740e1
Commit
b86740e1
authored
Jun 14, 2013
by
Arturas Slajus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
datadog_event module: submit your events to DataDog service.
parent
cf2ddb6f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
155 additions
and
0 deletions
+155
-0
library/monitoring/datadog_event
+155
-0
No files found.
library/monitoring/datadog_event
0 → 100644
View file @
b86740e1
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Author: Artūras 'arturaz' Šlajus <x11@arturaz.net>
#
# This module is proudly sponsored by iGeolise (www.igeolise.com) and
# Tiny Lab Productions (www.tinylabproductions.com).
DOCUMENTATION
=
'''
---
module: datadog_event
short_description: Posts events to DataDog service
description:
- "Allows to post events to DataDog (www.datadoghq.com) service."
- "Uses http://docs.datadoghq.com/api/#events API."
version_added: "1.3"
author: Artūras 'arturaz' Šlajus <x11@arturaz.net>
notes: []
requirements: [httplib2]
options:
api_key:
description: ["Your DataDog API key."]
required: true
default: null
title:
description: ["The event title."]
required: true
default: null
text:
description: ["The body of the event."]
required: true
default: null
date_happened:
description:
- POSIX timestamp of the event.
- Default value is now.
required: false
default: now
priority:
description: ["The priority of the event."]
required: false
default: normal
choices: [normal, low]
tags:
description: ["Comma separated list of tags to apply to the event."]
required: false
default: null
alert_type:
description: ["Type of alert."]
required: false
default: info
choices: ['error', 'warning', 'info', 'success']
aggregation_key:
description: ["An arbitrary string to use for aggregation."]
required: false
default: null
source_type_name:
description: ["The type of event being posted."]
required: false
default: null
choices:
- 'nagios'
- 'hudson'
- 'jenkins'
- 'user'
- 'my apps'
- 'feed'
- 'chef'
- 'puppet'
- 'git'
- 'bitbucket'
- 'fabric'
- 'capistrano'
'''
EXAMPLES
=
'''
# Post an event with low priority
datadog_event: title="Testing from ansible" text="Test!" priority="low"
api_key="6873258723457823548234234234"
# Post an event with several tags
datadog_event: title="Testing from ansible" text="Test!"
api_key="6873258723457823548234234234"
tags=aa,bb,cc
'''
import
socket
from
urllib2
import
urlopen
,
Request
,
URLError
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
api_key
=
dict
(
required
=
True
),
title
=
dict
(
required
=
True
),
text
=
dict
(
required
=
True
),
date_happened
=
dict
(
required
=
False
,
default
=
None
,
type
=
'int'
),
priority
=
dict
(
required
=
False
,
default
=
'normal'
,
choices
=
[
'normal'
,
'low'
]
),
tags
=
dict
(
required
=
False
,
default
=
None
),
alert_type
=
dict
(
required
=
False
,
default
=
'info'
,
choices
=
[
'error'
,
'warning'
,
'info'
,
'success'
]
),
aggregation_key
=
dict
(
required
=
False
,
default
=
None
),
source_type_name
=
dict
(
required
=
False
,
default
=
None
,
choices
=
[
'nagios'
,
'hudson'
,
'jenkins'
,
'user'
,
'my apps'
,
'feed'
,
'chef'
,
'puppet'
,
'git'
,
'bitbucket'
,
'fabric'
,
'capistrano'
]
)
)
)
post_event
(
module
)
def
post_event
(
module
):
uri
=
"https://app.datadoghq.com/api/v1/events?api_key="
+
\
module
.
params
[
'api_key'
]
body
=
dict
(
title
=
module
.
params
[
'title'
],
text
=
module
.
params
[
'text'
],
priority
=
module
.
params
[
'priority'
],
alert_type
=
module
.
params
[
'alert_type'
]
)
if
module
.
params
[
'date_happened'
]
!=
None
:
body
[
'date_happened'
]
=
module
.
params
[
'date_happened'
]
if
module
.
params
[
'tags'
]
!=
None
:
body
[
'tags'
]
=
module
.
params
[
'tags'
]
.
split
(
","
)
if
module
.
params
[
'aggregation_key'
]
!=
None
:
body
[
'aggregation_key'
]
=
module
.
params
[
'aggregation_key'
]
if
module
.
params
[
'source_type_name'
]
!=
None
:
body
[
'source_type_name'
]
=
module
.
params
[
'source_type_name'
]
json_body
=
module
.
jsonify
(
body
)
headers
=
{
"Content-Type"
:
"application/json"
}
request
=
Request
(
uri
,
json_body
,
headers
,
unverifiable
=
True
)
try
:
response
=
urlopen
(
request
)
response_body
=
response
.
read
()
response_json
=
module
.
from_json
(
response_body
)
if
response_json
[
'status'
]
==
'ok'
:
module
.
exit_json
(
changed
=
True
)
else
:
module
.
fail_json
(
msg
=
response
)
except
URLError
,
e
:
module
.
fail_json
(
msg
=
"URL error:
%
s."
%
e
)
except
socket
.
error
,
e
:
module
.
fail_json
(
msg
=
"Socket error:
%
s to
%
s"
%
(
e
,
uri
))
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment