except ValueError, err: print "Error: %s" % (err) sys.exit(1) except: print "notify: Error loading configuration." sys.exit(1) for apath in CONF['path'].split(':'): if os.path.isdir(apath): sys.path.append(apath) from Notifier import Notifier recp = '' if dryrun else args[0] msg = " ".join(args[1:]) for name in set(re.split('[\s,]+', CONF['notifier'])): try: cnf = CONF[name] klass = cnf['class'] if 'class' in cnf else name notifier = Notifier.new(klass, cnf) resp = 'Test success' if dryrun else notifier.notify(recp, msg) if debug: print("%s('%s', '%s') = %s\n" % (name, recp, msg, resp)) except Exception as ex: # Call all exceptions so that every configured notifier is visited. err = "%s %s = %s -- message = %s" % (time.strftime( "%Y-%m-%dT%H:%M:%S"), ex.__class__.__name__, str(ex), msg) try: flog = Notifier.new("Logfile", CONF['errorlog']) flog.notify(recp, err) except Exception as ex: sys.stderr.write("%s\n" % (err)) sys.exit(0)
CONF.update(json.load(open(conf, 'r'), 'utf-8')) except ValueError, err: print "Error: %s" % (err) sys.exit(1) except: print "notify: Error loading configuration." sys.exit(1) for apath in CONF['path'].split(':'): if os.path.isdir(apath): sys.path.append(apath) from Notifier import Notifier recp = '' if dryrun else args[0] msg = " ".join(args[1:]) for name in set(re.split('[\s,]+', CONF['notifier'])): try: cnf = CONF[name] klass = cnf['class'] if 'class' in cnf else name notifier = Notifier.new(klass, cnf) resp = 'Test success' if dryrun else notifier.notify(recp, msg) if debug: print("%s('%s', '%s') = %s\n" % (name, recp, msg, resp)) except Exception as ex: # Call all exceptions so that every configured notifier is visited. err = "%s %s = %s -- message = %s" % (time.strftime("%Y-%m-%dT%H:%M:%S"), ex.__class__.__name__, str(ex), msg) try: flog = Notifier.new("Logfile", CONF['errorlog']) flog.notify(recp, err) except Exception as ex: sys.stderr.write("%s\n" % (err)) sys.exit(0)