NEW: get alert from aws health rss
This commit is contained in:
parent
8c753e4733
commit
55efd4b3aa
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/python3
|
||||
import feedparser
|
||||
import sqlite3
|
||||
import smtplib
|
||||
import json
|
||||
from email.message import EmailMessage
|
||||
from email.headerregistry import Address
|
||||
|
||||
feeds = ['https://status.aws.amazon.com/rss/ec2-ap-east-1.rss',
|
||||
'https://status.aws.amazon.com/rss/rds-ap-east-1.rss',
|
||||
'https://status.aws.amazon.com/rss/vpnvpc-ap-east-1.rss',
|
||||
'https://status.aws.amazon.com/rss/directconnect-ap-east-1.rss',
|
||||
'https://status.aws.amazon.com/rss/directconnect-ap-southeast-1.rss']
|
||||
|
||||
|
||||
dbconn = sqlite3.connect('aws-rss.db')
|
||||
|
||||
for f in feeds:
|
||||
NewsFeed = feedparser.parse(f)
|
||||
for e in NewsFeed.entries:
|
||||
try:
|
||||
dbconn.execute("insert into rss values (?,?,?,?,false)", (e.id, e.published, e.title, e.summary))
|
||||
except sqlite3.IntegrityError:
|
||||
pass
|
||||
dbconn.commit()
|
||||
|
||||
results = dbconn.execute('select * from rss where notified = false')
|
||||
msg = " "
|
||||
records = results.fetchall()
|
||||
if len(records) == 0:
|
||||
print("All events already notified")
|
||||
quit()
|
||||
|
||||
content_list = []
|
||||
for r in records:
|
||||
map1 = {
|
||||
'Service': r[0].split('#')[1].split('-')[0].upper(),
|
||||
'PublishTime': r[1],
|
||||
'Link': r[0].replace("http","h t t p"),
|
||||
'Title': r[2],
|
||||
'Summary': r[3]
|
||||
}
|
||||
|
||||
content_list.append(map1)
|
||||
|
||||
dbconn.execute('update rss set notified = true where notified = false')
|
||||
dbconn.commit()
|
||||
dbconn.close()
|
||||
|
||||
email = EmailMessage()
|
||||
email['Subject'] = "[ALERT] AWS event detected!"
|
||||
email['From'] = 'DoNotReply@racker.pro'
|
||||
email['To'] = 'user@domain.com'
|
||||
email.set_content(json.dumps(content_list, sort_keys=False, indent=2, ensure_ascii = False))
|
||||
|
||||
s = smtplib.SMTP('localhost')
|
||||
s.send_message(email)
|
||||
|
Loading…
Reference in New Issue