Esempio n. 1
0
    def pre_threads(self):
        signal.signal(signal.SIGINT, self.kill_handler)
        signal.signal(signal.SIGTERM, self.kill_handler)
        signal.signal(signal.SIGUSR2, self.stack_trace_handler)

        if self.conf.pydev_host:
            utils.setup_remote_pydev(self.conf.pydev_host, self.conf.pydev_port)

        if "PYDEVD_DEBUG_HOST" in os.environ:
            pydev = os.environ["PYDEVD_DEBUG_HOST"]
            h, p = pydev.split(":")
            utils.setup_remote_pydev(h, int(p))

        if self.conf.intrusion_detection_ossec:
            self.g_logger.info("Setting up intrusion detection.")
            if not utils.ossec_installed(self.conf):
                utils.install_ossec(self.conf)
            rc = utils.start_ossec()
            if not rc:
                self.g_logger.warn("Ossec failed to start")
Esempio n. 2
0
    def pre_threads(self):
        signal.signal(signal.SIGINT, self.kill_handler)
        signal.signal(signal.SIGTERM, self.kill_handler)
        signal.signal(signal.SIGUSR2, self.stack_trace_handler)

        if self.conf.pydev_host:
            utils.setup_remote_pydev(self.conf.pydev_host,
                                     self.conf.pydev_port)

        if 'PYDEVD_DEBUG_HOST' in os.environ:
            pydev = os.environ['PYDEVD_DEBUG_HOST']
            h, p = pydev.split(":")
            utils.setup_remote_pydev(h, int(p))

        if self.conf.intrusion_detection_ossec:
            self.g_logger.info("Setting up intrusion detection.")
            if not utils.ossec_installed(self.conf):
                utils.install_ossec(self.conf)
            rc = utils.start_ossec()
            if not rc:
                self.g_logger.warn("Ossec failed to start")
Esempio n. 3
0
def main(argv=sys.argv[1:]):
    parser = setup_command_line_parser()
    opts = parser.parse_args(args=argv)

    opts.loglevel = opts.loglevel.upper()
    if opts.loglevel not in ["ERROR", "WARN", "INFO", "DEBUG"]:
        print("WARNING: %s is an invalid log level.  Using INFO"
              % opts.loglevel)
        opts.loglevel = "INFO"
    opts.intrusion_detection_ossec = opts.intrusion_detection_ossec.lower()
    opts.intrusion_detection_ossec =\
        opts.intrusion_detection_ossec in ['y', 'yes', 't', 'true']

    conf_d = gather_values(opts)
    if not opts.initial:
        guess_default_cloud(conf_d)
    do_interactive(opts, conf_d)
    normalize_cloud_name(conf_d)
    pick_meta_data(conf_d)
    validate_cacerts(conf_d)

    # before writing anything make sure that all the needed values are
    # set
    if not opts.initial:
        if not conf_d["system"]["user"]:
            raise Exception("You must set the user name that will run "
                            "this service.")
        if not conf_d["storage"]["base_dir"]:
            raise Exception("You must set the base dir for this service "
                            "installation.")

    try:
        make_dirs(conf_d)
        (_, base_dir) = conf_d["storage"]["base_dir"]
        if not opts.reload:
            copy_scripts(conf_d)
            do_plugin_conf(conf_d)
            do_logging_conf(conf_d, opts)
        else:
            if not os.path.isfile(os.path.join(base_dir, "etc", "plugin.conf")) or opts.rewrite_logging_plugin:
                do_plugin_conf(conf_d)
            if not os.path.isfile(os.path.join(base_dir, "etc", "logging.yaml")) or opts.rewrite_logging_plugin:
                do_logging_conf(conf_d, opts)
        cleanup_previous_install(conf_d)
        conf_file_name = os.path.join(base_dir, "etc", "agent.conf")
        write_conf_file(conf_file_name, conf_d)
        do_set_owner_and_perms(conf_d)
        if not opts.initial:
            enable_start_agent(opts)

        conf = config.AgentConfig([conf_file_name])
        if opts.install_extras:
            if opts.package_name:
                agent_utils.install_extras(conf, package=opts.package_name)
            else:
                agent_utils.install_extras(conf)
        if opts.intrusion_detection_ossec and not agent_utils.ossec_installed(conf):
            # call out to install ossec
            agent_utils.install_ossec(conf)

    except Exception as ex:
        print(str(ex), file=sys.stderr)
        if opts.verbose:
            raise
        return 1
    return 0