예제 #1
0
class ComponentGroupEdit(View):
    """Component Group Edit Page Controller"""

    template_name = 'templates/admin/component_group/edit.html'

    @login_if_not_authenticated
    def get(self, request, group_id):

        self.__context = Context()
        self.__component_group = ComponentGroupModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        group = self.__component_group.get_one_by_id(group_id)

        if not group:
            raise Http404("Component group not found.")

        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Edit Component Group · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "group":
            group
        })

        return render(request, self.template_name, self.__context.get())
예제 #2
0
class SubscriberEdit(View):
    """Subscriber Edit Page Controller"""

    template_name = 'templates/admin/subscriber/edit.html'

    @login_if_not_authenticated
    def get(self, request, subscriber_id):

        self.__context = Context()
        self.__subscriber = SubscriberModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        subscriber = self.__subscriber.get_one_by_id(subscriber_id)

        if not subscriber:
            raise Http404("Subscriber not found.")

        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Edit Subscriber · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "subscriber":
            subscriber
        })

        return render(request, self.template_name, self.__context.get())
예제 #3
0
class IncidentUpdateAdd(View):
    """Incident Update Add Page Controller"""

    template_name = 'templates/admin/incident/update/add.html'

    @login_if_not_authenticated
    def get(self, request, incident_id):
        self.__context = Context()
        self.__incident = IncidentModule()
        self.__incident_update = IncidentUpdateModule()
        self.__component = ComponentModule()
        self.__component_group = ComponentGroupModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        incident = self.__incident.get_one_by_id(incident_id)

        if not incident:
            raise Http404("Incident not found.")

        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Add Incident Update  · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "incident":
            incident
        })

        return render(request, self.template_name, self.__context.get())
예제 #4
0
class MetricEdit(View):
    """Metric Edit Page Controller"""

    template_name = 'templates/admin/metric/edit.html'

    @login_if_not_authenticated
    def get(self, request, metric_id):

        self.__context = Context()
        self.__metric = MetricModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        metric = self.__metric.get_one_by_id(metric_id)

        if not metric:
            raise Http404("Metric not found.")

        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Edit Metric · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "metric":
            metric
        })

        metric["data"] = json.loads(metric["data"])

        return render(request, self.template_name, self.__context.get())
예제 #5
0
class IncidentList(View):
    """Incident List Page Controller"""

    template_name = 'templates/admin/incident/list.html'

    @login_if_not_authenticated
    def get(self, request):

        self.__context = Context()
        self.__incident = IncidentModule()
        self.__incident_update = IncidentUpdateModule()
        self.__component = ComponentModule()
        self.__component_group = ComponentGroupModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Incidents · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
예제 #6
0
class Dashboard(View):
    """Dashboard Page Controller"""

    template_name = 'templates/admin/dashboard.html'

    @login_if_not_authenticated
    def get(self, request):
        self.__context = Context()
        self.__dashboard = DashboardModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Dashboard · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "count": {
                "incidents":
                self.__dashboard.incidents_count(),
                "subscribers":
                self.__dashboard.subscribers_count(),
                "components":
                self.__dashboard.components_count(),
                "component_groups":
                self.__dashboard.component_groups_count(),
                "metrics":
                self.__dashboard.metrics_count(),
                "users":
                self.__dashboard.users_count(),
                "delivered_notifications":
                self.__dashboard.notifications_count("success"),
                "failed_notifications":
                self.__dashboard.notifications_count("failed")
            },
            "chart": {
                "subscribers":
                self.__dashboard.subscribers_chart(),
                "components":
                self.__dashboard.components_chart(),
                "delivered_notifications":
                self.__dashboard.notifications_chart("success", 14),
                "failed_notifications":
                self.__dashboard.notifications_chart("failed", 14),
                "incidents":
                self.__dashboard.incidents_chart()
            },
            "open_incidents":
            self.__dashboard.get_open_incidents(),
            "affected_components":
            self.__dashboard.get_affected_components()
        })

        return render(request, self.template_name, self.__context.get())
예제 #7
0
class Settings(View):
    """Settings Page Controller"""

    template_name = 'templates/admin/settings.html'

    @login_if_not_authenticated_or_no_permission("manage_settings")
    def get(self, request):

        self.__context = Context()
        self.__upgrade = Upgrade()
        self.__acl = ACL()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.load_options({
            "app_name": "",
            "app_email": "",
            "app_url": "",
            "app_description": "",
            "google_analytics_account": "",
            "reset_mails_messages_count": "",
            "reset_mails_expire_after": "",
            "access_tokens_expire_after": "",
            "prometheus_token": "",
            "newrelic_api_key": ""
        })

        self.__context.push({
            "current": self.__upgrade.get_current_version(),
            "latest": self.__upgrade.get_latest_version()
        })

        self.__context.push({
            "page_title":
            _("Settings · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
예제 #8
0
class MetricAdd(View):
    """Metric Add Page Controller"""

    template_name = 'templates/admin/metric/add.html'

    @login_if_not_authenticated
    def get(self, request):
        self.__context = Context()
        self.__metric = MetricModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Add a Metric · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
예제 #9
0
파일: user.py 프로젝트: Maxtasy/silverback
class UserAdd(View):
    """User Add Page Controller"""

    template_name = 'templates/admin/user/add.html'

    @login_if_not_authenticated_or_no_permission("manage_settings")
    def get(self, request):

        self.__context = Context()
        self.__user = UserModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("Add a User · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
예제 #10
0
class Notification(View):
    """Notification List Page Controller"""

    template_name = 'templates/admin/notification.html'

    @login_if_not_authenticated
    def get(self, request):

        self.__context = Context()
        self.__acl = ACL()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)

        self.__context.push({
            "page_title":
            _("Notification · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
예제 #11
0
class Builder(View):
    """Builder Page Controller"""

    template_name = 'templates/admin/builder.html'

    @login_if_not_authenticated_or_no_permission("manage_settings")
    def get(self, request):

        self.__context = Context()
        self.__metric = MetricModule()
        self.__component = ComponentModule()
        self.__component_group = ComponentGroupModule()
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.load_options({
            "builder_headline": "",
            "builder_favicon_url": "",
            "builder_logo_url": "",
            "builder_about": "",
            "builder_components": json.dumps([]),
            "builder_metrics": json.dumps([])
        })
        self.__context.push({
            "page_title":
            _("Status Page Builder · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "groups":
            self.__format_groups(self.__component.get_all_groups()),
            "components":
            self.__format_components(self.__component.get_all()),
            "metrics":
            self.__format_metrics(self.__metric.get_all())
        })

        self.__context.push({
            "builder_components":
            json.loads(str(self.__context.get("builder_components"))),
            "builder_metrics":
            json.loads(str(self.__context.get("builder_metrics")))
        })

        return render(request, self.template_name, self.__context.get())

    def __format_components(self, components):
        components_list = []

        for component in components:
            components_list.append({
                "id": "c-%d" % component.id,
                "name": component.name
            })

        return components_list

    def __format_groups(self, groups):
        groups_list = []

        for group in groups:
            groups_list.append({"id": "g-%d" % group.id, "name": group.name})

        return groups_list

    def __format_metrics(self, metrics):
        metrics_list = []

        for metric in metrics:
            metrics_list.append({
                "id": "m-%d" % metric.id,
                "title": metric.title
            })

        return metrics_list
예제 #12
0
class IncidentUpdateView(View):
    """Incident Update View Page Controller"""

    template_name = 'templates/admin/incident/update/view.html'

    @login_if_not_authenticated
    def get(self, request, incident_id, update_id):

        self.__context = Context()
        self.__incident = IncidentModule()
        self.__incident_update = IncidentUpdateModule()
        self.__incident_update_component = IncidentUpdateComponentModule()
        self.__component = ComponentModule()
        self.__component_group = ComponentGroupModule()
        self.__incident_update_notification = IncidentUpdateNotificationModule(
        )
        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        incident = self.__incident.get_one_by_id(incident_id)

        if not incident:
            raise Http404("Incident not found.")

        update = self.__incident_update.get_one_by_id(update_id)

        if not update:
            raise Http404("Incident update not found.")

        update["datetime"] = update["datetime"].strftime("%b %d %Y %H:%M:%S")
        update["message"] = markdown2.markdown(update["message"])
        update[
            "notified_subscribers"] = self.__incident_update_notification.count_by_update_status(
                update["id"], IncidentUpdateNotificationModule.SUCCESS)
        update[
            "failed_subscribers"] = self.__incident_update_notification.count_by_update_status(
                update["id"], IncidentUpdateNotificationModule.FAILED)

        components = self.__format_components(self.__component.get_all())
        affected_components = self.__format_affected_components(
            self.__incident_update_component.get_all(update_id))

        self.__context.autoload_options()
        self.__context.autoload_user(
            request.user.id if request.user.is_authenticated else None)
        self.__context.push({
            "page_title":
            _("View Incident Update  · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "update":
            update,
            "incident":
            incident,
            "components":
            components,
            "affected_components":
            affected_components
        })

        return render(request, self.template_name, self.__context.get())

    def __format_components(self, components):
        components_list = []

        for component in components:
            components_list.append({
                "id": component.id,
                "name": component.name
            })

        return components_list

    def __format_affected_components(self, affected_components):
        affected_components_list = []

        for affected_component in affected_components:
            affected_components_list.append({
                "id":
                affected_component.id,
                "component_id":
                affected_component.component.id,
                "component_name":
                affected_component.component.name,
                "type":
                affected_component.type
            })

        return affected_components_list