diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..c43ea16 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 69ace3f..20e4bc5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,14 @@ + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 1cc9d9b..8d06ae4 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/pklSettings.xml b/.idea/pklSettings.xml new file mode 100644 index 0000000..7171c59 --- /dev/null +++ b/.idea/pklSettings.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hello-world.iml b/hello-world.iml deleted file mode 100644 index c90834f..0000000 --- a/hello-world.iml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/jmonit.iml b/jmonit.iml new file mode 100644 index 0000000..a80f8af --- /dev/null +++ b/jmonit.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/BaseMonitor.java b/src/BaseMonitor.java deleted file mode 100644 index b31d664..0000000 --- a/src/BaseMonitor.java +++ /dev/null @@ -1,69 +0,0 @@ -import java.io.IOException; - -public abstract class BaseMonitor implements Runnable { - private final String friendlyName; - private final String target; - private final int interval; - private final int timeout; - private MonitorStatus prevCheckStatus; - - public enum MonitorStatus { - ONLINE, - OFFLINE, - UNKNOWN - } - public BaseMonitor(String name, String target) { - this.friendlyName = name; - this.target = target; - this.interval = 5000; - this.timeout = 15000; - this.prevCheckStatus = MonitorStatus.UNKNOWN; - } - - public String getFriendlyName() { - return friendlyName; - } - - public String getTarget() { - return target; - } - - public int getInterval() { - return interval; - } - - public int getTimeout() { - return timeout; - } - - public void setPrevCheckStatus(MonitorStatus newStatus) { - this.prevCheckStatus = newStatus; - } - 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) { - System.out.println("Monitor '" + this.getFriendlyName() + "', changed, new status: " + checkStatus); - } - Thread.sleep(this.getInterval()); - } catch (IOException | InterruptedException e) { - throw new RuntimeException(e); - } - } - } -} \ No newline at end of file diff --git a/src/HTTPMonitor.java b/src/HTTPMonitor.java deleted file mode 100644 index bc0fbc4..0000000 --- a/src/HTTPMonitor.java +++ /dev/null @@ -1,19 +0,0 @@ -import javax.net.ssl.HttpsURLConnection; -import java.io.IOException; -import java.net.URI; - -public class HTTPMonitor extends BaseMonitor{ - public HTTPMonitor(String name, String target) { - super(name, target); - } - - @Override - 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; - } -} diff --git a/src/ICMPMonitor.java b/src/ICMPMonitor.java deleted file mode 100644 index 0a32eab..0000000 --- a/src/ICMPMonitor.java +++ /dev/null @@ -1,25 +0,0 @@ -import java.io.IOException; - -public class ICMPMonitor extends BaseMonitor{ - public ICMPMonitor(String name, String target) { - super(name, target); - } - - @Override - 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() { - - } -} \ No newline at end of file diff --git a/src/Main.java b/src/Main.java deleted file mode 100644 index 2c1df4f..0000000 --- a/src/Main.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -public class Main { - public static void main(String[] args) throws InterruptedException { -// ICMPMonitor cloudFlareIcmpMonitor = new ICMPMonitor("Oracle Server 01", "srv01.oci.mzsl.nl"); - HTTPMonitor mzieselHttpMonit = new HTTPMonitor("Website van Mans", "https://mziesel.nl/"); - HTTPMonitor testHttpMonit = new HTTPMonitor("Test website", "https://whoami.mzsl.nl/"); - HTTPMonitor mcaHttpMonit = new HTTPMonitor("Microcenter website", "https://microcenter.nl/"); - - ExecutorService executorService = Executors.newVirtualThreadPerTaskExecutor(); - - executorService.execute(mzieselHttpMonit); - executorService.execute(testHttpMonit); - executorService.execute(mcaHttpMonit); - - while (!executorService.isTerminated()) { - Thread.sleep(1000); - } - } -} \ No newline at end of file