I want to count backlog files on a host. The script works fine in a PowerShell window for both my user and the PRTG service user. But, when I run it through PRTG as a custom EXE/Script sensor, the module loads but the functionality doesn't work.
Solution for monitoring backlog files with custom EXE/Script sensor
Prerequisites
- PRTG Probe Service must run with a valid domain account with local admin rights on the server running the probe and the remote monitored systems.
PowerShell Script
Create `Get-DFSR-Count.ps1`:
Param(
$source=$args[0],
$target=$args[1]
)
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
if ( $principal.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)) {
$accessLvel = "Elevated"
} else {
$accessLvel = "Not Elevated"
}
if ([Environment]::Is64BitProcess) {
$64bits = "This is 64bits"
} else {
$64bits = "This is 32bits"
}
$count = (Get-DfsrBacklog -SourceComputerName $source -DestinationComputerName $target).count
Write-Output "$($count):$($count) Files in Backlog between $($source) and $($target): $($accessLvel): $($64bits)"
Batch Script
Create `InvokePS64.bat` to call the PowerShell script:
C:\windows\sysnative\windowspowershell\v1.0\powershell.exe -file "%~dp0\Get-DFSR-Count.ps1" %1 %2
PRTG Sensor Configuration
1. Upload Scripts:
- Place `Get-DFSR-Count.ps1` and `InvokePS64.bat` in the `Custom Sensors\EXE` directory on the PRTG server.
2. Create custom EXE/Script sensor:
- In PRTG, add a new custom EXE/Script sensor to the desired device.
- Choose `InvokePS64.bat` as the executable.
- Configure parameters to pass the source and target computer names for the DFSR backlog check.
3. Adjust PRTG Probe Service:
- Ensure the PRTG Probe Service runs under a domain account with appropriate permissions.
- Verify the service configuration in `services.msc` to confirm it uses the correct account.
Troubleshooting
- Security Context: Set the PRTG sensor to use the security context of the probe service.
- Logs: Enable writing EXE result to disk in PRTG sensor settings to check for errors in the log files (`Result of Sensor xxxx.txt`).
- Admin Rights: Ensure the account running the PRTG Probe Service has local admin rights on both the source and target servers.
Example Output
The PowerShell script should output clear information:
4:4 Files in Backlog between SVRAP01 and SVRDC01: Elevated: This is 64bits
This setup allows accurate counting and monitoring of backlog files between two servers using PRTG.
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.