示例#1
0
    def GetReportData(self, get_report_args, token):
        """Filter the last week of user actions."""
        ret = rdf_report_plugins.ApiReportData(
            representation_type=rdf_report_plugins.ApiReportData.
            RepresentationType.PIE_CHART)

        try:
            timerange_offset = get_report_args.duration
            timerange_end = get_report_args.start_time + timerange_offset

            counts = {}
            try:
                for event in report_utils.GetAuditLogEntries(
                        timerange_offset, timerange_end, token):
                    counts.setdefault(event.user, 0)
                    counts[event.user] += 1
            except ValueError:  # Couldn't find any logs..
                pass

            ret.pie_chart.data = sorted(
                (rdf_report_plugins.ApiReportDataPoint1D(x=count, label=user)
                 for user, count in counts.iteritems()
                 if user not in aff4_users.GRRUser.SYSTEM_USERS),
                key=lambda series: series.label)

        except IOError:
            pass

        return ret
示例#2
0
  def GetReportData(self, get_report_args, token):
    """Extract only the operating system type from the active histogram."""
    ret = rdf_report_plugins.ApiReportData(
        representation_type=rdf_report_plugins.ApiReportData.RepresentationType.
        PIE_CHART)

    try:
      fd = aff4.FACTORY.Open(
          rdfvalue.RDFURN("aff4:/stats/ClientFleetStats").Add(
              get_report_args.client_label),
          token=token)
      for graph in fd.Get(
          aff4_stats.ClientFleetStats.SchemaCls.RELEASE_HISTOGRAM):
        # Find the correct graph and merge the OS categories together
        if "%s day" % self.__class__.ACTIVE_DAYS in graph.title:
          for sample in graph:
            ret.pie_chart.data.Append(
                rdf_report_plugins.ApiReportDataPoint1D(
                    label=sample.label, x=sample.y_value))
          break
    except (IOError, TypeError):
      pass

    ret.pie_chart.data = sorted(
        ret.pie_chart.data, key=lambda point: point.label)

    return ret
示例#3
0
    def testOSBreakdownReportPlugin(self):
        # Add a client to be reported.
        self.SetupClients(1)

        # Scan for clients to be reported (the one we just added).
        flow_test_lib.TestFlowHelper(cron_system.OSBreakDown.__name__,
                                     token=self.token)

        report = report_plugins.GetReportByName(
            client_report_plugins.OSBreakdown30ReportPlugin.__name__)

        api_report_data = report.GetReportData(stats_api.ApiGetReportArgs(
            name=report.__class__.__name__, client_label="All"),
                                               token=self.token)

        self.assertEqual(
            api_report_data,
            rdf_report_plugins.ApiReportData(
                pie_chart=rdf_report_plugins.ApiPieChartReportData(data=[
                    rdf_report_plugins.ApiReportDataPoint1D(label="Linux", x=1)
                ]),
                representation_type=rdf_report_plugins.ApiReportData.
                RepresentationType.PIE_CHART))