This commit is contained in:
Matej Kramny
2015-03-20 20:58:56 +01:00
parent cdf51d89f6
commit d421b35e9b
7 changed files with 52 additions and 52 deletions

View File

@@ -1,13 +1,13 @@
package cachet package cachet
import ( import (
"os"
"fmt"
"flag"
"net/url"
"net/http"
"io/ioutil"
"encoding/json" "encoding/json"
"flag"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
) )
// Static config // Static config

View File

@@ -1,9 +1,9 @@
package cachet package cachet
import ( import (
"encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"encoding/json"
) )
// Incident Cachet data model // Incident Cachet data model
@@ -11,7 +11,7 @@ type Incident struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Message string `json:"message"` Message string `json:"message"`
Status int `json:"status"`// 4? Status int `json:"status"` // 4?
HumanStatus string `json:"human_status"` HumanStatus string `json:"human_status"`
Component *Component `json:"component"` Component *Component `json:"component"`
ComponentID *int `json:"component_id"` ComponentID *int `json:"component_id"`
@@ -75,7 +75,7 @@ func (incident *Incident) Send() {
incident.ID = data.Incident.ID incident.ID = data.Incident.ID
} }
fmt.Println("ID:"+strconv.Itoa(incident.ID)) fmt.Println("ID:" + strconv.Itoa(incident.ID))
if resp.StatusCode != 200 { if resp.StatusCode != 200 {
fmt.Println("Could not create/update incident!") fmt.Println("Could not create/update incident!")

View File

@@ -1,9 +1,9 @@
package cachet package cachet
import ( import (
"encoding/json"
"fmt" "fmt"
"strconv" "strconv"
"encoding/json"
) )
// SendMetric sends lag metric point // SendMetric sends lag metric point
@@ -16,7 +16,7 @@ func SendMetric(metricID int, delay int64) {
"value": delay, "value": delay,
}) })
resp, _, err := makeRequest("POST", "/metrics/" + strconv.Itoa(metricID) + "/points", jsonBytes) resp, _, err := makeRequest("POST", "/metrics/"+strconv.Itoa(metricID)+"/points", jsonBytes)
if err != nil || resp.StatusCode != 200 { if err != nil || resp.StatusCode != 200 {
fmt.Printf("Could not log data point!\n%v\n", err) fmt.Printf("Could not log data point!\n%v\n", err)
return return

View File

@@ -2,8 +2,8 @@ package cachet
import ( import (
"fmt" "fmt"
"time"
"net/http" "net/http"
"time"
) )
const timeout = time.Duration(time.Second) const timeout = time.Duration(time.Second)
@@ -66,7 +66,7 @@ func (monitor *Monitor) AnalyseData() {
} }
t := (float32(numDown) / float32(len(monitor.History))) * 100 t := (float32(numDown) / float32(len(monitor.History))) * 100
fmt.Printf("%s %.2f%% Down at %v. Threshold: %.2f%%\n", monitor.Url, t, time.Now().UnixNano() / int64(time.Second), monitor.Threshold) fmt.Printf("%s %.2f%% Down at %v. Threshold: %.2f%%\n", monitor.Url, t, time.Now().UnixNano()/int64(time.Second), monitor.Threshold)
if len(monitor.History) != 10 { if len(monitor.History) != 10 {
// not enough data // not enough data

View File

@@ -7,7 +7,7 @@ import (
) )
func makeRequest(requestType string, url string, reqBody []byte) (*http.Response, []byte, error) { func makeRequest(requestType string, url string, reqBody []byte) (*http.Response, []byte, error) {
req, err := http.NewRequest(requestType, Config.APIUrl + url, bytes.NewBuffer(reqBody)) req, err := http.NewRequest(requestType, Config.APIUrl+url, bytes.NewBuffer(reqBody))
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Cachet-Token", Config.APIToken) req.Header.Set("X-Cachet-Token", Config.APIToken)

View File

@@ -2,8 +2,8 @@ package main
import ( import (
"fmt" "fmt"
"time"
"github.com/castawaylabs/cachet-monitor/cachet" "github.com/castawaylabs/cachet-monitor/cachet"
"time"
) )
func main() { func main() {
@@ -19,7 +19,7 @@ func main() {
fmt.Println() fmt.Println()
ticker := time.NewTicker(time.Second) ticker := time.NewTicker(time.Second)
for _ = range ticker.C { for range ticker.C {
for _, monitor := range cachet.Config.Monitors { for _, monitor := range cachet.Config.Monitors {
go monitor.Run() go monitor.Run()
} }