diff --git a/Makefile b/Makefile index 8f560f62..5dc8564c 100644 --- a/Makefile +++ b/Makefile @@ -71,10 +71,28 @@ install: build run: build ./$(BINARY_NAME) --ip 0.0.0.0 --port 8080 +# run Statping with Delve for debugging +rundlv: + lsof -ti:8080 | xargs kill + DB_CONN=sqlite DB_HOST=localhost DB_DATABASE=sqlite DB_PASS=none DB_USER=none GO_ENV=test \ + dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./statping + +killdlv: + lsof -ti:2345 | xargs kill + +builddlv: + $(GOBUILD) -gcflags "all=-N -l" -o ./$(BINARY_NAME) -v ./cmd + +watch: + find . -print | grep -i '.*\.\(go\|gohtml\)' | justrun -v -c \ + 'go build -v -gcflags "all=-N -l" -o statping ./cmd && make rundlv &' \ + -delay 10s -stdin \ + -i="Makefile,statping,statup.db,statup.db-journal,handlers/graphql/generated.go" + # compile assets using SASS and Rice. compiles scss -> css, and run rice embed-go compile: generate sass source/scss/base.scss source/css/base.css - cd source && $(GOPATH)/bin/rice embed-go + cd source && rice embed-go rm -rf .sass-cache # benchmark testing @@ -240,7 +258,7 @@ clean: rm -rf dev/test/cypress/videos rm -f coverage.* sass rm -f source/rice-box.go - rm -f *.db-journal + rm -rf **/*.db-journal rm -rf *.snap find . -name "*.out" -type f -delete find . -name "*.cpu" -type f -delete diff --git a/cmd/main.go b/cmd/main.go index b0990e07..1463ed4f 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -25,6 +25,8 @@ import ( "github.com/hunterlong/statping/utils" "github.com/joho/godotenv" "os" + "os/signal" + "syscall" ) var ( @@ -61,6 +63,7 @@ func parseFlags() { // main will run the Statping application func main() { var err error + go sigterm() parseFlags() loadDotEnvs() source.Assets() @@ -92,6 +95,15 @@ func main() { mainProcess() } +// sigterm will attempt to close the database connections gracefully +func sigterm() { + sigs := make(chan os.Signal, 1) + signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL) + <-sigs + core.CloseDB() + os.Exit(1) +} + // loadDotEnvs attempts to load database configs from a '.env' file in root directory func loadDotEnvs() error { err := godotenv.Load() diff --git a/core/notifier/notifiers.go b/core/notifier/notifiers.go index 1de0e1b6..0e3d86ac 100644 --- a/core/notifier/notifiers.go +++ b/core/notifier/notifiers.go @@ -461,3 +461,19 @@ func (n *Notification) IsRunning() bool { return true } } + +// ExampleService can be used for the OnTest() method for notifiers +var ExampleService = &types.Service{ + Id: 1, + Name: "Interpol - All The Rage Back Home", + Domain: "https://www.youtube.com/watch?v=-u6DvRyyKGU", + ExpectedStatus: 200, + Interval: 30, + Type: "http", + Method: "GET", + Timeout: 20, + LastStatusCode: 404, + Expected: types.NewNullString("test example"), + LastResponse: "this is an example response", + CreatedAt: time.Now().Add(-24 * time.Hour), +} diff --git a/core/sample.go b/core/sample.go index 20d3c68f..f53fb386 100644 --- a/core/sample.go +++ b/core/sample.go @@ -44,6 +44,7 @@ func InsertSampleData() error { Order: 1, GroupId: 1, Permalink: types.NewNullString("google"), + VerifySSL: types.NewNullBool(true), CreatedAt: createdOn, }) s2 := ReturnService(&types.Service{ @@ -56,6 +57,7 @@ func InsertSampleData() error { Timeout: 20, Order: 2, Permalink: types.NewNullString("statping_github"), + VerifySSL: types.NewNullBool(true), CreatedAt: createdOn, }) s3 := ReturnService(&types.Service{ @@ -68,6 +70,7 @@ func InsertSampleData() error { Timeout: 30, Order: 3, Public: types.NewNullBool(true), + VerifySSL: types.NewNullBool(true), GroupId: 2, CreatedAt: createdOn, }) @@ -83,6 +86,7 @@ func InsertSampleData() error { Timeout: 30, Order: 4, Public: types.NewNullBool(true), + VerifySSL: types.NewNullBool(true), GroupId: 2, CreatedAt: createdOn, }) diff --git a/handlers/routes.go b/handlers/routes.go index bd1ca48e..44af5554 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -89,6 +89,7 @@ func Router() *mux.Router { // SERVICE Routes r.Handle("/services", authenticated(servicesHandler, true)).Methods("GET") + r.Handle("/service/create", authenticated(createServiceHandler, true)).Methods("GET") r.Handle("/service/{id}", http.HandlerFunc(servicesViewHandler)).Methods("GET") r.Handle("/service/{id}/edit", authenticated(servicesViewHandler, true)).Methods("GET") r.Handle("/service/{id}/delete_failures", authenticated(servicesDeleteFailuresHandler, true)).Methods("GET") diff --git a/handlers/services.go b/handlers/services.go index 8873926b..453b9050 100644 --- a/handlers/services.go +++ b/handlers/services.go @@ -335,3 +335,7 @@ func apiServiceHitsHandler(w http.ResponseWriter, r *http.Request) { returnJson(hits, w, r) } + +func createServiceHandler(w http.ResponseWriter, r *http.Request) { + ExecuteResponse(w, r, "service_create.gohtml", core.CoreApp, nil) +} diff --git a/notifiers/webhook.go b/notifiers/webhook.go index c76b69a9..41b1e03a 100644 --- a/notifiers/webhook.go +++ b/notifiers/webhook.go @@ -129,21 +129,7 @@ func (w *webhooker) sendHttpWebhook(body string) (*http.Response, error) { } func (w *webhooker) OnTest() error { - service := &types.Service{ - Id: 1, - Name: "Interpol - All The Rage Back Home", - Domain: "https://www.youtube.com/watch?v=-u6DvRyyKGU", - ExpectedStatus: 200, - Interval: 30, - Type: "http", - Method: "GET", - Timeout: 20, - LastStatusCode: 404, - Expected: types.NewNullString("test example"), - LastResponse: "this is an example response", - CreatedAt: time.Now().Add(-24 * time.Hour), - } - body := replaceBodyText(w.Var2, service, nil) + body := replaceBodyText(w.Var2, notifier.ExampleService, nil) resp, err := w.sendHttpWebhook(body) if err != nil { return err diff --git a/source/scss/mobile.scss b/source/scss/mobile.scss index 0ae37874..f5d4cdca 100644 --- a/source/scss/mobile.scss +++ b/source/scss/mobile.scss @@ -48,7 +48,7 @@ .card-body { font-size: 10pt; - padding: 0px 10px; + padding: 10px 10px; } .lg_number { diff --git a/source/tmpl/form_service.gohtml b/source/tmpl/form_service.gohtml index f9ee9376..964b84e2 100644 --- a/source/tmpl/form_service.gohtml +++ b/source/tmpl/form_service.gohtml @@ -7,6 +7,7 @@ {{else}}
{{end}} +

Basic Information

@@ -33,6 +34,21 @@ Statping will attempt to connect to this URL
+
+ +
+ + Attach this service to a group +
+
+ +

Request Details

+
@@ -80,6 +96,9 @@
+ +

Additional Options

+
@@ -138,18 +157,6 @@
-
- -
- - Attach this service to a group -
-
diff --git a/source/tmpl/messages.gohtml b/source/tmpl/messages.gohtml index 5ec025e4..4d19672e 100644 --- a/source/tmpl/messages.gohtml +++ b/source/tmpl/messages.gohtml @@ -4,7 +4,7 @@ {{template "nav"}} {{if .}}
-

Messages

+

Messages

@@ -34,7 +34,7 @@ {{end}} {{if Auth}}
-

Create Message

+

Create Message

{{template "form_message" NewMessage}}
{{end}} @@ -56,4 +56,4 @@ $(document).ready(function() { }); }); -{{end}} \ No newline at end of file +{{end}} diff --git a/source/tmpl/service_create.gohtml b/source/tmpl/service_create.gohtml new file mode 100644 index 00000000..86bb0712 --- /dev/null +++ b/source/tmpl/service_create.gohtml @@ -0,0 +1,9 @@ +{{define "title"}}Statping | Create Service{{end}} +{{define "content"}} +
+{{template "nav"}} +
+ {{template "form_service" NewService}} +
+
+{{end}} diff --git a/source/tmpl/services.gohtml b/source/tmpl/services.gohtml index f97252d4..99ce6b60 100644 --- a/source/tmpl/services.gohtml +++ b/source/tmpl/services.gohtml @@ -5,7 +5,9 @@
{{if ne (len .Services) 0}} -

Services

+

Services + Create +

@@ -21,7 +23,7 @@ @@ -36,14 +38,10 @@
{{.Name}} {{if .Online}}ONLINE{{else}}OFFLINE{{end}} - + {{if .Public.Bool}}PUBLIC{{else}}PRIVATE{{end}} {{if ne .GroupId 0}}{{(Group .GroupId).Name}}{{end}}
{{end}} - {{if Auth}} -

Create Service

- {{template "form_service" NewService}} - {{end}}
-
-

Groups

+
+

Groups

@@ -70,7 +68,7 @@
{{if Auth}} -

Create Group

+

Create Group

{{template "form_group" NewGroup}} {{end}}
diff --git a/source/tmpl/settings.gohtml b/source/tmpl/settings.gohtml index 11954288..465f9d96 100644 --- a/source/tmpl/settings.gohtml +++ b/source/tmpl/settings.gohtml @@ -6,11 +6,16 @@