Example #1
0
class NewRelicApps(View, Controller):
    """List NewRelic Apps Private Endpoint Controller"""

    def __init__(self):
        self.__metric = MetricModule()

    @allow_if_authenticated
    def get(self, request):

        result = False

        try:
            result = self.__metric.get_new_relic_apps()
        except Exception as e:
            self.logger().error(_("Error while listing newrelic applications: %(error)s") % {
                "error": str(e)
            })

        if result is False:
            return self.json([{
                "type": "error",
                "message": _("Error! Connecting to New Relic.")
            }])

        return self.json([], {
            'apps': result
        })
Example #2
0
class NewRelicApps(View):

    __request = None
    __response = None
    __helpers = None
    __form = None
    __logger = None
    __user_id = None
    __metric = None
    __correlation_id = None

    def __init__(self):
        self.__request = Request()
        self.__response = Response()
        self.__helpers = Helpers()
        self.__form = Form()
        self.__metric = MetricModule()
        self.__logger = self.__helpers.get_logger(__name__)
        self.__form.add_validator(ExtraRules())

    @allow_if_authenticated
    def get(self, request):

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

        result = False
        try:
            result = self.__metric.get_new_relic_apps()
        except Exception as e:
            self.__logger.error(
                _("Error while listing newrelic applications: %(error)s {'correlationId':'%(correlationId)s'}"
                  ) % {
                      "error": str(e),
                      "correlationId": self.__correlation_id
                  })

        if result is False:
            return JsonResponse(
                self.__response.send_private_failure(
                    [{
                        "type": "error",
                        "message": _("Error! Connecting to New Relic.")
                    }], {}, self.__correlation_id))

        return JsonResponse(
            self.__response.send_private_success([], {'apps': result},
                                                 self.__correlation_id))