Re: Monitoring GB free on mapped Windows drive
Posted: Tue Mar 11, 2014 7:09 am
For those who would be interested:
I did not post this yet on Exchange, as the script needs some refinement. For big volumes, it tends to run quite long, so timeout needs to be set really long (120 sec)
In fact it should be run by the client and then sent to Nagios, but I didn't found the time to test this yet.
Grtz
Code: Select all
Param(
[Parameter(Mandatory=$true)][string]$dfspad,
[Parameter(Mandatory=$true)][int]$quota,
[Parameter(Mandatory=$true)][double]$warningperc,
[Parameter(Mandatory=$true)][double]$criticalperc
)
$sumMB = 0
$warningMB = 0
$criticalMB = 0
$status = 0
$folderlist = Get-ChildItem $dfspad -Recurse -ErrorAction SilentlyContinue | Measure-Object -property length -sum
$sumMB = [System.Math]::Round($folderlist.sum / 1MB, 2)
$warningMB = $quota * $warningperc
$criticalMB = $quota * $criticalperc
echo "warningperc: $warningperc"
echo "criticalperc: $criticalperc"
echo "quota: $quota"
echo "sumMB: $sumMB"
echo "warning: $warningMB"
echo "critical: $criticalMB"
if ($sumMB -ge $criticalMB) {
$status = 2
echo "$dfspad has exceeded it's critical threshold!"
echo "Size = $sumMB MB, Critical Threshold = $criticalMB MB"
}
elseif ($sumMB -ge $warningMB) {
$status = 1
echo "$dfspad has exceeded it's warning threshold!"
echo "Size = $sumMB MB, Warning Threshold = $criticalMB MB"
}
else {
echo "$dfspad has not exceeded any thresholds."
echo "Size = $sumMB MB"
}
# echo "status: $status"
Write-Output "$sumMB MB | Used_Storage=$sumMB"
# $perfdata = "$sumMB MB | Used_Storage=$sumMB"
#$return.output = "$sumMBMB | Used_Storage=$sumMB"
#$outputstring=$return.output
#Write-Output "$outputstring"
Exit $status
In fact it should be run by the client and then sent to Nagios, but I didn't found the time to test this yet.
Grtz