aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/notifiers/xmpp.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-13 11:02:37 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-13 11:02:37 +0100
commitb22cbc87927553f6dbb5754281e95fe9bad2eed1 (patch)
tree5575791fe84492648a8cc92433c267815056507a /lib/mauve/notifiers/xmpp.rb
parent495c44445642cfae8f23fadde299ad5307f5be58 (diff)
* Tidied up mauveserver to handle HUP restarts
* Added HTML santizing to the alert class, so bad HTML is stripped as part of processing. * Alert#cleared? now means "not raised" * Better error handling in the Timer class, making sure that the timer never gets permanently frozen. * Moved notification and packet buffers to the Server class, meaning that if the Processor or Notifier threads crash, we don't lose all the items waiting to be processed/notified. * XMPP/Email Alerts now use templates, instead of instance methods. * Emails now get sent as multipart with HTML to allow detail fields to be shown as nature intended.
Diffstat (limited to 'lib/mauve/notifiers/xmpp.rb')
-rw-r--r--lib/mauve/notifiers/xmpp.rb23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/mauve/notifiers/xmpp.rb b/lib/mauve/notifiers/xmpp.rb
index fbc9640..4c30643 100644
--- a/lib/mauve/notifiers/xmpp.rb
+++ b/lib/mauve/notifiers/xmpp.rb
@@ -165,18 +165,10 @@ module Mauve
end
end
+ #
# Takes an alert and converts it into a message.
#
- # @param [Alert] alert The alert to convert.
- # @return [String] The message, either as HTML.
def convert_alert_to_message(alert)
- arr = alert.summary_three_lines
- str = arr[0] + ": " + arr[1]
- str += " -- " + arr[2] if false == arr[2].nil?
- str += "."
- return str
- #return alert.summary_two_lines.join(" -- ")
- #return "<p>" + alert.summary_two_lines.join("<br />") + "</p>"
end
# Attempt to send an alert using XMPP.
@@ -201,8 +193,17 @@ module Mauve
logger.info("Alert conditions not met, not sending XMPP alert to #{destination_jid}")
return false
end
+
+ template_file = File.join(File.dirname(__FILE__),"templates","xmpp.txt.erb")
+
+ txt = if File.exists?(template_file)
+ ERB.new(File.read(template_file)).result(binding).chomp
+ else
+ logger.error("Could not find xmpp.txt.erb template")
+ alert.to_s
+ end
- send_message(destination_jid, convert_alert_to_message(alert))
+ send_message(destination_jid, txt)
end
# Sends a message to the destionation.
@@ -413,7 +414,7 @@ module Mauve
if @mucs[msg.from.strip].is_a?(MUC::MUCClient) and
msg.from != @mucs[msg.from.strip].jid and
msg.x("jabber:x:delay") == nil and
- (msg.body =~ /\b#{Regexp.escape(@client.jid.resource)}\b/i or
+ (msg.body =~ /\b#{Regexp.escape(@mucs[msg.from.strip].jid.resource)}\b/i or
msg.body =~ /\b#{Regexp.escape(@client.jid.node)}\b/i)
receive_normal_message(msg)
end