Improve VPS health response DTO and metrics
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.litoralregas.vpnprovisioner.vps;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.litoralregas.vpnprovisioner.vps.dto.VpsHealthResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -14,9 +17,11 @@ public class WireGuardVpsService {
|
||||
Pattern.compile("\\b198\\.19\\.\\d{1,3}\\.\\d{1,3}\\b");
|
||||
|
||||
private final SshService sshService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
public WireGuardVpsService(SshService sshService) {
|
||||
public WireGuardVpsService(SshService sshService, ObjectMapper objectMapper) {
|
||||
this.sshService = sshService;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
public Set<String> findUsedVpnIps() {
|
||||
@@ -66,7 +71,7 @@ public class WireGuardVpsService {
|
||||
);
|
||||
}
|
||||
|
||||
public String getVpsHealthJson() {
|
||||
public VpsHealthResponse getVpsHealth() {
|
||||
SshCommandResult result = sshService.executeOnConfiguredVps(
|
||||
"sudo /usr/local/sbin/lr-vps-health"
|
||||
);
|
||||
@@ -77,7 +82,14 @@ public class WireGuardVpsService {
|
||||
);
|
||||
}
|
||||
|
||||
return result.stdout();
|
||||
try {
|
||||
return objectMapper.readValue(result.stdout(), VpsHealthResponse.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new IllegalStateException(
|
||||
"Invalid VPS health JSON returned by script",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public String restoreLastWireGuardBackup() {
|
||||
|
||||
Reference in New Issue
Block a user