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
cebdcaa9
Commit
cebdcaa9
authored
May 10, 2013
by
Adam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Campfire Notification Module
parent
8ef18c2f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
128 additions
and
0 deletions
+128
-0
library/notification/campfire
+128
-0
No files found.
library/notification/campfire
0 → 100644
View file @
cebdcaa9
#!/usr/bin/env python
# -*- coding: utf-8 -*-
DOCUMENTATION
=
'''
---
module: campfire
short_description: Send a message to Campfire
description:
- Send a message to Campfire.
version_added: "1.2"
options:
subscription:
description:
- The subscription name to use.
required: true
token:
description:
- API token.
required: true
room:
description:
- Room number to which the message should be sent.
required: true
msg:
description:
- The message body.
required: true
notify:
description:
- Send a notification sound before the message.
required: false
choices: ["56k", "bueller", "crickets", "dangerzone", "deeper",
"drama", "greatjob", "horn", "horror" , "inconceivable",
"live", "loggins", "noooo", "nyan", "ohmy", "ohyeah",
"pushit", "rimshot", "sax", "secret", "tada", "tmyk",
"trombone", "vuvuzela", "yeah", "yodel"]
# informational: requirements for nodes
requirements: [ urllib2, cgi ]
author: Adam Garside <adam.garside@gmail.com>
'''
EXAMPLES
=
'''
action: campfire subscription=foo token=12345 room=123 msg="Task completed."
action: campfire subscription=foo token=12345 room=123 msg="Messages
with
\n
Newlines will result in a PasteMessage type being sent."
action: campfire subscription=foo token=12345 room=123 notify=loggins
msg="Task completed ... with feeling."
'''
def
main
():
try
:
import
urllib2
except
ImportError
:
module
.
fail_json
(
msg
=
"urllib2 is required"
)
try
:
import
cgi
except
ImportError
:
module
.
fail_json
(
msg
=
"cgi is required"
)
module
=
AnsibleModule
(
argument_spec
=
dict
(
subscription
=
dict
(
required
=
True
),
token
=
dict
(
required
=
True
),
room
=
dict
(
required
=
True
),
msg
=
dict
(
required
=
True
),
notify
=
dict
(
required
=
False
,
choices
=
[
"56k"
,
"bueller"
,
"crickets"
,
"dangerzone"
,
"deeper"
,
"drama"
,
"greatjob"
,
"horn"
,
"horror"
,
"inconceivable"
,
"live"
,
"loggins"
,
"noooo"
,
"nyan"
,
"ohmy"
,
"ohyeah"
,
"pushit"
,
"rimshot"
,
"sax"
,
"secret"
,
"tada"
,
"tmyk"
,
"trombone"
,
"vuvuzela"
,
"yeah"
,
"yodel"
]),
),
supports_check_mode
=
True
)
subscription
=
module
.
params
[
"subscription"
]
token
=
module
.
params
[
"token"
]
room
=
module
.
params
[
"room"
]
msg
=
module
.
params
[
"msg"
]
notify
=
module
.
params
[
"notify"
]
URI
=
"https://
%
s.campfirenow.com"
%
subscription
NSTR
=
"<message><type>SoundMessage</type><body>
%
s</body></message>"
MSTR
=
"<message><body>
%
s</body></message>"
AGENT
=
"Ansible/1.2"
try
:
# Setup basic auth using token as the username
pm
=
urllib2
.
HTTPPasswordMgrWithDefaultRealm
()
pm
.
add_password
(
None
,
URI
,
token
,
'X'
)
# Setup Handler and define the opener for the request
handler
=
urllib2
.
HTTPBasicAuthHandler
(
pm
)
opener
=
urllib2
.
build_opener
(
handler
)
target_url
=
'
%
s/room/
%
s/speak.xml'
%
(
URI
,
room
)
# Send some audible notification if requested
if
notify
:
req
=
urllib2
.
Request
(
target_url
,
NSTR
%
cgi
.
escape
(
notify
))
req
.
add_header
(
'Content-Type'
,
'application/xml'
)
req
.
add_header
(
'User-agent'
,
AGENT
)
response
=
opener
.
open
(
req
)
# Send the message
req
=
urllib2
.
Request
(
target_url
,
MSTR
%
cgi
.
escape
(
msg
))
req
.
add_header
(
'Content-Type'
,
'application/xml'
)
req
.
add_header
(
'User-agent'
,
AGENT
)
response
=
opener
.
open
(
req
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to sent msg:
%
s"
%
e
)
module
.
exit_json
(
changed
=
True
,
room
=
room
,
msg
=
msg
,
notify
=
notify
)
# 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