From 8d7331a7e46e49c1599b2d15e7859eec4923a9b3 Mon Sep 17 00:00:00 2001 From: quentin on blaine Date: Thu, 1 Sep 2022 15:50:49 +0200 Subject: [PATCH 1/2] Fix notifications --- .../webclient/webif1/src/components/Timon.vue | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/timon/webclient/webif1/src/components/Timon.vue b/timon/webclient/webif1/src/components/Timon.vue index 5229494..eda74b0 100644 --- a/timon/webclient/webif1/src/components/Timon.vue +++ b/timon/webclient/webif1/src/components/Timon.vue @@ -132,7 +132,7 @@ import axios from 'axios' var autorefreshInterval var THREESECONDS = 3000 -var notifyHist = {} +var probe_notifs_to_send = [] var PROBE_STATUS_BY_PRIORITY = ["ERR", "TIM", "WAR", "UNK", "OK"] export default { @@ -321,19 +321,35 @@ export default { this.mk_minemap_cfg(cfg) return }, - notify (probeinfo) { + notify () { + console.log(probe_notifs_to_send) + let a = 1/0 if (Notification.permission === 'granted' ) { + let options = { + requireInteraction: true + } // send notif - if (notifyHist[realProbename] !== probeinfo.probe_tstamp) { - notifyHist[realProbename] = probeinfo.probe_tstamp - let options = { - requireInteraction: true - } + if (probe_notifs_to_send.length < 5) { + // Maximum five notifications + for( probeinfo in probe_notifs_to_send ){ + let host = probeinfo.host + let probename = probeinfo.probename + let msg = probeinfo.msg + let _ = new Notification( + `host: ${host} \nprobe: ${probename} \nerror: ${msg}`, + options) + } + } + else{ + let host = "all" + let probename = "all" + let msg = `${probe_notifs_to_send.length} new errors` let _ = new Notification( - `host: ${host} \nprobe: ${realProbename} \nerror: ${probeinfo.msg}`, + `host: ${host} \nprobe: ${probename} \nerror: ${msg}`, options) } } + probe_notifs_to_send = []; }, parse_state (state) { var statestr = '#' @@ -349,7 +365,9 @@ export default { newError: false, interval: 0, probe_tstamp: 0, - msg: '' + msg: '', + probename: realProbename, + host: host } if (!(host in this.minemap) || !(realProbename in this.minemap[host])){ cur_probe_rslt["state"] = "-"; @@ -390,7 +408,7 @@ export default { } } if(cur_probe_rslt["newError"]){ - this.notify(cur_probe_rslt); + probe_notifs_to_send.push(cur_probe_rslt); } } }, @@ -425,6 +443,10 @@ export default { console.log('got state', _state) if (_state && this._cfg) { this.parse_cfg_state(this._cfg, _state) + console.log(probe_notifs_to_send.length) + if(probe_notifs_to_send.length > 0){ + this.notify(); + } } }) .catch(e => { From b737a1bb1e66e908dde4d2f8739dc359c466bd3f Mon Sep 17 00:00:00 2001 From: quentin on blaine Date: Tue, 6 Sep 2022 10:13:02 +0200 Subject: [PATCH 2/2] clean --- timon/webclient/webif1/src/components/Timon.vue | 4 ---- 1 file changed, 4 deletions(-) diff --git a/timon/webclient/webif1/src/components/Timon.vue b/timon/webclient/webif1/src/components/Timon.vue index eda74b0..e7affaf 100644 --- a/timon/webclient/webif1/src/components/Timon.vue +++ b/timon/webclient/webif1/src/components/Timon.vue @@ -243,12 +243,10 @@ export default { var fullProbename, probename var minemap = this.minemap = {} for (let [host, hostCfg] of Object.entries(cfg.hosts)) { - // console.log('host', host, hostCfg) probemap[host] = {} minemap[host] = {} for (fullProbename of hostCfg.probes) { probename = cfg.all_probes[fullProbename]['probe'] - // console.log(fullProbename, probename) probes[probename] = probename probemap[host][probename] = { full_name: fullProbename, @@ -322,8 +320,6 @@ export default { return }, notify () { - console.log(probe_notifs_to_send) - let a = 1/0 if (Notification.permission === 'granted' ) { let options = { requireInteraction: true