Last active
May 17, 2016 10:36
-
-
Save Sam-Martin/171415b80c9fbf728855fb6ccad7e387 to your computer and use it in GitHub Desktop.
Pingdom2HipChat
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
# Get input and output params (as named in our function.json) | |
$result = $Env:res | |
$requestPath = $env:req | |
$executionPath = Split-Path -parent $PSCommandPath | |
$tempPath = Split-Path -parent $env:req | |
# Read the input from file and parse it to an object | |
[Console]::WriteLine("Reading input from $env:req") | |
$requestObj = Get-Content $requestPath | Out-String | ConvertFrom-Json | |
$ColourScheme = @{ | |
"Up" = "green" | |
"Down" = "red" | |
} | |
$params = @{ | |
Uri = "https://you.hipchat.com/v2/room/934419/notification?auth_token=???" | |
Method = "POST" | |
Body = @{ | |
color = $ColourScheme.$($requestObj.current_state) | |
message = "Check: '$($RequestObj.check_name)' is now $($RequestObj.current_state) with message: '$($requestObj.description)'" | |
notify = $false | |
message_format = "text" | |
} | ConvertTo-Json | |
ContentType = 'application/json' | |
ErrorAction = 'stop' | |
} | |
try{ | |
Invoke-RestMethod @params | |
}catch{ | |
[Console]::WriteLine($_.exception.message) | |
} | |
# Finally let's output it | |
$params | convertto-json | Out-File -Encoding Ascii $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment