From 89fce9020115e2089efa122cd8528e50e0e6601e Mon Sep 17 00:00:00 2001 From: Brian Landau Date: Mon, 26 Oct 2009 14:27:05 -0400 Subject: [PATCH] Allow for multiple email addresses. --- app/models/site.rb | 3 ++- app/templates/monit_check.mustache | 2 ++ app/views/monit_check.rb | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/models/site.rb b/app/models/site.rb index 3c92c75..fe61b5e 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -13,7 +13,8 @@ def self.email email_name_regex = '[A-Z0-9_\.%\+\-]+' domain_head_regex = '(?:[A-Z0-9\-]+\.)+' domain_tld_regex = '(?:[A-Z]{2,4}|museum|travel)' - /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i + full_email = "#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}" + /^#{full_email}(\s*,\s*#{full_email})*$/i end end diff --git a/app/templates/monit_check.mustache b/app/templates/monit_check.mustache index 601a3f0..a49c1bc 100644 --- a/app/templates/monit_check.mustache +++ b/app/templates/monit_check.mustache @@ -3,8 +3,10 @@ check host {{monit_check_name}} with address {{host_name}} {{#match_text?}}and content == "{{match_text}}" {{/match_text?}} for {{threshold}} cycles then alert + {{#emails}} alert {{email}} with mail-format { subject: [WATCH DOG] $EVENT for {{site_name}} message: As of $DATE {{site_name}} is $EVENT: $DESCRIPTION } + {{/emails}} diff --git a/app/views/monit_check.rb b/app/views/monit_check.rb index dbc7024..a39651d 100644 --- a/app/views/monit_check.rb +++ b/app/views/monit_check.rb @@ -22,6 +22,10 @@ def url @site.url end + def emails + @site.email.split(/\s*,\s*/).map {|e| {:email => e} } + end + def threshold @site.threshold end