From 0aba07a6ecacdb6887027100a84f58c583ed5b20 Mon Sep 17 00:00:00 2001 From: David Eisinger Date: Fri, 23 Oct 2009 15:17:06 -0400 Subject: [PATCH 1/2] Pulling status info from monit summary --- app/models/site.rb | 13 +++++++++++-- app/templates/monit_check.mustache | 2 -- app/views/index.rb | 4 +++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index ecd40cd..9d34204 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -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") system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload" diff --git a/app/templates/monit_check.mustache b/app/templates/monit_check.mustache index e537430..601a3f0 100644 --- a/app/templates/monit_check.mustache +++ b/app/templates/monit_check.mustache @@ -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: diff --git a/app/views/index.rb b/app/views/index.rb index 592058a..ab8d021 100644 --- a/app/views/index.rb +++ b/app/views/index.rb @@ -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 From 91dca1329d143c45b6c4ca717b6848c2cb5a6ba2 Mon Sep 17 00:00:00 2001 From: David Eisinger Date: Fri, 23 Oct 2009 15:23:48 -0400 Subject: [PATCH 2/2] Removed site status field --- db/migrate/002_remove_site_status.rb | 9 +++++++++ db/schema.rb | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 db/migrate/002_remove_site_status.rb diff --git a/db/migrate/002_remove_site_status.rb b/db/migrate/002_remove_site_status.rb new file mode 100644 index 0000000..c1d9f3c --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 29632a2..1b384eb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # 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" @@ -17,7 +17,6 @@ t.text "match_text" t.integer "threshold" t.string "email" - t.string "status_record" t.datetime "created_at" t.datetime "updated_at" end