I got tired of not knowing when I was running low on DHCP addresses so I wrote this little bit for our routers.
This is a basic script and my first time sharing. I have tested it on v2.9.42 and v3rc7
# WarnAt needs to be at what percentage you want to be warned you are running out of IP addresses.
:local WarnAt 10
# Set to your e-mail address.
:local EMail me@mydomain.com
# Set to the name of your DHCP pool
:local Pool dhcp_pool1
:local ip [:tostr [ip pool get $Pool ranges]]
:local Start [:pick $ip 0 [:find $ip "-"]]
:local Stop [:pick $ip ([:find $ip "-"] + 1) 31]
:local Total ($Stop - $Start)
:local Identity [/system identity get name]
:local Used [/ip dhcp-server lease print count-only]
:local Available ($Total - $Used)
:local Perc (($Available* 100) / $Total)
:local Subject ($Identity . " DHCP pool is at " . $Perc . "%")
:local Body ("Out of " . $Total . " addresses you have " . $Available . " available")
:if ($Perc <= $WarnAt) do={
/tool e-mail send to=$EMail subject=$Subject body=$Body
}