* Adapted the powershell to connect to the central with a dedicated sql login
* reverted script 9_Update_FTPLogin_Central to the original version
* script 9_Update_FTPLogin_Central is executed on the central directly with a dedicated login
* reverted scripts 20_update_system_site_centrale.sql and 21_update_point_of_sale_centrale.sql to work locally only
*  scripts scripts 20_update_system_site_centrale.sql and 21_update_point_of_sale_centrale.sql are executed on the cenrtal with a specific login and on the local instance
* when fetching the mac addresses, only take up interfaces in account and group the results by mac addresses, to avoid virtual mac addresses duplicate causing an error
This commit is contained in:
2024-03-15 11:23:24 +01:00
parent 6903f71717
commit 88a89d84fe
4 changed files with 93 additions and 168 deletions

View File

@@ -6,7 +6,7 @@ Update central system_site values for a specific OU
Parameters Parameters
---------------------- ----------------------
In script parameters updated from Powershell are present: In script parameters updated from Powershell are present:
@ou_id The id ofthe OU we need to update. This id is fetched from the local machine being migrated. @ou_id The id of the OU we need to update. This id is fetched from the local machine being migrated.
@fqdn The FQDN of the machine being migrated to Azure. This is fetched from a DNS request, not built. @fqdn The FQDN of the machine being migrated to Azure. This is fetched from a DNS request, not built.
@alias The alias of the machine being migrated to Azure. This is logically built from the FQDN @alias The alias of the machine being migrated to Azure. This is logically built from the FQDN
@@ -20,38 +20,14 @@ Creation : 04.03.2024 / TSC
Modifications: Modifications:
07.03.2024 TSC Rewrote to connect to the central through the pharmacy linked server ArizonaCash 07.03.2024 TSC Rewrote to connect to the central through the pharmacy linked server ArizonaCash
The values in the local pharmacy are updated as well The values in the local pharmacy are updated as well
15.03.2024 TSC Went back to a local update. this script will be run both locally and on the central from the powershell executing it
=============================================================================*/ =============================================================================*/
USE [master]; USE [master];
DECLARE @ou_id INT; DECLARE @ou_id INT = $ou_id;
DECLARE @fqdn VARCHAR(100) = '$fqdn'; DECLARE @fqdn VARCHAR(100) = '$fqdn';
DECLARE @alias VARCHAR(100) = '$alias'; DECLARE @alias VARCHAR(100) = '$alias';
EXECUTE [Arizona].[dbo].[sp_bmc_Bmc_Applic_Default]
@in_job_type = 3,
@in_param_int_1 = NULL, /* Company */
@in_param_int_2 = NULL, /* Subsidiary */
@in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
@out_default_value = @ou_id OUTPUT,
@out_param_int_1 = NULL;
--central
UPDATE ss
SET [ss].[SS_server_name] = @alias
, [ss].[SS_IP_server_address] = @alias
, [ss].[SS_domain_name] = @fqdn
FROM [arizonaCash].[arizona].[dbo].[Organizational_unit] ou
JOIN [arizonaCash].[arizona].[dbo].[System_site] ss ON ss.[System_site_ID] = ou.[OU_system_site]
WHERE ou.[Organizational_unit_ID] = @ou_id;
UPDATE ssi
SET [ssi].[SSSI_SQL_instance_name] = @alias+'\APSSQL'
FROM [arizonaCash].[arizona].[dbo].[Organizational_unit] ou
JOIN [arizonaCash].[arizona].[dbo].[System_site] ss ON ss.[System_site_ID] = ou.[OU_system_site]
JOIN [arizonaCash].[arizona].[dbo].[System_site_SQL_instance] ssi ON ssi.[SSSI_system_site] = ss.[System_site_ID]
WHERE ou.[Organizational_unit_ID] = @ou_id;
--local
UPDATE ss UPDATE ss
SET [ss].[SS_server_name] = @alias SET [ss].[SS_server_name] = @alias
, [ss].[SS_IP_server_address] = @alias , [ss].[SS_IP_server_address] = @alias

View File

@@ -6,7 +6,7 @@ Update central system_site values for a specific OU
Parameters Parameters
---------------------- ----------------------
In script parameters updated from Powershell are present: In script parameters updated from Powershell are present:
@ou_id The id ofthe OU we need to update. This id is fetched from the local machine being migrated. @ou_id The id of the OU we need to update. This id is fetched from the local machine being migrated.
@fqdn The FQDN of the machine being migrated to Azure. This is fetched from a DNS request, not built. @fqdn The FQDN of the machine being migrated to Azure. This is fetched from a DNS request, not built.
@mac The MAC address fetched from the local machine @mac The MAC address fetched from the local machine
@@ -20,29 +20,14 @@ Creation : 04.03.2024 / TSC
Modifications: Modifications:
07.03.2024 TSC Rewrote to connect to the central through the pharmacy linked server ArizonaCash 07.03.2024 TSC Rewrote to connect to the central through the pharmacy linked server ArizonaCash
The values in the local pharmacy are updated as well The values in the local pharmacy are updated as well
15.03.2024 TSC Went back to a local update. this script will be run both locally and on the central from the powershell executing it
=============================================================================*/ =============================================================================*/
USE [master]; USE [master];
DECLARE @ou_id INT; DECLARE @ou_id INT = $ou_id;
DECLARE @fqdn VARCHAR(100) = '$fqdn'; DECLARE @fqdn VARCHAR(100) = '$fqdn';
DECLARE @mac VARCHAR(100) = '$mac'; DECLARE @mac VARCHAR(100) = '$mac';
EXECUTE Arizona.[dbo].[sp_bmc_Bmc_Applic_Default]
@in_job_type = 3,
@in_param_int_1 = NULL, /* Company */
@in_param_int_2 = NULL, /* Subsidiary */
@in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
@out_default_value = @ou_id OUTPUT,
@out_param_int_1 = NULL;
--central
UPDATE ps
SET [ps].[POS_MAC_address] = @mac
, [ps].[POS_hostname] = @fqdn
FROM [arizonaCash].[arizona].[dbo].[Point_of_sale] ps
WHERE [ps].[POS_organizational_unit] = @ou_id
AND [ps].[POS_number]=99;
--local --local
UPDATE ps UPDATE ps
SET [ps].[POS_MAC_address] = @mac SET [ps].[POS_MAC_address] = @mac

View File

@@ -1,67 +1,46 @@
/*============================================================================= IF EXISTS ( SELECT 1
FROM [Arizona].[dbo].[System_site] SS
Update the ftp password in system_site_transfert table on the central from a pharmacy, for this pharmacy JOIN [Arizona].[dbo].[System_site_transfer] SST
ON SST.SST_dest_system_site = SS.System_site_ID
Parameters WHERE SS.SS_server_name = '$fqdn'
---------------------- AND SST.SST_bmc_task = 109)
Context
----------------------
This script is run in a pharmacy, during the preparation / migration of the pharmacy
Creation : 07.03.2024 / TSC
Modifications:
=============================================================================*/
IF EXISTS ( SELECT 1
FROM [ARIZONACASH].[Arizona].[dbo].[System_site] SS
JOIN [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] SST
ON [SST].[SST_dest_system_site] = [SS].[System_site_ID]
WHERE [SS].[SS_server_name] = '$fqdn'
AND [SST].[SST_bmc_task] = 109)
BEGIN BEGIN
UPDATE [Arizona].[dbo].[System_site_transfer]
UPDATE [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] SET SST_connection_info = '<ConnectionInfos><Ftp username="centralinfra\svc-APH-trans" pwd="$ftppass"/></ConnectionInfos>'
SET [SST_connection_info] = '<ConnectionInfos><Ftp username="centralinfra\svc-APH-trans" pwd="$ftppass"/></ConnectionInfos>' FROM [Arizona].[dbo].[System_site] SS
FROM [ARIZONACASH].[Arizona].[dbo].[System_site] SS JOIN [Arizona].[dbo].[System_site_transfer] SST
JOIN [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] SST ON SST.SST_dest_system_site = SS.System_site_ID
ON [SST].[SST_dest_system_site] = [SS].[System_site_ID] WHERE SS.SS_server_name = '$fqdn';
WHERE [SS].[SS_server_name] = '$fqdn';
END; END;
ELSE ELSE
BEGIN BEGIN
IF EXISTS ( SELECT 1
IF EXISTS ( SELECT 1 FROM Arizona.dbo.System_site
FROM [ARIZONACASH].Arizona.[dbo].[System_site] WHERE SS_server_name = '$fqdn')
WHERE [SS_server_name] = '$fqdn') BEGIN
BEGIN UPDATE Arizona.dbo.Bmc_ID_counter
SET BMCID_last_number = ( SELECT BMCID_last_number + 1
UPDATE [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter] FROM Arizona.dbo.Bmc_ID_counter
SET [BMCID_last_number] = ( SELECT [BMCID_last_number] + 1 WHERE BMCID_key = 'system_site_transfer')
FROM [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter] FROM Arizona.dbo.Bmc_ID_counter
WHERE [BMCID_key] = 'system_site_transfer') WHERE BMCID_key = 'system_site_transfer';
FROM [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter] INSERT INTO [Arizona].[dbo].[System_site_transfer] ([System_site_transfer_ID],
WHERE [BMCID_key] = 'system_site_transfer'; [SST_source_system_site],
[SST_dest_system_site],
INSERT INTO [ARIZONACASH].[Arizona].[dbo].[System_site_transfer] ([System_site_transfer_ID], [SST_bmc_task],
[SST_source_system_site], [SST_transfer_type],
[SST_dest_system_site], [SST_VGUID],
[SST_bmc_task], [SST_master_ID],
[SST_transfer_type], [SST_connection_info],
[SST_VGUID], [SST_start_date],
[SST_master_ID], [SST_end_date])
[SST_connection_info], VALUES (( SELECT BMCID_last_number
[SST_start_date], FROM Arizona.dbo.Bmc_ID_counter
[SST_end_date]) WHERE BMCID_key = 'system_site_transfer'), 102, ( SELECT System_site_ID
VALUES (( SELECT [BMCID_last_number] FROM Arizona.dbo.System_site
FROM [ARIZONACASH].Arizona.[dbo].[Bmc_ID_counter] WHERE SS_server_name = '$fqdn'), 109, 1,
WHERE [BMCID_key] = 'system_site_transfer'), 102, ( SELECT [System_site_ID] DEFAULT, NULL,
FROM [ARIZONACASH].Arizona.[dbo].[System_site] '<ConnectionInfos><Ftp username="centralinfra\svc-APH-trans" pwd="$ftppass"/></ConnectionInfos>',
WHERE [SS_server_name] = '$fqdn'), 109, 1, DEFAULT, (SELECT CONVERT(CHAR(10), GETDATE(), 126)), NULL);
NULL, '<ConnectionInfos><Ftp username="centralinfra\svc-APH-trans" pwd="$ftppass"/></ConnectionInfos>', END;
(SELECT CONVERT(CHAR(10), GETDATE(), 126)), NULL); END;
END;
END;

View File

@@ -143,6 +143,7 @@ $keyVaultName = "kv-ApoLsPoc-Tde"
$secretFtpPassword ="centralinfra---svc-APH-trans" $secretFtpPassword ="centralinfra---svc-APH-trans"
$secretMasterKey ="MasterKey" $secretMasterKey ="MasterKey"
$secretTriaPharmSQLCert = "TriaPharmSQLCert" $secretTriaPharmSQLCert = "TriaPharmSQLCert"
$secretSqlAzureMigration = "sqlAzureMigration"
# Convert the client secret to a secure string # Convert the client secret to a secure string
$securePassword = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force $securePassword = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
@@ -153,9 +154,11 @@ $psCred = New-Object System.Management.Automation.PSCredential -ArgumentList $cl
# Authenticate using the service principal # Authenticate using the service principal
$null = Connect-AzAccount -ServicePrincipal -Credential $psCred -TenantId $tenantId $null = Connect-AzAccount -ServicePrincipal -Credential $psCred -TenantId $tenantId
# Get the secret from Azure Key Vault # Get the login for sqlAzureMigration from Azure Key Vault
# $secret = Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretName $secret_central = Get-AzKeyVaultSecret -VaultName $keyVaultName -Name $secretSqlAzureMigration
# write-host "domain: $($ua.Tags["domain"])" $login_central = "sqlAzureMigration"
$psCredCentral = New-Object System.Management.Automation.PSCredential($login_central, $secret_central.SecretValue)
# Display the secret value # Display the secret value
#Write-Host "Secret Value: $($secret.SecretValue | ConvertFrom-SecureString -AsPlainText)" #Write-Host "Secret Value: $($secret.SecretValue | ConvertFrom-SecureString -AsPlainText)"
@@ -308,55 +311,14 @@ if($true -eq $checkoutGit){
#$instanceReachable = $false #$instanceReachable = $false
if($true -eq $instanceReachable){ if($true -eq $instanceReachable){
##fetch OU details from control center
## CLA: can be ignored due to SWITCH directly after this QUERY
<#
$query=@"
SELECT LOWER([SERV].[SE_DNS]) AS SE_DNS,
CASE
WHEN UPPER(LEFT([SERV].[SE_DNS], 3)) = 'SCV' THEN 'CVI'
WHEN UPPER(LEFT([SERV].[SE_DNS], 3)) = 'SSU' THEN 'SUN'
WHEN UPPER(LEFT([SERV].[SE_DNS], 3)) = 'SAM' THEN 'AMA'
ELSE UPPER(LEFT([SERV].[SE_DNS], 3))END AS [customer],
CASE
WHEN UPPER([SERV].[SE_designation]) LIKE '%ACCEPTANCE%' THEN 'ACCE'
WHEN UPPER([SERV].[SE_designation]) LIKE '%FORMATION%' THEN 'FORM'
WHEN UPPER([SERV].[SE_designation]) LIKE '%SCHULUNG%' THEN 'FORM'
ELSE 'PROD' END AS [context],
LEFT(LTRIM([cfg].[CF_value]), 4) AS [version],
LOWER([SERV].[SE_DNS] + '\' + [SERV].[SE_instance_name]) AS [aliasInstance]
FROM [ControlCenter].[dbo].[Server] SERV
JOIN [ControlCenter].[dbo].[Config] cfg
ON [cfg].[CF_server] = [SERV].[SE_id]
JOIN [ControlCenter].[dbo].[ConfigType] cfgt
ON [cfgt].[CFTY_id] = [cfg].[CF_configtype]
JOIN [ControlCenter].[dbo].[Entity] ent
ON [ent].[EN_id] = [SERV].[SE_entity]
WHERE [cfgt].[CFTY_type] = 'TriaPharmVersion'
AND [SERV].[SE_status] = 1
AND ( ([SERV].[SE_end_prod_date] > GETDATE())
OR ([SERV].[SE_end_prod_date] IS NULL))
AND [SERV].[SE_designation] NOT LIKE '%Fermé%'
AND [SERV].[SE_designation] NOT LIKE '%REF%'
AND [ent].[EN_code] IN ( 'AMA', 'SUN', 'CVI' )
AND LOWER([SERV].[SE_DNS]) LIKE '$alias%'
ORDER BY [SERV].[SE_entity],
SE_DNS;
"@ #> $dbacc = New-Object psobject
$dbacc | Add-Member -MemberType NoteProperty -Name "context" -Value $ContextType
# $dbacc = Invoke-Sqlcmd -ServerInstance hcimon -Database ControlCenter -Query $query $dbacc | Add-Member -MemberType NoteProperty -Name "customer" -Value $customer
if($null -eq $dbacc){ $dbacc | Add-Member -MemberType NoteProperty -Name "version" -Value -1
Write-Output "No results in HCIMON, faking them" $dbacc | Add-Member -MemberType NoteProperty -Name "SE_DNS" -Value $hostname
$dbacc = New-Object psobject $dbacc | Add-Member -MemberType NoteProperty -Name "aliasInstance" -Value $sqlVariables
#$dbacc | Add-Member -MemberType NoteProperty -Name "context" -Value "DEVE"
$dbacc | Add-Member -MemberType NoteProperty -Name "context" -Value $ContextType
$dbacc | Add-Member -MemberType NoteProperty -Name "customer" -Value $customer
$dbacc | Add-Member -MemberType NoteProperty -Name "version" -Value -1
$dbacc | Add-Member -MemberType NoteProperty -Name "SE_DNS" -Value $hostname
$dbacc | Add-Member -MemberType NoteProperty -Name "aliasInstance" -Value $sqlVariables
}
##step 1: configure SQL instance max memory ##step 1: configure SQL instance max memory
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -InputFile .\1_Configure_InstanceMemory.sql Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -InputFile .\1_Configure_InstanceMemory.sql
Write-Output "Executed 1_Configure_InstanceMemory.sql" Write-Output "Executed 1_Configure_InstanceMemory.sql"
@@ -392,10 +354,9 @@ if($true -eq $instanceReachable){
$query = $query.Replace("`$fqdn", $alias) $query = $query.Replace("`$fqdn", $alias)
#Invoke-Sqlcmd -ServerInstance gcmPrdCent -Database arizona -Query $query #Invoke-Sqlcmd -ServerInstance gcmPrdCent -Database arizona -Query $query
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database arizona -Query $query Invoke-Sqlcmd -ServerInstance $CentraleServer -Database arizona -Query $query -Credential $psCredCentral
Write-Output "Executed 9_Update_FTPLogin_Central.sql" Write-Output "Executed 9_Update_FTPLogin_Central.sql"
##step 6: execute all DBA packages ##step 6: execute all DBA packages
$LogFile = "C:\Temp\DBApackagesCLA.log" $LogFile = "C:\Temp\DBApackagesCLA.log"
@@ -532,21 +493,44 @@ if($true -eq $instanceReachable){
##step 20: update system_site on the central ##step 20: update system_site on the central
$fqdn = [System.Net.Dns]::GetHostByName($alias) $fqdn = [System.Net.Dns]::GetHostByName($alias)
#Get pharmacy OU_id
$query=@"
USE [master];
DECLARE @ou_id INT;
EXECUTE [Arizona].[dbo].[sp_bmc_Bmc_Applic_Default]
@in_job_type = 3,
@in_param_int_1 = NULL, /* Company */
@in_param_int_2 = NULL, /* Subsidiary */
@in_param_varchar_1 = 'cvCurrentOrganizationalUnit',
@out_default_value = @ou_id OUTPUT,
@out_param_int_1 = NULL;
SELECT @ou_id as ou_id
"@
$ou_dataset = Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
#update the centrale #update the centrale
$query=Get-Content -Path .\20_update_system_site_centrale.sql $query=Get-Content -Path .\20_update_system_site_centrale.sql
$query = $query.Replace("`$fqdn", $fqdn.HostName) $query = $query.Replace("`$fqdn", $fqdn.HostName)
$query = $query.Replace("`$alias", $alias) $query = $query.Replace("`$alias", $alias)
$query = $query.Replace("`$ou_id", $ou_dataset.ou_id)
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
Write-Output "Executed 20_update_system_site_centrale.sql" Write-Output "Executed 20_update_system_site_centrale.sql locally"
##step 21: update Point_of_sale on the central Invoke-Sqlcmd -ServerInstance $CentraleServer -Database master -Query $query -Credential $psCredCentral
Write-Output "Executed 20_update_system_site_centrale.sql on the central $CentraleServer"
##step 21: update Point_of_sale
#fetch a list of mac adresses #fetch a list of mac adresses
$macs = @{} $macs = @{}
$pos = 0 $pos = 0
Get-NetAdapter | Select-Object ifIndex, Name, MacAddress | ForEach-Object { Get-NetAdapter | Where-Object -Property status -eq up | Group-Object -Property MacAddress | ForEach-Object {
$macs.Add($pos, $_.MacAddress) $macs.Add($pos, $_.Name)
$pos++ $pos++
} }
@@ -556,11 +540,12 @@ if($true -eq $instanceReachable){
exit 42102 exit 42102
} }
else{ else{
$query=Get-Content -Path .\21_update_point_of_sale_centrale.sql $query=Get-Content -Path C:\Users\ua208700\Documents\21_update_point_of_sale_centrale.sql
$query = $query.Replace("`$fqdn", $fqdn.HostName) $query = $query.Replace("`$fqdn", $hostname)
$query = $query.Replace("`$mac", $macs[0].value) $query = $query.Replace("`$mac", $macs[0])
Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query #Invoke-Sqlcmd -ServerInstance $SqlInstance -Database master -Query $query
Write-Output $query
Write-Output "Executed 21_update_point_of_sale_centrale.sql" Write-Output "Executed 21_update_point_of_sale_centrale.sql"
} }