-
Notifications
You must be signed in to change notification settings - Fork 0
/
ziro-export-avaya.ps1
378 lines (297 loc) · 12.7 KB
/
ziro-export-avaya.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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#Requires -Version 7.0
#Requires -Modules Posh-SSH
function Wait-UntilTerminalIsReady {
param (
[Renci.SshNet.ShellStream]$ShellStream
)
$retry = 0
$streamOut = $ShellStream.Read()
# Wait until we can select terminal type and choose ossi
while (-Not ($streamOut).Contains("Terminal Type") -and $retry -le 10) {
Start-Sleep -s 1
$streamOut = $ShellStream.Read()
$retry++
}
if ($retry -gt 10) {
throw "Timed out whie initializing waiting for terminal type prompt"
}
$retry = 0
$ShellStream.WriteLine('ossi')
# Read until stream is empty before starting to send commands
while (($streamOut).length -ne 0 -and $retry -le 10) {
Start-Sleep -s 1
$streamOut = $ShellStream.Read()
}
if ($retry -gt 10) {
throw "Timed out whie initializing OSSI terminal"
}
}
function Write-CommandsToSshStream {
param (
[string[]]$Commands,
[Renci.SshNet.ShellStream]$ShellStream
)
$retry = 0
foreach ($Command in $Commands) {
$ShellStream.WriteLine($Command)
}
$ShellStream.WriteLine('t')
$streamOut = $ShellStream.Read()
while (($streamOut).length -eq 0 -and $retry -le 10) {
Start-Sleep -s 1
$streamOut = $ShellStream.Read()
$retry++
}
return $streamOut
}
function Get-AvayaSubEntities {
param (
$EntitiesId,
[string]$EntitiesName,
[string[]]$Commands,
[Renci.SshNet.ShellStream]$ShellStream
)
$progressCount = 0
foreach ($EntityId in $EntitiesId) {
# Remove the trailing d in all the Avaya ids
$EntityId = $EntityId.substring(1)
foreach ($Command in $Commands) {
Write-AyavaOutPutToFile "$Command $EntityId" $ShellStream
}
$progressCount++
Write-Progress -activity "Getting $EntitiesName information..." -status "Fetched: $progressCount of $($EntitiesId.Count)" -percentComplete (($progressCount / $EntitiesId.Count) * 100)
}
}
function Write-AyavaOutPutToFile {
param (
[string[]]$Commands,
[Renci.SshNet.ShellStream]$ShellStream
)
$retry = 0
$commandOutput = Write-CommandsToSshStream $Commands $ShellStream
while (([string]::IsNullOrEmpty($commandOutput) -or ($commandOutput).Contains('Terminator received but no command active')) -and $retry -le 5) {
Start-Sleep -s 1
$commandOutput = Write-CommandsToSshStream $Commands $ShellStream
$retry++
}
if ($retry -gt 5) {
Write-Warning "Failed to get result for commands $Commands"
}
Add-Content -Path "output-avaya/avaya.txt" -Value $commandOutput
}
function Write-AyavaOutPutToFileAndGetEntities {
param (
[string[]]$Commands,
[Renci.SshNet.ShellStream]$ShellStream
)
$retry = 0
$commandOutput = Write-CommandsToSshStream $Commands $ShellStream
while (([string]::IsNullOrEmpty($commandOutput) -or ($commandOutput).Contains('Terminator received but no command active')) -and $retry -le 5) {
Start-Sleep -s 1
$commandOutput = Write-CommandsToSshStream $Commands $ShellStream
$retry++
}
if ($retry -gt 5) {
Write-Warning "Failed to get result for commands $Commands"
}
Add-Content -Path "output-avaya/avaya.txt" -Value $commandOutput
return $commandOutput.Split("`n") | Where-Object { $_.Trim("") -and $Commands -notcontains $_ -and $_ -ne 'n' -and $_ -ne 't' }
}
function Write-EntitiesProgressToHost {
param (
[Int]$PbxProgressCount
)
Write-Progress -activity "Gathering PBX information..." -status "Fetched: $PbxProgressCount of 42" -percentComplete (($PbxProgressCount / 42) * 100)
}
function Get-CdrInformation {
param (
[string]$ServerUrl,
[string]$Date
)
$sftpSession = $null;
try {
$answer = Read-Host "Do you want to also export CDRs information? [y/N]? "
if ($answer -eq 'y') {
New-Item -Name "avaya_cdr" -ItemType Directory -Force | Out-Null
$credential = Get-Credential -Message 'Enter CDR username and password'
$sftpSession = New-SFTPSession -ComputerName $ServerUrl -Credential $credential -AcceptKey
Write-Output "Downloading CDRs..."
Get-SFTPItem -SFTPSession $sftpSession -Path "/var/home/ftp/CDR/" -Destination "avaya_cdr/" -Force -SkipSymLink
$ZipFileName = "avaya_" + $date + "_cdr.zip"
Compress-Archive -Path avaya_cdr/* -DestinationPath $ZipFileName -Force
Remove-Item -Path avaya_cdr -Recurse -Force
}
else {
Write-Output "Skipping CDRs export..."
}
}
finally {
if ($null -ne $sftpSession) {
Remove-SftpSession -SFTPSession $sftpSession | Out-Null
}
}
}
$sshsession = $null;
$stream = $null;
try {
$serverUrl = Read-Host 'Avaya FQDN or IP Address (avayacm.mycompany.com)'
$credential = Get-Credential -Message 'Enter administrator username and password'
$date = (Get-Date -Format "dd-MM-yyyy_HH-mm-ss").ToString()
New-Item -Name "output-avaya" -ItemType Directory -Force | Out-Null
New-Item -ItemType File -Name "output-avaya/avaya.txt" -Force | Out-Null
Get-CdrInformation $serverUrl $date
$sshsession = New-SSHSession -ComputerName $serverurl -Credential $credential -Port 5022 -AcceptKey
$stream = New-SSHShellStream -SSHSession $sshsession
Wait-UntilTerminalIsReady $stream
$pbxProgressCount = 0
Write-AyavaOutPutToFile 'cdisplay system-parameters cdr' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist hunt-group' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist pickup-group' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay alias station' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay tenant 1' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 1' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 2' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 3' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 4' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 5' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 6' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 7' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 8' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 9' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay coverage remote 10' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay feature-access-codes' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist coverage path' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay ip-network-map' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'cdisplay capacity' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist user-profiles' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist route-pattern' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist integrated-annc-boards' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist ars analysis' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist media-gateway' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist public-unknown-numbering' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist off-pbx-telephone station-mapping' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist intercom-group' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist abbreviated-dialing personal' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist station' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist trunk-group' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist vector' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist vdn' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist ip-network-region monitor' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Write-AyavaOutPutToFile 'clist announcement' $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$extensionIds = Write-AyavaOutPutToFileAndGetEntities @('clist station', 'f8005ff00') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$corIds = Write-AyavaOutPutToFileAndGetEntities @('clist station', 'f8001ff00') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$cosIds = Write-AyavaOutPutToFileAndGetEntities @('clist station', 'f8002ff00') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$trunkGroupIds = Write-AyavaOutPutToFileAndGetEntities @('clist trunk-group', 'f800bff00') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$vectorIds = Write-AyavaOutPutToFileAndGetEntities @('clist vector', 'f0001ff01') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$vdnIds = Write-AyavaOutPutToFileAndGetEntities @('clist vdn', 'f8005ff01') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$ipNetworkRegionMonitorIds = Write-AyavaOutPutToFileAndGetEntities @('clist ip-network-region monitor', 'f6c00ff00') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
$announcementIds = Write-AyavaOutPutToFileAndGetEntities @('clist announcement', 'f8005ff00') $stream
$pbxProgressCount++
Write-EntitiesProgressToHost $pbxProgressCount
Get-AvayaSubEntities $extensionIds 'Extensions' @('cdisplay station', 'clist bridged-extensions', 'cdisplay button-labels') $stream
Get-AvayaSubEntities $corIds 'CORs' 'cdisplay cor' $stream
Get-AvayaSubEntities $cosIds 'COSs' 'cdisplay cos' $stream
Get-AvayaSubEntities $trunkGroupIds 'Trunk Groups' @('cdisplay trunk-group', 'cdisplay inc-call-handling-trmt trunk-group') $stream
Get-AvayaSubEntities $vectorIds 'Vectors' 'cdisplay vector' $stream
Get-AvayaSubEntities $vdnIds 'VDNs' 'cdisplay vdn' $stream
Get-AvayaSubEntities $ipNetworkRegionMonitorIds 'IP Network Regions' 'cstatus ip-network-region' $stream
Get-AvayaSubEntities $announcementIds 'Announcements' 'cdisplay announcement' $stream
Write-AyavaOutPutToFile "clogoff" $stream
$ZipFileName = "avaya_" + $date + ".zip"
Compress-Archive -Path output-avaya/* -DestinationPath $ZipFileName -Force
Remove-Item -Path output-avaya -Recurse -Force
Write-Host "The script ran successfully" -ForegroundColor Green
exit 0
}
catch {
Write-host -f red "Encountered Error:"$_.Exception.Message
Write-Error "Avaya information export failed"
exit 1
}
finally {
if ($null -ne $sshsession) {
Remove-SSHSession -SSHSession $sshsession | Out-Null
}
}