-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartWiperOnCameras.ps1
101 lines (83 loc) · 3.92 KB
/
StartWiperOnCameras.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
###########################################################################
### ###
### PowerShell Script that uses REST API ###
### This script sends WIPE cmd to cameras in a list ###
### The 6 variables below are customer specific ###### ##############################################################################
$camerasWithWiper = 30, 39, 47 # Comma seperated list of cameras to wipe
$mstrRestHost = "Servername" # Server name or IP address with REST API
$mstrUserName = "" # Username
$mstrPassword = "" # Password
$tcp = "444" # Port for REST API
$mstrRestProtocol = "HTTPS" # Secure: HTTPS or unsecure: HTTP
###########################################################################
### ###
### End of customer specific variables ###### ##############################################################################
#User and Password handling
$mstrAuthInfo = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$mstrUserName`:$mstrPassword"))
$mstrRestHeaders = @{"X-Requested-With"="powershell";"Authorization"="Basic $mstrAuthInfo"}
#Send REST call
function RestCall($method, $path, $JSON, $expectedCode, $expectedDescription)
{
Start-Sleep -m 200
Try
{
$strUrl = $mstrRestProtocol + "://" + $mstrRestHost + ":" + $tcp + $path
Write-Host $method $strUrl $JSON -ForegroundColor yellow
$result = Invoke-RestMethod -Method $method -Uri $strUrl -headers $mstrRestHeaders -body $JSON -ContentType 'application/json' -ErrorVariable RestError -ErrorAction SilentlyContinue
return $result
}
Catch
{
Write-Host $_
$count = 0
#StatusCode
if($expectedCode -eq $_.Exception.Response.StatusCode.value__)
{
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ -ForegroundColor cyan
$count ++
}
else {Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ -ForegroundColor red}
#StatusDescription
if($expectedDescription -eq $_.Exception.Response.StatusDescription)
{
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription -ForegroundColor cyan
$count ++
}
else {Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription -ForegroundColor red}
#StatusCode or StatusDescription are not as expected
If($count -ne 2)
{
Write-Host "Exception:" $_.Exception -ForegroundColor red
}
}
return 1
}
#Handle the respnse from REST API
function ResultHandling($valueReturned)
{
if($valueReturned -ne "1")
{
Write-Host "Response:`n"($valueReturned | Format-List | Out-String) "`n" -ForegroundColor green
}
else
{
Write-Host
}
}
#############################################################
### Rest API CMDs ###
#############################################################
#Status
ResultHandling(RestCall "OPTIONS" "/status")
#Start Wipe foreach camera in the comma separated list of cameras
foreach($camera in $camerasWithWiper)
{
ResultHandling(RestCall "PUT" "/inputs/$camera/Wipe")
}
#############################################################
### End ofRest API CMDs ###
#############################################################