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:
- Add the DHCP Administration feature in Windows Server 2012r2 to the probe server using Windows Server Manager
- Import the Powershell module into the 32-bit Powershell environment
- 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.
Add comment