Created
December 7, 2016 16:40
-
-
Save pjperez/999967bbcd321d69dad8567c6200076d to your computer and use it in GitHub Desktop.
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
Write-Output "PowerShell Timer trigger function executed at:$(get-date)"; | |
$uri = "https://bing.com" | |
$poorsodnumber = "+44........" | |
if ((Invoke-WebRequest -Uri $uri -UseBasicParsing).StatusCode -eq 200) { write-output "$uri is UP" } else | |
{ | |
Write-Output "$uri is DOWN. Sending SMS." | |
# Pull in Twilio account info, previously set as environment variables | |
$sid = $env:TWILIO_ACCOUNT_SID | |
$token = $env:TWILIO_AUTH_TOKEN | |
$number = $env:TWILIO_NUMBER | |
# Twilio API endpoint and POST params | |
$url = "https://api.twilio.com/2010-04-01/Accounts/$sid/Messages.json" | |
$params = @{ To = "$poorsodnumer"; From = $number; Body = "$uri is down!! OMG!!" } | |
# Create a credential object for HTTP basic auth | |
$p = $token | ConvertTo-SecureString -asPlainText -Force | |
$credential = New-Object System.Management.Automation.PSCredential($sid, $p) | |
# Make API request, selecting JSON properties from response | |
Invoke-WebRequest $url -Method Post -Credential $credential -Body $params -UseBasicParsing | | |
ConvertFrom-Json | Select sid, body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment