Failed to fetch a free IP from proxy

Problem:

Hello! We are trying to set up Foreman in our company. We have the the following problem when we want to create a new host. When selecting domain and subnet we receive the following error:

Failed to fetch a free IP from proxy foreman-dev.xxx (https://foreman-dev.xxx:8443): ERF12-8202 [ProxyAPI::ProxyException]: Unable to retrieve unused IP ([RestClient::NotFound]: 404 Not Found) for proxy https://foreman-dev.xxx:8443/dhcp

When opening https://foreman-dev.xxx:8443/dhcp directly in the browser, I receive this message:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Expected outcome:

Expcted outcome would be a suggested IP address

Foreman and Proxy versions:

Foreman 2.5.1

Foreman and Proxy plugin versions:

foreman_discovery 17.0.1

Distribution and version:

Debian 10, Buster

Other relevant data:

2021-07-21T11:26:12 [W|app|8ee1cee7] Failed to fetch a free IP from proxy foreman-dev.xxx (https://foreman-dev.xxx:8443): ERF12-8202 [ProxyAPI::ProxyException]: Unable to retrieve unused IP ([RestClient::NotFound]: 404 Not Found) for proxy https://foreman-dev.xxx:8443/dhcp: ERF12-8202 [ProxyAPI::ProxyException]: Unable to retrieve unused IP ([RestClient::NotFound]: 404 Not Found) for proxy https://foreman-dev.xxx:8443/dhcp

If smart proxy reports 404, it usually means the module was not enabled correctly. Even if you enabled DHCP module, during startup proxy might disable it due to error - e.g. cannot access dhcp server configuration etc. Check startup logs.

Mhm, thanks for the advice.
I found this messages in /var/log/foreman-proxy/proxy.log

2021-07-21T11:59:16 4cfa10f5 [I] Started GET /dhcp/213.xxx.xxx.xxx/unused_ip from=213.xxx.xxx.xxx&to=213.xxx.xxx.xxx
2021-07-21T11:59:16 4cfa10f5 [E] Subnet 213.xxx.xxx.xxx could not found
2021-07-21T11:59:16 4cfa10f5 [W] Error details for Subnet 213.xxx.xxx.xxx could not found: <Exception>: Subnet 213.xxx.xxx.xxx could not found
2021-07-21T11:59:16 4cfa10f5 [W] Subnet 213.xxx.xxx.xxxcould not found: <Exception>: Subnet 213.xxx.xxx.xxxcould not found
2021-07-21T11:59:16 4cfa10f5 [I] Finished GET /dhcp/213.xxx.xxx.xxx/unused_ip with 404 (3.74 ms)

Will investigate that further. Thank you.

Sorry for the late reply.

When you add a subnet into Foreman, you need to add the same subnet into your ISC DHCP. This is NOT automatic, our proxy only manages records, not subnets. This is documented. Edit your dhcpd.conf and restart it.