-
Notifications
You must be signed in to change notification settings - Fork 316
/
victorops.go
46 lines (40 loc) · 1.21 KB
/
victorops.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
package alert
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"time"
"github.com/rudderlabs/rudder-server/config"
)
func (ops *VictorOps) Alert(message string) {
event := map[string]interface{}{
"message_type": "CRITICAL",
"entity_id": ops.instanceName,
"state_message": message,
}
eventJSON, _ := json.Marshal(event)
client := &http.Client{Timeout: config.GetDuration("HttpClient.victorops.timeout", 30, time.Second)}
victorOpsUrl := fmt.Sprintf("https://alert.victorops.com/integrations/generic/20131114/alert/%s/rudderRecovery", ops.routingKey)
resp, err := client.Post(victorOpsUrl, "application/json", bytes.NewBuffer(eventJSON))
// Not handling errors when sending alert to victorops
if err != nil {
pkgLogger.Errorf("Alert: Failed to alert service: %s", err.Error())
return
}
if resp.StatusCode != 200 && resp.StatusCode != 202 {
pkgLogger.Errorf("Alert: Got error response %d", resp.StatusCode)
}
body, err := io.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
pkgLogger.Errorf("Alert: Failed to read response body: %s", err.Error())
return
}
pkgLogger.Infof("Alert: Successful %s", string(body))
}
type VictorOps struct {
routingKey string
instanceName string
}