This VBScript check the status of local disks (used and free space) and performs a predictive analysis.
This script can be used in all Microsoft Windows Systems running the following command…
- cscript.exe /nologo CheckDiskPredictive_v1.0.vbs C: 95 98
… Or can be integrated into the file nrpe.cfg of NRPE_NT (Nagios Agent for Windows)
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | ' ############################################################################## ' #                                Lupi Gabriel                                # ' #                             www.lupigabriel.it                             # ' #                            info@lupigabriel.it                             # ' ############################################################################## ' #            Copyright (c) 2014 Lupi Gabriel All rights reserved.            # ' ############################################################################## ' # NAME       : Nagios Windows Check Disk with Predictive Analysis            # ' # VERSION    : 1.0                                                           # ' # FILE       : CheckDiskPredictive_v1.0.vbs                                  # ' # CLASS      : Script                                                        # ' # LANGUAGE   : VB Script                                                     # ' ############################################################################## On Error Resume Next DriveUnit = Wscript.Arguments(0) ' Drive PercentWarning = Wscript.Arguments(1) ' % Used Space for Warning PercentCritical = Wscript.Arguments(2) ' % Used Space for Critical PredictiveWarning = 3 ' Day Range for Predictive Warning PredictiveCritical = 1 ' Day Range for Predictive Critical PredictiveStep = 60 ' Max Log Lines  PredictiveStepSens = 6 ' Use Log Line every # of Log Lines PredictiveLog = "CheckDisk_" & UCase(Replace(DriveUnit, ":", "")) & "_Predictive.txt" Set fso = CreateObject("Scripting.FileSystemObject") Set d = fso.GetDrive(DriveUnit) UsedPercent = Round ((d.TotalSize - d.FreeSpace) * 100 / d.TotalSize, 2) UsedSpace = "Used: " & Round ((d.TotalSize - d.FreeSpace)) & " B (" & UsedPercent & "%)" If (d.TotalSize - d.FreeSpace) > 1023 Then 	UsedSpace = "Used: " & Round ((d.TotalSize - d.FreeSpace) / 1024 , 2) & " B (" & UsedPercent & "%)" End If If (d.TotalSize - d.FreeSpace) > 1048575 Then 	UsedSpace = "Used: " & Round ((d.TotalSize - d.FreeSpace) / 1024 / 1024 , 2) & " MB (" & UsedPercent & "%)" End If If (d.TotalSize - d.FreeSpace) > 1073741823 Then 	UsedSpace = "Used: " & Round ((d.TotalSize - d.FreeSpace) / 1024 / 1024 / 1024 , 2) & " GB (" & UsedPercent & "%)" End If If (d.TotalSize - d.FreeSpace) > 1099511627775 Then 	UsedSpace = "Used: " & Round ((d.TotalSize - d.FreeSpace) / 1024 / 1024 / 1024 / 1024 , 2) & " TB (" & UsedPercent & "%)" End If FreePercent = Round (d.FreeSpace * 100 / d.TotalSize) FreeSpace = "Free: " & Round (d.FreeSpace) & " B (" & FreePercent & "%)" If d.FreeSpace > 1023 Then 	FreeSpace = "Free: " & Round (d.FreeSpace / 1024 , 2) & " B (" & FreePercent & "%)" End If If d.FreeSpace > 1048575 Then 	FreeSpace = "Free: " & Round (d.FreeSpace / 1024 / 1024 , 2) & " MB (" & FreePercent & "%)" End If If d.FreeSpace > 1073741823 Then 	FreeSpace = "Free: " & Round (d.FreeSpace / 1024 / 1024 / 1024 , 2) & " GB (" & FreePercent & "%)" End If If d.FreeSpace > 1099511627775 Then 	FreeSpace = "Free: " & Round (d.FreeSpace / 1024 / 1024 / 1024 / 1024 , 2) & " TB (" & FreePercent & "%)" End If LineCount = 0 If (fso.FileExists (PredictiveLog)) Then 	Set objFile = fso.OpenTextFile(PredictiveLog, 1) 	Do Until objFile.AtEndOfStream 		Line = objFile.ReadLine 		If Line <> "" Then 			LineCount = LineCount + 1 		End If 	Loop 	objFile.Close 	Set objFile = Nothing End If StepCount = 0 StepAllLines = "" If LineCount > PredictiveStep - 1 Then 	Set objFile = fso.OpenTextFile(PredictiveLog, 1) 	Do Until objFile.AtEndOfStream 		StepLine = objFile.ReadLine 		If StepLine <> "" Then 			StepCount = StepCount + 1 			If StepCount > (LineCount - PredictiveStep + 1) Then 				If StepCount = LineCount Then 					StepAllLines = StepAllLines & StepLine 				Else 					StepAllLines = StepAllLines & StepLine & vbCrLf 				End If 			End If 		End If 	Loop 	objFile.Close 	Set objFile = Nothing 	Set objFile = fso.OpenTextFile(PredictiveLog, 2, True) 	objFile.WriteLine(StepAllLines) 	objFile.Close 	Set objFile = Nothing End If Set objFile = fso.OpenTextFile(PredictiveLog, 8, True) objFile.WriteLine(UsedPercent & " | " & Now) objFile.Close Set objFile = Nothing LineCount = 0 LineSensTotal = 0 LineSensCount = 0 PercentStep = 0 PercentLastStep = 0 TimeStep = "FirstLine" TimeStepLast = "" If (fso.FileExists (PredictiveLog)) Then 	Set objFile = fso.OpenTextFile(PredictiveLog, 1) 	Do Until objFile.AtEndOfStream 		Line = objFile.ReadLine 		If Line <> "" And InStr(Line, " | ") > 0 Then 			LineSplit = Split(Line, " | ") 			LineCount = LineCount + 1 			LineSensCount = LineSensCount + 1 			If LineSensCount = 1 Then 				If TimeStep = "FirstLine" Then 					TimeStep = 0 					TimeStepLast = LineSplit(1) 					PercentLastStep = LineSplit(0) 				Else 					TimeStep = TimeStep + DateDiff("s", TimeStepLast, LineSplit(1)) 					TimeStepLast = LineSplit(1) 					PercentStep = PercentStep + (LineSplit(0) - PercentLastStep) 					PercentLastStep = LineSplit(0) 				End If 				LineSensTotal = LineSensTotal + 1 			End If 			If LineSensCount = PredictiveStepSens Then LineSensCount = 0 End If 		End If 	Loop 	objFile.Close 	Set objFile = Nothing End If PercentStep = Round(PercentStep / (LineSensTotal - 1), 2) TimeStep = Round(TimeStep / (LineSensTotal - 1), 2) PredictivePercent = LineSplit(0) PredictiveTime = LineSplit(1) PredictiveTotalStep = Round(PredictiveWarning * 24 * 60 * 60 / TimeStep) PredictiveStatus = 0 PredictiveBreakDate = "" PredictiveBreakStep = 0 If PercentStep > 0 And PredictiveStep = LineCount Then 	For i = 1 to PredictiveTotalStep 		PredictivePercent = Round(PredictivePercent + PercentStep, 2) 		PredictiveTime = DateAdd("s", TimeStep, PredictiveTime) 		If PredictivePercent >= 100 Then 			PredictiveBreakStep = Round(i * TimeStep / 60 / 60 / 24, 2) 			If PredictiveBreakStep < PredictiveWarning Then PredictiveStatus = 1 End If 			If PredictiveBreakStep < PredictiveCritical Then PredictiveStatus = 2 End If 			i = PredictiveTotalStep 			PredictiveBreakDate = vbCrLf & "Predictive Disk Full: " & PredictiveTime 		End If 	Next End If Wscript.Echo UsedSpace & " " & FreeSpace & PredictiveBreakDate Set d = Nothing Set fso = Nothing If PredictiveStatus = 1 Then Wscript.Quit 1 End If If PredictiveStatus = 2 Then Wscript.Quit 2 End If If CInt(UsedPercent) < CInt(PercentCritical) And CInt(UsedPercent) < CInt(PercentWarning) Then Wscript.Quit 0 End If If CInt(UsedPercent) < CInt(PercentCritical) And CInt(UsedPercent) >= CInt(PercentWarning) Then Wscript.Quit 1 End If If CInt(UsedPercent) >= CInt(PercentCritical) And CInt(UsedPercent) >= CInt(PercentWarning) Then Wscript.Quit 2 End If Wscript.Quit 3 |