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
d82135a6
Commit
d82135a6
authored
May 05, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2827 from shirou/devel
Add notification/hipchat module.
parents
cfd0413b
f79be1e0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
143 additions
and
0 deletions
+143
-0
library/notification/hipchat
+143
-0
No files found.
library/notification/hipchat
0 → 100644
View file @
d82135a6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
DOCUMENTATION
=
'''
---
module: hipchat
short_description: Send a message to hipchat
description:
- Send a message to hipchat
options:
token:
description:
- API token.
required: true
room:
description:
- ID or name of the room.
required: true
from:
description:
- Name the message will appear be sent from. max 15 characters.
Over 15, will be shorten.
required: false
default: Ansible
msg:
description:
- The message body.
required: true
default: null
color:
description:
- Background color for the message. Default is yellow.
required: false
default: yellow
choices: [ "yellow", "red", "green", "purple", "gray", "random" ]
msg_format:
description:
- message format. html or text. Default is text.
required: false
default: text
choices: [ "text", "html" ]
notify:
description:
- notify or not (change the tab color, play a sound, etc)
required: false
default: true
choices: [ "true", "false" ]
# informational: requirements for nodes
requirements: [ urllib, urllib2 ]
author: WAKAYAMA Shirou
'''
EXAMPLES
=
'''
action: hipchat token=AAAAAA room=notify msg=Ansible task finished
'''
# ===========================================
# HipChat module specific support methods.
#
HAS_URLLIB
=
True
try
:
import
urllib
except
ImportError
:
HAS_URLLIB
=
False
HAS_URLLIB2
=
True
try
:
import
urllib2
except
ImportError
:
HAS_URLLIB2
=
False
MSG_URI
=
"https://api.hipchat.com/v1/rooms/message?"
def
send_msg
(
token
,
room
,
msg_from
,
msg
,
msg_format
=
'text'
,
color
=
'yellow'
,
notify
=
False
):
'''sending message to hipchat'''
params
=
{}
params
[
'room_id'
]
=
room
params
[
'from'
]
=
msg_from
[:
15
]
# max length is 15
params
[
'message'
]
=
msg
params
[
'message_format'
]
=
msg_format
params
[
'color'
]
=
color
if
notify
:
params
[
'notify'
]
=
1
else
:
params
[
'notify'
]
=
0
url
=
MSG_URI
+
"auth_token=
%
s"
%
(
token
)
response
=
urllib2
.
urlopen
(
url
,
urllib
.
urlencode
(
params
))
return
response
.
read
()
# ===========================================
# Module execution.
#
def
main
():
if
not
HAS_URLLIB
:
module
.
fail_json
(
msg
=
"urllib is not installed"
)
if
not
HAS_URLLIB2
:
module
.
fail_json
(
msg
=
"urllib2 is not installed"
)
module
=
AnsibleModule
(
argument_spec
=
dict
(
token
=
dict
(
required
=
True
),
room
=
dict
(
required
=
True
),
msg
=
dict
(
required
=
True
),
msg_from
=
dict
(
default
=
"Ansible"
),
color
=
dict
(
default
=
"yellow"
,
choices
=
[
"yellow"
,
"red"
,
"green"
,
"purple"
,
"gray"
,
"random"
]),
msg_format
=
dict
(
default
=
"text"
,
choices
=
[
"text"
,
"html"
]),
notify
=
dict
(
default
=
True
,
choices
=
BOOLEANS
),
),
supports_check_mode
=
True
)
token
=
module
.
params
[
"token"
]
room
=
module
.
params
[
"room"
]
msg
=
module
.
params
[
"msg"
]
msg_from
=
module
.
params
[
"msg_from"
]
color
=
module
.
params
[
"color"
]
msg_format
=
module
.
params
[
"msg_format"
]
notify
=
module
.
params
[
"notify"
]
try
:
send_msg
(
token
,
room
,
msg_from
,
msg
,
msg_format
,
color
,
notify
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to sent msg:
%
s"
%
e
)
changed
=
True
module
.
exit_json
(
changed
=
changed
,
room
=
room
,
msg_from
=
msg_from
,
msg
=
msg
)
# 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