aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notifiers
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-08 17:24:08 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-08 17:24:08 +0100
commit1ac431fa21907a2a95d87901825cff3dc462746b (patch)
treebee0d55b3fb936bdd77095cdb32970379f4c82d0 /lib/mauve/notifiers
parentfdfd98e5117b269d1f30dfbbd9c1cf2cf037658a (diff)
Added first basic history functionality, and rejigged when notify is called for
an alert.
Diffstat (limited to 'lib/mauve/notifiers')
-rw-r--r--lib/mauve/notifiers/email.rb6
-rw-r--r--lib/mauve/notifiers/sms_aql.rb19
-rw-r--r--lib/mauve/notifiers/templates/email.html.erb6
-rw-r--r--lib/mauve/notifiers/templates/email.txt.erb6
-rw-r--r--lib/mauve/notifiers/templates/xmpp.txt.erb6
-rw-r--r--lib/mauve/notifiers/xmpp.rb12
6 files changed, 39 insertions, 16 deletions
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index 75588f4..129afec 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -47,14 +47,20 @@ module Mauve
message = prepare_message(destination, alert, all_alerts, conditions)
args = [@server, @port]
args += [@username, @password, @login_method.to_sym] if @login_method
+ history = Mauve::History.new(:alert => alert, :type => :notification)
+
begin
Net::SMTP.start(*args) do |smtp|
smtp.send_message(message, @from, destination)
end
+ history.event = "Sent mail to #{destination}."
+ history.save
true
rescue StandardError => ex
logger.error "SMTP failure: #{ex.to_s}"
logger.debug ex.backtrace.join("\n")
+ history.event = "Failed to send mail to #{destination} due to #{ex.to_s}"
+ history.save
false
end
end
diff --git a/lib/mauve/notifiers/sms_aql.rb b/lib/mauve/notifiers/sms_aql.rb
index 856c494..b295e6c 100644
--- a/lib/mauve/notifiers/sms_aql.rb
+++ b/lib/mauve/notifiers/sms_aql.rb
@@ -41,12 +41,19 @@ module Mauve
'Content-Length' => opts_string.length.to_s
})
- raise response unless response.kind_of?(Net::HTTPSuccess)
-
- #
- # Woo -- return true!
- #
- true
+ history = Mauve::History.new(:alert => alert, :type => :notification)
+ if response.kind_of?(Net::HTTPSuccess)
+ history.event = "Sent SMS via AQL to #{destination}"
+ history.save
+ #
+ # Woo -- return true!
+ #
+ true
+ else
+ history.event = "Failed to send SMS via AQL to #{destination} due to #{response.class.to_s}"
+ history.save
+ false
+ end
end
protected
diff --git a/lib/mauve/notifiers/templates/email.html.erb b/lib/mauve/notifiers/templates/email.html.erb
index ab65b48..bf5aed5 100644
--- a/lib/mauve/notifiers/templates/email.html.erb
+++ b/lib/mauve/notifiers/templates/email.html.erb
@@ -2,10 +2,10 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title></head><body>
<p><strong><%= alert.update_type.upcase %>:</strong> <%
-case alert.update_type.to_sym
-when :cleared
+case alert.update_type
+when "cleared"
%><%= alert.cleared_at.to_s_relative %><%
-when :acknowledged
+when "acknowledged"
%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by%><%
else
%><%= alert.raised_at.to_s_relative %><%
diff --git a/lib/mauve/notifiers/templates/email.txt.erb b/lib/mauve/notifiers/templates/email.txt.erb
index 57b9309..d112718 100644
--- a/lib/mauve/notifiers/templates/email.txt.erb
+++ b/lib/mauve/notifiers/templates/email.txt.erb
@@ -1,8 +1,8 @@
<%= alert.update_type.upcase %>: <%
-case alert.update_type.to_sym
-when :cleared
+case alert.update_type
+when "cleared"
%><%= alert.cleared_at.to_s_relative %><%
-when :acknowledged
+when "acknowledged"
%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by %><%
else
%><%= alert.raised_at.to_s_relative %><%
diff --git a/lib/mauve/notifiers/templates/xmpp.txt.erb b/lib/mauve/notifiers/templates/xmpp.txt.erb
index 331d7ef..2f86cb6 100644
--- a/lib/mauve/notifiers/templates/xmpp.txt.erb
+++ b/lib/mauve/notifiers/templates/xmpp.txt.erb
@@ -1,8 +1,8 @@
<%= alert.update_type.upcase %>: <%
-case alert.update_type.to_sym
-when :cleared
+case alert.update_type
+when "cleared"
%><%= alert.cleared_at.to_s_relative %><%
-when :acknowledged
+when "acknowledged"
%><%= alert.acknowledged_at.to_s_relative %> by <%= alert.acknowledged_by %><%
else
%><%= alert.raised_at.to_s_relative %><%
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index 4c30643..c4e1785 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -203,7 +203,17 @@ module Mauve
alert.to_s
end
- send_message(destination_jid, txt)
+ history = Mauve::History.new(:alert_id => alert.id, :type => :notification)
+
+ if send_message(destination_jid, txt)
+ history.event = "Sent XMPP message to #{destination_jid}"
+ history.save
+ true
+ else
+ history.event = "Failed to send XMPP message to #{destination_jid}"
+ history.save
+ false
+ end
end
# Sends a message to the destionation.