def testHuntActionsReportPluginWithNoActivityToReport(self): report = report_plugins.GetReportByName( server_report_plugins.HuntActionsReportPlugin.__name__) 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) self.assertEqual( api_report_data, rdf_report_plugins.ApiReportData( representation_type=rdf_report_plugins.ApiReportData. RepresentationType.AUDIT_CHART, audit_chart=rdf_report_plugins.ApiAuditChartReportData( used_fields=[ "action", "description", "flow_name", "timestamp", "urn", "user" ], rows=[])))
def GetReportData(self, get_report_args, token): """Filter the cron job approvals in the given timerange.""" ret = rdf_report_plugins.ApiReportData( representation_type=rdf_report_plugins.ApiReportData. RepresentationType.AUDIT_CHART, audit_chart=rdf_report_plugins.ApiAuditChartReportData( used_fields=self.__class__.USED_FIELDS)) try: timerange_offset = get_report_args.duration timerange_end = get_report_args.start_time + timerange_offset rows = [] try: for event in report_utils.GetAuditLogEntries( timerange_offset, timerange_end, token): if event.action in self.__class__.TYPES: rows.append(event) except ValueError: # Couldn't find any logs.. pass except IOError: pass rows.sort(key=lambda row: row.timestamp, reverse=True) ret.audit_chart.rows = rows return ret