Add VPS health endpoint
This commit is contained in:
@@ -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() {
|
public Set<String> findUsedVpnIps() {
|
||||||
SshCommandResult result = sshService.executeOnConfiguredVps(
|
SshCommandResult result = sshService.executeOnConfiguredVps(
|
||||||
"sudo wg show wg0 allowed-ips"
|
"sudo /usr/local/sbin/lr-wg-used-ips"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.exitCode() != 0) {
|
if (result.exitCode() != 0) {
|
||||||
@@ -65,4 +65,18 @@ public class WireGuardVpsService {
|
|||||||
true
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user