def init(options): """Prepare to start up NagCat""" # Set uid/gid/file_limit util.setup(options.user, options.group, options.file_limit, options.core_dumps) # Write out the pid to make the verify script happy if options.pidfile: util.write_pid(options.pidfile) log.init(options.logfile, options.loglevel) config = coil.parse_file(options.config, expand=False) init_plugins(options) try: if options.test: nagcat = simple.NagcatSimple(config, rradir=options.rradir, rrdcache=options.rrdcache, monitor_port=options.status_port, test_name=options.test, host=options.host, port=options.port) else: nagcat = nagios.NagcatNagios(config, rradir=options.rradir, rrdcache=options.rrdcache, monitor_port=options.status_port, nagios_cfg=options.nagios, tag=options.tag) except (errors.InitError, coil.errors.CoilError), ex: log.error(str(ex)) sys.exit(1)
def testExample3(self): root = parse_file(os.path.join(self.path, "example3.coil")) self.assertEquals(root['x'], 1) self.assertEquals(root.get('y.a'), 2) self.assertEquals(root.get('y.x'), 1) self.assertEquals(root.get('y.a2'), 2) self.assertEquals(root.get('y.b'), 3)
def testExample2(self): root = parse_file(os.path.join(self.path, "example2.coil")) self.assertEquals(root.get('sub.x'), "foo") self.assertEquals(root.get('sub.y.a'), "bar") self.assertEquals(root.get('sub.y.x'), "foo") self.assertEquals(root.get('sub.y.a2'), "bar") self.assertEquals(root.get('sub2.y.a'), 2) self.assertEquals(root.get('sub2.y.x'), 1) self.assertEquals(root.get('sub2.y.a2'), 2)
def __init__(self, dir, host, rrd, period="day"): api = twirrdy.RRDBasicAPI() self.rrd = rrd self.host = host path = "%s/%s/%s" % (dir, host, rrd) self.rrd_path = "%s.rrd" % path self.info = api.info(self.rrd_path) self.color = Colorator() self.period = period try: self.conf = coil.parse_file("%s.coil" % path) except IOError, ex: raise errors.InitError("Unable to read coil file: %s" % ex)
def read_config_file(filename): """Read a configuration file in coil format and returns a Struct object (dict-like)""" def fatal(msg): sys.stderr.write("%s\n" % msg) sys.exit(1) config = coil.parse_file(filename, encoding="utf-8") if config.get("@root.datadir") is None: fatal("Config error: empty 'datadir' parameter") to_expand = ("@root.datadir", "@root.plugins.quotes2.db_path", "@root.plugins.markov.db_file") for name in to_expand: path = config.get(name) if path is not None and path.startswith("~"): config.set(name, os.path.expanduser(path)) return config
def main(args): for file in args[1:]: print coil.parse_file(file)
def fromFile(path): """Load a struct from a file, given a path on the filesystem.""" return parse_file(path)
def main(): options, method = parse_options() log.init(options.logfile, options.loglevel) if not options.dump and options.daemonize: if os.fork() > 0: os._exit(0) os.chdir("/") os.setsid() if os.fork() > 0: os._exit(0) log.init_stdio() try: config = coil.parse(DEFAULT_CONFIG) if method.defaults: if isinstance(method.defaults, str): config.merge(coil.parse(method.defaults)) else: config.merge(coil.struct.Struct(method.defaults)) if options.config: config.merge(coil.parse_file(options.config)) except coil.errors.CoilError, ex: log.error("Error parsing config: %s" % ex) sys.exit(1)