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

Commit

Permalink
Pulling status info from monit summary
Browse files Browse the repository at this point in the history
  • Loading branch information
dce committed Oct 23, 2009
1 parent 76620de commit 0aba07a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 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 :email, :with => Regex.email, :allow_nil => true
validates_format_of :url, :with => Regex.http_url, :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 def host
URI.parse(url).host URI.parse(url).host
end end

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


return true return true
end end

def delete_monit_check def delete_monit_check
FileUtils.rm_f root_path('monitrc', RACK_ENV, "#{self.id}.monitrc") FileUtils.rm_f root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload" system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} 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?}} {{#match_text?}}and content == "{{match_text}}" {{/match_text?}}
for {{threshold}} cycles for {{threshold}} cycles
then alert then alert
else if succeeded
then alert
alert {{email}} with mail-format { alert {{email}} with mail-format {
subject: [WATCH DOG] $EVENT for {{site_name}} subject: [WATCH DOG] $EVENT for {{site_name}}
message: As of $DATE {{site_name}} is $EVENT: 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 include Main::Helpers::AppHelper


def sites def sites
summaries = Site.statuses

Site.all.map do |site| Site.all.map do |site|
{ {
:id => site.id, :id => site.id,
:name => site.name, :name => site.name,
:url => site.url, :url => site.url,
:status => site.status_record :status => summaries[site.id]
} }
end end
end end
Expand Down

0 comments on commit 0aba07a

Please sign in to comment.