Added configuration file for list ip cli command.
This commit is contained in:
parent
0458382f86
commit
da1af17b04
2 changed files with 75 additions and 3 deletions
|
@ -118,7 +118,7 @@ public final class StatoolInfosCLI
|
|||
message.appendln();
|
||||
message.appendln(" statoolinfos list file <logfilesorconfigfile> display http access log files");
|
||||
message.appendln(" statoolinfos list log [-bot|-nobot] <logfilesorconfigfile> display http access log lines");
|
||||
message.appendln(" statoolinfos list ip [-bot|-nobot] <logfiles> generate ip list from http log file");
|
||||
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] <logfiles> 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");
|
||||
|
@ -313,6 +313,19 @@ public final class StatoolInfosCLI
|
|||
}
|
||||
System.out.println(chrono.format());
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "list", "ip", "(-all|-bot|-nobot)", ".+\\.conf*"))
|
||||
{
|
||||
BotFilter filter = parseLogFilterOption(args[2]);
|
||||
File configurationFile = new File(StringUtils.trim(args[3]));
|
||||
|
||||
StatoolInfos.listIps(configurationFile, filter);
|
||||
}
|
||||
else if (CLIUtils.isMatching(args, "list", "ip", ".+\\.conf"))
|
||||
{
|
||||
File configurationFile = new File(StringUtils.trim(args[2]));
|
||||
|
||||
StatoolInfos.listIps(configurationFile, BotFilter.ALL);
|
||||
}
|
||||
else if (CLIUtils.isMatchingEllipsis(args, "list", "ip", "(-all|-bot|-nobot)", ".+"))
|
||||
{
|
||||
BotFilter filter = parseLogFilterOption(args[2]);
|
||||
|
|
|
@ -223,6 +223,65 @@ public class StatoolInfos
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List ips.
|
||||
*
|
||||
* @param configurationFile
|
||||
* the configuration file
|
||||
* @param filter
|
||||
* the filter
|
||||
*/
|
||||
public static void listIps(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);
|
||||
}
|
||||
}
|
||||
|
||||
for (IpStat stat : stator.getIps())
|
||||
{
|
||||
System.out.println(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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* List ips.
|
||||
*
|
||||
|
@ -235,9 +294,9 @@ public class StatoolInfos
|
|||
{
|
||||
try
|
||||
{
|
||||
IpStator stator = new IpStator();
|
||||
|
||||
Chrono chrono = new Chrono().start();
|
||||
|
||||
IpStator stator = new IpStator();
|
||||
HttpAccessLogs logs = new HttpAccessLogs(source);
|
||||
for (HttpAccessLog log : logs)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue