|
| 1 | +package monitor |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "encoding/json" |
| 6 | + "io" |
| 7 | +) |
| 8 | + |
| 9 | +type CustomNotification struct { |
| 10 | + TitleTemplate string `json:"titleTemplate"` |
| 11 | + UseNewTemplate bool `json:"useNewTemplate"` |
| 12 | +} |
| 13 | + |
| 14 | +type SysdigCapture struct { |
| 15 | + Name string `json:"name"` |
| 16 | + Filters string `json:"filters,omitempty"` |
| 17 | + Duration int `json:"duration"` |
| 18 | + Type string `json:"type,omitempty"` |
| 19 | + BucketName string `json:"bucketName"` |
| 20 | + Folder string `json:"folder,omitempty"` |
| 21 | + Enabled bool `json:"enabled"` |
| 22 | + StorageID interface{} `json:"storageId,omitempty"` |
| 23 | +} |
| 24 | +type SegmentCondition struct { |
| 25 | + Type string `json:"type"` |
| 26 | +} |
| 27 | + |
| 28 | +type Criteria struct { |
| 29 | + Text string `json:"text"` |
| 30 | + Source string `json:"source"` |
| 31 | +} |
| 32 | + |
| 33 | +type Monitor struct { |
| 34 | + Metric string `json:"metric"` |
| 35 | + StdDevFactor float64 `json:"stdDevFactor"` |
| 36 | +} |
| 37 | + |
| 38 | +type alertWrapper struct { |
| 39 | + Alert Alert `json:"alert"` |
| 40 | +} |
| 41 | + |
| 42 | +type Alert struct { |
| 43 | + ID int `json:"id,omitempty"` |
| 44 | + Version int `json:"version,omitempty"` |
| 45 | + Type string `json:"type"` // computed MANUAL |
| 46 | + Name string `json:"name"` |
| 47 | + Description string `json:"description"` |
| 48 | + Enabled bool `json:"enabled"` |
| 49 | + NotificationChannelIds []int `json:"notificationChannelIds"` |
| 50 | + Filter string `json:"filter"` |
| 51 | + Severity int `json:"severity"` // 6 == INFO, 4 == LOW, 2 == MEDIUM, 0 == HIGH // NOT USED |
| 52 | + Timespan int `json:"timespan"` // computed 600000000 |
| 53 | + CustomNotification *CustomNotification `json:"customNotification"` |
| 54 | + TeamID int `json:"teamId,omitempty"` // computed |
| 55 | + AutoCreated bool `json:"autoCreated"` |
| 56 | + SysdigCapture *SysdigCapture `json:"sysdigCapture"` |
| 57 | + RateOfChange bool `json:"rateOfChange,omitempty"` |
| 58 | + ReNotifyMinutes int `json:"reNotifyMinutes"` |
| 59 | + ReNotify bool `json:"reNotify"` |
| 60 | + Valid bool `json:"valid"` |
| 61 | + SeverityLabel string `json:"severityLabel,omitempty"` // MEDIUM == MEDIUM, LOW == LOW, NONE == INFO, HIGH == HIGH |
| 62 | + SegmentBy []string `json:"segmentBy"` |
| 63 | + SegmentCondition *SegmentCondition `json:"segmentCondition"` |
| 64 | + Criteria *Criteria `json:"criteria,omitempty"` |
| 65 | + Monitor []*Monitor `json:"monitor,omitempty"` |
| 66 | + Condition string `json:"condition"` |
| 67 | + SeverityLevel int `json:"severityLevel,omitempty"` // 0 == MEDIUM, 2 == LOW, 4 == INFO, 6 == HIGH |
| 68 | +} |
| 69 | + |
| 70 | +func (a *Alert) ToJSON() io.Reader { |
| 71 | + payload, _ := json.Marshal(alertWrapper{Alert: *a}) |
| 72 | + return bytes.NewBuffer(payload) |
| 73 | +} |
| 74 | + |
| 75 | +func AlertFromJSON(body []byte) Alert { |
| 76 | + var result alertWrapper |
| 77 | + json.Unmarshal(body, &result) |
| 78 | + |
| 79 | + return result.Alert |
| 80 | +} |
0 commit comments