+
+
diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java
index 207c954..aaaa362 100644
--- a/src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java
+++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatus.java
@@ -41,7 +41,7 @@ public class HttpStatus
this.code = code;
this.message = message;
this.description = description;
- this.category = HttpStatusCategory.valueOfCode(code);
+ this.category = HttpStatusCategory.of(code);
}
public HttpStatusCategory getCategory()
diff --git a/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java
index 454db65..cd0132a 100644
--- a/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java
+++ b/src/fr/devinsy/statoolinfos/metrics/http/HttpStatusCategory.java
@@ -30,11 +30,11 @@ public enum HttpStatusCategory
SERVER_ERROR,
INVALID;
- public static boolean isClientError(final int code)
+ public static boolean isClientError(final int httpCode)
{
boolean result;
- result = ((code / 100) == 4);
+ result = ((httpCode / 100) == 4);
//
return result;
@@ -45,41 +45,41 @@ public enum HttpStatusCategory
*
* @return true, if is informational
*/
- public static boolean isInformational(final int code)
+ public static boolean isInformational(final int httpCode)
{
boolean result;
- result = ((code / 100) == 1);
+ result = ((httpCode / 100) == 1);
//
return result;
}
- public static boolean isRedirection(final int code)
+ public static boolean isRedirection(final int httpCode)
{
boolean result;
- result = ((code / 100) == 3);
+ result = ((httpCode / 100) == 3);
//
return result;
}
- public static boolean isServerError(final int code)
+ public static boolean isServerError(final int httpCode)
{
boolean result;
- result = ((code / 100) == 5);
+ result = ((httpCode / 100) == 5);
//
return result;
}
- public static boolean isSuccess(final int code)
+ public static boolean isSuccess(final int httpCode)
{
boolean result;
- result = ((code / 100) == 2);
+ result = ((httpCode / 100) == 2);
//
return result;
@@ -88,31 +88,31 @@ public enum HttpStatusCategory
/**
* Value of.
*
- * @param code
+ * @param httpCode
* the code
* @return the http status category
*/
- public static HttpStatusCategory valueOfCode(final int code)
+ public static HttpStatusCategory of(final int httpCode)
{
HttpStatusCategory result;
- if (isInformational(code))
+ if (isInformational(httpCode))
{
result = HttpStatusCategory.INFORMATIONAL;
}
- else if (isSuccess(code))
+ else if (isSuccess(httpCode))
{
result = HttpStatusCategory.SUCCESS;
}
- else if (isRedirection(code))
+ else if (isRedirection(httpCode))
{
result = HttpStatusCategory.REDIRECTION;
}
- else if (isClientError(code))
+ else if (isClientError(httpCode))
{
result = HttpStatusCategory.CLIENT_ERROR;
}
- else if (isServerError(code))
+ else if (isServerError(httpCode))
{
result = HttpStatusCategory.SERVER_ERROR;
}
diff --git a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java
index c8f3b98..e1f4ca2 100644
--- a/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java
+++ b/src/fr/devinsy/statoolinfos/properties/PathPropertyList.java
@@ -716,11 +716,13 @@ public class PathPropertyList extends ArrayList implements PathPro
}
else
{
- result = new URL(value);
+ result = new URL(value.trim());
}
}
catch (MalformedURLException exception)
{
+ logger.error("Error getURL with [" + path + "]");
+ exception.printStackTrace();
result = null;
}
diff --git a/src/fr/devinsy/statoolinfos/stats/StatAgent.java b/src/fr/devinsy/statoolinfos/stats/StatAgent.java
index 9b7e1c0..0956598 100644
--- a/src/fr/devinsy/statoolinfos/stats/StatAgent.java
+++ b/src/fr/devinsy/statoolinfos/stats/StatAgent.java
@@ -87,7 +87,7 @@ public class StatAgent
CategoryStat stat = new CategoryStat(category);
StringSet organizations = new StringSet();
- for (Service service : federation.getAllServices())
+ for (Service service : federation.getServicesAll())
{
String softwareName = service.getSoftwareName();
if (category.getSoftwares().containsIgnoreCase(softwareName))
@@ -195,7 +195,7 @@ public class StatAgent
SoftwareStat stat = new SoftwareStat(software.getName());
stat.getCategories().addAll(categories.findBySoftware(software.getName()));
StringSet organizations = new StringSet();
- for (Service service : federation.getAllServices())
+ for (Service service : federation.getServicesAll())
{
Software current = catalog.get(service.getSoftwareName());
if (current == software)
diff --git a/src/fr/devinsy/statoolinfos/uptime/URLSet.java b/src/fr/devinsy/statoolinfos/uptime/URLSet.java
new file mode 100644
index 0000000..62e9aac
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/URLSet.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class URLSet.
+ *
+ * WARNING: cannot extends HashSet because URL hashcode method resolves
+ * value, so all URL with same IP have the same hashcode.
+ */
+public class URLSet implements Iterable
+{
+ private static Logger logger = LoggerFactory.getLogger(URLSet.class);
+
+ private HashMap map;
+
+ /**
+ * Instantiates a new URL set.
+ */
+ public URLSet()
+ {
+ this.map = new HashMap();
+ }
+
+ /**
+ * Adds the.
+ *
+ * @param url
+ * the url
+ */
+ public void add(final URL url)
+ {
+ if (url != null)
+ {
+ this.map.put(url.toString(), url);
+ }
+ }
+
+ /**
+ * Clear.
+ */
+ public void clear()
+ {
+ this.map.clear();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Iterable#iterator()
+ */
+ @Override
+ public Iterator iterator()
+ {
+ Iterator result;
+
+ result = this.map.values().iterator();
+
+ //
+ return result;
+ }
+
+ /**
+ * Size.
+ *
+ * @return the int
+ */
+ public int size()
+ {
+ int result;
+
+ result = this.map.size();
+
+ //
+ return result;
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/URLs.java b/src/fr/devinsy/statoolinfos/uptime/URLs.java
new file mode 100644
index 0000000..ba3f875
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/URLs.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.net.URL;
+import java.util.ArrayList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class URLs.
+ */
+public class URLs extends ArrayList
+{
+ private static final long serialVersionUID = -2530910138006185902L;
+ private static Logger logger = LoggerFactory.getLogger(URLs.class);
+
+ /**
+ * Instantiates a new URLs.
+ */
+ public URLs()
+ {
+ super();
+ }
+
+ /**
+ * Instantiates a new UR ls.
+ *
+ * @param capacity
+ * the capacity
+ */
+ public URLs(final int capacity)
+ {
+ super(capacity);
+ }
+
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/Uptime.java b/src/fr/devinsy/statoolinfos/uptime/Uptime.java
new file mode 100644
index 0000000..6571373
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/Uptime.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.net.URL;
+import java.time.LocalDateTime;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fr.devinsy.statoolinfos.metrics.http.HttpStatusCategory;
+
+/**
+ * The Class UptimeCheck.
+ */
+public class Uptime
+{
+ private static Logger logger = LoggerFactory.getLogger(Uptime.class);
+
+ private URL url;
+ private LocalDateTime datetime;
+ private int code;
+ private UptimeStatus status;
+
+ /**
+ * Instantiates a new uptime check.
+ *
+ * @param url
+ * the url
+ */
+ public Uptime(final URL url)
+ {
+ this.url = url;
+ this.datetime = null;
+ this.code = 0;
+ this.status = UptimeStatus.VOID;
+ }
+
+ /**
+ * Instantiates a new uptime.
+ *
+ * @param datetime
+ * the datetime
+ * @param status
+ * the status
+ * @param code
+ * the code
+ * @param url
+ * the url
+ */
+ public Uptime(final URL url, final LocalDateTime datetime, final UptimeStatus status, final int code)
+ {
+ this.url = url;
+ this.datetime = datetime;
+ this.code = code;
+ this.status = status;
+ }
+
+ public int getCode()
+ {
+ return this.code;
+ }
+
+ public LocalDateTime getDatetime()
+ {
+ return this.datetime;
+ }
+
+ public UptimeStatus getStatus()
+ {
+ return this.status;
+ }
+
+ public URL getUrl()
+ {
+ return this.url;
+ }
+
+ /**
+ * Update.
+ *
+ * @param code
+ * the code
+ */
+ public void update(final int code)
+ {
+ this.datetime = LocalDateTime.now();
+ this.code = code;
+ if (HttpStatusCategory.isSuccess(code))
+ {
+ this.status = UptimeStatus.OK;
+ }
+ else
+ {
+ this.status = UptimeStatus.ERROR;
+ }
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java
new file mode 100644
index 0000000..e49a4e5
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java
@@ -0,0 +1,314 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.time.LocalDate;
+import java.util.HashMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class UptimeJournal.
+ */
+public class UptimeJournal
+{
+ private static Logger logger = LoggerFactory.getLogger(UptimeJournal.class);
+
+ private HashMap map;
+
+ /**
+ * Instantiates a new uptime journal.
+ */
+ public UptimeJournal()
+ {
+ super();
+ this.map = new HashMap();
+ }
+
+ /**
+ * Adds the.
+ *
+ * @param uptime
+ * the uptime
+ */
+ public void add(final Uptime uptime)
+ {
+ if (uptime != null)
+ {
+ Uptimes uptimes = this.map.get(uptime.getUrl().toString());
+
+ if (uptimes == null)
+ {
+ uptimes = new Uptimes();
+ this.map.put(uptime.getUrl().toString(), uptimes);
+ }
+
+ uptimes.add(uptime);
+ }
+ }
+
+ /**
+ * Adds the all.
+ *
+ * @param uptimes
+ * the uptimes
+ */
+ public void addAll(final Uptimes uptimes)
+ {
+ if (uptimes != null)
+ {
+ for (Uptime uptime : uptimes)
+ {
+ add(uptime);
+ }
+ }
+ }
+
+ /**
+ * Clear.
+ */
+ public void clear()
+ {
+ this.map.clear();
+ }
+
+ /**
+ * Gets the uptime stats.
+ *
+ * @param url
+ * the url
+ * @param date
+ * the date
+ * @return the uptime stats
+ */
+ public UptimeStat getStat(final URL url, final LocalDate date)
+ {
+ UptimeStat result;
+
+ result = new UptimeStat();
+
+ if (url != null)
+ {
+ Uptime older = null;
+ for (Uptime uptime : getUptimes(url, date))
+ {
+ if (uptime.getStatus() == UptimeStatus.OK)
+ {
+ result.incOk();
+ }
+ else if (uptime.getStatus() == UptimeStatus.ERROR)
+ {
+ result.incError();
+ }
+
+ if ((older == null) || (older.getDatetime().isAfter(uptime.getDatetime())))
+ {
+ older = uptime;
+ }
+ }
+ if (older != null)
+ {
+ result.setLastStatus(older.getStatus());
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the status.
+ *
+ * @param url
+ * the url
+ * @param date
+ * the date
+ * @return the status
+ */
+ public UptimeStatus getStatus(final URL url, final LocalDate date)
+ {
+ UptimeStatus result;
+
+ int count = 0;
+ int okCount = 0;
+ int errorCount = 0;
+ for (Uptime uptime : getUptimes(url, date))
+ {
+ count += 1;
+ if (uptime.getStatus() == UptimeStatus.OK)
+ {
+ okCount += 1;
+ }
+ else if (uptime.getStatus() == UptimeStatus.ERROR)
+ {
+ errorCount += 1;
+ }
+ }
+
+ if (count == 0)
+ {
+ result = UptimeStatus.VOID;
+ }
+ else if (okCount == 0)
+ {
+ result = UptimeStatus.ERROR;
+ }
+ else if (errorCount == 1)
+ {
+ result = UptimeStatus.WARNING;
+ }
+ else if (errorCount > 1)
+ {
+ result = UptimeStatus.ERROR;
+ }
+ else
+ {
+ result = UptimeStatus.OK;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the.
+ *
+ * @param url
+ * the url
+ * @return the uptimes
+ */
+ public Uptimes getUptimes(final URL url)
+ {
+ Uptimes result;
+
+ result = this.map.get(url.toString());
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the.
+ *
+ * @param url
+ * the url
+ * @param date
+ * the date
+ * @return the uptimes
+ */
+ public Uptimes getUptimes(final URL url, final LocalDate date)
+ {
+ Uptimes result;
+
+ result = this.map.get(url.toString());
+
+ if (result == null)
+ {
+ result = new Uptimes();
+ }
+ else
+ {
+ result = result.getByDate(date);
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the uptimes all.
+ *
+ * @return the uptimes all
+ */
+ public Uptimes getUptimesAll()
+ {
+ Uptimes result;
+
+ result = new Uptimes();
+
+ for (String urlValue : this.map.keySet())
+ {
+ for (Uptime uptime : this.map.get(urlValue))
+ {
+ result.add(uptime);
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the URL list.
+ *
+ * @return the URL list
+ */
+ public URLs getURLs()
+ {
+ URLs result;
+
+ result = new URLs(this.map.keySet().size());
+ for (String urlValue : this.map.keySet())
+ {
+ try
+ {
+ result.add(new URL(urlValue));
+ }
+ catch (MalformedURLException exception)
+ {
+ exception.printStackTrace();
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Purge.
+ *
+ * @param days
+ * the days
+ */
+ public void purge(final long days)
+ {
+ for (Uptimes uptimes : this.map.values())
+ {
+ uptimes.purge(days);
+ }
+ }
+
+ /**
+ * Size.
+ *
+ * @return the int
+ */
+ public int size()
+ {
+ int result;
+
+ result = this.map.size();
+
+ //
+ return result;
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java
new file mode 100644
index 0000000..d4e50bb
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournalFile.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDateTime;
+
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class UptimeJournalFile.
+ */
+public class UptimeJournalFile
+{
+ private static Logger logger = LoggerFactory.getLogger(UptimeJournalFile.class);
+
+ /**
+ * Instantiates a new uptime journal file.
+ */
+ private UptimeJournalFile()
+ {
+ }
+
+ /**
+ * Load.
+ *
+ * @param file
+ * the file
+ * @return the uptime journal
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static UptimeJournal load(final File file) throws IOException
+ {
+ UptimeJournal result;
+
+ result = load(file, StandardCharsets.UTF_8);
+
+ //
+ return result;
+ }
+
+ /**
+ * Load.
+ *
+ * @param file
+ * the file
+ * @param charset
+ * the charset
+ * @return the uptime journal
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static UptimeJournal load(final File file, final Charset charset) throws IOException
+ {
+ UptimeJournal result;
+
+ if (file == null)
+ {
+ throw new IllegalArgumentException("File parameter is null.");
+ }
+ else
+ {
+ BufferedReader in = null;
+ try
+ {
+ in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
+ result = read(in);
+ }
+ finally
+ {
+ IOUtils.closeQuietly(in);
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Read.
+ *
+ * @param in
+ * the in
+ * @return the uptime journal
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static UptimeJournal read(final BufferedReader in) throws IOException
+ {
+ UptimeJournal result;
+
+ result = new UptimeJournal();
+
+ boolean ended = false;
+ while (!ended)
+ {
+ String line = in.readLine();
+
+ if (line == null)
+ {
+ ended = true;
+ }
+ else
+ {
+ Uptime uptime = valueOf(line);
+ result.add(uptime);
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Save.
+ *
+ * @param file
+ * the file
+ * @param source
+ * the source
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static void save(final File file, final UptimeJournal source) throws IOException
+ {
+ PrintWriter out = null;
+ try
+ {
+ out = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
+ write(out, source);
+ }
+ finally
+ {
+ //
+ IOUtils.closeQuietly(out);
+ }
+ }
+
+ /**
+ * Value of.
+ *
+ * @param line
+ * the line
+ * @return the uptime
+ */
+ public static Uptime valueOf(final String line)
+ {
+ Uptime result;
+
+ try
+ {
+ if (line == null)
+ {
+ result = null;
+ }
+ else
+ {
+ String[] tokens = line.split(" ", 4);
+
+ LocalDateTime datetime = LocalDateTime.parse(tokens[0]);
+ UptimeStatus status = UptimeStatus.valueOf(tokens[1]);
+ int code = Integer.parseInt(tokens[2]);
+ URL url = new URL(tokens[3]);
+
+ result = new Uptime(url, datetime, status, code);
+ }
+ }
+ catch (MalformedURLException exception)
+ {
+ result = null;
+ exception.printStackTrace();
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Write.
+ *
+ * @param out
+ * the out
+ * @param journal
+ * the journal
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static void write(final PrintWriter out, final UptimeJournal journal) throws IOException
+ {
+ if (journal != null)
+ {
+ for (Uptime uptime : journal.getUptimesAll())
+ {
+ String line = String.format("%s %s %d %s", uptime.getDatetime().toString(), uptime.getStatus(), uptime.getCode(), uptime.getUrl());
+ out.write(line);
+ out.write("\n");
+ }
+ }
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeSet.java b/src/fr/devinsy/statoolinfos/uptime/UptimeSet.java
new file mode 100644
index 0000000..7ae59ba
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/UptimeSet.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Iterator;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import fr.devinsy.statoolinfos.core.Categories;
+import fr.devinsy.statoolinfos.core.Category;
+import fr.devinsy.statoolinfos.core.Federation;
+import fr.devinsy.statoolinfos.core.Metrics;
+import fr.devinsy.statoolinfos.core.Organization;
+import fr.devinsy.statoolinfos.core.Organizations;
+import fr.devinsy.statoolinfos.core.Service;
+import fr.devinsy.statoolinfos.core.Service.RegistrationType;
+import fr.devinsy.statoolinfos.core.Services;
+import fr.devinsy.statoolinfos.core.Software;
+import fr.devinsy.statoolinfos.core.Softwares;
+import fr.devinsy.statoolinfos.crawl.CrawlCache;
+import fr.devinsy.statoolinfos.properties.PathPropertyList;
+import fr.devinsy.statoolinfos.stats.categories.CategoryStat;
+import fr.devinsy.statoolinfos.stats.categories.CategoryStats;
+import fr.devinsy.statoolinfos.stats.country.CountryStats;
+import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats;
+import fr.devinsy.statoolinfos.stats.properties.PropertyStats;
+import fr.devinsy.statoolinfos.stats.propertyfiles.PropertiesFileStats;
+import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats;
+import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats;
+import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
+import fr.devinsy.statoolinfos.stats.services.ServiceInstallTypeStats;
+import fr.devinsy.statoolinfos.stats.softwares.SoftwareStat;
+import fr.devinsy.statoolinfos.stats.softwares.SoftwareStats;
+import fr.devinsy.strings.StringSet;
+
+/**
+ * The Class UptimeChecker.
+ */
+public class UptimeSet
+{
+ private static Logger logger = LoggerFactory.getLogger(UptimeSet.class);
+
+ /**
+ * Instantiates a new stat agent.
+ */
+ private UptimeSet()
+ {
+ }
+
+ /**
+ * Purge.
+ *
+ * @param days
+ * the days
+ */
+ public void purge(final long days)
+ {
+
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java b/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java
new file mode 100644
index 0000000..650138c
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class UptimeStat.
+ */
+public class UptimeStat
+{
+ private static Logger logger = LoggerFactory.getLogger(UptimeStat.class);
+
+ private int count;
+ private int okCount;
+ private int errorCount;
+ private UptimeStatus last;
+
+ /**
+ * Instantiates a new uptime check.
+ *
+ * @param url
+ * the url
+ */
+ public UptimeStat()
+ {
+ this.count = 0;
+ this.okCount = 0;
+ this.errorCount = 0;
+ this.last = null;
+ }
+
+ public int getCount()
+ {
+ return this.count;
+ }
+
+ public int getErrorCount()
+ {
+ return this.errorCount;
+ }
+
+ public int getOkCount()
+ {
+ return this.okCount;
+ }
+
+ /**
+ * Gets the status.
+ *
+ * @return the status
+ */
+ public UptimeStatus getStatus()
+ {
+ UptimeStatus result;
+
+ if (this.count == 0)
+ {
+ result = UptimeStatus.VOID;
+ }
+ else if (this.errorCount > 0)
+ {
+ if (this.last == UptimeStatus.OK)
+ {
+ result = UptimeStatus.WARNING;
+ }
+ else
+ {
+ result = UptimeStatus.ERROR;
+ }
+ }
+ else
+ {
+ result = UptimeStatus.OK;
+ }
+
+ //
+ return result;
+ }
+
+ public void incError()
+ {
+ this.count += 1;
+ this.errorCount += 1;
+ }
+
+ public void incOk()
+ {
+ this.count += 1;
+ this.okCount += 1;
+ }
+
+ public void setLastStatus(final UptimeStatus status)
+ {
+ this.last = status;
+ }
+
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeStatus.java b/src/fr/devinsy/statoolinfos/uptime/UptimeStatus.java
new file mode 100644
index 0000000..ae831db
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/UptimeStatus.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+/**
+ * The Enum UptimeStatus.
+ */
+public enum UptimeStatus
+{
+ OK,
+ WARNING,
+ ALERT,
+ ERROR,
+ VOID
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java b/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java
new file mode 100644
index 0000000..fcdbd09
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/UptimeSurveyor.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class UptimeChecker.
+ */
+public class UptimeSurveyor
+{
+ private static Logger logger = LoggerFactory.getLogger(UptimeSurveyor.class);
+
+ /**
+ * Instantiates a new stat agent.
+ */
+ private UptimeSurveyor()
+ {
+ }
+
+ /**
+ * Survey.
+ *
+ * @param journal
+ * the journal
+ * @param urls
+ * the urls
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static void survey(final UptimeJournal journal, final URLSet urls) throws IOException
+ {
+ Uptimes uptimes = survey(urls);
+ journal.addAll(uptimes);
+ journal.purge(30);
+ }
+
+ /**
+ * Survey.
+ *
+ * @param url
+ * the url
+ * @return the int
+ */
+ public static int survey(final URL url)
+ {
+ int result;
+
+ try
+ {
+ int boundMax = 5;
+ boolean ended = false;
+ URL currentURL = url;
+ result = 0;
+ int currentBound = 0;
+ while (!ended)
+ {
+ if (currentBound < boundMax)
+ {
+ HttpURLConnection connection = (HttpURLConnection) currentURL.openConnection();
+ connection.setConnectTimeout(5 * 1000);
+ connection.setReadTimeout(5 * 1000);
+ connection.setRequestProperty("User-Agent", "StatoolInfos Uptime Bot");
+ result = connection.getResponseCode();
+ String location = connection.getHeaderField("Location");
+ connection.disconnect();
+
+ if ((result == 301) || (result == 302) || (result == 307) || (result == 308))
+ {
+ System.out.println("BOUND DETECTED " + currentURL.toString() + " -> " + location);
+ currentURL = new URL(location);
+
+ currentBound += 1;
+ }
+ else
+ {
+ ended = true;
+ }
+ }
+ else
+ {
+ ended = true;
+ result = 0;
+ }
+ }
+ }
+ catch (IOException exception)
+ {
+ result = 0;
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Survey.
+ *
+ * @param urls
+ * the urls
+ * @return the uptimes
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ public static Uptimes survey(final URLSet urls) throws IOException
+ {
+ Uptimes result;
+
+ //
+ result = new Uptimes();
+ for (URL url : urls)
+ {
+ result.add(new Uptime(url));
+ }
+
+ //
+ System.out.println("Survey of " + result.size());
+ for (Uptime uptime : result)
+ {
+ int code = survey(uptime.getUrl());
+ uptime.update(code);
+ System.out.println("Uptime: " + uptime.getStatus().toString() + " " + uptime.getUrl().toString());
+ }
+
+ //
+ return result;
+ }
+}
diff --git a/src/fr/devinsy/statoolinfos/uptime/Uptimes.java b/src/fr/devinsy/statoolinfos/uptime/Uptimes.java
new file mode 100644
index 0000000..2533e98
--- /dev/null
+++ b/src/fr/devinsy/statoolinfos/uptime/Uptimes.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2021 Christian Pierre MOMON
+ *
+ * This file is part of StatoolInfos, simple service statistics tool.
+ *
+ * StatoolInfos is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * StatoolInfos is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with StatoolInfos. If not, see .
+ */
+package fr.devinsy.statoolinfos.uptime;
+
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The Class Uptimes.
+ */
+public class Uptimes extends ArrayList
+{
+ private static final long serialVersionUID = 7892787666725111836L;
+ private static Logger logger = LoggerFactory.getLogger(Uptimes.class);
+
+ /**
+ * Instantiates a new uptimes.
+ */
+ public Uptimes()
+ {
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.ArrayList#add(java.lang.Object)
+ */
+ @Override
+ public boolean add(final Uptime uptime)
+ {
+ boolean result;
+
+ if (uptime == null)
+ {
+ result = false;
+ }
+ else
+ {
+ result = super.add(uptime);
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Gets the uptimes.
+ *
+ * @param date
+ * the date
+ * @return the uptimes
+ */
+ public Uptimes getByDate(final LocalDate date)
+ {
+ Uptimes result;
+
+ result = new Uptimes();
+
+ for (Uptime uptime : this)
+ {
+ if (uptime.getDatetime().toLocalDate().isEqual(date))
+ {
+ result.add(uptime);
+ }
+ }
+
+ //
+ return result;
+ }
+
+ /**
+ * Purge.
+ *
+ * @param days
+ * the days
+ */
+ public void purge(final long days)
+ {
+ Iterator iterator = this.iterator();
+
+ LocalDate limit = LocalDate.now().minusDays(days);
+
+ while (iterator.hasNext())
+ {
+ Uptime uptime = iterator.next();
+
+ if (uptime.getDatetime().toLocalDate().isBefore(limit))
+ {
+ iterator.remove();
+ }
+ }
+ }
+}