'------------------------------------------------------------------------- ' Script Dims '------------------------------------------------------------------------- Dim logFile 'Log Name Dim objFSO 'File Object Dim logLocation 'Log Directory Dim SearchStrings(2) Dim verboselog, ArrayName, ConfigLocation, CommandArray(), EnvironmentVariables(), amsSERIAL, LocationofHDVM, cmdHDVMP, usrHDVM, passFile Dim NumofCores, NameofSNM2, TotalDisks, DiskRate(), CPURate(), CacheWait(), HighCpuRate, HighDiskRate, HighCacheWait, HighDiskHit Dim LocationOfAuOutput, HostGroupDef, HostGroupMap, PartList, UnitInfo, ArrayList, NumPFMtoCheck, LocationOfPFM, HighCpuHit, HighCacheHit Dim SMTPServerinfo, MailFromName, MailToName, NotifyEvery, LocationofSNM2, Simulate, RequiredMC, DiskHitPercent, CPUHitPercent, CacheHitPercent '------------------------------------------------------------------------- ' Script Variables '------------------------------------------------------------------------- today = Date CurDate = Year(today) & "-" & Month(today) & "-" & Day(today) verboselog = False 'Filter log output SearchStrings(0) = "Partition Write Pending Rate" SearchStrings(1) = "CTL Core Usage" SearchStrings(2) = "HDU Operating Rate" logLocation = "C:\Script_Logs" ConfigLocation = "C:\Temp\scripts\AMStest\" amsSERIAL = "" ' This needs to be looked up in the auunitinfo output. LocationofHDVM = "C:\HCMDCLI" Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject") 'Create object for creating fs changes Set wshShell = Wscript.CreateObject("WScript.shell") 'Create object to run executables in '------------------------------------------------------------------------- ' Storage Array Variables '------------------------------------------------------------------------- Simulate = True HighCacheWait = 15 ' Cache Write Pending HighCacheHit = 0 ' Number of times max was hit. TotalCacheEntries = 0 ' Number of Cache Entries CacheHitPercentMax = 10 ' Of all of the PFM files checked, this is the max percentage that is allowed to continue HighCpuRate = 50 ' CPU Usage % HighCpuHit = 0 ' Number of times max was hit. TotalCpuEntries = 0 ' Number of Cores / CPU Entries CPUHitPercentMax = 30 ' Of all of the PFM files checked, this is the max percentage that is allowed to continue HighDiskRate = 70 ' Disk usage % HighDiskHit = 0 ' Number of times max was hit. TotalDiskEntries = 0 ' Number of Disk Entries DiskHitPercentMax = 20 ' Of all of the PFM files checked, this is the max percentage that is allowed to continue RequiredMC = "08A0/J-Y" ArrayName = "UNIT1" LocationOfAuOutput = "C:\Documents and Settings\grhernandez\Desktop\Dale\Beta2\" LocationOfPFM = "C:\Documents and Settings\grhernandez\Desktop\Dale\Beta2\" & ArrayName & "\" LocationofSNM2 = "C:\HCMDCLI\SNM2CLI\" NumPFMtoCheck = 3 HostGroupDef = "auhgdef.txt" HostGroupMap = "auhgmap.txt" PartList = "auparts.txt" UnitInfo = "auunitinfo.txt" ArrayList = "auunitref.txt" cmdPROTO = LocationofSNM2 & "auunitinfo.exe" cmdMCVER = LocationofSNM2 & "auunitinfo.exe" cmdPARTS = LocationofSNM2 & "auparts.exe" cmdLUADD = LocationofSNM2 & "auluadd.exe" cmdHGDEF = LocationofSNM2 & "auhgdef.exe" cmdHGWWN = LocationofSNM2 & "auhgwwn.exe" cmdHGMAP = LocationofSNM2 & "auhgmap.exe" '------------------------------------------------------------------------- ' File Name and locations '------------------------------------------------------------------------- logFile = logLocation & "\Lun_Creation_Script-" & CurDate & ".log" '------------------------------------------------------------------------- ' Email Variables '------------------------------------------------------------------------- SMTPServerinfo = "SMTP.DOMAIN.ORG" MailFromName = "Notifcation@no-reply.DOMAIN.org" MailToName = "USER1@DOMAIN.ORG;USER2@DOMAIN.ORG;USER3@DOMAIN.ORG" '------------------------------------------------------------------------- ' Functions '------------------------------------------------------------------------- Function SendEmail(TheTextBody, TheSubject) Set objEmail = CreateObject("CDO.Message") objEmail.From = MailFromName 'From Address objEmail.To = MailToName 'To Address objEmail.Subject = TheSubject 'Subject Line objEmail.Textbody = TheTextBody 'Body Text objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send using Port objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServerinfo 'SMTP Address objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'Port to connect on objEmail.Configuration.Fields.Update 'Commit Changes. objEmail.Send 'Send email End Function Function CheckLogFolder() ' If folder doesnt exist, create it if not objFSO.FolderExists(logLocation) then set objFolder = objFSO.CreateFolder(logLocation) end If End Function '"CTL Partition Write Pending Rate(%)" 'CTL Core Usage 'HDU Operating Rate Function Parse_PFM_File(FileName) Set objReadPFM = objFSO.OpenTextFile(FileName, 1, false) Buffer = objReadPFM.ReadLine 'Cache line in temp variable Do until objReadPFM.AtEndOfStream = True 'If regex.Test(Buffer) = True Then 'We found one of the values to start processing. SearchStrings(0) = "Partition Write Pending Rate" SearchStrings(1) = "CTL Core Usage" SearchStrings(2) = "HDU Operating Rate" If InStr(Buffer, SearchStrings(0)) <> 0 Then Buffer = Parse_Write_Pending(objReadPFM) ElseIf InStr(Buffer, SearchStrings(1)) <> 0 Then Buffer = Parse_Core_Percentage(objReadPFM) ElseIf InStr(Buffer, SearchStrings(2)) <> 0 Then Buffer = Parse_Disk_Utilization(objReadPFM) Else Buffer = objReadPFM.ReadLine 'Cache line in temp variable End If Loop Set objReadPFM = Nothing End Function '--------------------------------------------------------- ' Parsing Functions '--------------------------------------------------------- Function Parse_Write_Pending(objReader) TotalCacheEntries = 0 ' Number of Cache Entries EndOfFile = False Line = objReader.ReadLine curBuffer = Clean_Extra_Delimiters(Split(Line, " ")) 'Tokenize line Do While IsNumeric(curBuffer(0)) AND EndOfFile = False 'Keep going until we run out of controllers If Int(curBuffer(2)) >= HighCacheWait Then HighCacheHit= HighCacheHit + 1 End If TotalCacheEntries = TotalCacheEntries + 1 If objReader.AtEndOfStream = False then Line = objReader.ReadLine curBuffer = Clean_Extra_Delimiters(Split(Line, " ")) 'Tokenize line Else EndOfFile = True End if Loop Parse_Write_Pending = Line End Function Function Parse_Core_Percentage(objReader) TotalCpuEntries = 0 ' Number of Cores / CPU Entries EndOfFile = False Line = objReader.ReadLine curBuffer = Clean_Extra_Delimiters(Split(Line, " ")) 'Tokenize line Do While IsNumeric(curBuffer(0)) AND EndOfFile = False If Int(curBuffer(2)) >= HighCpuRate Then HighCpuRate = HighCpuRate + 1 End If TotalCpuEntries = TotalCpuEntries + 1 If objReader.AtEndOfStream = False then Line = objReader.ReadLine curBuffer = Clean_Extra_Delimiters(Split(Line, " ")) 'Tokenize line Else EndOfFile = True End if Loop Parse_Core_Percentage = Line End Function Function Parse_Disk_Utilization(objReader) TotalDiskEntries = 0 EndOfFile = False Line = objReader.ReadLine curBuffer = Clean_Extra_Delimiters(Split(Line, " ")) 'Tokenize line Do While IsNumeric(curBuffer(0)) AND EndOfFile = False If Int(curBuffer(3)) >= HighDiskRate Then HighDiskHit = HighDiskHit + 1 End If TotalDiskEntries = TotalDiskEntries + 1 If objReader.AtEndOfStream = False then Line = objReader.ReadLine curBuffer = Clean_Extra_Delimiters(Split(Line, " ")) 'Tokenize line Else EndOfFile = True End if Loop Parse_Disk_Utilization = Line End Function 'Gets last X created PFM Files, by creation date. Function GetFileArray() Set regex = new RegExp 'Create the RegExp object regex.Pattern = "pfm" regex.IgnoreCase = False 'Case sensitive Dim FileList() Dim EndList() ReDim EndList(NumPFMtoCheck-1) 'Cant dim with a variable. Can Redim. counter=0 Set Folder = objFSO.GetFolder(LocationOfPFM) Set files = Folder.Files For Each folderidx In files If regex.Test(folderidx.Name) Then ReDim Preserve FileList(counter) FileList(counter) = folderidx.Name counter = counter + 1 End if Next Set files = Nothing Set Folder= nothing Ubou = UBound(FileList) If UBound(FileList) <= NumPFMtoCheck Then NumFiles = 0 Else NumFiles = UBound(FileList) - NumPFMtoCheck - 1 'zero index End if j=0 For i = UBound(FileList) To NumFiles Step -1 EndList(j) = FileList(i) j = j + 1 next GetFileArray = EndList End Function Function BoolCheckMicrocode() Set regex = new RegExp 'Create the RegExp object regex.Pattern = RequiredMC regex.IgnoreCase = False 'Case sensitive Set regex2 = new RegExp 'Create the RegExp object regex2.Pattern = "Serial Number" regex2.IgnoreCase = False 'Case sensitive objlogFile.Writeline("---------------------------") objlogFile.Writeline(Time & " Checking for hardware errors") 'Log everything to file MicroCodeFound = false If Simulate Then FileName = LocationOfAuOutput & UnitInfo Set objRead = objFSO.OpenTextFile(FileName, 1, false) Buffer = objRead.ReadLine 'Cache line in temp variable Do until objRead.AtEndOfStream = True If regex.Test(Buffer) Then MicroCodeFound = True End If If regex2.Test(Buffer) Then splt = Clean_Extra_Delimiters(Split(Buffer, " ")) amsSERIAL= splt(3) End If Buffer = objRead.ReadLine 'Cache line in temp variable Loop Set objRead = Nothing Else Set RunCheck = wshShell.Exec(cmdMCVER) 'Run name Do while RunCheck.status = 0 wscript.sleep 1 Buffer = RunCheck.StdOut.ReadLine If verboselog = True Then 'Check verbosity level objlogFile.Writeline(Time & " " & Buffer) 'Log everything to file End If If regex2.Test(Buffer) Then splt = Clean_Extra_Delimiters(Split(Buffer, " ")) amsSERIAL= splt(4) End If If regex.Test(Buffer) Then MicroCodeFound = True objlogFile.Writeline(Time & " Microcode correct. " & strMC) End if Loop End if BoolCheckMicrocode = MicroCodeFound objlogFile.Writeline("---------------------------") End Function 'kds 'Checks for non-secure protocol 'kds ' HDVM Protocol information Function BoolCheckSecure() 'Build Command cmdHDVMP = "cmd /c " & LocationofHDVM & "\HiCommandCLI.bat --user " & usrHDVM & " --password " & passFile & " GetStorageArray subtarget=commparameters -f csv | find """ & amsSERIAL & """" Set regex = new RegExp 'Create the RegExp object regex.Pattern = "Non-Secure" regex.IgnoreCase = False 'Case sensitive objlogFile.Writeline("---------------------------") objlogFile.Writeline(Time & " Checking HDvM for Non-Secure Protocol") 'Log everything to file SecureProtoFound = false If Simulate Then FileName = LocationOfAuOutput & HDVMOUT Set objRead = objFSO.OpenTextFile(FileName, 1, false) Buffer = objRead.ReadLine 'Cache line in temp variable Do until objRead.AtEndOfStream = True If regex.Test(Buffer) Then MicroCodeFound = True End if Buffer = objRead.ReadLine 'Cache line in temp variable Loop Set objRead = Nothing Else Set RunCheck = wshShell.Exec(cmdHDVMP) 'Run name Do while RunCheck.status = 0 wscript.sleep 1 Buffer = RunCheck.StdOut.ReadLine If Len(Buffer) > 0 then 'Buffer contains data If verboselog = True Then 'Check verbosity level objlogFile.Writeline(Time & " " & Buffer) 'Log everything to file End If If regex.Test(Buffer) Then SecureProtoFound = True objlogFile.Writeline(Time & " Protocol is correctly set to Non-Secure. " & strMC) End if End if Loop End if BoolCheckSecure = SecureProtoFound objlogFile.Writeline("---------------------------") End Function Function BoolCheckForErrors() Set regex = new RegExp 'Create the RegExp object regex.Pattern = "(WARNING)|(ERROR)" regex.IgnoreCase = True 'Case sensitive objlogFile.Writeline("---------------------------") objlogFile.Writeline(Time & " Checking for hardware errors") 'Log everything to file ErrorsFound = False If Simulate Then FileName = LocationOfAuOutput & PartList Set objRead = objFSO.OpenTextFile(FileName, 1, false) Buffer = objRead.ReadLine 'Cache line in temp variable Do until objRead.AtEndOfStream = True If regex.Test(Buffer) Then ErrorsFound = True End if Buffer = objRead.ReadLine 'Cache line in temp variable Loop Else Set RunCheck = wshShell.Exec(cmdPARTS) 'Run name Do while RunCheck.status = 0 wscript.sleep 1 Buffer = RunCheck.StdOut.ReadLine If verboselog = True Then 'Check verbosity level objlogFile.Writeline(Time & " " & Buffer) 'Log everything to file End If If regex.Test(Buffer) Then ErrorsFound = True objlogFile.Writeline(Time & " Error Found: " & Buffer) End if Loop End if BoolCheckForErrors = ErrorsFound objlogFile.Writeline("---------------------------") End Function Sub ParseFiles() For Each File In GetFileArray Parse_PFM_File(LocationOfPFM & "\" & File) Next 'Percentages CPUHitPercent = (HighCpuHit / (TotalCpuEntries * NumPFMtoCheck) * 100) CacheHitPercent = (HighCacheHit / (TotalCacheEntries * NumPFMtoCheck) * 100) DiskHitPercent = (HighDiskHit / (TotalDiskEntries * NumPFMtoCheck) * 100) End Sub Function GetConfigFileArray() Set regex = new RegExp 'Create the RegExp object regex.Pattern = "bat" regex.IgnoreCase = False 'Case sensitive Dim FileList() counter=0 Set Folder = objFSO.GetFolder(ConfigLocation) Set files = Folder.Files For Each folderidx In files If regex.Test(folderidx.Name) Then ReDim Preserve FileList(counter) FileList(counter) = folderidx.Name counter = counter + 1 End if Next 'We can do some sort of sorting here to make sure commands get written in the correct order. 'Typically Luns and HG's need to be added prior to adding them to the HG, ya know. GetConfigFileArray = FileList End Function Function LoadConfig(FileName) Set regex = new RegExp 'Create the RegExp object regex.Pattern = "REM" regex.IgnoreCase = True Set regex2 = new RegExp 'Create the RegExp object regex2.Pattern = "set " regex2.IgnoreCase = True 'Case sensitive Set regex3 = new RegExp 'Create the RegExp object regex3.Pattern = "unit" regex3.IgnoreCase = True 'Case sensitive objlogFile.Writeline(Time & " ---------------------------") objlogFile.Writeline(Time & " Loading Configuration file: " & FileName) 'Log everything to file objlogFile.Writeline(Time & " ---------------------------") Set objRead = objFSO.OpenTextFile(FileName, 1, false) Buffer = objRead.ReadLine 'Cache line in temp variable i=0 j=0 Do until objRead.AtEndOfStream = True If Not regex.Test(Buffer) And Not regex2.Test(Buffer) Then ReDim Preserve CommandArray(i) CommandArray(i) = Buffer objlogFile.Writeline(Time & " Command Found, Adding to Queue") objlogFile.Writeline(Time & " "& Buffer) i= i + 1 'Do some sort of check here to make sure that commands come in the correct order. 'Add Luns to HG's at bottom of array 'Add Create HG's and Create Luns at Top of array. ElseIf regex2.Test(Buffer) And Not regex.Test(Buffer) And Not regex3.Test(Buffer) Then ReDim Preserve EnvironmentVariables(j) EnvironmentVariables(j) = Buffer objlogFile.Writeline(Time & " Environment Variable Found, Adding to Queue") objlogFile.Writeline(Time & " "& Buffer) j = j + 1 End if Buffer = objRead.ReadLine 'Cache line in temp variable Loop objlogFile.Writeline("---------------------------") MsgBox "test" End Function Function RunCommands() ReturnCode = 0 Do While UBound(CommandList) >= 1 Or ReturnCode = 0 ReturnCode = RunCommand(pop_top(CommandList)) Loop If ReturnCode <> 0 Then 'Output all left overs to file for next run. End If End Function Function RunCommand(command) Set RunCheck = wshShell.Exec(command) 'Run name objlogFile.Writeline("---------------------------") objlogFile.Writeline(Time & " Starting Execution of: " & command) objlogFile.Writeline(Time & "Output from command follows:") objlogFile.Writeline("---------------------------") Do while RunCheck.status = 0 wscript.sleep 1 Buffer = RunCheck.StdOut.ReadLine If Len(Buffer) > 0 Then objlogFile.Writeline(Time & " " & Buffer) 'Log everything to file End if Loop If RunCheck.ExitCode <> 0 Then objlogFile.Writeline(Time & " Execution of Command, " & command & ", failed!") objlogFile.Writeline(Time & " Error Code was: " & RunCheck.ExitCode ) End If objlogFile.Writeline("---------------------------") RunCommand = RunCheck.ExitCode End Function '--------------------------------------------------------- ' Support Functions '--------------------------------------------------------- 'Split does not handle Extra Delimiters, clean it. Function Clean_Extra_Delimiters(Split_Array) Dim New_Array() i=0 For Each str In Split_Array If Not str = "" Then ReDim Preserve New_Array(i) New_Array(i) = str i=i+1 End If Next Clean_Extra_Delimiters = New_Array End Function 'Pops the last element and resizes the array Function pop_top(Arr) Dim ret ret = Arr(UBound(Arr)) redim preserve Arr(UBound(Arr)-1) pop_top = ret End Function 'Pops the first element(0) and resizes the array Function pop_bot(Arr) Dim newarr() Dim val val = Arr(0) For i = 1 To UBound(Arr) Step 1 ReDim Preserve newarr(i-1) newarr(i-1) = Arr(i) Next For i = 0 To UBound(newarr) Step 1 Arr(i) = newarr(i) Next ReDim Preserve Arr(UBound(Arr)-1) pop_bot = val End Function 'Adds value to the bottom of the array(0) Function push_bot(value, Arr) ReDim newarr(UBound(Arr)) For i = 0 To UBound(Arr) Step 1 newarr(i) = Arr(i) Next Arr(0) = value ReDim Preserve Arr(UBound(arr)+1) For i = 1 To UBound(Arr) Step 1 Arr(i) = newarr(i - 1) Next End Function 'Adds Value to the top of the array Function push_top(value, Arr) redim preserve Arr(UBound(Arr)+1) Arr(UBound(Arr)) = value End Function 'gunnings for crab cakes 'helmond 'in baltimore afgahny '--------------------------------------------------------- ' Begin Code ' Initial Check / Exits '--------------------------------------------------------- CheckLogFolder Set objlogFile = objFSO.CreateTextFile(logfile) 'Check for Errors If BoolCheckForErrors Then objlogFile.Writeline(Time & " Exitting due to hardware errors. Code 103") WScript.Quit 105 End If 'Check for Microcode Status If Not BoolCheckMicrocode Then objlogFile.Writeline(Time & " Exitting due to Incorrect Microcode. Code 104") WScript.Quit 104 End If If False Then 'BoolCheckSecure Then objlogFile.Writeline(Time & " Exitting because connection is Secure. Code 106") WScript.Quit 106 End If 'Check for Thresholds ParseFiles If DiskHitPercent >= DiskHitPercentMax Then WScript.Quit 103 End If If CPUHitPercent >= CPUHitPercentMax Then WScript.Quit 102 End If If CacheHitPercent >= CacheHitPercentMax Then WScript.Quit 101 End If '--------------------------------------------------------- ' Start Creation of Devices '--------------------------------------------------------- 'TODO: Read Lines from Batch Files. ' Run each line. ' At Seperators, put in a wait. ' Check Time passed. 'Load Commands to be ran. For Each File In GetConfigFileArray LoadConfig(ConfigLocation & File) Next WScript.Echo "-------------------------------------------" WScript.Echo "No Errors Found." WScript.Echo "-------------------------------------------" WScript.Echo "Microcode: " & RequiredMC WScript.Echo "-------------------------------------------" WScript.Echo "Total Disks: " & (TotalDiskEntries/2) WScript.Echo "Disks hits above threshold(" & HighDiskRate &"): " & HighDiskHit WScript.Echo "-------------------------------------------" WScript.Echo "Total Cores: " & TotalCpuEntries WScript.Echo "Cores hits above threshold(" & HighCpuHit &"): " & HighCpuHit WScript.Echo "-------------------------------------------" WScript.Echo "Total Cache Entries: " & TotalCacheEntries WScript.Echo "Cache hits above threshold(" & HighCacheWait &"): " & HighCacheHit WScript.Echo "-------------------------------------------" 'RETURN CODES '=========================== '0 - All precheck test were successful it is safe to continue '106 - HDvM is using secure protocol '105 - Failed or Failing components were detected '104 - Wrong version of Microcode detected '103 - Disk utilization rates were detected above threshold '102 - CPU utilization rates were detected above threshold '101 - Cache Write Pending rates were detected above threshold