diff --git a/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java index abd01d4..5be51b5 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java +++ b/src/fr/devinsy/statoolinfos/htmlize/UptimeView.java @@ -32,6 +32,7 @@ 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.statoolinfos.uptime.UptimeStatus; import fr.devinsy.strings.StringList; import fr.devinsy.xidyn.XidynException; import fr.devinsy.xidyn.data.TagDataManager; @@ -45,6 +46,66 @@ public class UptimeView { private static Logger logger = LoggerFactory.getLogger(UptimeView.class); + /** + * Gets the stat. + * + * @param services + * the services + * @param date + * the date + * @return the stat + */ + public static UptimeStat getStat(final UptimeJournal journal, final Services services, final LocalDate date) + { + UptimeStat result; + + result = new UptimeStat(); + + if ((services != null) || (date != null)) + { + for (Service service : services.sortByName()) + { + UptimeStat stat = journal.getStat(service.getWebsiteURL(), date); + if (stat.getStatus() == UptimeStatus.OK) + { + result.incOk(); + } + else if (stat.getStatus() == UptimeStatus.WARNING) + { + result.incWarning(); + } + else if (stat.getStatus() == UptimeStatus.ALERT) + { + result.incAlert(); + } + else if (stat.getStatus() == UptimeStatus.ERROR) + { + result.incError(); + } + else if (stat.getStatus() == UptimeStatus.VOID) + { + result.incVoid(); + } + } + + if (result.getCount() == 0) + { + result.setStatus(UptimeStatus.VOID); + } + else if (result.getOkCount() != result.getCount()) + { + result.setStatus(UptimeStatus.ERROR); + } + else + { + result.setStatus(UptimeStatus.OK); + } + } + + // + return result; + } + /** * Htmlize. * @@ -65,6 +126,15 @@ public class UptimeView TagDataManager data = new TagDataManager(); LocalDate now = LocalDate.now(); + + UptimeStat last = getStat(journal, services, now); + + data.setContent("okCount", last.getOkCount()); + data.setContent("warningCount", last.getWarningCount()); + data.setContent("alertCount", last.getAlertCount()); + data.setContent("errorCount", last.getErrorCount()); + data.setContent("voidCount", last.getVoidCount()); + for (int dayCount = 0; dayCount < 22; dayCount++) { LocalDate date = now.minusDays(dayCount); diff --git a/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos.css b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos.css index a253de1..b8b388a 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos.css +++ b/src/fr/devinsy/statoolinfos/htmlize/stuff/statoolinfos.css @@ -847,6 +847,32 @@ table > tfoot > tr > th.danger width: 50px; } /************************************************/ +.uptimeCounts +{ + text-align: center; +} + +.uptimeCounts ul li +{ + display: inline-block; + list-style-type:none; + padding: 0 5px 5px 5px; +} + +.uptimeCounts img +{ + height: 18px; + width: 11px; + vertical-align: bottom; +} + +.uptimeCounts ul li span +{ + padding-left : 5px; + padding-right : 5px; + width: 50px; +} + .uptimeTable { } diff --git a/src/fr/devinsy/statoolinfos/htmlize/uptimeView.xhtml b/src/fr/devinsy/statoolinfos/htmlize/uptimeView.xhtml index 4ea8d40..7352ee4 100644 --- a/src/fr/devinsy/statoolinfos/htmlize/uptimeView.xhtml +++ b/src/fr/devinsy/statoolinfos/htmlize/uptimeView.xhtml @@ -26,6 +26,15 @@ +
+ +
diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java index 0739f92..6791643 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeJournal.java @@ -131,7 +131,7 @@ public class UptimeJournal } if (older != null) { - result.setLastStatus(older.getStatus()); + result.setStatus(older.getStatus()); } } diff --git a/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java b/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java index 1801d5d..7ff3fd1 100644 --- a/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java +++ b/src/fr/devinsy/statoolinfos/uptime/UptimeStat.java @@ -30,7 +30,10 @@ public class UptimeStat private int count; private int okCount; + private int warningCount; + private int alertCount; private int errorCount; + private int voidCount; private UptimeStatus last; /** @@ -39,11 +42,19 @@ public class UptimeStat public UptimeStat() { this.count = 0; + this.warningCount = 0; + this.alertCount = 0; this.okCount = 0; this.errorCount = 0; + this.voidCount = 0; this.last = null; } + public int getAlertCount() + { + return this.alertCount; + } + public int getCount() { return this.count; @@ -96,6 +107,22 @@ public class UptimeStat return result; } + public int getVoidCount() + { + return this.voidCount; + } + + public int getWarningCount() + { + return this.warningCount; + } + + public void incAlert() + { + this.count += 1; + this.alertCount += 1; + } + public void incError() { this.count += 1; @@ -108,9 +135,20 @@ public class UptimeStat this.okCount += 1; } - public void setLastStatus(final UptimeStatus status) + public void incVoid() + { + this.count += 1; + this.voidCount += 1; + } + + public void incWarning() + { + this.count += 1; + this.warningCount += 1; + } + + public void setStatus(final UptimeStatus status) { this.last = status; } - }
Service