Last active
September 22, 2016 06:50
-
-
Save imorrish/ae0b20327b9b9d63d94d to your computer and use it in GitHub Desktop.
PowerShell function to send alert to PushAlot
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
function Send-PushAlot { | |
<# | |
.SYNOPSIS | |
Send alert via https://pushalot.com/api#webapi to Windows Phone or Desktop device app | |
#> | |
Param( | |
[String] | |
[parameter(Mandatory=$true)] | |
[ValidateLength(1,250)] | |
$pushTitle = "test", | |
[String] | |
[parameter(Mandatory=$true)] | |
[ValidateLength(1,32768)] | |
$pushBody = "text here", | |
[String] | |
[ValidateLength(1,100)] | |
$pushLinkTitle = 'Gist GitHub Link', | |
[String] | |
[ValidateLength(1,1000)] | |
$pushLink = 'https://gist.github.com/imorrish/ae0b20327b9b9d63d94d', | |
[String] | |
$pushURI = 'https://pushalot.com/api/sendmessage', | |
[String] | |
$pushToken = 'Put your token from https://pushalot.com here' | |
) | |
BEGIN{ | |
Add-Type -AssemblyName System.Web | |
} | |
PROCESS{ | |
try | |
{ | |
$message = Invoke-WebRequest -Uri $pushURI -Method POST -Body "AuthorizationToken=$($pushToken)&Title=$([System.Web.HttpUtility]::UrlEncode($pushTitle))&Body=$([System.Web.HttpUtility]::UrlEncode($pushBody))&LinkTitle=$([System.Web.HttpUtility]::UrlEncode($pushLinkTitle))&Link=$([System.Web.HttpUtility]::UrlEncode($pushLink))" | |
switch ($message.StatusCode) | |
{ | |
"200" {Write-Host -ForegroundColor Green "Message Sent"} | |
"400" {Write-Host -ForegroundColor Red "Input data validation failed. Check result information Description field for detailed information."} | |
"406" {Write-Host -ForegroundColor Red "Message throttle limit hit. Check result information Description field for information which limit was exceeded."} | |
"410" {Write-Host -ForegroundColor Red "The AuthorizationToken is no longer valid and no more messages should be ever sent again using that token. "} | |
"500" {Write-Host -ForegroundColor Red "Something is broken"} | |
"510" {Write-Host -ForegroundColor Red "servers are currently overloaded with requests"} | |
} | |
} | |
catch [System.Net.WebException] | |
{ | |
Write-Host -ForegroundColor Red $_.Exception.Message | |
} | |
finally | |
{ | |
} | |
} | |
END{} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Thanks 👍