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
b48b22b2
Commit
b48b22b2
authored
Dec 05, 2013
by
Matt Martz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Try to follow RFC2812 for waiting on serverl welcome and join messages before performing more tasks
parent
36a305ce
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
34 deletions
+65
-34
library/notification/irc
+65
-34
No files found.
library/notification/irc
View file @
b48b22b2
...
...
@@ -61,10 +61,16 @@ options:
description:
- Server password
required: false
timeout:
description:
- Timeout to use while waiting for successful registration and join
messages, this is to prevent an endless loop
default: 30
version_added: 1.5
# informational: requirements for nodes
requirements: [ socket ]
author: Jan-Piet Mens
author: Jan-Piet Mens
, Matt Martz
'''
EXAMPLES
=
'''
...
...
@@ -81,19 +87,22 @@ EXAMPLES = '''
# IRC module support methods.
#
from
time
import
sleep
import
re
import
socket
from
time
import
sleep
def
send_msg
(
channel
,
msg
,
server
=
'localhost'
,
port
=
'6667'
,
nick
=
"ansible"
,
color
=
'black'
,
passwd
=
False
):
nick
=
"ansible"
,
color
=
'black'
,
passwd
=
False
,
timeout
=
30
):
'''send message to IRC'''
colornumbers
=
{
'black'
:
"01"
,
'red'
:
"04"
,
'green'
:
"09"
,
'yellow'
:
"08"
,
'blue'
:
"12"
,
'black'
:
"01"
,
'red'
:
"04"
,
'green'
:
"09"
,
'yellow'
:
"08"
,
'blue'
:
"12"
,
}
try
:
...
...
@@ -103,18 +112,38 @@ def send_msg(channel, msg, server='localhost', port='6667',
message
=
"
\x03
"
+
colornumber
+
msg
irc
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
irc
.
connect
(
(
server
,
int
(
port
)
)
)
irc
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
irc
.
connect
(
(
server
,
int
(
port
))
)
if
passwd
:
irc
.
send
(
'PASS
%
s
\r\n
'
%
passwd
)
irc
.
send
(
'NICK
%
s
\r\n
'
%
nick
)
irc
.
send
(
'USER
%
s
%
s
%
s :ansible IRC
\r\n
'
%
(
nick
,
nick
,
nick
))
time
.
sleep
(
1
)
irc
.
send
(
'JOIN
%
s
\r\n
'
%
channel
)
irc
.
send
(
'PRIVMSG
%
s :
%
s
\r\n
'
%
(
channel
,
message
))
irc
.
send
(
'PASS
%
s
\r\n
'
%
passwd
)
irc
.
send
(
'NICK
%
s
\r\n
'
%
nick
)
irc
.
send
(
'USER
%
s
%
s
%
s :ansible IRC
\r\n
'
%
(
nick
,
nick
,
nick
))
motd
=
''
start
=
time
.
time
()
while
1
:
motd
+=
irc
.
recv
(
1024
)
if
re
.
search
(
'^:
\
S+ 00[1-4]
%
s :'
%
nick
,
motd
,
flags
=
re
.
M
):
break
elif
time
.
time
()
-
start
>
timeout
:
module
.
fail_json
(
msg
=
'Timeout waiting for IRC server welcome '
'response'
)
time
.
sleep
(
0.5
)
irc
.
send
(
'JOIN
%
s
\r\n
'
%
channel
)
join
=
''
start
=
time
.
time
()
while
1
:
join
+=
irc
.
recv
(
1024
)
if
re
.
search
(
'^:
\
S+ 366
%
s
%
s :'
%
(
nick
,
channel
),
join
,
flags
=
re
.
M
):
break
elif
time
.
time
()
-
start
>
timeout
:
module
.
fail_json
(
msg
=
'Timeout waiting for IRC JOIN response'
)
time
.
sleep
(
0.5
)
irc
.
send
(
'PRIVMSG
%
s :
%
s
\r\n
'
%
(
channel
,
message
))
time
.
sleep
(
1
)
irc
.
send
(
'PART
%
s
\r\n
'
%
channel
)
irc
.
send
(
'QUIT
\r\n
'
)
irc
.
send
(
'PART
%
s
\r\n
'
%
channel
)
irc
.
send
(
'QUIT
\r\n
'
)
time
.
sleep
(
1
)
irc
.
close
()
...
...
@@ -122,32 +151,34 @@ def send_msg(channel, msg, server='localhost', port='6667',
# Main
#
def
main
():
def
main
():
module
=
AnsibleModule
(
argument_spec
=
dict
(
server
=
dict
(
default
=
'localhost'
),
port
=
dict
(
default
=
6667
),
nick
=
dict
(
default
=
'ansible'
),
msg
=
dict
(
required
=
True
),
color
=
dict
(
default
=
"black"
,
choices
=
[
"yellow"
,
"red"
,
"green"
,
"blue"
,
"black"
]),
channel
=
dict
(
required
=
True
),
passwd
=
dict
()
server
=
dict
(
default
=
'localhost'
),
port
=
dict
(
default
=
6667
),
nick
=
dict
(
default
=
'ansible'
),
msg
=
dict
(
required
=
True
),
color
=
dict
(
default
=
"black"
,
choices
=
[
"yellow"
,
"red"
,
"green"
,
"blue"
,
"black"
]),
channel
=
dict
(
required
=
True
),
passwd
=
dict
(),
timeout
=
dict
(
type
=
'int'
,
default
=
30
)
),
supports_check_mode
=
True
)
server
=
module
.
params
[
"server"
]
port
=
module
.
params
[
"port"
]
nick
=
module
.
params
[
"nick"
]
msg
=
module
.
params
[
"msg"
]
color
=
module
.
params
[
"color"
]
server
=
module
.
params
[
"server"
]
port
=
module
.
params
[
"port"
]
nick
=
module
.
params
[
"nick"
]
msg
=
module
.
params
[
"msg"
]
color
=
module
.
params
[
"color"
]
channel
=
module
.
params
[
"channel"
]
passwd
=
module
.
params
[
"passwd"
]
passwd
=
module
.
params
[
"passwd"
]
timeout
=
module
.
params
[
"timeout"
]
try
:
send_msg
(
channel
,
msg
,
server
,
port
,
nick
,
color
,
passwd
)
send_msg
(
channel
,
msg
,
server
,
port
,
nick
,
color
,
passwd
,
timeout
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"unable to send to IRC:
%
s"
%
e
)
...
...
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