示例#1
0
文件: config.py 项目: decanio/broctl
    def __init__(self, config, basedir, version):
        global Config
        Config = self

        self.config = {}
        self.state = {}

        # Read broctl.cfg.
        self.config = self._readConfig(config)

        # Set defaults for options we get passed in.
        self._setOption("brobase", basedir)
        self._setOption("version", version)

        # Initialize options.
        for opt in options.options:
            if not opt.dontinit:
                self._setOption(opt.name, opt.default)

        # Set defaults for options we derive dynamically.
        self._setOption("mailto", "%s" % os.getenv("USER"))
        self._setOption("mailfrom", "Big Brother <bro@%s>" % socket.gethostname())
        self._setOption("home", os.getenv("HOME"))
        self._setOption("mailalarmsto", self.config["mailto"])

        # Determine operating system.
        (success, output) = execute.captureCmd("uname")
        if not success:
            util.error("cannot run uname")
        self._setOption("os", output[0].lower().strip())

        # Find the time command (should be a GNU time for best results).
        (success, output) = execute.captureCmd("which time")
        self._setOption("time", output[0].lower().strip())
示例#2
0
    def __init__(self, config, basedir, version):
        global Config
        Config = self

        self.config = {}
        self.state = {}

        # Read broctl.cfg.
        self.config = self._readConfig(config)

        # Set defaults for options we get passed in.
        self._setOption("brobase", basedir)
        self._setOption("version", version)

        # Initialize options.
        for opt in options.options:
            if not opt.dontinit:
                self._setOption(opt.name.lower(), opt.default)

        # Set defaults for options we derive dynamically.
        self._setOption("mailto", "%s" % os.getenv("USER"))
        self._setOption("mailfrom",
                        "Big Brother <bro@%s>" % socket.gethostname())
        self._setOption("home", os.getenv("HOME"))
        self._setOption("mailalarmsto", self.config["mailto"])

        # Determine operating system.
        (success, output) = execute.captureCmd("uname")
        if not success:
            util.error("cannot run uname")
        self._setOption("os", output[0].lower().strip())

        # Find the time command (should be a GNU time for best results).
        (success, output) = execute.captureCmd("which time")
        self._setOption("time", output[0].lower().strip())
示例#3
0
文件: cron.py 项目: zhezhe168/telex
def _updateHTTPStats():

    # Get the prof.logs.
    _getProfLogs()

    # Copy stats.dat.
    shutil.copy(config.Config.statslog, config.Config.statsdir)

    # Creat meta file. 
    meta = open(os.path.join(config.Config.statsdir, "meta.dat"), "w")
    for node in config.Config.hosts():
        print >>meta, "node", node.tag, node.type, node.host

    print >>meta, "time", time.asctime()
    print >>meta, "version", config.Config.version

    try:
        print >>meta, "os", execute.captureCmd("uname -a")[1][0]
    except IndexError:
        print >>meta, "os <error>"

    try:
        print >>meta, "host", execute.captureCmd("hostname")[1][0]
    except IndexError:
        print >>meta, "host <error>"

    meta.close()
示例#4
0
    def __init__(self, config, basedir, distdir, version, standalone):
        global Config
        global Installing

        Config = self

        if "BROCTL_INSTALL" in os.environ:
            Installing = True
            
            global BroBase
            BroBase = basedir
            
            if "MAKE_DESTDIR" in os.environ:
                global MakeDestDir
                MakeDestDir = os.environ["MAKE_DESTDIR"]

        self.config = {}
        self.state = {}

        # Read broctl.cfg.
        self.config = self._readConfig(os.path.join(basedir, config))

        # Set defaults for options we get passed in.
        self._setOption("brobase", basedir)
        self._setOption("distdir", distdir)
        self._setOption("version", version)
        self._setOption("standalone", standalone and "1" or "0")
		
		# Initialize options.
        for opt in options.options:
            if not opt.dontinit:
                self._setOption(opt.name.lower(), opt.default)
		
		# Set defaults for options we derive dynamically.
		self._setOption("mailto", "%s" % os.getenv("USER"))
		self._setOption("mailfrom", "Big Brother <bro@%s>" % socket.gethostname())
		self._setOption("home", os.getenv("HOME"))
		self._setOption("mailalarmsto", self.config["mailto"]) 
		
        # Determine operating system.
        (success, output) = execute.captureCmd("uname")
        if not success:
            util.error("cannot run uname")
        self._setOption("os", output[0].lower().strip())

        # Find the time command (should be a GNU time for best results).
        (success, output) = execute.captureCmd("which time")
        self._setOption("time", output[0].lower().strip())
		
        # Read nodes.cfg and broctl.dat.
        self._readNodes()
        self.readState()

        # Setup the kinds of analyses which we support.
        self._analysis = Analysis(self.analysiscfg)

        # Make sure cron flag is cleared.
        self.config["cron"] = "0"
示例#5
0
文件: config.py 项目: decanio/broctl
    def determineBroVersion(self):
        version = None
        bro = self.subst("${bindir}/bro")
        if execute.exists(None, bro):
            (success, output) = execute.captureCmd("%s -v 2>&1" % bro)
            if success:
                version = output[len(output)-1]

        if not version:
            # Ok if it's already set.
            if "broversion" in self.state:
                return

            util.error("cannot find Bro binary to determine version")

        m = re.search(".* version ([^ ]*).*$", version)
        if not m:
            util.error("cannot determine Bro version [%s]" % version.strip())

        version = m.group(1)
        if version.endswith("-debug"):
            version = version[:-6]

        self.state["broversion"] = version
        self.state["bro"] = self.subst("${bindir}/bro")
示例#6
0
    def determineBroVersion(self):
        version = None
        bro = self.subst("${bindir}/bro")
        if execute.exists(None, bro):
            (success, output) = execute.captureCmd("%s -v 2>&1" % bro)
            if success:
                version = output[len(output) - 1]

        if not version:
            # Ok if it's already set.
            if "broversion" in self.state:
                return

            util.error("cannot find Bro binary to determine version")

        m = re.search(".* version ([^ ]*).*$", version)
        if not m:
            util.error("cannot determine Bro version [%s]" % version.strip())

        version = m.group(1)
        if version.endswith("-debug"):
            version = version[:-6]

        self.state["broversion"] = version
        self.state["bro"] = self.subst("${bindir}/bro")
示例#7
0
文件: cron.py 项目: sunchen92/OFM
def _updateHTTPStats():
    # Get the prof.logs.

    # FIXME: Disabled for now. This currently copies the complete prof.log
    # each time. As these can get huge, that can take a while. We should
    # change that to only copy the most recent chunk and then also expire old
    # prof logs on the manager.
    # _getProfLogs()

    # Create meta file.
    if not os.path.exists(config.Config.statsdir):
        util.warn("creating directory for stats file: %s" %
                  config.Config.statsdir)
        os.makedirs(config.Config.statsdir)

    meta = open(os.path.join(config.Config.statsdir, "meta.dat"), "w")
    for node in config.Config.hosts():
        print >> meta, "node", node, node.type, node.host

    print >> meta, "time", time.asctime()
    print >> meta, "version", config.Config.version

    try:
        print >> meta, "os", execute.captureCmd("uname -a")[1][0]
    except IndexError:
        print >> meta, "os <error>"

    try:
        print >> meta, "host", execute.captureCmd("hostname")[1][0]
    except IndexError:
        print >> meta, "host <error>"

    meta.close()

    # Run the update-stats script.
    (success, output) = execute.runLocalCmd(
        os.path.join(config.Config.scriptsdir, "update-stats"))

    if not success:
        util.output("error running update-stats\n\n")
        util.output(output)
示例#8
0
def _updateHTTPStats():
    # Get the prof.logs.

    # FIXME: Disabled for now. This currently copies the complete prof.log
    # each time. As these can get huge, that can take a while. We should
    # change that to only copy the most recent chunk and then also expire old
    # prof logs on the manager.
    # _getProfLogs()

    # Create meta file.
    if not os.path.exists(config.Config.statsdir):
        util.warn("creating directory for stats file: %s" % config.Config.statsdir)
        os.makedirs(config.Config.statsdir)

    meta = open(os.path.join(config.Config.statsdir, "meta.dat"), "w")
    for node in config.Config.hosts():
        print >>meta, "node", node, node.type, node.host

    print >>meta, "time", time.asctime()
    print >>meta, "version", config.Config.version

    try:
        print >>meta, "os", execute.captureCmd("uname -a")[1][0]
    except IndexError:
        print >>meta, "os <error>"

    try:
        print >>meta, "host", execute.captureCmd("hostname")[1][0]
    except IndexError:
        print >>meta, "host <error>"

    meta.close()

    # Run the update-stats script.
    (success, output) = execute.runLocalCmd(os.path.join(config.Config.scriptsdir, "update-stats"))

    if not success:
        util.output("error running update-stats\n\n")
        util.output(output)
示例#9
0
文件: util.py 项目: zhezhe168/telex
def sendMail(subject, body):
    cmd = "%s '%s'" % (os.path.join(config.Config.scriptsdir, "send-mail"), subject)
    (success, output) = execute.captureCmd(cmd, "", body)
    if not success:
        warn("cannot send mail")