Пример #1
0
 def GetStatsPaths(self, request):
     paths = []
     labels = aff4_grr.GetAllClientLabels(request.token,
                                          include_catchall=True)
     for cls in self.classes.values():
         if aff4.issubclass(cls, Report) and cls.category:
             paths.extend(InterpolatePaths(cls.category, labels).keys())
     paths.sort()
     return paths
Пример #2
0
    def Start(self):
        """Retrieve all the clients for the AbstractClientStatsCollectors."""
        try:

            # Get a list of all the client labels in the db
            self.labels = aff4_grr.GetAllClientLabels(self.token,
                                                      include_catchall=True)
            self.stats = {}
            for label in self.labels:
                self.stats[label] = aff4.FACTORY.Create(
                    self.CLIENT_STATS_URN.Add(label),
                    "ClientFleetStats",
                    mode="w",
                    token=self.token)

            self.BeginProcessing()

            root = aff4.FACTORY.Open(aff4.ROOT_URN, token=self.token)
            children_urns = list(root.ListChildren())
            logging.debug("Found %d children.", len(children_urns))

            processed_count = 0
            for child in aff4.FACTORY.MultiOpen(children_urns,
                                                mode="r",
                                                token=self.token,
                                                age=aff4.NEWEST_TIME):
                if isinstance(child, aff4.AFF4Object.VFSGRRClient):
                    self.ProcessClient(child)
                    processed_count += 1

                # This flow is not dead: we don't want to run out of lease time.
                self.HeartBeat()

            self.FinishProcessing()
            for fd in self.stats.values():
                fd.Close()

            logging.info("%s: processed %d clients.", self.__class__.__name__,
                         processed_count)
        except Exception as e:  # pylint: disable=broad-except
            logging.exception("Error while calculating stats: %s", e)
            raise
Пример #3
0
    def Layout(self, request, response):
        """Delegate to a stats renderer if needed."""
        path = request.REQ.get("path", "")

        labels = aff4_grr.GetAllClientLabels(request.token,
                                             include_catchall=True)
        # Try and find the correct renderer to use.
        lookup_dict = GetClassLookupDict(self.classes.values(), labels)
        if path in lookup_dict:
            self.delegated_renderer = lookup_dict[path][0]()

            # Tell the renderer which label it should be using
            request.label = lookup_dict[path][1]

            # Render the renderer directly here
            self.delegated_renderer.Layout(request, response)

        response = super(ReportRenderer, self).Layout(request, response)
        return self.CallJavascript(response,
                                   "ReportRenderer.Layout",
                                   renderer=self.__class__.__name__)