From c49913ce19fae92821a1919e68e94e1cfe6e0dc3 Mon Sep 17 00:00:00 2001 From: Malcolm Stewart <63060860+Malcolm-Stewart@users.noreply.github.com> Date: Wed, 20 Nov 2024 11:04:29 -0500 Subject: [PATCH] SQLTrace and SQLCheck Integration Altered SQLTrace to run SQLCheck if it's in the same directory (default) or in the specified directory. Place the SQLCheck log into the SQLTrace log folder. --- SQLTrace/SQLTrace.ini | 4 +++- SQLTrace/SQLTrace.ps1 | 31 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/SQLTrace/SQLTrace.ini b/SQLTrace/SQLTrace.ini index 5ce3e7c..17899f0 100644 --- a/SQLTrace/SQLTrace.ini +++ b/SQLTrace/SQLTrace.ini @@ -75,4 +75,6 @@ SQLErrorLog = Yes # Line up SQL errors with other traces SQLXEventLog = No # These are large; do not collect unless you suspect a SQL Health issue DeleteOldFiles = No # This triggers the switch to delete old files depending on configuration of MinFiles and MinMinutes MinFiles = 20 # Only delete files beyond this limit that are more than MinMinutes old -MinMinutes = 60 # Only delete files older than this number of minutes (LastWriteTime) has elapsed \ No newline at end of file +MinMinutes = 60 # Only delete files older than this number of minutes (LastWriteTime) has elapsed +SQLCheck = Yes # Run SQLCheck if it's in the SQLTrace.ps1 folder and redirect the output to the log folder +SQLCheckPath = .\ # SQLCheck.exe location - defaults to the current folder diff --git a/SQLTrace/SQLTrace.ps1 b/SQLTrace/SQLTrace.ps1 index a40aeaa..2607383 100644 --- a/SQLTrace/SQLTrace.ps1 +++ b/SQLTrace/SQLTrace.ps1 @@ -95,7 +95,7 @@ LogRaw " /_______ /\_____\ \_/|_______ \|____| |__| (____ / \___ >\___ > \/ \__> \/ \/ \/ \/ - SQLTrace.ps1 version 1.0.0217.0 + SQLTrace.ps1 version 1.0.0234.0 by the Microsoft SQL Server Networking Team " @@ -177,6 +177,8 @@ Function ReadINIFile DeleteOldFiles = "No" MinFiles = "20" MinMinutes = "30" + SQLCheck = "Yes" + SQLCheckPath = ".\" # default to current folder } $fileName = $INIFile @@ -232,6 +234,8 @@ Function ReadINIFile "DeleteOldFiles" { $global:INISettings.DeleteOldFiles = $value } "MinFiles" { $global:INISettings.MinFiles = $value } "MinMinutes" { $global:INISettings.MinMinutes = $value } + "SQLCheck" { $global:INISettings.SQLCheck = $value } + "SQLCheckPath" { $global:INISettings.SQLCheckPath = $value } default { "Unknown keyword $keyWord in line: $l" } } } @@ -269,6 +273,8 @@ Function DisplayINIValues LogInfo "DeleteOldFiles $($global:INISettings.DeleteOldFiles)" LogInfo "MinFiles $($global:INISettings.MinFiles)" LogInfo "MinMinutes $($global:INISettings.MinMinutes)" + LogInfo "SQLCheck $($global:INISettings.SQLCheck)" + LogInfo "SQLCheckPath $($global:INISettings.SQLCheckPath)" } function RegisterEventLog @@ -406,6 +412,29 @@ Function StartTraces FlushExistingTraces FlushCaches + # Run SQLCheck + + if($global:INISettings.SQLCheck -eq "Yes") + { + if((Test-Path "$($global:INISettings.SQLCheckPath)SQLCheck.exe" -PathType Leaf) -eq $false) + { + LogWarning "SQLCheck not found at the following location: $($global:INISettings.SQLCheckPath)SQLCheck.exe" + } + else + { + LogInfo "Starting SQLCheck." + $cmd = (get-item "$($global:INISettings.SQLCheckPath)SQLCheck.exe").FullName # absolute path to SQLCheck, e.g. .\sqlcheck.exe -> c:\msdata\sqlcheck.exe + Push-Location "$($global:LogFolderName)" # change to the log folder and preserve the path + $result = invoke-expression $cmd # log is written to the current [log folder] location + LogInfo "SQLCheck: $result" + Pop-Location # return to the last folder before the Push-Location + } + } + else + { + LogInfo "SQLCheck not run." + } + tasklist > "$($global:LogFolderName)\TasklistAtStart.txt" netstat -abon > "$($global:LogFolderName)\NetStatAtStart.txt" ipconfig -all > "$($global:LogFolderName)\IPCONFIG.txt"