From e08051b78bae61dd42b48f4f8d9d086823ddbd2a Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Tue, 14 May 2013 13:42:41 +0100 Subject: Database now queried to work out if a notification should be suppressed. --- lib/mauve/notifiers/debug.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/mauve/notifiers') diff --git a/lib/mauve/notifiers/debug.rb b/lib/mauve/notifiers/debug.rb index a9afc52..b3e88e2 100644 --- a/lib/mauve/notifiers/debug.rb +++ b/lib/mauve/notifiers/debug.rb @@ -69,7 +69,7 @@ module Mauve deliver_to_queue << [Time.now, self.class, destination, message] if deliver_to_queue - if @disable_normal_delivery + if @disable_normal_delivery true # pretend it happened OK if we're just testing else send_alert_without_debug(destination, alert, all_alerts, conditions) -- cgit v1.2.3 From bf87bfa0e0add362febf7d376a509c68e0144d7a Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 16 May 2013 12:40:37 +0100 Subject: Alert level now in templates --- .../notifiers/templates/email_subject.txt.erb | 23 +--------------------- lib/mauve/notifiers/templates/sms.txt.erb | 23 +--------------------- lib/mauve/notifiers/templates/xmpp.html.erb | 6 +++--- lib/mauve/notifiers/templates/xmpp.txt.erb | 6 +++--- 4 files changed, 8 insertions(+), 50 deletions(-) mode change 100644 => 120000 lib/mauve/notifiers/templates/email_subject.txt.erb mode change 100644 => 120000 lib/mauve/notifiers/templates/sms.txt.erb (limited to 'lib/mauve/notifiers') diff --git a/lib/mauve/notifiers/templates/email_subject.txt.erb b/lib/mauve/notifiers/templates/email_subject.txt.erb deleted file mode 100644 index 119c742..0000000 --- a/lib/mauve/notifiers/templates/email_subject.txt.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%=alert.id %>: <%= alert.update_type.upcase %>: <% -case alert.update_type -when "cleared" -%><%= alert.cleared_at.to_s_relative %><% -when "acknowledged" -%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by %> until <%= alert.will_unacknowledge_at.to_s_human %><% -else -%><%= alert.raised_at.to_s_relative %><% -end -%>: <%= alert.subject %>: <%= alert.summary %><% -if alert.source != alert.subject -%> -- from <%= alert.source %><% -end -%>. <%=WebInterface.url_for(alert)%><% -if defined? was_suppressed and defined? will_suppress - if was_suppressed and not will_suppress -%> (Normal service has resumed.)<% - elsif will_suppress and not was_suppressed -%> (Further alerts suppressed until things calm down.)<% - end -end -%> diff --git a/lib/mauve/notifiers/templates/email_subject.txt.erb b/lib/mauve/notifiers/templates/email_subject.txt.erb new file mode 120000 index 0000000..802c711 --- /dev/null +++ b/lib/mauve/notifiers/templates/email_subject.txt.erb @@ -0,0 +1 @@ +xmpp.txt.erb \ No newline at end of file diff --git a/lib/mauve/notifiers/templates/sms.txt.erb b/lib/mauve/notifiers/templates/sms.txt.erb deleted file mode 100644 index faec37d..0000000 --- a/lib/mauve/notifiers/templates/sms.txt.erb +++ /dev/null @@ -1,22 +0,0 @@ -<%= alert.update_type.upcase %>: <% -case alert.update_type -when "cleared" -%><%= alert.cleared_at.to_s_relative %><% -when "acknowledged" -%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by %> until <%= alert.will_unacknowledge_at.to_s_human %><% -else -%><%= alert.raised_at.to_s_relative %><% -end -%>: <%= alert.subject %>: <%= alert.summary %><% -if alert.source != alert.subject -%> -- from <%= alert.source %><% -end -%>. <%=WebInterface.url_for(alert)%><% -if defined? was_suppressed and defined? will_suppress - if was_suppressed and not will_suppress -%> (Normal service has resumed.)<% - elsif will_suppress and not was_suppressed -%> (Further alerts suppressed until things calm down.)<% - end -end -%> diff --git a/lib/mauve/notifiers/templates/sms.txt.erb b/lib/mauve/notifiers/templates/sms.txt.erb new file mode 120000 index 0000000..802c711 --- /dev/null +++ b/lib/mauve/notifiers/templates/sms.txt.erb @@ -0,0 +1 @@ +xmpp.txt.erb \ No newline at end of file diff --git a/lib/mauve/notifiers/templates/xmpp.html.erb b/lib/mauve/notifiers/templates/xmpp.html.erb index 12354a2..85bec3b 100644 --- a/lib/mauve/notifiers/templates/xmpp.html.erb +++ b/lib/mauve/notifiers/templates/xmpp.html.erb @@ -1,5 +1,5 @@ -<%= alert.id%>: <%= alert.update_type.upcase %>: <% +<%= alert.id%>: <%= alert.update_type.upcase %> <%= alert.level.to_s.capitalize %>: <% case alert.update_type when "cleared" %><%= alert.cleared_at.to_s_relative %><% @@ -15,9 +15,9 @@ end %>.<% if defined? was_suppressed and defined? will_suppress if was_suppressed and not will_suppress -%>
Normal service has resumed.<% +%>
Normal service for <%= alert.level %> alerts has resumed.<% elsif will_suppress and not was_suppressed -%>
Further alerts suppressed until things calm down.<% +%>
Further <%= alert.level %> alerts suppressed until things calm down.<% end end %> diff --git a/lib/mauve/notifiers/templates/xmpp.txt.erb b/lib/mauve/notifiers/templates/xmpp.txt.erb index f63c96c..63ad000 100644 --- a/lib/mauve/notifiers/templates/xmpp.txt.erb +++ b/lib/mauve/notifiers/templates/xmpp.txt.erb @@ -1,4 +1,4 @@ -<%=alert.id %>: <%= alert.update_type.upcase %>: <% +<%=alert.id %>: <%= alert.update_type.upcase %> <%= alert.level.to_s.capitalize %>: <% case alert.update_type when "cleared" %><%= alert.cleared_at.to_s_relative %><% @@ -14,9 +14,9 @@ end %>. <%=WebInterface.url_for(alert)%><% if defined? was_suppressed and defined? will_suppress if was_suppressed and not will_suppress -%> (Normal service has resumed.)<% +%> (Normal service for <%= alert.level %> alerts has resumed.)<% elsif will_suppress and not was_suppressed -%> (Further alerts suppressed until things calm down.)<% +%> (Further <%= alert.level %> alerts suppressed until things calm down.)<% end end %> -- cgit v1.2.3 From 46e55b62412cea23beba4efb7ee169245619b6de Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Thu, 16 May 2013 14:13:35 +0100 Subject: Updated templates again --- lib/mauve/notifiers/templates/xmpp.html.erb | 2 +- lib/mauve/notifiers/templates/xmpp.txt.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/mauve/notifiers') diff --git a/lib/mauve/notifiers/templates/xmpp.html.erb b/lib/mauve/notifiers/templates/xmpp.html.erb index 85bec3b..7792bd9 100644 --- a/lib/mauve/notifiers/templates/xmpp.html.erb +++ b/lib/mauve/notifiers/templates/xmpp.html.erb @@ -1,5 +1,5 @@ -<%= alert.id%>: <%= alert.update_type.upcase %> <%= alert.level.to_s.capitalize %>: <% +<%= alert.id%>: <%= alert.update_type.upcase %> (<%= alert.level %>): <% case alert.update_type when "cleared" %><%= alert.cleared_at.to_s_relative %><% diff --git a/lib/mauve/notifiers/templates/xmpp.txt.erb b/lib/mauve/notifiers/templates/xmpp.txt.erb index 63ad000..c148f41 100644 --- a/lib/mauve/notifiers/templates/xmpp.txt.erb +++ b/lib/mauve/notifiers/templates/xmpp.txt.erb @@ -1,4 +1,4 @@ -<%=alert.id %>: <%= alert.update_type.upcase %> <%= alert.level.to_s.capitalize %>: <% +<%=alert.id %>: <%= alert.update_type.upcase %> (<%= alert.level %>): <% case alert.update_type when "cleared" %><%= alert.cleared_at.to_s_relative %><% -- cgit v1.2.3 From 65fcea0eac21f95fd4398006551c56bc6760e261 Mon Sep 17 00:00:00 2001 From: James Hannah Date: Mon, 3 Jun 2013 15:35:29 +0100 Subject: Added an SMS provider for clockworksms.com --- etc/mauveserver.conf | 14 ++++++- lib/mauve/notifiers.rb | 1 + lib/mauve/notifiers/sms_clockwork.rb | 72 ++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 lib/mauve/notifiers/sms_clockwork.rb (limited to 'lib/mauve/notifiers') diff --git a/etc/mauveserver.conf b/etc/mauveserver.conf index 4baec0a..75dfb68 100644 --- a/etc/mauveserver.conf +++ b/etc/mauveserver.conf @@ -75,8 +75,8 @@ notification_method("email") { # password "x" # } -# How to notify by SMS - we use aql.com, you'll need to write a module -# to use any other provider. +# How to notify by SMS - we use aql.com, a provider for clockworksms.com +# is also provided. For another provider, you'll need to write a module. # # notification_method("sms") { # provider "AQL" @@ -88,6 +88,16 @@ notification_method("email") { # # Maximum number of SMS messages to concatenate for one notification # max_messages_per_alert 3 # } +# +# notification_method("sms") { +# provider "Clockwork" +# +# apikey "sssseeeeeeccccccccrrrrreeeeeettttsssssss" +# from "01234567890" +# +# # Maximum number of SMS messages to concatenate for one notification +# max_messages_per_alert 3 +# } # Simple default notification preference for root at this machine, at all # alert levels. You probably want more people, see below for a more complete diff --git a/lib/mauve/notifiers.rb b/lib/mauve/notifiers.rb index 7276091..5a7acc0 100644 --- a/lib/mauve/notifiers.rb +++ b/lib/mauve/notifiers.rb @@ -1,6 +1,7 @@ require 'mauve/notifiers/email' require 'mauve/notifiers/sms_default' require 'mauve/notifiers/sms_aql' +require 'mauve/notifiers/sms_clockwork' require 'mauve/notifiers/xmpp' module Mauve diff --git a/lib/mauve/notifiers/sms_clockwork.rb b/lib/mauve/notifiers/sms_clockwork.rb new file mode 100644 index 0000000..b4bd860 --- /dev/null +++ b/lib/mauve/notifiers/sms_clockwork.rb @@ -0,0 +1,72 @@ +require 'mauve/notifiers/debug' +require 'cgi' + +module Mauve + module Notifiers + module Sms + + require 'net/https' + + class Clockwork + GATEWAY = "https://api.clockworksms.com/http/send.aspx" + + attr_writer :apikey, :from + attr_reader :name + + def initialize(name) + @name = name + end + + def send_alert(destination, alert, all_alerts, conditions = {}) + uri = URI.parse(GATEWAY) + + opts_string = { + :key => @apikey, + :to => normalize_number(destination), + :content => prepare_message(destination, alert, all_alerts, conditions), + :from => @from, + }.map { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join("&") + + http = Net::HTTP.new(uri.host, uri.port) + if uri.port == 443 + http.use_ssl = true + http.verify_mode = OpenSSL::SSL::VERIFY_NONE + end + response, data = http.post(uri.path, opts_string, { + 'Content-Type' => 'application/x-www-form-urlencoded', + 'Content-Length' => opts_string.length.to_s + }) + + if response.kind_of?(Net::HTTPSuccess) + # + # Woo -- return true! + # + true + else + false + end + end + + protected + def prepare_message(destination, alert, all_alerts, conditions={}) + was_suppressed = conditions[:was_suppressed] || false + will_suppress = conditions[:will_suppress] || false + + template_file = File.join(File.dirname(__FILE__),"templates","sms.txt.erb") + + txt = if File.exists?(template_file) + ERB.new(File.read(template_file)).result(binding).chomp + else + logger.error("Could not find sms.txt.erb template") + alert.to_s + end + end + + def normalize_number(n) + n.split("").select { |s| (?0..?9).include?(s[0]) }.join.gsub(/^0/, "44") + end + end + end + end +end + -- cgit v1.2.3