Skip to content

Commit 52a8261

Browse files
shane-bordenShane Borden
andauthored
feat(mssql): pull always on availability groups and add ability to specify output directory (#471)
* fix: collect availability group information by counting the number of groups * chore: bump version * feat: add option to specify output directory chore: update docs * fix: add default value for outputDir and logging messages for custom output directory * Update collection_scripts.md Signed-off-by: Shane Borden <[email protected]> * Update collection_scripts.md Signed-off-by: Shane Borden <[email protected]> * Update README.txt Signed-off-by: Shane Borden <[email protected]> --------- Signed-off-by: Shane Borden <[email protected]> Co-authored-by: Shane Borden <[email protected]>
1 parent b2bb8d4 commit 52a8261

File tree

11 files changed

+54
-20
lines changed

11 files changed

+54
-20
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 4.3.39
2+
current_version = 4.3.40
33
commit = False
44
tag = False
55

docs/user_guide/sqlserver/collection_scripts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ The script will create a permon data set that will collect the above metrics at
230230
- -ignorePerfmon \*\*Optional (Defaults to "false" / Set to "true" to ignore perfmon collection)
231231
- -manualUniqueId \*\*Optional (Defaults to "NA" - Gives the ability the user to tag their collection with a unique name)
232232
- -collectVMSpecs \*\*Optional switch. See [below](#collectvmspecs).
233+
- -outputDirectory \*\*Optional (write the final zip file to another location - must be escaped properly if spaces are in the directory name)
233234

234235
To Execute the Collection:
235236

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ license = { text = "Apache-2.0" }
88
name = "dma"
99
readme = "README.md"
1010
requires-python = ">=3.9,<3.13"
11-
version = "4.3.39"
11+
version = "4.3.40"
1212

1313
# keywords for easier look-up on PyPI
1414
authors = [

scripts/collector/mysql/collect-data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
### Setup directories needed for execution
1818
#############################################################################
19-
OpVersion="4.3.39"
19+
OpVersion="4.3.40"
2020
dbmajor=""
2121

2222
LOCALE=$(echo $LANG | cut -d '.' -f 1)

scripts/collector/oracle/collect-data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
### Setup directories needed for execution
1818
#############################################################################
19-
OpVersion="4.3.39"
19+
OpVersion="4.3.40"
2020
dbmajor=""
2121

2222
LOCALE=$(echo $LANG | cut -d '.' -f 1)

scripts/collector/postgres/collect-data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
### Setup directories needed for execution
1818
#############################################################################
19-
OpVersion="4.3.39"
19+
OpVersion="4.3.40"
2020
dbmajor=""
2121

2222
LOCALE=$(echo $LANG | cut -d '.' -f 1)

scripts/collector/sqlserver/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Operating System Versions:
207207
-ignorePerfmon **Optional (Defaults to "false" / Set to "true" to ignore perfmon collection)
208208
-manualUniqueId **Optional (Defaults to "NA" - Gives the ability the user to tag their collection with a unique name)
209209
-collectVMSpecs **Optional switch. See below.
210+
-outputDirectory **Optional (write the final zip file to another location - must be escaped properly if spaces are in the directory name)
210211

211212
For a Named Instance (all databases):
212213
.\runAssessment.bat -serverName [servername\instanceName] -port [port number] -collectionUserName [collection user name] -collectionUserPass [collection user password] -manualUniqueId [string]

scripts/collector/sqlserver/instanceReview.ps1

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
Note the script will attempt to collect VM specs using the current users regardless. (default:false)
3838
.PARAMETER useWindowsAuthentication
3939
Specifies if the loging to the database will utilize the current Windows Authenticated User or the supplied username / password for SQL Authentication (default:false)
40+
.PARAMETER outputDirectory
41+
User specified output directory if desired to be different from the $PSScriptRoot default
4042
.EXAMPLE
4143
To use a specific username / password combination for a named instance:
4244
instanceReview.ps1 -serverName [server name / ip address]\[instance name] -collectionUserName [collection username] -collectionUserPass [collection username password] -ignorePerfmon [true/false] -dmaManualId [string]
@@ -56,7 +58,8 @@ Param(
5658
[Parameter(Mandatory = $false)][string]$ignorePerfmon = "false",
5759
[Parameter(Mandatory = $false)][string]$manualUniqueId = "NA",
5860
[Parameter(Mandatory = $false)][switch]$collectVMSpecs,
59-
[Parameter(Mandatory = $false)][switch]$useWindowsAuthentication = $false
61+
[Parameter(Mandatory = $false)][switch]$useWindowsAuthentication = $false,
62+
[Parameter(Mandatory = $false)][string]$outputDirectory = "default"
6063
)
6164

6265
Import-Module $PSScriptRoot\dmaCollectorCommonFunctions.psm1
@@ -249,7 +252,7 @@ $validSQLInstanceVersionCheckValues = $splitValidInstanceVerisionCheckObj | ForE
249252
$isValidSQLInstanceVersion = $validSQLInstanceVersionCheckValues[0]
250253
$isCloudOrLinuxHost = $validSQLInstanceVersionCheckValues[1]
251254

252-
$op_version = "4.3.39"
255+
$op_version = "4.3.40"
253256

254257
if ([string]($isValidSQLInstanceVersion) -eq "N") {
255258
Write-Host "#############################################################"
@@ -351,6 +354,7 @@ $PSVersionTable | out-string | Add-Content -Encoding utf8 -Path $foldername\$log
351354
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "FILE"
352355
WriteLog -logLocation $foldername\$logFile -logMessage "Windows OS Version" -logOperation "FILE"
353356
WriteLog -logLocation $foldername\$logFile -logMessage "$windowsOSVersion" -logOperation "FILE"
357+
WriteLog -logLocation $foldername\$logFile -logMessage "Custom Output Directory: " $outputDirectory
354358

355359
if ($ignorePerfmonOsIncompatible -eq $true) {
356360
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "FILE"
@@ -661,10 +665,23 @@ else {
661665
$zippedopfolder = $foldername + '.zip'
662666
}
663667

664-
WriteLog -logLocation $foldername\$logFile -logMessage "Zipping Output to $zippedopfolder..." -logOperation "BOTH"
665-
666668
if ($powerShellVersion -ge 5) {
667-
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $zippedopfolder
669+
670+
if (([string]::IsNullorEmpty($outputDirectory)) -or ($outputDirectory -eq "default")) {
671+
WriteLog -logLocation $foldername\$logFile -logMessage "Zipping Output to $zippedopfolder..." -logOperation "BOTH"
672+
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $zippedopfolder
673+
$customOutputDir = 0
674+
} else {
675+
if ((Test-Path -Path $outputDirectory) -and ($outputDirectory -ne "default")) {
676+
WriteLog -logLocation $foldername\$logFile -logMessage "Zipping Output to $outputDirectory\$zippedopfolder..." -logOperation "BOTH"
677+
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $outputDirectory\$zippedopfolder
678+
$customOutputDir = 1
679+
} else {
680+
WriteLog -logLocation $foldername\$logFile -logMessage "Specified $outputDirectory is not valid. Zipping Output to default directory $PSScriptRoot\$zippedopfolder..." -logOperation "BOTH"
681+
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $zippedopfolder
682+
$customOutputDir = 0
683+
}
684+
}
668685

669686
if (Test-Path -Path $zippedopfolder) {
670687
WriteLog -logLocation $foldername\$logFile -logMessage "Removing directory $foldername..." -logOperation "MESSAGE"
@@ -677,9 +694,15 @@ if ($powerShellVersion -ge 5) {
677694

678695
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "MESSAGE"
679696
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "MESSAGE"
680-
WriteLog -logLocation $foldername\$logFile -logMessage "Return file $PSScriptRoot\$zippedopfolder" -logOperation "MESSAGE"
681-
WriteLog -logLocation $foldername\$logFile -logMessage "to Google to complete assessment" -logOperation "MESSAGE"
682-
WriteLog -logLocation $foldername\$logFile -logMessage "Collection Complete..." -logOperation "MESSAGE"
697+
698+
if ($customOutputDir -eq 0) {
699+
WriteLog -logLocation $foldername\$logFile -logMessage "Return file $PSScriptRoot\$zippedopfolder" -logOperation "MESSAGE"
700+
WriteLog -logLocation $foldername\$logFile -logMessage "to Google to complete assessment" -logOperation "MESSAGE"
701+
} else {
702+
WriteLog -logLocation $foldername\$logFile -logMessage "Return file $outputDirectory\$zippedopfolder" -logOperation "MESSAGE"
703+
WriteLog -logLocation $foldername\$logFile -logMessage "to Google to complete assessment" -logOperation "MESSAGE"
704+
}
705+
WriteLog -logLocation $foldername\$logFile -logMessage "Collection Complete..." -logOperation "MESSAGE"
683706
}
684707
else {
685708
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "MESSAGE"
@@ -689,4 +712,4 @@ else {
689712
WriteLog -logLocation $foldername\$logFile -logMessage "Collection Complete..." -logOperation "MESSAGE"
690713
}
691714

692-
Exit 0
715+
Exit 0

scripts/collector/sqlserver/runAssessment.bat

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ set database=all
2222
set noPerfmon=false
2323
set collectVMSpecs=
2424
set useWindowsAuthentication=false
25+
set outputDir=default
2526

26-
set helpMessage=Usage: runAssessment.bat -serverName [servername] -port [port number] -database [database name] -collectionUserName [username] -collectionUserPass [password] -ignorePerfmon [true/false] -manualUniqueId [unique tag to identify collection] [-collectVMSpecs]
27+
set helpMessage=Usage: runAssessment.bat -serverName [servername] -port [port number] -database [database name] -collectionUserName [username] -collectionUserPass [password] -ignorePerfmon [true/false] -manualUniqueId [unique tag to identify collection] [-collectVMSpecs] -outputDirectory [write zip file to different directory]
2728
set helpExample=Example (default port): runAssessment.bat -serverName MS-SERVER1\SQL2019 -collectionUserName sa -collectionUserPass password123 -ignorePerfmon [true/false] -manualUniqueId mySQLServerDB1
2829
set helpExamplePort=Example (specified port): runAssessment.bat -serverName MS-SERVER1 -port 1436 -collectionUserName sa -collectionUserPass password123 -ignorePerfmon [true/false] -manualUniqueId mySQLServerDB1
2930
set helpExampleDatabase=Example (default port / single database): runAssessment.bat -serverName MS-SERVER1\SQL2019 -database AdventureWorks2019 -collectionUserName sa -collectionUserPass password123 -ignorePerfmon [true/false] -manualUniqueId mySQLServerDB1
@@ -50,6 +51,7 @@ if /i "%1" == "-ignorePerfmon" set "noPerfmon=%2"
5051
if /i "%1" == "-manualUniqueId" set "manualUniqueId=%2"
5152
if /i "%1" == "-collectVMSpecs" set "collectVMSpecs=true"
5253
if /i "%1" == "-useWindowsAuthentication" set "useWindowsAuthentication=true"
54+
if /i "%1" == "-outputDirectory" set "outputDir=%2"
5355

5456
shift
5557
goto :loop
@@ -69,15 +71,15 @@ if [%user%] == [] (
6971

7072
if "%useWindowsAuthentication%"=="false" (
7173
if not [%user%]==[] (
72-
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -collectionUserName %user% -collectionUserPass %pass% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId%"
74+
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -collectionUserName %user% -collectionUserPass %pass% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -outputDirectory %outputDir%"
7375
) ELSE (
7476
goto error
7577
)
7678
) ELSE (
7779
if not [%user%]==[] (
78-
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -collectionUserName %user% -collectionUserPass %pass% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -useWindowsAuthentication"
80+
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -collectionUserName %user% -collectionUserPass %pass% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -useWindowsAuthentication -outputDirectory %outputDir%"
7981
) ELSE (
80-
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -useWindowsAuthentication"
82+
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -useWindowsAuthentication -outputDirectory %outputDir%"
8183
)
8284
)
8385

scripts/collector/sqlserver/sql/serverProperties.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,13 @@ BEGIN
254254
IF ERROR_NUMBER() = 208 AND ERROR_SEVERITY() = 16 AND ERROR_STATE() = 1
255255
exec('INSERT INTO #serverProperties SELECT ''IsDTCInUse'', ''0'' /* SQL Server 2016 (13.x) and above */');
256256
END CATCH
257-
257+
BEGIN TRY
258+
exec('INSERT INTO #serverProperties SELECT ''AvailabilityGroupCount'', count(*) FROM sys.availability_groups /* SQL Server 2012 (11.x) and above */')
259+
END TRY
260+
BEGIN CATCH
261+
IF ERROR_NUMBER() = 208 AND ERROR_SEVERITY() = 16 AND ERROR_STATE() = 1
262+
exec('INSERT INTO #serverProperties SELECT ''AvailabilityGroupCount'', ''0''');
263+
END CATCH
258264
exec('INSERT INTO #serverProperties SELECT ''HostPlatform'', ''Azure VM''');
259265
exec('INSERT INTO #serverProperties SELECT ''HostDistribution'', ''Linux''');
260266
exec('INSERT INTO #serverProperties SELECT ''HostRelease'', ''UNKNOWN''');
@@ -357,6 +363,7 @@ BEGIN
357363
exec('INSERT INTO #serverProperties SELECT ''SQLServerMemoryTargetInMB'', CONVERT(NVARCHAR(255), committed_target_kb/1024) FROM sys.dm_os_sys_info /* SQL Server 2012 (11.x) above */');
358364
/* Must Query a different column for committed memory in versions above 10.x */
359365
exec('INSERT INTO #serverProperties SELECT ''TotalSQLServerCommittedMemoryMB'', CONVERT(NVARCHAR(255), committed_target_kb/1024) FROM sys.dm_os_sys_info')
366+
exec('INSERT INTO #serverProperties SELECT ''AvailabilityGroupCount'', count(*) FROM sys.availability_groups /* SQL Server 2012 (11.x) and above */')
360367
END;
361368
END;
362369

0 commit comments

Comments
 (0)