Skip to content

Commit cfc1159

Browse files
committed
fix monitoring
1 parent 8779839 commit cfc1159

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

monitoring/src/main/java/io/sentrius/agent/monitoring/service/RegisteredMonitoringAgent.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
import io.sentrius.sso.core.dto.agents.AgentExecution;
77
import io.sentrius.sso.core.dto.capabilities.EndpointDescriptor;
88
import io.sentrius.sso.core.exceptions.ZtatException;
9+
import io.sentrius.sso.core.model.security.Ztat;
910
import io.sentrius.sso.core.services.agents.AgentClientService;
1011
import io.sentrius.sso.core.services.agents.AgentExecutionService;
1112
import io.sentrius.sso.core.services.agents.ZeroTrustClientService;
13+
import io.sentrius.sso.core.utils.JsonUtil;
1214
import jakarta.annotation.PreDestroy;
1315
import lombok.extern.slf4j.Slf4j;
1416
import org.springframework.beans.factory.annotation.Autowired;
@@ -19,6 +21,7 @@
1921
import org.springframework.stereotype.Component;
2022

2123
import 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

Comments
 (0)