Added configuration file for stat ip cli command.

This commit is contained in:
Christian P. MOMON 2023-07-03 19:15:30 +02:00
parent 7af1766f4f
commit 8564cef205
2 changed files with 74 additions and 1 deletions

View file

@ -121,7 +121,7 @@ public final class StatoolInfosCLI
message.appendln(" statoolinfos list ip [-bot|-nobot] <logfilesorconfigfile> generate ip list from http log file");
message.appendln(" statoolinfos list ua [-bot|-nobot] <logfilesorconfigfile> generate user agent list from http log file");
message.appendln(" statoolinfos list visitor [-bot|-nobot] <logfilesorconfigfile> generate visitors (ip+ua) list from http log file");
message.appendln(" statoolinfos stat ip [-bot|-nobot] <logfiles> generate stats about ip from http log file");
message.appendln(" statoolinfos stat ip [-bot|-nobot] <logfilesorconfigfile> generate stats about ip from http log file");
message.appendln(" statoolinfos stat ua [-bot|-nobot] <logfiles> generate stats about user agent from http log file");
message.appendln(" statoolinfos stat visitor [-bot|-nobot] <logfiles> generate stats about visitor (ip+ua) from http log file");
@ -518,6 +518,19 @@ public final class StatoolInfosCLI
exception.printStackTrace();
}
}
else if (CLIUtils.isMatching(args, "stat", "ip", "(-all|-bot|-nobot)", ".+\\.conf*"))
{
BotFilter filter = parseLogFilterOption(args[2]);
File configurationFile = new File(StringUtils.trim(args[3]));
StatoolInfos.statIps(configurationFile, filter);
}
else if (CLIUtils.isMatching(args, "stat", "ip", ".+\\.conf"))
{
File configurationFile = new File(StringUtils.trim(args[2]));
StatoolInfos.statIps(configurationFile, BotFilter.ALL);
}
else if (CLIUtils.isMatchingEllipsis(args, "stat", "ip", "(-all|-bot|-nobot)", ".+"))
{
BotFilter filter = parseLogFilterOption(args[2]);

View file

@ -647,6 +647,66 @@ public class StatoolInfos
Prober.probe(configurationFile, dayCountFilter);
}
/**
* Stat ips.
*
* @param configurationFile
* the configuration file
* @param filter
* the filter
*/
public static void statIps(final File configurationFile, final BotFilter filter)
{
try
{
if ((configurationFile == null) || (!configurationFile.exists()))
{
System.out.println("No configuration file found.");
}
else
{
System.out.println("Testing HttpAccesLog lines from [" + configurationFile.toString() + "]");
Configuration configuration = Factory.loadConfiguration(configurationFile);
logger.info("== Testing HttpAccessLog lines.");
String source = configuration.getProbeHttpAccessLogSource();
String dateTimePattern = configuration.getProbeHttpAccessLogDateTimePattern();
String pattern = configuration.getProbeHttpAccessLogPattern();
String pathFilter = configuration.getProbeHttpAccessLogPathFilter();
logger.info("source=[{}]", source);
logger.info("pattern=[{}]", pattern);
logger.info("dateTimePattern=[{}]", dateTimePattern);
logger.info("pathFilter=[{}]", pathFilter);
Chrono chrono = new Chrono().start();
IpStator stator = new IpStator();
HttpAccessLogs logs = new HttpAccessLogs(FilesUtils.searchByWildcard(source), pattern, dateTimePattern, pathFilter);
for (HttpAccessLog log : logs)
{
if (filter.matches(log))
{
stator.putLog(log);
}
}
System.err.println("IpCount Ip");
for (IpStat stat : stator.getIps().sortByCount().reverse())
{
System.out.println(stat.getCount() + " " + stat.getValue());
}
System.err.println(String.format("%s %10d", "Ip count: ", stator.getIps().size()));
System.err.println(String.format("%s %10d", "Log count: ", stator.getLogCount()));
System.err.println(chrono.format());
}
}
catch (Exception exception)
{
logger.error("Error: {}", exception.getMessage());
exception.printStackTrace();
}
}
/**
* Stat ips.
*