Dynamic Leases Back to Sonar


#1

For some reason I’m not seeing the dynamic leases getting pushed back into Sonar from our test Mikrotik DHCP server. I have the provided script entered with my user/pass (Super Admin) and I’m not finding any way to debug in Sonar…


#2

Would also note that it does seem to work the other direction with static leases, though I had a few problems with it complaining about an existing lease…


#3

Under Network > Provisioning > Logging, enable the dynamic IP logging, it will give you more details. You can also run the script that you put into the DHCP server by hand with a specific IP/MAC directly in the MikroTik command line interface and see what you get back.

95% of the time, it’s a bad username/password for the API, or the MAC/IP is unknown in Sonar. Running the script by hand will normally tell you that. As long as it’s not a bad username/password, turning on the logging will diagnose any other problems.


#4

No DNS resolution on the test router. Oops! fixed.

Now I’m getting “failure: closing connection: <404 Not Found> 67.205.153.26:443 (4)” when I run the script and not seeing anything in Provision Notices…


#5

Sounds like your path is wrong or something is invalid in the URL. You definitely won’t see anything in the notices if you’re getting a 404.


#6

I’m using the script from the documentation:

:if ($leaseBound = 0) do={ /tool fetch url=“https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$leaseActIP&mac_address=$leaseActMAC&expired=1” mode=https keep-result=no user=$username password=$password } else={ /tool fetch url=“https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$leaseActIP&mac_address=$leaseActMAC&expired=0” mode=https keep-result=no user=$username password=$password }


#7

Can you send a screenshot of exactly what you’re putting into the terminal and the output? Will probably be easier to troubleshoot. (You can email it into support if you have secret stuff you want to preserve in there.)


#8

I was having a slimier issue trying to get dhcp servers to report to sonar with leases. When pasting the script in the command line, and replacing the variables with real data, I noticed the ? was being stripped from the URL, causing a 404. The ? symbol is caught by the mikrotik command handler as a help request.
The fix is simple. Properly escape the special character by adding a \.

:if ($leaseBound = 0) do={ /tool fetch url=“https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$leaseActIP&mac_address=$leaseActMAC&expired=1” mode=https keep-result=no user=$username password=$password } else={ { :delay 1 }; /tool fetch url=“https://$url/api/v1/network/ipam/dynamic_ip_assignment?ip_address=$leaseActIP&mac_address=$leaseActMAC&expired=0” mode=https keep-result=no user=$username password=$password };