I created a custom sensor using Powershell, Nuttercode-Prtg and PSFTP.
Param (
[Parameter(Mandatory=$True,Position=0)][String]$Hostname,
[Parameter(Mandatory=$True,Position=1)][String]$Username,
[Parameter(Mandatory=$True,Position=2)][String]$Password,
[Parameter(Mandatory=$True,Position=3)][String]$Path,
[Parameter(Mandatory=$False,Position=4)][String]$Filter = "*",
[Parameter(Mandatory=$False,Position=5)][switch]$Recurse = $false
)
$ErrorActionPreference = "Stop"
Import-Module PSFTP
$sensor = New-PRTGSensor
[int]$itemCount = 0
try {
$garbage = Set-FTPConnection -Session Session -Server $Hostname -Credentials (New-Object -TypeName System.Management.Automation.PSCredential -Argumentlist $Username, ($Password | ConvertTo-SecureString -AsPlainText -Force))
$session = Get-FtpConnection -Session Session
$itemCount = @(
$(
if( $Recurse ) {
Get-FTPChildItem -Session $Session -Path $Path -Recurse
}
else {
Get-FTPChildItem -Session $Session -Path $Path
}
) | ? { $_.Name -like $Filter }
).Count
}
catch {
$sensor.has_error = $true
$sensor.error_code = 1
$sensor = $sensor | Set-PRTGSensorText -text "An error occurend while running this sensor. Message: $_"
}
$sensor |
Add-PRTGChannel -name "File Count" -value $itemCount -unit Count |
Convert-PRTGSensorToXML
Add comment