Merge branch 'master' into master

pull/324/head
Hunter Long 2019-12-26 04:44:35 -08:00 committed by GitHub
commit 76f85ebb2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 141 additions and 78 deletions

View File

@ -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

View File

@ -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()

View File

@ -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: "<html>this is an example response</html>",
CreatedAt: time.Now().Add(-24 * time.Hour),
}

View File

@ -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,
})

View File

@ -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")

View File

@ -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)
}

View File

@ -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: "<html>this is an example response</html>",
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

View File

@ -48,7 +48,7 @@
.card-body {
font-size: 10pt;
padding: 0px 10px;
padding: 10px 10px;
}
.lg_number {

View File

@ -7,6 +7,7 @@
{{else}}
<form class="ajax_form" action="/api/services" data-redirect="/services" method="POST">
{{end}}
<h4 class="mb-5 text-muted">Basic Information</h4>
<div class="form-group row">
<label for="service_name" class="col-sm-4 col-form-label">Service Name</label>
<div class="col-sm-8">
@ -33,6 +34,21 @@
<small class="form-text text-muted">Statping will attempt to connect to this URL</small>
</div>
</div>
<div class="form-group row">
<label for="service_type" class="col-sm-4 col-form-label">Group</label>
<div class="col-sm-8">
<select name="group_id" class="form-control" id="group_id">
<option value="0" {{if eq $s.GroupId 0}}selected{{end}}>None</option>
{{range Groups false}}
<option value="{{.Id}}" {{if eq $s.GroupId .Id}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
<small class="form-text text-muted">Attach this service to a group</small>
</div>
</div>
<h4 class="mt-5 mb-5 text-muted">Request Details</h4>
<div class="form-group row{{if (eq .Type "tcp") or (eq .Type "udp")}} d-none{{end}}">
<label for="service_check_type" class="col-sm-4 col-form-label">Service Check Type</label>
<div class="col-sm-8">
@ -80,6 +96,9 @@
<input type="number" name="port" class="form-control" value="{{if ne .Port 0}}{{.Port}}{{end}}" id="service_port" placeholder="8080">
</div>
</div>
<h4 class="mt-5 mb-5 text-muted">Additional Options</h4>
<div class="form-group row">
<label for="service_interval" class="col-sm-4 col-form-label">Check Interval (Seconds)</label>
<div class="col-sm-8">
@ -138,18 +157,6 @@
</span>
</div>
</div>
<div class="form-group row">
<label for="service_type" class="col-sm-4 col-form-label">Group</label>
<div class="col-sm-8">
<select name="group_id" class="form-control" id="group_id">
<option value="0" {{if eq $s.GroupId 0}}selected{{end}}>None</option>
{{range Groups false}}
<option value="{{.Id}}" {{if eq $s.GroupId .Id}}selected{{end}}>{{.Name}}</option>
{{end}}
</select>
<small class="form-text text-muted">Attach this service to a group</small>
</div>
</div>
<div class="form-group row">
<div class="{{if ne .Id 0}}col-6{{else}}col-12{{end}}">
<button type="submit" class="btn btn-success btn-block">{{if ne .Id 0}}Update Service{{else}}Create Service{{end}}</button>

View File

@ -4,7 +4,7 @@
{{template "nav"}}
{{if .}}
<div class="col-12">
<h3>Messages</h3>
<h1 class="text-black-50">Messages</h1>
<table class="table table-striped">
<thead>
<tr>
@ -34,7 +34,7 @@
{{end}}
{{if Auth}}
<div class="col-12">
<h3>Create Message</h3>
<h1 class="text-black-50 mt-5">Create Message</h1>
{{template "form_message" NewMessage}}
</div>
{{end}}
@ -56,4 +56,4 @@ $(document).ready(function() {
});
});
</script>
{{end}}
{{end}}

View File

@ -0,0 +1,9 @@
{{define "title"}}Statping | Create Service{{end}}
{{define "content"}}
<div class="container col-md-7 col-sm-12 mt-md-5 bg-light">
{{template "nav"}}
<div class="col-12">
{{template "form_service" NewService}}
</div>
</div>
{{end}}

View File

@ -5,7 +5,9 @@
<div class="col-12">
{{if ne (len .Services) 0}}
<h3>Services</h3>
<h1 class="text-black-50">Services <a href="/service/create" class="btn btn-outline-success mt-1 float-right">
<i class="fas fa-plus"></i> Create</a>
</h1>
<table class="table">
<thead>
<tr>
@ -21,7 +23,7 @@
<tr id="service_{{.Id}}" data-id="{{.Id}}">
<td><span class="drag_icon d-none d-md-inline"><i class="fas fa-bars"></i></span> {{.Name}}</td>
<td class="d-none d-md-table-cell">{{if .Online}}<span class="badge badge-success">ONLINE</span>{{else}}<span class="badge badge-danger">OFFLINE</span>{{end}}
<i class="toggle-service fas {{if .IsRunning}}fa-toggle-on text-success{{else}}fa-toggle-off text-muted{{end}}" data-online="{{if .IsRunning}}true{{else}}false{{end}}" data-id="{{.Id}}"></i>
<i class="toggle-service fas {{if .IsRunning}}fa-toggle-on{{else}}fa-toggle-off{{end}} {{if .Online}}text-success{{else}}text-danger{{end}}" data-online="{{if .IsRunning}}true{{else}}false{{end}}" data-id="{{.Id}}"></i>
</td>
<td class="d-none d-md-table-cell">{{if .Public.Bool}}<span class="badge badge-primary">PUBLIC</span>{{else}}<span class="badge badge-secondary">PRIVATE</span>{{end}}</td>
<td class="d-none d-md-table-cell">{{if ne .GroupId 0}}<span class="badge badge-secondary">{{(Group .GroupId).Name}}</span>{{end}}</td>
@ -36,14 +38,10 @@
</tbody>
</table>
{{end}}
{{if Auth}}
<h3>Create Service</h3>
{{template "form_service" NewService}}
{{end}}
</div>
<div class="col-12 mt-3">
<h3>Groups</h3>
<div class="col-12 mt-5">
<h1 class="text-muted">Groups</h1>
<table class="table">
<thead>
<tr>
@ -70,7 +68,7 @@
</tbody>
</table>
{{if Auth}}
<h3>Create Group</h3>
<h1 class="text-muted mt-5">Create Group</h1>
{{template "form_group" NewGroup}}
{{end}}
</div>

View File

@ -6,11 +6,16 @@
<div class="row">
<div class="col-md-3 col-sm-12 mb-4 mb-md-0">
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<h6 class="text-muted">Main Settings</h6>
<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true"><i class="fa fa-cogs"></i> Settings</a>
<a class="nav-link" id="v-pills-notifications-tab" data-toggle="pill" href="#v-pills-notifications" role="tab" aria-controls="v-pills-notifications" aria-selected="true"><i class="fa fa-bell"></i> Notifications</a>
<a class="nav-link" id="v-pills-style-tab" data-toggle="pill" href="#v-pills-style" role="tab" aria-controls="v-pills-style" aria-selected="false"><i class="fa fa-image"></i> Theme Editor</a>
<a class="nav-link" id="v-pills-cache-tab" data-toggle="pill" href="#v-pills-cache" role="tab" aria-controls="v-pills-cache" aria-selected="false"><i class="fa fa-paperclip"></i> Cache</a>
<h6 class="mt-4 text-muted">Notifiers</h6>
{{ range .Notifications }}
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Select.Method}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Select.Method}}" role="tab" aria-controls="v-pills-{{underscore .Select.Method}}" aria-selected="false"><i class="{{.Select.Icon}}"></i> {{.Select.Method}}</a>
<a class="nav-link text-capitalize" id="v-pills-{{underscore .Select.Method}}-tab" data-toggle="pill" href="#v-pills-{{underscore .Select.Method}}" role="tab" aria-controls="v-pills-{{underscore .Select.Method}}" aria-selected="false"><i class="{{.Select.Icon}}"></i> {{.Select.Method}}
{{if .Select.Enabled.Bool}}<span class="badge badge-light float-right mt-1"><div class="fas fa-check text-success"></div></span>{{end}}</a>
{{ end }}
<a class="nav-link d-none" id="v-pills-backups-tab" data-toggle="pill" href="#v-pills-backups" role="tab" aria-controls="v-pills-backups" aria-selected="false">Backups</a>
{{ range .Plugins }}
@ -24,8 +29,6 @@
{{end}}
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">
<h3>Settings</h3>
<form method="POST" action="/settings">
<div class="form-group">
<label for="project">Project Name</label>
@ -37,21 +40,6 @@
<input type="text" name="description" class="form-control" value="{{ .Description }}" id="description" placeholder="Great Uptime">
</div>
<div class="form-group">
<div class="col-4 col-sm-4 mt-sm-1 mt-0">
<label for="update_notify" class="d-inline d-sm-none">Send Updates only</label>
<label for="update_notify" class="d-none d-sm-block">Send Updates only</label>
<span class="switch">
<input type="checkbox" name="update_notify-option" class="switch" id="switch-update_notify"{{if UPDATENOTIFY}} checked{{end}}>
<label for="switch-update_notify" class="mt-2 mt-sm-0"></label>
<small class="form-text text-muted">Enabling this will send only notifications when the status of a services changes.</small>
</span>
<input type="hidden" name="update_notify" id="switch-update_notify-value" value="{{if UPDATENOTIFY}}true{{else}}false{{end}}">
</div>
</div>
<div class="form-group row">
<div class="col-8 col-sm-9">
<label for="domain">Domain</label>
@ -138,7 +126,7 @@
</form>
<h3 class="mt-4">Bulk Import Services</h3>
<h2 class="mt-5">Bulk Import Services</h2>
You can import multiple services based on a CSV file with the format shown on the <a href="https://github.com/hunterlong/statping/wiki/Bulk-Import-Services" target="_blank">Bulk Import Wiki</a>.
<div class="card mt-2">
@ -154,22 +142,42 @@
</div>
</div>
<h3 class="mt-4">Additional Settings</h3>
<div class="row">
<div class="col-12">
{{if .Domain}}
<div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
<h2 class="mt-5">Additional Settings</h2>
<div class="row">
<div class="col-12">
<div class="row align-content-center">
<img class="rounded text-center" width="300" height="300" src="https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl={{ QrAuth }}">
</div>
<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a>
<a href="/settings/export" class="btn btn-sm btn-secondary">Export Settings</a>
</div>
</div>
<a class="btn btn-sm btn-primary" href={{safeURL QrAuth}}>Open in Statping App</a>
<a href="/settings/export" class="btn btn-sm btn-secondary">Export Settings</a>
{{end}}
</div>
</div>
</div>
<div class="tab-pane" id="v-pills-notifications" role="tabpanel" aria-labelledby="v-pills-notifications-tab">
<h3>Notifications</h3>
<form method="POST" action="/settings">
<div class="form-group">
<div class="col-12">
<label for="update_notify" class="d-inline d-sm-none">Send Updates only</label>
<label for="update_notify" class="d-none d-sm-block">Send Updates only</label>
<span class="switch">
<input type="checkbox" name="update_notify-option" class="switch" id="switch-update_notify"{{if UPDATENOTIFY}} checked{{end}}>
<label for="switch-update_notify" class="mt-2 mt-sm-0"></label>
<small class="form-text text-muted">Enabling this will send only notifications when the status of a services changes.</small>
</span>
<input type="hidden" name="update_notify" id="switch-update_notify-value" value="{{if UPDATENOTIFY}}true{{else}}false{{end}}">
</div>
</div>
<button type="submit" class="btn btn-primary btn-block">Save Settings</button>
</form>
</div>
<div class="tab-pane" id="v-pills-style" role="tabpanel" aria-labelledby="v-pills-style-tab">

View File

@ -3,7 +3,7 @@
<div class="container col-md-7 col-sm-12 mt-md-5 bg-light">
{{template "nav"}}
<div class="col-12">
<h3>Users</h3>
<h1 class="text-black-50">Users</h1>
<table class="table table-striped">
<thead>
<tr>
@ -26,7 +26,7 @@
</tbody>
</table>
{{if Auth}}
<h3>Create User</h3>
<h1 class="text-black-50 mt-5">Create User</h1>
{{template "form_user" NewUser}}
{{end}}
</div>

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
0.80.65
0.80.66