Below is an example of a script for simple monitoring, pressing 1 or 2 to send OK or Failure.

The purpose of this example is only to demonstrate how calls should be made to the webhook monitoring created by 1P.

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/<Your Company URL>’ `

                -Method POST `

                -Headers $headers `

                -ContentType ‘application/json’ `

                -Body ‘{“client_id”: “<YOUR INFORMATION HERE>”,”client_secret”: “<YOUR INFORMATION HERE>”}’

 

$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”: <YOUR SERVICE ID HERE>, “organization”: “<YOUR ORGANIZATION ID HERE>”}’

  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”: <YOUR SERVICE ID HERE>, “organization”: “<YOUR ORGANIZATION ID HERE>”}’

  Write-Output($FAILURE)

}

Elvenworks Soluções em tecnologia LTDA

Smart Platforms

 

Follow Us

Email: contact@elven.works