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

Commit

Permalink
Some fixes to interaction with monit.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjlandau committed Oct 22, 2009
1 parent 51588ad commit aeec267
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 43 deletions.
2 changes: 1 addition & 1 deletion 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
4 changes: 4 additions & 0 deletions app/models/site.rb
Expand Up @@ -37,6 +37,10 @@ def self.http_url
def host
URI.parse(url).host
end

def monit_check_name
"#{host}_#{self.id}"
end

private

Expand Down
6 changes: 0 additions & 6 deletions app/routes/sites.rb
Expand Up @@ -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
8 changes: 4 additions & 4 deletions 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:
Expand Down
12 changes: 2 additions & 10 deletions app/views/monit_check.rb
Expand Up @@ -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
Expand All @@ -38,10 +34,6 @@ def match_text
@site.match_text
end

def site_id
@site.id
end

def email
@site.email
end
Expand Down
2 changes: 0 additions & 2 deletions 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"

Expand Down
20 changes: 0 additions & 20 deletions test/stories/sites_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit aeec267

Please sign in to comment.