From b60967999355de9a0efea619cfd23bc643eaa829 Mon Sep 17 00:00:00 2001 From: Matej Kramny Date: Sun, 19 Jul 2015 21:32:26 +0100 Subject: [PATCH] Report new incident and set as fixed --- cachet/incident.go | 14 -------------- cachet/monitor.go | 13 +++++++------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/cachet/incident.go b/cachet/incident.go index cce2c19..f02bab1 100644 --- a/cachet/incident.go +++ b/cachet/incident.go @@ -86,20 +86,6 @@ func (incident *Incident) Send() { } } -// GetSimilarIncidentID gets the same incident. -// Updates incident.ID -func (incident *Incident) GetSimilarIncidentID() { - incidents := GetIncidents() - - for _, inc := range incidents { - if incident.Name == inc.Name && incident.Message == inc.Message && incident.Status == inc.Status { - incident.ID = inc.ID - Logger.Printf("Updated incident id to %v\n", inc.ID) - break - } - } -} - func (incident *Incident) fetchComponent() error { _, body, err := makeRequest("GET", "/components/"+string(*incident.ComponentID), nil) if err != nil { diff --git a/cachet/monitor.go b/cachet/monitor.go index 413a418..6dc687b 100644 --- a/cachet/monitor.go +++ b/cachet/monitor.go @@ -100,15 +100,12 @@ func (monitor *Monitor) AnalyseData() { } if monitor.LastFailReason != nil { - monitor.Incident.Message += "\n\n" + *monitor.LastFailReason + monitor.Incident.Message += "\n\n - " + *monitor.LastFailReason } // set investigating status monitor.Incident.SetInvestigating() - // lookup relevant incident - monitor.Incident.GetSimilarIncidentID() - // create/update incident monitor.Incident.Send() monitor.Incident.UpdateComponent() @@ -116,8 +113,12 @@ func (monitor *Monitor) AnalyseData() { // was down, created an incident, its now ok, make it resolved. Logger.Println("Updating incident to resolved...") - // Add resolved message - monitor.Incident.Message += "\n\n-\n\nResolved at " + time.Now().String() + component_id := json.Number(strconv.Itoa(*monitor.ComponentID)) + monitor.Incident = &Incident{ + Name: monitor.Incident.Name, + Message: monitor.Name + " check succeeded", + ComponentID: &component_id, + } monitor.Incident.SetFixed() monitor.Incident.Send()