Skip to content

Commit e2c120c

Browse files
committed
[backend] 1 Crowdstrike agent per endpoint
1 parent 965201e commit e2c120c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

openbas-api/src/main/java/io/openbas/service/EndpointService.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,19 @@ public List<Asset> syncAgentsEndpoints(
224224
Arrays.asList(input.getMacAddresses()).contains(macAddress)))
225225
.findFirst();
226226
if (optionalInputToSave.isPresent()) {
227-
final AgentRegisterInput inputToSave = optionalInputToSave.get();
228-
setUpdatedEndpointAttributes(endpointToUpdate, inputToSave);
229-
agentToSave = new Agent();
230-
setNewAgentAttributes(inputToSave, agentToSave);
231-
setUpdatedAgentAttributes(agentToSave, inputToSave, endpointToUpdate);
232-
endpointsToSave.add(endpointToUpdate);
233-
agentsToSave.add(agentToSave);
234-
inputs.removeIf(
235-
input -> Arrays.equals(input.getMacAddresses(), inputToSave.getMacAddresses()));
227+
// If no existing agent Crowdstrike in this endpoint, add to it
228+
if (existingAgents.stream()
229+
.noneMatch(agent -> agent.getAsset().getId().equals(endpointToUpdate.getId()))) {
230+
final AgentRegisterInput inputToSave = optionalInputToSave.get();
231+
setUpdatedEndpointAttributes(endpointToUpdate, inputToSave);
232+
agentToSave = new Agent();
233+
setNewAgentAttributes(inputToSave, agentToSave);
234+
setUpdatedAgentAttributes(agentToSave, inputToSave, endpointToUpdate);
235+
endpointsToSave.add(endpointToUpdate);
236+
agentsToSave.add(agentToSave);
237+
inputs.removeIf(
238+
input -> Arrays.equals(input.getMacAddresses(), inputToSave.getMacAddresses()));
239+
}
236240
}
237241
}
238242
}

0 commit comments

Comments
 (0)