From: Frank L. <fr...@fr...> - 2009-12-01 17:16:18
|
Hello, I'm currently working on a script for server monitoring, specifically the notification module for it. Since we use Jabber in house, I'd like to be able to send alerts this way. Actually sending the alerts was not difficult, however, I cannot find a solution to be able to verify that the person its being sent to is "Available." Currently, it will send it regardless of their status, but if they are offline, they get flooded with messages as soon as they sign on. I've pasted the applicable code below, if anyone could give me some guidance I'd greatly appreciate it. As a bit of background, jabber() is called with all strings as arguments. def jabber(name, jabberid, servername, load, eximcount, type): jid = xmpp.protocol.JID(config.jabberID) cl = xmpp.Client(jid.getDomain(), debug=[]) con = cl.connect() if not con: print "Could not connect to jabber\n" auth = cl.auth(jid.getNode(), config.jabberPass, resource=jid.getResource()) if not auth: print "Could not authenticate to jabber\n" if type == 'exim': msg = "[ALERT]: Too many messages in queue on %s - Current count: %s" % (servername, eximcount) elif type == 'load': msg = "[ALERT]: Processor load high on %s - Current load: %s" % (servername, load) elif type == 'down': msg = "[ALERT]: Server %s is unreachable. - Last recorded load: %s" % (servername, load) else: print "Invalid alert type: '%s'" % (type) id = cl.send(xmpp.protocol.Message(jabberid, msg)) time.sleep(1) print "Jabber alert message sent to %s" % (jabberid) -Frank |