Return AWS Service Health Dashboard details to Nagios

I was recently looking into returning service details from the AWS Service Health Dashboard to Nagios where any service issues would be reported as a critical state and remain with this status for the duration of the publication date.

I was able to do this by using the Invoke-RestMethod in Windows Powershell by querying a particular services RSS feed.

As the script was to be run against a number of different AWS services , I did not want to create multiple scripts as well as multiple services within Nagios. Therefore, the script defined parameters for the RSS feed, which were called with the RSS argument.

The RSS argument would be the filename of the services RSS file, as the URL for each service status would always contain http://status.aws.amazon.com/rss/. We will also specify the current date as a variable for later comparing to the publication date of the link,

Param ([string] $RSS)
$Date = (get-date).toString('dd MMM yyyy')

Once the RSS parameter is specified we can build the string to query the URL of the RSS feed using the Invoke-RestMethod. As querying the RSS feed returns multiple links we will also need to return the most recent link using the select-object cmdlet.

$url = Invoke-RestMethod -Uri "http://status.aws.amazon.com/rss/$RSS.rss"   | Select -first 1

Once we have returned the link, we want to check the publication date to determine if this is from the current day and if so return this to be a critical status to Nagios and return the description to be the service status.

If ($url.pubdate -like "*" + $Date + "*")
{ 
$returncode = 2
$url.description 
}

If the publication date is not the current date we want to return this as an OK status to Nagios and return the service status as returning as normally.

Else
{ 
$returncode = 0
"Service is operating normally"  
}

Finally, we will exit the powershell session returning the exit code.

exit $returncode

An example of executing the above script to query the ‘Amazon Virtual Private Cloud (Ireland)’ service which has the URL of http://status.aws.amazon.com/rss/vpc-eu-west-1.rss, the script would be run as the below:

./Read-AWSServiceHealthDashboard.ps1 -RSS vpc-eu-west-1

While the script was created to be executed as an external script within Nagios, this can be run standalone from Windows Powershell. If your are looking to add external scripts to Nagios such as this one see the below link for more information;

https://deangrant.wordpress.com/2013/09/12/creating-and-running-external-scripts-within-nagios-xi/

The full Windows Powershell script can be downloaded from the below link:

https://app.box.com/s/848trplqvu9v8f6um84m

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s