gofmt -w
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
package cachet
|
||||
|
||||
import (
|
||||
"os"
|
||||
"fmt"
|
||||
"flag"
|
||||
"net/url"
|
||||
"net/http"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Static config
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cachet
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// Incident Cachet data model
|
||||
@@ -11,7 +11,7 @@ type Incident struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Message string `json:"message"`
|
||||
Status int `json:"status"`// 4?
|
||||
Status int `json:"status"` // 4?
|
||||
HumanStatus string `json:"human_status"`
|
||||
Component *Component `json:"component"`
|
||||
ComponentID *int `json:"component_id"`
|
||||
@@ -75,7 +75,7 @@ func (incident *Incident) Send() {
|
||||
incident.ID = data.Incident.ID
|
||||
}
|
||||
|
||||
fmt.Println("ID:"+strconv.Itoa(incident.ID))
|
||||
fmt.Println("ID:" + strconv.Itoa(incident.ID))
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
fmt.Println("Could not create/update incident!")
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cachet
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// SendMetric sends lag metric point
|
||||
@@ -16,7 +16,7 @@ func SendMetric(metricID int, delay int64) {
|
||||
"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 {
|
||||
fmt.Printf("Could not log data point!\n%v\n", err)
|
||||
return
|
||||
|
||||
@@ -2,8 +2,8 @@ package cachet
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
const timeout = time.Duration(time.Second)
|
||||
@@ -66,7 +66,7 @@ func (monitor *Monitor) AnalyseData() {
|
||||
}
|
||||
|
||||
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 {
|
||||
// not enough data
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
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("X-Cachet-Token", Config.APIToken)
|
||||
|
||||
4
main.go
4
main.go
@@ -2,8 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/castawaylabs/cachet-monitor/cachet"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -19,7 +19,7 @@ func main() {
|
||||
fmt.Println()
|
||||
|
||||
ticker := time.NewTicker(time.Second)
|
||||
for _ = range ticker.C {
|
||||
for range ticker.C {
|
||||
for _, monitor := range cachet.Config.Monitors {
|
||||
go monitor.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user