Last active
March 31, 2021 07:43
-
-
Save hasokeric/a5aab1a4c981d2445bbfef31438b58bc to your computer and use it in GitHub Desktop.
Epicor Health Check PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ignore SSL | |
if (-not("dummy" -as [type])) { | |
add-type -TypeDefinition @" | |
using System; | |
using System.Net; | |
using System.Net.Security; | |
using System.Security.Cryptography.X509Certificates; | |
public static class Dummy { | |
public static bool ReturnTrue(object sender, | |
X509Certificate certificate, | |
X509Chain chain, | |
SslPolicyErrors sslPolicyErrors) { return true; } | |
public static RemoteCertificateValidationCallback GetDelegate() { | |
return new RemoteCertificateValidationCallback(Dummy.ReturnTrue); | |
} | |
} | |
"@ | |
} | |
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate() | |
Enum TaskStatus { | |
Submitted = 0 | |
Running = 1 | |
Completed = 2 | |
Error = 3 | |
} | |
[int]$maxTimeout = 30 # Timeout | |
[int]$sleepSeconds = 10 # How long to wait between check cycles | |
$userName = 'manager' | |
$password = 'manager' | |
$authInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $userName, $password))) | |
$headers = @{Authorization=("Basic {0}" -f $authInfo)} | |
$url = 'https://YOURAPPSERVER/E10_Demo1/api/v1/Ice.BO.HealthCheckSvc' | |
$contentType = 'application/json' | |
$companyParameter = '{ "companyID": "" }' | |
Write-Host 'Checking App Server...' | |
try { | |
$result = Invoke-RestMethod -Uri ('{0}/ErpAlive' -f $url) -Headers $headers -Method Post | |
Write-Host 'ERP Alive' | |
} | |
catch { | |
Write-Warning 'ERP Dead' | |
} | |
Write-Host 'Checking Database...' | |
try { | |
$result = Invoke-RestMethod -Uri ('{0}/DatabaseAlive' -f $url) -Headers $headers -Method Post | |
if ($result) { | |
Write-Host ('Database Response {0}ms' -f $result.returnObj) | |
} | |
} | |
catch { | |
Write-Warning 'Database Dead' | |
} | |
Write-Host 'Checking Report Server...' | |
try { | |
$result = Invoke-RestMethod -Uri ('{0}/ReportServerAlive' -f $url) -Headers $headers -Method Post | |
Write-Host 'Report Server Alive' | |
} | |
catch { | |
Write-Warning 'Report Server Dead' | |
} | |
function GetTaskStatus([string]$type) | |
{ | |
Write-Host ('Checking {0} Task...' -f $type) | |
$submitReturnObj = Invoke-RestMethod -Uri ('{0}/Start{1}' -f $url, $type) -Headers $headers -Method Post -Body $companyParameter -ContentType $contentType | |
[TaskStatus]$status = [TaskStatus]::Submitted | |
Start-Sleep -Seconds 5 | |
$maxAttempts = $maxTimeout / $sleepSeconds | |
for ($i = 0; $i -lt $maxAttempts; $i++) | |
{ | |
$statusReturnObj = Invoke-RestMethod -Uri ('{0}/{1}Status' -f $url, $type) -Headers $headers -Method Post -Body $submitReturnObj.returnObj -ContentType $contentType | |
$status = ConvertFrom-Json $statusReturnObj.returnObj | |
if ($status -eq [TaskStatus]::Completed -or | |
$status -eq [TaskStatus]::Error) { | |
break | |
} | |
Start-Sleep $sleepSeconds | |
} | |
Write-Host ('{0} Result: {1}' -f $type, $status) | |
} | |
GetTaskStatus -type Process | |
GetTaskStatus -type Print |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment