-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
75 lines (67 loc) · 1.38 KB
/
main.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
73
74
75
package main
import (
"flag"
"log"
"time"
)
func main() {
cfgfile := flag.String("config", "config.ini", "config file path")
flag.Parse()
cfg, err := NewGateConfig(*cfgfile)
if err != nil {
log.Fatal("Error parsing config: ", err)
}
bus := &MonitorConn{
State: make(chan State),
Sms: make(chan SMS),
}
monitors := make(map[string]Monitor)
for n, c := range cfg.Dev_AMI {
log.Println("Monitor: creating", n)
c.Name = n
mon, err := NewMonitorAMI(c)
if err != nil {
log.Fatal(err)
}
monitors[n] = mon
}
for n, mon := range monitors {
log.Println("Monitor: starting", n)
err := mon.Start(bus)
if err != nil {
log.Fatal(err)
}
}
for exit := false; exit == false; {
select {
case st := <-bus.State:
log.Println("Event:", st.Name, st)
dev := monitors[st.Name]
switch st.Num {
case MonitorStopped:
if st.Status == "" {
exit = true
break
}
time.Sleep(4 * time.Second)
err := dev.Start(bus)
if err != nil {
log.Fatal(err)
}
/*case MonitorRunning:
log.Println("Event:", st.name, st)
case MonitorStarting:
log.Println("Event:", st.name, st)*/
}
case sms := <-bus.Sms:
log.Println("SMS:", sms)
case <-time.After(15 * time.Second):
dev := monitors["stas0"]
if dev.GetState().Num == MonitorRunning {
dev.Status()
//dev.Stop()
}
}
}
log.Println("Monitor: Exiting")
}