undo changes

This commit is contained in:
Mans Ziesel 2024-02-04 14:43:36 +01:00
parent af880fff0f
commit 947e581da2
3 changed files with 5 additions and 28 deletions

View File

@ -41,23 +41,14 @@ public abstract class BaseMonitor implements Runnable {
}
public abstract MonitorStatus check() throws IOException, InterruptedException;
// public void checkCmd() throws IOException, InterruptedException {
// MonitorStatus currStatus = this.check();
//
// if (currStatus == MonitorStatus.ONLINE) {
// System.out.println(this.getFriendlyName() + ", with address '" + this.getTarget() + "' is online!");
// } else if (currStatus == MonitorStatus.OFFLINE) {
// System.out.println(this.getFriendlyName() + ", with address '" + this.getTarget() + "' is offline!");
// }
// }
@Override
public void run() {
System.out.println("Monitor '" + this.friendlyName + "' start status: " + this.prevCheckStatus);
while (true) {
try {
MonitorStatus prevStatus = this.prevCheckStatus;
MonitorStatus checkStatus = this.check();
if (prevStatus != checkStatus) {
if (this.prevCheckStatus != checkStatus) {
this.setPrevCheckStatus(checkStatus);
System.out.println("Monitor '" + this.getFriendlyName() + "', changed, new status: " + checkStatus);
}
Thread.sleep(this.getInterval());

View File

@ -11,9 +11,6 @@ public class HTTPMonitor extends BaseMonitor{
public MonitorStatus check() throws IOException {
URI uri = URI.create(super.getTarget());
HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection();
MonitorStatus checkStatus = (conn.getResponseCode() == 200) ? MonitorStatus.ONLINE : MonitorStatus.OFFLINE;
super.setPrevCheckStatus(checkStatus);
return checkStatus;
return (conn.getResponseCode() == 200) ? MonitorStatus.ONLINE : MonitorStatus.OFFLINE;
}
}

View File

@ -9,17 +9,6 @@ public class ICMPMonitor extends BaseMonitor{
public MonitorStatus check() throws IOException, InterruptedException {
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 " + this.getTarget());
int returnVal = p1.waitFor();
if (returnVal==0) {
return MonitorStatus.ONLINE;
} else {
return MonitorStatus.OFFLINE;
}
// InetAddress address = InetAddress.getByName(super.getTarget());
// return address.isReachable(super.getTimeout());
}
@Override
public void run() {
return (returnVal == 0) ? MonitorStatus.ONLINE : MonitorStatus.OFFLINE;
}
}