예제 #1
0
파일: control.py 프로젝트: J-Gras/broctl
    def update(self, nodes):
        results = cmdresult.CmdResult()

        running = self._isrunning(nodes)
        zone = self.config.zoneid
        if not zone:
            zone = "NOZONE"

        cmds = []
        for (node, isrunning) in running:
            if isrunning:
                env = _make_env_params(node)
                env += " BRO_DNS_FAKE=1"
                args = " ".join(_make_bro_params(node, False))
                cmds += [(node.name, os.path.join(self.config.scriptsdir, "update") + " %s %s %s/tcp %s" % (util.format_bro_addr(node.addr), zone, node.getPort(), args), env, None)]
                self.ui.info("updating %s ..." % node.name)

        res = execute.run_localcmds(cmds)

        for (tag, success, output) in res:
            node = self.config.nodes(tag=tag)[0]
            if not success:
                self.ui.info("failed to update %s: %s" % (tag, output[0]))
                results.set_node_fail(node)
            else:
                self.ui.info("%s: %s" % (tag, output[0]))
                results.set_node_success(node)

        return results
예제 #2
0
파일: control.py 프로젝트: aeppert/broctl
    def update(self, nodes):
        results = cmdresult.CmdResult()

        running = self._isrunning(nodes)
        zone = self.config.zoneid
        if not zone:
            zone = "NOZONE"

        cmds = []
        for (node, isrunning) in running:
            if isrunning:
                env = _make_env_params(node)
                env += " BRO_DNS_FAKE=1"
                args = " ".join(_make_bro_params(node, False))
                cmds += [(node.name,
                          os.path.join(self.config.scriptsdir, "update") +
                          " %s %s %s/tcp %s" % (util.format_bro_addr(
                              node.addr), zone, node.getPort(), args), env,
                          None)]
                self.ui.info("updating %s ..." % node.name)

        res = execute.run_localcmds(cmds)

        for (tag, success, output) in res:
            node = self.config.nodes(tag=tag)[0]
            if not success:
                self.ui.info("failed to update %s: %s" % (tag, output[0]))
                results.set_node_fail(node)
            else:
                self.ui.info("%s: %s" % (tag, output[0]))
                results.set_node_success(node)

        return results
예제 #3
0
    def _check_config(self, nodes, installed, list_scripts):
        results = cmdresult.CmdResult()

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

        nodes = []
        for (node, cwd) in nodetmpdirs:
            if os.path.isdir(cwd):
                try:
                    shutil.rmtree(cwd)
                except OSError as err:
                    self.ui.error("cannot remove directory %s: %s" % (cwd, err))
                    results.ok = False
                    return results

            try:
                os.makedirs(cwd)
            except OSError as err:
                self.ui.error("cannot create temporary directory: %s" % err)
                results.ok = False
                return results

            nodes += [(node, cwd)]

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

            env = _make_env_params(node)

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

            if not install.make_layout(cwd, self.ui, True):
                results.ok = False
                return results
            if not install.make_local_networks(cwd, self.ui, True):
                results.ok = False
                return results

            if not install.make_broctl_config_policy(cwd, self.ui, self.pluginregistry, True):
                results.ok = False
                return results

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

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

        for ((node, cwd), success, output) in execute.run_localcmds(cmds):
            results.set_node_output(node, success, output)
            try:
                shutil.rmtree(cwd)
            except OSError as err:
                # Don't bother reporting an error now.
                pass

        return results
예제 #4
0
파일: control.py 프로젝트: aeppert/broctl
    def _check_config(self, nodes, installed, list_scripts):
        results = cmdresult.CmdResult()

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

        nodes = []
        for (node, cwd) in nodetmpdirs:
            if os.path.isdir(cwd):
                try:
                    shutil.rmtree(cwd)
                except OSError as err:
                    self.ui.error("cannot remove directory: %s" % err)
                    results.ok = False
                    return results

            try:
                os.makedirs(cwd)
            except OSError as err:
                self.ui.error("cannot create temporary directory: %s" % err)
                results.ok = False
                return results

            nodes += [(node, cwd)]

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

            env = _make_env_params(node)

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

            install.make_layout(cwd, self.ui, True)
            if not install.make_local_networks(cwd, self.ui, True):
                results.ok = False
                return results

            install.make_broctl_config_policy(cwd, self.ui, True)

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

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

        for ((node, cwd), success, output) in execute.run_localcmds(cmds):
            results.set_node_output(node, success, output)
            shutil.rmtree(cwd)

        return results