Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Created November 5, 2020 22:33
Show Gist options
  • Save JohnL4/145ffe1fe272be4095a7623d54e06864 to your computer and use it in GitHub Desktop.
Save JohnL4/145ffe1fe272be4095a7623d54e06864 to your computer and use it in GitHub Desktop.
Create a Grafana annotation via the api in PowerShell
$grafana = "http://yerhost:3000"
$headers = @{ Accept = "application/json"; Authorization = "Bearer yerApiKey" }
# This is how you get your timezone handled properly. Also, this lovely .ToUnixTimeMilliseconds() is just the ticket.
#
$timeEpoch = (new-object DateTimeOffset -ArgumentList $(get-date)).ToUnixTimeMilliseconds()
# Panel id is optional.
#
$createAnnotationReq = @{ dashboardId = 3; panelId = 4; text = "I can haz annotations via api?"; time = $timeEpoch }
Invoke-RestMethod `
-Headers $headers `
-ContentType application/json `
-method post `
-uri ("{0}/api/annotations" -f $grafana) `
-body $(convertto-json $createAnnotationReq -compress)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment