- for attempt in ('first', 'second'):
- jid = JID(section['jid'])
- resource = "Nagios/" + hashlib.md5(''.join(recpt)).hexdigest()[:10]
- if attempt == 'second':
- # if something went wrong the second time around, it's
- # most likely a resource name conflict on login, so let's
- # wait a bit, randomize the resource name and try again
- resource = resource + '/' + repr(os.getpid())
- time.sleep(0.8)
- if not jid.resource:
- jid = JID(jid.node, jid.domain, resource)
-
- c = Client(jid, section['password'], auth_methods = ['sasl:DIGEST-MD5', 'sasl:PLAIN', 'digest'],
- tls_settings = TLSSettings(require = False, verify_peer = False))
- try:
- c.connect()
- try:
- c.loop(1)
- except XMPPStreamError, e:
- # Most likely a duplicate stream problem
- # don't log anything, just try again
- c.disconnect()
- continue
- except Exception, e:
- err.append("ERROR1: %s: %s" % (section['jid'], e))
- c.disconnect()
- # don't try another attempt, jump straigt to
- # another section
- break
- c.disconnect()
- # stop after first successful attempt at sending the msg
- sys.exit(0)
- except Exception, e:
- err.append("ERROR2: %s: %s" % (section['jid'], e))
+ for attempt in ('first', 'second'):
+ jid = JID(section['jid'])
+ resource = "Nagios/" + hashlib.md5(''.join(recpt)).hexdigest()[:10]
+ if attempt == 'second':
+ # if something went wrong the second time around, it's
+ # most likely a resource name conflict on login, so let's
+ # wait a bit, randomize the resource name and try again
+ resource = resource + '/' + repr(os.getpid())
+ time.sleep(0.8)
+ if not jid.resource:
+ jid = JID(jid.node, jid.domain, resource)
+
+ c = Client(jid, section['password'], auth_methods = ['sasl:DIGEST-MD5', 'sasl:PLAIN', 'digest'],
+ tls_settings = TLSSettings(require = False, verify_peer = False))
+ try:
+ c.connect()
+ try:
+ c.loop(1)
+ except XMPPStreamError, e:
+ # Most likely a duplicate stream problem
+ # don't log anything, just try again
+ c.disconnect()
+ continue
+ except Exception, e:
+ err.append("ERROR1: %s: %s" % (section['jid'], e))
+ c.disconnect()
+ # don't try another attempt, jump straigt to
+ # another section
+ break
+ c.disconnect()
+ # stop after first successful attempt at sending the msg
+ sys.exit(0)
+ except Exception, e:
+ err.append("ERROR2: %s: %s" % (section['jid'], e))