Registering the Wazuh agents using the Wazuh API

The Wazuh API allows the Wazuh agent registration by running a single request from any host. This request returns the Wazuh agent's registration key, which must be manually added to the Wazuh agent using manage_agents utility.

Note

Root user privileges are necessary to execute all the commands described below, and the Wazuh API must be accessible from the host on which the request is executed.

Warning

Terminal history will keep the generated agent key when using the manage_agents utility. Consider disabling it beforehand, cleaning it afterward, or using another registration method.

Choose the tab corresponding to the Wazuh agent host operating system:

  1. Open a terminal in the Wazuh agent's host as a root user. To add the Wazuh agent to the Wazuh manager and extract the registration key execute the following Wazuh API request POST /agents and replacing the values in the angle brackets:

    # curl -k -X POST -d '{"name":"<agent_name>","ip":"<agent_IP>"}' "https://localhost:55000/agents?pretty=true" -H "Content-Type:application/json" -H "Authorization: Bearer $TOKEN"
    

    The output of the Wazuh API request returns the registration key:

    {
        "error": 0,
        "data": {
            "id": "001",
            "key": "MDAxIE5ld0FnZW50IDEwLjAuMC44IDM0MGQ1NjNkODQyNjcxMWIyYzUzZTE1MGIzYjEyYWVlMTU1ODgxMzVhNDE3MWQ1Y2IzZDY4M2Y0YjA0ZWVjYzM=",
        },
    }
    

    More information about API credentials and HTTPS support can be found on Wazuh API configuration.

  2. Import the registration key to the Wazuh agent using manage_agents utility. Replace the Wazuh agent's registration key:

    # /var/ossec/bin/manage_agents -i <key>
    

    An example output of the command looks as follows:

    Agent information:
       ID:001
       Name:agent_1
       IP Address:any
    
    Confirm adding it?(y/n): y
    Added.
    

    Optionally, clean the terminal history if it was not disabled. There are two options:

    1. Clean it all

      # history -c
      
    2. Clean any specific line

      # history -d <line to delete>
      
  3. To enable the communication with the Wazuh manager, edit the Wazuh agent's configuration file placed at /var/ossec/etc/ossec.conf.

    In the <client><server> section, MANAGER_IP has to be replaced with the Wazuh server's IP address or the DNS name:

    <client>
      <server>
        <address>MANAGER_IP</address>
        ...
      </server>
    </client>
    
  4. Restart the Wazuh agent:

# systemctl restart wazuh-agent