Exemplo n.º 1
0
def test_checking_configuration(read_config):
    """
    Checks wrong configurations to check the proper exceptions are raised
    """
    with patch('wazuh.cluster.cluster.get_ossec_conf') as m:
        m.return_value = read_config.copy()
        with pytest.raises(WazuhException, match=r'.* 3004 .*'):
            configuration = cluster.read_config()
            cluster.check_cluster_config(configuration)
Exemplo n.º 2
0
def check_cluster_status():
    # Get cluster config
    cluster_config = read_config()

    if not cluster_config or cluster_config['disabled'] == 'yes':
        raise WazuhException(3013)

    # Validate cluster config
    check_cluster_config(cluster_config)

    status = get_status_json()
    if status["running"] != "yes":
        raise WazuhException(3012)
Exemplo n.º 3
0
        clean_exit(reason=str(e), error=True)

    if not cluster_config or cluster_config['disabled'] == 'yes':
        clean_exit(reason="Cluster disabled", error=True)

    # Drop privileges to ossec
    if not args.r:
        setgid(common.ossec_gid)
        seteuid(common.ossec_uid)

    # Creating pid file
    create_pid("wazuh-clusterd", getpid())

    # Validate config
    try:
        check_cluster_config(cluster_config)
    except WazuhException as e:
        clean_exit(reason="Invalid configuration: '{0}'".format(str(e)),
                   error=True)

    # Clean all temporary files before starting
    clean_up()

    # Main
    try:

        if cluster_config['node_type'] == "master":
            manager_tag = "Master"
            logger.info("[{0}] PID: {1}".format(manager_tag, getpid()))

            try:
Exemplo n.º 4
0
                           action='store',
                           nargs='?',
                           const='health',
                           help='Show cluster health')
    args = parser.parse_args()

    logging.basicConfig(level=logging.DEBUG if args.debug else logging.ERROR,
                        format='%(levelname)s: %(message)s')

    cluster_status = cluster.get_status_json()
    if cluster_status['enabled'] == 'no' or cluster_status['running'] == 'no':
        logging.error("Cluster is not running.")
        sys.exit(1)

    cluster_config = cluster.read_config()
    cluster.check_cluster_config(config=cluster_config)

    try:
        if args.filter_status and not args.list_agents:
            logging.error("Wrong arguments.")
            parser.print_help()
            sys.exit(1)
        elif args.list_agents:
            my_function, my_args = print_agents, (
                args.filter_status,
                args.filter_node,
            )
        elif args.list_nodes:
            my_function, my_args = print_nodes, (args.filter_node, )
        elif args.health:
            more = args.health.lower() == 'more'
Exemplo n.º 5
0
        debug_mode = 0

    # set correct permissions on cluster.log file
    if os.path.exists('{0}/logs/cluster.log'.format(common.ossec_path)):
        os.chown('{0}/logs/cluster.log'.format(common.ossec_path),
                 common.ossec_uid, common.ossec_gid)
        os.chmod('{0}/logs/cluster.log'.format(common.ossec_path), 0o660)

    main_logger = set_logging(debug_mode)

    cluster_configuration = cluster.read_config(config_file=args.config_file)
    if cluster_configuration['disabled']:
        sys.exit(0)
    cluster_items = cluster.get_cluster_items()
    try:
        cluster.check_cluster_config(cluster_configuration)
    except Exception as e:
        main_logger.error(e)
        sys.exit(1)

    if args.test_config:
        sys.exit(0)

    # clean
    cluster.clean_up()

    # Foreground/Daemon
    if not args.foreground:
        pyDaemonModule.pyDaemon()

    # Drop privileges to ossec