Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some fixes to interaction with monit.

  • Loading branch information...
commit aeec267e206b896dcb7db71d138bff6d292d3598 1 parent 51588ad
@brianjlandau brianjlandau authored
View
2  README.md
@@ -1,3 +1,3 @@
Make sure to add this line to your monit control file:
- include /path/to/watch-dog/monitrc/*.monitrc
+ include /path/to/watch-dog/monitrc/**/*.monitrc
View
4 app/models/site.rb
@@ -37,6 +37,10 @@ def self.http_url
def host
URI.parse(url).host
end
+
+ def monit_check_name
+ "#{host}_#{self.id}"
+ end
private
View
6 app/routes/sites.rb
@@ -40,10 +40,4 @@ class Main
Site.find(params[:id]).delete
redirect '/'
end
-
- post "/sites/:id/status" do
- @site = Site.find(params[:id])
- @site.update_attribute(:status_record, params[:status])
- ""
- end
end
View
8 app/templates/monit_check.mustache
@@ -1,10 +1,10 @@
-check host {{host_name}}_{{site_id}} with address {{host_name}}
+check host {{monit_check_name}} with address {{host_name}}
if failed url {{url}}
- {{#match_text?}}and content != "{{match_text}}"{{/match_text?}}
+ {{#match_text?}}and content == "{{match_text}}" {{/match_text?}}
for {{threshold}} cycles
- then exec "{{curl_bin_dir}}/curl -fs -d status=fail http://{{watch_dog_host}}/sites/{{site_id}}/status"
+ then alert
else if succeeded
- then exec "{{curl_bin_dir}}/curl -fs -d status=success http://{{watch_dog_host}}/sites/{{site_id}}/status"
+ then alert
alert {{email}} with mail-format {
subject: [WATCH DOG] $EVENT for {{site_name}}
message: As of $DATE {{site_name}} is $EVENT:
View
12 app/views/monit_check.rb
@@ -6,12 +6,8 @@ def initialize(site)
@site = site
end
- def watch_dog_host
- settings :host_name
- end
-
- def curl_bin_dir
- settings :curl_bin_dir
+ def monit_check_name
+ @site.monit_check_name
end
def site_name
@@ -38,10 +34,6 @@ def match_text
@site.match_text
end
- def site_id
- @site.id
- end
-
def email
@site.email
end
View
2  config/settings.example.yml
@@ -1,7 +1,5 @@
defaults: &defaults
:log_level: warn
- :host_name: watch-dog.local
- :curl_bin_dir: "/usr/bin"
:monit_bin_dir: "/usr/local/bin"
:monit_cli_options: "-d 60 -c /path/to/monitrc"
View
20 test/stories/sites_test.rb
@@ -111,26 +111,6 @@ class SitesTest < Test::Unit::TestCase
end
end
- story "monit should be able update the satus of a site" do
- scenario "monit hits the API endpoint with a success status" do
- site = Factory(:site)
-
- visit "/sites/#{site.id}/status", :post, {:status => "success"}
-
- site = Site.find(site.id)
- assert_equal "success", site.status_record
- end
-
- scenario "monit hits the API endpoint with a fail status" do
- site = Factory(:site)
-
- visit "/sites/#{site.id}/status", :post, {:status => "fail"}
-
- site = Site.find(site.id)
- assert_equal "fail", site.status_record
- end
- end
-
teardown do
FileUtils.rm_f(Dir["monitrc/#{RACK_ENV}/*.monitrc"])
end
Please sign in to comment.
Something went wrong with that request. Please try again.