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
2021-05-04 12:23:34 +00:00
import org.apache.camel.main.Main ;
2021-05-10 14:56:56 +00:00
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 ;
2021-05-08 16:55:37 +00:00
import java.net.InetAddress ;
2021-05-07 15:53:47 +00:00
import java.net.URL ;
2021-05-10 14:56:56 +00:00
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
2021-05-10 14:56:56 +00:00
private static final Logger log = LoggerFactory . getLogger ( Application . class ) ;
2021-05-08 16:55:37 +00:00
@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
2021-05-11 13:37:23 +00:00
@CommandLine.Option ( names = { " -n " , " --hostname " } , description = " Client hostname (default: <hostname>). " , paramLabel = " <name> " )
2021-05-08 16:55:37 +00:00
private String hostname ;
2021-05-13 17:28:31 +00:00
@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-05-04 12:23:34 +00:00
}
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
2021-05-08 16:55:37 +00:00
if ( hostname = = null | | hostname . isEmpty ( ) ) {
2021-05-10 14:56:56 +00:00
try {
hostname = InetAddress . getLocalHost ( ) . getHostName ( ) ;
} catch ( UnknownHostException e ) {
log . warn ( e . getMessage ( ) ) ;
hostname = " unknown " ;
}
2021-05-08 16:55:37 +00:00
}
2021-05-13 17:28:31 +00:00
String pf4jPluginsDir = System . getProperty ( " pf4j.pluginsDir " ) ;
if ( pf4jPluginsDir ! = null ) {
pluginPath = pf4jPluginsDir ;
}
2021-05-07 15:53:47 +00:00
Main main = new Main ( ) ;
2021-05-13 17:28:31 +00:00
main . bind ( " pluginPath " , pluginPath ) ;
2021-05-07 15:53:47 +00:00
main . bind ( " myServerUrl " , serverUrl . toString ( ) ) ;
2021-05-08 16:55:37 +00:00
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