예제 #1
0
 def doAuthenticatedGet(self, _):
   if users.is_current_user_admin():
     for error in LoggedError.all():
       error.delete()
     for instance in LoggedErrorInstance.all():
       instance.delete()
     self.response.out.write('Done')
   else:
     self.redirect(users.create_login_url(self.request.uri))
예제 #2
0
 def doAuthenticatedGet(self, _):
     if users.is_current_user_admin():
         for error in LoggedError.all():
             error.delete()
         for instance in LoggedErrorInstance.all():
             instance.delete()
         self.response.out.write('Done')
     else:
         self.redirect(users.create_login_url(self.request.uri))
예제 #3
0
def getAggregatedError(project, errorHash):
  """Gets (and updates) the error matching the given report, or None if no matching error is found."""
  error = None

  project = getProject(project)

  q = LoggedError.all().filter('project =', project).filter('hash =', errorHash).filter('active =', True)

  for possibility in q:
    return possibility

  return error
예제 #4
0
def getAggregatedError(project, errorHash):
    """Gets (and updates) the error matching the given report, or None if no matching error is found."""
    error = None

    project = getProject(project)

    q = LoggedError.all().filter("project =", project).filter("hash =", errorHash).filter("active =", True)

    for possibility in q:
        return possibility

    return error
예제 #5
0
def getErrors(filters, limit, offset):
  """Gets a list of errors, filtered by the given filters."""
  for key in filters:
    if key in INSTANCE_FILTERS:
      return None, getInstances(filters, limit=limit, offset=offset)

  errors = LoggedError.all().filter('active =', True)
  for key, value in filters.items():
    if key == 'maxAgeHours':
      errors = errors.filter('firstOccurrence >', datetime.now() - timedelta(hours = int(value)))
    elif key == 'project':
      errors = errors.filter('project =', getProject(value))
    else:
      errors = errors.filter(key, value)
  if 'maxAgeHours' in filters:
    errors = errors.order('-firstOccurrence')
  else:
    errors = errors.order('-lastOccurrence')

  return errors.fetch(limit, offset), None
예제 #6
0
def getErrors(filters, limit, offset):
    """Gets a list of errors, filtered by the given filters."""
    for key in filters:
        if key in INSTANCE_FILTERS:
            return None, getInstances(filters, limit=limit, offset=offset)

    errors = LoggedError.all().filter('active =', True)
    for key, value in filters.items():
        if key == 'maxAgeHours':
            errors = errors.filter(
                'firstOccurrence >',
                datetime.now() - timedelta(hours=int(value)))
        elif key == 'project':
            errors = errors.filter('project =', getProject(value))
        else:
            errors = errors.filter(key, value)
    if 'maxAgeHours' in filters:
        errors = errors.order('-firstOccurrence')
    else:
        errors = errors.order('-lastOccurrence')

    return errors.fetch(limit, offset), None
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)

    projects = collections.defaultdict(list)
    for error in errors:
      projects[error.project.key().name()].append(error)

    context = {'projects': sorted(projects.items()), 'errorCount': len(errors), 'baseUrl': config.get('baseUrl')}

    body = template.render(getTemplatePath('dailymail.html'), context).strip()
    mail.send_mail(
        sender=fromEmail, to=toEmail, subject='Latest GEC reports', body='Only available in HTML', html=body)