Esempio n. 1
0
def update(nodes):

    running = isRunning(nodes)
    zone = config.Config.zoneid
    if zone == "":
        zone = "NOZONE"

    cmds = []
    for (node, isrunning) in running:
        if isrunning:
            env = _makeEnvParam(node)
            env += " BRO_DNS_FAKE=1"
            args = " ".join(_makeBroParams(node, False))
            cmds += [(node.name, os.path.join(config.Config.scriptsdir, "update") + " %s %s %s/tcp %s" % (util.formatBroAddr(node.addr), zone, node.getPort(), args), env, None)]
            util.output("updating %s ..." % node.name)

    results = execute.runLocalCmdsParallel(cmds)

    for (tag, success, output) in results:
        if not success:
            util.output("could not update %s: %s" % (tag, output))
        else:
            util.output("%s: %s" % (tag, output[0]))

    return [(config.Config.nodes(tag=tag)[0], success) for (tag, success, output) in results]
Esempio n. 2
0
def update(nodes):

    running = isRunning(nodes)
    zone = config.Config.zoneid
    if zone == "":
        zone = "NOZONE"

    cmds = []
    for (node, isrunning) in running:
        if isrunning:
            env = _makeEnvParam(node)
            env += " BRO_DNS_FAKE=1"
            args = " ".join(_makeBroParams(node, False))
            cmds += [
                (node.name, os.path.join(config.Config.scriptsdir, "update") +
                 " %s %s %s/tcp %s" %
                 (util.formatBroAddr(node.addr), zone, node.getPort(), args),
                 env, None)
            ]
            util.output("updating %s ..." % node.name)

    results = execute.runLocalCmdsParallel(cmds)

    for (tag, success, output) in results:
        if not success:
            util.output("could not update %s: %s" % (tag, output))
        else:
            util.output("%s: %s" % (tag, output[0]))

    return [(config.Config.nodes(tag=tag)[0], success)
            for (tag, success, output) in results]
Esempio n. 3
0
def _doCheckConfig(nodes, installed, list_scripts):

    results = []

    manager = config.Config.manager()

    all = [(node,
            os.path.join(config.Config.tmpdir, "check-config-%s" % node.name))
           for node in nodes]

    nodes = []
    for (node, cwd) in all:
        if os.path.isdir(cwd):
            if not execute.rmdir(config.Config.manager(), cwd):
                util.output("cannot remove directory %s on manager" % cwd)
                continue

        if not execute.mkdir(config.Config.manager(), cwd):
            util.output("cannot create directory %s on manager" % cwd)
            continue

        nodes += [(node, cwd)]

    cmds = []
    for (node, cwd) in nodes:

        env = _makeEnvParam(node)

        installed_policies = installed and "1" or "0"
        print_scripts = list_scripts and "1" or "0"

        install.makeLayout(cwd, True)
        install.makeLocalNetworks(cwd, True)
        install.makeConfig(cwd, True)

        cmd = os.path.join(
            config.Config.scriptsdir, "check-config") + " %s %s %s %s" % (
                installed_policies, print_scripts, cwd, " ".join(
                    _makeBroParams(node, False)))
        cmd += " broctl/check"

        cmds += [((node, cwd), cmd, env, None)]

    for ((node, cwd), success, output) in execute.runLocalCmdsParallel(cmds):
        if success:
            util.output("%s is ok." % node.name)
            if list_scripts:
                for line in output:
                    util.output("  %s" % line)
        else:
            ok = False
            util.output("%s failed." % node.name)
            for line in output:
                util.output("   %s" % line)

        execute.rmdir(manager, cwd)

    return results
Esempio n. 4
0
def _doCheckConfig(nodes, installed, list_scripts):

    results = []

    manager = config.Config.manager()

    all = [(node, os.path.join(config.Config.tmpdir, "check-config-%s" % node.name)) for node in nodes]

    nodes = []
    for (node, cwd) in all:
        if os.path.isdir(cwd):
            if not execute.rmdir(config.Config.manager(), cwd):
                util.output("cannot remove directory %s on manager" % cwd)
                continue

        if not execute.mkdir(config.Config.manager(), cwd):
            util.output("cannot create directory %s on manager" % cwd)
            continue

        nodes += [(node, cwd)]

    cmds = []
    for (node, cwd) in nodes:

        env = _makeEnvParam(node)

        installed_policies = installed and "1" or "0"
        print_scripts = list_scripts and "1" or "0"

        install.makeLayout(cwd, True)
        install.makeLocalNetworks(cwd, True)
        install.makeConfig(cwd, True)

        cmd = os.path.join(config.Config.scriptsdir, "check-config") + " %s %s %s %s" % (installed_policies, print_scripts, cwd, " ".join(_makeBroParams(node, False)))
        cmd += " broctl/check"

        cmds += [((node, cwd), cmd, env, None)]

    for ((node, cwd), success, output) in execute.runLocalCmdsParallel(cmds):
        results += [(node, success)]
        if success:
            util.output("%s is ok." % node.name)
            if list_scripts:
                for line in output:
                    util.output("  %s" % line)
        else:
            ok = False
            util.output("%s failed." % node.name)
            for line in output:
                util.output("   %s" % line)

        execute.rmdir(manager, cwd)

    return results
Esempio n. 5
0
def _getProfLogs():
    cmds = []

    for node in config.Config.hosts():
        if not execute.isAlive(node.addr):
            continue

        cmd = os.path.join(config.Config.scriptsdir, "get-prof-log") + " %s %s %s/prof.log" % (node.name, node.host, node.cwd())
        cmds += [(node, cmd, [], None)]

    for (node, success, output) in execute.runLocalCmdsParallel(cmds):
        if not success:
            util.output("cannot get prof.log from %s" % node.name)
Esempio n. 6
0
def _getProfLogs():
    cmds = []

    for node in config.Config.hosts():
        if not execute.isAlive(node.addr):
            continue

        cmd = os.path.join(config.Config.scriptsdir,
                           "get-prof-log") + " %s %s %s/prof.log" % (
                               node.name, node.host, node.cwd())
        cmds += [(node, cmd, [], None)]

    for (node, success, output) in execute.runLocalCmdsParallel(cmds):
        if not success:
            util.output("cannot get prof.log from %s" % node.name)
Esempio n. 7
0
def _getProfLogs():        

    dir = config.Config.statsdir
    if not os.path.exists(dir):
        os.mkdir(dir)

    if not os.path.exists(dir) or not os.path.isdir(dir):
        util.output("cannot create directory %s" % dir)
        return

    cmds = []

    for node in config.Config.hosts():
        cmd = os.path.join(config.Config.scriptsdir, "get-prof-log") + " %s %s %s/prof.log" % (node.tag, node.host, node.cwd())
        cmds += [(node, cmd, [], None)]

    for (node, success, output) in execute.runLocalCmdsParallel(cmds):
        if not success:
            util.output("cannot get prof.log from %s" % node.tag)
Esempio n. 8
0
def update(nodes):

    running = isRunning(nodes)

    cmds = []
    for (node, isrunning) in running:
        if isrunning:
            env = _makeEnvParam(node)
            env += " BRO_DNS_FAKE=1"
            args = " ".join(_makeBroParams(node, False))
            cmds += [
                (node.tag, os.path.join(config.Config.scriptsdir, "update") +
                 " %s %s" % (node.tag.replace("worker-", "w"), args), env,
                 None)
            ]
            util.output("updating %s ..." % node.tag)

    results = execute.runLocalCmdsParallel(cmds)

    for (tag, success, output) in results:
        if not success:
            util.output("could not update %s: %s" % (tag, output))
        else:
            util.output("%s: %s" % (tag, output[0]))
Esempio n. 9
0
def _doCheckConfig(nodes, installed, list_scripts):

    results = []

    manager = config.Config.manager()

    all = [(node, os.path.join(config.Config.tmpdir, "check-config-%s" % node.name)) for node in nodes]

    if not os.path.exists(os.path.join(config.Config.scriptsdir, "broctl-config.sh")):
        util.output("error: broctl-config.sh not found (try 'broctl install')")
        # Return a failure for one node to indicate that the command failed
        results += [(all[0][0], False)]
        return results

    nodes = []
    for (node, cwd) in all:
        if os.path.isdir(cwd):
            if not execute.rmdir(config.Config.manager(), cwd):
                util.output("cannot remove directory %s on manager" % cwd)
                results += [(node, False)]
                continue

        if not execute.mkdir(config.Config.manager(), cwd):
            util.output("cannot create directory %s on manager" % cwd)
            results += [(node, False)]
            continue

        nodes += [(node, cwd)]

    cmds = []
    for (node, cwd) in nodes:

        env = _makeEnvParam(node)

        installed_policies = installed and "1" or "0"
        print_scripts = list_scripts and "1" or "0"

        install.makeLayout(cwd, True)
        install.makeLocalNetworks(cwd, True)
        install.makeConfig(cwd, True)

        cmd = os.path.join(config.Config.scriptsdir, "check-config") + " %s %s %s %s" % (
            installed_policies,
            print_scripts,
            cwd,
            " ".join(_makeBroParams(node, False)),
        )
        cmd += " broctl/check"

        cmds += [((node, cwd), cmd, env, None)]

    for ((node, cwd), success, output) in execute.runLocalCmdsParallel(cmds):
        results += [(node, success)]
        if success:
            util.output("%s scripts are ok." % node.name)
            if list_scripts:
                for line in output:
                    util.output("  %s" % line)
        else:
            util.output("%s scripts failed." % node.name)
            for line in output:
                util.output("   %s" % line)

        execute.rmdir(manager, cwd)

    return results
Esempio n. 10
0
def _doCheckConfig(nodes, installed, list_scripts, fullpaths):

    ok = True

    manager = config.Config.manager()

    all = [(node,
            os.path.join(config.Config.tmpdir, "check-config-%s" % node.tag))
           for node in nodes]

    nodes = []
    for (node, cwd) in all:
        if os.path.isdir(cwd):
            if not execute.rmdir(config.Config.manager(), cwd):
                util.output("cannot remove directory %s on manager" % cwd)
                continue

        if not execute.mkdir(config.Config.manager(), cwd):
            util.output("cannot create directory %s on manager" % cwd)
            continue

        nodes += [(node, cwd)]

    cmds = []
    for (node, cwd) in nodes:

        env = ""
        if node.type == "worker" or node.type == "proxy":
            env = "BRO_%s=%s" % (node.type.upper(), str(node.count))

        dashl = list_scripts and ["-l"] or []

        broargs = " ".join(dashl + _makeBroParams(node, False)) + " terminate"
        installed_policies = installed and "1" or "0"

        cmd = os.path.join(
            config.Config.scriptsdir,
            "check-config") + " %s %s %s" % (installed_policies, cwd, broargs)

        cmds += [((node, cwd), cmd, env, None)]

    for ((node, cwd), success, output) in execute.runLocalCmdsParallel(cmds):

        if not list_scripts:

            if success:
                util.output("%s is ok." % node.tag)
            else:
                ok = False
                util.output("%s failed." % node.tag)
                for line in output:
                    util.output("   %s" % line)

        else:
            util.output(node.tag)
            for line in output:
                if line.find("loading") >= 0:

                    line = line.replace("loading ", "")
                    if not fullpaths:
                        line = re.sub("\S+/", "", line)

                    util.output("   %s" % line)

            if not success:
                ok = False
                util.output("%s failed to load all scripts correctly." %
                            node.tag)

        execute.rmdir(manager, cwd)

    return ok