-
Notifications
You must be signed in to change notification settings - Fork 1
/
AppServicesLogCollector.ps1
141 lines (114 loc) · 7.05 KB
/
AppServicesLogCollector.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
$collectionScript = {
$node = $env:computername
$nodename = $using:server
Write-Host -ForegroundColor White "******************************************************************************************************"
Write-Host -ForegroundColor White " Starting log collection on" $node "(" $nodename ")"
Write-Host -ForegroundColor White "******************************************************************************************************"
$DataCollectionDir = "c:\temp\CSS_AppServiceLogs"
$sharename = "CSS"
#Logs to collect
$CollectGuestLogsPath = "C:\WindowsAzure\GuestAgent*\"
$CollectGuestLogsPath2 = "C:\WindowsAzure\Packages\"
$httplogdirectory = "C:\DWASFiles\Log\"
$ftpLogDirectory = "C:\inetpub\logs\LogFiles\"
$WebsitesInstalldir = "C:\WebsitesInstall\"
$windowsEventLogdir = "C:\Windows\System32\winevt\Logs"
$webPILogdir = "C:\Program Files\IIS\Microsoft Web farm framework\roles\resources\antareslogs"
$packagesdir = "C:\Packages"
#Remove CSS_AppServiceLogs directory if already exists
if (test-path -Path $DataCollectionDir -PathType Any){
Remove-Item -Path $DataCollectionDir -Recurse -Force -Confirm:$false | Out-Null
}
#Create CSS_AppServiceLogs directory
New-Item -path $DataCollectionDir -ItemType Directory -Force | out-null
#Create CSS share
#Get-SmbShare -name $sharename | Remove-SmbShare -Confirm:$false -Force -ErrorAction SilentlyContinue | Out-Null
New-SmbShare -Name $sharename -Path $DataCollectionDir -FullAccess "$env:UserDomain\$env:UserName" | Out-Null
#Starting CollectGuestLogs
Write-host "Collect Guest Logs started on" $node -ForegroundColor Green
if (test-path -Path $CollectGuestLogsPath -PathType Any){
start-process "$CollectGuestLogsPath\CollectGuestLogs.exe" -Verb runAs -WorkingDirectory $CollectGuestLogsPath -wait ;
Move-Item $CollectGuestLogsPath\*.zip -Destination $DataCollectionDir\ -Force
Move-Item $CollectGuestLogsPath\*.zip.json -Destination $DataCollectionDir\ -Force
Dir $DataCollectionDir\*.zip.json | rename-item -newname { $_.name -replace ".zip.json",".json" }
}
elseif(test-path -Path $CollectGuestLogsPath2 -PathType Any){
start-process "$CollectGuestLogsPath2\CollectGuestLogs.exe" -Verb runAs -WorkingDirectory $CollectGuestLogsPath2 -wait ;
Move-Item $CollectGuestLogsPath2\*.zip -Destination $DataCollectionDir\ -Force
Move-Item $CollectGuestLogsPath2\*.zip.json -Destination $DataCollectionDir\ -Force
Dir $DataCollectionDir\*.zip.json | rename-item -newname { $_.name -replace ".zip.json",".json" }
}
Write-host "Collect Guest Logs completed on" $node -ForegroundColor Green
if ($node -notlike "CN*"){
#Collecting IIS logs
Write-host "Collect IIS logs started on" $node -ForegroundColor Yellow
Copy-Item $httplogdirectory\ -Recurse -Destination $DataCollectionDir\HTTPLogs -Force
Write-host "Collect IIS logs completed on" $node -ForegroundColor Yellow
#Collecting WFF logs
Write-host "Collect WFF logs started on" $node -ForegroundColor Green
Copy-Item $webPILogdir\ -Recurse -Destination $DataCollectionDir\
Write-host "Collect WFF logs completed on" $node -ForegroundColor Green
}
#Collect FTP logs on Publisher servers
if ($node -like "FTP*"){
#Collecting FTP logs
Write-host "Collect FTP logs started on" $node -ForegroundColor Yellow
Copy-Item $ftpLogDirectory\ -Recurse -Destination $DataCollectionDir\FTPLogs -Force
Write-host "Collect FTP logs completed on" $node -ForegroundColor Yellow
}
#Collecting Event logs
Write-host "Collect Event logs started on" $node -ForegroundColor Yellow
Copy-Item $windowsEventLogdir\Microsoft-Windows-WebSites%4Administrative.evtx -Destination $DataCollectionDir\
Copy-Item $windowsEventLogdir\Microsoft-Windows-WebSites%4Operational.evtx -Destination $DataCollectionDir\
Copy-Item $windowsEventLogdir\Microsoft-Windows-WebSites%4Verbose.evtx -Destination $DataCollectionDir\
Write-host "Collect Event logs completed on" $node -ForegroundColor Yellow
#Collecting WebsitesInstall logs
Write-host "Collect WebsitesInstall logs started on" $node -ForegroundColor Green
Copy-Item $WebsitesInstalldir\ -Recurse -Destination $DataCollectionDir\
Write-host "Collect WebsitesInstall logs completed on" $node -ForegroundColor Green
#Collecting C:\Packages
Write-host "Collect C:\Packages started on" $node -ForegroundColor Yellow
Copy-Item $packagesdir\ -Recurse -Destination $DataCollectionDir\
Write-host "Collect C:\Packages completed on" $node -ForegroundColor Yellow
write-host "Compressing Files" -ForegroundColor Green
Compress-Archive -Path $DataCollectionDir\* -DestinationPath $DataCollectionDir\$nodename.$env:computername.zip -Force
Get-ChildItem -Path $DataCollectionDir\ -Recurse | Where-Object {$_.Name -notlike "*$nodename.*"} | Remove-Item -Recurse -Force -Confirm:$false
}
$cleanupScript = {
Write-Host -ForegroundColor Yellow "Starting log cleanup on" $env:computername
$DataCollectionDir = "c:\temp\CSS_AppServiceLogs"
$sharename = "CSS"
#Remove CSS share
Get-SmbShare -name $sharename | Remove-SmbShare -Confirm:$false -Force -ErrorAction SilentlyContinue | Out-Null
#Remove CSS_AppServiceLogs directory if already exists
if (test-path -Path $DataCollectionDir -PathType Any){
Remove-Item -Path $DataCollectionDir -Recurse -Force -Confirm:$false | Out-Null
}
}
$logDirectory = "c:\temp\CSS"
if (test-path -Path $logDirectory -PathType Any){
Remove-Item -Path $logDirectory -Recurse -Force -Confirm:$false | Out-Null
}
New-Item -path $logDirectory -ItemType Directory -Force | out-null
$workerCred = Get-Credential -Message "Enter credentials for Worker Admin"
Get-AppServiceServer | select Name, Status, Role, CpuPercentage, MemoryPercentage, ServerState, PlatformVersion | ft > $logDirectory"\Get-AppServiceServer.txt"
Get-AppServiceServer | ConvertTo-Json | Out-File $logDirectory"\AppServiceServer.json"
Get-AppServiceEvent | ConvertTo-Json | Out-File $logDirectory"\AppServiceEvent.json"
$roleServers = Get-AppServiceServer | Select -ExpandProperty Name
foreach ($server in $roleServers) {
$serverRole = Get-AppServiceServer | Where-Object {$_.Name -eq $server} | Select -ExpandProperty Role
if($serverRole -eq "WebWorker")
{
$workerSession = New-PSSession -Credential $workerCred -ComputerName $server
Invoke-Command -Session $workerSession -ScriptBlock $collectionScript
Copy-Item -FromSession $workerSession -Path c:\temp\CSS_AppServiceLogs\*.zip -Destination $logDirectory -Verbose
Invoke-Command -Session $workerSession -ScriptBlock $cleanupScript
Remove-PSSession $workerSession
}
else
{
Invoke-Command -ComputerName $server -ScriptBlock $collectionScript
Copy-Item \\$server\CSS\* -Destination $logDirectory -Verbose
Invoke-Command -ComputerName $server -ScriptBlock $cleanupScript
}
}