def _global(self, app_name): self._data["applications"] = ApplicationService.get_applications(self._data["user"]["_id"]) self._data["keyword"] = "" # Get Applications if app_name: app_name = app_name.replace("/", "") app = ApplicationService.get_application_by_url_name(self._data["user"]["_id"], app_name) if not app: raise tornado.web.HTTPError(404) self._data["current_application"] = str(app["_id"]) else: app = ApplicationService.get_first_application(self._data["user"]["_id"]) self._data["current_application"] = str(app["_id"]) if app: app_name = app["url_name"] else: app_name = "" self._data["app"] = app self._data["app_name"] = app_name return app, app_name
def _global(self, app_name): self._data['applications'] = ApplicationService.get_applications(self._data['user']['_id']) self._data['keyword'] = '' #Get Applications if app_name: app_name = app_name.replace('/', '') app = ApplicationService.get_application_by_url_name( self._data['user']['_id'], app_name ) if not app: raise tornado.web.HTTPError(404) self._data['current_application'] = str(app['_id']) else: app = ApplicationService.get_first_application(self._data['user']['_id']) if app: app_name = app['url_name'] self._data['current_application'] = str(app['_id']) else: app_name = '' self._data['app'] = app self._data['app_name'] = app_name return app, app_name
def post(self, app_name): app, app_name = self._global(app_name) app["github_account"] = self.get_argument("github_account", None) app["github_repository"] = self.get_argument("github_repository", None) app["github_username"] = self.get_argument("github_username", None) app["github_token"] = self.get_argument("github_token", None) app["lighthouse_apitoken"] = self.get_argument("lighthouse_apitoken", None) app["lighthouse_project_id"] = self.get_argument("lighthouse_project_id", None) ApplicationService.save_application(app) self.redirect("/configure/%s" % app_name)
def post(self, app_name): app, app_name = self._global(app_name) app['github_account'] = self.get_argument('github_account', None) app['github_repository'] = self.get_argument('github_repository', None) app['github_username'] = self.get_argument('github_username', None) app['github_token'] = self.get_argument('github_token', None) app['lighthouse_apitoken'] = self.get_argument('lighthouse_apitoken', None) app['lighthouse_project_id'] = self.get_argument('lighthouse_project_id', None) ApplicationService.save_application(app) self.redirect('/configure/%s' % app_name)
def insert_exception(d): exceptions = Database.Instance().exceptions() exception_groups = Database.Instance().exception_groups() applications = Database.Instance().applications() #Check for required keys required_fields = ['key', 'message', 'application', 'severity'] if len(list(set(required_fields) & set(d))) != len(required_fields): raise KeyError('Some required fields are missing') check_severity(d['severity']) #Validate the key which was passed if not _validate_key(d['key']): raise KeyError('The key you specified is invalid') d['application'] = ApplicationService.insert_application(d['key'], d['application']) if 'stacktrace' not in d: d['stacktrace'] = '' #Setup the string to be hashed hash_string = '%s\n%s\n%s\n%s\n%s\n%s' % (d['key'], d['severity'], str(d['stacktrace']), d['message'], d['filename'], d['application']) #Has the string unique_hash = hash(hash_string) #Create and insert the exception record exception = d exception['insert_date'] = datetime.datetime.utcnow() exception['unique_hash'] = unique_hash exception_id = exceptions.save(exception) #Check if the exception group exists group = exception_groups.find_one({'unique_hash': unique_hash, 'status': False }) #If Exception already exists, increment count if group: group['count'] += 1 group['exceptions'].append(exception_id) group['status'] = False #Otherwise, create the exception group record else: group = { 'message': d['message'], 'severity': d['severity'], 'key': d['key'], 'application': d['application'], 'exceptions': [ exception_id ], 'unique_hash': unique_hash, 'status': False, 'count': 1, 'insert_date': datetime.datetime.utcnow(), 'filename': d['filename'], 'stacktrace': d['stacktrace'], } applications.update({'_id': d['application'] }, {'$inc': {'count': 1 }}) applications.update({'_id': d['application'] }, {'$inc': {str(d['severity']): 1 }}) #Set the last seen_date group['last_seen_on'] = datetime.datetime.utcnow() #Save the exception group exception_group_id = exception_groups.save(group) increment_statistics(d, exception_group_id) #Update the Exception with the Exception Group Id exception['exception_group_id'] = exception_group_id exceptions.save(exception) exception_groups.ensure_index([('severity', 1), ('application', 1), ('key', 1), ('unique_hash', 1), ('status', 1 ), ('last_seen_on', -1) ]) exceptions.ensure_index([('severity', 1), ('application', 1), ('key', 1), ('unique_hash', 1), ('insert_date', -1), ]) #Index the Document mdb_search = mongodbsearch.mongodb_search(Database.Instance().db()) text = [d['message']] if 'headers' in d: for k, v in d['headers'].iteritems(): text.append(str(k)) text.append(str(v)) if 'params' in d: for k, v in d['params'].iteritems(): text.append(str(k)) text.append(str(v)) for s in d['stacktrace']: text.extend([str(x) for x in s.values()]) kwargs = {'key': d['key'], 'application': str(d['application']), 'severity': d['severity'], 'last_seen_on': group['last_seen_on'], 'filename': d['filename'], 'unique_hash': unique_hash } mdb_search.index_document(str(exception_group_id), ' '.join(text), ensureindex=kwargs.keys(), **kwargs) return exception_group_id, exception_id
def insert_exception(d): exceptions = Database.Instance().exceptions() exception_groups = Database.Instance().exception_groups() applications = Database.Instance().applications() # Check for required keys required_fields = ["key", "message", "application", "severity"] if len(list(set(required_fields) & set(d))) != len(required_fields): raise KeyError("Some required fields are missing") check_severity(d["severity"]) # Validate the key which was passed if not _validate_key(d["key"]): raise KeyError("The key you specified is invalid") d["application"] = ApplicationService.insert_application(d["key"], d["application"]) if "stacktrace" not in d: d["stacktrace"] = "" # Setup the string to be hashed hash_string = "%s\n%s\n%s\n%s\n%s\n%s" % ( d["key"], d["severity"], str(d["stacktrace"]), d["message"], d["filename"], d["application"], ) # Has the string unique_hash = hash(hash_string) # Create and insert the exception record exception = d exception["insert_date"] = datetime.datetime.utcnow() exception["unique_hash"] = unique_hash exception_id = exceptions.save(exception) # Check if the exception group exists group = exception_groups.find_one({"unique_hash": unique_hash, "status": False}) # If Exception already exists, increment count if group: group["count"] += 1 group["exceptions"].append(exception_id) group["status"] = False # Otherwise, create the exception group record else: group = { "message": d["message"], "severity": d["severity"], "key": d["key"], "application": d["application"], "exceptions": [exception_id], "unique_hash": unique_hash, "status": False, "count": 1, "insert_date": datetime.datetime.utcnow(), "filename": d["filename"], "stacktrace": d["stacktrace"], } applications.update({"_id": d["application"]}, {"$inc": {"count": 1}}) applications.update({"_id": d["application"]}, {"$inc": {str(d["severity"]): 1}}) # Set the last seen_date group["last_seen_on"] = datetime.datetime.utcnow() # Save the exception group exception_group_id = exception_groups.save(group) increment_statistics(d, exception_group_id) # Update the Exception with the Exception Group Id exception["exception_group_id"] = exception_group_id exceptions.save(exception) # Index the Document mdb_search = mongodbsearch.mongodb_search(Database.Instance().db()) text = [d["message"]] if "headers" in d: for k, v in d["headers"].iteritems(): text.append(str(k)) text.append(str(v)) if "params" in d: for k, v in d["params"].iteritems(): text.append(str(k)) text.append(str(v)) for s in d["stacktrace"]: text.extend([str(x) for x in s.values()]) kwargs = { "key": d["key"], "application": str(d["application"]), "severity": d["severity"], "last_seen_on": group["last_seen_on"], "filename": d["filename"], "unique_hash": unique_hash, } mdb_search.index_document(str(exception_group_id), " ".join(text), ensureindex=kwargs.keys(), **kwargs) return exception_group_id, exception_id