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
40c4c205
Commit
40c4c205
authored
Mar 24, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
yeah I forgot all these
parent
78e22223
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
42 additions
and
33 deletions
+42
-33
Rakefile
Rakefile
+5
-4
noah-watcher.rb
bin/noah-watcher.rb
+4
-3
noah.rb
lib/noah.rb
+1
-0
agent.rb
lib/noah/agent.rb
+2
-1
base_agent.rb
lib/noah/agents/base_agent.rb
+15
-3
dummy_agent.rb
lib/noah/agents/dummy_agent.rb
+4
-10
http_agent.rb
lib/noah/agents/http_agent.rb
+5
-11
models.rb
lib/noah/models.rb
+1
-1
spec_helper.rb
spec/spec_helper.rb
+5
-0
No files found.
Rakefile
View file @
40c4c205
...
@@ -44,10 +44,11 @@ task :sample, :redis_url do |t, args|
...
@@ -44,10 +44,11 @@ task :sample, :redis_url do |t, args|
Ohm
::
connect
(
:url
=>
args
.
redis_url
)
Ohm
::
connect
(
:url
=>
args
.
redis_url
)
Ohm
::
redis
.
flushdb
Ohm
::
redis
.
flushdb
puts
"Creating watchers..."
puts
"Creating watchers..."
Noah
::
Watcher
.
create
:endpoint
=>
"http://localhost:3000/webhook"
,
:pattern
=>
"//noah/application"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://applications"
,
:pattern
=>
"//noah/applications"
Noah
::
Watcher
.
create
:endpoint
=>
"http://localhost:3001/webhook"
,
:pattern
=>
"//noah/configuration"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://configurations"
,
:pattern
=>
"//noah/configurations"
Noah
::
Watcher
.
create
:endpoint
=>
"http://localhost:3002/webhook"
,
:pattern
=>
"//noah/host"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://hosts"
,
:pattern
=>
"//noah/hosts"
Noah
::
Watcher
.
create
:endpoint
=>
"http://localhost:3003/webhook"
,
:pattern
=>
"//noah/service"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://services"
,
:pattern
=>
"//noah/services"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://ephemerals"
,
:pattern
=>
"//noah/ephemerals"
puts
"Creating Host entry for 'localhost'"
puts
"Creating Host entry for 'localhost'"
h
=
Noah
::
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
h
=
Noah
::
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
if
h
.
save
if
h
.
save
...
...
bin/noah-watcher.rb
View file @
40c4c205
...
@@ -20,8 +20,9 @@ rescue LoadError => e
...
@@ -20,8 +20,9 @@ rescue LoadError => e
exit
exit
end
end
#LOGGER = Logger.new('rundeck-test.log')
Noah
::
Log
.
logger
=
Logger
.
new
(
STDOUT
)
LOGGER
=
Logger
.
new
(
STDOUT
)
LOGGER
=
Noah
::
Log
.
logger
LOGGER
.
progname
=
__FILE__
EventMachine
.
run
do
EventMachine
.
run
do
EM
.
error_handler
do
|
e
|
EM
.
error_handler
do
|
e
|
...
@@ -38,7 +39,7 @@ EventMachine.run do
...
@@ -38,7 +39,7 @@ EventMachine.run do
r
=
EventMachine
::
Hiredis
::
Client
.
connect
r
=
EventMachine
::
Hiredis
::
Client
.
connect
r
.
errback
{
|
x
|
logger
.
error
(
"Unable to connect to redis:
#{
x
}
"
)}
r
.
errback
{
|
x
|
logger
.
error
(
"Unable to connect to redis:
#{
x
}
"
)}
logger
.
debug
(
"Starting up"
)
logger
.
debug
(
"Starting up"
)
r
.
psubscribe
(
"
//noah/
*"
)
r
.
psubscribe
(
"*"
)
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
r
.
on
(
:pmessage
)
do
|
pattern
,
event
,
message
|
noah
.
reread_watchers
if
event
=~
/^\/\/noah\/watcher\/.*/
noah
.
reread_watchers
if
event
=~
/^\/\/noah\/watcher\/.*/
noah
.
broker
(
"
#{
event
}
|
#{
message
}
"
)
unless
noah
.
watchers
==
0
noah
.
broker
(
"
#{
event
}
|
#{
message
}
"
)
unless
noah
.
watchers
==
0
...
...
lib/noah.rb
View file @
40c4c205
...
@@ -16,6 +16,7 @@ require 'haml'
...
@@ -16,6 +16,7 @@ require 'haml'
require
'yaml'
require
'yaml'
require
'sinatra/base'
require
'sinatra/base'
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'log'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'custom_watcher'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'custom_watcher'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'validations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'validations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'models'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'noah'
,
'models'
)
...
...
lib/noah/agent.rb
View file @
40c4c205
...
@@ -13,7 +13,8 @@ module Noah
...
@@ -13,7 +13,8 @@ module Noah
@@agents
=
Noah
::
Watchers
.
agents
@@agents
=
Noah
::
Watchers
.
agents
def
initialize
def
initialize
@logger
=
LOGGER
@logger
=
Noah
::
Log
.
logger
@logger
.
progname
=
self
.
class
.
name
@logger
.
debug
(
"Initializing with
#{
@@watchers
.
size
}
registered watches"
)
@logger
.
debug
(
"Initializing with
#{
@@watchers
.
size
}
registered watches"
)
@logger
.
debug
(
"
#{
@@agents
}
agents registered"
)
@logger
.
debug
(
"
#{
@@agents
}
agents registered"
)
if
EventMachine
.
reactor_running?
if
EventMachine
.
reactor_running?
...
...
lib/noah/agents/base_agent.rb
View file @
40c4c205
require
'logger'
module
Noah::Agents
module
Noah::Agents
module
Base
module
Base
class
<<
self
class
<<
self
PREFIX
=
"base"
PREFIX
=
"base"
NAME
=
"base-agent"
NAME
=
"base-agent"
end
end
...
@@ -16,6 +14,11 @@ module Noah::Agents
...
@@ -16,6 +14,11 @@ module Noah::Agents
module
AgentClassMethods
module
AgentClassMethods
def
logger
Noah
::
Log
.
logger
.
progname
=
self
.
name
Noah
::
Log
.
logger
end
def
find_watched_patterns!
(
watchlist
)
def
find_watched_patterns!
(
watchlist
)
watched_patterns
=
[]
watched_patterns
=
[]
watchlist
.
find_all
do
|
w
|
watchlist
.
find_all
do
|
w
|
...
@@ -25,5 +28,14 @@ module Noah::Agents
...
@@ -25,5 +28,14 @@ module Noah::Agents
watched_patterns
watched_patterns
end
end
def
notify
(
event
,
message
,
watch_list
)
logger
.
info
(
"Worker Initiated"
)
logger
.
debug
(
"got event -
#{
event
}
"
)
watched_patterns
=
find_watched_patterns!
(
watch_list
)
matches
=
watched_patterns
.
find_all
{
|
w
|
event
=~
/^
#{
w
}
/
}
logger
.
debug
(
"Found
#{
matches
.
size
}
matches for
#{
event
}
"
)
self
.
callback!
(
matches
,
message
)
end
end
end
end
end
lib/noah/agents/dummy_agent.rb
View file @
40c4c205
...
@@ -5,19 +5,13 @@ module Noah::Agents
...
@@ -5,19 +5,13 @@ module Noah::Agents
include
Noah
::
Agents
::
Base
include
Noah
::
Agents
::
Base
PREFIX
=
"dummy://"
PREFIX
=
"dummy://"
NAME
=
"dummy"
NAME
=
self
.
name
def
self
.
notify
(
event
,
message
,
watch_list
)
def
self
.
callback!
(
matches
,
message
)
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
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
).
each
do
|
watch
,
iter
|
EM
::
Iterator
.
new
(
matches
).
each
do
|
watch
,
iter
|
p
,
ep
=
watch
.
split
(
"|"
)
p
,
ep
=
watch
.
split
(
"|"
)
logger
.
info
(
"
#{
NAME
}
:
Sending message to:
#{
ep
}
for pattern:
#{
p
}
"
)
logger
.
info
(
"Sending message to:
#{
ep
}
for pattern:
#{
p
}
"
)
logger
.
debug
(
"
#{
NAME
}
:
message received:
#{
message
}
"
)
logger
.
debug
(
"message received:
#{
message
}
"
)
iter
.
next
iter
.
next
end
end
end
end
...
...
lib/noah/agents/http_agent.rb
View file @
40c4c205
...
@@ -5,24 +5,18 @@ module Noah::Agents
...
@@ -5,24 +5,18 @@ module Noah::Agents
include
Noah
::
Agents
::
Base
include
Noah
::
Agents
::
Base
PREFIX
=
"http://"
PREFIX
=
"http://"
NAME
=
"http"
NAME
=
self
.
name
def
self
.
notify
(
event
,
message
,
watch_list
)
def
self
.
callback!
(
matches
,
message
)
logger
=
LOGGER
logger
.
info
(
"
#{
NAME
}
: Worker initiated"
)
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
|
EM
::
Iterator
.
new
(
matches
,
100
).
each
do
|
watch
,
iter
|
p
,
ep
=
watch
.
split
(
"|"
)
p
,
ep
=
watch
.
split
(
"|"
)
logger
.
info
(
"
#{
NAME
}
:
Sending message to (
#{
ep
}
) for pattern (
#{
p
}
)"
)
logger
.
info
(
"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
(
"Message posted to
#{
ep
}
successfully"
)
}
}
http
.
errback
{
http
.
errback
{
logger
.
error
(
"
#{
NAME
}
:
Something went wrong with
#{
ep
}
"
)
logger
.
error
(
"Something went wrong with
#{
ep
}
"
)
}
}
iter
.
next
iter
.
next
end
end
...
...
lib/noah/models.rb
View file @
40c4c205
...
@@ -67,7 +67,7 @@ module Noah
...
@@ -67,7 +67,7 @@ module Noah
protected
protected
def
patternize_me
def
patternize_me
name
.
match
(
/^\//
)
?
n
=
name
.
gsub
(
/^\//
,
''
)
:
n
=
name
name
.
match
(
/^\//
)
?
n
=
name
.
gsub
(
/^\//
,
''
)
:
n
=
name
"//noah/
#{
self
.
class_to_lower
}
/
#{
n
}
"
"//noah/
#{
self
.
class_to_lower
}
s
/
#{
n
}
"
end
end
def
stash_name
def
stash_name
...
...
spec/spec_helper.rb
View file @
40c4c205
...
@@ -14,6 +14,11 @@ RSpec.configure do |config|
...
@@ -14,6 +14,11 @@ RSpec.configure do |config|
config
.
after
(
:all
,
:populate_sample_data
=>
true
)
{
Ohm
::
redis
.
flushdb
}
config
.
after
(
:all
,
:populate_sample_data
=>
true
)
{
Ohm
::
redis
.
flushdb
}
config
.
before
(
:all
,
:populate_sample_data
=>
true
)
do
config
.
before
(
:all
,
:populate_sample_data
=>
true
)
do
Ohm
::
redis
.
flushdb
Ohm
::
redis
.
flushdb
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://applications"
,
:pattern
=>
"//noah/applications"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://configurations"
,
:pattern
=>
"//noah/configurations"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://hosts"
,
:pattern
=>
"//noah/hosts"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://services"
,
:pattern
=>
"//noah/services"
Noah
::
Watcher
.
create
:endpoint
=>
"dummy://ephemerals"
,
:pattern
=>
"//noah/ephemerals"
h
=
Noah
::
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
h
=
Noah
::
Host
.
create
(
:name
=>
'localhost'
,
:status
=>
"up"
)
if
h
.
save
if
h
.
save
%w[redis noah]
.
each
do
|
service
|
%w[redis noah]
.
each
do
|
service
|
...
...
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