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.
Add comment