From 1c57f5af535f47ae28383cc311b561a58b8926fe Mon Sep 17 00:00:00 2001 From: hunterlong Date: Tue, 1 Sep 2020 20:50:17 -0700 Subject: [PATCH] notifier endpoint fixes, timeframe rounding chart data --- frontend/src/API.js | 2 +- .../src/components/Dashboard/ServiceInfo.vue | 20 +++++++++---------- .../components/Service/FailuresBarChart.vue | 3 ++- .../src/components/Service/ServiceBlock.vue | 1 - .../src/components/Service/ServiceChart.vue | 13 +++++------- frontend/src/mixin.js | 17 ++++++++++++---- frontend/src/pages/Help.vue | 2 +- frontend/src/pages/Index.vue | 13 +++++------- handlers/notifications.go | 9 ++++++++- notifiers/slack_test.go | 2 +- 10 files changed, 46 insertions(+), 36 deletions(-) diff --git a/frontend/src/API.js b/frontend/src/API.js index 82dbb00b..9cbc9ed6 100644 --- a/frontend/src/API.js +++ b/frontend/src/API.js @@ -8,7 +8,7 @@ const tokenKey = "statping_auth"; class Api { constructor() { this.version = "0.90.65"; - this.commit = "3051206a7a843b97c92462a536f1c54ee92fbab8"; + this.commit = "5bc10fcc8536a08ce7a099a0b4cbceb2dc9fc35b"; } async oauth() { diff --git a/frontend/src/components/Dashboard/ServiceInfo.vue b/frontend/src/components/Dashboard/ServiceInfo.vue index d9e7d23c..eecb593d 100644 --- a/frontend/src/components/Dashboard/ServiceInfo.vue +++ b/frontend/src/components/Dashboard/ServiceInfo.vue @@ -121,13 +121,14 @@ } }, async getUptime() { - const start = this.nowSubtract(3 * 86400) - this.uptime = await Api.service_uptime(this.service.id, this.toUnix(start), this.toUnix(this.now())) + const end = this.endOf("day", this.now()) + const start = this.beginningOf("day", this.nowSubtract(3 * 86400)) + this.uptime = await Api.service_uptime(this.service.id, this.toUnix(start), this.toUnix(end)) }, async loadInfo() { - this.set1 = await this.getHits(24 * 7, "720m") + this.set1 = await this.getHits(86400 * 7, "12h") this.set1_name = this.calc(this.set1) - this.set2 = await this.getHits(24, "60m") + this.set2 = await this.getHits(86400, "60m") this.set2_name = this.calc(this.set2) this.loaded = true }, @@ -145,14 +146,13 @@ }); total = total / data.length }, - async getHits(hours, group) { - const start = this.nowSubtract(3600 * hours) - const fetched = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(this.now()), group, true) - + async getHits(seconds, group) { + let start = this.nowSubtract(seconds) + let end = this.endOf("today") + const startEnd = this.startEndParams(start, end, group) + const fetched = await Api.service_hits(this.service.id, startEnd.start, startEnd.end, group, true) const data = this.convertToChartData(fetched, 0.001, true) - return [{name: "Latency", ...data}] - }, calc(s) { let data = s[0].data diff --git a/frontend/src/components/Service/FailuresBarChart.vue b/frontend/src/components/Service/FailuresBarChart.vue index d241d776..5720e60a 100644 --- a/frontend/src/components/Service/FailuresBarChart.vue +++ b/frontend/src/components/Service/FailuresBarChart.vue @@ -157,7 +157,8 @@ export default { }, async loadFailures() { this.loaded = false - const data = await Api.service_failures_data(this.service.id, this.toUnix(this.parseISO(this.start)), this.toUnix(this.parseISO(this.end)), this.group, true) + const startEnd = this.startEndParams(this.parseISO(this.start), this.parseISO(this.end), this.group) + const data = await Api.service_failures_data(this.service.id, startEnd.start, startEnd.end, this.group, true) this.loaded = true this.data = [{data: this.convertChartData(data)}] } diff --git a/frontend/src/components/Service/ServiceBlock.vue b/frontend/src/components/Service/ServiceBlock.vue index 735e6d5d..eaa6e31f 100644 --- a/frontend/src/components/Service/ServiceBlock.vue +++ b/frontend/src/components/Service/ServiceBlock.vue @@ -61,7 +61,6 @@ const Analytics = () => import(/* webpackChunkName: "service" */ './Analytics'); const ServiceChart = () => import(/* webpackChunkName: "service" */ "./ServiceChart"); const ServiceTopStats = () => import(/* webpackChunkName: "service" */ "@/components/Service/ServiceTopStats"); -const Graphing = () => import(/* webpackChunkName: "service" */ '../../graphing'); export default { name: 'ServiceBlock', diff --git a/frontend/src/components/Service/ServiceChart.vue b/frontend/src/components/Service/ServiceChart.vue index fca32d5a..482ff7cf 100644 --- a/frontend/src/components/Service/ServiceChart.vue +++ b/frontend/src/components/Service/ServiceChart.vue @@ -195,17 +195,14 @@ methods: { async chartHits(val) { this.ready = false - const start = val.start_time - const end = this.toUnix(new Date()) - this.data = await Api.service_hits(this.service.id, start, end, val.interval, false) - if (this.data === null && val.interval !== "5m") { - await this.chartHits({start_time: val.start_time, interval: "5m"}) - } - this.ping_data = await Api.service_ping(this.service.id, start, end, val.interval, false) + const end = this.endOf("hour", this.now()) + const start = this.beginningOf("hour", this.fromUnix(val.start_time)) + this.data = await Api.service_hits(this.service.id, this.toUnix(start), this.toUnix(end), val.interval, false) + this.ping_data = await Api.service_ping(this.service.id, this.toUnix(start), this.toUnix(end), val.interval, false) this.series = [ {name: "Latency", ...this.convertToChartData(this.data)}, - {name: "Ping", ...this.convertToChartData(this.ping_data)}, + {name: "Ping", ...this.convertToChartData(this.ping_data)}, ] this.ready = true } diff --git a/frontend/src/mixin.js b/frontend/src/mixin.js index e211e907..f66c7d7d 100644 --- a/frontend/src/mixin.js +++ b/frontend/src/mixin.js @@ -1,5 +1,5 @@ import Vue from "vue"; -const { startOfDay, startOfWeek, endOfMonth, startOfToday, startOfTomorrow, startOfYesterday, endOfYesterday, endOfTomorrow, endOfToday, endOfDay, startOfMonth, lastDayOfMonth, subSeconds, getUnixTime, fromUnixTime, differenceInSeconds, formatDistance, addMonths, addSeconds, isWithinInterval } = require('date-fns') +const { startOfDay, startOfHour, startOfWeek, endOfMonth, endOfHour, startOfToday, startOfTomorrow, startOfYesterday, endOfYesterday, endOfTomorrow, endOfToday, endOfDay, startOfMonth, lastDayOfMonth, subSeconds, getUnixTime, fromUnixTime, differenceInSeconds, formatDistance, addMonths, addSeconds, isWithinInterval } = require('date-fns') import formatDistanceToNow from 'date-fns/formatDistanceToNow' import format from 'date-fns/format' import parseISO from 'date-fns/parseISO' @@ -59,6 +59,8 @@ export default Vue.mixin({ }, endOf(method, val) { switch (method) { + case "hour": + return endOfHour(val) case "day": return endOfDay(val) case "today": @@ -70,10 +72,17 @@ export default Vue.mixin({ case "month": return endOfMonth(val) } - return roundToNearestMinutes(val) + return val + }, + startEndParams(start, end, group) { + start = this.beginningOf("hour", start) + end = this.endOf("hour", end) + return {start: this.toUnix(start), end: this.toUnix(end), group: group} }, beginningOf(method, val) { switch (method) { + case "hour": + return startOfHour(val) case "day": return startOfDay(val) case "today": @@ -83,11 +92,11 @@ export default Vue.mixin({ case "yesterday": return startOfYesterday() case "week": - return startOfWeek() + return startOfWeek(val) case "month": return startOfMonth(val) } - return roundToNearestMinutes(val) + return val }, isZero(val) { return getUnixTime(parseISO(val)) <= 0 diff --git a/frontend/src/pages/Help.vue b/frontend/src/pages/Help.vue index 62fae234..03f407de 100755 --- a/frontend/src/pages/Help.vue +++ b/frontend/src/pages/Help.vue @@ -2275,7 +2275,7 @@ OluFxewsEO0QNDrfFb+0gnjYlnGqOFcZjUMXbDdY5oLSPtXohynuTK1qyQ==
-Automatically generated from Statping's Wiki on 2020-08-30 00:32:40.685063 +0000 UTC +Automatically generated from Statping's Wiki on 2020-09-02 02:46:04.864615 +0000 UTC
diff --git a/frontend/src/pages/Index.vue b/frontend/src/pages/Index.vue index 8dd36692..78197ea8 100644 --- a/frontend/src/pages/Index.vue +++ b/frontend/src/pages/Index.vue @@ -24,7 +24,6 @@ -
@@ -64,20 +63,18 @@ export default { }, computed: { loading_text() { - if (this.core == null) { + if (!this.$store.getters.core.version) { return "Loading Core" - } else if (this.groups == null) { + } else if (this.$store.getters.groups.length === 0) { return "Loading Groups" - } else if (this.services == null) { + } else if (this.$store.getters.services.length === 0) { return "Loading Services" - } else if (this.messages == null) { + } else if (this.$store.getters.messages == null) { return "Loading Announcements" - } else { - return "Completed" } }, loaded() { - return this.core !== null && this.groups !== null && this.services !== null + return this.$store.getters.core.version && this.$store.getters.services.length !== 0 }, core() { return this.$store.getters.core diff --git a/handlers/notifications.go b/handlers/notifications.go index da4a2c1f..8832487d 100644 --- a/handlers/notifications.go +++ b/handlers/notifications.go @@ -13,7 +13,14 @@ import ( func apiNotifiersHandler(w http.ResponseWriter, r *http.Request) { var notifs []notifications.Notification for _, n := range services.AllNotifiers() { - notifs = append(notifs, *n.Select()) + notif := n.Select() + no, err := notifications.Find(notif.Method) + if err != nil { + log.Error(err) + sendErrorJson(err, w, r) + } + notif.UpdateFields(no) + notifs = append(notifs, *notif) } sort.Sort(notifications.NotificationOrder(notifs)) returnJson(notifs, w, r) diff --git a/notifiers/slack_test.go b/notifiers/slack_test.go index 8600d1fa..4ed28bce 100644 --- a/notifiers/slack_test.go +++ b/notifiers/slack_test.go @@ -40,7 +40,7 @@ func TestSlackNotifier(t *testing.T) { t.Run("Load slack", func(t *testing.T) { slacker.Host = null.NewNullString(SLACK_URL) - slacker.Delay = time.Duration(100 * time.Millisecond) + slacker.Delay = 100 * time.Millisecond slacker.Limits = 3 Add(slacker) assert.Equal(t, "Hunter Long", slacker.Author)