예제 #1
0
def get_agent_conf(group_list=None, filename='agent.conf', offset=0, limit=common.database_limit):
    """ Reads agent conf for specified group.

    :param group_list: List of Group names.
    :param filename: Filename to read config from.
    :param offset: First item to return.
    :param limit: Maximum number of items to return.
    :return: WazuhResult.
    """
    # We access unique group_id from list, this may change if and when we decide to add option to get agent conf for
    # a list of groups
    group_id = group_list[0]

    return WazuhResult(configuration.get_agent_conf(group_id=group_id, filename=filename, offset=offset, limit=limit))
예제 #2
0
def test_get_agent_conf():
    with pytest.raises(WazuhError, match=".* 1710 .*"):
        configuration.get_agent_conf(group_id='noexists')

    with patch('wazuh.core.common.shared_path', new=os.path.join(parent_directory, tmp_path, 'configuration')):
        with pytest.raises(WazuhError, match=".* 1006 .*"):
            configuration.get_agent_conf(group_id='default', filename='noexists.conf')

    with patch('wazuh.core.common.shared_path', new=os.path.join(parent_directory, tmp_path, 'configuration')):
        with patch('wazuh.core.configuration.load_wazuh_xml', return_value=Exception):
            with pytest.raises(WazuhError, match=".* 1101 .*"):
                assert isinstance(configuration.get_agent_conf(group_id='default'), dict)

    with patch('wazuh.core.common.shared_path', new=os.path.join(parent_directory, tmp_path, 'configuration')):
        assert configuration.get_agent_conf(group_id='default', filename='agent1.conf')['total_affected_items'] == 1