Run asset discovery

Demonstrates how to start an asset discovery scan

Code sample

Java

static void runAssetDiscovery(OrganizationName organizationName) {
  try (SecurityCenterClient client = SecurityCenterClient.create()) {
    // Call the API.  Note calls to runAssetDiscovery are throttled if too many requests
    // are made.
    OperationFuture<RunAssetDiscoveryResponse, Empty> result =
        client.runAssetDiscoveryAsync(organizationName);

    // Uncomment this line to wait for a certain amount of time for the asset discovery run
    // to complete.
    // result.get(130, TimeUnit.SECONDS);
    System.out.println("Asset discovery runs asynchronously.");
  } catch (IOException e) {
    throw new RuntimeException("Couldn't create client.", e);
  } catch (ResourceExhaustedException e) {
    System.out.println("Asset discovery run already in progress.");
  }
}

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser