forked from alsotang/goagent_monitor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemail_handler.py
44 lines (32 loc) · 1.1 KB
/
email_handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import webapp2
from google.appengine.api import urlfetch
from google.appengine.api import taskqueue
from google.appengine.api import memcache
from google.appengine.api import mail
import logging
import urlparse
import time
from monitor_config import config as monitor_config
from monitor_config import email_sender
import api_handler
class EmailHandler(webapp2.RequestHandler):
def get(self):
for cluster_id, cluster_attrs in monitor_config.iteritems():
taskqueue.add(url="/start_email", params={'cluster_id': cluster_id})
self.response.write("start email...")
def post(self):
cluster_id = self.request.get('cluster_id')
defer_fetch(cluster_id)
def defer_fetch(cluster_id):
email(cluster_id)
def email(cluster_id):
cluster_attrs = monitor_config[cluster_id]
logging.info("email...%s" % cluster_id)
message = mail.EmailMessage(sender=email_sender,
subject=("GoAgentMonitor-"+cluster_id))
message.to = cluster_attrs["email"]
message.body = api_handler.getJson(cluster_id)
message.send()
app = webapp2.WSGIApplication([
("/start_email", EmailHandler)
], debug=True)