first commit
This commit is contained in:
commit
1a20bfc01c
29
.gitignore
vendored
Normal file
29
.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
### IntelliJ IDEA ###
|
||||||
|
out/
|
||||||
|
!**/src/main/**/out/
|
||||||
|
!**/src/test/**/out/
|
||||||
|
|
||||||
|
### Eclipse ###
|
||||||
|
.apt_generated
|
||||||
|
.classpath
|
||||||
|
.factorypath
|
||||||
|
.project
|
||||||
|
.settings
|
||||||
|
.springBeans
|
||||||
|
.sts4-cache
|
||||||
|
bin/
|
||||||
|
!**/src/main/**/bin/
|
||||||
|
!**/src/test/**/bin/
|
||||||
|
|
||||||
|
### NetBeans ###
|
||||||
|
/nbproject/private/
|
||||||
|
/nbbuild/
|
||||||
|
/dist/
|
||||||
|
/nbdist/
|
||||||
|
/.nb-gradle/
|
||||||
|
|
||||||
|
### VS Code ###
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
### Mac OS ###
|
||||||
|
.DS_Store
|
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/hello-world.iml" filepath="$PROJECT_DIR$/hello-world.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
2
README.md
Normal file
2
README.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# jmonit
|
||||||
|
Java Monitor, a simple monitoring application inspired by uptime kuma.
|
11
hello-world.iml
Normal file
11
hello-world.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
41
src/BaseMonitor.java
Normal file
41
src/BaseMonitor.java
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public abstract class BaseMonitor {
|
||||||
|
private final String friendlyName;
|
||||||
|
private final String target;
|
||||||
|
private final int interval;
|
||||||
|
private final int timeout;
|
||||||
|
|
||||||
|
public BaseMonitor(String name, String target) {
|
||||||
|
this.friendlyName = name;
|
||||||
|
this.target = target;
|
||||||
|
this.interval = 120;
|
||||||
|
this.timeout = 5000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFriendlyName() {
|
||||||
|
return friendlyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInterval() {
|
||||||
|
return interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeout() {
|
||||||
|
return timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract boolean check() throws IOException;
|
||||||
|
|
||||||
|
public void checkCmd() throws IOException {
|
||||||
|
if (this.check()) {
|
||||||
|
System.out.println(this.getFriendlyName() + ", with address '" + this.getTarget() + "' is online!");
|
||||||
|
} else {
|
||||||
|
System.out.println(this.getFriendlyName() + ", with address '" + this.getTarget() + "' is offline!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
src/HTTPMonitor.java
Normal file
16
src/HTTPMonitor.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
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 boolean check() throws IOException {
|
||||||
|
URI uri = URI.create(super.getTarget());
|
||||||
|
HttpsURLConnection conn = (HttpsURLConnection) uri.toURL().openConnection();
|
||||||
|
return conn.getResponseCode() == 200;
|
||||||
|
}
|
||||||
|
}
|
14
src/ICMPMonitor.java
Normal file
14
src/ICMPMonitor.java
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
|
||||||
|
public class ICMPMonitor extends BaseMonitor{
|
||||||
|
public ICMPMonitor(String name, String target) {
|
||||||
|
super(name, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check() throws IOException {
|
||||||
|
InetAddress address = InetAddress.getByName(super.getTarget());
|
||||||
|
return address.isReachable(super.getTimeout());
|
||||||
|
}
|
||||||
|
}
|
11
src/Main.java
Normal file
11
src/Main.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
ICMPMonitor cloudFlareIcmpMonitor = new ICMPMonitor("Oracle Server 01", "srv01.oci.mzsl.nl");
|
||||||
|
HTTPMonitor mzieselHttpMonit = new HTTPMonitor("Website van Mans", "https://mziesel.nl/bestaat-niet");
|
||||||
|
|
||||||
|
cloudFlareIcmpMonitor.checkCmd();
|
||||||
|
mzieselHttpMonit.checkCmd();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user