-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcheckNotifications.go
72 lines (67 loc) · 2.11 KB
/
checkNotifications.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"github.com/platinasystems/tiles/pccserver/models"
"strings"
"time"
)
const (
FREQUENCY = 10 // FIXME move to props
AGENT_TIMEOUT = 300 // FIXME move to props
COLLECTOR_TIMEOUT = 300 // FIXME move to props
LLDP_TIMEOUT = 300 // FIXME move to props
DEFAULT_TIMEOUT = 300 // FIXME move to props
MAAS_INSTALL_TIMEOUT = 900 // FIXME move to props
K8S_INSTALL_TIMEOUT = 1800 // FIXME move to props
PORTUS_TIMEOUT = 600 // FIXME move to props
PXEBOOT_TIMEOUT = 400 // FIXME move to props
PORTUS_NOTIFICATION = "PORTUS"
COLLECTOR_NOTIFICATION = "COLLECTOR"
AGENT_NOTIFICATION = "AGENT"
LLDP_NOTIFICATION = "LLDPD"
SELF_HEAL_NOTIFICATION = "NODE-SELF-HEALING"
PXEBOOT_NODE_ADD_NOTIFICATION = "new node added successfully"
PXEBOOT_NODE_ADD_FAILED_NOTIFICATION = "add node at failed"
)
type status struct {
msg string
isError bool
}
// Synchronize checking for installation
func syncCheckGenericInstallation(id uint64, appTimeout time.Duration, str2Check string, from time.Time, found chan status, breakLoop chan bool) {
s := status{}
timeout := appTimeout * time.Second
for time.Since(from) < timeout {
select {
case <-breakLoop:
return
default:
var (
events []models.Notification
err error
)
events, err = Pcc.GetEvents()
if err != nil {
s.msg = fmt.Sprintf("failed to getEvents ERROR: %v", err)
s.isError = true
found <- s
} else {
for i := 0; i < len(events); i++ {
if events[i].CreatedAt < ConvertToMillis(from) {
continue
}
if strings.Contains(events[i].Message, str2Check) {
s.msg = fmt.Sprintf("\"%v\" notification found in events", str2Check)
s.isError = false
found <- s
break
}
}
}
}
time.Sleep(FREQUENCY * time.Second)
}
s.msg = fmt.Sprint("timeout exceeded")
s.isError = true
found <- s
}