Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
DigitalOcean.Status.AtomFeed.Poll.ps1
# DigitalOcean.Status.AtomFeed.Poll.ps1
<#
This script can be used as a Solarwinds Orion component monitor to poll the statuspage.io status feed for Digital Ocean.
It will send notifications for new updates between polling periods, and will list recent updates in the Solarwinds Orion portal.
#>
# Get Atom Feed
$Response = Invoke-WebRequest -Uri "https://status.digitalocean.com/history.atom" -UseBasicParsing -ContentType "application/xml"
If ($Response.StatusCode -ne "200") {
# Feed failed to respond.
Write-Host "Statistic: 2" # Warning
Write-Host "Message: $($Response.StatusCode) $($Response.StatusDescription)"
Exit 3 # Critical
}
$FeedXml = [xml]$Response.Content
$Entries = @()
$Now = Get-Date
# Exract recent entries (currently set for updated within the last 24 hours)
ForEach ($Entry in $FeedXml.feed.entry) {
If (($Now - [datetime]$Entry.updated).TotalHours -le 24) {
$Entries += [PSCustomObject] @{
'Id' = "status.digitalocean.com - " + ($Entry.id).Remove(0, 24)
'Updated' = [datetime]$Entry.updated
'Title' = $Entry.title
'Content' = $Entry.content.'#text'
}
}
}
# Send email notifications for entries updated in the last 5 minutes.
ForEach ($Entry in $Entries) {
If (($Now - [datetime]$Entry.updated).TotalMinutes -le 5) {
$Params = @{
'Body' = $Entry.Content
'BodyAsHtml' = $true
'From' = "alert@example.com"
'SmtpServer' = "smtp.example.com"
'Subject' = $Entry.Id + " - " + $Entry.Title
'To' = "alerts@example.com"
}
# Send notifications
Send-MailMessage @Params
}
}
# Return entries from last 24 hours for Solarwinds dashboard display
$Head = "<style>th{font-weight: bold; padding: 4px;}</style>"
$StatisticMessage = $null
If ($Entries.Count -eq 0 ) {
$StatisticMessage = "No updated events in the last 24 hours."
}
else {
ForEach ($Entry in $Entries) {
$StatisticMessage += "</br><table><tr><th>" + $Entry.Id + " - " + $Entry.Title + "</th></tr><tr><td>" + $Entry.Content + "</td></tr></table>"
}
}
Write-Host "Statistic:" $Entries.Count # Up
Write-Host "Message: $StatisticMessage"
Exit 0 # Up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment