Created
September 18, 2015 06:15
-
-
Save WilliamBerryiii/ca9113053b4f6ef7831c to your computer and use it in GitHub Desktop.
Add an event to the Scriptrock Timeline that includes the company favicon for branding.
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
# A reuseable enum for meduim types | |
Add-Type -TypeDefinition @" | |
public enum EventStatus | |
{ | |
ERROR = 0, | |
WARNING = 1, | |
OK = 2 | |
} | |
"@ | |
# source and applicance configuration | |
$siteUrl = 'http://my.company.com' | |
$appliance = "https://my.scriptrock.com" | |
$apiKey = "api_key" | |
$secretKey = "secret_key" | |
#event variables | |
$eventStatus = [EventStatus]::OK -as [int] | |
$eventType = 'Deployment' | |
$eventAction = 'Deployed' | |
$eventSOurce = 'myhost.company.com' | |
$duration = 10 #minutes | |
$extra = 'These are some notes about the deployment' | |
# get faviocon from corporate website | |
$html = (Invoke-WebRequest -Method GET -Uri $siteUrl -TimeoutSec 300) | |
$favicon = $html.ParsedHtml.GetElementsByTagName('link') | | |
where {$_.rel -eq 'SHORTCUT ICON' } | | |
Select-Object -first 1 | |
$iconUrl = $siteUrl + $favicon.href | |
# setup API access token | |
$token = $apiKey + $secretKey | |
$authToken = 'Token token="' + $token + '"' | |
$headers = @{'Authorization'=$authToken;'Content-Type'='application/json'; 'Accept'='application/json'} | |
# event to post to appliance | |
$body = "{ | |
`"event`": | |
{ | |
`"sub_category`": `"$eventType`", | |
`"action_taken`": `"$eventAction`", | |
`"status`": $eventStatus, | |
`"source`": `"$eventSource`", | |
`"duration`": $duration, | |
`"extra`": `"$extra`", | |
`"icon_url`": `"$iconUrl`" | |
} | |
}" | |
$resource = 'api/v1/events.json' | |
$url = $appliance + $resource | |
Invoke-RestMethod -Method POST -Uri $url -Headers $headers -Body $body -TimeoutSec 300 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment