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

Custom sensor powershell provide scaling

Votes:

0

Hello community

I created a new powershell sensor to read out free IP Adresses from a DHCP server:

param([string]$sitename)

function Set-PrtgResult {}
function Set-PrtgError {}
#functions downloaded from https://github.com/brianaddicks/prtgshell

try
    {
        $scope1 = ((Get-DhcpServerv4Scope -ComputerName srvmwdhcp01.domain.local | Where name -eq $sitename).ScopeId).IPAddressToString
        $freeIPs = Get-DhcpServerv4ScopeStatistics -ComputerName srvmwdhcp01.domain.local -ScopeId $scope1 | select free -ExpandProperty free
        $usedIPs = Get-DhcpServerv4ScopeStatistics -ComputerName srvmwdhcp01.domain.local -ScopeId $scope1 | select InUse -ExpandProperty InUse
        $totalIPs = $freeIPs + $usedIPs
        $XMLOutput = "<prtg>`n"
        $XMLOutput += Set-PrtgResult "Total IPs" $totalIPs ""
        $XMLOutput += Set-PrtgResult "Free IPs" $freeIPs ""
        $XMLOutput += "</prtg>"
    }
    catch
    {
        $XMLOutput = "<prtg>`n"
        $XMLOutput += Set-PrtgError "Irgndöppis isch mächtig id Hose"
        $XMLOutput += "</prtg>"
    }

return $XMLOutput.ToString()

It runs very good. Problem is, it creates two channels. Free IPs and Total IPs. I would like to have only one channel showing free IPs where the Total IPs is the "max" value that can be achieved. I would like to have a field in a channel where i can define a maximum to scale it correctly. I know i can scale it in PRTG manually. Problem is, that the max value is different for every DHCP Scope and i'd have to maintain it manually for every sensor. Is there a possibility to do that?

I've seen the taglist provided here: https://www.paessler.com/manuals/prtg/custom_sensors But none of these seem to fit. Any help is appreciated.

Thanks

custom-sensor dhcp powershell scaling

Created on Feb 8, 2016 2:26:54 PM

Last change on Jul 24, 2018 7:41:01 AM by  Brandy Greger [Paessler Support]



5 Replies

Votes:

0

That would be possible using the <LimitMaxWarning>, <LimitMaxError>. Make sure to enable the limit mode prior to that in the XML output:

<LimitMode>1</LimitMode>

Created on Feb 9, 2016 7:43:22 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hello Master Stephan

I already enhanced the script to include:

<LimitMinWarning>$warning</LimitMinWarning> <LimitMinError>$error</LimitMinError> <LimitMode>1</LimitMode>

But these are only the Warnings. Let me explain it in another way. The Channel gets a value of IP addresses free in a scope. Lets say 17. It should set the channel to warning, once the value goes below 5 and set it to error once it goes below 3. But the max IPs in this scope can be 72. So this information is not shown anywhere in the channel. My hope was to provide the channel a maxvalue that can be reached so the graph is displayed accordingly. The max value changes from channel to channel and can be calculated by the powershell script. Is there a way to take advantage of this information?

Created on Feb 9, 2016 8:21:09 AM



Votes:

0

Hm, the only way to get this done is to fill the values with their max values in the first run and then create some kind of file that says "okay, run normally now". Then check if a file like hostname.dat exists and run normally. No other way unfortunately :(

Created on Feb 9, 2016 2:58:51 PM by  Stephan Linke [Paessler Support]



Votes:

0

I changed my script completely again. I still cant define Max values for channels. The workaround from Stephan worked. The GUI will remember the max values from history and adapts the graphs to it. For anyone out there that want to observe their DHCP scopes as well, i post the script here. It reads out every scope on your dhcp server with names and displays the remaining adresses in them. You can adjust the 3 values at the beginning to enter your DHCP server and your respective Warn and Error Limit. You can always override these limits within the PRTG Gui afterwards.

Basic task to get the script working

  1. Disable execution policy on PRTG server in both 64 and 32bit powershell
  2. Install DHCP cmdlets on PRTG Server
  3. Run PRTG Probe service with AD user that has admin access on DHCP Server
  4. Put script into folder: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\dhcpscript.ps1
  5. Create custom EXE/Script sensor in PRTG and choose script from dropdown
$DHCPservername = "DHCPserver.company.local"
$WarnLimit = "8"
$ErrLimit = "3"

function Add-Block ()
{
    Param (
    [Parameter()]
    [string]$Fname,
    [Parameter()]
    [string]$Ffree,
    [Parameter()]
    [string]$FwarnAt,
    [Parameter()]
    [string]$FerrAt
    )
    $global:report += "  <result>"
    $global:report += "    <channel>$Fname</channel>"
    $global:report += "    <value>$Ffree</value>"
    $global:report += "    <CustomUnit>IPs</CustomUnit>"
    $global:report += "    <LimitMinWarning>$FwarnAt</LimitMinWarning>"
    $global:report += "    <LimitMinError>$FerrAt</LimitMinError>"
    $global:report += "    <LimitMode>1</LimitMode>"
    $global:report += "  </result>"
}


function Add-Error {
	Param (
		[Parameter(Position=0)]
		[string]$FErrorText
	)
	
	@"
<prtg>
  <error>1</error>
  <text>$FErrorText</text>
</prtg>
"@

exit

}


function GetDHCPDetails ()
{
    $scopes = Get-DhcpServerv4Scope -ComputerName $DHCPservername | select ScopeId, Name
    $DHCPdetails = @()
    Foreach ($s in $scopes)
    {
        $statistics = Get-DhcpServerv4ScopeStatistics -ComputerName $DHCPservername -ScopeID $s.ScopeId
        $Object = New-Object -TypeName PSObject
        $Object | Add-Member –MemberType NoteProperty –Name Name –Value $s.Name
        $Object | Add-Member –MemberType NoteProperty –Name Free –Value $statistics.Free
        $Object | Add-Member –MemberType NoteProperty –Name Used –Value $statistics.InUse
        $Object | Add-Member –MemberType NoteProperty –Name Total –Value ($statistics.InUse + $statistics.Free)
        $Object | Add-Member –MemberType NoteProperty –Name WarnAt –Value $WarnLimit
        $Object | Add-Member –MemberType NoteProperty –Name ErrAt –Value $ErrLimit
        $DHCPdetails += $Object
    }
    return $DHCPdetails
}


$MasterObject = GetDHCPDetails

try
    {
        $global:report = @()
        $global:report += "<prtg>"
        Foreach ($s in $MasterObject)
                {
                Add-Block -Fname $s.Name -Ffree $s.Free -FwarnAt $s.WarnAt -FerrAt $s.ErrAt
                }
        $global:report += "</prtg>"
    }
    catch
    {
        $global:report = "<prtg>`n"
        $global:report += Add-Error "Irgndwas isch heftig id Hose"
        $global:report += "</prtg>"
    }
return $report

Created on Feb 10, 2016 2:55:16 PM

Last change on Feb 11, 2016 12:42:53 PM by  Torsten Lindner [Paessler Support]



Votes:

0

Thanks for sharing!

Created on Feb 10, 2016 3:11:52 PM by  Stephan Linke [Paessler Support]




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.