66import io .sentrius .sso .core .dto .agents .AgentExecution ;
77import io .sentrius .sso .core .dto .capabilities .EndpointDescriptor ;
88import io .sentrius .sso .core .exceptions .ZtatException ;
9+ import io .sentrius .sso .core .model .security .Ztat ;
910import io .sentrius .sso .core .services .agents .AgentClientService ;
1011import io .sentrius .sso .core .services .agents .AgentExecutionService ;
1112import io .sentrius .sso .core .services .agents .ZeroTrustClientService ;
13+ import io .sentrius .sso .core .utils .JsonUtil ;
1214import jakarta .annotation .PreDestroy ;
1315import lombok .extern .slf4j .Slf4j ;
1416import org .springframework .beans .factory .annotation .Autowired ;
1921import org .springframework .stereotype .Component ;
2022
2123import java .util .List ;
24+ import java .util .UUID ;
2225
2326/**
2427 * Monitoring Agent - A registered NPE (Non-Person Entity) agent
@@ -85,6 +88,10 @@ public void onApplicationEvent(final ApplicationReadyEvent event) {
8588 while (running ) {
8689 try {
8790 var register = zeroTrustClientService .registerAgent (agentExecution );
91+ var ztat = JsonUtil .MAPPER .readValue (register , Ztat .class );
92+ agentExecution .setZtatToken (ztat .getZtatToken ());
93+ agentExecution .setCommunicationId (ztat .getCommunicationId ());
94+
8895 log .info ("Monitoring Agent registered response: {}" , register );
8996 break ;
9097 } catch (Exception | ZtatException e ) {
@@ -167,6 +174,7 @@ private void initializeDefaultMonitoring() {
167174 try {
168175 UserDTO user = UserDTO .builder ().username (agentName ).build ();
169176 AgentExecution execution = agentExecutionService .getAgentExecution (user );
177+ execution .setCommunicationId (UUID .randomUUID ().toString ());
170178
171179 log .info ("Loading endpoints via AgentClientService..." );
172180 List <EndpointDescriptor > endpoints = agentClientService .getAvailableEndpoints (execution );
@@ -175,9 +183,9 @@ private void initializeDefaultMonitoring() {
175183 if (endpoints != null && !endpoints .isEmpty ()) {
176184 // Register monitoring for discovered endpoints
177185 for (EndpointDescriptor endpoint : endpoints ) {
178- if ("HEALTH" .equalsIgnoreCase (endpoint .getType ()) ||
186+ if ("HEALTH" .equalsIgnoreCase (endpoint .getType ()) || ( endpoint . getPath () != null &&
179187 endpoint .getPath ().contains ("/health" ) ||
180- endpoint .getPath ().contains ("/actuator" )) {
188+ endpoint .getPath ().contains ("/actuator" ))) {
181189
182190 String endpointUrl = endpoint .getPath ();
183191 if (!endpointUrl .startsWith ("http" )) {
0 commit comments