forked from sensu/uchiwa
-
Notifications
You must be signed in to change notification settings - Fork 3
/
check.go
69 lines (57 loc) · 1.46 KB
/
check.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
package uchiwa
import (
"fmt"
"github.com/sensu/uchiwa/uchiwa/helpers"
"github.com/sensu/uchiwa/uchiwa/logger"
"github.com/sensu/uchiwa/uchiwa/structs"
)
// GetCheck retrieves a specific check
func (u *Uchiwa) GetCheck(dc, name string) (map[string]interface{}, error) {
api, err := getAPI(u.Datacenters, dc)
if err != nil {
logger.Warning(err)
return nil, err
}
check, err := api.GetCheck(name)
if err != nil {
logger.Warning(err)
return nil, err
}
// lock results
u.Mu.Lock()
defer u.Mu.Unlock()
check["dc"] = dc
check["silenced"], check["silenced_by"] = helpers.IsCheckSilenced(check, nil, dc, u.Data.Silenced)
return check, nil
}
// IssueCheckExecution sends a POST request to the /stashes endpoint in order to create a stash
func (u *Uchiwa) IssueCheckExecution(data structs.CheckExecution) error {
api, err := getAPI(u.Datacenters, data.Dc)
if err != nil {
logger.Warning(err)
return err
}
_, err = api.IssueCheckExecution(data)
if err != nil {
logger.Warning(err)
return err
}
return nil
}
func (u *Uchiwa) findCheck(name string) ([]interface{}, error) {
var checks []interface{}
for _, c := range u.Data.Checks {
m, ok := c.(map[string]interface{})
if !ok {
logger.Warningf("Could not assert this check to an interface %+v", c)
continue
}
if m["name"] == name {
checks = append(checks, m)
}
}
if len(checks) == 0 {
return nil, fmt.Errorf("Could not find any checks with the name '%s'", name)
}
return checks, nil
}