Beispiel #1
0
 def __init__(self):
     self.__acl = ACL()
     self.__option_entity = OptionEntity()
     self.__user_entity = UserEntity()
     self.__notification_entity = NotificationEntity()
     self.__register_request_entity = RegisterRequestEntity()
     self.__task_core = TaskCore()
Beispiel #2
0
 def __init__(self):
     self.__option_entity = OptionEntity()
     self.__user_entity = UserEntity()
     self.__task_entity = TaskEntity()
     self.__profile_entity = ProfileEntity()
     self.__app_name = self.__option_entity.get_value_by_key(
         "app_name").lower()
Beispiel #3
0
 def __init__(self):
     self.__option_entity = OptionEntity()
     self.__metric_entity = MetricEntity()
     new_relic_api = self.__option_entity.get_one_by_key("newrelic_api_key")
     self.__newrelic = None
     if new_relic_api:
         self.__newrelic = NewRelic_Provider(new_relic_api.value)
Beispiel #4
0
 def test_delete_one_by_id(self):
     option_entity = OptionEntity()
     option = option_entity.insert_one({
         "key": "key10",
         "value": "value10",
         "autoload": True
     })
     self.assertTrue(option_entity.delete_one_by_id(option.id))
     self.assertFalse(option_entity.delete_one_by_id(600))
Beispiel #5
0
def globals(request):

    option_entity = OptionEntity()

    return {
        "google_account": option_entity.get_value_by_key("google_analytics_account", ""),
        "app_timezone": os.getenv("APP_TIMEZONE", "UTC"),
        "activate_notifications": os.getenv("ACTIVATE_NOTIFICATIONS", "false") == "true",
    }
Beispiel #6
0
 def __init__(self):
     self.__option_entity = OptionEntity()
     self.__incident_entity = IncidentEntity()
     self.__incident_update_entity = IncidentUpdateEntity()
     self.__incident_update_component_entity = IncidentUpdateComponentEntity()
     self.__component_group_entity = ComponentGroupEntity()
     self.__component_entity = ComponentEntity()
     self.__metric_entity = MetricEntity()
     self.__load_system_status()
Beispiel #7
0
    def test_insert_one(self):
        option_entity = OptionEntity()
        option = option_entity.insert_one({
            "key": "key1",
            "value": "value1",
            "autoload": True
        })

        self.assertTrue(option)
        self.assertTrue(option.id >= 1)
Beispiel #8
0
 def test_update_value_by_id(self):
     option_entity = OptionEntity()
     option = option_entity.insert_one({
         "key": "key8",
         "value": "value8",
         "autoload": True
     })
     self.assertTrue(
         option_entity.update_value_by_id(option.id, "new_value8"))
     self.assertFalse(option_entity.update_value_by_id(700, "new_value8"))
Beispiel #9
0
    def check_db(self):
        errors = []

        try:
            option_entity = OptionEntity()
            if option_entity.count() < Health.MIN_OPTIONS:
                errors.append(_("Application not installed yet."))
        except Exception as e:
            errors.append(_("Error Connecting to database: %(error)s") % {"error": str(e)})

        return errors
Beispiel #10
0
class Settings():

    def __init__(self):
        self.__option_entity = OptionEntity()

    def update_options(self, options):
        status = True
        for key, value in options.items():
            status &= self.__option_entity.update_value_by_key(key, value)
        return status

    def get_value_by_key(self, key, default=""):
        return self.__option_entity.get_value_by_key(key, default)
Beispiel #11
0
    def get(self, request):

        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())
Beispiel #12
0
    def __init__(self):

        self.__option_entity = OptionEntity()
        self.__user_entity = UserEntity()
        self.__data["AUTHOR"] = AUTHOR
        self.__data["COPYRIGHT"] = COPYRIGHT
        self.__data["LICENSE"] = LICENSE
        self.__data["VERSION"] = VERSION
        self.__data["MAINTAINER"] = MAINTAINER
        self.__data["EMAIL"] = EMAIL
        self.__data["STATUS"] = STATUS
        self.__data["REPO_URL"] = REPO_URL
        self.__data["AUTHOR_URL"] = AUTHOR_URL
        self.__data["RELEASES"] = RELEASES
        self.__data["SUPPORT_URL"] = SUPPORT_URL
Beispiel #13
0
    def __init__(self):
        self.__reset_request_entity = ResetRequestEntity()
        self.__option_entity = OptionEntity()
        self.__user_entity = UserEntity()
        self.__task_core = TaskCore()

        messages_count_option = self.__option_entity.get_one_by_key(
            "reset_mails_messages_count")
        reset_expire_option = self.__option_entity.get_one_by_key(
            "reset_mails_expire_after")

        if messages_count_option:
            self.__messages_count_option = int(messages_count_option.value)

        if reset_expire_option:
            self.__reset_expire_option = int(reset_expire_option.value)
    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())
Beispiel #15
0
    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')
Beispiel #16
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())
Beispiel #17
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())
    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())
Beispiel #19
0
class Statistics():
    def __init__(self):
        self.__option_entity = OptionEntity()
        self.__user_entity = UserEntity()
        self.__task_entity = TaskEntity()
        self.__profile_entity = ProfileEntity()
        self.__app_name = self.__option_entity.get_value_by_key(
            "app_name").lower()

    def get_all_users(self):
        return {
            "type": "count",
            "record": "%s_all_users" % self.__app_name,
            "count": self.__user_entity.count_all(),
            "comment": "Current All Users on System"
        }

    def get_all_profiles(self):
        return {
            "type": "count",
            "record": "%s_all_profiles" % self.__app_name,
            "count": self.__profile_entity.count_all_profiles(),
            "comment": "Current All Profiles on System"
        }

    def get_all_tasks(self):
        return {
            "type": "count",
            "record": "%s_all_tasks" % self.__app_name,
            "count": self.__task_entity.count_all_tasks(),
            "comment": "Current All Tasks on System"
        }
Beispiel #20
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())
Beispiel #21
0
 def wrap(controller, request, *args, **kwargs):
     installed = False if OptionEntity().get_one_by_key("app_installed") is False else True
     if installed:
         response = Response()
         return JsonResponse(response.send_private_failure([{
             "type": "error",
             "message": _("Error! Application is already installed.")
         }]))
     return function(controller, request, *args, **kwargs)
Beispiel #22
0
 def wrap(controller, request, *args, **kwargs):
     if kwargs["type"] == "prometheus":
         prometheus_token = OptionEntity().get_one_by_key(
             "prometheus_token")
         if prometheus_token.value != "" and (
                 "HTTP_AUTHORIZATION" not in request.META
                 or prometheus_token.value !=
                 request.META["HTTP_AUTHORIZATION"]):
             raise Http404("Host not found.")
     return function(controller, request, *args, **kwargs)
Beispiel #23
0
 def test_insert_many(self):
     option_entity = OptionEntity()
     self.assertTrue(
         option_entity.insert_many([{
             "key": "key2",
             "value": "value2",
             "autoload": False
         }, {
             "key": "key3",
             "value": "value3"
         }, {
             "key": "key4",
             "value": "value4",
             "autoload": True
         }, {
             "key": "key5",
             "value": "value5",
             "autoload": True
         }]))
Beispiel #24
0
class Metric():

    __metric_entity = None
    __option_entity = None
    __newrelic = None

    def __init__(self):
        self.__option_entity = OptionEntity()
        self.__metric_entity = MetricEntity()
        new_relic_api = self.__option_entity.get_one_by_key("newrelic_api_key")
        if new_relic_api:
            self.__newrelic = NewRelic_Provider(new_relic_api.value)

    def get_one_by_id(self, id):
        metric = self.__metric_entity.get_one_by_id(id)

        if not metric:
            return False

        return {
            "id": metric.id,
            "title": metric.title,
            "description": metric.description,
            "source": metric.source,
            "data": metric.data,
            "x_axis": metric.x_axis,
            "y_axis": metric.y_axis
        }

    def insert_one(self, metric):
        return self.__metric_entity.insert_one(metric)

    def update_one_by_id(self, id, metric_data):
        return self.__metric_entity.update_one_by_id(id, metric_data)

    def count_all(self):
        return self.__metric_entity.count_all()

    def get_all(self, offset=None, limit=None):
        return self.__metric_entity.get_all(offset, limit)

    def delete_one_by_id(self, id):
        return self.__metric_entity.delete_one_by_id(id)

    def get_new_relic_apps(self):
        result = []
        try:
            response = self.__newrelic.get_apps()
        except Exception as e:
            raise Exception(e)
        apps = json.loads(response)
        for app in apps["applications"]:
            result.append({"key": app["id"], "value": app["name"]})
        return result
Beispiel #25
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())
Beispiel #26
0
 def test_get_many_by_autoload(self):
     option_entity = OptionEntity()
     self.assertTrue(
         option_entity.insert_many([{
             "key": "key2",
             "value": "value2",
             "autoload": False
         }, {
             "key": "key3",
             "value": "value3"
         }, {
             "key": "key4",
             "value": "value4",
             "autoload": True
         }, {
             "key": "key5",
             "value": "value5",
             "autoload": True
         }]))
     self.assertEqual(option_entity.get_many_by_autoload(True).count(), 2)
     self.assertEqual(option_entity.get_many_by_autoload(False).count(), 2)
Beispiel #27
0
 def test_delete_one_by_key(self):
     option_entity = OptionEntity()
     option_entity.insert_one({
         "key": "key11",
         "value": "value11",
         "autoload": True
     })
     self.assertTrue(option_entity.delete_one_by_key("key11"), 1)
     self.assertFalse(option_entity.delete_one_by_key("key12"))
Beispiel #28
0
 def test_get_one_by_key(self):
     option_entity = OptionEntity()
     option = option_entity.insert_one({
         "key": "key7",
         "value": "value7",
         "autoload": True
     })
     self.assertEqual(option_entity.get_one_by_key("key7"), option)
     self.assertEqual(option_entity.get_one_by_key("key7").key, "key7")
     self.assertFalse(option_entity.get_one_by_key("not_found_key"))
Beispiel #29
0
 def test_update_value_by_key(self):
     option_entity = OptionEntity()
     option_entity.insert_one({
         "key": "key9",
         "value": "value9",
         "autoload": True
     })
     self.assertTrue(option_entity.update_value_by_key(
         "key9", "new_value9"))
     self.assertTrue(
         option_entity.update_value_by_key("not_found_key", "new_value9"))
Beispiel #30
0
    def test_get_one_by_id(self):
        option_entity = OptionEntity()
        option = option_entity.insert_one({
            "key": "key6",
            "value": "value6",
            "autoload": True
        })

        self.assertEqual(option_entity.get_one_by_id(option.id), option)
        self.assertEqual(option_entity.get_one_by_id(option.id).key, "key6")
        self.assertFalse(option_entity.get_one_by_id(1000))