Exemple #1
0
  def testMostActiveUsersReportPlugin(self):
    with test_lib.FakeTime(
        rdfvalue.RDFDatetime.FromHumanReadable("2012/12/14")):
      AddFakeAuditLog(
          "Fake audit description 14 Dec.",
          "C.123",
          "User123",
          token=self.token)

    with test_lib.FakeTime(
        rdfvalue.RDFDatetime.FromHumanReadable("2012/12/22")):
      for _ in xrange(10):
        AddFakeAuditLog(
            "Fake audit description 22 Dec.",
            "C.123",
            "User123",
            token=self.token)

      AddFakeAuditLog(
          "Fake audit description 22 Dec.",
          "C.456",
          "User456",
          token=self.token)

    report = report_plugins.GetReportByName(
        server_report_plugins.MostActiveUsersReportPlugin.__name__)

    with test_lib.FakeTime(
        rdfvalue.RDFDatetime.FromHumanReadable("2012/12/31")):

      now = rdfvalue.RDFDatetime().Now()
      month_duration = rdfvalue.Duration("30d")

      api_report_data = report.GetReportData(
          stats_api.ApiGetReportArgs(
              name=report.__class__.__name__,
              start_time=now - month_duration,
              duration=month_duration),
          token=self.token)

      # pyformat: disable
      self.assertEqual(
          api_report_data,
          rdf_report_plugins.ApiReportData(
              representation_type=rdf_report_plugins.ApiReportData.
              RepresentationType.PIE_CHART,
              pie_chart=rdf_report_plugins.ApiPieChartReportData(
                  data=[
                      rdf_report_plugins.ApiReportDataPoint1D(
                          label="User123",
                          x=11
                      ),
                      rdf_report_plugins.ApiReportDataPoint1D(
                          label="User456",
                          x=1
                      )
                  ]
              )))
Exemple #2
0
    def testOSReleaseBreakdownReportPlugin(self):
        # Add a client to be reported.
        self.SetupClients(1)

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

        report = report_plugins.GetReportByName(
            client_report_plugins.OSReleaseBreakdown30ReportPlugin.__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="Unknown",
                                                            x=1)
                ]),
                representation_type=rdf_report_plugins.ApiReportData.
                RepresentationType.PIE_CHART))
Exemple #3
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
Exemple #4
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