Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pulling status info from monit summary

  • Loading branch information...
commit 0aba07a6ecacdb6887027100a84f58c583ed5b20 1 parent 76620de
@dce dce authored
View
13 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"
View
2  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:
View
4 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
Please sign in to comment.
Something went wrong with that request. Please try again.