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
exit
end
LOGGER
=
Logger
.
new
(
'rundeck-test.log'
)
#
LOGGER = Logger.new(STDOUT)
#
LOGGER = Logger.new('rundeck-test.log')
LOGGER
=
Logger
.
new
(
STDOUT
)
EventMachine
.
run
do
EM
.
error_handler
do
|
e
|
...
...
lib/noah/agent.rb
View file @
d98730b1
...
...
@@ -42,7 +42,7 @@ module Noah
e
,
m
=
msg
.
split
(
"|"
)
# Below isn't being used right now
#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
)
iter
.
next
end
...
...
lib/noah/agents/base_agent.rb
View file @
d98730b1
...
...
@@ -3,14 +3,27 @@ require 'logger'
module
Noah::Agents
module
Base
class
<<
self
include
EM
::
Deferrable
PREFIX
=
"base"
NAME
=
"base-agent"
end
def
self
.
included
(
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
lib/noah/agents/dummy_agent.rb
View file @
d98730b1
...
...
@@ -4,21 +4,20 @@ module Noah::Agents
class
DummyAgent
include
Noah
::
Agents
::
Base
PREFIX
=
"dummy"
PREFIX
=
"dummy
://
"
NAME
=
"dummy"
def
self
.
notify
(
event
,
message
,
watch_list
)
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
matches
=
watch_list
.
find_all
{
|
w
|
event
=~
/^
#{
Base64
.
decode64
(
w
)
}
/
}
logger
.
debug
(
"
#{
NAME
}
: Found
#{
matches
.
size
}
possible matches for
#{
event
}
"
)
watched_patterns
=
find_watched_patterns!
(
watch_list
)
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
|
p
,
ep
=
Base64
.
decode64
(
watch
).
split
(
"|"
)
if
ep
=~
/^
#{
PREFIX
}
/
logger
.
info
(
"
#{
NAME
}
: Sending message to:
#{
ep
}
for pattern:
#{
p
}
"
)
logger
.
debug
(
"
#{
NAME
}
: message received:
#{
message
}
"
)
end
p
,
ep
=
watch
.
split
(
"|"
)
logger
.
info
(
"
#{
NAME
}
: Sending message to:
#{
ep
}
for pattern:
#{
p
}
"
)
logger
.
debug
(
"
#{
NAME
}
: message received:
#{
message
}
"
)
iter
.
next
end
end
...
...
lib/noah/agents/http_agent.rb
View file @
d98730b1
...
...
@@ -4,31 +4,26 @@ module Noah::Agents
class
HttpAgent
include
Noah
::
Agents
::
Base
PREFIX
=
"http"
PREFIX
=
"http
://
"
NAME
=
"http"
def
self
.
notify
(
event
,
message
,
watch_list
)
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
# TODO
# I can save work by only decoding once.
# This is retarded doing it twice.
# 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
}
"
)
logger
.
debug
(
"
#{
NAME
}
: got event -
#{
event
}
"
)
watched_patterns
=
find_watched_patterns!
(
watch_list
)
matches
=
watched_patterns
.
find_all
{
|
w
|
event
=~
/^
#{
w
}
/
}
logger
.
debug
(
"
#{
NAME
}
: Found
#{
matches
.
size
}
matches for
#{
event
}
"
)
EM
::
Iterator
.
new
(
matches
,
100
).
each
do
|
watch
,
iter
|
p
,
ep
=
Base64
.
decode64
(
watch
).
split
(
"|"
)
if
ep
=~
/^
#{
PREFIX
}
/
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
.
callback
{
logger
.
info
(
"
#{
NAME
}
: Message posted to
#{
ep
}
successfully"
)
}
http
.
errback
{
logger
.
error
(
"
#{
NAME
}
: Something went wrong with
#{
ep
}
"
)
}
end
p
,
ep
=
watch
.
split
(
"|"
)
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
.
callback
{
logger
.
info
(
"
#{
NAME
}
: Message posted to
#{
ep
}
successfully"
)
}
http
.
errback
{
logger
.
error
(
"
#{
NAME
}
: Something went wrong with
#{
ep
}
"
)
}
iter
.
next
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