Refactored prober call from CLI.

This commit is contained in:
Christian P. MOMON 2023-02-24 00:46:37 +01:00
parent 9a1b76343e
commit 0555c41c10

View file

@ -22,6 +22,8 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -95,8 +97,7 @@ public class Prober
* @param configuration * @param configuration
* the configuration * the configuration
* @param dayCountFilter * @param dayCountFilter
* the day count filter, 0=today, 1=previous day, 7=previous * the day count filter
* week
* @throws IOException * @throws IOException
* Signals that an I/O exception has occurred. * Signals that an I/O exception has occurred.
* @throws StatoolInfosException * @throws StatoolInfosException
@ -111,168 +112,18 @@ public class Prober
if (!types.isEmpty()) if (!types.isEmpty())
{ {
PathCounters counters = new PathCounters(); PathCounters counters = new PathCounters();
for (String type : types)
//
if (types.containsAnyIgnoreCase("HttpAccessLog"))
{ {
logger.info("== Probing HttpAccessLog."); try
String source = configuration.getProbeHttpAccessLogSource(); {
String pattern = configuration.getProbeHttpAccessLogPattern(); Method method = Prober.class.getMethod("probe" + type, Configuration.class);
String pathFilter = configuration.getProbeHttpAccessLogPathFilter(); PathCounters subCounters = (PathCounters) method.invoke(null, configuration);
logger.info("source=[{}]", source); counters.putAll(subCounters);
logger.info("pattern=[{}]", pattern);
logger.info("path=[{}]", pathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(source), pattern, pathFilter);
PathCounters data = HttpAccessLogAnalyzer.probe(httpAccessLogs);
counters.putAll(data);
} }
catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception)
//
if (types.containsAnyIgnoreCase("HttpErrorLog"))
{ {
logger.info("== Probing HttpErrorLog."); logger.error("Prober not found: [{}]", type);
String source = configuration.getProbeHttpErrorLogSource();
logger.info("source=[{}]", source);
PathCounters data = HttpErrorLogAnalyzer.probe(source);
counters.putAll(data);
} }
//
if (types.containsAnyIgnoreCase("Etherpad"))
{
logger.info("== Probing Etherpad.");
String logs = configuration.get("conf.probe.etherpad.logs");
logger.info("logs=[{}]", logs);
DatabaseConfig database = configuration.getDatabaseConfig("conf.probe.etherpad");
logger.info("database={}", database.toString());
String httpLogs = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("httpLogs=[{}]", httpLogs);
logger.info("httpAccessPattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPathFilter=[{}]", httpAccessPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpLogs), httpAccessLogPattern, httpAccessPathFilter);
PathCounters metrics = EtherpadProber.probe(httpAccessLogs, FilesUtils.searchByWildcard(logs), database);
counters.putAll(metrics);
}
//
if (types.containsAnyIgnoreCase("Framadate"))
{
logger.info("== Probing Framadate.");
String source = configuration.getProbeHttpAccessLogSource();
logger.info("source=[{}]", source);
// PathCounters datafilesPath =
// HttpErrorLogAnalyzer.probe(source);
// counters.putAll(data);
}
//
if (types.containsAnyIgnoreCase("Gitea"))
{
logger.info("== Probing Gitea.");
File dataDirectory = configuration.getAsFile("conf.probe.gitea.data");
logger.info("dataPath=[{}]", dataDirectory);
String apiURL = configuration.get("conf.probe.gitea.api.url");
logger.info("apiURL=[{}]", apiURL);
String apiToken = configuration.get("conf.probe.gitea.api.token");
logger.info("apiToken=[{}]", apiToken == null ? "null" : "************************");
DatabaseConfig database = configuration.getDatabaseConfig("conf.probe.gitea");
logger.info("database={}", database.toString());
String httpLogs = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessLogPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("httpLogs=[{}]", httpLogs);
logger.info("httpAccessPattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPath=[{}]", httpAccessLogPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpLogs), httpAccessLogPattern, httpAccessLogPathFilter);
PathCounters metrics = GiteaProber.probe(httpAccessLogs, apiURL, apiToken, dataDirectory, database);
counters.putAll(metrics);
}
//
if (types.containsAnyIgnoreCase("GSL"))
{
logger.info("== Probing GSL.");
File statsFile = configuration.getAsFile("conf.probe.gsl.stats");
logger.info("statsfile=[{}]", statsFile);
PathCounters data = GSLProber.probe(statsFile);
counters.putAll(data);
}
//
if (types.containsAnyIgnoreCase("LibreQR"))
{
logger.info("== Probing LibreQR.");
String httpAccessSource = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessLogPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("httpAccessSource=[{}]", httpAccessSource);
logger.info("httpAccessPattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPath=[{}]", httpAccessLogPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpAccessSource), httpAccessLogPattern, httpAccessLogPathFilter);
File dataDirectory = configuration.getAsFile("conf.probe.libreqr.datafiles");
logger.info("dataDirectory=[{}]", dataDirectory);
PathCounters data = LibreQRProber.probe(httpAccessLogs, dataDirectory);
counters.putAll(data);
}
//
if (types.containsAnyIgnoreCase("Minetest"))
{
logger.info("== Probing Minetest.");
String source = configuration.get("conf.probe.minetest.logs");
logger.info("source=[{}]", source);
DatabaseConfig playerDatabase = configuration.getDatabaseConfig("conf.probe.minetest.players");
logger.info("players database={}", playerDatabase.toString());
DatabaseConfig worldDatabase = configuration.getDatabaseConfig("conf.probe.minetest.worlds");
logger.info("wordls database={}", worldDatabase.toString());
PathCounters data = MinetestProber.probe(source, playerDatabase, worldDatabase);
counters.putAll(data);
}
//
if (types.containsAnyIgnoreCase("Mumble"))
{
logger.info("== Probing Mumble.");
String source = configuration.get("conf.probe.mumble.logs");
logger.info("source=[{}]", source);
PathCounters data = MumbleProber.probe(source);
counters.putAll(data);
}
//
if (types.containsAnyIgnoreCase("PrivateBin"))
{
logger.info("== Probing Privatebin.");
String httpAccessLogSource = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessLogPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("source=[{}]", httpAccessLogSource);
logger.info("pattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPath=[{}]", httpAccessLogPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpAccessLogSource), httpAccessLogPattern, httpAccessLogPathFilter);
File dataDirectory = configuration.getAsFile("conf.probe.privatebin.data");
logger.info("dataDirectory=[{}]", dataDirectory);
PathCounters data = PrivatebinProber.probe(httpAccessLogs, dataDirectory);
counters.putAll(data);
} }
// Filter. // Filter.
@ -353,6 +204,302 @@ public class Prober
probe(configuration, dayCountFilter); probe(configuration, dayCountFilter);
} }
/**
* Probe etherpad.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeEtherpad(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing Etherpad.");
String logs = configuration.get("conf.probe.etherpad.logs");
DatabaseConfig database = configuration.getDatabaseConfig("conf.probe.etherpad");
logger.info("logs=[{}]", logs);
logger.info("database={}", database.toString());
String httpLogs = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("httpLogs=[{}]", httpLogs);
logger.info("httpAccessPattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPathFilter=[{}]", httpAccessPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpLogs), httpAccessLogPattern, httpAccessPathFilter);
result = EtherpadProber.probe(httpAccessLogs, FilesUtils.searchByWildcard(logs), database);
//
return result;
}
/**
* Probe framadate.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeFramadate(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing Framadate.");
String source = configuration.getProbeHttpAccessLogSource();
logger.info("source=[{}]", source);
// TODO
// PathCounters datafilesPath =
// HttpErrorLogAnalyzer.probe(source);
// counters.putAll(data);
result = new PathCounters();
//
return result;
}
/**
* Probe gitea.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeGitea(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing Gitea.");
File dataDirectory = configuration.getAsFile("conf.probe.gitea.data");
String apiURL = configuration.get("conf.probe.gitea.api.url");
String apiToken = configuration.get("conf.probe.gitea.api.token");
DatabaseConfig database = configuration.getDatabaseConfig("conf.probe.gitea");
logger.info("dataPath=[{}]", dataDirectory);
logger.info("apiURL=[{}]", apiURL);
logger.info("apiToken=[{}]", apiToken == null ? "null" : "************************");
logger.info("database={}", database.toString());
String httpLogs = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessLogPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("httpLogs=[{}]", httpLogs);
logger.info("httpAccessPattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPath=[{}]", httpAccessLogPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpLogs), httpAccessLogPattern, httpAccessLogPathFilter);
result = GiteaProber.probe(httpAccessLogs, apiURL, apiToken, dataDirectory, database);
//
return result;
}
/**
* Probe GSL.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeGSL(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing GSL.");
File statsFile = configuration.getAsFile("conf.probe.gsl.stats");
logger.info("statsfile=[{}]", statsFile);
result = GSLProber.probe(statsFile);
//
return result;
}
/**
* Probe htt access log.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeHttpAccessLog(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing HttpAccessLog.");
String source = configuration.getProbeHttpAccessLogSource();
String pattern = configuration.getProbeHttpAccessLogPattern();
String pathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("source=[{}]", source);
logger.info("pattern=[{}]", pattern);
logger.info("path=[{}]", pathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(source), pattern, pathFilter);
result = HttpAccessLogAnalyzer.probe(httpAccessLogs);
//
return result;
}
public static PathCounters probeHttpErrorLog(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing HttpErrorLog.");
String source = configuration.getProbeHttpErrorLogSource();
logger.info("source=[{}]", source);
result = HttpErrorLogAnalyzer.probe(source);
//
return result;
}
/**
* Probe libre QR.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeLibreQR(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing LibreQR.");
String httpAccessSource = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessLogPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("httpAccessSource=[{}]", httpAccessSource);
logger.info("httpAccessPattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPath=[{}]", httpAccessLogPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpAccessSource), httpAccessLogPattern, httpAccessLogPathFilter);
File dataDirectory = configuration.getAsFile("conf.probe.libreqr.datafiles");
logger.info("dataDirectory=[{}]", dataDirectory);
result = LibreQRProber.probe(httpAccessLogs, dataDirectory);
//
return result;
}
/**
* Probe minetest.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeMinetest(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing Minetest.");
String source = configuration.get("conf.probe.minetest.logs");
DatabaseConfig playerDatabase = configuration.getDatabaseConfig("conf.probe.minetest.players");
DatabaseConfig worldDatabase = configuration.getDatabaseConfig("conf.probe.minetest.worlds");
logger.info("source=[{}]", source);
logger.info("players database={}", playerDatabase.toString());
logger.info("wordls database={}", worldDatabase.toString());
result = MinetestProber.probe(source, playerDatabase, worldDatabase);
//
return result;
}
/**
* Probe mumble.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probeMumble(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing Mumble.");
String source = configuration.get("conf.probe.mumble.logs");
logger.info("source=[{}]", source);
result = MumbleProber.probe(source);
//
return result;
}
/**
* Probe private bin.
*
* @param configuration
* the configuration
* @return the path counters
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws StatoolInfosException
* the statool infos exception
*/
public static PathCounters probePrivateBin(final Configuration configuration) throws IOException, StatoolInfosException
{
PathCounters result;
logger.info("== Probing Privatebin.");
String httpAccessLogSource = configuration.getProbeHttpAccessLogSource();
String httpAccessLogPattern = configuration.getProbeHttpAccessLogPattern();
String httpAccessLogPathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("source=[{}]", httpAccessLogSource);
logger.info("pattern=[{}]", httpAccessLogPattern);
logger.info("httpAccessPath=[{}]", httpAccessLogPathFilter);
HttpAccessLogs httpAccessLogs = new HttpAccessLogs(FilesUtils.searchByWildcard(httpAccessLogSource), httpAccessLogPattern, httpAccessLogPathFilter);
File dataDirectory = configuration.getAsFile("conf.probe.privatebin.data");
logger.info("dataDirectory=[{}]", dataDirectory);
result = PrivatebinProber.probe(httpAccessLogs, dataDirectory);
//
return result;
}
/** /**
* Read metrics. * Read metrics.
* *