-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopsgenie.go
57 lines (44 loc) · 1.23 KB
/
opsgenie.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
// Functions to get information from OpsGenie
package main
import (
"encoding/json"
"fmt"
"log"
"net/url"
)
const (
opsGenieAPIURL = "https://api.opsgenie.com/v2/schedules/%s/on-calls?scheduleIdentifierType=name&flat=true"
)
type genieRorationJSON struct {
Data struct {
OnCallRecipients []string `json:"onCallRecipients"`
} `json:"data"`
}
func whoIsOnCallOpsGenie(token string, schedule string, admins map[string]adminAccount) {
var parsedJSON genieRorationJSON
apiURL := fmt.Sprintf(opsGenieAPIURL, url.QueryEscape(schedule))
headers := make(map[string]string)
headers["Authorization"] = fmt.Sprintf("GenieKey %s", url.QueryEscape(token))
unparsedJSON, err := httpGet(apiURL, headers)
if err != nil {
log.Fatalln(err)
}
err = json.Unmarshal(unparsedJSON, &parsedJSON)
if err != nil {
log.Fatalln(err)
}
if *debug {
log.Println("DEBUG: Raw data from OpsGenie")
log.Println("DEBUG:", parsedJSON.Data.OnCallRecipients)
}
for emailFromConfig, dataFromConfig := range admins {
oncall := false
for _, adminFromGenie := range parsedJSON.Data.OnCallRecipients {
if emailFromConfig == adminFromGenie {
oncall = true
}
}
dataFromConfig.genieOnCall = oncall
admins[emailFromConfig] = dataFromConfig
}
}