forked from Cepave/open-falcon-backend
/
bossInfoGen.go
49 lines (43 loc) · 954 Bytes
/
bossInfoGen.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
package boss
import "github.com/astaxie/beego/orm"
func getOrmObj() (q orm.Ormer) {
q = orm.NewOrm()
q.Using("boss")
return
}
func GetIPMap() (hostmap map[string]Hosts) {
hosts := Gethosts()
hostmap = map[string]Hosts{}
for _, h := range hosts {
hostmap[h.Hostname] = h
}
return
}
func Gethosts() (hosts []Hosts) {
q := getOrmObj()
hosts = []Hosts{}
q.Raw("select * from `hosts` where exist = 1").QueryRows(&hosts)
return
}
func GetContactIfo() (contmap map[string]Contactor) {
q := getOrmObj()
contacts := []Contacts{}
q.Raw("select name, phone, email from `contacts`").QueryRows(&contacts)
contmap = map[string]Contactor{}
for _, c := range contacts {
contmap[c.Name] = Contactor{
c.Phone,
c.Email,
c.Name,
}
}
return
}
func GenContactMap() (contactMap map[string]Contactor) {
contactMap = map[string]Contactor{}
contmap := GetContactIfo()
for _, ct := range contmap {
contactMap[ct.Name] = ct
}
return
}