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 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
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("Monitor '" + this.friendlyName + "' start status: " + this.prevCheckStatus);
|
System.out.println("Monitor '" + this.friendlyName + "' start status: " + this.prevCheckStatus);
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
MonitorStatus prevStatus = this.prevCheckStatus;
|
|
||||||
MonitorStatus checkStatus = this.check();
|
MonitorStatus checkStatus = this.check();
|
||||||
if (prevStatus != checkStatus) {
|
if (this.prevCheckStatus != checkStatus) {
|
||||||
|
this.setPrevCheckStatus(checkStatus);
|
||||||
System.out.println("Monitor '" + this.getFriendlyName() + "', changed, new status: " + checkStatus);
|
System.out.println("Monitor '" + this.getFriendlyName() + "', changed, new status: " + checkStatus);
|
||||||
}
|
}
|
||||||
Thread.sleep(this.getInterval());
|
Thread.sleep(this.getInterval());
|
||||||
|
@ -11,9 +11,6 @@ public class HTTPMonitor extends BaseMonitor{
|
|||||||
public MonitorStatus check() throws IOException {
|
public MonitorStatus check() throws IOException {
|
||||||
URI uri = URI.create(super.getTarget());
|
URI uri = URI.create(super.getTarget());
|
||||||
HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection();
|
HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection();
|
||||||
MonitorStatus checkStatus = (conn.getResponseCode() == 200) ? MonitorStatus.ONLINE : MonitorStatus.OFFLINE;
|
return (conn.getResponseCode() == 200) ? MonitorStatus.ONLINE : MonitorStatus.OFFLINE;
|
||||||
|
|
||||||
super.setPrevCheckStatus(checkStatus);
|
|
||||||
return checkStatus;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,6 @@ public class ICMPMonitor extends BaseMonitor{
|
|||||||
public MonitorStatus check() throws IOException, InterruptedException {
|
public MonitorStatus check() throws IOException, InterruptedException {
|
||||||
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 " + this.getTarget());
|
Process p1 = java.lang.Runtime.getRuntime().exec("ping -c 1 " + this.getTarget());
|
||||||
int returnVal = p1.waitFor();
|
int returnVal = p1.waitFor();
|
||||||
if (returnVal==0) {
|
return (returnVal == 0) ? MonitorStatus.ONLINE : MonitorStatus.OFFLINE;
|
||||||
return MonitorStatus.ONLINE;
|
|
||||||
} else {
|
|
||||||
return MonitorStatus.OFFLINE;
|
|
||||||
}
|
|
||||||
// InetAddress address = InetAddress.getByName(super.getTarget());
|
|
||||||
// return address.isReachable(super.getTimeout());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user