What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

How to monitor Windows DHCP Scope Release?

Votes:

0

Hello Team, I want to monitor windows DHCP scope release, ideally the sensor can return to a percent, which is showing in which percent address is in used.

I have created the custom sensor

" NETSH DHCP Server \\DHCPserver show mibinfo"

it won't work with an error.

So question here are:

  1. Do you have any plan to create such sensor? I think many IT Pros do need it.
  2. If you have no plan to create such sensor, can you please help me to create the custom sensor?

Thanks Best regards, James

dhcp release windows

Created on Nov 8, 2010 1:03:35 PM

Last change on Nov 8, 2010 2:44:33 PM by  Torsten Lindner [Paessler Support]



Best Answer

Accepted Answer

Votes:

3

Here is a way to monitor DHCP statistics per scope:

Summary

Monitor DHCP statistics, using DHCP MIB and PRTG SNMP-Custom sensors.

Steps

1. Install the snmp service in your DHCP server if not installed, using add/remove windows components. Then go to Network and management tools and install the service.

2. Once the snmp service is installed, click on it, then click on the security tab. Specify the community name and hosts allowed to get snmp info.

3. Check the available OID's in the DHCP-MIB You will find all the relevant MIB values related to the DHCP scope statistics:

dhcpScope1.3.6.1.4.1.311.1.3.2
scopeTable1.3.6.1.4.1.311.1.3.2.1
scopeTableEntry1.3.6.1.4.1.311.1.3.2.1.1
subnetAdd1.3.6.1.4.1.311.1.3.2.1.1.1.ScopeAddress
noAddInUse (Used IPs)1.3.6.1.4.1.311.1.3.2.1.1.2.ScopeAddress
noAddFree ((Available IPs))1.3.6.1.4.1.311.1.3.2.1.1.3.ScopeAddress
noPendingOffers1.3.6.1.4.1.311.1.3.2.1.1.4.ScopeAddress

4. Add a PRTG SNMP Custom or SNMP Custom Advanced Sensor with the MIB value required, and make sure you modify the SNMP credentials. Example, if your scope is 192.168.100.0 and you want to know the number of used IP's, the complete OID will look like this:

1.3.6.1.4.1.311.1.3.2.1.1.2.192.168.100.0

5. Then You can add notifications and thresholds per sensor. Ex.: Set a notification to send an email/sms if the number of available IPs are below 10.


Edited by Mod, thanks for the contribution. Some notes/comments:

  1. Since the data is a SNMP Table, this is a great opportunity to try-out the SNMP Custom Table sensor
  2. If you encounter Generic Error (SNMP error # 5) on Windows Server 2012, please refer to this
  3. If you wish to monitor DHCP using powershell instead, there are several customer-shared scripts available, pick the one that suits you best:

Best Regards,
Luciano Lingnau [Paessler Support]

Created on May 14, 2013 6:37:19 AM

Last change on Mar 13, 2018 8:19:10 AM by  Luciano Lingnau [Paessler]



40 Replies

Votes:

0

Hello,

yes we plan to add such a sensor to PRTG, however I can't give you an ETA yet. Please bear with us.

Best Regards.

Created on Nov 8, 2010 3:51:40 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Hi Paessler Support,

Does it support on the latest version yet?

Created on May 27, 2011 10:17:05 AM



Votes:

0

PRTG does have a DHCP-Sensor now, but this will only show if PRTG would get a DHCP-assigned IP or not (i.e. if there is at least one free DHCP-IP).

Created on May 27, 2011 1:15:20 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Does PRTG have this sensor now? If yes, can you advise which one to use. I'm currently using PRTG 9.

Created on Jul 12, 2012 3:06:15 AM



Votes:

0

It's on the wish-list.

Created on Jul 13, 2012 10:57:14 AM by  Torsten Lindner [Paessler Support]



Accepted Answer

Votes:

3

Here is a way to monitor DHCP statistics per scope:

Summary

Monitor DHCP statistics, using DHCP MIB and PRTG SNMP-Custom sensors.

Steps

1. Install the snmp service in your DHCP server if not installed, using add/remove windows components. Then go to Network and management tools and install the service.

2. Once the snmp service is installed, click on it, then click on the security tab. Specify the community name and hosts allowed to get snmp info.

3. Check the available OID's in the DHCP-MIB You will find all the relevant MIB values related to the DHCP scope statistics:

dhcpScope1.3.6.1.4.1.311.1.3.2
scopeTable1.3.6.1.4.1.311.1.3.2.1
scopeTableEntry1.3.6.1.4.1.311.1.3.2.1.1
subnetAdd1.3.6.1.4.1.311.1.3.2.1.1.1.ScopeAddress
noAddInUse (Used IPs)1.3.6.1.4.1.311.1.3.2.1.1.2.ScopeAddress
noAddFree ((Available IPs))1.3.6.1.4.1.311.1.3.2.1.1.3.ScopeAddress
noPendingOffers1.3.6.1.4.1.311.1.3.2.1.1.4.ScopeAddress

4. Add a PRTG SNMP Custom or SNMP Custom Advanced Sensor with the MIB value required, and make sure you modify the SNMP credentials. Example, if your scope is 192.168.100.0 and you want to know the number of used IP's, the complete OID will look like this:

1.3.6.1.4.1.311.1.3.2.1.1.2.192.168.100.0

5. Then You can add notifications and thresholds per sensor. Ex.: Set a notification to send an email/sms if the number of available IPs are below 10.


Edited by Mod, thanks for the contribution. Some notes/comments:

  1. Since the data is a SNMP Table, this is a great opportunity to try-out the SNMP Custom Table sensor
  2. If you encounter Generic Error (SNMP error # 5) on Windows Server 2012, please refer to this
  3. If you wish to monitor DHCP using powershell instead, there are several customer-shared scripts available, pick the one that suits you best:

Best Regards,
Luciano Lingnau [Paessler Support]

Created on May 14, 2013 6:37:19 AM

Last change on Mar 13, 2018 8:19:10 AM by  Luciano Lingnau [Paessler]



Votes:

0

I know this is an older post but i could never get this to work and i figured out why. when using a windows DHCP server and you have multiple scopes the above OIDs need to have the subnet's IP address of the scope at the end of the OID. in other words if you want to see the free IP's and you have 2 scopes for subnets 10.10.0.0 and 10.20.0.0 you would use the OIDs 1.3.6.1.4.1.311.1.3.2.1.1.3.10.10.0.0 and 1.3.6.1.4.1.311.1.3.2.1.1.3.10.20.0.0 all the other OIDs listed above work the same way when you have multiple scopes. Hope this helps someone!

Created on Mar 30, 2014 1:50:45 PM



Votes:

0

Since SNMP has been deprecated in Windows Server 2012, you cannot query DHCP statistics using SNMP any more. Is there a sensor in the works that will allow us to monitor DHCP scopes on Windows Server 2012?

Created on Jul 29, 2014 3:25:38 PM



Votes:

0

At the moment, SNMP is being deprecated but it can still be installed through features on Windows Server 2012. We don't have any sensors that can monitor this at this time through any other protocols.

Created on Jul 29, 2014 7:40:36 PM by  Greg Campion [Paessler Support]



Votes:

0

We are using the above method to successfully monitor many of our DHCP scopes. (Thank you for your excellent posts.)

The problem that we are now having is that we are using a (Microsoft) super scope with two class C ranges for wireless clients... Using the above method requires two separate sensors which alert us when either range is exhausted of free addresses. The problem with that is that what we ACTUALLY need to be notified of is when BOTH scopes are exhausted.

- Is there a way to modify the OIDs listed above to monitor a super-scope? - Or is there a way to create a custom sensor that uses Regular Expressions to compare two or more existing sensors? - Or is there another solution all together that we haven't considered?

Thanks in advance for any assistance. :)

Created on Sep 17, 2014 5:21:36 PM



Votes:

0

Hi Stu,

You could use the sensor factory for that - you can determine when the sensor will go into a down state depending on the state of the used source channels.

Channel definition

#1:Available in Scope 1
Channel(1234,1)
#2:Available in Scope 2
Channel(1235,1)

Error Handling > Use custom formula status(1234) AND status(1235)

This should do what you're looking for :)

Created on Sep 18, 2014 9:25:35 AM by  Stephan Linke [Paessler Support]

Last change on Sep 18, 2014 9:25:49 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hello, on my Windows 2012 R2 getting the OID 1.3.6.1.4.1.311.1.3.2.1.1.3.10.8.83.0 (for my 10.8.83.0/24 network) is no longer working.

The PRTG error code: Generic Error (SNMP error # 5)

Thanks in advance for any ideas!

Created on Nov 4, 2014 4:12:52 PM



Votes:

0

This seems to be a bug of Windows 2012 R2, where after a reboot the dll's for monitoring DHCP servers is simply not loaded. See this thread at windows technet for further details. Not much we can do about that :(

Created on Nov 7, 2014 8:05:34 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hello, are there any news about the Problem with the dhcp sensor? We have the same problem too.

Created on Dec 10, 2014 6:26:25 AM



Votes:

0

What OS are you using?

Created on Dec 10, 2014 8:16:32 AM by  Stephan Linke [Paessler Support]



Votes:

0

Windows 2012 R2

Created on Dec 10, 2014 8:46:24 AM



Votes:

0

As stated before, it's a problem of the operating system not propagating it over SNMP anymore.

Quote from Stephan: This seems to be a bug of Windows 2012 R2, where after a reboot the dll's for monitoring DHCP servers is simply not loaded. Not much we can do about that :(

Nothing has changed about that as far as I know. Please contact Microsoft about the issue. Thanks!

Created on Dec 10, 2014 9:22:19 AM by  Stephan Linke [Paessler Support]



Votes:

1

So I was facing the same problem here, trying to monitor DHCP scopes using PRTG, the DHCP server being a role on a Windows Server 2012 R2. I found the following:

  • when running SNMP as a service, I get the "error #5" message.
  • when stopping the SNMP service, instead running C:\Windows\System32\snmp.exe as SYSTEM from a scheduled task that runs at server startup, it runs perfectly each time. The C:\Windows\system32\snmp.exe application has to be allowed through Windows Firewall as simply allowing the SNMP service does not work.
  • Is someone else seeing this?
  • Is this a usable fix or does this tear a giant security hole into that server by running the service as SYSTEM?

Created on Nov 30, 2015 6:11:34 PM

Last change on Oct 13, 2016 11:31:06 AM by  Luciano Lingnau [Paessler]



Votes:

0

It shouldn't be that big of an issue. However, to be sure, I'd go ask in the technet forums. Those guys have more insights on these kind of things than we do :)

Created on Dec 1, 2015 8:14:48 AM by  Stephan Linke [Paessler Support]



Votes:

0

I just want to upvote the workaround proposed by SwissJay about starting the SNMP process with a scheduled task instead of the service. Once you do that, it allows the normal sensors to work properly again.

Created on Jan 11, 2016 9:23:53 AM



Votes:

0

@SwissJay - brilliant solution, works a treat.

Created on Apr 19, 2016 9:26:42 AM



Votes:

0

@swissjay: You so made my day! I already gave up on this 'till I read your post. Now I can finally monitor my DHCP scopes...

Created on Dec 8, 2016 3:46:05 PM



Votes:

0

Hi, If you want you can use the following powershell script (which is not deprecated on 2012 server) with an advanced exe/script sensor. Put this code as "dhcpprtg.ps1" in the EXE/XML folder.

# Import modules 
Import-Module DhcpServer
Import-Module pscx

$server= $env:computername
$scope = Get-DhcpServerv4Scope -ComputerName $server
$ScopeList = Get-DhcpServerv4Scope -ComputerName $Server
$scope=$ScopeList.ScopeID

$debut='<?xml version="1.0" encoding="Windows-1252" ?><prtg>'
Try{ 
    $ScopeInfo = Get-DhcpServerv4Scope -ComputerName $Server -ScopeId $Scope 
    $ScopeStats = Get-DhcpServerv4ScopeStatistics -ComputerName $Server -ScopeId $Scope | Select ScopeID,AddressesFree,AddressesInUse,PercentageInUse,ReservedAddress 
	$ScopeReserved =$ScopeStats.ReservedAddress	
    } 
   Catch{ 
    } 

$result ="<result><channel>PercentageInUse</channel><unit>Percent</unit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><warning>0</warning><float>1</float><value>"+$ScopeStats.PercentageInUse+"</value><LimitMaxError>90</LimitMaxError><LimitMaxWarning>75</LimitMaxWarning><LimitWarningMsg>Attention 75% des adresse IP affectes !</LimitWarningMsg><LimitErrorMsg>Attention 90% des adresse IP affectes !</LimitErrorMsg><LimitMode>1</LimitMode></result>"
$result +="<result><channel>AddressesInUse</channel><unit>Custom</unit><customUnit>IP</customUnit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><float>0</float><value>"+$ScopeStats.AddressesInUse+"</value></result>"
$result +="<result><channel>AddressesFree</channel><unit>Custom</unit><customUnit>IP</customUnit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><float>0</float><value>"+$ScopeStats.AddressesFree+"</value></result>"
$result +="<result><channel>ReservedAddress</channel><unit>Custom</unit><customUnit>IP</customUnit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><float>0</float><value>"+$ScopeStats.ReservedAddress+"</value></result>"
$result +="<text>LeaseDuration "+$ScopeInfo.LeaseDuration+"</text>"

$fin='</prtg>'
$xml=$debut+$result+$fin
Format-Xml -InputObject $xml

Created on Apr 12, 2017 11:34:02 AM

Last change on Apr 12, 2017 12:35:03 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

Hi there,

Thanks for the share! Perhaps someone can try this to verify the functionality?

Best regards.

Created on Apr 12, 2017 12:35:53 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

Thanks for the PowerShell script, I may just adapt it to our environment and use it. However, in the past, I've noticed that PowerShell scripts can create a bit more load on PRTG than simple SNMP queries. But good to have, I will test.

Created on Apr 12, 2017 1:46:11 PM



Votes:

0

experts, I am having same issue when monitor dhcp scope - snmp error 5

I have tried to apply: when stopping the SNMP service, instead running C:\Windows\System32\snmp.exe as SYSTEM from a scheduled task that runs at server startup, it runs perfectly each time. The C:\Windows\system32\snmp.exe application has to be allowed through Windows Firewall as simply allowing the SNMP service does not work.

should I completely disable snmp from service and run snmp.exe as scheduled task in windows ?

Created on May 15, 2017 12:04:14 PM

Last change on May 22, 2017 4:57:26 AM by  Luciano Lingnau [Paessler]



Votes:

0

So I tried the PS1 script in an advanced exe/script sensor on my DHCP server. Any clue what this result is all about?

XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)

Created on May 19, 2017 4:28:42 PM

Last change on May 22, 2017 4:57:03 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hello randhall,
thank you for your reply.

Please note that we can only offer limited support for customer-shared scripts. However:

  1. Make sure that you meet the requirements to run powershell sensors as described here
  2. Since there's a $env:computername, the script most likely requires you to enable the Environment: Set placeholders as environment values option in the sensor's settings.
  3. The sensor needs to run with an account that has sufficient privileges to query information from the remote (monitored system) via powershell remoting. The remote system must allow remote powershell connections.

As a workaround I suggest that you try the snmp-based approach workaround.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on May 22, 2017 7:33:23 AM by  Luciano Lingnau [Paessler]



Votes:

0

I have been using DHCP 2012 R2 with PRTG for monitoring specific pool and with C:\Windows\system32\snmp.exe running at start up works for a while, and after that sensor goes into error/down state. After rebooting DHCP server all is ok until some time (around week) and again all sensors used to monitor IP pools are down. Since this solution is not reliable I cannot use it in enterprise.

I was happy and loved that was able to monitor pools using PRTG, but now I guess I have to find another solution.

The option with the script is working for anybody? maybe I should try that and forget about the sensor that dying after a week .......

Created on Jun 28, 2017 5:46:57 PM



Votes:

0

Hello AdamG,
thank you for your reply.

Out of curiosity, which error did the sensors display after a week?

As for the script, it's the "more elegant" solution with the script, it should work. Keep in mind that some configuration needs to be done for custom powershell sensors to run:

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Jun 30, 2017 7:57:27 AM by  Luciano Lingnau [Paessler]



Votes:

0

Luciano,

Sorry for the delay.

The sensor is giving:

No response (check: firewalls, routing, snmp settings of device, IPs, SNMP version, community, passwords etc) (SNMP error # -2003)

Its not only the one monitor DHCP but also CPU Memory etc...

Created on Sep 8, 2017 11:59:26 AM

Last change on Sep 11, 2017 6:43:59 AM by  Luciano Lingnau [Paessler]



Votes:

0

I have decided to use PS script but after placing $server= "dhcpwin.myorg.org" and runing script manually I have all data, but sensors shows empty values in last value, min & max - any thoughts??????????

Created on Sep 14, 2017 12:11:37 PM



Votes:

0

Give up on SNMP as a method to monitor a Windows based DHCP server. Microsoft has removed the MIB OID structure that is used to query that information. You have to use another method as described above or in this KB article that I wrote.

https://kb.paessler.com/en/topic/75819-single-sensor-to-display-dhcp-scope-status

Created on Sep 14, 2017 4:12:28 PM



Votes:

1

I've been using the workaround from SwissJay for a while.
It worked perfectly!

However, I had to install some Health Agents which have a dependency on the SNMP service.
Unfortunately it meant I couldn't use that workaround anymore.

So I decided to use the script Crazypod provided, only to run into the "XML: The returned XML does not match the expected schema. (code: PE233) -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)" error.

I ended up modifying the script in order to get the correct XML output:

## Import modules 
Import-Module DhcpServer

$server = $Args[0]
$ScopeList = Get-DhcpServerv4Scope -ComputerName $Server
$scope = $ScopeList.ScopeID

Write-Host "<prtg>"
Try{ 
    $ScopeStats = Get-DhcpServerv4ScopeStatistics -ComputerName $Server -ScopeId $Scope | Select ScopeID,AddressesFree,AddressesInUse,PercentageInUse,ReservedAddress 
    } 
   Catch{ 
    Write-Host $_
    } 

Write-Host "<result><channel>PercentageInUse</channel><unit>Percent</unit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><warning>0</warning><float>1</float><value>" $ScopeStats.PercentageInUse "</value><LimitMaxError>90</LimitMaxError><LimitMaxWarning>75</LimitMaxWarning><LimitWarningMsg>Over 75% addresses in use!</LimitWarningMsg><LimitErrorMsg>Over 90% addresses in use!</LimitErrorMsg><LimitMode>1</LimitMode></result>"
Write-Host "<result><channel>AddressesInUse</channel><unit>Custom</unit><customUnit>IP</customUnit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><float>0</float><value>" $ScopeStats.AddressesInUse "</value></result>"
Write-Host "<result><channel>AddressesFree</channel><unit>Custom</unit><customUnit>IP</customUnit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><float>0</float><value>" $ScopeStats.AddressesFree "</value></result>"
Write-Host "<result><channel>ReservedAddress</channel><unit>Custom</unit><customUnit>IP</customUnit><mode>Absolute</mode><showChart>1</showChart><showTable>1</showTable><float>0</float><value>" $ScopeStats.ReservedAddress "</value></result>"
Write-Host "</prtg>"
Parameter:%host
Security Context:Use Windows credentials of parent device



Oh, and I had to install the DHCP Server Tools (Feature: Role Administration Tools) on my monitoring cluster in order to get the Get-DhcpSeriverv4Scope command in PowerShell.

The only thing I'm still running into, is whilst on our test server all channels work perfectly, on our production cluster the PercentageInUse channel displays zeros in the table (whilst when running the script from PowerShell, it does give the percentage).
It's not the most important issue; I'm alerting on AddressesFree anyway.

Created on Nov 6, 2017 3:31:51 PM

Last change on Nov 7, 2017 6:20:54 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hello Corné van den Bosch,
thank you for sharing! I've just changed the formatting a bit.

Cheers!

Created on Nov 7, 2017 6:22:03 AM by  Luciano Lingnau [Paessler]



Votes:

1

I switched to the following home-cooked script recently because the stats given by the other script and SNMP are bogus (especially "Leases In Use"), due to what I would consider a Microsoft "bug" (see https://social.technet.microsoft.com/Forums/windowsserver/en-US/43c2bcc9-4c4e-420d-96db-11f05843859c/dhcp-leases-vs-dhcp-statistics?forum=winservergen):

param(
	[string] $DHCPServerName,
	[string] $ScopeID
)
# Get Total by adding bogus stats returned by Microsoft
$ScopeStats = Invoke-Command -ComputerName $DHCPServerName -ScriptBlock { get-dhcpserverv4scopestatistics -ScopeId $using:ScopeID }
$FakeInUse = ($ScopeStats).InUse
$FakeFree = ($ScopeStats).Free
$Total = $FakeInUse + $FakeFree
# Find actual values by counting issued leases
$ActualInUse = (Invoke-Command -ComputerName $DHCPServerName -ScriptBlock { get-dhcpserverv4lease -ScopeId $using:ScopeID }).Count
$ActualFree = $Total - $ActualInUse

Write-Host '<?xml version="1.0" encoding="Windows-1252" ?>'
Write-Host "<prtg>"
Write-Host "<result>"
Write-Host "<channel>Total Addresses</channel>"
Write-Host "<value>$Total</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel>Used Addresses</channel>"
Write-Host "<value>$ActualInUse</value>"
Write-Host "</result>"
Write-Host "<result>"
Write-Host "<channel>Available Addresses</channel>"
Write-Host "<value>$ActualFree</value>"
Write-Host "</result>"
Write-Host "</prtg>"
Parameters%device ScopeName
Example%device 10.32.105.0
EnvironmentDefault Environment
Security ContextUse Windows credentials of parent device

I have this querying 9 scopes on 2 DHCP servers (18 scopes total) every 5 minutes without any performance issues. I run the script on the PRTG server itself and Powershell runs the code remotely on the 2 DHCP servers. The reason I did this is so I would NOT have to install the DHCP management tools on the PRTG server as Powershell leverages those tools on the DHCP server (since their part of the role).

Please note that I'm not a PowerShell Pro, so if you can optimize this in any way, feel free to let me know :)

Hope this helps someone...

Created on Nov 7, 2017 3:41:21 PM



Votes:

0

Hi, This PS script above by SwissJay works great. I don't have enough reputation to vote so just saying :)

Created on Jan 31, 2018 8:12:02 AM



Votes:

6

I cooked up my own script for this a couple a month or so ago which also monitors DHCP replication from one server to another. The code could probably use a bit of tidying up and commenting, but functions quite nicely for me. Call it using:

DHCPStatus.ps1 -ComputerName %host

Script

Param
(
    [Parameter (Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string] $ComputerName
)

Write-Host '<prtg>'

$msg = @()
$failover = Get-DhcpServerv4Failover -ComputerName $ComputerName

foreach ($fo in $failover)
{
    Write-Host '<result>'
    Write-Host "<channel>$($fo.name)</channel>"

    # States: 'NoState', 'Normal', 'Init', 'CommunicationInterrupted', 'PartnerDown', 'PotentialConflict', 'Startup', 'ResolutionInterrupted', 'ConflictDone', 'Recover', 'RecoverWait', 'RecoverDone'
    switch ($fo.state)
    {
        'NoState'                  { Write-Host '<value>0</value>' }
        'Normal'                   { Write-Host '<value>1</value>' }
        'Init'                     { Write-Host '<value>2</value>' }
        'CommunicationInterrupted' { Write-Host '<value>3</value>' }
        'PartnerDown'              { Write-Host '<value>4</value>' }
        'PotentialConflict'        { Write-Host '<value>5</value>' }
        'Startup'                  { Write-Host '<value>6</value>' }
        'ResolutionInterrupted'    { Write-Host '<value>7</value>' }
        'ConflictDone'             { Write-Host '<value>8</value>' }
        'Recover'                  { Write-Host '<value>9</value>' }
        'RecoverWait'              { Write-Host '<value>10</value>' }
        'RecoverDone'              { Write-Host '<value>11</value>' }
        default                    { Write-Host '<value>-1</value>' }
    }

    Write-Host '<ValueLookup>windows.dhcp.replication.state</ValueLookup>'
    Write-Host '</result>'

    # Note any replication relationship that isn't "normal"

    if ($fo.State -ne 'Normal') { $msg += "Replication Relationship $($fo.Name) state: $($fo.State)" }
}


$scopes = Get-DhcpServerv4Scope -ComputerName $ComputerName | Where-Object { $_.State -eq 'Active' }

foreach ($s in $scopes)
{
    $ss = Get-DhcpServerv4ScopeStatistics -ComputerName $ComputerName -ScopeId $s.ScopeID

    # Warn at less than 10% free or 10 IP addresses, whichever is less
    try
    {
        $totaddr = $ss.Free + $ss.InUse
        $tenpct = $totaddr / 10

        if ($tenpct -le 10)
        {
            # 10% of available addresses is less than 10 - default to 10.
            $warn = 10
            $warnpct = 10.0 / $totaddr * 100
        }
        else
        {
            # 10% of available addresses is greater than 10, default to 10%
            $warn = $tenpct
            $warnpct = 10
        }
    }
    catch
    {
        # Since we couldn't calculate the minimum value for whatever reason, don't return warning levels
        $warn = null
        $warnpct = null
    }

    Write-Host '<result>'
    Write-Host "<channel>$($s.Name) IPs free</channel>"
    Write-Host "<value>$($ss.Free)</value>"
    
    if ($warn)
    {
        Write-Host '<LimitMode>1</LimitMode>'
        Write-Host "<LimitMinWarning>$warn</LimitMinWarning>"
        Write-Host "<LimitMinError>$($warn / 2)</LimitMinError>"
    }

    Write-Host '</result>'

    Write-Host '<result>'
    Write-Host "<channel>$($s.Name) % In Use</channel>"
    Write-Host "<value>$($ss.PercentageInUse)</value>"
    Write-Host '<unit>Percent</unit>'

    if ($warnpct)
    {
        Write-Host '<LimitMode>1</LimitMode>'
        Write-Host "<LimitMaxWarning>$(100 - $warnpct)</LimitMaxWarning>"
        Write-Host "<LimitMaxError>$(100 - ($warnpct / 2))</LimitMaxError>"
    }

    Write-Host '</result>'
}

if ($msg.Count -eq 0)
{
    Write-Host "<text>All scope relationships normal</text>"
}
else
{
    Write-Host "<text>$($msg -join ',')</text>"
}

Write-Host '</prtg>'

Note that you'll also need a custom lookup "windows.dhcp.replication.state.ovl" saved in lookups/custom, as follows:

Lookup

<?xml version="1.0" encoding="UTF-8"?>
<ValueLookup id="windows.dhcp.replication.state" desiredValue="1" undefinedState="Error" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PaeValueLookup.xsd">
	<Lookups>
		<SingleInt state="Error" value="-1">Unknown Status</SingleInt>
		<SingleInt state="Error" value="0">No State</SingleInt>
		<SingleInt state="Ok" value="1">Normal</SingleInt>
		<SingleInt state="Warning" value="2">Init</SingleInt>
		<SingleInt state="Error" value="3">Communication Interrupted</SingleInt>
		<SingleInt state="Error" value="4">Partner Down</SingleInt>
		<SingleInt state="Warning" value="5">Potential Conflict</SingleInt>
		<SingleInt state="Warning" value="6">Startup</SingleInt>
		<SingleInt state="Error" value="7">Resolution Interrupted</SingleInt>
		<SingleInt state="Ok" value="8">Conflict Done</SingleInt>
		<SingleInt state="Warning" value="9">Recover</SingleInt>
		<SingleInt state="Warning" value="10">Waiting for Recovery</SingleInt>
		<SingleInt state="Ok" value="11">Recovery Done</SingleInt>
	</Lookups>
</ValueLookup>

Created on Mar 11, 2018 1:41:52 PM

Last change on Oct 1, 2021 12:19:29 PM by  Luciano Lingnau [Paessler]



Votes:

1

The script by rhil_au works well for me, after I made 2 changes (full edited script below, for those interested):

  • made a few edits so the script would run on our PRTG server as we did not add the DHCP mgmt modules to it, so it runs the Powershell commands on the DHCP server remotely,
  • had to round the percentages returned by the script as PRTG would show 0% otherwise in the GUI (could be related to localization perhaps?!)

But +1 for failover monitoring, didn't think of that!! Thanks!

Param
(
    [Parameter (Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string] $ComputerName
)

Write-Host '<prtg>'

$msg = @()
#$failover = Get-DhcpServerv4Failover -ComputerName $ComputerName
$failover = Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-DhcpServerv4Failover -ComputerName $using:ComputerName }


foreach ($fo in $failover)
{
    Write-Host '<result>'
    Write-Host "<channel>$($fo.name)</channel>"

    # States: 'NoState', 'Normal', 'Init', 'CommunicationInterrupted', 'PartnerDown', 'PotentialConflict', 'Startup', 'ResolutionInterrupted', 'ConflictDone', 'Recover', 'RecoverWait', 'RecoverDone'
    switch ($fo.state)
    {
        'NoState'                  { Write-Host '<value>0</value>' }
        'Normal'                   { Write-Host '<value>1</value>' }
        'Init'                     { Write-Host '<value>2</value>' }
        'CommunicationInterrupted' { Write-Host '<value>3</value>' }
        'PartnerDown'              { Write-Host '<value>4</value>' }
        'PotentialConflict'        { Write-Host '<value>5</value>' }
        'Startup'                  { Write-Host '<value>6</value>' }
        'ResolutionInterrupted'    { Write-Host '<value>7</value>' }
        'ConflictDone'             { Write-Host '<value>8</value>' }
        'Recover'                  { Write-Host '<value>9</value>' }
        'RecoverWait'              { Write-Host '<value>10</value>' }
        'RecoverDone'              { Write-Host '<value>11</value>' }
        default                    { Write-Host '<value>-1</value>' }
    }

    Write-Host '<ValueLookup>windows.dhcp.replication.state</ValueLookup>'
    Write-Host '</result>'

    # Note any replication relationship that isn't "normal"

    if ($fo.State -ne 'Normal') { $msg += "Replication Relationship $($fo.Name) state: $($fo.State)" }
}


#$scopes = Get-DhcpServerv4Scope -ComputerName $ComputerName | Where-Object { $_.State -eq 'Active' }
$scopes = Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-DhcpServerv4Scope -ComputerName $using:ComputerName | Where-Object { $_.State -eq 'Active' } }


foreach ($s in $scopes)
{
    #$ss = Get-DhcpServerv4ScopeStatistics -ComputerName $ComputerName -ScopeId $s.ScopeID
    $ss = Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-DhcpServerv4ScopeStatistics -ComputerName $using:ComputerName -ScopeId $using:s.ScopeID }

    # Warn at less than 10% free or 10 IP addresses, whichever is less
    try
    {
        $totaddr = $ss.Free + $ss.InUse
        $tenpct = $totaddr / 10

        if ($tenpct -le 10)
        {
            # 10% of available addresses is less than 10 - default to 10.
            $warn = 10
            $warnpct = 10.0 / $totaddr * 100
        }
        else
        {
            # 10% of available addresses is greater than 10, default to 10%
            $warn = $tenpct
            $warnpct = 10
        }
    }
    catch
    {
        # Since we couldn't calculate the minimum value for whatever reason, don't return warning levels
        $warn = null
        $warnpct = null
    }

    Write-Host '<result>'
    Write-Host "<channel>$($s.Name) IPs free</channel>"
    Write-Host "<value>$($ss.Free)</value>"
    
    if ($warn)
    {
        Write-Host '<LimitMode>1</LimitMode>'
        Write-Host "<LimitMinWarning>$warn</LimitMinWarning>"
        Write-Host "<LimitMinError>$($warn / 2)</LimitMinError>"
    }

    Write-Host '</result>'

    Write-Host '<result>'
    Write-Host "<channel>$($s.Name) % In Use</channel>"
    Write-Host '<unit>Percent</unit>'
#    Write-Host "<value>$($ss.PercentageInUse)</value>"
    Write-Host "<value>$([math]::Round($ss.PercentageInUse))</value>"


    if ($warnpct)
    {
        Write-Host '<LimitMode>1</LimitMode>'
        Write-Host "<LimitMaxWarning>$(100 - $warnpct)</LimitMaxWarning>"
        Write-Host "<LimitMaxError>$(100 - ($warnpct / 2))</LimitMaxError>"
    }

    Write-Host '</result>'
}

if ($msg.Count -eq 0)
{
    Write-Host "<text>All scope relationships normal</text>"
}
else
{
    Write-Host "<text>$($msg -join ',')</text>"
}

Write-Host '</prtg>'

Created on Mar 12, 2018 7:53:31 PM

Last change on Mar 13, 2018 8:20:08 AM by  Luciano Lingnau [Paessler]



Votes:

0

Hello SwissJay and rhil_au
thank you for your replies.

@rhil_au - Many thanks for the script, it's a thing of beauty.Very tidy and extra points for using a custom lookup. :)


Regarding @SwissJay's changes/notes:

made a few edits so the script would run on our PRTG server as we did not add the DHCP mgmt modules to it, so it runs the Powershell commands on the DHCP server remotely,

I (personally) also prefer this approach. Having to install as little software as possible on the remote probe. Running it via Invoke-Command definitively adds the Skookum to it.

had to round the percentages returned by the script as PRTG would show 0% otherwise in the GUI (could be related to localization perhaps?!)

I'm able to confirm an open bug with the API for Custom sensors (XML based), when PRTG is unable to identify a numerical value between the <value></value> it displays the value of 0 (zero) instead of producing a parse error. Enabling the "Log Result to Disk" would tell you what the actual output was. But it could definitively be a localization issue like dot vs comma.

Best Regards,
Luciano Lingnau [Paessler Support]

Created on Mar 13, 2018 8:29:04 AM by  Luciano Lingnau [Paessler]

Last change on Apr 7, 2022 1:07:14 PM by  Luciano Lingnau [Paessler]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.