in dlp/src/inspect_send_data_to_hybrid_job_trigger.php [44:132]
function inspect_send_data_to_hybrid_job_trigger(
// TODO(developer): Replace sample parameters before running the code.
string $callingProjectId,
string $jobTriggerId,
string $string
): void {
// Instantiate a client.
$dlp = new DlpServiceClient();
$content = (new ContentItem())
->setValue($string);
$container = (new Container())
->setFullPath('10.0.0.2:logs1:app1')
->setRelativePath('app1')
->setRootPath('10.0.0.2:logs1')
->setType('logging_sys')
->setVersion('1.2');
$findingDetails = (new HybridFindingDetails())
->setContainerDetails($container)
->setLabels([
'env' => 'prod',
'appointment-bookings-comments' => ''
]);
$hybridItem = (new HybridContentItem())
->setItem($content)
->setFindingDetails($findingDetails);
$parent = "projects/$callingProjectId/locations/global";
$name = "projects/$callingProjectId/locations/global/jobTriggers/" . $jobTriggerId;
$triggerJob = null;
try {
$triggerJob = $dlp->activateJobTrigger($name);
} catch (ApiException $e) {
$result = $dlp->listDlpJobs($parent, ['filter' => 'trigger_name=' . $name]);
foreach ($result as $job) {
$triggerJob = $job;
}
}
$dlp->hybridInspectJobTrigger($name, [
'hybridItem' => $hybridItem,
]);
$numOfAttempts = 10;
do {
printf('Waiting for job to complete' . PHP_EOL);
sleep(10);
$job = $dlp->getDlpJob($triggerJob->getName());
if ($job->getState() != JobState::RUNNING) {
break;
}
$numOfAttempts--;
} while ($numOfAttempts > 0);
// Print finding counts.
printf('Job %s status: %s' . PHP_EOL, $job->getName(), JobState::name($job->getState()));
switch ($job->getState()) {
case JobState::DONE:
$infoTypeStats = $job->getInspectDetails()->getResult()->getInfoTypeStats();
if (count($infoTypeStats) === 0) {
printf('No findings.' . PHP_EOL);
} else {
foreach ($infoTypeStats as $infoTypeStat) {
printf(
' Found %s instance(s) of infoType %s' . PHP_EOL,
$infoTypeStat->getCount(),
$infoTypeStat->getInfoType()->getName()
);
}
}
break;
case JobState::FAILED:
printf('Job %s had errors:' . PHP_EOL, $job->getName());
$errors = $job->getErrors();
foreach ($errors as $error) {
var_dump($error->getDetails());
}
break;
case JobState::PENDING:
printf('Job has not completed. Consider a longer timeout or an asynchronous execution model' . PHP_EOL);
break;
default:
printf('Unexpected job state. Most likely, the job is either running or has not yet started.');
}
}