mirror of https://github.com/statping/statping
parent
68f0654b38
commit
55f5322985
2
Makefile
2
Makefile
|
@ -235,7 +235,7 @@ dev-deps:
|
|||
# remove files for a clean compile/build
|
||||
clean:
|
||||
rm -rf ./{logs,assets,plugins,statup.db,config.yml,.sass-cache,config.yml,statping,build,.sass-cache,statup.db,index.html,vendor}
|
||||
rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf cmd/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log,*.html,*.json}
|
||||
rm -rf core/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf handlers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
|
||||
rm -rf notifiers/{logs,assets,plugins,statup.db,config.yml,.sass-cache,*.log}
|
||||
|
|
|
@ -41,8 +41,6 @@ func catchCLI(args []string) error {
|
|||
loadDotEnvs()
|
||||
|
||||
switch args[0] {
|
||||
case "app":
|
||||
handlers.DesktopInit(ipAddress, port)
|
||||
case "version":
|
||||
if COMMIT != "" {
|
||||
fmt.Printf("Statping v%v (%v)\n", VERSION, COMMIT)
|
||||
|
|
|
@ -60,7 +60,7 @@ func TestHelpCommand(t *testing.T) {
|
|||
assert.True(t, c.StdoutContains("statping help - Shows the user basic information about Statping"))
|
||||
}
|
||||
|
||||
func TestExportCommand(t *testing.T) {
|
||||
func TestStaticCommand(t *testing.T) {
|
||||
cmd := helperCommand(nil, "static")
|
||||
var got = make(chan string)
|
||||
commandAndSleep(cmd, time.Duration(10*time.Second), got)
|
||||
|
@ -68,7 +68,16 @@ func TestExportCommand(t *testing.T) {
|
|||
t.Log(gg)
|
||||
assert.Contains(t, gg, "Exporting Static 'index.html' page...")
|
||||
assert.Contains(t, gg, "Exported Statping index page: 'index.html'")
|
||||
assert.True(t, fileExists(dir+"/index.html"))
|
||||
assert.FileExists(t, dir+"/index.html")
|
||||
}
|
||||
|
||||
func TestExportCommand(t *testing.T) {
|
||||
cmd := helperCommand(nil, "export")
|
||||
var got = make(chan string)
|
||||
commandAndSleep(cmd, time.Duration(10*time.Second), got)
|
||||
gg, _ := <-got
|
||||
t.Log(gg)
|
||||
assert.FileExists(t, dir+"/statping-export.json")
|
||||
}
|
||||
|
||||
func TestUpdateCommand(t *testing.T) {
|
||||
|
@ -123,9 +132,12 @@ func TestSassCLI(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateCLI(t *testing.T) {
|
||||
t.SkipNow()
|
||||
run := catchCLI([]string{"update"})
|
||||
assert.EqualError(t, run, "end")
|
||||
cmd := helperCommand(nil, "update")
|
||||
var got = make(chan string)
|
||||
commandAndSleep(cmd, time.Duration(15*time.Second), got)
|
||||
gg, _ := <-got
|
||||
t.Log(gg)
|
||||
assert.Contains(t, gg, "version")
|
||||
}
|
||||
|
||||
func TestTestPackageCLI(t *testing.T) {
|
||||
|
@ -168,13 +180,6 @@ func runCommand(c *exec.Cmd, out chan<- string) {
|
|||
out <- string(bout)
|
||||
}
|
||||
|
||||
func fileExists(file string) bool {
|
||||
if _, err := os.Stat(file); os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func Clean() {
|
||||
utils.DeleteFile(dir + "/config.yml")
|
||||
utils.DeleteFile(dir + "/statping.db")
|
||||
|
|
|
@ -205,5 +205,13 @@ func (f *Failure) ParseError() string {
|
|||
if err {
|
||||
return fmt.Sprintf("Domain is offline or not found")
|
||||
}
|
||||
err = strings.Contains(f.Issue, "i/o timeout")
|
||||
if err {
|
||||
return fmt.Sprintf("Connection Timed Out")
|
||||
}
|
||||
err = strings.Contains(f.Issue, "Client.Timeout exceeded while reading body")
|
||||
if err {
|
||||
return fmt.Sprintf("Timed Out on Response Body")
|
||||
}
|
||||
return f.Issue
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1342,14 +1342,6 @@ More info on: https://github.com/hunterlong/statping
|
|||
|
||||
## Usage
|
||||
|
||||
#### func DesktopInit
|
||||
|
||||
```go
|
||||
func DesktopInit(ip string, port int)
|
||||
```
|
||||
DesktopInit will run the Statping server on a specific IP and port using SQLite
|
||||
database
|
||||
|
||||
#### func ExecuteResponse
|
||||
|
||||
```go
|
||||
|
@ -1601,7 +1593,7 @@ and sass installed on your local system.
|
|||
More info on: https://github.com/hunterlong/statping
|
||||
|
||||
Code generated by go generate; DO NOT EDIT. This file was generated by robots at
|
||||
2019-02-06 10:11:39.973396 -0800 PST m=+0.560856203
|
||||
2019-02-06 12:42:08.202468 -0800 PST m=+0.598756678
|
||||
|
||||
This contains the most recently Markdown source for the Statping Wiki.
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ package handlers
|
|||
import (
|
||||
"encoding/json"
|
||||
"github.com/hunterlong/statping/core"
|
||||
"github.com/hunterlong/statping/types"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -39,85 +37,3 @@ func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
json.NewEncoder(w).Encode(health)
|
||||
}
|
||||
|
||||
func trayHandler(w http.ResponseWriter, r *http.Request) {
|
||||
ExecuteResponse(w, r, "tray.gohtml", core.CoreApp, nil)
|
||||
}
|
||||
|
||||
// DesktopInit will run the Statping server on a specific IP and port using SQLite database
|
||||
func DesktopInit(ip string, port int) {
|
||||
var err error
|
||||
exists := utils.FileExists(utils.Directory + "/statup.db")
|
||||
if exists {
|
||||
core.Configs, err = core.LoadConfigFile(utils.Directory)
|
||||
if err != nil {
|
||||
utils.Log(3, err)
|
||||
return
|
||||
}
|
||||
err = core.Configs.Connect(false, utils.Directory)
|
||||
if err != nil {
|
||||
utils.Log(3, err)
|
||||
return
|
||||
}
|
||||
core.InitApp()
|
||||
RunHTTPServer(ip, port)
|
||||
}
|
||||
|
||||
config := &core.DbConfig{
|
||||
DbConn: "sqlite",
|
||||
Project: "Statping",
|
||||
Description: "Statping running as an App!",
|
||||
Domain: "http://localhost",
|
||||
Username: "admin",
|
||||
Password: "admin",
|
||||
Email: "user@email.com",
|
||||
Error: nil,
|
||||
Location: utils.Directory,
|
||||
}
|
||||
|
||||
config, err = config.Save()
|
||||
if err != nil {
|
||||
utils.Log(4, err)
|
||||
}
|
||||
|
||||
config.DropDatabase()
|
||||
config.CreateDatabase()
|
||||
core.CoreApp = config.CreateCore()
|
||||
|
||||
if err != nil {
|
||||
utils.Log(3, err)
|
||||
return
|
||||
}
|
||||
|
||||
core.Configs, err = core.LoadConfigFile(utils.Directory)
|
||||
if err != nil {
|
||||
utils.Log(3, err)
|
||||
config.Error = err
|
||||
return
|
||||
}
|
||||
|
||||
err = core.Configs.Connect(false, utils.Directory)
|
||||
if err != nil {
|
||||
utils.Log(3, err)
|
||||
core.DeleteConfig()
|
||||
config.Error = err
|
||||
return
|
||||
}
|
||||
|
||||
admin := core.ReturnUser(&types.User{
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
Email: config.Email,
|
||||
Admin: types.NewNullBool(true),
|
||||
})
|
||||
admin.Create()
|
||||
|
||||
core.InsertSampleData()
|
||||
|
||||
config.ApiKey = core.CoreApp.ApiKey
|
||||
config.ApiSecret = core.CoreApp.ApiSecret
|
||||
config.Update()
|
||||
|
||||
core.InitApp()
|
||||
RunHTTPServer(ip, port)
|
||||
}
|
||||
|
|
|
@ -146,7 +146,6 @@ func Router() *mux.Router {
|
|||
// API Generic Routes
|
||||
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
|
||||
r.Handle("/health", http.HandlerFunc(healthCheckHandler))
|
||||
r.Handle("/tray", http.HandlerFunc(trayHandler))
|
||||
r.Handle("/.well-known/", http.StripPrefix("/.well-known/", http.FileServer(http.Dir(dir+"/.well-known"))))
|
||||
|
||||
r.NotFoundHandler = http.HandlerFunc(error404Handler)
|
||||
|
|
|
@ -178,6 +178,13 @@ function FailureAnnotations(chart, service, start=0, end=9999999999, group="hour
|
|||
});
|
||||
}
|
||||
|
||||
|
||||
$('input[id=service_name]').on('keyup', function() {
|
||||
var url = $(this).val();
|
||||
url = url.replace(/[^\w\s]/gi, '').replace(/\s+/g, '-').toLowerCase();
|
||||
$('#permalink').val(url);
|
||||
});
|
||||
|
||||
$('input[type=checkbox]').on('change', function() {
|
||||
var element = $(this).attr('id');
|
||||
$("#"+element+"-value").val(this.checked ? "true" : "false")
|
||||
|
|
|
@ -103,10 +103,11 @@ func UsingAssets(folder string) bool {
|
|||
|
||||
// SaveAsset will save an asset to the '/assets/' folder.
|
||||
func SaveAsset(data []byte, folder, file string) error {
|
||||
utils.Log(1, fmt.Sprintf("Saving %v", folder+"/assets/"+file))
|
||||
err := ioutil.WriteFile(folder+"/assets/"+file, data, 0744)
|
||||
location := folder + "/assets/" + file
|
||||
utils.Log(1, fmt.Sprintf("Saving %v", location))
|
||||
err := utils.SaveFile(location, data)
|
||||
if err != nil {
|
||||
utils.Log(3, fmt.Sprintf("Failed to save %v/%v, %v", folder, file, err))
|
||||
utils.Log(3, fmt.Sprintf("Failed to save %v, %v", location, err))
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -168,16 +169,14 @@ func CopyAllToPublic(box *rice.Box, folder string) error {
|
|||
}
|
||||
if info.IsDir() {
|
||||
folder := fmt.Sprintf("%v/assets/%v/%v", utils.Directory, folder, info.Name())
|
||||
MakePublicFolder(folder)
|
||||
return nil
|
||||
return MakePublicFolder(folder)
|
||||
}
|
||||
file, err := box.Bytes(path)
|
||||
if err != nil {
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
filePath := fmt.Sprintf("%v%v", folder, path)
|
||||
SaveAsset(file, utils.Directory, filePath)
|
||||
return nil
|
||||
filePath := fmt.Sprintf("%v/%v", folder, path)
|
||||
return SaveAsset(file, utils.Directory, filePath)
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2019-02-06 10:11:39.973396 -0800 PST m=+0.560856203
|
||||
// 2019-02-06 12:42:08.202468 -0800 PST m=+0.598756678
|
||||
//
|
||||
// This contains the most recently Markdown source for the Statping Wiki.
|
||||
package source
|
||||
|
|
|
@ -41,7 +41,12 @@ func init() {
|
|||
if os.Getenv("STATPING_DIR") != "" {
|
||||
Directory = os.Getenv("STATPING_DIR")
|
||||
} else {
|
||||
Directory = dir()
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
Directory = "."
|
||||
return
|
||||
}
|
||||
Directory = dir
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +56,23 @@ func ToInt(s interface{}) int64 {
|
|||
case string:
|
||||
val, _ := strconv.Atoi(v)
|
||||
return int64(val)
|
||||
case []byte:
|
||||
val, _ := strconv.Atoi(string(v))
|
||||
return int64(val)
|
||||
case float32:
|
||||
return int64(v)
|
||||
case float64:
|
||||
return int64(v)
|
||||
case int:
|
||||
return int64(v)
|
||||
case int16:
|
||||
return int64(v)
|
||||
case int32:
|
||||
return int64(v)
|
||||
case int64:
|
||||
return v
|
||||
case uint:
|
||||
return int64(v)
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
|
@ -59,7 +81,7 @@ func ToInt(s interface{}) int64 {
|
|||
// ToString converts a int to a string
|
||||
func ToString(s interface{}) string {
|
||||
switch v := s.(type) {
|
||||
case int, int32, int64:
|
||||
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64:
|
||||
return fmt.Sprintf("%v", v)
|
||||
case float32, float64:
|
||||
return fmt.Sprintf("%f", v)
|
||||
|
@ -76,15 +98,6 @@ func ToString(s interface{}) string {
|
|||
}
|
||||
}
|
||||
|
||||
// dir returns the current working directory
|
||||
func dir() string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
return "."
|
||||
}
|
||||
return dir
|
||||
}
|
||||
|
||||
type Timestamp time.Time
|
||||
type Timestamper interface {
|
||||
Ago() string
|
||||
|
|
|
@ -39,26 +39,12 @@ func TestDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCommand(t *testing.T) {
|
||||
t.SkipNow()
|
||||
in, out, err := Command("pwd")
|
||||
assert.Nil(t, err)
|
||||
assert.Contains(t, in, "statup")
|
||||
assert.Contains(t, in, "statping")
|
||||
assert.Empty(t, out)
|
||||
}
|
||||
|
||||
func TestDurationReadable(t *testing.T) {
|
||||
dur, _ := time.ParseDuration("1505s")
|
||||
readable := DurationReadable(dur)
|
||||
assert.Equal(t, "25 minutes", readable)
|
||||
}
|
||||
|
||||
func ExampleDurationReadable() {
|
||||
dur, _ := time.ParseDuration("25m")
|
||||
readable := DurationReadable(dur)
|
||||
fmt.Print(readable)
|
||||
// Output: 25 minutes
|
||||
}
|
||||
|
||||
func TestLog(t *testing.T) {
|
||||
assert.Nil(t, Log(0, errors.New("this is a 0 level error")))
|
||||
assert.Nil(t, Log(1, errors.New("this is a 1 level error")))
|
||||
|
@ -68,31 +54,21 @@ func TestLog(t *testing.T) {
|
|||
assert.Nil(t, Log(5, errors.New("this is a 5 level error")))
|
||||
}
|
||||
|
||||
func TestFormatDuration(t *testing.T) {
|
||||
dur, _ := time.ParseDuration("158s")
|
||||
formatted := FormatDuration(dur)
|
||||
assert.Equal(t, "3 minutes", formatted)
|
||||
dur, _ = time.ParseDuration("-65s")
|
||||
formatted = FormatDuration(dur)
|
||||
assert.Equal(t, "1 minute", formatted)
|
||||
}
|
||||
|
||||
func TestDeleteFile(t *testing.T) {
|
||||
assert.Nil(t, DeleteFile(Directory+"/logs/statup.log"))
|
||||
}
|
||||
|
||||
func TestFailedDeleteFile(t *testing.T) {
|
||||
assert.Error(t, DeleteFile(Directory+"/missingfilehere.txt"))
|
||||
}
|
||||
|
||||
func TestLogHTTP(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", "/", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotEmpty(t, Http(req))
|
||||
func TestToInt(t *testing.T) {
|
||||
assert.Equal(t, int64(55), ToInt("55"))
|
||||
assert.Equal(t, int64(55), ToInt(55))
|
||||
assert.Equal(t, int64(55), ToInt(55.0))
|
||||
assert.Equal(t, int64(55), ToInt([]byte("55")))
|
||||
}
|
||||
|
||||
func TestToString(t *testing.T) {
|
||||
assert.Equal(t, "1", ToString(1))
|
||||
assert.Equal(t, "55", ToString(55))
|
||||
assert.Equal(t, "55.000000", ToString(55.0))
|
||||
assert.Equal(t, "55", ToString([]byte("55")))
|
||||
dir, _ := time.ParseDuration("55s")
|
||||
assert.Equal(t, "55s", ToString(dir))
|
||||
assert.Equal(t, "true", ToString(true))
|
||||
assert.Equal(t, time.Now().Format("Monday January _2, 2006 at 03:04PM"), ToString(time.Now()))
|
||||
}
|
||||
|
||||
func ExampleToString() {
|
||||
|
@ -101,6 +77,46 @@ func ExampleToString() {
|
|||
// Output: 42
|
||||
}
|
||||
|
||||
func TestSaveFile(t *testing.T) {
|
||||
assert.Nil(t, SaveFile(Directory+"/test.txt", []byte("testing saving a file")))
|
||||
}
|
||||
|
||||
func TestFileExists(t *testing.T) {
|
||||
assert.True(t, FileExists(Directory+"/test.txt"))
|
||||
assert.False(t, FileExists(Directory+"fake.txt"))
|
||||
}
|
||||
|
||||
func TestDeleteFile(t *testing.T) {
|
||||
assert.Nil(t, DeleteFile(Directory+"/test.txt"))
|
||||
assert.Error(t, DeleteFile(Directory+"/missingfilehere.txt"))
|
||||
}
|
||||
|
||||
func TestFormatDuration(t *testing.T) {
|
||||
dur, _ := time.ParseDuration("158s")
|
||||
assert.Equal(t, "3 minutes", FormatDuration(dur))
|
||||
dur, _ = time.ParseDuration("-65s")
|
||||
assert.Equal(t, "1 minute", FormatDuration(dur))
|
||||
dur, _ = time.ParseDuration("3s")
|
||||
assert.Equal(t, "3 seconds", FormatDuration(dur))
|
||||
dur, _ = time.ParseDuration("48h")
|
||||
assert.Equal(t, "2 days", FormatDuration(dur))
|
||||
dur, _ = time.ParseDuration("12h")
|
||||
assert.Equal(t, "12 hours", FormatDuration(dur))
|
||||
}
|
||||
|
||||
func ExampleDurationReadable() {
|
||||
dur, _ := time.ParseDuration("25m")
|
||||
readable := DurationReadable(dur)
|
||||
fmt.Print(readable)
|
||||
// Output: 25 minutes
|
||||
}
|
||||
|
||||
func TestLogHTTP(t *testing.T) {
|
||||
req, err := http.NewRequest("GET", "/", nil)
|
||||
assert.Nil(t, err)
|
||||
assert.NotEmpty(t, Http(req))
|
||||
}
|
||||
|
||||
func TestStringInt(t *testing.T) {
|
||||
assert.Equal(t, "1", ToString("1"))
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
0.80.46
|
||||
0.80.47
|
||||
|
|
Loading…
Reference in New Issue