Código de exemplo para monitoramento via Webhook na linguagem Powershell

Há um exemplo abaixo de script para monitoramento simples, pressionando 1 ou 2 para enviar OK ou Failure.

O objetivo deste exemplo é apenas demonstrar como as chamadas devem
ser feitas para o monitoramento, via webhook, criado pela plataforma.

Exemplo:

				
					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)

}
				
			

Há um exemplo abaixo de script para monitoramento simples, pressionando 1 ou 2 para enviar OK ou Failure.

O objetivo deste exemplo é apenas demonstrar como as chamadas devem
ser feitas para o monitoramento, via webhook, criado pela plataforma.

Exemplo:

				
					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)

}
				
			

Experimente agora, grátis!