-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployment-monitor.ps1
67 lines (59 loc) · 1.69 KB
/
deployment-monitor.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
param (
[Parameter(Mandatory = $true)]
[string] $Url,
[int]
$Delay = 10,
[int]
$Count = 99999,
[int]
$TimeoutValue = 99999
)
$ErrorActionPreference = "Stop"
$previous = {}
$previousVersion = Get-Date
$message = "Starting"
$machineName = "Unknown"
For ($i = 0; $i -lt $Count; $i++) {
$progressTime = (Get-Date) - $previousVersion
Write-Progress -Activity $message -Status "$machineName, $Delay ms" -SecondsRemaining $progressTime.TotalSeconds
$startTime = Get-Date
try {
$response = Invoke-RestMethod -Method GET -Uri $Url -DisableKeepAlive -TimeoutSec 1
$machineName = $response.machineName
if ($response.content -ne $previous.content) {
"$($startTime): $($startTime - $previousVersion)"
$response
$previous = $response
$previousVersion = Get-Date
$message = "Online"
}
}
catch {
if ([string]::IsNullOrWhiteSpace($previous.content) -eq $false) {
"$($startTime): $($startTime - $previousVersion) -> Offline"
$previous = {}
$previousVersion = Get-Date
$message = "Offline"
}
}
if ([Console]::KeyAvailable) {
$pressedKey = [Console]::ReadKey($true)
$change = $Delay * 0.1
if ($change -lt 1) {
$change = 1
}
switch ($pressedKey.Key) {
UpArrow {
$Delay += $change
}
DownArrow {
$Delay -= $change
if (0 -gt $Delay) {
$Delay = 0
}
}
Default {}
}
}
Start-Sleep -Milliseconds $Delay
}