Merge branch 'master' into bugfix-522

pull/523/head
Hunter Long 2020-04-26 16:14:46 -07:00 committed by GitHub
commit d1073ca254
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 236 additions and 191 deletions

View File

@ -1,17 +1,25 @@
name: Dev Release
name: Push Request Testing
on:
push:
branches:
- dev
- '*' # matches every branch
- '*/*' # matches every branch containing a single '/'
- '!master' # excludes master
pull_request:
branches:
- master
jobs:
compile:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v1
- uses: actions/setup-go@v2
with:
go-version: '1.14.x'
go-version: '1.14.2'
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- uses: actions/checkout@v2
- name: Add GOBIN to PATH
run: |
@ -19,40 +27,14 @@ jobs:
echo ::set-env name=VERSION::$(cat version.txt)
shell: bash
- name: Install Node
uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Install Global Dependencies
run: npm install -g yarn sass cross-env
- name: Checkout Statping Repo
uses: actions/checkout@v2
- uses: actions/cache@v1
id: nodecache
with:
path: ./frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Download Frontend Dependencies
if: steps.nodecache.outputs.cache-hit != 'true'
working-directory: ./frontend
run: yarn
- uses: actions/cache@v1
id: golangcache
with:
path: |
~/go/pkg/mod
~/go/bin
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go mods
if: steps.golangcache.outputs.cache-hit != 'true'
run: |
@ -61,25 +43,49 @@ jobs:
make test-deps
- name: Build Frontend Statping
run: make clean frontend-build
run: make clean compile
- name: Upload Compiled Frontend
- name: Upload Compiled Frontend (rice-box.go)
uses: actions/upload-artifact@v1
with:
name: static-frontend
path: /home/runner/work/statping/statping/source/dist
name: static-rice-box
path: ./source
test:
pr-test:
needs: compile
runs-on: ubuntu-latest
steps:
- name: Checkout Statping Repo
uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v1
services:
postgres:
image: postgres:10.8
env:
POSTGRES_USER: root
POSTGRES_PASSWORD: password123
POSTGRES_DB: statping
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password123
MYSQL_DATABASE: statping
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- uses: actions/setup-go@v2
with:
go-version: '1.14.x'
go-version: '1.14.2'
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- uses: actions/checkout@v2
- name: Install Global Dependencies
run: npm install -g yarn sass newman cross-env wait-on @sentry/cli
- name: Setting ENV's
run: |
@ -88,75 +94,73 @@ jobs:
echo ::set-env name=VERSION::$(cat version.txt)
shell: bash
- name: Install Node
uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Install Global Dependencies
run: npm install -g yarn sass newman cross-env wait-on @sentry/cli
- uses: actions/cache@v1
id: golangcache
with:
path: |
~/go/pkg/mod
~/go/bin
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go mods
if: steps.golangcache.outputs.cache-hit != 'true'
run: |
go mod download
go mod verify
make test-deps
- name: Download Compiled Frontend
- name: Download Compiled Frontend (rice-box.go)
uses: actions/download-artifact@v1
with:
name: static-frontend
path: /home/runner/work/statping/statping/source/dist
name: static-rice-box
path: ./source
- name: Install Statping
env:
VERSION: ${{ env.VERSION }}
VERSION: ${{ env.VERSION }}
run: |
make build
chmod +x statping
mv statping $(go env GOPATH)/bin/
- name: Go Tests
run: SASS=`which sass` go test -v -covermode=count -coverprofile=coverage.out -p=1 ./...
run: |
go get gotest.tools/gotestsum
gotestsum --no-summary=skipped --format dots -- -covermode=count -coverprofile=coverage.out -p=1 ./...
env:
VERSION: ${{ env.VERSION }}
DB_CONN: sqlite3
STATPING_DIR: /home/runner/work/statping/statping
STATPING_DIR: ${{ github.workspace }}
API_KEY: demopassword123
DISABLE_LOGS: true
ALLOW_REPORTS: true
COVERALLS: ${{ secrets.COVERALLS }}
DISCORD_URL: ${{ secrets.DISCORD_URL }}
EMAIL_HOST: ${{ secrets.EMAIL_HOST }}
EMAIL_USER: ${{ secrets.EMAIL_USER }}
EMAIL_PASS: ${{ secrets.EMAIL_PASS }}
EMAIL_OUTGOING: ${{ secrets.EMAIL_OUTGOING }}
EMAIL_SEND_TO: ${{ secrets.EMAIL_SEND_TO }}
EMAIL_PORT: ${{ secrets.EMAIL_PORT }}
MOBILE_ID: ${{ secrets.MOBILE_ID }}
MOBILE_NUMBER: ${{ secrets.MOBILE_NUMBER }}
PUSHOVER_TOKEN: ${{ secrets.PUSHOVER_TOKEN }}
PUSHOVER_API: ${{ secrets.PUSHOVER_API }}
SLACK_URL: ${{ secrets.SLACK_URL }}
TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }}
TELEGRAM_CHANNEL: ${{ secrets.TELEGRAM_CHANNEL }}
TWILIO_SID: ${{ secrets.TWILIO_SID }}
TWILIO_SECRET: ${{ secrets.TWILIO_SECRET }}
TWILIO_FROM: ${{ secrets.TWILIO_FROM }}
TWILIO_TO: ${{ secrets.TWILIO_TO }}
PUSH_REQUEST: true
- name: Coveralls Testing Coverage
run: goveralls -coverprofile=coverage.out -repotoken $COVERALLS
pr-test-postman:
needs: compile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.14.2'
- name: Setting ENV's
run: |
echo "::add-path::$(go env GOPATH)/bin"
echo "::add-path::/opt/hostedtoolcache/node/10.20.1/x64/bin"
echo ::set-env name=VERSION::$(cat version.txt)
shell: bash
- name: Download Compiled Frontend (rice-box.go)
uses: actions/download-artifact@v1
with:
name: static-rice-box
path: ./source
- name: Install Statping
env:
COVERALLS: ${{ secrets.COVERALLS }}
VERSION: ${{ env.VERSION }}
run: |
make build
chmod +x statping
mv statping $(go env GOPATH)/bin/
- name: Run Statping
run: |
API_SECRET=demosecret123 statping --port=8080 > /dev/null &
sleep 3
- name: Postman Tests
uses: matt-ball/newman-action@master
with:
postmanApiKey: ${{ secrets.POSTMAN_API }}
collection: ./dev/postman.json
environment: ./dev/postman_environment.json
timeoutRequest: 15000
delayRequest: 1000

View File

@ -266,7 +266,9 @@ jobs:
env:
VERSION: ${{ env.VERSION }}
COMMIT: $GITHUB_SHA
run: make build-linux
run: |
go env
make build-linux
- name: Upload Linux Builds
uses: actions/upload-artifact@v1

View File

@ -1,3 +1,12 @@
# 0.90.33 (04-24-2020)
- Fixed config loading method
# 0.90.32 (04-23-2020)
- Modified the saving and loading process config.yml
# 0.90.31 (04-21-2020)
- Version bump for github actions
# 0.90.30 (04-19-2020)
- Attempt to fix Github Actions build process
- Fix for empty database connection string, and not starting in setup mode

View File

@ -1,15 +1,12 @@
FROM statping/statping:base AS base
# Statping main Docker image that contains all required libraries
FROM alpine:latest
LABEL maintainer="Hunter Long (https://github.com/hunterlong)"
ARG VERSION
ARG ARCH
RUN apk --no-cache add libgcc libstdc++ ca-certificates curl jq && update-ca-certificates
RUN apk --no-cache add curl jq libsass linux-headers ca-certificates
RUN curl -L -s https://assets.statping.com/sass -o /usr/local/bin/sass && \
chmod +x /usr/local/bin/sass
RUN curl -fsSL https://github.com/statping/statping/releases/download/v$VERSION/statping-linux-$ARCH.tar.gz -o statping.tar.gz && \
tar -C /usr/local/bin -xzf statping.tar.gz && rm statping.tar.gz
COPY --from=base /go/bin/statping /usr/local/bin/
COPY --from=base /usr/local/bin/sass /usr/local/bin/
COPY --from=base /usr/local/share/ca-certificates /usr/local/share/
WORKDIR /app

View File

@ -10,6 +10,7 @@ PUBLISH_BODY='{ "request": { "branch": "master", "message": "Homebrew update ver
TRAVIS_BUILD_CMD='{ "request": { "branch": "master", "message": "Compile master for Statping v${VERSION}", "config": { "merge_mode": "replace", "language": "go", "go": 1.14, "install": true, "sudo": "required", "services": ["docker"], "env": { "secure": "${TRVIS_SECRET}" }, "before_deploy": ["git config --local user.name \"hunterlong\"", "git config --local user.email \"info@socialeck.com\"", "git tag v$(VERSION) --force"], "deploy": [{ "provider": "releases", "api_key": "$$GITHUB_TOKEN", "file_glob": true, "file": "build/*", "skip_cleanup": true, "on": { "branch": "master" } }], "before_script": ["rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install stable", "nvm install 10.17.0", "nvm use 10.17.0 --default", "npm install -g sass yarn cross-env", "pip install --user awscli"], "script": ["make release"], "after_success": [], "after_deploy": ["make post-release"] } } }'
TEST_DIR=$(GOPATH)/src/github.com/statping/statping
PATH:=/usr/local/bin:$(GOPATH)/bin:$(PATH)
OS = freebsd linux openbsd
ARCHS = 386 arm amd64 arm64
all: clean yarn-install compile docker-base docker-vue build-all
@ -150,38 +151,19 @@ install-local: build
generate:
cd source && go generate
#docker-manifest:
# for arch in $(ARCHS);\
# do \
# echo "Docker build v${VERSION} for linux-$$arch"; \
# docker build -t statping/statping:v${VERSION}-$$arch --build-arg VERSION=${VERSION} --build-arg ARCH=$$arch .; \
# docker push statping/statping:v${VERSION}-$$arch; \
# done
# docker manifest create statping/statping:v${VERSION} statping/statping:v${VERSION}-amd64 statping/statping:v${VERSION}-386 statping/statping:v${VERSION}-arm statping/statping:v${VERSION}-arm64
# for arch in $(ARCHS);\
# do \
# echo "Docker Manifest v${VERSION} for linux-$$arch"; \
# docker manifest annotate --os linux --arch $$arch statping/statping:v${VERSION}-$$arch; \
# done
# docker manifest push statping/statping:v${VERSION}
# docker manifest create statping/statping:latest statping/statping:v${VERSION}-amd64 statping/statping:v${VERSION}-386 statping/statping:v${VERSION}-arm statping/statping:v${VERSION}-arm64
# for arch in $(ARCHS);\
# do \
# echo "Docker Manifest v${VERSION} for linux-$$arch"; \
# docker manifest annotate --os linux --arch $$arch statping/statping:v${VERSION}-$$arch; \
# done
# docker manifest push statping/statping:latest
build-linux:
mkdir build || true
export PWD=`pwd`
@for arch in $(ARCHS);\
do \
echo "Building v${VERSION} for linux-$$arch"; \
mkdir -p releases/statping-linux-$$arch/; \
GO111MODULE="on" GOOS=linux GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -linkmode external -extldflags -static" -o releases/statping-linux-$$arch/statping ${PWD}/cmd || true; \
chmod +x releases/statping-linux-$$arch/statping || true; \
tar -czf releases/statping-linux-$$arch.tar.gz -C releases/statping-linux-$$arch statping || true; \
for os in $(OS);\
do \
echo "Building v$$VERSION for $$os-$$arch"; \
mkdir -p releases/statping-$$os-$$arch/; \
GO111MODULE="on" GOOS=$$os GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" -o releases/statping-$$os-$$arch/statping ${PWD}/cmd || true; \
chmod +x releases/statping-$$os-$$arch/statping || true; \
tar -czf releases/statping-$$os-$$arch.tar.gz -C releases/statping-$$os-$$arch statping || true; \
done \
done
find ./releases/ -name "*.tar.gz" -type f -size +1M -exec mv "{}" build/ \;
@ -190,9 +172,9 @@ build-mac:
export PWD=`pwd`
@for arch in $(ARCHS);\
do \
echo "Building v${VERSION} for darwin-$$arch"; \
echo "Building v$$VERSION for darwin-$$arch"; \
mkdir -p releases/statping-darwin-$$arch/; \
GO111MODULE="on" GOOS=darwin GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION}" -o releases/statping-darwin-$$arch/statping ${PWD}/cmd || true; \
GO111MODULE="on" GOOS=darwin GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" -o releases/statping-darwin-$$arch/statping ${PWD}/cmd || true; \
chmod +x releases/statping-darwin-$$arch/statping || true; \
tar -czf releases/statping-darwin-$$arch.tar.gz -C releases/statping-darwin-$$arch statping || true; \
done
@ -203,9 +185,9 @@ build-win:
export PWD=`pwd`
@for arch in $(ARCHS);\
do \
echo "Building v${VERSION} for windows-$$arch"; \
echo "Building v$$VERSION for windows-$$arch"; \
mkdir -p releases/statping-windows-$$arch/; \
GO111MODULE="on" GOOS=windows GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION}" -o releases/statping-windows-$$arch/statping.exe ${PWD}/cmd || true; \
GO111MODULE="on" GOOS=windows GOARCH=$$arch go build -a -ldflags "-X main.VERSION=${VERSION} -X main.COMMIT=$(TRAVIS_COMMIT)" -o releases/statping-windows-$$arch/statping.exe ${PWD}/cmd || true; \
chmod +x releases/statping-windows-$$arch/statping.exe || true; \
zip -j releases/statping-windows-$$arch.zip releases/statping-windows-$$arch/statping.exe || true; \
done

View File

@ -16,7 +16,7 @@ An easy to use Status Page for your websites and applications. Statping will aut
<h2>A Future-Proof Status Page</h2>
Statping strives to remain future-proof and remain intact if a failure is created. Your Statping service should not be running on the same instance you're trying to monitor. If your server crashes your Status Page should still remaining online to notify your users of downtime.
<br><a href="https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/statping/statping/master/dev/pwd-stack.yml"><img height=25 src="https://assets.statping.com/docker-pwd.png"></a>
<br><a href="https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/statping/statping/master/dev/pwd-stack.yml"><img height=25 src="https://assets.statping.com/docker-pwd.png"></a> (dashboard login is `admin`, password `admin`)
<br><br><br>
<h2>No Requirements</h2>

View File

@ -58,8 +58,7 @@ func TestAssetsCLI(t *testing.T) {
b := bytes.NewBufferString("")
cmd.SetOut(b)
cmd.SetArgs([]string{"assets"})
err := cmd.Execute()
require.Nil(t, err)
cmd.Execute()
out, err := ioutil.ReadAll(b)
assert.Nil(t, err)
assert.Contains(t, string(out), VERSION)

2
go.mod
View File

@ -18,7 +18,7 @@ require (
github.com/jinzhu/gorm v1.9.12
github.com/joho/godotenv v1.3.0
github.com/kataras/iris/v12 v12.0.1
github.com/mattn/go-sqlite3 v2.0.1+incompatible
github.com/mattn/go-sqlite3 v2.0.3+incompatible
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/pelletier/go-toml v1.7.0 // indirect
github.com/pkg/errors v0.9.1

2
go.sum
View File

@ -195,6 +195,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mediocregopher/mediocre-go-lib v0.0.0-20181029021733-cb65787f37ed/go.mod h1:dSsfyI2zABAdhcbvkXqgxOxrCsbYeHCPgrZkku60dSg=

View File

@ -185,6 +185,7 @@ func apiLoginHandler(w http.ResponseWriter, r *http.Request) {
form := parseForm(r)
username := form.Get("username")
password := form.Get("password")
user, auth := users.AuthUser(username, password)
if auth {
utils.Log.Infoln(fmt.Sprintf("User %v logged in from IP %v", user.Username, r.RemoteAddr))

View File

@ -24,7 +24,7 @@ func TestCore_UsingAssets(t *testing.T) {
}
func TestCreateAssets(t *testing.T) {
assert.Nil(t, CreateAllAssets(dir))
CreateAllAssets(dir)
assert.True(t, UsingAssets(dir))
assert.Nil(t, CompileSASS(DefaultScss...))
assert.FileExists(t, dir+"/assets/css/main.css")

View File

@ -23,6 +23,7 @@ import (
// Connect will attempt to connect to the sqlite, postgres, or mysql database
func Connect(configs *DbConfig, retry bool) error {
conn := configs.ConnectionString()
p := utils.Params
var err error
log.WithFields(utils.ToFields(configs, conn)).Debugln("attempting to connect to database")
@ -39,16 +40,16 @@ func Connect(configs *DbConfig, retry bool) error {
}
}
apiKey := utils.Params.GetString("API_KEY")
apiSecret := utils.Params.GetString("API_SECRET")
apiKey := p.GetString("API_KEY")
apiSecret := p.GetString("API_SECRET")
configs.ApiKey = apiKey
configs.ApiSecret = apiSecret
log.WithFields(utils.ToFields(dbSession)).Debugln("connected to database")
maxOpenConn := utils.Params.GetInt("MAX_OPEN_CONN")
maxIdleConn := utils.Params.GetInt("MAX_IDLE_CONN")
maxLifeConn := utils.Params.GetDuration("MAX_LIFE_CONN")
maxOpenConn := p.GetInt("MAX_OPEN_CONN")
maxIdleConn := p.GetInt("MAX_IDLE_CONN")
maxLifeConn := p.GetDuration("MAX_LIFE_CONN")
dbSession.DB().SetMaxOpenConns(maxOpenConn)
dbSession.DB().SetMaxIdleConns(maxIdleConn)
@ -82,16 +83,19 @@ func initModels(db database.Database) {
}
func CreateAdminUser(c *DbConfig) error {
log.Infoln(fmt.Sprintf("Core database does not exist, creating now!"))
log.Infoln(fmt.Sprintf("Default Admininstrator user does not exist, creating now! (admin/admin)"))
if c.Username == "" || c.Password == "" {
c.Username = utils.Params.GetString("ADMIN_USER")
c.Password = utils.Params.GetString("ADMIN_PASSWORD")
adminUser := utils.Params.GetString("ADMIN_USER")
adminPass := utils.Params.GetString("ADMIN_PASSWORD")
if adminUser == "" || adminPass == "" {
adminUser = "admin"
adminPass = "admin"
}
admin := &users.User{
Username: c.Username,
Password: c.Password,
Username: adminUser,
Password: adminPass,
Email: "info@admin.com",
Admin: null.NewNullBool(true),
}

View File

@ -1,48 +1,56 @@
package configs
import (
"fmt"
"github.com/statping/statping/types/errors"
"github.com/statping/statping/utils"
"gopkg.in/yaml.v2"
"os"
)
func (d *DbConfig) ConnectionString() string {
var conn string
postgresSSL := utils.Params.GetString("POSTGRES_SSLMODE")
switch d.DbConn {
case "memory", ":memory:":
conn = "sqlite3"
d.DbConn = ":memory:"
return d.DbConn
case "sqlite", "sqlite3":
conn, err := findDbFile(d)
if err != nil {
log.Errorln(err)
}
d.SqlFile = conn
log.Infof("SQL database file at: %s", d.SqlFile)
d.DbConn = "sqlite3"
return d.SqlFile
case "mysql":
host := fmt.Sprintf("%v:%v", d.DbHost, d.DbPort)
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC&time_zone=%%27UTC%%27", d.DbUser, d.DbPass, host, d.DbData)
return conn
case "postgres":
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v timezone=UTC sslmode=%v", d.DbHost, d.DbPort, d.DbUser, d.DbData, d.DbPass, postgresSSL)
return conn
}
return conn
}
func LoadConfigFile(directory string) (*DbConfig, error) {
p := utils.Params
log.Infof("Attempting to read config file at: %s/config.yml ", directory)
utils.Params.SetConfigFile(directory + "/config.yml")
utils.Params.SetConfigType("yaml")
p.SetConfigFile(directory + "/config.yml")
p.SetConfigType("yaml")
p.ReadInConfig()
if utils.FileExists(directory + "/config.yml") {
utils.Params.ReadInConfig()
db := new(DbConfig)
content, err := utils.OpenFile(directory + "/config.yml")
if err == nil {
if err := yaml.Unmarshal([]byte(content), &db); err != nil {
return nil, err
}
}
if os.Getenv("DB_CONN") == "sqlite" || os.Getenv("DB_CONN") == "sqlite3" {
db.DbConn = "sqlite3"
}
if db.DbConn != "" {
p.Set("DB_CONN", db.DbConn)
}
if db.DbHost != "" {
p.Set("DB_HOST", db.DbHost)
}
if db.DbPort != 0 {
p.Set("DB_PORT", db.DbPort)
}
if db.DbPass != "" {
p.Set("DB_PASS", db.DbPass)
}
if db.DbUser != "" {
p.Set("DB_USER", db.DbUser)
}
if db.DbData != "" {
p.Set("DB_DATABASE", db.DbData)
}
if db.Location != "" {
p.Set("LOCATION", db.Location)
}
if db.ApiKey != "" {
p.Set("API_KEY", db.ApiKey)
}
if db.ApiSecret != "" {
p.Set("API_SECRET", db.ApiSecret)
}
configs := &DbConfig{

View File

@ -1,11 +1,48 @@
package configs
import "github.com/statping/statping/utils"
import (
"fmt"
"github.com/statping/statping/utils"
"gopkg.in/yaml.v2"
)
// Save will initially create the config.yml file
func (d *DbConfig) Save(directory string) error {
if err := utils.Params.WriteConfigAs(directory + "/config.yml"); err != nil {
c, err := yaml.Marshal(d)
if err != nil {
return err
}
if err := utils.SaveFile(directory+"/config.yml", c); err != nil {
return nil
}
return nil
}
func (d *DbConfig) ConnectionString() string {
var conn string
postgresSSL := utils.Params.GetString("POSTGRES_SSLMODE")
switch d.DbConn {
case "memory", ":memory:":
conn = "sqlite3"
d.DbConn = ":memory:"
return d.DbConn
case "sqlite", "sqlite3":
conn, err := findDbFile(d)
if err != nil {
log.Errorln(err)
}
d.SqlFile = conn
log.Infof("SQL database file at: %s", d.SqlFile)
d.DbConn = "sqlite3"
return d.SqlFile
case "mysql":
host := fmt.Sprintf("%v:%v", d.DbHost, d.DbPort)
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC&time_zone=%%27UTC%%27", d.DbUser, d.DbPass, host, d.DbData)
return conn
case "postgres":
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v timezone=UTC sslmode=%v", d.DbHost, d.DbPort, d.DbUser, d.DbData, d.DbPass, postgresSSL)
return conn
}
return conn
}

View File

@ -28,7 +28,7 @@ func Samples() error {
}
func createHitsAt(db database.Database, serviceID int64) database.Database {
log.Infoln(fmt.Sprintf("Adding Sample records to service #%d", serviceID))
log.Infoln(fmt.Sprintf("Adding Sample records to service #%d...", serviceID))
createdAt := utils.Now().Add(-3 * types.Day)
p := utils.NewPerlin(2, 2, 5, utils.Now().UnixNano())

View File

@ -1 +1 @@
0.90.31
0.90.33