sysmon/client/src/main/java/sysmon/client/Application.java

73 lines
2.3 KiB
Java
Raw Normal View History

2021-04-25 13:25:20 +00:00
/*
* This Java source file was generated by the Gradle 'init' task.
*/
2021-05-21 09:08:43 +00:00
package sysmon.client;
2021-04-25 13:25:20 +00:00
import org.apache.camel.main.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2021-05-07 15:53:47 +00:00
import picocli.CommandLine;
2021-04-25 13:25:20 +00:00
2021-05-07 15:53:47 +00:00
import java.io.IOException;
import java.net.InetAddress;
2021-05-07 15:53:47 +00:00
import java.net.URL;
import java.net.UnknownHostException;
2021-05-07 15:53:47 +00:00
import java.util.concurrent.Callable;
2021-04-25 13:25:20 +00:00
2021-05-07 15:53:47 +00:00
@CommandLine.Command(name = "sysmon-client", mixinStandardHelpOptions = true)
public class Application implements Callable<Integer> {
2021-05-01 12:44:55 +00:00
private static final Logger log = LoggerFactory.getLogger(Application.class);
@CommandLine.Option(names = { "-s", "--server-url" }, description = "Server URL (default: ${DEFAULT-VALUE}).", defaultValue = "http://127.0.0.1:9925/metrics", paramLabel = "<url>")
2021-05-07 15:53:47 +00:00
private URL serverUrl;
2021-05-01 12:44:55 +00:00
@CommandLine.Option(names = { "-n", "--hostname" }, description = "Client hostname (default: <hostname>).", paramLabel = "<name>")
private String hostname;
@CommandLine.Option(names = { "-p", "--plugin-dir" }, description = "Plugin jar path (default: ${DEFAULT-VALUE}).", paramLabel = "<path>", defaultValue = "/opt/sysmon/plugins")
private String pluginPath;
2021-04-25 13:25:20 +00:00
2021-05-07 15:53:47 +00:00
public static void main(String... args) {
int exitCode = new CommandLine(new Application()).execute(args);
System.exit(exitCode);
}
2021-04-25 13:25:20 +00:00
2021-05-07 15:53:47 +00:00
@Override
public Integer call() throws IOException {
2021-05-01 12:44:55 +00:00
if(hostname == null || hostname.isEmpty()) {
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
log.warn(e.getMessage());
hostname = "unknown";
}
}
String pf4jPluginsDir = System.getProperty("pf4j.pluginsDir");
if(pf4jPluginsDir != null) {
pluginPath = pf4jPluginsDir;
}
2021-05-07 15:53:47 +00:00
Main main = new Main();
main.bind("pluginPath", pluginPath);
2021-05-07 15:53:47 +00:00
main.bind("myServerUrl", serverUrl.toString());
main.bind("myHostname", hostname);
2021-05-07 15:53:47 +00:00
main.configure().addRoutesBuilder(ClientRouteBuilder.class);
2021-05-01 12:44:55 +00:00
2021-05-07 15:53:47 +00:00
// now keep the application running until the JVM is terminated (ctrl + c or sigterm)
try {
main.run();
} catch (Exception e) {
System.err.println(e.getMessage());
2021-04-25 13:25:20 +00:00
}
2021-05-07 15:53:47 +00:00
return 0;
2021-05-01 12:44:55 +00:00
2021-04-25 13:25:20 +00:00
}
2021-05-01 12:44:55 +00:00
2021-04-25 13:25:20 +00:00
}
2021-05-07 15:53:47 +00:00