Added uptime features.

This commit is contained in:
Christian P. MOMON 2021-06-10 03:54:39 +02:00
parent a163cfed18
commit 818dc60c4d
45 changed files with 2148 additions and 98 deletions

View file

@ -27,6 +27,7 @@ import fr.devinsy.statoolinfos.core.Factory;
import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.crawl.CrawlCache;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
/**
* The Class Manager.
@ -44,6 +45,7 @@ public class HtmlizerContext
private Federation federation;
private Categories categories;
private CrawlCache cache;
private UptimeJournal uptimeJournal;
/**
* Instantiates a new manager.
@ -89,6 +91,7 @@ public class HtmlizerContext
{
this.federation = Factory.loadFederation(this.configuration.getHtmlizeInputURL(), this.cache);
this.categories = Factory.loadCategories(this.configuration.getCategoryFile(), this.federation);
this.uptimeJournal = this.cache.restoreUptimeJournal();
}
else
{
@ -172,6 +175,11 @@ public class HtmlizerContext
return result;
}
public UptimeJournal getUptimeJournal()
{
return this.uptimeJournal;
}
/**
* Instance.
*

View file

@ -117,6 +117,7 @@ public final class StatoolInfosCLI
message.appendln(" statoolinfos stat ua [-bot|-nobot] <fileordirectory> generate stats about user agent from log file");
message.appendln(" statoolinfos stat visitors [-bot|-nobot] <fileordirectory> generate stats about visitors (ip+ua) from log file");
message.appendln(" statoolinfos tagdate <fileordirectory> update the file.datetime file");
message.appendln(" statoolinfos uptime <fileordirectory> update uptime journal");
System.out.println(message.toString());
}
@ -461,6 +462,24 @@ public final class StatoolInfosCLI
}
}
}
else if (isMatching(args, "uptime", "\\s*.+\\s*"))
{
Chrono chrono = new Chrono().start();
Files inputs = convertPath(StringUtils.trim(args[1]));
for (File input : inputs)
{
try
{
StatoolInfos.uptime(input);
}
catch (Exception exception)
{
logger.error("Error with [{}]: {}", input.getAbsoluteFile(), exception.getMessage());
exception.printStackTrace();
}
}
System.out.println(chrono.format());
}
else
{
System.out.println("Bad usage.");

View file

@ -33,6 +33,7 @@ import fr.devinsy.statoolinfos.crawl.CrawlJournal;
import fr.devinsy.statoolinfos.properties.PathProperties;
import fr.devinsy.statoolinfos.properties.PathProperty;
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
import fr.devinsy.statoolinfos.util.Chrono;
import fr.devinsy.strings.StringList;
import fr.devinsy.strings.StringSet;
@ -167,6 +168,7 @@ public class Factory
Federation result;
System.out.println("Loading federation " + inputURL);
Chrono chrono = new Chrono().start();
if (inputURL == null)
{
@ -220,9 +222,10 @@ public class Factory
}
//
result.getCrawlJournal().addAll(cache.restoreJournal());
result.getCrawlJournal().addAll(cache.restoreCrawlJournal());
}
}
System.out.println("Federation loaded in " + chrono.format());
//
return result;
@ -329,7 +332,7 @@ public class Factory
}
//
CrawlJournal journal = cache.restoreJournal();
CrawlJournal journal = cache.restoreCrawlJournal();
result.getCrawlJournal().add(journal.getByUrl(inputURL));
result.getCrawlJournal().addAll(journal.searchByParent(result.getInputURL()));
for (Service service : result.getServices())
@ -398,7 +401,7 @@ public class Factory
result.getInputChecks().addAll(checks);
//
CrawlJournal journal = cache.restoreJournal();
CrawlJournal journal = cache.restoreCrawlJournal();
result.getCrawlJournal().add(journal.getByUrl(inputURL));
result.getCrawlJournal().addAll(journal.searchByParent(result.getInputURL()));

View file

@ -32,6 +32,7 @@ import fr.devinsy.statoolinfos.htmlize.charts.WeekValues;
import fr.devinsy.statoolinfos.htmlize.charts.YearValues;
import fr.devinsy.statoolinfos.properties.PathProperties;
import fr.devinsy.statoolinfos.properties.PathPropertyList;
import fr.devinsy.statoolinfos.uptime.URLSet;
import fr.devinsy.statoolinfos.util.URLUtils;
/**
@ -80,26 +81,6 @@ public class Federation extends PathPropertyList
}
}
/**
* Gets the all services.
*
* @return the all services
*/
public Services getAllServices()
{
Services result;
result = new Services();
for (Organization organization : this.organizations)
{
result.addAll(organization.getServices());
}
//
return result;
}
/**
* Gets the contact email.
*
@ -278,9 +259,8 @@ public class Federation extends PathPropertyList
* Gets the logo URL.
*
* @return the logo URL
* @throws MalformedURLException
*/
public URL getLogoURL() throws MalformedURLException
public URL getLogoURL()
{
URL result;
@ -425,6 +405,26 @@ public class Federation extends PathPropertyList
return result;
}
/**
* Gets the all services.
*
* @return the all services
*/
public Services getServicesAll()
{
Services result;
result = new Services();
for (Organization organization : this.organizations)
{
result.addAll(organization.getServices());
}
//
return result;
}
/**
* Gets the software catalog.
*
@ -436,7 +436,7 @@ public class Federation extends PathPropertyList
result = new Softwares();
for (Service service : getAllServices())
for (Service service : getServicesAll())
{
if (StringUtils.isNotBlank(service.getSoftwareName()))
{
@ -501,6 +501,54 @@ public class Federation extends PathPropertyList
return result;
}
/**
* Gets the URL all.
*
* @return the URL all
*/
public URLSet getURLAll()
{
URLSet result;
result = new URLSet();
//
result.add(getContactURL());
result.add(getLegalURL());
result.add(getLogoURL());
result.add(getTechnicalGuideURL());
result.add(getUserGuideURL());
result.add(getWebsiteURL());
//
for (Organization organization : getOrganizations())
{
result.add(organization.getContactURL());
result.add(organization.getLegalURL());
result.add(organization.getLogoURL());
result.add(organization.getTechnicalGuideURL());
result.add(organization.getUserGuideURL());
result.add(organization.getWebsiteURL());
//
for (Service service : organization.getServices())
{
result.add(service.getContactURL());
result.add(service.getLegalURL());
result.add(service.getLogoURL());
result.add(service.getSoftwareWebsite());
result.add(service.getSoftwareLicenseURL());
result.add(service.getSoftwareSourceURL());
result.add(service.getTechnicalGuideURL());
result.add(service.getUserGuideURL());
result.add(service.getWebsiteURL());
}
}
//
return result;
}
/**
* Gets the user doc website.
*

View file

@ -19,7 +19,6 @@
package fr.devinsy.statoolinfos.core;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -431,10 +430,8 @@ public class Service extends PathPropertyList
* Gets the logo URL.
*
* @return the logo URL
* @throws MalformedURLException
* the malformed URL exception
*/
public URL getLogoURL() throws MalformedURLException
public URL getLogoURL()
{
URL result;

View file

@ -28,6 +28,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.build.Builder;
import fr.devinsy.statoolinfos.crawl.Crawler;
import fr.devinsy.statoolinfos.htmlize.Htmlizer;
@ -42,6 +43,8 @@ import fr.devinsy.statoolinfos.stats.useragent.UserAgentStat;
import fr.devinsy.statoolinfos.stats.useragent.UserAgentStator;
import fr.devinsy.statoolinfos.stats.visitor.VisitorStat;
import fr.devinsy.statoolinfos.stats.visitor.VisitorStator;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.statoolinfos.uptime.UptimeSurveyor;
import fr.devinsy.statoolinfos.util.Chrono;
import fr.devinsy.statoolinfos.util.LineIterator;
import fr.devinsy.strings.StringList;
@ -527,4 +530,24 @@ public class StatoolInfos
StringsUtils.save(inputFile, lines);
}
}
/**
* Uptime.
*
* @param configurationFile
* the configuration file
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void uptime(final File configurationFile) throws StatoolInfosException, IOException
{
HtmlizerContext.instance().configure(configurationFile);
UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal();
Federation federation = HtmlizerContext.instance().getFederation();
UptimeSurveyor.survey(journal, federation.getURLAll());
HtmlizerContext.instance().getCache().storeUptimeJournal(journal);
}
}

View file

@ -37,6 +37,8 @@ import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
import fr.devinsy.statoolinfos.properties.PathProperties;
import fr.devinsy.statoolinfos.properties.PathPropertyList;
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.statoolinfos.uptime.UptimeJournalFile;
import fr.devinsy.statoolinfos.util.URLUtils;
/**
@ -144,6 +146,22 @@ public class CrawlCache
return result;
}
/**
* @return
* @throws IOException
*/
public CrawlJournal restoreCrawlJournal() throws IOException
{
CrawlJournal result;
File journalFile = restoreFile(getCrawlJournalURL());
result = CrawlJournalFile.load(journalFile);
//
return result;
}
/**
* Restore file.
*
@ -191,22 +209,6 @@ public class CrawlCache
}
}
/**
* @return
* @throws IOException
*/
public CrawlJournal restoreJournal() throws IOException
{
CrawlJournal result;
File journalFile = restoreFile(getJournalURL());
result = CrawlJournalFile.load(journalFile);
//
return result;
}
/**
* Restore logo to.
*
@ -281,6 +283,32 @@ public class CrawlCache
return result;
}
/**
* Restore uptime journal.
*
* @return the crawl journal
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public UptimeJournal restoreUptimeJournal() throws IOException
{
UptimeJournal result;
File journalFile = restoreFile(getUptimeJournalURL());
if (journalFile == null)
{
result = new UptimeJournal();
}
else
{
result = UptimeJournalFile.load(journalFile);
}
//
return result;
}
/**
* Store.
*
@ -311,15 +339,18 @@ public class CrawlCache
}
/**
* Store journal.
* Store crawl journal.
*
* @param journal
* the journal
*/
public void storeJournal(final CrawlJournal journal)
public void storeCrawlJournal(final CrawlJournal journal)
{
try
{
File file = Files.createTempFile("tmp-", ".statoolsinfos").toFile();
CrawlJournalFile.save(file, journal);
store(getJournalURL(), file);
store(getCrawlJournalURL(), file);
file.delete();
}
catch (IOException exception)
@ -393,13 +424,34 @@ public class CrawlCache
return result;
}
/**
* Store journal.
*
* @param journal
* the journal
*/
public void storeUptimeJournal(final UptimeJournal journal)
{
try
{
File file = Files.createTempFile("tmp-", ".statoolsinfos").toFile();
UptimeJournalFile.save(file, journal);
store(getUptimeJournalURL(), file);
file.delete();
}
catch (IOException exception)
{
exception.printStackTrace();
}
}
/**
* Gets the journal URL.
*
* @return the journal URL
* @throws MalformedURLException
*/
public static URL getJournalURL() throws MalformedURLException
public static URL getCrawlJournalURL() throws MalformedURLException
{
URL result;
@ -408,4 +460,21 @@ public class CrawlCache
//
return result;
}
/**
* Gets the uptimes journal URL.
*
* @return the uptimes journal URL
* @throws MalformedURLException
* the malformed URL exception
*/
public static URL getUptimeJournalURL() throws MalformedURLException
{
URL result;
result = new URL("http://localhost/uptimes.journal");
//
return result;
}
}

View file

@ -341,7 +341,7 @@ public class Crawler
logger.info("Restoring crawl journal.");
result = this.cache.restoreJournal();
result = this.cache.restoreCrawlJournal();
//
return result;
@ -353,6 +353,6 @@ public class Crawler
public void storeJournal()
{
logger.info("Storing crawl journal.");
this.cache.storeJournal(this.journal);
this.cache.storeCrawlJournal(this.journal);
}
}

View file

@ -60,7 +60,7 @@ public class CategoryPage
logger.info("Htmlize category pages.");
for (Category category : categories)
{
Services services = federation.getAllServices().getBy(category);
Services services = federation.getServicesAll().getBy(category);
String page = CategoryPage.htmlize(category, services);
FileUtils.write(new File(htmlizeDirectory, "category-" + category.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
}

View file

@ -620,8 +620,6 @@ public class ChartHtmlizer
* the dataset
* @param color
* the color
* @param animated
* the animated
* @return the string
* @throws StatoolInfosException
* the statool infos exception
@ -1078,7 +1076,7 @@ public class ChartHtmlizer
{
String result;
result = htmlizeServiceCountMonthChart(federation.getAllServices(),
result = htmlizeServiceCountMonthChart(federation.getServicesAll(),
YearMonth.from(StatoolInfosUtils.parseDate(federation.getStartDate())));
//
@ -1264,7 +1262,7 @@ public class ChartHtmlizer
{
String result;
result = htmlizeServiceCountYearChart(federation.getAllServices(),
result = htmlizeServiceCountYearChart(federation.getServicesAll(),
StatoolInfosUtils.parseDate(federation.getStartDate()).getYear());
//

View file

@ -69,7 +69,7 @@ public class CrawlJournalPage
FileUtils.write(new File(htmlizeDirectory, organization.getTechnicalName() + "-crawl.xhtml"), page, StandardCharsets.UTF_8);
}
for (Service service : federation.getAllServices())
for (Service service : federation.getServicesAll())
{
page = htmlize("Journal des téléchargements de " + service.getName(), service.getCrawlJournal());
FileUtils.write(new File(htmlizeDirectory, service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + "-crawl.xhtml"), page, StandardCharsets.UTF_8);

View file

@ -60,7 +60,7 @@ public class ExportsPage
{
logger.info("EXPORTS CSV.");
CSVFile.save(new File(htmlizeDirectory, "organizations.csv"), federation.getOrganizations());
CSVFile.save(new File(htmlizeDirectory, "services.csv"), federation.getAllServices());
CSVFile.save(new File(htmlizeDirectory, "services.csv"), federation.getServicesAll());
}
catch (IOException exception)
{
@ -73,7 +73,7 @@ public class ExportsPage
logger.info("EXPORTS JSON.");
JSONFile.save(new File(htmlizeDirectory, "federation.json"), federation);
JSONFile.save(new File(htmlizeDirectory, "organizations.json"), federation.getOrganizations());
JSONFile.save(new File(htmlizeDirectory, "services.json"), federation.getAllServices());
JSONFile.save(new File(htmlizeDirectory, "services.json"), federation.getServicesAll());
}
catch (IOException exception)
{
@ -85,7 +85,7 @@ public class ExportsPage
{
logger.info("EXPORTS ODS.");
ODSFile.save(new File(htmlizeDirectory, "organizations.ods"), federation.getOrganizations());
ODSFile.save(new File(htmlizeDirectory, "services.ods"), federation.getAllServices());
ODSFile.save(new File(htmlizeDirectory, "services.ods"), federation.getServicesAll());
}
catch (Exception exception)
{

View file

@ -77,6 +77,8 @@ public class FederationHeaderView
data.setAttribute("metricsLink", "href", federation.getTechnicalName() + "-metrics-summary-months-last.xhtml");
data.setAttribute("crawlLink", "href", federation.getTechnicalName() + "-crawl.xhtml");
data.setAttribute("uptimeLink", "href", federation.getLocalFileBaseName() + "-uptimes.xhtml");
if (federation.getCrawlJournal().getErrors().isEmpty())
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg");

View file

@ -69,14 +69,14 @@ public class FederationStatsPage
data.setContent("organizationCountChart", ChartHtmlizer.htmlizeOrganizationCountChart(federation));
data.setContent("organizationInOutChart", ChartHtmlizer.htmlizeOrganizationInOutChart(federation));
data.setContent("hostServerTypeChart", ChartHtmlizer.htmlizeHostServerTypeChart(federation.getAllServices()));
data.setContent("hostProviderTypeChart", ChartHtmlizer.htmlizeHostProviderTypeChart(federation.getAllServices()));
data.setContent("serviceInstallTypeChart", ChartHtmlizer.htmlizeServiceInstallTypeChart(federation.getAllServices()));
data.setContent("serviceCountryChart", ChartHtmlizer.htmlizeServiceCountryChart(federation.getAllServices()));
data.setContent("hostServerTypeChart", ChartHtmlizer.htmlizeHostServerTypeChart(federation.getServicesAll()));
data.setContent("hostProviderTypeChart", ChartHtmlizer.htmlizeHostProviderTypeChart(federation.getServicesAll()));
data.setContent("serviceInstallTypeChart", ChartHtmlizer.htmlizeServiceInstallTypeChart(federation.getServicesAll()));
data.setContent("serviceCountryChart", ChartHtmlizer.htmlizeServiceCountryChart(federation.getServicesAll()));
//
{
RegistrationStats stats = StatAgent.statRegistrationTypes(federation.getAllServices());
RegistrationStats stats = StatAgent.statRegistrationTypes(federation.getServicesAll());
data.setContent("registrationTypeChart", ChartHtmlizer.htmlizeRegistrationBarChart(stats));
data.setContent("registrationNoneTypeChart", ChartHtmlizer.htmlizeRegistrationNonePieChart(stats));
@ -86,14 +86,14 @@ public class FederationStatsPage
}
data.setContent("serviceCountYearChart", ChartHtmlizer.htmlizeServiceCountYearChart(federation));
data.setContent("serviceDateStatusChart", ChartHtmlizer.htmlizeServiceDateStatusChart(federation.getAllServices()));
data.setContent("serviceDateStatusChart", ChartHtmlizer.htmlizeServiceDateStatusChart(federation.getServicesAll()));
data.setContent("softwareDistributionChart", ChartHtmlizer.htmlizeSoftwareDistributionChart());
data.setContent("softwareDistributionPieChart", ChartHtmlizer.htmlizeSoftwareDistributionPieChart(federation.getAllServices()));
data.setContent("softwareDistributionPieChart", ChartHtmlizer.htmlizeSoftwareDistributionPieChart(federation.getServicesAll()));
data.setContent("categoryDistributionChart", ChartHtmlizer.htmlizeCategoryDistributionChart());
data.setContent("categoryDistributionPieChart", ChartHtmlizer.htmlizeCatergoryDistributionPieChart(federation.getAllServices()));
data.setContent("categoryDistributionPieChart", ChartHtmlizer.htmlizeCatergoryDistributionPieChart(federation.getServicesAll()));
data.setContent("hostNameChart", ChartHtmlizer.htmlizeHostNamePieChart(federation.getAllServices()));
data.setContent("hostNameChart", ChartHtmlizer.htmlizeHostNamePieChart(federation.getServicesAll()));
//
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/federationStats.xhtml", data).toString();

View file

@ -0,0 +1,99 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class FederationUptimePage.
*/
public class FederationUptimePage
{
private static Logger logger = LoggerFactory.getLogger(FederationUptimePage.class);
/**
* Builds the.
*
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void build() throws StatoolInfosException, IOException
{
Federation federation = HtmlizerContext.instance().getFederation();
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal();
String page = htmlize(federation, journal);
FileUtils.write(new File(htmlizeDirectory, federation.getLocalFileBaseName() + "-uptimes.xhtml"), page, StandardCharsets.UTF_8);
}
/**
* Htmlize.
*
* @param services
* the services
* @param journal
* the journal
* @return the string
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
*/
public static String htmlize(final Federation federation, final UptimeJournal journal) throws StatoolInfosException, IOException
{
String result;
try
{
TagDataManager data = new TagDataManager();
data.setContent("headerView", FederationHeaderView.htmlize(federation));
data.setContent("uptimeView", UptimeView.htmlize(federation.getServicesAll(), journal));
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add("Disponibilités", federation.getLocalFileBaseName() + "-uptimes.xhtml");
result = WebCharterView.build(content, trail);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building FederationUptime page: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -165,11 +165,14 @@ public class Htmlizer
ExportsPage.build();
FederationPage.build();
FederationStatsPage.build();
FederationUptimePage.build();
OrganizationPage.buildAll();
OrganizationUptimePage.buildAll();
PropertyFileCheckPage.buildAll();
PropertiesFilesPage.build();
PropertyStatsPage.buildAll();
ServicePage.buildAll();
ServiceUptimePage.buildAll();
ServicesPage.build();
SoftwaresPage.build();
SoftwarePage.buildAll();

View file

@ -103,6 +103,8 @@ public class OrganizationHeaderView
data.setAttribute("metricsLink", "href", organization.getTechnicalName() + "-metrics-summary-months-last.xhtml");
data.setAttribute("crawlLink", "href", organization.getTechnicalName() + "-crawl.xhtml");
data.setAttribute("uptimeLink", "href", organization.getLocalFileBaseName() + "-uptimes.xhtml");
if (organization.getCrawlJournal().getErrors().isEmpty())
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download-mono.svg");

View file

@ -0,0 +1,115 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.Organization;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class OrganizationUptimePage.
*/
public class OrganizationUptimePage
{
private static Logger logger = LoggerFactory.getLogger(OrganizationUptimePage.class);
/**
* Builds the.
*
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void build(final Organization organization) throws StatoolInfosException, IOException
{
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal();
String page = htmlize(organization, journal);
FileUtils.write(new File(htmlizeDirectory, organization.getLocalFileBaseName() + "-uptimes.xhtml"), page, StandardCharsets.UTF_8);
}
/**
* Builds the all.
*
* @throws IOException
* @throws StatoolInfosException
*/
public static void buildAll() throws StatoolInfosException, IOException
{
Federation federation = HtmlizerContext.instance().getFederation();
for (Organization organization : federation.getOrganizations())
{
build(organization);
}
}
/**
* Htmlize.
*
* @param organization
* the organization
* @param journal
* the journal
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlize(final Organization organization, final UptimeJournal journal) throws StatoolInfosException
{
String result;
try
{
TagDataManager data = new TagDataManager();
data.setContent("headerView", OrganizationHeaderView.htmlize(organization));
data.setContent("uptimeView", UptimeView.htmlize(organization.getServices(), journal));
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(organization.getName(), organization.getLocalFileBaseName() + ".xhtml");
trail.add("Disponibilités", organization.getLocalFileBaseName() + "-uptimes.xhtml");
result = WebCharterView.build(content, trail);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building about page: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -74,7 +74,7 @@ public class PropertyStatsPage
page = PropertyStatsPage.htmlize("Les propriétés des organizations", organizationsStats);
FileUtils.write(new File(htmlizeDirectory, "propertyStats-organizations.xhtml"), page, StandardCharsets.UTF_8);
PropertyStats servicesStats = StatAgent.statServicesProperties(federation.getAllServices());
PropertyStats servicesStats = StatAgent.statServicesProperties(federation.getServicesAll());
page = PropertyStatsPage.htmlize("Les propriétés des services", servicesStats);
FileUtils.write(new File(htmlizeDirectory, "propertyStats-services.xhtml"), page, StandardCharsets.UTF_8);
}

View file

@ -180,6 +180,7 @@ public class ServiceHeaderView
{
data.setAttribute("crawlLinkImg", "src", "circle-icons/download.svg");
}
data.setAttribute("uptimeLink", "href", service.getLocalFileBaseName() + "-uptimes.xhtml");
{
PropertyChecks checks = service.getInputChecksAll();

View file

@ -107,7 +107,7 @@ public class ServicePage
*/
public static void buildAll() throws IOException, StatoolInfosException
{
for (Service service : HtmlizerContext.instance().getFederation().getAllServices())
for (Service service : HtmlizerContext.instance().getFederation().getServicesAll())
{
build(service);
}

View file

@ -0,0 +1,122 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.HtmlizerContext;
import fr.devinsy.statoolinfos.core.Federation;
import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.Services;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
/**
* The Class ServiceUptimePage.
*/
public class ServiceUptimePage
{
private static Logger logger = LoggerFactory.getLogger(ServiceUptimePage.class);
/**
* Builds the.
*
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void build(final Service service) throws StatoolInfosException, IOException
{
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
UptimeJournal journal = HtmlizerContext.instance().getUptimeJournal();
String page = htmlize(service, journal);
FileUtils.write(new File(htmlizeDirectory, service.getLocalFileBaseName() + "-uptimes.xhtml"), page, StandardCharsets.UTF_8);
}
/**
* Builds the all.
*
* @throws StatoolInfosException
* the statool infos exception
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public static void buildAll() throws StatoolInfosException, IOException
{
Federation federation = HtmlizerContext.instance().getFederation();
for (Service service : federation.getServicesAll())
{
build(service);
}
}
/**
* Htmlize.
*
* @param service
* the service
* @param journal
* the journal
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlize(final Service service, final UptimeJournal journal) throws StatoolInfosException
{
String result;
try
{
TagDataManager data = new TagDataManager();
data.setContent("headerView", ServiceHeaderView.htmlize(service));
Services services = new Services();
services.add(service);
data.setContent("uptimeView", UptimeView.htmlize(services, journal));
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimePage.xhtml", data).toString();
BreadcrumbTrail trail = new BreadcrumbTrail();
trail.add(service.getOrganization().getName(), service.getOrganization().getLocalFileBaseName() + ".xhtml");
trail.add(service.getName(), service.getLocalFileBaseName() + ".xhtml");
trail.add("Disponibilités", service.getLocalFileBaseName() + "-uptimes.xhtml");
result = WebCharterView.build(content, trail);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building about page: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -53,7 +53,7 @@ public class ServicesPage
File htmlizeDirectory = HtmlizerContext.instance().getHtmlizeDirectory();
logger.info("Htmlize services page.");
String page = ServicesPage.htmlize(federation.getAllServices());
String page = ServicesPage.htmlize(federation.getServicesAll());
FileUtils.write(new File(htmlizeDirectory, "services.xhtml"), page, StandardCharsets.UTF_8);
}

View file

@ -58,7 +58,7 @@ public class SoftwarePage
Softwares catalog = federation.getSoftwares();
for (Software software : catalog.values())
{
Services services = federation.getAllServices().getBy(software);
Services services = federation.getServicesAll().getBy(software);
String page = SoftwarePage.htmlize(software, services);
FileUtils.write(new File(htmlizeDirectory, "software-" + software.getTechnicalName() + ".xhtml"), page, StandardCharsets.UTF_8);
}

View file

@ -0,0 +1,121 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.htmlize;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.devinsy.statoolinfos.core.Service;
import fr.devinsy.statoolinfos.core.Services;
import fr.devinsy.statoolinfos.core.StatoolInfosException;
import fr.devinsy.statoolinfos.uptime.UptimeJournal;
import fr.devinsy.statoolinfos.uptime.UptimeStat;
import fr.devinsy.xidyn.XidynException;
import fr.devinsy.xidyn.data.TagDataManager;
import fr.devinsy.xidyn.presenters.PresenterUtils;
import fr.devinsy.xidyn.utils.XidynUtils;
/**
* The Class UptimeView.
*/
public class UptimeView
{
private static Logger logger = LoggerFactory.getLogger(UptimeView.class);
/**
* Htmlize.
*
* @param services
* the services
* @param journal
* the journal
* @return the string
* @throws StatoolInfosException
* the statool infos exception
*/
public static String htmlize(final Services services, final UptimeJournal journal) throws StatoolInfosException
{
String result;
try
{
TagDataManager data = new TagDataManager();
int index = 0;
for (Service service : services.sortByName())
{
//
data.setAttribute("line", index, "lineLogo", "src", service.getLogoFileName());
data.setEscapedContent("line", index, "lineNameValue", service.getName());
data.setAttribute("line", index, "lineNameLink", "href", service.getOrganization().getTechnicalName() + "-" + service.getTechnicalName() + ".xhtml");
data.setAttribute("line", index, "lineOrganizationLink", "href", service.getOrganization().getTechnicalName() + ".xhtml");
data.setAttribute("line", index, "lineOrganizationLogo", "src", service.getOrganization().getLogoFileName());
data.setEscapedContent("line", index, "lineOrganizationValue", service.getOrganization().getName());
//
LocalDate now = LocalDate.now();
for (int dayCount = 0; dayCount < 22; dayCount++)
{
LocalDate date = now.minusDays(dayCount);
//
data.setContent("lineHeader-" + dayCount, StringUtils.capitalize(date.format(DateTimeFormatter.ofPattern("EEEE", Locale.FRENCH)).substring(0, 2)));
data.setAttribute("lineHeader-" + dayCount, "title", date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
DayOfWeek weekDay = date.getDayOfWeek();
if ((weekDay == DayOfWeek.SUNDAY) || (weekDay == DayOfWeek.SATURDAY))
{
data.setAttribute("lineHeader-" + dayCount, "style", "background-color: gainsboro;");
data.setAttribute("line", index, "uptime-" + dayCount, "style", "background-color: gainsboro;");
}
else
{
data.setAttribute("lineHeader-" + dayCount, "style", "background-color: #ececec;");
}
//
UptimeStat stat = journal.getStat(service.getWebsiteURL(), date);
data.setAttribute("line", index, "statusImg-" + dayCount, "src", "status-" + stat.getStatus().toString().toLowerCase() + ".png");
String title = String.format("%d ok + %d err&#10;%s", stat.getOkCount(), stat.getErrorCount(), date.format(DateTimeFormatter.ofPattern("dd/MM/yyyy")));
data.setAttribute("line", index, "statusImg-" + dayCount, "title", title);
}
//
index += 1;
}
String content = PresenterUtils.dynamize("/fr/devinsy/statoolinfos/htmlize/uptimeView.xhtml", data).toString();
result = XidynUtils.extractBodyContent(content);
}
catch (XidynException exception)
{
throw new StatoolInfosException("Error building about page: " + exception.getMessage(), exception);
}
//
return result;
}
}

View file

@ -23,7 +23,6 @@
<p id="federationDescription">Description absente…</p>
<div>Depuis <span id="federationStartDate">n/a</span></div>
<div class="content_infos" style="margin: 5px;">
Liens :
<a id="legalLink" href="#"><img id="legalLinkImg" src="circle-icons/ribbon.svg" class="disabled" title="Mentions légales"/></a>
<a id="contactLink" href="#"><img id="contactLinkImg" src="circle-icons/contacts.svg" class="disabled" title="Page web de contact"/></a>
<a id="emailLink" href="#"><img id="emailLinkImg" src="circle-icons/mail.svg" class="disabled" title="Courriel de contact/support"/></a>
@ -35,6 +34,7 @@
<a id="crawlLink" href="#"><img id="crawlLinkImg" src="circle-icons/download-mono.svg" title="Statut des téléchargements"/></a>
<a id="statsLink" href="#"><img id="statsLinkImg" src="circle-icons/piechart-mono.svg" title="Statistiques"/></a>
<a id="metricsLink" href="#"><img id="metricsLinkImg" src="circle-icons/barchart-mono.svg" title="Métriques"/></a>
<a id="uptimeLink" href="#"><img id="uptimeLinkImg" src="circle-icons/countdown-mono.svg" title="Disponibilité"/></a>
<div style="display: inline-block; vertical-align: middle; font-size: smaller; margin-left: 2px; width: 35px;">
<a id="alertLink" href="#" style="text-decoration: none;">
<div id="errorCount" class="bg_error center" title="Propriétés en erreurs">n/a</div>

View file

@ -25,7 +25,6 @@
<div><span id="organizationStartDateWord">Depuis</span> <span id="organizationStartDate">n/a</span><span id="organizationEndDateData"> <span id="organizationEndDate">n/a</span></span> (<span id="organizationAge">n/a</span>)</div>
<div>Membre <span id="organizationMemberOfName">n/a</span> <span id="organizationMemberOfWord">depuis/:</span> <span id="organizationMemberStartDate">n/a</span><span id="organizationMemberEndDateData"> <span id="organizationMemberEndDate">n/a</span></span> (<span id="organizationMemberAge">n/a</span>)</div>
<div class="content_infos" style="margin: 5px;">
Liens :
<a id="legalLink" href="#"><img id="legalLinkImg" src="circle-icons/ribbon.svg" class="disabled" title="Mentions légales"/></a>
<a id="contactLink" href="#"><img id="contactLinkImg" src="circle-icons/contacts.svg" class="disabled" title="Page web de contact"/></a>
<a id="emailLink" href="#"><img id="emailLinkImg" src="circle-icons/mail.svg" class="disabled" title="Courriel de contact/support"/></a>
@ -37,6 +36,7 @@
<a id="crawlLink" href="#"><img id="crawlLinkImg" src="circle-icons/download-mono.svg" title="Statut des téléchargements"/></a>
<a id="statsLink" href="#"><img id="statsLinkImg" src="circle-icons/piechart-mono.svg" title="Statistiques"/></a>
<a id="metricsLink" href="#"><img id="metricsLinkImg" src="circle-icons/barchart-mono.svg" title="Métriques"/></a>
<a id="uptimeLink" href="#"><img id="uptimeLinkImg" src="circle-icons/countdown-mono.svg" title="Disponibilité"/></a>
<div style="display: inline-block; vertical-align: middle; font-size: smaller; margin-left: 2px; width: 35px;">
<a id="alertLink" href="#" style="text-decoration: none;">
<div id="errorCount" class="bg_error center" title="Propriétés en erreurs">n/a</div>

View file

@ -33,7 +33,6 @@
<img id="registrationLoadImg" src="circle-icons/lock-mono.svg" class="disabled" title="Actuellement fermé"/>
</div>
<div class="content_infos" style="margin: 5px;">
Liens :
<a id="legalLink" href="#"><img id="legalLinkImg" src="circle-icons/ribbon.svg" class="disabled" title="Mentions légales"/></a>
<a id="contactLink" href="#"><img id="contactLinkImg" src="circle-icons/contacts.svg" class="disabled" title="Page web de contact"/></a>
<a id="emailLink" href="#"><img id="emailLinkImg" src="circle-icons/mail.svg" class="disabled" title="Courriel de contact/support"/></a>
@ -45,6 +44,7 @@
<a id="crawlLink" href="#"><img id="crawlLinkImg" src="circle-icons/download-mono.svg" title="Statut des téléchargements"/></a>
<a id="statsLink" href="#"><img id="statsLinkImg" src="circle-icons/piechart-mono.svg" title="Statistiques"/></a>
<a id="metricsLink" href="#"><img id="metricsLinkImg" src="circle-icons/barchart-mono.svg" title="Métriques"/></a>
<a id="uptimeLink" href="#"><img id="uptimeLinkImg" src="circle-icons/countdown-mono.svg" title="Disponibilité"/></a>
<div style="display: inline-block; vertical-align: middle; font-size: smaller; margin-left: 2px; width: 35px;">
<a id="alertLink" href="#" style="text-decoration: none;">
<div id="errorCount" class="bg_error center" title="Propriétés en erreurs">n/a</div>

View file

@ -846,3 +846,26 @@ table > tfoot > tr > th.danger
{
width: 50px;
}
/************************************************/
.uptimeTable
{
}
.uptimeTable tr:first-child td:nth-child(n+3)
{
padding: 5px 2px 5px 2px;
}
.uptimeTable tr:nth-child(n+1) td:nth-child(n+3)
{
padding: 5px 2px 5px 2px;
width: 26px;
text-align: center;
}
.uptimeTable tr td img
{
height: 18px;
width: 11px;
vertical-align: bottom;
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div id="headerView" />
<div id="uptimeView" />
</body>
</html>

View file

@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>StatoolInfos</title>
<meta charset="UTF-8" />
<meta name="keywords" content="statoolinfos,devinsy,federation" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
<script src="sorttable.js" />
<script src="Chart.bundle.min.js"></script>
</head>
<body>
<div style="width:1150px; margin: 0 auto 0 auto;">
<h2>Disponibilités</h2>
<table class="center_table table_classic left uptimeTable">
<tr id="lineHeader">
<th id="lineName" style="padding-top: 0; padding-bottom: 0;">Service</th>
<th id="lineName" style="padding-top: 0; padding-bottom: 0;">Organisation</th>
<td id="lineHeader-21">X</td>
<td id="lineHeader-20">X</td>
<td id="lineHeader-19">X</td>
<td id="lineHeader-18">X</td>
<td id="lineHeader-17">X</td>
<td id="lineHeader-16">X</td>
<td id="lineHeader-15">X</td>
<td id="lineHeader-14">X</td>
<td id="lineHeader-13">X</td>
<td id="lineHeader-12">X</td>
<td id="lineHeader-11">X</td>
<td id="lineHeader-10">X</td>
<td id="lineHeader-9">X</td>
<td id="lineHeader-8">X</td>
<td id="lineHeader-7">X</td>
<td id="lineHeader-6">X</td>
<td id="lineHeader-5">X</td>
<td id="lineHeader-4">X</td>
<td id="lineHeader-3">X</td>
<td id="lineHeader-2">X</td>
<td id="lineHeader-1">X</td>
<td id="lineHeader-0">X</td>
</tr>
<tr id="line">
<td id="lineName" style="padding-top: 0; padding-bottom: 0;">
<a href="#" id="lineNameLink">
<img id="lineLogo" src="" style="width: 26px; height: 26px; padding-top:0; padding-bottom: 0; vertical-align: middle;"/>
&#160;<span id="lineNameValue">n/a</span>
</a>
</td>
<td id="lineOrganization" style="padding-top: 0; padding-bottom: 0;">
<a href="#" id="lineOrganizationLink">
<img id="lineOrganizationLogo" src="" style="width: 26px; height: 26px; padding-top:0; padding-bottom: 0; vertical-align: middle;"/>
&#160;<span id="lineOrganizationValue">n/a</span>
</a>
</td>
<td id="uptime-21"><img id="statusImg-21" src="status-void.png" /></td>
<td id="uptime-20"><img id="statusImg-20" src="status-void.png" /></td>
<td id="uptime-19"><img id="statusImg-19" src="status-void.png" /></td>
<td id="uptime-18"><img id="statusImg-18" src="status-void.png" /></td>
<td id="uptime-17"><img id="statusImg-17" src="status-void.png" /></td>
<td id="uptime-16"><img id="statusImg-16" src="status-void.png" /></td>
<td id="uptime-15"><img id="statusImg-15" src="status-void.png" /></td>
<td id="uptime-14"><img id="statusImg-14" src="status-void.png" /></td>
<td id="uptime-13"><img id="statusImg-13" src="status-void.png" /></td>
<td id="uptime-12"><img id="statusImg-12" src="status-void.png" /></td>
<td id="uptime-11"><img id="statusImg-11" src="status-void.png" /></td>
<td id="uptime-10"><img id="statusImg-10" src="status-void.png" /></td>
<td id="uptime-9"><img id="statusImg-9" src="status-void.png" /></td>
<td id="uptime-8"><img id="statusImg-8" src="status-void.png" /></td>
<td id="uptime-7"><img id="statusImg-7" src="status-void.png" /></td>
<td id="uptime-6"><img id="statusImg-6" src="status-void.png" /></td>
<td id="uptime-5"><img id="statusImg-5" src="status-void.png" /></td>
<td id="uptime-4"><img id="statusImg-4" src="status-void.png" /></td>
<td id="uptime-3"><img id="statusImg-3" src="status-void.png" /></td>
<td id="uptime-2"><img id="statusImg-2" src="status-void.png" /></td>
<td id="uptime-1"><img id="statusImg-1" src="status-void.png" /></td>
<td id="uptime-0"><img id="statusImg-0" src="status-void.png" /></td>
</tr>
</table>
</div>
</body>
</html>

View file

@ -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()

View file

@ -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;
}

View file

@ -716,11 +716,13 @@ public class PathPropertyList extends ArrayList<PathProperty> 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;
}

View file

@ -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)

View file

@ -0,0 +1,98 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<URL> because URL hashcode method resolves
* value, so all URL with same IP have the same hashcode.
*/
public class URLSet implements Iterable<URL>
{
private static Logger logger = LoggerFactory.getLogger(URLSet.class);
private HashMap<String, URL> map;
/**
* Instantiates a new URL set.
*/
public URLSet()
{
this.map = new HashMap<String, URL>();
}
/**
* 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<URL> iterator()
{
Iterator<URL> result;
result = this.map.values().iterator();
//
return result;
}
/**
* Size.
*
* @return the int
*/
public int size()
{
int result;
result = this.map.size();
//
return result;
}
}

View file

@ -0,0 +1,54 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<URL>
{
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);
}
}

View file

@ -0,0 +1,114 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
}

View file

@ -0,0 +1,314 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<String, Uptimes> map;
/**
* Instantiates a new uptime journal.
*/
public UptimeJournal()
{
super();
this.map = new HashMap<String, Uptimes>();
}
/**
* 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;
}
}

View file

@ -0,0 +1,230 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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");
}
}
}
}

View file

@ -0,0 +1,80 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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)
{
}
}

View file

@ -0,0 +1,115 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -0,0 +1,31 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
package fr.devinsy.statoolinfos.uptime;
/**
* The Enum UptimeStatus.
*/
public enum UptimeStatus
{
OK,
WARNING,
ALERT,
ERROR,
VOID
}

View file

@ -0,0 +1,149 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}

View file

@ -0,0 +1,111 @@
/*
* Copyright (C) 2021 Christian Pierre MOMON <christian@momon.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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<Uptime>
{
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<Uptime> iterator = this.iterator();
LocalDate limit = LocalDate.now().minusDays(days);
while (iterator.hasNext())
{
Uptime uptime = iterator.next();
if (uptime.getDatetime().toLocalDate().isBefore(limit))
{
iterator.remove();
}
}
}
}