Exemple #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]
Exemple #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]
Exemple #3
0
def makeLayout(path, silent=False):
    def nextPort(node):
        global port
        port += 1
        node.setPort(port)
        return port

    global port
    port = 47759
    manager = config.Config.manager()

    if not manager:
        return

    filename = os.path.join(path, "cluster-layout.bro")

    # If there is a standalone node, delete any cluster-layout file to
    # avoid the cluster framework from activating and get out of here.
    if ( len(config.Config.nodes("standalone")) > 0 ):
        if os.access(filename, os.W_OK):
            os.unlink(filename)
        # We do need to establish the port for the manager.
        if ( not silent ):
            util.output("generating standalone-layout.bro ...", False)

        filename = os.path.join(path, "standalone-layout.bro")
        out = open(filename, "w")
        print >>out, "# Automatically generated. Do not edit."
        # This is the port that standalone nodes listen on for remote control by default.
        print >>out, "redef Communication::listen_port = %s/tcp;" % nextPort(manager)
        print >>out, "redef Communication::nodes += {"
        print >>out, "	[\"control\"] = [$host=%s, $zone_id=\"%s\", $class=\"control\", $events=Control::controller_events]," % (util.formatBroAddr(manager.addr), manager.zone_id)
        print >>out, "};"

    else:
        if ( not silent ):
            util.output("generating cluster-layout.bro ...", False)

        out = open(filename, "w")

        workers = config.Config.nodes("workers")
        proxies = config.Config.nodes("proxies")

        print >>out, "# Automatically generated. Do not edit."
        print >>out, "redef Cluster::nodes = {";

        # Control definition.  For now just reuse the manager information.
        print >>out, "\t[\"control\"] = [$node_type=Cluster::CONTROL, $ip=%s, $zone_id=\"%s\", $p=%s/tcp]," % (util.formatBroAddr(manager.addr), config.Config.zoneid, nextPort(manager))

        # Manager definition
        print >>out, "\t[\"%s\"] = [$node_type=Cluster::MANAGER, $ip=%s, $zone_id=\"%s\", $p=%s/tcp, $workers=set(" % (manager.name, util.formatBroAddr(manager.addr), manager.zone_id, nextPort(manager)),
        for s in workers:
            print >>out, "\"%s\"" % (s.name),
            if s != workers[-1]:
                print >>out, ",",
        print >>out, ")],"

        # Proxies definition
        for p in proxies:
            print >>out, "\t[\"%s\"] = [$node_type=Cluster::PROXY, $ip=%s, $zone_id=\"%s\", $p=%s/tcp, $manager=\"%s\", $workers=set(" % (p.name, util.formatBroAddr(p.addr), p.zone_id, nextPort(p), manager.name),
            for s in workers:
                print >>out, "\"%s\"" % (s.name),
                if s != workers[-1]:
                    print >>out, ",",
            print >>out, ")],"

        # Workers definition
        for w in workers:
            p = w.count % len(proxies)
            print >>out, "\t[\"%s\"] = [$node_type=Cluster::WORKER, $ip=%s, $zone_id=\"%s\", $p=%s/tcp, $interface=\"%s\", $manager=\"%s\", $proxy=\"%s\"]," % (w.name, util.formatBroAddr(w.addr), w.zone_id, nextPort(w), w.interface, manager.name, proxies[p].name),

        # Activate time-machine support if configured.
        if config.Config.timemachinehost:
            print >>out, "[\"time-machine\"] = [$node_type=Cluster::TIME_MACHINE, $ip=%s, $p=%s/tcp]," % (config.Config.timemachinehost, config.Config.timemachineport),

        print >>out, "};"

        # TODO: This is definitely the wrong spot for this.
        #
        # This doesn't work at all right now ... -Robin
        #print >>out, "redef Cluster::log_dir = \"%s\";" % config.Config.subst(config.Config.logdir)

    if ( not silent ):
        util.output(" done.")
Exemple #4
0
def makeLayout(path, silent=False):
    def nextPort(node):
        global port
        port += 1
        node.setPort(port)
        return port

    global port
    port = 47759
    manager = config.Config.manager()

    if not manager:
        return

    filename = os.path.join(path, "cluster-layout.bro")

    # If there is a standalone node, delete any cluster-layout file to
    # avoid the cluster framework from activating and get out of here.
    if (len(config.Config.nodes("standalone")) > 0):
        if os.access(filename, os.W_OK):
            os.unlink(filename)
        # We do need to establish the port for the manager.
        if (not silent):
            util.output("generating standalone-layout.bro ...", False)

        filename = os.path.join(path, "standalone-layout.bro")
        out = open(filename, "w")
        print >> out, "# Automatically generated. Do not edit."
        # This is the port that standalone nodes listen on for remote control by default.
        print >> out, "redef Communication::listen_port = %s/tcp;" % nextPort(
            manager)
        print >> out, "redef Communication::nodes += {"
        print >> out, "	[\"control\"] = [$host=%s, $zone_id=\"%s\", $class=\"control\", $events=Control::controller_events]," % (
            util.formatBroAddr(manager.addr), manager.zone_id)
        print >> out, "};"

    else:
        if (not silent):
            util.output("generating cluster-layout.bro ...", False)

        out = open(filename, "w")

        workers = config.Config.nodes("workers")
        proxies = config.Config.nodes("proxies")

        print >> out, "# Automatically generated. Do not edit."
        print >> out, "redef Cluster::nodes = {"

        # Control definition.  For now just reuse the manager information.
        print >> out, "\t[\"control\"] = [$node_type=Cluster::CONTROL, $ip=%s, $zone_id=\"%s\", $p=%s/tcp]," % (
            util.formatBroAddr(
                manager.addr), config.Config.zoneid, nextPort(manager))

        # Manager definition
        print >> out, "\t[\"%s\"] = [$node_type=Cluster::MANAGER, $ip=%s, $zone_id=\"%s\", $p=%s/tcp, $workers=set(" % (
            manager.name, util.formatBroAddr(
                manager.addr), manager.zone_id, nextPort(manager)),
        for s in workers:
            print >> out, "\"%s\"" % (s.name),
            if s != workers[-1]:
                print >> out, ",",
        print >> out, ")],"

        # Proxies definition
        for p in proxies:
            print >> out, "\t[\"%s\"] = [$node_type=Cluster::PROXY, $ip=%s, $zone_id=\"%s\", $p=%s/tcp, $manager=\"%s\", $workers=set(" % (
                p.name, util.formatBroAddr(
                    p.addr), p.zone_id, nextPort(p), manager.name),
            for s in workers:
                print >> out, "\"%s\"" % (s.name),
                if s != workers[-1]:
                    print >> out, ",",
            print >> out, ")],"

        # Workers definition
        for w in workers:
            p = w.count % len(proxies)
            print >> out, "\t[\"%s\"] = [$node_type=Cluster::WORKER, $ip=%s, $zone_id=\"%s\", $p=%s/tcp, $interface=\"%s\", $manager=\"%s\", $proxy=\"%s\"]," % (
                w.name, util.formatBroAddr(w.addr), w.zone_id, nextPort(w),
                w.interface, manager.name, proxies[p].name),

        # Activate time-machine support if configured.
        if config.Config.timemachinehost:
            print >> out, "[\"time-machine\"] = [$node_type=Cluster::TIME_MACHINE, $ip=%s, $p=%s/tcp]," % (
                config.Config.timemachinehost, config.Config.timemachineport),

        print >> out, "};"

        # TODO: This is definitely the wrong spot for this.
        #
        # This doesn't work at all right now ... -Robin
        #print >>out, "redef Cluster::log_dir = \"%s\";" % config.Config.subst(config.Config.logdir)

    if (not silent):
        util.output(" done.")