Exemplo n.º 1
0
def get_node_wrapper():
    """ Wrapper for get_node

    :return: AffectedItemsWazuhResult
    """
    result = AffectedItemsWazuhResult(
        all_msg='All selected information was returned',
        none_msg='No information was returned')
    try:
        result.affected_items.append(get_node())
    except WazuhError as e:
        result.add_failed_item(id_=node_id, error=e)
    result.total_affected_items = len(result.affected_items)

    return result
Exemplo n.º 2
0
def create_json_message(command: str = '',
                        arguments: list = None,
                        alert: dict = None) -> str:
    """Create the JSON message that will be sent. Function used when Wazuh agent version is >= 4.2.0.

    Parameters
    ----------
    command : str
        Command running in the agent. If this value starts by !, then it refers to a script name instead of a command
        name.
    arguments : list
        Command arguments.
    alert : dict
        Alert data that will be sent with the AR command.

    Raises
    ------
    WazuhError(1650)
        If the command is not specified.

    Returns
    -------
    str
        Message that will be sent to the socket.
    """
    if not command:
        raise WazuhError(1650)

    cluster_enabled = not read_cluster_config()['disabled']
    node_name = get_node().get('node') if cluster_enabled else None

    msg_queue = json.dumps(
        create_wazuh_socket_message(origin={
            'name': node_name,
            'module': common.origin_module.get()
        },
                                    command=command,
                                    parameters={
                                        'extra_args':
                                        arguments if arguments else [],
                                        'alert':
                                        alert if alert else {}
                                    }))

    return msg_queue
Exemplo n.º 3
0
# Copyright (C) 2015-2019, Wazuh Inc.
# Created by Wazuh, Inc. <*****@*****.**>.
# This program is a free software; you can redistribute it and/or modify it under the terms of GPLv2
from wazuh.core import common
from wazuh.core.cluster import local_client
from wazuh.core.cluster.cluster import get_node
from wazuh.core.cluster.control import get_health, get_nodes
from wazuh.core.cluster.utils import get_cluster_status, read_cluster_config, read_config
from wazuh.core.exception import WazuhError, WazuhResourceNotFound
from wazuh.core.results import AffectedItemsWazuhResult
from wazuh.rbac.decorators import expose_resources, async_list_handler

cluster_enabled = not read_cluster_config()['disabled']
node_id = get_node().get('node') if cluster_enabled else None


@expose_resources(actions=['cluster:read'], resources=[f'node:id:{node_id}'])
def read_config_wrapper():
    """ Wrapper for read_config

    :return: AffectedItemsWazuhResult
    """
    result = AffectedItemsWazuhResult(
        all_msg='All selected information was returned',
        none_msg='No information was returned')
    try:
        result.affected_items.append(read_config())
    except WazuhError as e:
        result.add_failed_item(id_=node_id, error=e)
    result.total_affected_items = len(result.affected_items)
Exemplo n.º 4
0
from wazuh.core import common, configuration
from wazuh.core.cluster.cluster import get_node
from wazuh.core.cluster.utils import manager_restart, read_cluster_config
from wazuh.core.configuration import get_ossec_conf, write_ossec_conf
from wazuh.core.exception import WazuhError
from wazuh.core.manager import status, get_api_conf, get_ossec_logs, get_logs_summary, validate_ossec_conf
from wazuh.core.results import AffectedItemsWazuhResult
from wazuh.core.utils import process_array, safe_move, validate_wazuh_xml
from wazuh.rbac.decorators import expose_resources

allowed_api_fields = {
    'behind_proxy_server', 'logs', 'cache', 'cors', 'use_only_authd',
    'experimental_features'
}
cluster_enabled = not read_cluster_config()['disabled']
node_id = get_node().get('node') if cluster_enabled else 'manager'


@expose_resources(
    actions=[f"{'cluster' if cluster_enabled else 'manager'}:read"],
    resources=[f'node:id:{node_id}' if cluster_enabled else '*:*:*'])
def get_status():
    """Wrapper for status().

    :return: AffectedItemsWazuhResult
    """
    result = AffectedItemsWazuhResult(
        all_msg=f"Processes status was successfully read"
        f"{' in specified node' if node_id != 'manager' else ''}",
        some_msg='Could not read basic information in some nodes',
        none_msg=f"Could not read processes status"