MUM 2010
It is currently Tue Feb 09, 2010 5:11 am

All times are UTC + 2 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [CONTRIB] DHCP Pool usage
PostPosted: Wed Oct 24, 2007 8:54 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 05, 2006 6:16 am
Posts: 338
Location: South Carolina
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
}


Top
 Profile  
 
 Post subject: Re: [CONTRIB] DHCP Pool usage
PostPosted: Sun May 04, 2008 9:41 pm 
Offline
Long time Member
Long time Member
User avatar

Joined: Thu Sep 07, 2006 5:12 pm
Posts: 590
Location: Jozi (aka Johannesburg), South Africa
This script is very useful, thanks.

Just one thing, it calculates one less IP in the range than is really defined.

I'm not that sure what this line means;

:local Stop [:pick $ip ([:find $ip "-"] + 1) 31]

_________________
Regards
Hilton


Top
 Profile  
 
 Post subject: Re: [CONTRIB] DHCP Pool usage
PostPosted: Mon May 05, 2008 5:34 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 05, 2006 6:16 am
Posts: 338
Location: South Carolina
Thank you for noticing that hilton.

Here is my revised script that fixes that issue as well as adds the ability to use the script when running multiple dhcp servers.

Tested on v3.7
Code:
# WarnAt needs to be at what percentage you want to be warned you are running out of IP addresses.
:local WarnAt 10
#Name of DHCP Pool you want to monitor
:local DHCPPoolName dhcp_pool1
#Your Email to notify you when running out of available ip's
:local Email my@email.com
#Your mail server ip address
:local EmailServer 0.0.0.0

#Declare Variable
:local Total

:foreach i in=[/ip pool get $DHCPPoolName ranges] do={
#Get the DHCP pool range and put into a string.
:local range [:tostr $i]
#Get the Start address of the range
:local Start [:pick $range 0 [:find $range "-"]]
#Get the End address of the range
:local Stop [:pick $range ([:find $range "-"] + 1) 31]
#Calculate how many IP's are in the Pool by subtracting the end address and the start address and add one.
:local ip ($Stop - $Start +1 )
#Save the size of the pool to Total
:set Total ($ip + $Total)
}

#Get the name of the Server that is using the Pool
:local Server [/ip dhcp-server get [/ip dhcp-server find address-pool="$DHCPPoolName"] name]
#Get the number of IP address's used in the pool
:local Used [/ip dhcp-server lease print count-only where server=[/ip dhcp-server get [/ip dhcp-server find address-pool=$DHCPPoolName] name]]
#Subtract used from total to get available
:local Available ($Total - $Used)
#Calculate percentage IP's available
:local Perc (($Available * 100) / $Total)
#Setup e-mail
:local Subject ([/system identity get name] . " DHCP pool is at $Perc")
:local Body ("Out of $Total addresses you have $Available available")

#Send out Email when available ip's percentage is below or equal to warnat
:if ($Perc <= $WarnAt) do={
  /tool e-mail send to=$Email subject=$Subject body=$Body server=$EmailServer
}
:log info $Body


Top
 Profile  
 
 Post subject: Re: [CONTRIB] DHCP Pool usage
PostPosted: Thu May 08, 2008 5:26 pm 
Offline
Long time Member
Long time Member
User avatar

Joined: Thu Sep 07, 2006 5:12 pm
Posts: 590
Location: Jozi (aka Johannesburg), South Africa
Thanks a lot!

_________________
Regards
Hilton


Top
 Profile  
 
 Post subject: Re: [CONTRIB] DHCP Pool usage
PostPosted: Wed Oct 21, 2009 5:55 am 
Offline
just joined
User avatar

Joined: Thu Jun 14, 2007 2:52 am
Posts: 23
Can someone please provide a script to send an email when an IP is given out by a DHCP server/pool? Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 2 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
MUM Poland and MUM China free REGISTRATION OPEN