/
Network-Insight-Install.ps1
294 lines (253 loc) · 12 KB
/
Network-Insight-Install.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
282
283
284
285
286
287
288
289
290
291
292
293
294
param (
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$VI_Server,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Platform_OVA,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Proxy_OVA,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$License,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Platform_VM_Name,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Proxy_VM_Name,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$TargetVMHost,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$TargetDatastore,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$TargetPortGroup,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Platform_IP,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Proxy_IP,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Netmask,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Gateway,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$DNS,
[parameter(Mandatory=$true, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Domain,
[parameter(Mandatory=$false, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$NTP,
[parameter(Mandatory=$false, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Web_Proxy_IP,
[parameter(Mandatory=$false, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Web_Proxy_Port,
[parameter(Mandatory=$false, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[string]$Syslog,
[parameter(Mandatory=$false, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[switch]$Telemetry,
[parameter(Mandatory=$false, ValueFromPipeLine=$true, ValueFromPipeLineByPropertyName=$true)]
[ValidateNotNullOrEmpty()]
[switch]$Log_Push
)
# Load PowerCLI
if (!(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
if (Test-Path -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VMware, Inc.\VMware vSphere PowerCLI' ) {
$Regkey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\VMware, Inc.\VMware vSphere PowerCLI'
}
else {
$Regkey = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMware vSphere PowerCLI'
}
.(join-path -path (Get-ItemProperty $Regkey).InstallPath -childpath 'Scripts\Initialize-PowerCLIEnvironment.ps1')
}
if (!(Get-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue)) {
Write-Host "VMware modules not loaded/unable to load"
Exit
}
if (!(Test-Path $Platform_OVA)) {
Write-Host "[$(Get-Date)] Network Insight Plaform OVA not found! ($Platform_OVA)" -ForegroundColor "red"
Exit
}
if (!(Test-Path $Proxy_OVA)) {
Write-Host "[$(Get-Date)] Network Insight Proxt OVA not found! ($Proxy_OVA)" -ForegroundColor "red"
Exit
}
# Ignore SSL certificate errors
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
function loginNetworkInsight([string]$Platform_VM_IP)
{
$POST_Data = @{
username = 'admin@local'
password = 'admin'
}
$json = $POST_Data | ConvertTo-Json
try {
$response = Invoke-RestMethod "https://$Platform_VM_IP/api/auth/login" -Method POST -Body $json -ContentType 'application/json' -SessionVariable webSessionJar
$global:webSessionJar = $webSessionJar
}
catch
{
if($_.Exception.Response.StatusCode.value__ -ne 200) {
Write-Host "[$(Get-Date)] Platform VM still initializing, sleeping for 30 seconds and trying again.." -ForegroundColor "yellow"
Start-Sleep -s 30
loginNetworkInsight $Platform_VM_IP
}
else
{
if($response.message -ne "Logged in") {
Write-Host "[$(Get-Date)] Unable to login with default credentials!" -ForegroundColor "red"
Exit
}
}
}
}
function validateLicense([string]$Platform_VM_IP, [string]$License)
{
$POST_Data = @{
licenseKey = $License
}
$json = $POST_Data | ConvertTo-Json
try {
$response = Invoke-RestMethod "https://$Platform_VM_IP/api/management/licensing/validate" -Method POST -Body $json -ContentType 'application/json' -WebSession $global:webSessionJar
}
catch
{
if($_.Exception.Response.StatusCode.value__ -ne 200) {
Write-Host "[$(Get-Date)] Platform VM still initializing, sleeping for 30 seconds and trying again.." -ForegroundColor "yellow"
Start-Sleep -s 30
validateLicense $Platform_VM_IP $License
}
}
if($response.message -eq "License key is OK") {
$sockets = $response.data.numberOfSockets
Write-Host "[$(Get-Date)] License validated for $sockets sockets!" -ForegroundColor "green"
}
}
function activateLicense([string]$Platform_VM_IP, [string]$License)
{
$POST_Data = @{
licenseKey = $License
}
$json = $POST_Data | ConvertTo-Json
try {
$response = Invoke-RestMethod "https://$Platform_VM_IP/api/management/licensing/activate" -Method POST -Body $json -ContentType 'application/json' -WebSession $global:webSessionJar
}
catch
{
if($_.Exception.Response.StatusCode.value__ -ne 200)
{
Write-Host "[$(Get-Date)] Activating the license failed!" -ForegroundColor "red"
if($Debug.IsPresent) { $_.Exception.Response }
Exit
}
}
if($response.message -eq "License applied") {
Write-Host "[$(Get-Date)] License activated!" -ForegroundColor "green"
}
}
function generateSharedSecret([string]$Platform_VM_IP)
{
try {
$response = Invoke-RestMethod "https://$Platform_VM_IP/api/management/nodes" -Method POST -ContentType 'application/json' -WebSession $global:webSessionJar
}
catch
{
if($_.Exception.Response.StatusCode.value__ -ne 200) {
Write-Host "[$(Get-Date)] Generating the Shared Secret failed!" -ForegroundColor "red"
if($Debug.IsPresent) { $_.Exception.Response }
Exit
}
}
if($response.message -eq "Proxy Key Generated") {
$shared_secret = $response.data
Write-Host "[$(Get-Date)] Proxy Shared Secret generated!" -ForegroundColor "green"
}
return $shared_secret
}
if(!(Connect-VIServer -Server $VI_Server)) {
Write-Host "Unable to connect to vCenter!" -ForegroundColor "red"
Exit
}
## Get the OVF configuration and fill the parameters
$OvfConfiguration = Get-OvfConfiguration -Ovf $Platform_OVA
$OvfConfiguration.Common.IP_Address.value = $Platform_IP
$OvfConfiguration.Common.Netmask.value = $Netmask
$OvfConfiguration.Common.Default_Gateway.value = $Gateway
$OvfConfiguration.Common.DNS.value = $DNS
$OvfConfiguration.Common.Domain_Search.value = $Domain
$OvfConfiguration.Common.NTP.value = $NTP
$OvfConfiguration.Common.Web_Proxy_IP.value = $Web_Proxy_IP
$OvfConfiguration.Common.Web_Proxy_Port.value = $Web_Proxy_Port
$OvfConfiguration.Common.Rsyslog_IP.value = $Syslog
$OvfConfiguration.NetworkMapping.Vlan256_corp_2.value = (Get-VDPortgroup -Name $TargetPortGroup)
if($Log_Push.IsPresent) { $OvfConfiguration.Common.Log_Push.value = $True }
else { $OvfConfiguration.Common.Log_Push.value = $False }
if($Telemetry.IsPresent) { $OvfConfiguration.Common.Health_Telemetry_Push.value = $True }
else { $OvfConfiguration.Common.Health_Telemetry_Push.value = $False }
# Deploy the OVA.
Write-Host "[$(Get-Date)] Deploying vRealize Network Insight Platform OVA"
Write-Progress -Activity "Deploying vRealize Network Insight Platform OVA"
$VM = Import-vApp -Source $Platform_OVA -OvfConfiguration $OvfConfiguration -Name $Platform_VM_Name -VMHost $TargetVMHost -Datastore $TargetDatastore -DiskStorageFormat Thin
# Testlab edition: change vHW & strip reservations from VM
#$tmp = ($VM | Set-VM -NumCpu 4 -Confirm:$false)
#$tmp = ($VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemReservationMB 0 -Confirm:$false)
#$tmp = ($VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuReservationMhz 0 -Confirm:$false)
Write-Host "[$(Get-Date)] Starting vRealize Network Insight Platform"
Write-Progress -Activity "Starting vRealize Network Insight Platform"
$VM | Start-VM
Write-Host "[$(Get-Date)] vRealize Network Insight Platform VM has been deployed and started!" -ForegroundColor "green"
Write-Host "[$(Get-Date)] This script is now going to wait until the Platform VM has initialized, insert the license and generate a shared secret for the Proxy VM. All this is tested on 3.2 and uses UNSUPPORTED APIs, so any other version may break."
# Before bugging the Platform VM, give it 2 minutes for the initial boot
Sleep -s 120
# Login to UI first to get authenticated, the license activation and shared secret generating appear to require authentication
Write-Host "[$(Get-Date)] Logging into Network Insight.."
loginNetworkInsight $Platform_IP
Write-Host "[$(Get-Date)] Validating license.."
validateLicense $Platform_IP $License
Write-Host "[$(Get-Date)] Activating license.."
activateLicense $Platform_IP $License
Write-Host "[$(Get-Date)] Generating Shared Secret.."
$Shared_Secret = generateSharedSecret $Platform_IP
Write-Host "[$(Get-Date)] Deploying Proxy VM.."
## Get the OVF configuration and fill the parameters
$OvfConfiguration = Get-OvfConfiguration -Ovf $Proxy_OVA
$OvfConfiguration.Common.Proxy_Shared_Secret.value = $Shared_Secret
$OvfConfiguration.Common.IP_Address.value = $Proxy_IP
$OvfConfiguration.Common.Netmask.value = $Netmask
$OvfConfiguration.Common.Default_Gateway.value = $Gateway
$OvfConfiguration.Common.DNS.value = $DNS
$OvfConfiguration.Common.Domain_Search.value = $Domain
$OvfConfiguration.Common.NTP.value = $NTP
$OvfConfiguration.Common.Web_Proxy_IP.value = $Web_Proxy_IP
$OvfConfiguration.Common.Web_Proxy_Port.value = $Web_Proxy_Port
$OvfConfiguration.Common.Rsyslog_IP.value = $Syslog
$OvfConfiguration.NetworkMapping.Vlan256_corp_2.value = (Get-VDPortgroup -Name $TargetPortGroup)
if($Log_Push.IsPresent) { $OvfConfiguration.Common.Log_Push.value = $True }
else { $OvfConfiguration.Common.Log_Push.value = $False }
if($Telemetry.IsPresent) { $OvfConfiguration.Common.Health_Telemetry_Push.value = $True }
else { $OvfConfiguration.Common.Health_Telemetry_Push.value = $False }
# Deploy the OVA.
Write-Host "[$(Get-Date)] Deploying vRealize Network Insight Proxy OVA"
Write-Progress -Activity "Deploying vRealize Network Insight Proxy OVA"
$VM = Import-vApp -Source $Proxy_OVA -OvfConfiguration $OvfConfiguration -Name $Proxy_VM_Name -VMHost $TargetVMHost -Datastore $TargetDatastore -DiskStorageFormat Thin
# Testlab edition: strip reservations from VM
#$tmp = ($VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -MemReservationMB 0 -Confirm:$false)
#$tmp = ($VM | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuReservationMhz 0 -Confirm:$false)
Write-Host "[$(Get-Date)] Starting vRealize Network Insight Proxy"
Write-Progress -Activity "Starting vRealize Network Insight Proxy"
#$VM | Start-VM
Write-Host "[$(Get-Date)] vRealize Network Insight Proxy VM has been deployed and started!" -ForegroundColor "green"
Write-Host "[$(Get-Date)] The deployment should now be complete. Login to the Platform UI and add your data sources." -ForegroundColor "green"