Permalink
Browse files

Add daily GEC email of new errors

  • Loading branch information...
1 parent 27547aa commit 8c5adb4bfb70bffea47f3448f580793c45c1a22f @robbywalker robbywalker committed Jun 17, 2011
Showing with 93 additions and 9 deletions.
  1. +6 −2 server/app.yaml.template
  2. +6 −0 server/common.py
  3. +4 −0 server/cron.yaml
  4. +58 −0 server/emailCron.py
  5. +1 −7 server/server.py
  6. +18 −0 server/templates/dailymail.txt
View
@@ -13,8 +13,12 @@ handlers:
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
-- url: /mapreduce(/.*)?
- script: mapreduce/main.py
+- url: /tasks/aggregate
+ script: aggregate.py
+ login: admin
+
+- url: /tasks/email
+ script: emailCron.py
login: admin
- url: /.*
View
@@ -22,6 +22,7 @@
from datamodel import Project
import datetime
+import os.path
def getProject(name):
@@ -40,6 +41,11 @@ def parseDate(string):
return datetime.datetime.strptime(string.split('.')[0], '%Y-%m-%d %H:%M:%S')
+def getTemplatePath(name):
+ """Gets a path to the named template."""
+ return os.path.join(os.path.dirname(__file__), 'templates', name)
+
+
class AttrDict(dict):
"""A dict that is accessible as attributes."""
View
@@ -2,3 +2,7 @@ cron:
- description: four times daily stats aggregation
url: /tasks/aggregate
schedule: every 6 hours synchronized
+- description: daily email
+ url: /tasks/email
+ schedule: every day 13:00
+ timezone: America/Los_Angeles
View
@@ -0,0 +1,58 @@
+# Copyright 2011 The greplin-exception-catcher Authors.
+#
+# 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.
+
+"""AppEngine server for emailing new exceptions."""
+
+# pylint: disable=E0611
+from google.appengine.dist import use_library
+use_library('django', '1.2')
+
+# pylint: disable=E0611
+from google.appengine.api import mail
+# pylint: disable=E0611
+from google.appengine.ext.webapp import template
+
+from common import getTemplatePath
+import config
+from datamodel import LoggedError
+
+from datetime import datetime, timedelta
+import logging
+
+
+
+def main():
+ """Runs the aggregation."""
+ toEmail = config.get('toEmail')
+ fromEmail = config.get('fromEmail')
+
+ if toEmail and fromEmail:
+ logging.info('running the email cron')
+
+ errorQuery = (LoggedError.all().filter('active =', True)
+ .filter('firstOccurrence >', datetime.now() - timedelta(hours = 24))
+ .order('-firstOccurrence'))
+
+ errors = errorQuery.fetch(500, 0)
+ errors.sort(key = lambda x: x.count, reverse=True)
+ context = {'errors': errors, 'baseUrl': config.get('baseUrl')}
+
+ body = template.render(getTemplatePath('dailymail.txt'), context).strip()
+ mail.send_mail(sender=fromEmail, to=toEmail, subject='Latest GEC reports', body=body)
+
+
+
+if __name__ == '__main__':
+ main()
+
View
@@ -36,13 +36,12 @@
except ImportError:
import json
import logging
-import os
import random
import sys
import time
import traceback
-from common import getProject
+from common import getProject, getTemplatePath
from datamodel import LoggedError, LoggedErrorInstance, AggregatedStats
@@ -58,11 +57,6 @@
####### Utility methods. #######
-def getTemplatePath(name):
- """Gets a path to the named template."""
- return os.path.join(os.path.dirname(__file__), 'templates', name)
-
-
INSTANCE_FILTERS = ('environment', 'server', 'affectedUser')
INTEGER_FILTERS = ('affectedUser',)
@@ -0,0 +1,18 @@
+{% autoescape off %}{% if errors %}
+{{ errors|length }} new errors today:
+
+{% for error in errors %}
+{{baseUrl}}/view/{{error.key}}
+Last Message: {{error.lastMessage}}
+Count: {{error.count}}
+Project: {{error.parent_key.name}}
+Level: {{error.errorLevel}}
+Type: {{error.type}}
+Environments: {{error.environments|join:", "}}
+Servers: {{error.servers|join:", "}}
+
+{% endfor %}
+{% else %}
+Hooray - no new errors!
+{% endif %}
+{% endautoescape %}

0 comments on commit 8c5adb4

Please sign in to comment.