Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notifications #86

Merged
merged 2 commits into from
Apr 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 30 additions & 12 deletions timon/webclient/webif1/src/components/Timon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -321,19 +319,33 @@ export default {
this.mk_minemap_cfg(cfg)
return
},
notify (probeinfo) {
notify () {
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 = '#'
Expand All @@ -349,7 +361,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"] = "-";
Expand Down Expand Up @@ -390,7 +404,7 @@ export default {
}
}
if(cur_probe_rslt["newError"]){
this.notify(cur_probe_rslt);
probe_notifs_to_send.push(cur_probe_rslt);
}
}
},
Expand Down Expand Up @@ -425,6 +439,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 => {
Expand Down