Add VPS health endpoint

This commit is contained in:
litoral05
2026-05-07 15:38:47 +01:00
parent 8b849e6560
commit 66adf1b42b
2 changed files with 35 additions and 1 deletions
@@ -0,0 +1,20 @@
package com.litoralregas.vpnprovisioner.vps;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/vps")
public class VpsController {
private final WireGuardVpsService wireGuardVpsService;
public VpsController(WireGuardVpsService wireGuardVpsService) {
this.wireGuardVpsService = wireGuardVpsService;
}
@GetMapping(value = "/health", produces = MediaType.APPLICATION_JSON_VALUE)
public String health() {
return wireGuardVpsService.getVpsHealthJson();
}
}
@@ -21,7 +21,7 @@ public class WireGuardVpsService {
public Set<String> findUsedVpnIps() {
SshCommandResult result = sshService.executeOnConfiguredVps(
"sudo wg show wg0 allowed-ips"
"sudo /usr/local/sbin/lr-wg-used-ips"
);
if (result.exitCode() != 0) {
@@ -65,4 +65,18 @@ public class WireGuardVpsService {
true
);
}
public String getVpsHealthJson() {
SshCommandResult result = sshService.executeOnConfiguredVps(
"sudo /usr/local/sbin/lr-vps-health"
);
if (result.exitCode() != 0) {
throw new SshCommandException(
"Failed to query VPS health: " + result.stderr()
);
}
return result.stdout();
}
}