This commit is contained in:
A. Feldmann
2018-03-14 09:48:49 +01:00
committed by Alexander Trost
parent 3c343fb0a2
commit 33bb722e06
5 changed files with 43 additions and 0 deletions

View File

@@ -21,6 +21,32 @@ type Incident struct {
ComponentStatus int `json:"component_status"`
}
//Get the last still open incident
func (mon *AbstractMonitor) Get(cfg *CachetMonitor) (*Incident, error) {
requestType := "GET"
requestURL := fmt.Sprintf("/incidents?component_id=%d", mon.ComponentID)
_, body, err := cfg.API.NewRequest(requestType, requestURL, nil)
if err != nil {
return nil, err
}
data := make([]Incident, 0)
if err := json.Unmarshal(body.Data, &data); err != nil {
return nil, fmt.Errorf("Cannot parse incident body: %v, %v", err, string(body.Data))
}
//filter out resolved incidents
openIncidents := make([]Incident, 0)
for _, i := range data {
if i.Status < 4 {
openIncidents = append(openIncidents, i)
}
}
if len(openIncidents) == 0 {
return nil, nil
}
return &openIncidents[0], nil
}
// Send - Create or Update incident
func (incident *Incident) Send(cfg *CachetMonitor) error {
switch incident.Status {