Permalink
Browse files

Merge branch 'unix-interface'

  • Loading branch information...
2 parents 002fe79 + 91dca13 commit 52b404545a6430409be46bf3d7b72435e0731822 @dce dce committed Oct 23, 2009
Showing with 24 additions and 7 deletions.
  1. +11 −2 app/models/site.rb
  2. +0 −2 app/templates/monit_check.mustache
  3. +3 −1 app/views/index.rb
  4. +9 −0 db/migrate/002_remove_site_status.rb
  5. +1 −2 db/schema.rb
View
@@ -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
@@ -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
@@ -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:
View
@@ -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
@@ -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
View
@@ -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

0 comments on commit 52b4045

Please sign in to comment.