Last active
September 21, 2017 19:40
-
-
Save jdmills-edu/a58af7917d8dee3d2f7d9a98ebb0246a to your computer and use it in GitHub Desktop.
A PowerShell script that adds a data point to a StatusPage.io public metric.
This file contains 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
param( | |
[Parameter(Mandatory=$true)][String]$metric_id, | |
[Parameter(Mandatory=$true)][Float]$datapoint | |
) | |
$api_key = YourStatusPageAPIKey | |
$page_id = YourStatusPagePageID | |
$api_base = 'https://api.statuspage.io/v1' | |
$metricURI = $api_base+"/pages/"+$page_id+"/metrics/"+$metric_id+"/data.json" | |
$headers = @{Authorization = "OAuth "+$api_key} | |
#A good way to get a Unix timestamp. | |
$unixTimestamp = [int][double]::Parse(((Get-Date).ToUniversalTime() | Get-Date -UFormat %s )) | |
#Creating nested hashtables to be converted to the JSON structure StatusPage expects. | |
$params = @{ | |
timestamp = $unixTimestamp | |
value = $datapoint | |
} | |
$data = @{ | |
data = $params | |
} | |
Invoke-RestMethod -Uri $metricURI -Method Post -Headers $headers -ContentType "application/json" -Body ($data | ConvertTo-Json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment