Permalink
Browse files

merge from origin/master

  • Loading branch information...
2 parents 60a01ae + ea4b903 commit a389164ac06934889312e92302a69036e9a6f875 @cndreisbach cndreisbach committed Oct 22, 2009
View
@@ -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
@@ -23,6 +23,7 @@ def self.http_url
end
after_save :create_monit_check
+ after_destroy :delete_monit_check
validates_presence_of :name
validates_presence_of :url
@@ -37,6 +38,10 @@ def self.http_url
def host
URI.parse(url).host
end
+
+ def monit_check_name
+ "#{host}_#{self.id}"
+ end
private
@@ -51,4 +56,11 @@ 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"
+
+ return true
+ end
end
View
@@ -37,18 +37,7 @@ class Main
end
delete "/sites/:id" do
- Site.find(params[:id]).delete
+ Site.find(params[:id]).destroy
redirect '/'
end
-
- post "/sites/:id/status" do
- @site = Site.find(params[:id])
- @site.update_attribute(:status_record, params[:status])
- ""
- end
-
- get "/watchdog.css" do
- content_type 'text/css', :charset => 'utf-8'
- sass :stylesheet
- end
end
@@ -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
@@ -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
@@ -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
@@ -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
View
@@ -77,6 +77,26 @@ def system(*args); end
@site.save
end
+
+ context 'that has been saved' do
+ setup do
+ @site.save
+ end
+
+ should 'remove monitrc file when destroyed' do
+ @site.destroy
+ assert !File.exist?(root_path('monitrc', RACK_ENV, "#{@site.id}.monitrc"))
+ end
+
+ should 'reload monit when destroyed' do
+ @site.class_eval do
+ def system(*args); end
+ end
+ @site.expects(:system).with("#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload").returns(true)
+
+ @site.destroy
+ end
+ end
teardown do
unless @site.new_record?

0 comments on commit a389164

Please sign in to comment.