Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nagios plugin to check AWS Status RSS feeds
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'net/http'
# check_aws_status.rb
# A nagios plugin for fetching RSS feeds from http://status.aws.amazon.com.
# Source: https://gist.github.com/1604786
# Written by Aaron Suggs: https://github.com/ktheory
if ARGV[0].nil? || ARGV[0] == '-h'
puts %{
USAGE:
#{$0} url
E.g.:
#{$0} http://status.aws.amazon.com/rss/EC2.rss
Returns an approriate response based on the most recent status message
}
exit 3
end
# Nagios exit status conventions
EXIT_OK = 0
EXIT_WARNING = 1
EXIT_CRITICAL = 2
EXIT_UNKNOWN = 3
begin
url = ARGV[0]
xml_data = Net::HTTP.get_response(URI.parse(url)).body
xml_doc = Nokogiri::XML(xml_data)
latest_status = xml_doc.css("item title").first.text
puts latest_status
case latest_status
when /^Service is operating normally/i, /Informational message/i
exit EXIT_OK
when /^Performance issues/i
exit EXIT_WARNING
when /^Service disruption/i
exit EXIT_CRITICAL
else
exit EXIT_UNKNOWN
end
rescue
puts "Error fetching status: #{$!}"
exit EXIT_UNKNOWN
end
#!/usr/bin/env ruby
# Test script to fetch all AWS RSS feeds and all item titles
require 'rubygems'
require 'nokogiri'
require 'net/http'
feed_urls = `curl -s http://status.aws.amazon.com/|grep rss|awk -F '"' '{print "http://status.aws.amazon.com/" $4}'`.split
responses = []
feed_urls.each do |url|
xml_data = Net::HTTP.get_response(URI.parse(url)).body
xml_doc = Nokogiri::XML(xml_data)
responses += xml_doc.css("item title").map(&:text)
end
puts responses.sort
@mpatters72

This comment has been minimized.

Show comment
Hide comment
@mpatters72

mpatters72 Jun 29, 2012

Thanks for sharing this.
Only comment is that it throws "UNKNOWN" status for services that are blank "e.g. never had outage info posted" such as cloudwatch-ap-southeast-1.rss

mpatters72 commented Jun 29, 2012

Thanks for sharing this.
Only comment is that it throws "UNKNOWN" status for services that are blank "e.g. never had outage info posted" such as cloudwatch-ap-southeast-1.rss

@ktheory

This comment has been minimized.

Show comment
Hide comment
@ktheory

ktheory Jul 2, 2012

Ah, thanks for the heads up.

I noticed this weekend that it's also giving a warning when EC2 in us-east1 is in the "resolved" state.

Patches welcome. :-)

Owner

ktheory commented Jul 2, 2012

Ah, thanks for the heads up.

I noticed this weekend that it's also giving a warning when EC2 in us-east1 is in the "resolved" state.

Patches welcome. :-)

@scaissie

This comment has been minimized.

Show comment
Hide comment
@scaissie

scaissie Jul 10, 2015

This fixes the "never had an outage" problem:

if xml_doc.css("item title").first.nil?
# There's no "<title>", the service has had no recent problems
exit EXIT_OK
else
latest_status = xml_doc.css("item title").first.text
end

scaissie commented Jul 10, 2015

This fixes the "never had an outage" problem:

if xml_doc.css("item title").first.nil?
# There's no "<title>", the service has had no recent problems
exit EXIT_OK
else
latest_status = xml_doc.css("item title").first.text
end

@dragan1979

This comment has been minimized.

Show comment
Hide comment
@dragan1979

dragan1979 Aug 23, 2018

.```
/1.rb http://status.aws.amazon.com//rss/a4b-us-east-1.rss
Error fetching status: undefined method `text' for nil:NilClass

dragan1979 commented Aug 23, 2018

.```
/1.rb http://status.aws.amazon.com//rss/a4b-us-east-1.rss
Error fetching status: undefined method `text' for nil:NilClass

@ssm-alex

This comment has been minimized.

Show comment
Hide comment
@ssm-alex

ssm-alex Sep 6, 2018

The issue is that AWS has converted from using 'http' to 'https' for the RSS links now.

ssm-alex commented Sep 6, 2018

The issue is that AWS has converted from using 'http' to 'https' for the RSS links now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment