Added CLI commands to test HttpAccessLog files and lines.
This commit is contained in:
parent
580d2ff447
commit
8fdafcdf1d
2 changed files with 102 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2022 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2023 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
@ -122,6 +122,8 @@ public final class StatoolInfosCLI
|
|||
message.appendln(" statoolinfos stat ip [-bot|-nobot] <fileordirectory> generate stats about ip from http log file");
|
||||
message.appendln(" statoolinfos stat ua [-bot|-nobot] <fileordirectory> generate stats about user agent from http log file");
|
||||
message.appendln(" statoolinfos stat visitors [-bot|-nobot] <fileordirectory> generate stats about visitors (ip+ua) from http log file");
|
||||
message.appendln(" statoolinfos test HttpAccessLog -files <configurationfile> display log files from the configuration file");
|
||||
message.appendln(" statoolinfos test HttpAccessLog -lines <configurationfile> display log lines from the configuration file");
|
||||
|
||||
System.out.print(message.toString());
|
||||
}
|
||||
|
@ -549,6 +551,33 @@ public final class StatoolInfosCLI
|
|||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (isMatching(args, "test", "HttpAccessLog", "-files", "\\s*.+\\.conf\\s*"))
|
||||
{
|
||||
File configurationFile = new File(StringUtils.trim(args[3]));
|
||||
try
|
||||
{
|
||||
StatoolInfos.testHttpAccessLogFiles(configurationFile);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
else if (isMatching(args, "test", "HttpAccessLog", "-lines", "\\s*.+\\.conf\\s*"))
|
||||
{
|
||||
File configurationFile = new File(StringUtils.trim(args[3]));
|
||||
|
||||
try
|
||||
{
|
||||
StatoolInfos.testHttpAccessLogLines(configurationFile);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
logger.error("Error with [{}]: {}", configurationFile.getAbsoluteFile(), exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Bad usage.");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2020-2022 Christian Pierre MOMON <christian@momon.org>
|
||||
* Copyright (C) 2020-2023 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
|
@ -36,6 +36,7 @@ import fr.devinsy.statoolinfos.metrics.Prober;
|
|||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLog;
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogIterator;
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogParser;
|
||||
import fr.devinsy.statoolinfos.metrics.http.HttpAccessLogs;
|
||||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
|
||||
import fr.devinsy.statoolinfos.stats.ip.IpStat;
|
||||
|
@ -48,6 +49,7 @@ import fr.devinsy.statoolinfos.uptime.UptimeJournal;
|
|||
import fr.devinsy.statoolinfos.uptime.UptimeSurveyor;
|
||||
import fr.devinsy.statoolinfos.util.Chrono;
|
||||
import fr.devinsy.statoolinfos.util.Files;
|
||||
import fr.devinsy.statoolinfos.util.FilesUtils;
|
||||
import fr.devinsy.statoolinfos.util.LineIterator;
|
||||
import fr.devinsy.strings.StringList;
|
||||
import fr.devinsy.strings.StringsUtils;
|
||||
|
@ -549,6 +551,75 @@ public class StatoolInfos
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test http access log files.
|
||||
*
|
||||
* @param configurationFile
|
||||
* the configuration file
|
||||
* @throws IOException
|
||||
* @throws StatoolInfosException
|
||||
*/
|
||||
public static void testHttpAccessLogFiles(final File configurationFile) throws StatoolInfosException, IOException
|
||||
{
|
||||
if ((configurationFile == null) || (!configurationFile.exists()))
|
||||
{
|
||||
System.out.println("No configuration file found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Testing HttpAccesLog files from [" + configurationFile.toString() + "]");
|
||||
Configuration configuration = Factory.loadConfiguration(configurationFile);
|
||||
|
||||
logger.info("== Testing HttpAccessLog files.");
|
||||
String source = configuration.getProbeHttpAccessLogSource();
|
||||
logger.info("source=[{}]", source);
|
||||
|
||||
Files files = FilesUtils.searchByWildcard(source);
|
||||
for (File file : files)
|
||||
{
|
||||
System.out.println(file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test http access log lines.
|
||||
*
|
||||
* @param configurationFile
|
||||
* the configuration file
|
||||
* @throws StatoolInfosException
|
||||
* the statool infos exception
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void testHttpAccessLogLines(final File configurationFile) throws StatoolInfosException, IOException
|
||||
{
|
||||
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 pattern = configuration.getProbeHttpAccessLogPattern();
|
||||
String pathFilter = configuration.getProbeHttpAccessLogPathFilter();
|
||||
logger.info("source=[{}]", source);
|
||||
logger.info("pattern=[{}]", pattern);
|
||||
logger.info("path=[{}]", pathFilter);
|
||||
|
||||
HttpAccessLogs logs = new HttpAccessLogs(FilesUtils.searchByWildcard(source), pattern, pathFilter);
|
||||
|
||||
for (HttpAccessLog log : logs)
|
||||
{
|
||||
System.out.println(log.toStringLog());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uptime.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue