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
82605a8c
Commit
82605a8c
authored
Feb 22, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
missed some files
parent
f46e9723
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
213 deletions
+16
-213
applications.rb
lib/noah/applications.rb
+0
-34
configurations.rb
lib/noah/configurations.rb
+0
-46
hosts.rb
lib/noah/hosts.rb
+0
-53
models.rb
lib/noah/models.rb
+16
-6
services.rb
lib/noah/services.rb
+0
-51
watchers.rb
lib/noah/watchers.rb
+0
-23
No files found.
lib/noah/applications.rb
deleted
100644 → 0
View file @
f46e9723
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'configurations'
)
module
Noah
class
Application
<
Model
collection
:configurations
,
Configuration
def
to_hash
arr
=
[]
configurations
.
sort
.
each
{
|
c
|
arr
<<
c
.
to_hash
}
super
.
merge
(
:name
=>
name
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
,
:configurations
=>
arr
)
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
find
(
opts
).
first
.
nil?
?
(
app
=
create
(
opts
))
:
(
app
=
find
(
opts
).
first
)
if
app
.
valid?
app
.
save
end
app
rescue
Exception
=>
e
e
.
message
end
end
end
end
class
Applications
def
self
.
all
(
options
=
{})
options
.
empty?
?
Application
.
all
.
sort
:
Application
.
find
(
options
).
sort
end
end
end
lib/noah/configurations.rb
deleted
100644 → 0
View file @
f46e9723
module
Noah
class
Configuration
<
Model
attribute
:format
attribute
:body
attribute
:new_record
reference
:application
,
Application
index
:format
index
:body
def
validate
super
assert_present
:format
assert_present
:body
assert_present
:application_id
assert_unique
[
:name
,
:application_id
]
end
def
to_hash
Application
[
application_id
].
nil?
?
app_name
=
nil
:
app_name
=
Application
[
application_id
].
name
super
.
merge
(
:name
=>
name
,
:format
=>
format
,
:body
=>
body
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
,
:application
=>
app_name
)
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
if
find
(
opts
).
first
.
nil?
conf
=
create
(
opts
)
else
conf
=
find
(
opts
).
first
end
rescue
Exception
=>
e
e
.
message
end
end
end
end
class
Configurations
def
self
.
all
(
options
=
{})
options
.
empty?
?
Configuration
.
all
.
sort
:
Configuration
.
find
(
options
).
sort
end
end
end
lib/noah/hosts.rb
deleted
100644 → 0
View file @
f46e9723
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'services'
)
module
Noah
class
Host
<
Model
# Host model
# @return {Host} a {Host} object
attribute
:status
collection
:services
,
Service
index
:status
def
validate
super
assert_present
:status
assert_unique
:name
assert_member
:status
,
[
"up"
,
"down"
,
"pending"
]
end
# @return [Hash] A hash representation of a {Host}
def
to_hash
arr
=
[]
services
.
sort
.
each
{
|
s
|
arr
<<
s
.
to_hash
}
h
=
{
:name
=>
name
,
:status
=>
status
,
:created_at
=>
created_at
,
:updated_at
=>
updated_at
,
:services
=>
arr
}
super
.
merge
(
h
)
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
# exclude requested status from lookup
h
=
find
(
opts
.
reject
{
|
key
,
value
|
key
==
:status
}).
first
host
=
h
.
nil?
?
create
(
opts
)
:
h
host
.
status
=
opts
[
:status
]
if
host
.
valid?
host
.
save
end
host
rescue
Exception
=>
e
e
.
message
end
end
end
end
class
Hosts
# @param [Hash] optional filters for results
# @return [Array] Array of {Host} objects
def
self
.
all
(
options
=
{})
options
.
empty?
?
Noah
::
Host
.
all
.
sort
:
Noah
::
Host
.
find
(
options
).
sort
end
end
end
lib/noah/models.rb
View file @
82605a8c
...
...
@@ -35,11 +35,21 @@ module Noah
@deleted_name
=
self
.
name
end
def
dbnum
require
'uri'
o
=
Ohm
.
options
.
first
if
o
[
:db
].
nil?
&&
o
[
:url
].
nil?
# We're on db 0
"0"
else
o
[
:db
].
nil?
?
"
#{
o
[
:url
].
split
(
'/'
).
last
}
"
:
"
#{
o
[
:db
]
}
"
end
end
[
"save"
,
"create"
,
"update"
,
"delete"
].
each
do
|
meth
|
class_eval
do
define_method
(
"notify_via_redis_
#{
meth
}
"
.
to_sym
)
do
self
.
name
.
nil?
?
name
=
@deleted_name
:
name
=
self
.
name
pub_category
=
"noah.
#{
self
.
class
.
to_s
}
[name].
#{
meth
}
"
pub_category
=
"
#{
dbnum
}
:
noah.
#{
self
.
class
.
to_s
}
[name].
#{
meth
}
"
Ohm
.
redis
.
publish
(
pub_category
,
self
.
to_json
)
end
end
...
...
@@ -47,8 +57,8 @@ module Noah
end
end
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'hosts'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'services'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'applications'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'configurations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'watchers'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'
models'
,
'
hosts'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'
models'
,
'
services'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'
models'
,
'
applications'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'
models'
,
'
configurations'
)
require
File
.
join
(
File
.
dirname
(
__FILE__
),
'
models'
,
'
watchers'
)
lib/noah/services.rb
deleted
100644 → 0
View file @
f46e9723
module
Noah
class
Service
<
Model
attribute
:status
reference
:host
,
Host
index
:status
def
validate
super
assert_present
:status
assert_present
:host_id
assert_unique
[
:name
,
:host_id
]
assert_member
:status
,
[
"up"
,
"down"
,
"pending"
]
end
def
to_hash
Host
[
host_id
].
nil?
?
host_name
=
nil
:
host_name
=
Host
[
host_id
].
name
super
.
merge
(
:name
=>
name
,
:status
=>
status
,
:updated_at
=>
updated_at
,
:host
=>
host_name
)
end
class
<<
self
def
find_or_create
(
opts
=
{})
begin
# convert passed host object to host_id if passed
if
opts
.
has_key?
(
:host
)
opts
.
merge!
({
:host_id
=>
opts
[
:host
].
id
})
opts
.
reject!
{
|
key
,
value
|
key
==
:host
}
end
# exclude requested status from lookup
s
=
find
(
opts
.
reject
{
|
key
,
value
|
key
==
:status
}).
first
service
=
s
.
nil?
?
create
(
opts
)
:
s
service
.
status
=
opts
[
:status
]
if
service
.
valid?
service
.
save
end
service
rescue
Exception
=>
e
e
.
message
end
end
end
end
class
Services
def
self
.
all
(
options
=
{})
options
.
empty?
?
Service
.
all
.
sort
:
Service
.
find
(
options
).
sort
end
end
end
lib/noah/watchers.rb
deleted
100644 → 0
View file @
f46e9723
module
Noah
class
Watcher
<
Model
#NYI
attribute
:client
attribute
:endpoint
attribute
:event
attribute
:action
index
:client
index
:event
def
validate
assert_present
:client
,
:endpoint
,
:event
,
:action
assert_unique
[
:client
,
:endpoint
,
:event
,
:action
]
end
end
class
Watchers
def
self
.
all
(
options
=
{})
options
.
empty?
?
Watcher
.
all
.
sort
:
Watcher
.
find
(
options
).
sort
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