演示如何按状态变化对活跃发现结果进行分组
代码示例
Java
static ImmutableList<GroupResult> groupActiveFindingsWithSourceAndCompareDuration(
SourceName sourceName, Duration duration) {
try (SecurityCenterClient client = SecurityCenterClient.create()) {
// SourceName sourceName = SourceName.of(/*organization=*/"123234324",/*source=*/
// "423432321");
GroupFindingsRequest.Builder request =
GroupFindingsRequest.newBuilder()
.setParent(sourceName.toString())
.setGroupBy("state_change")
.setFilter("state=\"ACTIVE\"");
request
.getCompareDurationBuilder()
.setSeconds(duration.getSeconds())
.setNanos(duration.getNano());
// Call the API.
GroupFindingsPagedResponse response = client.groupFindings(request.build());
// This creates one list for all findings. If your organization has a large number of
// findings
// this can cause out of memory issues. You can process them batches by returning
// the Iterable returned response.iterateAll() directly.
ImmutableList<GroupResult> results = ImmutableList.copyOf(response.iterateAll());
System.out.println("Findings:");
System.out.println(results);
return results;
} catch (IOException e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
后续步骤
如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器。