undo changes
This commit is contained in:
parent
af880fff0f
commit
947e581da2
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user