Local check for Quota usage on Windows servers (Checkmk Agent 1.5.x)

Hi forum
i wrote a simple local check to keep track of all the disk quotas of all our 900 file servers since the Agent (at least 1.5, havent tried 1.6 yet) cannot handle it out of the box.
The check reads out all set quotas, translates them human readable (with thresholds set to 85/95%) and even makes pretty graphs too :slight_smile:
Requires the cmdlet Get-FsrmQuota which is automatically installed with File Server Resource Manager

$OK=0
$Warn=1
$Crit=2
$Unk=3
$Quotas=@(Get-FsrmQuota | Select-Object Path, Size, Usage)
$Output = β€œβ€
$Output1 = β€œβ€

echo <<<local>>>

foreach ($Quota in $Quotas) {

$Size=($Quota.Size / 1gb)
$Usage=[math]::Round($Quota.Usage / 1gb,1)
$Path=($Quota.Path)
$Percent=($Usage / $Size * 100)
$warnvalue=85
$critvalue=95

if ($Percent -lt $warnvalue)
{$Output = $OK.ToString() + " Disk_Quota_" +$Path + " " + β€œUsage=” + $Percent + β€œ;” + $warnvalue + β€œ;” + $critvalue + " Size=" + $Size + " GB, Usage=" + $Usage + " GB " + $Percent + β€œ%”}
elseif ($Percent -ge $warnvalue -and $Percent -lt $critvalue)
{$Output = $Warn.ToString() + " Disk_Quota_" +$Path + " " + β€œUsage=” + $Percent + β€œ;” + $warnvalue + β€œ;” + $critvalue + " Size=" + $Size + " GB, Usage=" + $Usage + " GB " + $Percent + β€œ%”}
elseif ($Percent -ge $critvalue)
{$Output = $Crit.ToString() + " Disk_Quota_" +$Path + " " + β€œUsage=” + $Percent + β€œ;” + $warnvalue + β€œ;” + $critvalue + " Size=" + $Size + " GB, Usage=" + $Usage + " GB " + $Percent + β€œ%”}

$Output1 = $Output1 + β€œ|” + $Output

write-host $Output
}

You local check a little bit shorter and better readable :slight_smile:

# Quota Output as Local Check for CMK
$Quotas = @(Get-FsrmQuota | Select-Object Path, Size, Usage)

foreach ($Quota in $Quotas) {
    $Size = ($Quota.Size / 1gb)
    $Usage = [math]::Round($Quota.Usage / 1gb, 1)
    $Path = ($Quota.Path)
    $Percent = ($Usage / $Size * 100)
    Write-Host("P Disk_Quota_" + $Path + " Usage=" + "{0:N0}" -f $Percent + ";85;95|Size=" + "{0:N0}" -f $Size + " The quota usage in percent and GB size")
} 

The Status is dynamically calculated by CMK itself. You don’t need to invest to much time for if-then-else statements anymore.

1 Like

Hi Andreas
thank you so much. Indeed this is muss less code and is much better to read. I did some minor cosmetic changes for the output and this is the final result:

# Quota Output as Local Check for CMK
$Quotas = @(Get-FsrmQuota | Select-Object Path, Size, Usage)

foreach ($Quota in $Quotas) {
    $Size = ($Quota.Size / 1gb)
    $Usage = [math]::Round($Quota.Usage / 1gb, 1)
    $Path = ($Quota.Path)
    $Percent = ($Usage / $Size * 100)
    Write-Host("P Disk_Quota_" + $Path + " Usage=" + "{0:N0}" -f $Percent + ";85;95|Size=" + "{0:N0}" -f $Size + " Used: $Percent%, $Usage GB")
}

No problem - my code was only written without the real possibility to test :smiley: