7.18.2 IP Pool Exhaustion Script (alert at 80%)

Hello all,

I’ve seen where some have created scripts for alerting a user when an IP Pool reaches a certain utilization %, but these seem to be for older version of routerOS. It looks like some backend changes were made in 7.18.2 with the pools.

Does anyone have a script that I could use that will put IP Utilization numbers into the logs and from there I can script that up to email them out?

Thanks in advance.

:local threshold 5

:foreach pool in=[/ip/pool/find] do={

    :local name [/ip/pool/get $pool name]
    :local available [/ip/pool/get $pool available]
    :local used [/ip/pool/get $pool used]
    :local total [/ip/pool/get $pool total]

    :if ($available <= $threshold) do={

        :local subject ("ALERT: DHCP Pool " . $name . " is low")
        :local body ("Warning:\nDHCP Pool: " . $name . "\nUsed: " . $used . "\nAvailable: " . $available . "\nTotal: " . $total)

        :log warning $body

        /tool e-mail send to="admin@example.com" subject=$subject body=$body
    } else={
        :log info ("DHCP Pool \"$name\": $used used, $available available, total $total")
    }
}