# Check free space on Windows volume mount points # # This script will execute checks against volume mount points using WMI via powershell and nsclient++ # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # # Revision History # 2013-08-14 Barry Mulholland [basra.mulholland@gmail.com] 1.0 # * Initial script created # # To execute from within NSClient++ # #[NRPE Handlers] #check_windows_volume_mount_point_freespace=cmd /c echo Scripts\CheckWindowsVolumeMountPointFreeSpace.ps1; exit($lastexitcode) | PowerShell.exe -Command - # # On the check_nrpe command include the -t 20, since it takes some time to load the cmdlet's. $server = $env:computername $NagiosStatus = "0" $NagiosDescription = "" $Critical = 5 $Warning = 10 $volumes = Get-WmiObject -computer $server win32_volume | Where-object {$_.DriveLetter -eq $null -and $_.Label -notlike "*System Reserved*"} | ForEach-Object { $Label = $_.Label #Calculate totals in GB, round to 2 decimal places $TotalGB = [math]::round(($_.Capacity/ 1073741824),2) $FreeGB = [math]::round(($_.FreeSpace / 1073741824),2) #Calculate free space as percentage, $FreePerc = [math]::round(((($_.FreeSpace / 1073741824)/($_.Capacity / 1073741824)) * 100),0) #Check to see if volume free space is less than $Critical if ($FreeGB -lt $Critical) { #Format for Nagios if ($NagiosDescription -ne "") { $NagiosDescription = $NagiosDescription + ", " } #Add details of failure $NagiosDescription = $NagiosDescription + "Volume: " + $Label + " Total Size (GB):" + $TotalGB + ", Free Space (GB):" + $FreeGB + ", Free (%):" + $FreePerc #Set the status to failed $NagiosStatus = "2" } #Else check to make sure it's not less than $Warning elseif ($FreeGB -lt $Warning) { #Format for Nagios if ($NagiosDescription -ne "") { $NagiosDescription = $NagiosDescription + ", " } #Add details of warning $NagiosDescription = $NagiosDescription + "Volume: " + $Label + " Total Size (GB):" + $TotalGB + ", Free Space (GB):" + $FreeGB + ", Free (%):" + $FreePerc #Set the status to warning if ($NagiosStatus -ne "2") { $NagiosStatus = "1" } } } # Output, final text message for Nagios if ($NagiosStatus -eq "2") { Write-Host "CRITICAL: " $NagiosDescription } elseif ($NagiosStatus -eq "1") { Write-Host "WARNING: " $NagiosDescription } else { Write-Host "OK: All volumes have adequate free space" } exit $NagiosStatus