Hello!
As I can see in your logs, the agents are trying to register with the manager with the same name. It is not possible to have two agents with the same name.
You can solve this error in different ways:
Delete the existing agent: taking into account the log I put before, there is already a registered agent with the same name, but if you no longer need it or you want to re-register it, you should delete it from the manager in the first place. You can refer to this link to do so, or execute this command in your manager:
/var/ossec/bin/manage_agents -r <AGENT_ID>
Set a different name in the enrollment configuration: you can change the name of the agent you want you re-register using its configuration. In this link, you have all the information.
Check the document for agent Deployment variables and use the WAZUH_AGENT_NAME with a different agent name value while installing the agent.
https://documentation.wazuh.com/current/user-manual/agent/agent-enrollment/deployment-variables/index.html
Using the force option will force the insertion of an agent if there is a duplicate name or IP address and will remove the old agent with the same name or IP address, as explained in our documentation. This will create another problem as your agents will be removed and registered again in a looping process.
https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/auth.html#force
I hope you find this information useful.
The "Agent key already in use" warning occurs because an agent is trying to register or re-authenticate using a hostname or ID that the Wazuh manager already has logged in its database(client.keys). This usually happens due to a network connection timeout, an abrupt endpoint reboot, or a duplicate agent name during an automated installation.
When enrollment is enabled, the agent keeps sending enrollment requests to the manager to ensure that the agent reconnects if it is disconnected accidentally or if connectivity issues arise. The manager then rejects those requests because the agent already has a valid key and is active. It should automatically reconnect after some retries, depending on time-reconnect and force_reconnect_interval.
In your case, deleting the agent and re-registering the agent should solve the issue, but it would re-register the agent with a new agent ID, so the old alert from this agent will not match the new ID.
Check if the agents recover and reconnect after some tries, and I will suggest you check if you have a stable network connection between the agent and the manager.
Let me know if you need further help on this.