diff --git a/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java b/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java index 4e0df43..0ac7fef 100644 --- a/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java +++ b/src/fr/devinsy/statoolinfos/cli/StatoolInfosCLI.java @@ -119,7 +119,7 @@ public final class StatoolInfosCLI message.appendln(" statoolinfos list file display http access log files"); message.appendln(" statoolinfos list log [-bot|-nobot] display http access log lines"); message.appendln(" statoolinfos list ip [-bot|-nobot] generate ip list from http log file"); - message.appendln(" statoolinfos list ua [-bot|-nobot] generate user agent list from http log file"); + message.appendln(" statoolinfos list ua [-bot|-nobot] generate user agent list from http log file"); message.appendln(" statoolinfos list visitor [-bot|-nobot] generate visitors (ip+ua) list from http log file"); message.appendln(" statoolinfos stat ip [-bot|-nobot] generate stats about ip from http log file"); message.appendln(" statoolinfos stat ua [-bot|-nobot] generate stats about user agent from http log file"); @@ -384,6 +384,19 @@ public final class StatoolInfosCLI StatoolInfos.listLogs(source, BotFilter.ALL); } + else if (CLIUtils.isMatching(args, "list", "(useragent|ua)", "(-all|-bot|-nobot)", ".+\\.conf*")) + { + BotFilter filter = parseLogFilterOption(args[2]); + File configurationFile = new File(StringUtils.trim(args[3])); + + StatoolInfos.listUserAgents(configurationFile, filter); + } + else if (CLIUtils.isMatching(args, "list", "(useragent|ua)", ".+\\.conf")) + { + File configurationFile = new File(StringUtils.trim(args[2])); + + StatoolInfos.listUserAgents(configurationFile, BotFilter.ALL); + } else if (CLIUtils.isMatchingEllipsis(args, "list", "(useragent|ua)", "(-all|-bot|-nobot)", ".+")) { BotFilter filter = parseLogFilterOption(args[2]); diff --git a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java index a1e1c41..812d49f 100644 --- a/src/fr/devinsy/statoolinfos/core/StatoolInfos.java +++ b/src/fr/devinsy/statoolinfos/core/StatoolInfos.java @@ -358,6 +358,66 @@ public class StatoolInfos } } + /** + * List user agents. + * + * @param configurationFile + * the configuration file + * @param filter + * the filter + */ + public static void listUserAgents(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(); + UserAgentStator stator = new UserAgentStator(); + HttpAccessLogs logs = new HttpAccessLogs(FilesUtils.searchByWildcard(source), pattern, dateTimePattern, pathFilter); + + for (HttpAccessLog log : logs) + { + if (filter.matches(log)) + { + stator.putLog(log); + } + } + + for (UserAgentStat stat : stator.getUserAgentStats().sortByLabel()) + { + System.out.println(stat.getUserAgent()); + } + + System.err.println(String.format("%s %10d", "UserAgent count: ", stator.getUserAgentStats().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 user agents. *