Ejemplo n.º 1
0
    def get(self, app_name):

        global ITEMS_PER_PAGE

        app, app_name = self._global(app_name)

        # Check if the Archive All flag was passed
        archive_all = self.get_argument("archive_all", None)
        if archive_all == "True":
            LoggingService.archive_all_exception_group(app["_id"])
            self.redirect("/dashboard/%s" % app_name)

        # Check if there are any exceptions to archive, if so
        exception = self.get_arguments("exception", None)
        if exception:
            for ex in exception:
                LoggingService.archive_exception_group(ex)

        # Get Severity
        severity = None
        log_choice = self.get_argument("log_choice", None)
        if log_choice is None or log_choice == "specific":
            severity = int(self.get_argument("severity_level", 1))

        # Get Page and Offset
        page = int(self.get_argument("page", 1))
        start = (page * ITEMS_PER_PAGE) - ITEMS_PER_PAGE

        # Get Exceptions
        keyword = self.get_argument("keyword", "")

        # Sorting Variables
        sort = self.get_argument("sort", "last_seen_on")
        sort_direction = int(self.get_argument("sort_direction", -1))

        lso_new_sort = -1
        cnt_new_sort = -1

        if sort == "last_seen_on":
            if sort_direction == -1:
                lso_new_sort = 1
        else:
            if sort_direction == -1:
                cnt_new_sort = 1

        if not keyword and app:
            self._data["exceptions"] = LoggingService.get_exceptions_groups(
                self._data["user"]["_id"],
                app["_id"],
                severity=severity,
                start=start,
                sort=sort,
                sort_direction=sort_direction,
            )

            total_count = self._data["exceptions"].count()
        elif keyword:
            from Packages.mongodbsearch import mongodbsearch
            from pymongo import Connection

            self._data["exceptions"] = []

            mongo_search = mongodbsearch.mongodb_search(Connection()["onerrorlog"])
            conditions = {"key": str(self._data["user"]["_id"]), "application": str(app["_id"])}

            if severity is not None:
                conditions["severity"] = severity

            documents, _, total_count = mongo_search.search(
                keyword, conditions=conditions, fields=["unique_hash, _id"], start=start, scoring=("last_save_date", -1)
            )

            for doc in documents:
                self._data["exceptions"].append(LoggingService.get_exception_group(doc["_id"]))
        else:
            self._data["exceptions"] = []
            total_count = 0

        if app:

            stats_data = {"today": [], "previous": []}

            stats = LoggingService.get_statistics_for_application(app["_id"], severity=severity)
            for i, s in enumerate(stats):
                stats_data["today"].append([i, s["count"]])

            stats = LoggingService.get_statistics_for_application(app["_id"], days_back=1, severity=severity)
            for i, s in enumerate(stats):
                stats_data["previous"].append([i, s["count"]])

            self._data["stats_data"] = stats_data
            self._data["log_choice"] = log_choice
            self._data["severity"] = severity
            self._data["get_severity_string"] = LoggingService.get_severity_string
            self._data["keyword"] = keyword
            self._data["total_count"] = total_count
            self._data["lso_new_sort"] = lso_new_sort
            self._data["cnt_new_sort"] = cnt_new_sort
            self._data["cgi"] = cgi

            self._compute_paging(page, total_count, app_name)

            self._data["section_title"] = "Dashboard : %s : %s" % (
                self._data["user"]["company_name"],
                app["application"],
            )
            self._data["application_name"] = app["application"]
            self._data["htmlTitle"] = "OnErrorLog - Dashboard"
            self.write(self.render_view("../Views/dashboard.html", self._data))

        else:
            self._data["section_title"] = "Getting Started"
            self._data["htmlTitle"] = "OnErrorLog - Getting Started"
            self.write(self.render_view("../Views/gettingstarted.html", self._data))
Ejemplo n.º 2
0
    def get(self, app_name):

        global ITEMS_PER_PAGE

        app, app_name = self._global(app_name)

        #Check if the Archive All flag was passed
        archive_all = self.get_argument('archive_all', None)
        if archive_all == 'True':
            LoggingService.archive_all_exception_group(app['_id'])
            self.redirect('/dashboard/%s' % app_name)

        #Check if there are any exceptions to archive, if so
        exception = self.get_arguments('exception', None)
        if exception:
            for ex in exception:
                LoggingService.archive_exception_group(ex)

        #Get Severity
        severity = None
        log_choice = self.get_argument('log_choice', "all")
        if log_choice is None or log_choice == 'specific':
            severity = int(self.get_argument('severity_level', 1))

        #Get Page and Offset
        page = int(self.get_argument('page', 1))
        start = (page * ITEMS_PER_PAGE) - ITEMS_PER_PAGE

        #Get Exceptions
        keyword = self.get_argument('keyword', '')

        #Sorting Variables
        sort = self.get_argument('sort', 'last_seen_on')
        sort_direction = int(self.get_argument('sort_direction', -1))

        lso_new_sort = -1
        cnt_new_sort = -1

        if sort == 'last_seen_on':
            if sort_direction == -1:
                lso_new_sort = 1
        else:
            if sort_direction == -1:
                cnt_new_sort = 1

        if not keyword and app:
            self._data['exceptions'] = LoggingService.get_exceptions_groups(
                                    self._data['user']['_id'],
                                    app['_id'], severity=severity,
                                    start=start,
                                    sort=sort,
                                    sort_direction=sort_direction)

            total_count = self._data['exceptions'].count()
        elif keyword:
            from Packages.mongodbsearch import mongodbsearch
            from pymongo import Connection

            self._data['exceptions'] = []

            mongo_search = mongodbsearch.mongodb_search(Connection()['onerrorlog'])
            conditions = {'key': str(self._data['user']['_id']),
                          'application': str(app['_id']),
                         }

            if severity is not None:
                conditions['severity'] = severity

            documents, _, total_count = mongo_search.search(keyword,
                                                            conditions=conditions,
                                                            fields=['unique_hash, _id'],
                                                            start=start,
                                                            scoring=('last_save_date', -1))

            for doc in documents:
                self._data['exceptions'].append(LoggingService.get_exception_group(doc['_id']))
        else:
            self._data['exceptions'] = []
            total_count = 0

        if app:

            stats_data = {'today': [], 'previous': []}

            stats = LoggingService.get_statistics_for_application(app['_id'], severity=severity)
            for i, s in enumerate(stats):
                stats_data['today'].append([i, s['count']])

            stats = LoggingService.get_statistics_for_application(app['_id'], days_back=1, severity=severity)
            for i, s in enumerate(stats):
                stats_data['previous'].append([i, s['count']])

            self._data['stats_data'] = stats_data
            self._data['log_choice'] = log_choice
            self._data['severity'] = severity
            self._data['get_severity_string'] = LoggingService.get_severity_string
            self._data['keyword'] = keyword
            self._data['total_count'] = total_count
            self._data['lso_new_sort'] = lso_new_sort
            self._data['cnt_new_sort'] = cnt_new_sort
            self._data['cgi'] = cgi

            self._compute_paging(page, total_count, app_name)

            self._data['section_title'] = 'Dashboard : %s : %s' % (self._data['user']['company_name'], app['application'])
            self._data['application_name'] = app['application']
            self._data['htmlTitle'] = 'OnErrorLog - Dashboard'
            self.write(self.render_view('../Views/dashboard.html', self._data))

        else:
            self._data['section_title'] = 'Getting Started'
            self._data['htmlTitle'] = 'OnErrorLog - Getting Started'
            self.write(self.render_view('../Views/gettingstarted.html', self._data))