There is an example script below for simple monitoring, pressing 1 or 2 to send OK or Failure.
The purpose of this example is just to demonstrate how calls should be made for monitoring, via webhook, created by the platform.
Example:
Write-Output("FAILURE OR OK?")
Write-Output("TYPE 1 FOR FAILURE")
Write-Output("TYPE 2 FOR OK")
$status = Read-host "SELECT 1 OR 2 "
Write-Output("---","the option to be performed is: ", $status, "---")
$headers=@{}
$headers.Add("content-type", "application/json")
$response = Invoke-WebRequest -Uri 'https://apis.elven.works/external/auth/v1/client/' `
-Method POST `
-Headers $headers `
-ContentType 'application/json' `
-Body '{"client_id": "","client_secret": ""}'
$StatusCode = $Response.StatusCode
Write-Output "Get Token 1P - código resposta: $StatusCode"
$token = ($response.Content | ConvertFrom-Json).access_token
$Date = Get-Date
$headers.Add("authorization", "Bearer $token")
$invoke_headers =@{
authorization = "Bearer $token"
}
$invoke_headers.Add("content-type", "application/json")
if($status -eq 2)
{
Write-Output("HITS")
$HITS = Invoke-WebRequest -Uri 'https://apis.elven.works/external/monitoring/v1/hits' `
-Method POST `
-Headers $invoke_headers `
-ContentType 'application/json' `
-Body '{"latency": 100000, "service": , "organization": ""}'
Write-Output("$HITS")
}
if($status -eq 1)
{
Write-Output("FAILURE")
$FAILURE = Invoke-WebRequest -Uri 'https://apis.elven.works/external/monitoring/v1/failures' `
-Method POST `
-Headers $invoke_headers `
-ContentType 'application/json' `
-Body '{"issue": "ERROR MESSAGE", "service": , "organization": ""}'
Write-Output($FAILURE)
}