Created
November 5, 2020 22:33
-
-
Save JohnL4/145ffe1fe272be4095a7623d54e06864 to your computer and use it in GitHub Desktop.
Create a Grafana annotation via the api in PowerShell
This file contains hidden or 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
$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