Esempio n. 1
0
    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())
Esempio n. 2
0
    def get(self, request, token):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__user = UserModule()
        self.__context = Context()
        self.__option_entity = OptionEntity()

        if not self.__user.check_register_request(token):
            messages.error(
                request,
                _("Register token is expired or invalid, Please contact system administrator!"
                  ))
            return redirect("app.web.login")

        self.__context.autoload_options()
        self.__context.push({
            "page_title":
            _("Register · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "register_request":
            self.__user.get_register_request_by_token(token)
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 3
0
    def get(self, request, token):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__reset_password_core = ResetPasswordModule()
        self.__context = Context()
        self.__option_entity = OptionEntity()

        self.__context.autoload_options()
        self.__context.push({
            "page_title":
            _("Reset Password · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "reset_token":
            token
        })

        if not self.__reset_password_core.check_token(token):
            messages.error(
                request,
                _("Reset token is expired or invalid, Please request another token!"
                  ))
            return redirect("app.web.forgot_password")

        return render(request, self.template_name, self.__context.get())
Esempio n. 4
0
class Endpoint_Add(View):

    template_name = 'templates/admin/namespaces/endpoints/add.html'
    __context = Context()
    __context = Context()
    __namespace_module = Namespace_Module()
    __endpoint_module = Endpoint_Module()

    def get(self, request, namespace_slug):

        namespace = self.__namespace_module.get_one_by_slug(namespace_slug)

        if namespace == False or request.user.id != namespace.user.id:
            raise Http404("Namespace 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":
            _("Create Endpoint · %s") %
            (self.__context.get("app_name", os.getenv("APP_NAME", "Kevin"))),
            "namespace":
            namespace
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 5
0
    def get(self, request, uri):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context = Context()
        self.__option_entity = OptionEntity()
        self.__status_page_module = StatusPageModule()

        incident = self.__status_page_module.get_incident_by_uri(uri)

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

        self.__context.autoload_options()
        self.__context.push({
            "page_title":
            self.__context.get("app_name", os.getenv("APP_NAME",
                                                     "Silverback")),
            "logo_url":
            self.__status_page_module.get_logo_url(),
            "favicon_url":
            self.__status_page_module.get_favicon_url(),
            "is_authenticated":
            request.user and request.user.is_authenticated,
            "uri":
            uri,
            "incident":
            incident
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 6
0
class Login(View):
    """Login Page Controller"""

    template_name = 'templates/login.html'

    @redirect_if_not_installed
    @redirect_if_authenticated
    def get(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context = Context()
        self.__option_entity = OptionEntity()

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

        if "redirect" in request.GET:
            self.__context.push({"redirect_url": request.GET["redirect"]})
        else:
            self.__context.push(
                {"redirect_url": reverse("app.web.admin.dashboard")})

        return render(request, self.template_name, self.__context.get())
Esempio n. 7
0
class Install(View):

    template_name = 'templates/install.html'
    __context = None
    __install = None
    __option_entity = None
    __correlation_id = None

    def get(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context = Context()
        self.__install = InstallModule()
        self.__option_entity = OptionEntity()

        if self.__install.is_installed():
            return redirect("app.web.login")

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

        return render(request, self.template_name, self.__context.get())
Esempio n. 8
0
class RssHistory(View):
    """RSS History Page Controller"""

    @redirect_if_not_installed
    def get(self, request):

        self.__correlation_id = request.META["X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__fg = FeedGenerator()
        self.__context = Context()
        self.__option_entity = OptionEntity()

        self.__context.autoload_options()
        self.__context.push({
            "page_title": self.__context.get("app_name", os.getenv("APP_NAME", "Silverback")),
            "is_authenticated": request.user and request.user.is_authenticated
        })

        self.__fg.id('http://silverbackhq.org')
        self.__fg.title('Some Testfeed')
        self.__fg.author({'name': 'John Doe', 'email': '*****@*****.**'})
        self.__fg.link(href='http://example.com', rel='alternate')
        self.__fg.logo('http://ex.com/logo.jpg')
        self.__fg.subtitle('This is a cool feed!')
        self.__fg.link(href='http://silverbackhq.org/test.atom', rel='self')
        self.__fg.language('en')

        return HttpResponse(self.__fg.atom_str(), content_type='text/xml')
Esempio n. 9
0
    def get(self, request):

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context = Context()
        self.__option_entity = OptionEntity()
        self.__status_page_module = StatusPageModule()

        self.__context.autoload_options()
        self.__context.push({
            "page_title":
            self.__context.get("app_name", os.getenv("APP_NAME",
                                                     "Silverback")),
            "is_authenticated":
            request.user and request.user.is_authenticated,
            "system_status":
            self.__status_page_module.get_system_status(),
            "about_site":
            self.__status_page_module.get_about_site(),
            "logo_url":
            self.__status_page_module.get_logo_url(),
            "favicon_url":
            self.__status_page_module.get_favicon_url(),
            "past_incidents":
            self.__status_page_module.get_past_incidents(7),
            "system_metrics":
            self.__status_page_module.get_system_metrics(),
            "services":
            self.__status_page_module.get_services()
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 10
0
    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())
Esempio n. 11
0
    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())
Esempio n. 12
0
class Login(View):

    template_name = 'templates/login.html'
    __context = None
    __option_entity = None

    @redirect_if_not_installed
    @redirect_if_authenticated
    def get(self, request):

        self.__context = Context()
        self.__option_entity = Option_Entity()

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

        if "redirect" in request.GET:
            self.__context.push({"redirect_url": request.GET["redirect"]})
        else:
            self.__context.push(
                {"redirect_url": reverse("app.web.admin.dashboard")})

        return render(request, self.template_name, self.__context.get())
Esempio n. 13
0
    def get(self, request):

        self.__context = Context()
        self.__option_entity = Option_Entity()

        self.__context.autoload_options()
        self.__context.push({
            "page_title": _("Forgot Password · %s") % self.__context.get("app_name", os.getenv("APP_NAME", "Kraven"))
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 14
0
    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())
Esempio n. 15
0
    def get(self, request):

        self.__context = Context()
        self.__option_entity = Option_Entity()

        self.__context.autoload_options()
        self.__context.push({
            "page_title": self.__context.get("app_name", os.getenv("APP_NAME", "Kraven")),
            "is_authenticated": request.user and request.user.is_authenticated
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 16
0
    def get(self, request):

        self.__correlation_id = request.META["X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__context = Context()
        self.__option_entity = OptionEntity()

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

        return render(request, self.template_name, self.__context.get())
Esempio n. 17
0
def handler500(request, exception=None, template_name='templates/500.html'):
    correlation_id = request.META[
        "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
    helpers = Helpers()
    logger = helpers.get_logger(__name__)

    if exception is not None:
        logger.error(
            "Server Error: %(exception)s {'correlationId':'%(correlationId)s'}"
            % {
                "exception": exception,
                "correlationId": correlation_id
            })

    template_name = 'templates/500.html'

    context = Context()

    context.autoload_options()
    context.push({
        "page_title":
        _("500 · %s") %
        context.get("app_name", os.getenv("APP_NAME", "Silverback"))
    })

    return render(request, template_name, context.get(), status=500)
Esempio n. 18
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())
Esempio n. 19
0
class IncidentAdd(View):
    """Incident Add Page Controller"""

    template_name = 'templates/admin/incident/add.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":
            _("Add an Incident · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Silverback"))
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 20
0
def handler404(request, exception=None, template_name='templates/404.html'):
    """404 Error Page Controller"""

    correlation_id = request.META[
        "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
    helpers = Helpers()
    logger = helpers.get_logger(__name__)

    if exception is not None:
        logger.debug(
            "Route Not Found: %(exception)s {'correlationId':'%(correlationId)s'}"
            % {
                "exception": exception,
                "correlationId": correlation_id
            })

    template_name = 'templates/404.html'

    context = Context()

    context.autoload_options()
    context.push({
        "page_title":
        _("404 · %s") %
        context.get("app_name", os.getenv("APP_NAME", "Silverback"))
    })

    return render(request, template_name, context.get(), status=404)
Esempio n. 21
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())
Esempio n. 22
0
    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())
Esempio n. 23
0
    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())
Esempio n. 24
0
class Settings(View):

    template_name = 'templates/admin/settings.html'
    __context = Context()
    __upgrade = Upgrade()


    def get(self, request):

        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": ""
        })

        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", "Kevin"))
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 25
0
    def get(self, request):

        self.__context = Context()
        self.__install = Install_Module()
        self.__option_entity = Option_Entity()

        if self.__install.is_installed():
            return redirect("app.web.login")

        self.__context.push({
            "page_title":
            _("Installation · %s") % self.__option_entity.get_value_by_key(
                "app_name", os.getenv("APP_NAME", "Kraven"))
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 26
0
class Reset_Password(View):

    template_name = 'templates/reset_password.html'
    __reset_password_core = Reset_Password_Module()
    __context = Context()
    __option_entity = Option_Entity()

    @redirect_if_not_installed
    @redirect_if_authenticated
    def get(self, request, token):

        self.__context.autoload_options()
        self.__context.push({
            "page_title":
            _("Reset Password · %s") %
            self.__context.get("app_name", os.getenv("APP_NAME", "Kevin")),
            "reset_token":
            token
        })

        if not self.__reset_password_core.check_token(token):
            messages.error(
                request,
                _("Reset token is expired or invalid, Please request another token!"
                  ))
            return redirect("app.web.forgot_password")

        return render(request, self.template_name, self.__context.get())
Esempio n. 27
0
class Host_View(View):

    template_name = 'templates/admin/hosts/docker/view.html'
    __context = Context()
    __host_module = Host_Module()

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

        host = self.__host_module.get_one_by_slug_user_id(
            host_slug, request.user.id)

        if not host or request.user.id != host.user.id:
            raise Http404("Host 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":
            _("%s Host · %s") %
            (host.name,
             self.__context.get("app_name", os.getenv("APP_NAME", "Kraven"))),
            "host":
            host,
            "screen":
            "main"
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 28
0
class ComponentEdit(View):

    template_name = 'templates/admin/component/edit.html'
    __context = Context()
    __component = ComponentModule()
    __correlation_id = None

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

        self.__correlation_id = request.META[
            "X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        component = self.__component.get_one_by_id(component_id)

        if not component:
            raise Http404("Component 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 · %s") % self.__context.get(
                "app_name", os.getenv("APP_NAME", "Silverback")),
            "component":
            component,
            "groups":
            self.__component.get_all_groups()
        })

        return render(request, self.template_name, self.__context.get())
Esempio n. 29
0
class Profile(View):

    template_name = 'templates/admin/profile.html'
    __context = Context()
    __profile = Profile()
    __user_id = None
    __correlation_id = None

    @login_if_not_authenticated
    def get(self, request):

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

        self.__context.push(self.__profile.get_profile(self.__user_id))

        return render(request, self.template_name, self.__context.get())
Esempio n. 30
0
class Namespaces_List(View):

    template_name = 'templates/admin/namespaces/list.html'
    __context = Context()
    __namespace_module = Namespace_Module()
    __namespaces_statistics = NamespacesStatistics()

    def get(self, request):

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

        self.__context.push({
            "namespaces":
            self.__namespace_module.get_many_by_user(request.user.id),
            "donut":
            self.__namespaces_statistics.overall_count_chart(request.user.id),
            "line_chart":
            self.__namespaces_statistics.count_over_time_chart(
                20, request.user.id)
        })

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