SOURCES: nagios-jabber.alert - added html messages support (-x), t...
glen
glen at pld-linux.org
Thu Dec 7 16:40:19 CET 2006
Author: glen Date: Thu Dec 7 15:40:19 2006 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- added html messages support (-x), thx goes to to jajcus
---- Files affected:
SOURCES:
nagios-jabber.alert (1.5 -> 1.6)
---- Diffs:
================================================================
Index: SOURCES/nagios-jabber.alert
diff -u SOURCES/nagios-jabber.alert:1.5 SOURCES/nagios-jabber.alert:1.6
--- SOURCES/nagios-jabber.alert:1.5 Mon Nov 13 10:00:44 2006
+++ SOURCES/nagios-jabber.alert Thu Dec 7 16:40:14 2006
@@ -4,8 +4,9 @@
# glen at pld-linux.org,arekm at pld-linux.org, 2006-10-30 - added ssl support (for gmail.com)
# glen at pld-linux.org 2006-11-03 - made it work with jabber.pld-linux.org again
# glen at pld-linux.org,arekm at pld-linux.org, 2006-11-13 - added config file support
+# glen at pld-linux.org, 2006-12-07 - added html messages support (-x), thx goes to to jajcus
# usage:
-# jabber.alert [-a account_id] [-J from_jid -P password] to_jid1 to_jid2 to_jid3
+# jabber.alert [-x] [-a account_id] [-J from_jid -P password] to_jid1 to_jid2 to_jid3
import os
import re
@@ -13,6 +14,7 @@
import getopt
import string
import time
+import libxml2
from pyxmpp.jid import JID
from pyxmpp.message import Message
@@ -20,15 +22,18 @@
from pyxmpp.streamtls import TLSSettings
try:
- opts, args = getopt.getopt(sys.argv[1:], "J:P:a:")
+ opts, args = getopt.getopt(sys.argv[1:], "J:P:a:x")
except getopt.GetoptError, e:
print "%s: %s " % (sys.argv[0], e)
sys.exit(1)
jid = None
password = None
+html = False
for o, a in opts:
+ if o == '-x':
+ html = True
if o == '-J':
jid = a
if o == '-P':
@@ -73,9 +78,25 @@
class Client(JabberClient):
def session_started(self):
+ if (html == True):
+ import re
+ message = re.sub('<.*?>', '', body)
+ else:
+ message = body
+
for r in recpt:
+
jid_r = JID(r)
- msg = Message(to_jid = jid_r, body = body, subject = subject, stanza_type = message_type)
+ msg = Message(to_jid = jid_r, body = message, subject = subject, stanza_type = message_type)
+
+ if (html == True):
+ node = msg.add_new_content('http://jabber.org/protocol/xhtml-im', 'html')
+ xbody = node.newChild(None, "body", None)
+ html_ns = xbody.newNs('http://www.w3.org/1999/xhtml', None)
+ xbody.setNs(html_ns)
+ doc = libxml2.parseDoc(body)
+ xbody.addChild(doc.getRootElement())
+
self.stream.send(msg)
self.disconnect()
================================================================
---- CVS-web:
http://cvs.pld-linux.org/SOURCES/nagios-jabber.alert?r1=1.5&r2=1.6&f=u
More information about the pld-cvs-commit
mailing list