Load config from disk|url, create incidents

- Resolve incidents after the monitor is up
- Example configuration
- Updated readme
This commit is contained in:
Matej Kramny
2015-03-18 22:58:45 +01:00
parent 44a9cf905f
commit 42237e9c86
9 changed files with 130 additions and 49 deletions

View File

@@ -5,38 +5,33 @@ import (
"bytes"
"strconv"
"net/http"
"io/ioutil"
"encoding/json"
)
func SendMetric(metricId int, delay int64) {
jsonBytes, err := json.Marshal(&map[string]interface{}{
if metricId <= 0 {
return
}
jsonBytes, _ := json.Marshal(&map[string]interface{}{
"value": delay,
})
if err != nil {
panic(err)
}
req, err := http.NewRequest("POST", apiUrl + "/metrics/" + strconv.Itoa(metricId) + "/points", bytes.NewBuffer(jsonBytes))
if err != nil {
panic(err)
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Cachet-Token", apiToken)
client := &http.Client{}
req, _ := http.NewRequest("POST", Config.API_Url + "/metrics/" + strconv.Itoa(metricId) + "/points", bytes.NewBuffer(jsonBytes))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Cachet-Token", Config.API_Token)
resp, err := client.Do(req)
if err != nil {
panic(err)
fmt.Printf("Could not log data point!\n%v\n", err)
return
}
defer resp.Body.Close()
_, _ = ioutil.ReadAll(resp.Body)
// fmt.Println(strconv.Itoa(resp.StatusCode) + " " + string(body))
if resp.StatusCode != 200 {
fmt.Println("Could not log data point!")
}
}
}