Skip to content

Commit

Permalink
feat(mssql): pull always on availability groups and add ability to sp…
Browse files Browse the repository at this point in the history
…ecify 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]>
  • Loading branch information
shane-borden and Shane Borden authored Nov 6, 2024
1 parent b2bb8d4 commit 52a8261
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 4.3.39
current_version = 4.3.40
commit = False
tag = False

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

To Execute the Collection:

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = { text = "Apache-2.0" }
name = "dma"
readme = "README.md"
requires-python = ">=3.9,<3.13"
version = "4.3.39"
version = "4.3.40"

# keywords for easier look-up on PyPI
authors = [
Expand Down
2 changes: 1 addition & 1 deletion scripts/collector/mysql/collect-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### Setup directories needed for execution
#############################################################################
OpVersion="4.3.39"
OpVersion="4.3.40"
dbmajor=""

LOCALE=$(echo $LANG | cut -d '.' -f 1)
Expand Down
2 changes: 1 addition & 1 deletion scripts/collector/oracle/collect-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### Setup directories needed for execution
#############################################################################
OpVersion="4.3.39"
OpVersion="4.3.40"
dbmajor=""

LOCALE=$(echo $LANG | cut -d '.' -f 1)
Expand Down
2 changes: 1 addition & 1 deletion scripts/collector/postgres/collect-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

### Setup directories needed for execution
#############################################################################
OpVersion="4.3.39"
OpVersion="4.3.40"
dbmajor=""

LOCALE=$(echo $LANG | cut -d '.' -f 1)
Expand Down
1 change: 1 addition & 0 deletions scripts/collector/sqlserver/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Operating System Versions:
-ignorePerfmon **Optional (Defaults to "false" / Set to "true" to ignore perfmon collection)
-manualUniqueId **Optional (Defaults to "NA" - Gives the ability the user to tag their collection with a unique name)
-collectVMSpecs **Optional switch. See below.
-outputDirectory **Optional (write the final zip file to another location - must be escaped properly if spaces are in the directory name)

For a Named Instance (all databases):
.\runAssessment.bat -serverName [servername\instanceName] -port [port number] -collectionUserName [collection user name] -collectionUserPass [collection user password] -manualUniqueId [string]
Expand Down
41 changes: 32 additions & 9 deletions scripts/collector/sqlserver/instanceReview.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
Note the script will attempt to collect VM specs using the current users regardless. (default:false)
.PARAMETER useWindowsAuthentication
Specifies if the loging to the database will utilize the current Windows Authenticated User or the supplied username / password for SQL Authentication (default:false)
.PARAMETER outputDirectory
User specified output directory if desired to be different from the $PSScriptRoot default
.EXAMPLE
To use a specific username / password combination for a named instance:
instanceReview.ps1 -serverName [server name / ip address]\[instance name] -collectionUserName [collection username] -collectionUserPass [collection username password] -ignorePerfmon [true/false] -dmaManualId [string]
Expand All @@ -56,7 +58,8 @@ Param(
[Parameter(Mandatory = $false)][string]$ignorePerfmon = "false",
[Parameter(Mandatory = $false)][string]$manualUniqueId = "NA",
[Parameter(Mandatory = $false)][switch]$collectVMSpecs,
[Parameter(Mandatory = $false)][switch]$useWindowsAuthentication = $false
[Parameter(Mandatory = $false)][switch]$useWindowsAuthentication = $false,
[Parameter(Mandatory = $false)][string]$outputDirectory = "default"
)

Import-Module $PSScriptRoot\dmaCollectorCommonFunctions.psm1
Expand Down Expand Up @@ -249,7 +252,7 @@ $validSQLInstanceVersionCheckValues = $splitValidInstanceVerisionCheckObj | ForE
$isValidSQLInstanceVersion = $validSQLInstanceVersionCheckValues[0]
$isCloudOrLinuxHost = $validSQLInstanceVersionCheckValues[1]

$op_version = "4.3.39"
$op_version = "4.3.40"

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

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

WriteLog -logLocation $foldername\$logFile -logMessage "Zipping Output to $zippedopfolder..." -logOperation "BOTH"

if ($powerShellVersion -ge 5) {
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $zippedopfolder

if (([string]::IsNullorEmpty($outputDirectory)) -or ($outputDirectory -eq "default")) {
WriteLog -logLocation $foldername\$logFile -logMessage "Zipping Output to $zippedopfolder..." -logOperation "BOTH"
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $zippedopfolder
$customOutputDir = 0
} else {
if ((Test-Path -Path $outputDirectory) -and ($outputDirectory -ne "default")) {
WriteLog -logLocation $foldername\$logFile -logMessage "Zipping Output to $outputDirectory\$zippedopfolder..." -logOperation "BOTH"
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $outputDirectory\$zippedopfolder
$customOutputDir = 1
} else {
WriteLog -logLocation $foldername\$logFile -logMessage "Specified $outputDirectory is not valid. Zipping Output to default directory $PSScriptRoot\$zippedopfolder..." -logOperation "BOTH"
Compress-Archive -Path $foldername\*.csv, $foldername\*.log, $foldername\*.txt -DestinationPath $zippedopfolder
$customOutputDir = 0
}
}

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

WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "MESSAGE"
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "MESSAGE"
WriteLog -logLocation $foldername\$logFile -logMessage "Return file $PSScriptRoot\$zippedopfolder" -logOperation "MESSAGE"
WriteLog -logLocation $foldername\$logFile -logMessage "to Google to complete assessment" -logOperation "MESSAGE"
WriteLog -logLocation $foldername\$logFile -logMessage "Collection Complete..." -logOperation "MESSAGE"

if ($customOutputDir -eq 0) {
WriteLog -logLocation $foldername\$logFile -logMessage "Return file $PSScriptRoot\$zippedopfolder" -logOperation "MESSAGE"
WriteLog -logLocation $foldername\$logFile -logMessage "to Google to complete assessment" -logOperation "MESSAGE"
} else {
WriteLog -logLocation $foldername\$logFile -logMessage "Return file $outputDirectory\$zippedopfolder" -logOperation "MESSAGE"
WriteLog -logLocation $foldername\$logFile -logMessage "to Google to complete assessment" -logOperation "MESSAGE"
}
WriteLog -logLocation $foldername\$logFile -logMessage "Collection Complete..." -logOperation "MESSAGE"
}
else {
WriteLog -logLocation $foldername\$logFile -logMessage " " -logOperation "MESSAGE"
Expand All @@ -689,4 +712,4 @@ else {
WriteLog -logLocation $foldername\$logFile -logMessage "Collection Complete..." -logOperation "MESSAGE"
}

Exit 0
Exit 0
10 changes: 6 additions & 4 deletions scripts/collector/sqlserver/runAssessment.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ set database=all
set noPerfmon=false
set collectVMSpecs=
set useWindowsAuthentication=false
set outputDir=default

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]
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]
set helpExample=Example (default port): runAssessment.bat -serverName MS-SERVER1\SQL2019 -collectionUserName sa -collectionUserPass password123 -ignorePerfmon [true/false] -manualUniqueId mySQLServerDB1
set helpExamplePort=Example (specified port): runAssessment.bat -serverName MS-SERVER1 -port 1436 -collectionUserName sa -collectionUserPass password123 -ignorePerfmon [true/false] -manualUniqueId mySQLServerDB1
set helpExampleDatabase=Example (default port / single database): runAssessment.bat -serverName MS-SERVER1\SQL2019 -database AdventureWorks2019 -collectionUserName sa -collectionUserPass password123 -ignorePerfmon [true/false] -manualUniqueId mySQLServerDB1
Expand All @@ -50,6 +51,7 @@ if /i "%1" == "-ignorePerfmon" set "noPerfmon=%2"
if /i "%1" == "-manualUniqueId" set "manualUniqueId=%2"
if /i "%1" == "-collectVMSpecs" set "collectVMSpecs=true"
if /i "%1" == "-useWindowsAuthentication" set "useWindowsAuthentication=true"
if /i "%1" == "-outputDirectory" set "outputDir=%2"

shift
goto :loop
Expand All @@ -69,15 +71,15 @@ if [%user%] == [] (

if "%useWindowsAuthentication%"=="false" (
if not [%user%]==[] (
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -collectionUserName %user% -collectionUserPass %pass% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId%"
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%"
) ELSE (
goto error
)
) ELSE (
if not [%user%]==[] (
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"
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%"
) ELSE (
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -useWindowsAuthentication"
SET "command=PowerShell -nologo -NoProfile -ExecutionPolicy Bypass -File .\instanceReview.ps1 -serverName %serverName% -port %port% -database %database% -ignorePerfmon %noPerfmon% -manualUniqueId %manualUniqueId% -useWindowsAuthentication -outputDirectory %outputDir%"
)
)

Expand Down
9 changes: 8 additions & 1 deletion scripts/collector/sqlserver/sql/serverProperties.sql
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,13 @@ BEGIN
IF ERROR_NUMBER() = 208 AND ERROR_SEVERITY() = 16 AND ERROR_STATE() = 1
exec('INSERT INTO #serverProperties SELECT ''IsDTCInUse'', ''0'' /* SQL Server 2016 (13.x) and above */');
END CATCH

BEGIN TRY
exec('INSERT INTO #serverProperties SELECT ''AvailabilityGroupCount'', count(*) FROM sys.availability_groups /* SQL Server 2012 (11.x) and above */')
END TRY
BEGIN CATCH
IF ERROR_NUMBER() = 208 AND ERROR_SEVERITY() = 16 AND ERROR_STATE() = 1
exec('INSERT INTO #serverProperties SELECT ''AvailabilityGroupCount'', ''0''');
END CATCH
exec('INSERT INTO #serverProperties SELECT ''HostPlatform'', ''Azure VM''');
exec('INSERT INTO #serverProperties SELECT ''HostDistribution'', ''Linux''');
exec('INSERT INTO #serverProperties SELECT ''HostRelease'', ''UNKNOWN''');
Expand Down Expand Up @@ -357,6 +363,7 @@ BEGIN
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 */');
/* Must Query a different column for committed memory in versions above 10.x */
exec('INSERT INTO #serverProperties SELECT ''TotalSQLServerCommittedMemoryMB'', CONVERT(NVARCHAR(255), committed_target_kb/1024) FROM sys.dm_os_sys_info')
exec('INSERT INTO #serverProperties SELECT ''AvailabilityGroupCount'', count(*) FROM sys.availability_groups /* SQL Server 2012 (11.x) and above */')
END;
END;

Expand Down
2 changes: 1 addition & 1 deletion scripts/masker/dma-collection-masker
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ __all__ = (
"run_masker",
)

__version__ = "4.3.39"
__version__ = "4.3.40"

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 52a8261

Please sign in to comment.