Attached are the relevant scripts, I just open the text file in crimson
editor, copy all the text and paste it into a terminal window.
While you're still in the window, change to
/system script
and
run IPPoolInfo
or whatever you have the name set to if you changed the name of the
script. It will output in the terminal window.
Depending on how many pools you have, the output should resemble below:
[admin@Attica] /system script> run IPPoolInfo
IP Pool Statistics
------------------
Attica [0/245] 0 % used
Imlay [0/245] 0 % used
Imlay-Public [116/125] 92 % used
Attica-Public [99/122] 81 % used
[admin@Attica]/system script>
On 9/20/2012 9:03 AM, Ty Featherling wrote:
Please do. It doesn't seem the script is doing anything at all right now,
even when I change the thresholds to low numbers.
-Ty
On Wed, Sep 19, 2012 at 6:56 PM, Leroy Koglin <[email protected]>wrote:
Correct. Kerry has our routers setup to run the script every 4 hours. If
the
pool usage us above the warning value defined in the script an error is
logged. Remote syslog is enabled and he has rules built into the syslog
server to alert us when the dhcp pool error is detected.
As a minimum, if you pool usage is above the value you have set it the
script on the line :local criticalthreshold 90 you should get an error in
the log. The script is set to kick an error if the pool is 90% utilized.
Change the 90 to a lower value to test with.
The copy/paste may have messed the script up if that is not working for
you.
Let me know and I'll send you the script as an attachment.
Leroy
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ty Featherling
Sent: Wednesday, September 19, 2012 5:53 PM
To: Mikrotik discussions
Subject: Re: [Mikrotik] Managing DHCP Pools
Yeah that didn't do it. It just spits out a warning in the log, right?
-Ty
On Wed, Sep 19, 2012 at 4:39 PM, Josh Luthman
<[email protected]>wrote:
Pretty sure you'd need 70% or 90% capacity filled for it to spit out an
error. Make the warning value something like 1 or 5 and run it to test.
Josh Luthman
Office: 937-552-2340
Direct: 937-552-2343
1100 Wayne St
Suite 1337
Troy, OH 45373
On Wed, Sep 19, 2012 at 5:16 PM, Ty Featherling <[email protected]
wrote:
Ok new script added. Dumped the code in the source field. Left all
permissions checked and gave it a name. It added it in the list but
licking
"Run Script" does nothing. Nothing in the log nor any indication is
started
anything.
-Ty
On Wed, Sep 19, 2012 at 4:04 PM, Josh Luthman
<[email protected]>wrote:
I thought there was code above the actual script, sorry!
You should use the GUI to make a new script. There are no proper
breaks
in
the email to make it easy in the terminal.
Josh Luthman
Office: 937-552-2340
Direct: 937-552-2343
1100 Wayne St
Suite 1337
Troy, OH 45373
On Wed, Sep 19, 2012 at 5:00 PM, Ty Featherling <
[email protected]
wrote:
Pasted it in.. looks like it cleared with no errors. Now what? I
don't
see
a new script or any indication of anything new in ip>pool or
ip>dhcp-server.
-Ty
On Wed, Sep 19, 2012 at 3:37 PM, Josh Luthman
<[email protected]>wrote:
Yep. Put it in a terminal. Sometimes browsers turn " into some
weird
character...
On Sep 19, 2012 3:56 PM, "Ty Featherling" <
[email protected]
wrote:
Ok, hold my hand here.. Just copy that text and paste it into a
terminal
windows, yes? Or do I create a script and paste it there? Be
gentle,
it's
my first time.
-Ty
On Wed, Sep 19, 2012 at 1:45 PM, Kerry <[email protected]>
wrote:
I use this script, schedule it to run however often you'd
like.
It
throws
a script error when it's above the thresholds in the script.
I have system logging set to log script errors to my syslog
box
which
email-alerts us.
/system logging
add action=remote disabled=no prefix=DCHP-Server
topics=script,error
# List stats for IP -> Pool
#
# criticalthreshold = output pool display in red if pool used
is
above
this %
# warnthreshold = output pool display in gold if pool used is
above
this
%
:local criticalthreshold 90
:local warnthreshold 70
# Internal processing below...
# ------------------------------**----
/ip pool {
:local poolname
:local pooladdresses
:local poolused
:local poolpercent
:local minaddress
:local maxaddress
:local findindex
:local tmpint
:local maxindex
:local line
:put ("IP Pool Statistics")
:put ("------------------")
# Iterate through IP Pools
:foreach p in=[find] do={
:set poolname [get $p name]
:set pooladdresses 0
:set poolused 0
:set line ""
:set line (" " . $poolname)
# Iterate through current pool's IP ranges
:foreach r in=[:toarray [get $p range]] do={
# Get min and max addresses
:set findindex [:find [:tostr $r] "-"]
:if ([:len $findindex] > 0) do={
:set minaddress [:pick [:tostr $r] 0 $findindex]
:set maxaddress [:pick [:tostr $r] ($findindex +
1)
[:len
[:tostr $r]]]
} else={
:set minaddress [:tostr $r]
:set maxaddress [:tostr $r]
}
# Convert to array of octets (replace '.' with ',')
:for x from=0 to=([:len [:tostr $minaddress]] - 1)
do={
:if ([:pick [:tostr $minaddress] $x ($x + 1)] =
".")
do={
:set minaddress ([:pick [:tostr $minaddress] 0
$x] .
","
. \
[:pick [:tostr
$minaddress]
($x
+
1) [:len [:tostr $minaddress]]]) }
}
:for x from=0 to=([:len [:tostr $maxaddress]] - 1)
do={
:if ([:pick [:tostr $maxaddress] $x ($x + 1)] =
".")
do={
:set maxaddress ([:pick [:tostr $maxaddress] 0
$x] .
","
. \
[:pick [:tostr
$maxaddress]
($x
+
1) [:len [:tostr $maxaddress]]]) }
}
# Calculate available addresses for current range
:if ([:len [:toarray $minaddress]] = [:len [:toarray
$maxaddress]]) do={
:set maxindex ([:len [:toarray $minaddress]] - 1)
:for x from=$maxindex to=0 step=-1 do={
# Calculate 256^($maxindex - $x)
:set tmpint 1
:if (($maxindex - $x) > 0) do={
:for y from=1 to=($maxindex - $x) do={ :set
tmpint
(256
* $tmpint) }
}
:set tmpint ($tmpint * ([:tonum [:pick
[:toarray
$maxaddress] $x]] - \
[:tonum
[:pick
[:toarray $minaddress] $x]]) )
:set pooladdresses ($pooladdresses + $tmpint)
# for x
}
# if len array $minaddress = $maxaddress
}
# Add current range to total pool's available addresses
:set pooladdresses ($pooladdresses + 1)
# foreach r
}
# Now, we have the available address for all ranges in this
pool
# Get the number of used addresses for this pool
:set poolused [:len [used find pool=[:tostr
$poolname]]]
:set poolpercent (($poolused * 100) / $pooladdresses)
# Output information
:set line ([:tostr $line] . " [" . $poolused . "/" .
$pooladdresses
. "]")
:set line ([:tostr $line] . " " . $poolpercent . " %
used")
# Set colored display for used thresholds
:if ( [:tonum $poolpercent] > $criticalthreshold ) do={
:log error ("IP Pool " . $poolname . " is " .
$poolpercent .
"%
full" . " [" . $poolused . "/" . $pooladdresses . "]")
:put ([:terminal style varname] . $line)
} else={
:if ( [:tonum $poolpercent] > $warnthreshold ) do={
:log warning ("IP Pool " . $poolname . " is " .
$poolpercent
.
"% full")
:put ([:terminal style syntax-meta] . $line)
} else={
:put ([:terminal style none] . $line)
}
}
# foreach p
}
# /ip pool
}
On 9/19/2012 11:33 AM, Ty Featherling wrote:
I have a routerboard acting as my primary DHCP server. I am
also
adding
routers to this large bridged network a tower at a time and
each
new
router
holds DHCP pools for their segment as well.
How can I keep track of how many addresses are being
utilized
per
pool?
I
know that "ip dhcp-server lease print" will show how many
active
leases
there are but I want to see the number of unused addresses
in
a
pool.
I
have to do math in my head each time to compare the number
of
addresses
in
the pool to the number of active leases to get that number.
Has anyone found or created a more elegant solution to this?
-Ty
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.butchevans.com/**pipermail/mikrotik/**
attachments/20120919/54ec5d39/**attachment.html<
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/54ec5d39/a
ttachment.html
______________________________**_________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/**mailman/listinfo/mikrotik<
http://www.butchevans.com/mailman/listinfo/mikrotik>
Visit http://blog.butchevans.com/ for tutorials related to
Mikrotik
RouterOS
______________________________**_________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/**mailman/listinfo/mikrotik<
http://www.butchevans.com/mailman/listinfo/mikrotik>
Visit http://blog.butchevans.com/ for tutorials related to
Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/abf0ef50/a
ttachment.html
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to
Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/45f5f7e4/a
ttachment.html
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to
Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/d4411d56/a
ttachment.html
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to
Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/efe00c84/a
ttachment.html
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/80dc40f5/a
ttachment.html
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/3f7ad5cd/a
ttachment.html
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<
http://www.butchevans.com/pipermail/mikrotik/attachments/20120919/08b665f3/
attachment.html>
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik
RouterOS
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik
RouterOS
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.butchevans.com/pipermail/mikrotik/attachments/20120920/f520cb00/attachment.html>
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS
-------------- next part --------------
/system logging
add action=remote disabled=no prefix=ChangeMe topics=script,error
/system logging action
set remote bsd-syslog=no name=remote remote=xxx.xxx.xxx.xxx remote-port=514 \
src-address=0.0.0.0 syslog-facility=daemon syslog-severity=auto target=\
remote
/system script
add name=IPPoolInfo policy=\
ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api \
source="# List stats for IP -> Pool\r\
\n#\r\
\n# criticalthreshold = output pool display in red if pool used is above t\
his %\r\
\n# warnthreshold = output pool display in gold if pool used is above this\
\_%\r\
\n\r\
\n:local criticalthreshold 90\r\
\n:local warnthreshold 70\r\
\n\r\
\n# Internal processing below...\r\
\n# ----------------------------------\r\
\n/ip pool {\r\
\n :local poolname\r\
\n :local pooladdresses\r\
\n :local poolused\r\
\n :local poolpercent\r\
\n :local minaddress\r\
\n :local maxaddress\r\
\n :local findindex\r\
\n :local tmpint\r\
\n :local maxindex\r\
\n :local line\r\
\n\r\
\n :put (\"IP Pool Statistics\")\r\
\n :put (\"------------------\")\r\
\n\r\
\n# Iterate through IP Pools\r\
\n :foreach p in=[find] do={\r\
\n\r\
\n :set poolname [get \$p name]\r\
\n :set pooladdresses 0\r\
\n :set poolused 0\r\
\n :set line \"\"\r\
\n\r\
\n :set line (\" \" . \$poolname)\r\
\n\r\
\n# Iterate through current pool's IP ranges\r\
\n :foreach r in=[:toarray [get \$p range]] do={\r\
\n\r\
\n# Get min and max addresses\r\
\n :set findindex [:find [:tostr \$r] \"-\"]\r\
\n :if ([:len \$findindex] > 0) do={\r\
\n :set minaddress [:pick [:tostr \$r] 0 \$findindex]\r\
\n :set maxaddress [:pick [:tostr \$r] (\$findindex + 1) [:len \
[:tostr \$r]]]\r\
\n } else={\r\
\n :set minaddress [:tostr \$r]\r\
\n :set maxaddress [:tostr \$r]\r\
\n }\r\
\n\r\
\n# Convert to array of octets (replace '.' with ',')\r\
\n :for x from=0 to=([:len [:tostr \$minaddress]] - 1) do={\r\
\n :if ([:pick [:tostr \$minaddress] \$x (\$x + 1)] = \".\") do\
={\r\
\n :set minaddress ([:pick [:tostr \$minaddress] 0 \$x] . \"\
,\" . \\\r\
\n [:pick [:tostr \$minaddress] (\$x\
\_+ 1) [:len [:tostr \$minaddress]]]) }\r\
\n }\r\
\n :for x from=0 to=([:len [:tostr \$maxaddress]] - 1) do={\r\
\n :if ([:pick [:tostr \$maxaddress] \$x (\$x + 1)] = \".\") do\
={\r\
\n :set maxaddress ([:pick [:tostr \$maxaddress] 0 \$x] . \"\
,\" . \\\r\
\n [:pick [:tostr \$maxaddress] (\$x\
\_+ 1) [:len [:tostr \$maxaddress]]]) }\r\
\n }\r\
\n\r\
\n# Calculate available addresses for current range\r\
\n :if ([:len [:toarray \$minaddress]] = [:len [:toarray \$maxaddr\
ess]]) do={\r\
\n :set maxindex ([:len [:toarray \$minaddress]] - 1)\r\
\n :for x from=\$maxindex to=0 step=-1 do={\r\
\n# Calculate 256^(\$maxindex - \$x)\r\
\n :set tmpint 1\r\
\n :if ((\$maxindex - \$x) > 0) do={\r\
\n :for y from=1 to=(\$maxindex - \$x) do={ :set tmpint (\
256 * \$tmpint) }\r\
\n }\r\
\n :set tmpint (\$tmpint * ([:tonum [:pick [:toarray \$maxad\
dress] \$x]] - \\\r\
\n [:tonum [:pick [:toa\
rray \$minaddress] \$x]]) )\r\
\n :set pooladdresses (\$pooladdresses + \$tmpint)\r\
\n# for x\r\
\n }\r\
\n\r\
\n# if len array \$minaddress = \$maxaddress\r\
\n }\r\
\n\r\
\n# Add current range to total pool's available addresses\r\
\n :set pooladdresses (\$pooladdresses + 1)\r\
\n\r\
\n# foreach r\r\
\n }\r\
\n\r\
\n# Now, we have the available address for all ranges in this pool\r\
\n# Get the number of used addresses for this pool\r\
\n :set poolused [:len [used find pool=[:tostr \$poolname]]]\r\
\n :set poolpercent ((\$poolused * 100) / \$pooladdresses)\r\
\n\r\
\n# Output information\r\
\n :set line ([:tostr \$line] . \" [\" . \$poolused . \"/\" . \$pool\
addresses . \"]\")\r\
\n :set line ([:tostr \$line] . \" \" . \$poolpercent . \" % used\")\
\r\
\n\r\
\n# Set colored display for used thresholds\r\
\n :if ( [:tonum \$poolpercent] > \$criticalthreshold ) do={\r\
\n :log error (\"IP Pool \" . \$poolname . \" is \" . \$poolpercen\
t . \"% full\" . \" [\" . \$poolused . \"/\" . \$pooladdresses . \"]\")\r\
\n :put ([:terminal style varname] . \$line)\r\
\n } else={\r\
\n :if ( [:tonum \$poolpercent] > \$warnthreshold ) do={\r\
\n :log warning (\"IP Pool \" . \$poolname . \" is \" . \$poolp\
ercent . \"% full\")\r\
\n :put ([:terminal style syntax-meta] . \$line)\r\
\n } else={\r\
\n :put ([:terminal style none] . \$line)\r\
\n }\r\
\n }\r\
\n\r\
\n# foreach p\r\
\n }\r\
\n# /ip pool\r\
\n}\r\
\n"
_______________________________________________
Mikrotik mailing list
[email protected]
http://www.butchevans.com/mailman/listinfo/mikrotik
Visit http://blog.butchevans.com/ for tutorials related to Mikrotik RouterOS