diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b5ae9a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +tags +statusok +vendor diff --git a/Dockerfile b/Dockerfile index 64d064d..148d61a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,16 @@ -# Donot use this Dockerfile.This is not ready yet. - -# Start from a Debian image with the latest version of Go installed -# and a workspace (GOPATH) configured at /go. -FROM golang +FROM golang:1.11 # Copy the local package files to the container's workspace. -ADD . /go/src/github.com/sanathp/StatusOk - -# Build the outyet command inside the container. -# (You may fetch or manage dependencies here, -# either manually or with a tool like "godep".) -RUN go get github.com/codegangsta/cli -RUN go get github.com/influxdb/influxdb -RUN go get github.com/mailgun/mailgun-go -RUN go install github.com/sanathp/StatusOk - -RUN wget http://influxdb.s3.amazonaws.com/influxdb_0.9.3_amd64.deb -RUN dpkg -i influxdb_0.9.3_amd64.deb -RUN /etc/init.d/influxdb start - -RUN wget https://grafanarel.s3.amazonaws.com/builds/grafana_2.1.3_amd64.deb -RUN apt-get update -RUN apt-get install -y adduser libfontconfig -RUN dpkg -i grafana_2.1.3_amd64.deb -RUN service grafana-server start +ADD . /go/src/github.com/sanathp/statusok +WORKDIR /go/src/github.com/sanathp/statusok +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o statusok . -#how to connect to localhost inside ?? http://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach +# Production image +FROM alpine:3.6 -ENTRYPOINT /go/bin/StatusOk --config /go/src/github.com/sanathp/StatusOk/config.json +RUN apk add --no-cache tzdata ca-certificates gettext +COPY --from=0 /go/src/github.com/sanathp/statusok/statusok /statusok +COPY --from=0 /go/src/github.com/sanathp/statusok/config.template /config.template +COPY --from=0 /go/src/github.com/sanathp/statusok/docker-entrypoint.sh /docker-entrypoint.sh -# Document that the service listens -EXPOSE 80 8083 8086 7321 3000 +ENTRYPOINT /docker-entrypoint.sh diff --git a/README.md b/README.md index d4e6031..e3e753d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,32 @@ Monitor your Website and APIs from your computer.Get notified through Slack or E-mail when your server is down or response time is more than expected. +## Building and running + +You can build or run this project via docker or locally. If running Go 1.11 or later, you can vendor the project via: + +``` +GO111MODULE=on go mod vendor +``` + +And then build: + +``` +go build +``` + +Alternatively, you can build a docker container: + +``` +docker build -t sanathp/statusok +``` + +This relies on the config being passed through as an environment variable. For example, support you have your config locally in config.json: + +``` +CONFIG=$(cat config.json) +docker run --rm -e "CONFIG=$(echo $CONFIG)" sanathp/statusok +``` ## Simple Version diff --git a/config.template b/config.template new file mode 100644 index 0000000..93313f0 --- /dev/null +++ b/config.template @@ -0,0 +1 @@ +$CONFIG diff --git a/database/database.go b/database/database.go index 3e970fb..fec1a8f 100644 --- a/database/database.go +++ b/database/database.go @@ -7,8 +7,8 @@ import ( "reflect" "strings" - "github.com/Sirupsen/logrus" "github.com/sanathp/statusok/notify" + "github.com/sirupsen/logrus" ) var ( diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..d333b4b --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +cat /config.template | envsubst > /config.json +/statusok --config /config.json diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c336bf2 --- /dev/null +++ b/go.mod @@ -0,0 +1,9 @@ +module github.com/sanathp/statusok + +require ( + github.com/codegangsta/cli v1.20.0 + github.com/influxdata/influxdb v1.6.4 + github.com/mailgun/mailgun-go v1.1.1 + github.com/pkg/errors v0.8.0 // indirect + github.com/sirupsen/logrus v1.2.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..be23276 --- /dev/null +++ b/go.sum @@ -0,0 +1,20 @@ +github.com/codegangsta/cli v1.20.0 h1:iX1FXEgwzd5+XN6wk5cVHOGQj6Q3Dcp20lUeS4lHNTw= +github.com/codegangsta/cli v1.20.0/go.mod h1:/qJNoX69yVSKu5o4jLyXAENLRyk1uhi7zkbQ3slBdOA= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/influxdata/influxdb v1.6.4 h1:K8wPlkrP02HzHTJbbUQQ1CZ2Hw6LtpG4xbNEgnlhMZU= +github.com/influxdata/influxdb v1.6.4/go.mod h1:qZna6X/4elxqT3yI9iZYdZrWWdeFOOprn86kgg4+IzY= +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/mailgun/mailgun-go v1.1.1 h1:mjMcm4qz+SbjAYbGJ6DKROViKtO5S0YjpuOUxQfdr2A= +github.com/mailgun/mailgun-go v1.1.1/go.mod h1:NWTyU+O4aczg/nsGhQnvHL6v2n5Gy6Sv5tNDVvC6FbU= +github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/sirupsen/logrus v1.2.0 h1:juTguoYk5qI21pwyTXY3B3Y5cOTH3ZUyZCg1v/mihuo= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/notify/dingding.go b/notify/dingding.go index f65d858..0f2f685 100644 --- a/notify/dingding.go +++ b/notify/dingding.go @@ -40,16 +40,17 @@ func (dingdingNotify DingdingNotify) SendResponseTimeNotification(responseTimeNo } fmt.Printf("%v", msgParam) - if dingdingNotify.Headers[ContentType] == JsonContentType { + if !(dingdingNotify.Headers[ContentType] == JsonContentType) { + return fmt.Errorf("No content provided") + } - jsonBody, jsonErr := getJsonParamsBodyDingding(msgParam) - if jsonErr != nil { - return jsonErr - } - request, reqErr = http.NewRequest(dingdingNotify.RequestType, - dingdingNotify.Url, - jsonBody) + jsonBody, jsonErr := getJsonParamsBodyDingding(msgParam) + if jsonErr != nil { + return jsonErr } + request, reqErr = http.NewRequest(dingdingNotify.RequestType, + dingdingNotify.Url, + jsonBody) if reqErr != nil { return reqErr diff --git a/notify/notify.go b/notify/notify.go index b2f9671..5fd0aea 100644 --- a/notify/notify.go +++ b/notify/notify.go @@ -71,7 +71,7 @@ func AddNew(notificationTypes NotificationTypes) { println("Notifications : Failed to Initialize ", value.GetClientName(), ".Please check the details in config file ") println("Error Details :", initErr.Error()) } else { - println("Notifications :", value.GetClientName(), " Intialized") + println("Notifications :", value.GetClientName(), " Initialized") } } diff --git a/statusok.go b/statusok.go index 4991a8d..dc9720e 100644 --- a/statusok.go +++ b/statusok.go @@ -3,16 +3,17 @@ package main import ( "encoding/json" "fmt" - "github.com/codegangsta/cli" - "github.com/sanathp/statusok/database" - "github.com/sanathp/statusok/notify" - "github.com/sanathp/statusok/requests" "io" "math/rand" "net/http" "os" "strconv" "time" + + "github.com/codegangsta/cli" + "github.com/sanathp/statusok/database" + "github.com/sanathp/statusok/notify" + "github.com/sanathp/statusok/requests" ) type configParser struct {