Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge branch 'unix-interface'
Browse files Browse the repository at this point in the history
  • Loading branch information
dce committed Oct 23, 2009
2 parents 002fe79 + 91dca13 commit 52b4045
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
13 changes: 11 additions & 2 deletions app/models/site.rb
Expand Up @@ -35,10 +35,19 @@ def self.http_url
validates_format_of :email, :with => Regex.email, :allow_nil => true
validates_format_of :url, :with => Regex.http_url, :allow_nil => true

def self.statuses
output = `monit summary `.scan(/Remote Host '.*_(\d+)'[ ]*(.*)$/)

output.inject({}) do |coll, (site_id, status)|
coll[site_id.to_i] = (status == "online with all services" ? "success" : "fail")
coll
end
end

def host
URI.parse(url).host
end

def monit_check_name
"#{host}_#{self.id}"
end
Expand All @@ -56,7 +65,7 @@ def create_monit_check

return true
end

def delete_monit_check
FileUtils.rm_f root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
Monit.reload
Expand Down
2 changes: 0 additions & 2 deletions app/templates/monit_check.mustache
Expand Up @@ -3,8 +3,6 @@ check host {{monit_check_name}} with address {{host_name}}
{{#match_text?}}and content == "{{match_text}}" {{/match_text?}}
for {{threshold}} cycles
then alert
else if succeeded
then alert
alert {{email}} with mail-format {
subject: [WATCH DOG] $EVENT for {{site_name}}
message: As of $DATE {{site_name}} is $EVENT:
Expand Down
4 changes: 3 additions & 1 deletion app/views/index.rb
Expand Up @@ -4,12 +4,14 @@ class Index < Mustache
include Main::Helpers::AppHelper

def sites
summaries = Site.statuses

Site.all.map do |site|
{
:id => site.id,
:name => site.name,
:url => site.url,
:status => site.status_record
:status => summaries[site.id]
}
end
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/002_remove_site_status.rb
@@ -0,0 +1,9 @@
class RemoveSiteStatus < ActiveRecord::Migration
def self.up
remove_column :sites, :status_record
end

def self.down
add_column :sites, :status_record, :string
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Expand Up @@ -9,15 +9,14 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 1) do
ActiveRecord::Schema.define(:version => 2) do

create_table "sites", :force => true do |t|
t.string "name"
t.string "url"
t.text "match_text"
t.integer "threshold"
t.string "email"
t.string "status_record"
t.datetime "created_at"
t.datetime "updated_at"
end
Expand Down

0 comments on commit 52b4045

Please sign in to comment.