Ejemplo n.º 1
0
    def _get_screenshot(self) -> bytes:
        """
        Get a chart or dashboard screenshot

        :raises: ReportScheduleScreenshotFailedError
        """
        screenshot: Optional[BaseScreenshot] = None
        if self._report_schedule.chart:
            url = self._get_url(standalone="true")
            screenshot = ChartScreenshot(
                url,
                self._report_schedule.chart.digest,
                window_size=app.config["WEBDRIVER_WINDOW"]["slice"],
                thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"],
            )
        else:
            url = self._get_url()
            screenshot = DashboardScreenshot(
                url,
                self._report_schedule.dashboard.digest,
                window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
                thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
            )
        user = self._get_screenshot_user()
        try:
            image_data = screenshot.get_screenshot(user=user)
        except SoftTimeLimitExceeded:
            raise ReportScheduleScreenshotTimeout()
        except Exception as ex:
            raise ReportScheduleScreenshotFailedError(
                f"Failed taking a screenshot {str(ex)}")
        if not image_data:
            raise ReportScheduleScreenshotFailedError()
        return image_data
Ejemplo n.º 2
0
 def _get_screenshots(self) -> List[bytes]:
     """
     Get chart or dashboard screenshots
     :raises: ReportScheduleScreenshotFailedError
     """
     url = self._get_url()
     user = self._get_user()
     if self._report_schedule.chart:
         screenshot: Union[
             ChartScreenshot, DashboardScreenshot] = ChartScreenshot(
                 url,
                 self._report_schedule.chart.digest,
                 window_size=app.config["WEBDRIVER_WINDOW"]["slice"],
                 thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"],
             )
     else:
         screenshot = DashboardScreenshot(
             url,
             self._report_schedule.dashboard.digest,
             window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
             thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
         )
     try:
         image = screenshot.get_screenshot(user=user)
     except SoftTimeLimitExceeded as ex:
         logger.warning("A timeout occurred while taking a screenshot.")
         raise ReportScheduleScreenshotTimeout() from ex
     except Exception as ex:
         raise ReportScheduleScreenshotFailedError(
             f"Failed taking a screenshot {str(ex)}") from ex
     if not image:
         raise ReportScheduleScreenshotFailedError()
     return [image]
Ejemplo n.º 3
0
 def _get_screenshots(self) -> List[bytes]:
     """
     Get chart or dashboard screenshots
     :raises: ReportScheduleScreenshotFailedError
     """
     image_data = []
     screenshots: List[BaseScreenshot] = []
     if self._report_schedule.chart:
         url = self._get_url()
         logger.info("Screenshotting chart at %s", url)
         screenshots = [
             ChartScreenshot(
                 url,
                 self._report_schedule.chart.digest,
                 window_size=app.config["WEBDRIVER_WINDOW"]["slice"],
                 thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"],
             )
         ]
     else:
         tabs: Optional[List[str]] = json.loads(self._report_schedule.extra).get(
             "dashboard_tab_ids", None
         )
         dashboard_base_url = self._get_url()
         if tabs is None:
             urls = [dashboard_base_url]
         else:
             urls = [f"{dashboard_base_url}#{tab_id}" for tab_id in tabs]
         screenshots = [
             DashboardScreenshot(
                 url,
                 self._report_schedule.dashboard.digest,
                 window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
                 thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
             )
             for url in urls
         ]
     user = self._get_user()
     for screenshot in screenshots:
         try:
             image = screenshot.get_screenshot(user=user)
         except SoftTimeLimitExceeded as ex:
             logger.warning("A timeout occurred while taking a screenshot.")
             raise ReportScheduleScreenshotTimeout() from ex
         except Exception as ex:
             raise ReportScheduleScreenshotFailedError(
                 f"Failed taking a screenshot {str(ex)}"
             ) from ex
         if image is not None:
             image_data.append(image)
     if not image_data:
         raise ReportScheduleScreenshotFailedError()
     return image_data
Ejemplo n.º 4
0
    def _get_screenshot(self) -> ScreenshotData:
        """
        Get a chart or dashboard screenshot

        :raises: ReportScheduleScreenshotFailedError
        """
        screenshot: Optional[BaseScreenshot] = None
        if self._report_schedule.chart:
            url = self._get_url(standalone="true")
            screenshot = ChartScreenshot(
                url,
                self._report_schedule.chart.digest,
                window_size=app.config["WEBDRIVER_WINDOW"]["slice"],
                thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"],
            )
        else:
            url = self._get_url()
            screenshot = DashboardScreenshot(
                url,
                self._report_schedule.dashboard.digest,
                window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
                thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
            )
        image_url = self._get_url(user_friendly=True)
        user = self._get_screenshot_user()
        image_data = screenshot.compute_and_cache(
            user=user,
            cache=thumbnail_cache,
            force=True,
        )
        if not image_data:
            raise ReportScheduleScreenshotFailedError()
        return ScreenshotData(url=image_url, image=image_data)
Ejemplo n.º 5
0
    def _get_screenshot(self) -> bytes:
        """
        Get a chart or dashboard screenshot

        :raises: ReportScheduleScreenshotFailedError
        """
        screenshot: Optional[BaseScreenshot] = None
        if self._report_schedule.chart:
            url = self._get_url()
            logger.info("Screenshotting chart at %s", url)
            screenshot = ChartScreenshot(
                url,
                self._report_schedule.chart.digest,
                window_size=app.config["WEBDRIVER_WINDOW"]["slice"],
                thumb_size=app.config["WEBDRIVER_WINDOW"]["slice"],
            )
        else:
            url = self._get_url()
            logger.info("Screenshotting dashboard at %s", url)
            screenshot = DashboardScreenshot(
                url,
                self._report_schedule.dashboard.digest,
                window_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
                thumb_size=app.config["WEBDRIVER_WINDOW"]["dashboard"],
            )
        user = self._get_user()
        try:
            image_data = screenshot.get_screenshot(user=user)
        except SoftTimeLimitExceeded as ex:
            logger.warning("A timeout occurred while taking a screenshot.")
            raise ReportScheduleScreenshotTimeout() from ex
        except Exception as ex:
            raise ReportScheduleScreenshotFailedError(
                f"Failed taking a screenshot {str(ex)}"
            ) from ex
        if not image_data:
            raise ReportScheduleScreenshotFailedError()
        return image_data
Ejemplo n.º 6
0
 def _get_screenshot(self, report_schedule: ReportSchedule) -> ScreenshotData:
     """
     Get a chart or dashboard screenshot
     :raises: ReportScheduleScreenshotFailedError
     """
     url = self._get_url(report_schedule)
     screenshot: Optional[BaseScreenshot] = None
     if report_schedule.chart:
         screenshot = ChartScreenshot(url, report_schedule.chart.digest)
     else:
         screenshot = DashboardScreenshot(url, report_schedule.dashboard.digest)
     image_url = self._get_url(report_schedule, user_friendly=True)
     user = security_manager.find_user(app.config["THUMBNAIL_SELENIUM_USER"])
     image_data = screenshot.compute_and_cache(
         user=user, cache=thumbnail_cache, force=True,
     )
     if not image_data:
         raise ReportScheduleScreenshotFailedError()
     return ScreenshotData(url=image_url, image=image_data)
Ejemplo n.º 7
0
 def _get_screenshot(self) -> ScreenshotData:
     """
     Get a chart or dashboard screenshot
     :raises: ReportScheduleScreenshotFailedError
     """
     url = self._get_url()
     screenshot: Optional[BaseScreenshot] = None
     if self._report_schedule.chart:
         screenshot = ChartScreenshot(url, self._report_schedule.chart.digest)
     else:
         screenshot = DashboardScreenshot(
             url, self._report_schedule.dashboard.digest
         )
     image_url = self._get_url(user_friendly=True)
     user = self._get_screenshot_user()
     image_data = screenshot.compute_and_cache(
         user=user, cache=thumbnail_cache, force=True,
     )
     if not image_data:
         raise ReportScheduleScreenshotFailedError()
     return ScreenshotData(url=image_url, image=image_data)