def get_agent_conf_multigroup(multigroup_id=None, offset=0, limit=common.database_limit, filename=None): """ Returns agent.conf as dictionary. :return: agent.conf as dictionary. """ # Check if a multigroup_id is provided and it exists if multigroup_id and not os_path.exists(os_path.join(common.multi_groups_path, multigroup_id)) or not multigroup_id: raise WazuhResourceNotFound(1710, extra_message=multigroup_id if multigroup_id else "No multigroup provided") agent_conf_name = filename if filename else 'agent.conf' agent_conf = os_path.join(common.multi_groups_path, multigroup_id, agent_conf_name) if not os_path.exists(agent_conf): raise WazuhError(1006, extra_message=os_path.join("WAZUH_PATH", "var", "multigroups", agent_conf)) try: # Read XML xml_data = load_wazuh_xml(agent_conf) # Parse XML to JSON data = _agentconf2json(xml_data) except Exception: raise WazuhError(1101) return {'totalItems': len(data), 'items': cut_array(data, offset=offset, limit=limit)}
def get_agent_conf(group_id=None, offset=0, limit=common.database_limit, filename='agent.conf', return_format=None): """ Returns agent.conf as dictionary. :return: agent.conf as dictionary. """ if not os_path.exists(os_path.join(common.shared_path, group_id)): raise WazuhResourceNotFound(1710, group_id) agent_conf = os_path.join(common.shared_path, group_id if group_id is not None else '', filename) if not os_path.exists(agent_conf): raise WazuhError(1006, agent_conf) try: # Read RAW file if filename == 'agent.conf' and return_format and 'xml' == return_format.lower(): with open(agent_conf, 'r') as xml_data: data = xml_data.read() return data # Parse XML to JSON else: # Read XML xml_data = load_wazuh_xml(agent_conf) data = _agentconf2json(xml_data) except Exception as e: raise WazuhError(1101, str(e)) return {'total_affected_items': len(data), 'affected_items': cut_array(data, offset=offset, limit=limit)}