check_aws_status.rb

Nagios plugin to check AWS Status RSS feeds

0

Votes

check_aws_status.rb

#!/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

list_all_statuses.rb

#!/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

Vote Here

You must earn at least 1 vote on your snippets to be allowed to vote

Terms Of Use

Privacy Policy

Featured snippets are MIT license

Gears & Masters

Advertise

DevOpsnipp.com © 2020

medium.png