which is working perfect from server side BUT this weird happens:
at log output window i get mac correctly and as clienthostname i get -hostname which of course is parsed to database as client name and is wrong.
i understand that i must parse variables another way so i try to parse it as follows:
/tool fetch url=(“http://10.10.10.1/add.php?clienthostname=” . $lease-hostname . “&mac=” . $leaseActMAC) and it gives me an empty client name but mac address is ok which of course again it parses only mac address on database and leaves hostname empty.
even if i change the order of mac and client name the client name remains empty.
would it be me and the way i use to handle this specific variable or it does not want to give host name?
I have this script setup to email us when something gets an IP address from the router. I’d like to add the DHCP pool’s total size and how many IP’s are used, but I am having a hard time finding what those variables would be. I am not really finding anything pertaining to IP Pools. Does anyone have those handy?
:local recipient "youremail@email.com"
/ip dhcp-server lease
:if ($leaseBound = 1) do={
:do {
:tool e-mail send to=$recipient subject="5th and Main New Device Alert: $"lease-hostname"" body="The following MAC address $leaseActMAC received an IP address $leaseActIP from the $leaseServerName"
:log info "Sent DHCP alert for MAC $leaseActMAC"
} on-error={:log error "Failed to send alert email to $recipient"}}
If you want other statistics, just get them using regular Mikrotik commands. For example I have a pool named “local-pool” and to get information about it I would use:
:local usedAddrs [ /ip/pool/get local-pool used ]
:local totalAddrs [ /ip/pool/get local-pool total ]
:put "Of $totalAddrs addresses, $usedAddrs are used."
This results in the output:
Of 154 addresses, 6 are used.
Should basically work anywhere. Other than that, show the script and maybe I can spot the error. Of course you have to replace the pool name with yours, and “:put” is the equivalent of “print” in most languages, so prints output to the console; to log the stuff use “:log info” as in the other places in your script.
Sure, here is what I’ve got. This was my latest attempt, nothing failed but nothing in the email either. I did try putting this into the body and that did fail.
Thanks again for your help, I appreciate it.
:local recipient "email@email.com"
/ip dhcp-server lease
:if ($leaseBound = 1) do={
:do {
:tool e-mail send to=$recipient subject="5th and Main New Device Alert: $"lease-hostname"" body="The following MAC address $leaseActMAC received an IP address $leaseActIP from the $leaseServerName"
:local usedAddrs [ /ip/pool/get "Public DHCP Pool" used ]
:local totalAddrs [ /ip/pool/get "Public DHCP Pool" total ]
:put "Of $totalAddrs addresses, $usedAddrs are used."
:log info "Sent DHCP alert for MAC $leaseActMAC"
} on-error={:log error "Failed to send alert email to $recipient"}}
you’re still using “:put” - again, that writes to the console
if you want this in the e-mail, then you’ll have to put it in the e-mail body - if by any chance you have not placed the “:local” declaration before sending the e-mail, well, of course that will fail: the variables don’t exist yet. Place the declarations before their usage do before the line where you send the e-mail
it’s often wise to debug things in steps - before sending it in an e-mail I would simply log it by replacing “:put” with “:log info” to ensure that getting the pool data actually works and then put it into the e-mail
are you receiving the e-mail at all? (with or without the additional content)