Example #1
0
class IncidentUpdatesComponent(View):
    """Remove Component from Incident Update Private Endpoint Controller"""

    def __init__(self):
        self.__request = Request()
        self.__response = Response()
        self.__helpers = Helpers()
        self.__form = Form()
        self.__incident_update_component = IncidentUpdateComponentModule()
        self.__logger = self.__helpers.get_logger(__name__)
        self.__user_id = None
        self.__correlation_id = ""
        self.__form.add_validator(ExtraRules())

    @allow_if_authenticated
    def delete(self, request, incident_id, update_id, item_id):

        self.__correlation_id = request.META["X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__user_id = request.user.id

        if self.__incident_update_component.delete_one_by_id(item_id):
            return JsonResponse(self.__response.send_private_success([{
                "type": "success",
                "message": _("Affected component deleted successfully.")
            }], {}, self.__correlation_id))

        else:
            return JsonResponse(self.__response.send_private_failure([{
                "type": "error",
                "message": _("Error! Something goes wrong while deleting affected component.")
            }], {}, self.__correlation_id))
Example #2
0
 def __init__(self):
     self.__request = Request()
     self.__response = Response()
     self.__helpers = Helpers()
     self.__form = Form()
     self.__incident_update_component = IncidentUpdateComponentModule()
     self.__logger = self.__helpers.get_logger(__name__)
     self.__form.add_validator(ExtraRules())
Example #3
0
 def __init__(self):
     self.__request = Request()
     self.__response = Response()
     self.__helpers = Helpers()
     self.__form = Form()
     self.__incident_update = IncidentUpdateModule()
     self.__task = Task_Module()
     self.__notification = NotificationModule()
     self.__subscriber = SubscriberModule()
     self.__logger = self.__helpers.get_logger(__name__)
     self.__incident_update_component = IncidentUpdateComponentModule()
     self.__form.add_validator(ExtraRules())
Example #4
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())
Example #5
0
class IncidentUpdatesComponents(View):

    __request = None
    __response = None
    __helpers = None
    __form = None
    __logger = None
    __user_id = None
    __incident_update = None
    __task = None
    __notification = None
    __subscriber = None
    __incident_update_component = None
    __correlation_id = None

    def __init__(self):
        self.__request = Request()
        self.__response = Response()
        self.__helpers = Helpers()
        self.__form = Form()
        self.__incident_update = IncidentUpdateModule()
        self.__task = Task_Module()
        self.__notification = NotificationModule()
        self.__subscriber = SubscriberModule()
        self.__logger = self.__helpers.get_logger(__name__)
        self.__incident_update_component = IncidentUpdateComponentModule()
        self.__form.add_validator(ExtraRules())

    @allow_if_authenticated
    def post(self, request, incident_id, update_id):

        self.__correlation_id = request.META["X-Correlation-ID"] if "X-Correlation-ID" in request.META else ""
        self.__user_id = request.user.id
        self.__request.set_request(request)

        request_data = self.__request.get_request_data("post", {
            "type": "",
            "component_id": ""
        })

        self.__form.add_inputs({
            'component_id': {
                'value': request_data["component_id"],
                'validate': {
                    'sv_numeric': {
                        'error': _('Error! Component is required.')
                    }
                }
            },
            'type': {
                'value': request_data["type"],
                'validate': {
                    'any_of': {
                        'param': [["operational", "degraded_performance", "partial_outage", "major_outage", "maintenance"]],
                        'error': _('Error! Type is required.')
                    }
                }
            }
        })

        self.__form.process()

        if not self.__form.is_passed():
            return JsonResponse(self.__response.send_errors_failure(self.__form.get_errors(), {}, self.__correlation_id))

        result = self.__incident_update_component.insert_one({
            "component_id": int(self.__form.get_sinput("component_id")),
            "type": self.__form.get_sinput("type"),
            "incident_update_id": int(update_id)
        })

        if result:
            return JsonResponse(self.__response.send_private_success([{
                "type": "success",
                "message": _("Affected component created successfully.")
            }], {}, self.__correlation_id))
        else:
            return JsonResponse(self.__response.send_private_failure([{
                "type": "error",
                "message": _("Error! Something goes wrong while creating affected component.")
            }], {}, self.__correlation_id))