-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathECE_log_collection_tool_v2.ps1
281 lines (261 loc) · 10.1 KB
/
ECE_log_collection_tool_v2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# Copyright (c) 2023 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# This software contains the intellectual property of Dell Inc. or is licensed to Dell Inc. from third parties.
# Use of this software and the intellectual property contained therein is expressly limited to the terms and
# conditions of the License Agreement under which it is provided by or on behalf of Dell Inc. or its subsidiaries.
# Describe
#This script use to collect ECE log from node, if you Failed on create azure cluster step, maybe need to use this to collect
#
# User guide:
# 1.Please Login to primary node
# - if primary node already join AD, please use AD account to login, if not join AD or can not login please use local admin account
# 2.Copy this script to node any path
# 3.Run command ./Anacortes_Day1_ECE_log_collection_tool.ps1 LocalAdminUser LocalAdminPswd AdUser AdPswd
# - please replace LocalAdminUser,LocalAdminPswd,AdUser,AdPswd
# 4.The log zip will be generated in the directory where this script is located
Function Invoke-EceLogCollection{
# Gather creds without showing the Password
$LocalAdminCreds=Get-Credential -UserName (Get-LocalUser | Where-Object { $_.SID -like '*-500' }).name -Message "Please enter the local administrator account credentials."
$LocalAdminUser = $LocalAdminCreds.UserName
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($LocalAdminCreds.Password)
$LocalAdminPswd = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($Ptr)
$LcmCreds=Get-Credential -Message "Please enter the LCM account credentials."
$AdUser = $LcmCreds.UserName
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($LcmCreds.Password)
$AdPswd = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($Ptr)
Invoke-RunEceLogCollection $LocalAdminUser $LocalAdminPswd $AdUser $AdPswd
}
Function Invoke-RunEceLogCollection {
function copyFile(){
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true, Position=0, HelpMessage="Nodecredential")]
[System.Management.Automation.PSCredential]
$Nodecredential,
[Parameter(Mandatory=$true, Position=1, HelpMessage="ADcredential")]
[System.Management.Automation.PSCredential]
$ADcredential,
[Parameter(Mandatory=$true, Position=2, HelpMessage="node ip")]
[String]
$IP,
[Parameter(Mandatory=$true, Position=3, HelpMessage="file path")]
[String]
$Path,
[Parameter(Mandatory=$true, Position=4, HelpMessage="destination file path")]
[String]
$DestinationFile
)
New-Item -ItemType Directory -Path $DestinationFile -Force
try {
#use ad credential
if ($ADcredential){
Write-Host "use provided AD credential to copy file"
Copy-Item -Path "\\$IP\$Path" -Destination $DestinationFile -Credential $ADcredential
}else{
Write-Host "use current logined account to copy file"
Copy-Item -Path "\\$IP\$Path" -Destination $DestinationFile -Recurse
}
} catch {
#use node credential
try {
if ($Nodecredential){
Write-Host "use AD account fail, use provided node credential copy file"
Copy-Item -Path "\\$IP\$Path" -Destination $DestinationFile -Credential $Nodecredential
}else{
Write-Host "use AD account fail, use current logined account to copy file"
Copy-Item -Path "\\$IP\$Path" -Destination $DestinationFile -Recurse
}
} catch {
Write-Host "use Node account fail, use logined account"
Copy-Item -Path "\\$IP\$Path" -Destination $DestinationFile -Recurse
}
}
}
#node credential
if ($LocalAdminUser -and $LocalAdminPswd){
$securePassword = ConvertTo-SecureString -String $LocalAdminPswd -AsPlainText -Force
$Nodecredential = New-Object System.Management.Automation.PSCredential ($LocalAdminUser, $securePassword)
}else{
$Nodecredential = $null
}
#AD credential
if ($AdUser -and $AdPswd){
$securePassword = ConvertTo-SecureString -String $AdPswd -AsPlainText -Force
$ADcredential = New-Object System.Management.Automation.PSCredential ($AdUser, $securePassword)
}else{
$ADcredential = $null
}
# this script directory
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Path
#root folder name
$timestamp = Get-Date -Format "yyyy-MM-dd.HH-mm-ss"
$LogsRootDirectory = $scriptDirectory + "\ECELogs" + $timestamp
Write-Host "Log folder: $LogsRootDirectory"
# use ece payload to get node ip
$ecePayloadFile = "C:\config.json"
if(-not (Test-Path $ecePayloadFile)){
#day1 post node clean will remove C:\config.json, so get node ip from this path
$ecePayloadFile = "C:\CloudDeployment\DeploymentData\Unattended.json"
}
if(Test-Path $ecePayloadFile){
# read ece payload
$jsonContent = Get-Content -Path $ecePayloadFile -Raw | ConvertFrom-Json
# get nodes from ece payload
$nodes = $jsonContent.ScaleUnits[0].DeploymentData.PhysicalNodes
}
$adapter = Get-NetAdapter | Where-Object { $_.Name -like "vManagement*"}
$primaryIpAddress = $adapter | Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.SkipAsSource -eq $false } | Select-Object -ExpandProperty IPAddress
$logFiles = @(
@{
Path = "C:\CloudDeployment\Logs\*"
Name = "C_CloudDeployment_Logs"
OnlyPrimary = $true
},
@{
Path = "C:\CloudDeployment\DeploymentData\*"
Name = "C_CloudDeployment_DeploymentData"
OnlyPrimary = $true
},
@{
Path = "C:\EceStore\*"
Name = "C_EceStore"
OnlyPrimary = $true
},
@{
Path = "C:\MASLogs\*"
Name = "C_MASLogs"
OnlyPrimary = $false
},
@{
Path = "D:\CloudContent\MASLogs\*"
Name = "D_CloudContent_MASLogs"
OnlyPrimary = $false
},
@{
Path = "C:\Windows\Tasks\ArcForServers\RegisterArc_*.log"
Name = "C_Windows_Tasks_ArcForServers"
OnlyPrimary = $false
},
@{
Path = "D:\CloudContent\RegisterHCI_*.log"
Name = "D_CloudContent"
OnlyPrimary = $false
},
@{
Path = "D:\CloudContent\ArcForServerInstall_*.txt"
Name = "D_CloudContent"
OnlyPrimary = $false
},
@{
Path = "C:\Windows\Temp\*"
Name = "C_Window_Temp"
OnlyPrimary = $true
},
@{
Path = "C:\Dell\Logs\Lcm\*"
Name = "C_Dell_Logs_Lcm"
OnlyPrimary = $false
},
@{
Path = "C:\Dell\Payload\Log\*"
Name = "C_Dell_Payload_Log"
OnlyPrimary = $false
},
@{
Path = "C:\config.json"
Name = "C_day1payload"
OnlyPrimary = $true
},
@{
Path = "C:\ProgramData\AzureConnectedMachineAgent\Log\*"
Name = "C_ProgramData_AzureConnectedMachineAgent_Log"
OnlyPrimary = $true
},
@{
Path = "C:\ProgramData\GuestConfig\arc_policy_logs\gc_agent.log"
Name = "C_ProgramData_GuestConfig_arc_policy_logs"
OnlyPrimary = $true
},
@{
Path = "C:\ProgramData\GuestConfig\ext_mgr_logs\gc_ext.log"
Name = "C_ProgramData_GuestConfig_ext_mgr_logs"
OnlyPrimary = $true
},
@{
Path = "C:\ProgramData\GuestConfig\extension_logs"
Name = "C_ProgramData_GuestConfig_extension_logs"
OnlyPrimary = $true
}
)
# collect primary node logs
Write-Host "=====================collect log on primary==========================="
Write-Host "collect log on primary, ip: $primaryIpAddress"
foreach ($logFile in $logFiles) {
$logPath = $logFile.Path
$parentPath = Split-Path -Path $logPath -Parent
$destinationFile = $LogsRootDirectory + "\$primaryIpAddress\" + $logFile.Name
Write-Host "collect path from: $logPath to path: $destinationFile"
#\* or \xxxx_*.xxx
if ($logPath -like "*\`*") {
if (Test-Path $parentPath) {
New-Item -ItemType Directory -Path $destinationFile -Force
Copy-item $logPath -Destination $destinationFile -Recurse
}
else {
Write-Host "directory $( $logPath ) not exist"
}
}else{
if (Test-Path $parentPath) {
New-Item -ItemType Directory -Path $destinationFile -Force
Copy-item $logPath -Destination $destinationFile
}
}
}
# collect non-primary node logs
Write-Host "=====================collect log on non-primary==========================="
if($nodes){
foreach ($node in $nodes) {
if ($node.IPv4Address -ne $primaryIpAddress){
$ip = $node.IPv4Address
Write-Host "collect log on non-primary, ip: $ip"
#skip current node(primary node)
foreach ($logFile in $logFiles) {
if ($logFile.OnlyPrimary -eq $false){
$parentPath = Split-Path -Path $logFile.Path -Parent
$destinationFile = $LogsRootDirectory + "\$ip\" + $logFile.Name
$logPath = $logFile.Path
Write-Host "collect path from: $logPath to path: $destinationFile"
$path = $logPath.Replace(":", "$")
#\* or \xxxx_*.xxx
if ($logPath -like "*\`*") {
if (Test-Path $parentPath) {
copyFile $Nodecredential $ADcredential $ip $path $destinationFile
}
else {
Write-Host "directory $( $logPath ) not exist"
}
}else{
if (Test-Path $parentPath) {
copyFile $Nodecredential $ADcredential $ip $path $destinationFile
}
}
}
}
}
}
}else{
Write-Host "can not get nodes ip from C:\config.json"
}
Write-Host "=====================Compress log==========================="
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zipFilePath = "$LogsRootDirectory.zip"
[System.IO.Compression.ZipFile]::CreateFromDirectory($LogsRootDirectory, $zipFilePath)
Write-Host "=====================remove log folder==========================="
Remove-Item -Path $LogsRootDirectory -Force -Recurse
Write-Host "collect finish!"
$ZipFileOutputFullName=(Get-item $zipFilePath).fullname
Write-Host "zip path: $ZipFileOutputFullName"
Return $ZipFileOutputFullName
}