Created
July 8, 2022 07:11
-
-
Save justynroberts/40f1ff6f8c8a71f30fbefa8cbaf13da5 to your computer and use it in GitHub Desktop.
AWS Status parser for Diagnostics
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
# Modified for Process Automation, Python 3.x , Justyn Roberts 2022 | |
# Based on original code from AppliedTrust / Ryan Hartkopf in 2014 | |
# Licensed under the Apache License, Version 2.0 (the "License"); | |
# you may not use this file except in compliance with the License. | |
# You may obtain a copy of the License at | |
# | |
# http://www.apache.org/licenses/LICENSE-2.0 | |
# | |
# Unless required by applicable law or agreed to in writing, software | |
# distributed under the License is distributed on an "AS IS" BASIS, | |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
# See the License for the specific language governing permissions and | |
# limitations under the License. | |
# Usage | |
# python aws-status.py --service [aws service and region] eg | |
# python aws-status.py --service ec2-us-east-1 | |
# to return status. This can then be used to write to incident notes | |
# Important. You WILL have to pip install feedparser before running. Tested Python 3. | |
import feedparser | |
import argparse | |
parser = argparse.ArgumentParser(description='Check current status information from the AWS Service Health Dashboard (status.aws.amazon.com).') | |
parser.add_argument('--service') | |
args = parser.parse_args() | |
feed = args.service | |
# Parse the feed and return value from the first entry. Return UNKNOWN to Nagios if error. | |
try: | |
d = feedparser.parse('http://status.aws.amazon.com/rss/'+feed+'.rss') | |
if d.entries: | |
title = d.entries[0]['title'] | |
pubdate = d.entries[0]['published'] | |
dsc = d.entries[0]['description'] | |
elif d['feed']['title']: | |
print ('🟩 AWS OK: No events to display.') | |
exit(0) | |
except KeyError: | |
print ('🟧 AWS UNKNOWN: Feed http://status.aws.amazon.com/rss/'+feed+'.rss could not be parsed. Check command options.') | |
exit(3) | |
# Determine the state of the feed | |
if title.startswith("Service is operating normally"): | |
status = 0 | |
msg = "🟩 AWS OK: " | |
elif (title.startswith("Informational message") or title.startswith("Performance issues") ): | |
status = 1 | |
msg = "🟨 AWS WARNING: " | |
elif (title.startswith("Service disruption")): | |
status = 2 | |
msg = "🟥 AWS CRITICAL: " | |
else: | |
status = 3 | |
msg = "🟧 AWS UNKNOWN: " | |
msg += title | |
print (msg) | |
print (pubdate) | |
print (dsc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment