New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


Single sensor to display DHCP scope status

Votes:

0

Your Vote:

Up

Down

I wanted to share this information because the Powershell integration with PRTG is difficult to comprehend at times. Let's put it this way, I sure found it difficult to understand!

I find that there are many things that I need to monitor but PRTG does not always supply a specific sensor to solve that problem.

One thing that forced me to make this work was that Microsoft depricated SNMP monitoring of DHCP services. They have completely removed the SNMP OID category for DHCP in their SNMP support on 2012 and higher servers. (Not a good decision Microsoft!!!)

I really needed to find a new way to get the current status of specific DHCP scopes that might fill up from time to time.

I know that there is a WMI scripting sensor but I wanted to write it in Powershell so that I could recycle the process for other Microsoft items that need monitoring via Powershell. This should help me to do that with small modifications. I am hoping to use this method with VMware PowerCLI to help monitor our VMware systems, too.

I use several probe servers so the first tasks were to:

  1. Add the DHCP Administration feature in Windows Server 2012r2 to the probe server using Windows Server Manager
  2. Import the Powershell module into the 32-bit Powershell environment
  3. Write a Powershell command that could capture the correct information without formatting. That command which returns an in-use percentage is here:

(get-dhcpserverv4scopestatistics -ComputerName servername -ScopeId $scopeid).PercentageInUse

ScopeID is the IP scope assigned to DHCP server. In this case our example is 10.10.20.0.

The second task was to create a script that would work with PRTG. I named it dhcpscopevalue.ps1 and placed it into the Custom Sensor/EXE location on the probe that will run the script. I did much Googling and found various PRTG examples, scripts, and Powershell tutorials that helped me figure it out.

That script is here:

<# Add the following parameters separated by spaces to the PRTG parameters field in the same order as listed.  Powershell requires them to be surrounded by single quotes.

Parameters Example: '10.10.20.0' '%host' '%windowsuser' '%windowspassword'
#>

Param(
[string]$scopeid,
[string]$hostname,
[string]$Username,
[string]$Password
)

# create credentials
$SecPassword = $Password | ConvertTo-SecureString -AsPlainText -force
$cred = new-object -typename System.Management.Automation.PSCredential ($Username, $SecPassword)

# Create session and run script. Use invoke-command with credentials. Import scopeid variable into scriptblock.

$ret = invoke-command -ComputerName $hostname -Credential $cred -ScriptBlock {Param($scopeid) (get-dhcpserverv4scopestatistics -ComputerName dhcpprd01 -ScopeId $scopeid).PercentageInUse} -ArgumentList $scopeid

# output data for prtg to use
write-host $ret":DHCP Scope $scopeid Used: $ret%"

# Do some housekeeping
Remove-Variable -Name scopeid

# The exit command seems to help end the script to avoid timeouts.
exit


The third task is to create a custom EXE sensor with the noted settings. Name it something useful and add a tag name that makes sense. An example of my probe name is DHCP Scope - Guest Wireless: 10.10.20.0. My tag is dhcppercent. The Security Context was changed to Use Windows credentials of parent device. The Value Type is float and I changed the Primary Channel field to ScopePercent(%). Remember to change the Value Type and the Primary Channel field when you first create the sensor. It cannot be modified later.

I made a PRTG Map for our Networking Team Members to leave on display so that they would have a visual monitoring of the important scopes. I also modified the sensor channel event thresholds to that it would show the proper warning and error conditions when it hit 90% and 100%. Once you have done all of this work, use the clone feature to make new ones and edit the appropriate settings after you clone the sensor. It saves a lot of time.

Please note: If you add more of these sensors, remember that each one runs another Powershell script which puts a big load on the computer. I found that I could safely run about 22 sensors with 60 sec. intervals, 44 sensors with 5 minute intervals, or 80 using 10 minute intervals. I could tell they were having problems because they would start showing 0 data values.

My next step will be to check out the new REST sensor or the EXEXML sensor and see if we can create a single sensor with multiple channels. I hope it will have a lighter load on the system by running a single script instead of many.

custom-script-exe custom-sensor dhcp powershell prtg scope snmp

Created on Sep 14, 2017 12:09:46 AM by  Tom Stone (0) 1



17 Replies

Votes:

0

Your Vote:

Up

Down

Hi Tom,

Awesome work, thanks for sharing! The script will find its way into our PRTG Sensor World soon :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Sep 14, 2017 12:59:37 PM by  Stephan Linke [Paessler Support]

Last change on Sep 14, 2017 12:59:37 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I forgot to credit some sources that helped me to figure out this solution in addition to the PRTG KB articles and documentation.

https://lockstepgroup.com/blog/extreme-basics-of-prtg-custom-sensors-with-powershell/ https://thedomainiown.wordpress.com/prtg-related/general-custom-exe-script/

Created on Sep 14, 2017 6:27:55 PM by  Tom Stone (0) 1



Votes:

0

Your Vote:

Up

Down

After 6 months: Has there been any progress implementing this as an "out-of-the-box"-sensor?

Created on Mar 6, 2018 1:31:12 PM by  Babylon6 (0) 1



Votes:

0

Your Vote:

Up

Down

I'm afraid this is not planned as a native sensor. It's part of the script world now, and if there is enough usage there, we can consider building a native sensor.

Created on Mar 7, 2018 11:22:30 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

That is sad to hear. It seems like Paessler is more and more ignoring new ideas and improvement recommendations from users. Don't get me wrong. Support has always been very good. Questions to support@ always get answered very fast. But in regards of improvements and enhancements to the system I feel pretty ignored right about now as I have brought in at least 10 new ideas for improvements over the last year and not even one of them was picked up. I always read "that is not planned". :-(

Created on Mar 13, 2018 9:41:51 AM by  Babylon6 (0) 1



Votes:

0

Your Vote:

Up

Down

Please bear in mind, we've got 200,000 installations of our software, often with several users per installation working with our applications. It's in the nature of being a user of any product that you'll come up with ideas much faster than the ideas can put into reality. This applies to software as to pretty much any other product.
That means we have to focus on implementing those ideas where most users benefit from. Because even if we've had one developer per user, it would still be impossible to implement each idea, because thinking of an idea is instant, whereas putting it into code, testing it, documenting and supporting it, isn't instant.
So we have to say no a lot. That does not mean though, that we like to say no, it simply is the reality we live in. And it doesn't mean that the rejected ideas aren't useful in their specific use cases. It's always a compromise.

Created on Mar 13, 2018 9:57:25 AM by  Torsten Lindner [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Torsten,

I understand your point, but in this case sounds like an Excuse. There are many many people who would be very glad to have this sensor available. It is not a random request. The DHCP service is one of the most critical elements in the infrastructure. Having a ping is not enough.

I hope that this can be taken not as another stupid request, but as a very important one.

Regards.

Created on Apr 11, 2018 11:05:32 AM by  NetGuy (0)



Votes:

1

Your Vote:

Up

Down

Hi Tom,

Thanks for the great script. I made a few changes to allow for the fact that my DHCP server is running 2008 R2 and there for didn't have the required PowerShell command get-dhcpserverv4scopestatistics.

Since my PRTG server was running Server 2012 R2 I added the DHCP Server Tools feature to it and then used the belwo modifed version of your script. Basically I just removed the invoke piece and run the get-dhcpserverv4scopestatistics command directly from the PRTG server.

Add the following parameters separated by spaces to the PRTG parameters field in the same order as listed. Powershell requires them to be surrounded by single quotes.

Parameters Example

'10.10.20.0' '%host' '%windowsuser' '%windowspassword'

Script

Param(
[string]$scopeid,
[string]$hostname,
[string]$Username,
[string]$Password
)

# create credentials
$SecPassword = $Password | ConvertTo-SecureString -AsPlainText -force
$cred = new-object -typename System.Management.Automation.PSCredential ($Username, $SecPassword)

# Create session and run script. Use invoke-command with credentials. Import scopeid variable into scriptblock.

$ret = (get-dhcpserverv4scopestatistics -ComputerName DhcpServername -ScopeId $scopeid).PercentageInUse 

# output data for prtg to use
write-host $ret":DHCP Scope $scopeid Used: $ret%"

# Do some housekeeping
Remove-Variable -Name scopeid

# The exit command seems to help end the script to avoid timeouts.
exit

Created on Jun 29, 2018 2:50:05 PM by  iano128 (10)

Last change on Jun 29, 2018 5:40:12 PM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

If you are running 2008r2, I believe you would need to install the Microsoft Framework 3 or higher.

Created on Jun 29, 2018 8:51:27 PM by  Tom Stone (0) 1



Votes:

0

Your Vote:

Up

Down

Hi,

is the script still working on any system? We have a 2016 DHCP server, but get no information back from the script.

Created on Aug 13, 2018 9:29:06 AM by  PekkaHopp (0)



Votes:

0

Your Vote:

Up

Down

Dear PekkaHopp,

in order to debug it, please open the sensor's settings tab and enable the sensor option "Write Exe result to disk". After the next scan, the log files are in "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)" where you can analyze the script output.

Created on Aug 13, 2018 2:04:52 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

My newest DHCP server is Windows 2012 Standard.
I'm using the script from Luciano (normal EXE, not Advanced EXE).

Parameters:'<dhcp_scope>' '%host' '%windowsuser' '%windowspassword'
Result:The_number_of_available_addresses

I've not been able to create a multi-scope sensor.

Created on Aug 13, 2018 2:10:56 PM by  Corné van den Bosch (40) 1 1

Last change on Aug 14, 2018 4:16:23 AM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Dear Corné,

please also open the sensor's settings tab and enable the sensor option "Write Exe result to disk". You find the log in "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)" after the next sensor scan, allowing you a look at the output.

For example, it could be that the parameters were provided wrongly, or that the script has not enough rights to run. In order to address the latter issue, please check the script sensor's security context.

Created on Aug 14, 2018 1:35:41 PM by  Arne Seifert [Paessler Support]

Last change on Aug 14, 2018 1:36:13 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Dear PekkaHopp,

Be sure that you have created this in the 32-bit Powershell environment on your probe that will be running the script. For troubleshooting purposes, run the script from the Powershell window to see if it returns information or throws an error message.

Created on Aug 31, 2018 6:02:51 PM by  Tom Stone (0) 1

Last change on Sep 3, 2018 9:08:18 AM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I second the request of a native DHCP scope sensor as well, since this is really a critical service for us.

In the meanwhile I use a little modified version of the script I found on Reddit: https://www.reddit.com/r/prtg/comments/632z0d/script_monitor_dhcp_scope_usage/

Param (
    [STRING]$serverName
)

$dhcpScopeStats = Get-DhcpServerv4ScopeStatistics -ComputerName $serverName

$xmlOutput = '<?xml version="1.0" encoding="UTF-8" ?><prtg>'

foreach ($scope in $dhcpScopeStats)
{
    $xmlOutput = $xmlOutput + "<result>
        <channel>$($scope.ScopeId)</channel>
        <value>$([math]::Round($scope.PercentageInUse))</value>
        <unit>Percent</unit>
        <limitmode>1</limitmode>
        <LimitMaxError>95</LimitMaxError>
        <LimitMaxWarning>90</LimitMaxWarning>
        <LimitErrorMsg>DHCP Scope is over 95%</LimitErrorMsg>
        <LimitWarningMsg>DHCP Scope is over 90%</LimitWarningMsg>
    </result>"
}

$xmlOutput = $xmlOutput + "</prtg>"

$xmlOutput

Set it up as xmlexesensor and the parameter of it to '%host' (including the single quotes). Requires the DHCP-Tools on the probe server.

In this way I can check the older 2008 R2 DHCP servers as well and have all scopes in channels.

Created on Sep 24, 2018 1:18:21 PM by  stiwa_schd (49) 1

Last change on Sep 24, 2018 3:19:14 PM by  Arne Seifert [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hello,

Can someone help me please All i keep getting is a percentage symbol but no value next to it. The sensors green and i've set limits but it just stays at 0% even though we're using a lot of the scope. Help please?

Created on Oct 15, 2018 9:56:56 AM by  KarbonHomes (0)



Votes:

0

Your Vote:

Up

Down

Dear KarbonHomes,

in order to debug custom scripts, please go to its sensor "Settings" tab, and enable "Write exe result to disk". The logs are written to "C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)", and show the output produced by the script. In many cases, the output shows an error message which prevents the further execution of the Powershell program.

Created on Oct 15, 2018 12:25:32 PM by  Arne Seifert [Paessler Support]



Please log in or register to enter your reply.


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.