forked from sensu/uchiwa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
42 lines (35 loc) · 1.09 KB
/
helpers.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
package daemon
import (
"errors"
"fmt"
"github.com/contegix/uchiwa/uchiwa/logger"
"github.com/contegix/uchiwa/uchiwa/sensu"
)
// FindDcFromInterface ...
func FindDcFromInterface(data interface{}, datacenters *[]sensu.Sensu) (*sensu.Sensu, map[string]interface{}, error) {
m, ok := data.(map[string]interface{})
if !ok {
logger.Warningf("Type assertion failed. Could not assert the given interface into a map: %+v", data)
return nil, nil, errors.New("Could not determine the datacenter.")
}
id := m["dc"].(string)
if id == "" {
logger.Warningf("The received interface does not contain any datacenter information: ", data)
return nil, nil, errors.New("Could not determine the datacenter.")
}
for _, dc := range *datacenters {
if dc.Name == id {
return &dc, m, nil
}
}
logger.Warningf("Could not find the datacenter %s into %+v: ", id, data)
return nil, nil, fmt.Errorf("Could not find the datacenter %s", id)
}
func setDc(v interface{}, dc string) {
m, ok := v.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert interface: %+v", v)
} else {
m["dc"] = dc
}
}