Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
Noah
Commits
d98730b1
Commit
d98730b1
authored
Mar 24, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abstracting more agent logic
parent
fd57abd9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
32 deletions
+39
-32
noah-watcher.rb
bin/noah-watcher.rb
+2
-2
agent.rb
lib/noah/agent.rb
+1
-1
base_agent.rb
lib/noah/agents/base_agent.rb
+15
-2
dummy_agent.rb
lib/noah/agents/dummy_agent.rb
+7
-8
http_agent.rb
lib/noah/agents/http_agent.rb
+14
-19
No files found.
bin/noah-watcher.rb
View file @
d98730b1
...
@@ -20,8 +20,8 @@ rescue LoadError => e
...
@@ -20,8 +20,8 @@ rescue LoadError => e
exit
exit
end
end
LOGGER
=
Logger
.
new
(
'rundeck-test.log'
)
#
LOGGER = Logger.new('rundeck-test.log')
#
LOGGER = Logger.new(STDOUT)
LOGGER
=
Logger
.
new
(
STDOUT
)
EventMachine
.
run
do
EventMachine
.
run
do
EM
.
error_handler
do
|
e
|
EM
.
error_handler
do
|
e
|
...
...
lib/noah/agent.rb
View file @
d98730b1
...
@@ -42,7 +42,7 @@ module Noah
...
@@ -42,7 +42,7 @@ module Noah
e
,
m
=
msg
.
split
(
"|"
)
e
,
m
=
msg
.
split
(
"|"
)
# Below isn't being used right now
# Below isn't being used right now
#be = Base64.encode64(e).gsub("\n","")
#be = Base64.encode64(e).gsub("\n","")
EM
::
Iterator
.
new
(
@@agents
).
each
do
|
agent
,
iter
|
EM
::
Iterator
.
new
(
@@agents
,
@@agents
.
size
).
each
do
|
agent
,
iter
|
agent
.
send
(
:notify
,
e
,
m
,
@@watchers
.
clone
)
agent
.
send
(
:notify
,
e
,
m
,
@@watchers
.
clone
)
iter
.
next
iter
.
next
end
end
...
...
lib/noah/agents/base_agent.rb
View file @
d98730b1
...
@@ -3,14 +3,27 @@ require 'logger'
...
@@ -3,14 +3,27 @@ require 'logger'
module
Noah::Agents
module
Noah::Agents
module
Base
module
Base
class
<<
self
class
<<
self
include
EM
::
Deferrable
PREFIX
=
"base"
PREFIX
=
"base"
NAME
=
"base-agent"
NAME
=
"base-agent"
end
end
def
self
.
included
(
base
)
def
self
.
included
(
base
)
Noah
::
Watchers
.
register_agent
(
base
)
Noah
::
Watchers
.
register_agent
(
base
)
base
.
send
:include
,
EM
::
Deferrable
base
.
send
:extend
,
AgentClassMethods
end
end
module
AgentClassMethods
def
find_watched_patterns!
(
watchlist
)
watched_patterns
=
[]
watchlist
.
find_all
do
|
w
|
p
,
ep
=
Base64
.
decode64
(
w
).
split
(
'|'
)
watched_patterns
<<
"
#{
p
}
|
#{
ep
}
"
if
ep
=~
/^
#{
self
.
const_get
(
"PREFIX"
)
}
/
end
watched_patterns
end
end
end
end
end
end
lib/noah/agents/dummy_agent.rb
View file @
d98730b1
...
@@ -4,21 +4,20 @@ module Noah::Agents
...
@@ -4,21 +4,20 @@ module Noah::Agents
class
DummyAgent
class
DummyAgent
include
Noah
::
Agents
::
Base
include
Noah
::
Agents
::
Base
PREFIX
=
"dummy"
PREFIX
=
"dummy
://
"
NAME
=
"dummy"
NAME
=
"dummy"
def
self
.
notify
(
event
,
message
,
watch_list
)
def
self
.
notify
(
event
,
message
,
watch_list
)
logger
=
LOGGER
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
matches
=
watch_list
.
find_all
{
|
w
|
event
=~
/^
#{
Base64
.
decode64
(
w
)
}
/
}
watched_patterns
=
find_watched_patterns!
(
watch_list
)
logger
.
debug
(
"
#{
NAME
}
: Found
#{
matches
.
size
}
possible matches for
#{
event
}
"
)
matches
=
watched_patterns
.
find_all
{
|
w
|
event
=~
/^
#{
w
}
/
}
logger
.
debug
(
"
#{
NAME
}
: Found
#{
matches
.
size
}
matches for
#{
event
}
"
)
EM
::
Iterator
.
new
(
matches
).
each
do
|
watch
,
iter
|
EM
::
Iterator
.
new
(
matches
).
each
do
|
watch
,
iter
|
p
,
ep
=
Base64
.
decode64
(
watch
).
split
(
"|"
)
p
,
ep
=
watch
.
split
(
"|"
)
if
ep
=~
/^
#{
PREFIX
}
/
logger
.
info
(
"
#{
NAME
}
: Sending message to:
#{
ep
}
for pattern:
#{
p
}
"
)
logger
.
info
(
"
#{
NAME
}
: Sending message to:
#{
ep
}
for pattern:
#{
p
}
"
)
logger
.
debug
(
"
#{
NAME
}
: message received:
#{
message
}
"
)
logger
.
debug
(
"
#{
NAME
}
: message received:
#{
message
}
"
)
end
iter
.
next
iter
.
next
end
end
end
end
...
...
lib/noah/agents/http_agent.rb
View file @
d98730b1
...
@@ -4,31 +4,26 @@ module Noah::Agents
...
@@ -4,31 +4,26 @@ module Noah::Agents
class
HttpAgent
class
HttpAgent
include
Noah
::
Agents
::
Base
include
Noah
::
Agents
::
Base
PREFIX
=
"http"
PREFIX
=
"http
://
"
NAME
=
"http"
NAME
=
"http"
def
self
.
notify
(
event
,
message
,
watch_list
)
def
self
.
notify
(
event
,
message
,
watch_list
)
logger
=
LOGGER
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
# TODO
watched_patterns
=
find_watched_patterns!
(
watch_list
)
# I can save work by only decoding once.
matches
=
watched_patterns
.
find_all
{
|
w
|
event
=~
/^
#{
w
}
/
}
# This is retarded doing it twice.
logger
.
debug
(
"
#{
NAME
}
: Found
#{
matches
.
size
}
matches for
#{
event
}
"
)
# Populate matches with decoded data for chrissakes
matches
=
watch_list
.
find_all
{
|
w
|
event
=~
/^
#{
Base64
.
decode64
(
w
)
}
/
}
logger
.
debug
(
"
#{
PREFIX
}
: Found
#{
matches
.
size
}
possible matches for
#{
event
}
"
)
EM
::
Iterator
.
new
(
matches
,
100
).
each
do
|
watch
,
iter
|
EM
::
Iterator
.
new
(
matches
,
100
).
each
do
|
watch
,
iter
|
p
,
ep
=
Base64
.
decode64
(
watch
).
split
(
"|"
)
p
,
ep
=
watch
.
split
(
"|"
)
if
ep
=~
/^
#{
PREFIX
}
/
logger
.
info
(
"
#{
NAME
}
: Sending message to (
#{
ep
}
) for pattern (
#{
p
}
)"
)
logger
.
info
(
"
#{
NAME
}
: Sending message to (
#{
ep
}
) for pattern (
#{
p
}
)"
)
http
=
EM
::
HttpRequest
.
new
(
ep
,
:connection_timeout
=>
2
,
:inactivity_timeout
=>
4
).
post
:body
=>
message
http
=
EM
::
HttpRequest
.
new
(
ep
,
:connection_timeout
=>
2
,
:inactivity_timeout
=>
4
).
post
:body
=>
message
http
.
callback
{
http
.
callback
{
logger
.
info
(
"
#{
NAME
}
: Message posted to
#{
ep
}
successfully"
)
logger
.
info
(
"
#{
NAME
}
: Message posted to
#{
ep
}
successfully"
)
}
}
http
.
errback
{
http
.
errback
{
logger
.
error
(
"
#{
NAME
}
: Something went wrong with
#{
ep
}
"
)
logger
.
error
(
"
#{
NAME
}
: Something went wrong with
#{
ep
}
"
)
}
}
end
iter
.
next
iter
.
next
end
end
end
end
...
...
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