Skip to main content

 

DHCP Scope full monitor (Windows only, SNMP)

4 months ago
OfflineLinwood Ferguson
Linwood Ferguson
Description:

 Active monitor which polls all scopes on windows servers and reports if they are getting full.  The result (which is available in %ActiveMonitor.Payload  will show each scope's current size and in use.  The limits as coded are that it alarms if you are EITHER under 10% free or 10 IP's, but you can change that at the top of the code.

Windows only, and only tested on 2003 and 2008 but it's a pretty old MIB.

Language: VB Script/JScript
Code:
 

'  Active monitor for DHCP on MIcrosoft servers.
'  Limits are hard coded below
'  Messages in log indicate statistics whether success or failure

LimitPct = 0.10  ' Percentage (as real number) below which we alarm
LimitAdd = 10    ' Or alarm if less than this many addresses

set objSNMP = CreateObject("CoreAsp.SnmpRqst")
nDeviceID = Context.GetProperty("DeviceID")
set strResult = objSNMP.Initialize(nDeviceID)

On Error Resume Next

SubnetAdd ="1.3.6.1.4.1.311.1.3.2.1.1.1"
noAddInUse="1.3.6.1.4.1.311.1.3.2.1.1.2"
NoAddFree ="1.3.6.1.4.1.311.1.3.2.1.1.3"

Msg = ""
Index = -1
ThisOID = SubnetAdd
MaxAddresses = 0
FinalStatus = -1  ' This will mean we got none

Set myRegExp = New RegExp  ' So we can match subnet
myRegExp.IgnoreCase = True
myRegExp.Global = True
myRegExp.Pattern = "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b"  ' OK, this matches invalid IP's, but it is simpler

while index <  200  ' Safety limit just in case

    set oSnmpResponse= objSNMP.GetNext(ThisOID)
    if oSnmpResponse.Failed then
        index = 99999
        Msg = "Failed call to GetNext, err=" & oSnmpResponse.GetErrorMsg
        FinalStatus = 1
    else
        ThisOID = oSnmpResponse.GetOID  ' Value returned
        Subnet = oSnmpResponse.GetValue
        if myRegExp.Test(Subnet)  then
            if Subnet = right(ThisOID,len(Subnet)) then  ' Are we still in the list of subnets?
                if FinalStatus = -1 then FinalStatus = 0
                index = index + 1
                InUse = CInt(objSNMP.Get(noAddInUse & "." & Subnet).GetValue)
                Free = CInt(objSNMP.Get(noAddFree & "." & Subnet).GetValue)
                if InUse + Free =0 then Pct = 0 else Pct = (Free  / (Free + InUse)) 
                If Pct < LimitPct or Free < 10 then FinalStatus = 1
                Msg = Msg + vbcr + Subnet & ": In use=" & InUse & " Free=" & Free & " Pct Free=" & FormatPercent(Pct)
            else ' At end of list
                MaxAddresses = Index
                Index = 99999
            end if
        else ' Didn't get something that looks like a subnet
            MaxAddresses = Index
            Index = 99999
        end if
    end if
wend

If FinalStatus = 1 then Msg = "Fail: " & Msg
If FinalStatus = 0 then Msg = "Succeed: " & Msg
If FinalStatus = -1 then
    Msg = "Fail No DHCP"
    FinalStatus = 1
End If

Context.SetResult FinalStatus, Msg

-----
You liked this too3 people like this discussion.
 
Concluded

0 Conclusions:

2 Replies

OfflineTobias Feichtinger Tobias Feichtinger said 3 months ago

Hi

I have testet the Script on 2 DHCP Servers from Customers. And it works :)

But is there an option to mage the Monitor only for one Subnet?

Because we have got about 250 different Scopes and some of them are full an thats ok. And so i get an alarm because these Scopes are also in the script. So it would be good if you can add an variable where we can describe the subnet we want to be monitored.


OfflineThoralf Geese Thoralf Geese said 2 months ago

Hi, there is a litte erro in the script:

LimitPct = 0.10  ' Percentage (as real number) below which we alarm
LimitAdd = 10    ' Or alarm if less than this many addresses

The variable LimitAdd will not be used in the script  in Line 46 the Limit will set HARD so the first definition will never be used.

If Pct < LimitPct or Free < 10 then FinalStatus = 1

Replace 10 with LimitAdd and it will work fine.


Would you like to comment?

You must be a member. Sign In if you are already a member.

  • 669 views
  • $obj.VersionIndex versions
  • 2 replies
  • 0 followers
     
Post Date:
January 8, 2012
Posted By:
Linwood Ferguson

About this forum

  • 52,475 views
  • 75 topics
  • 20 followers
     

Viewed 669 times