From 50e3cf2143b5ec633937b4b97b621c59892e5b26 Mon Sep 17 00:00:00 2001 From: Hunter Long Date: Tue, 8 Jan 2019 20:20:43 -0800 Subject: [PATCH] export groups - minor updates --- .dockerignore | 1 + cmd/cli.go | 1 + core/export.go | 10 +++++++++ core/sample.go | 4 ++-- core/services.go | 5 ++--- dev/Dockerfile-demo | 26 +++++++++++++++++++++++ dev/demo-script.sh | 7 +++++++ dev/play-with-docker.yml | 15 ++++++++++++++ dev/postman_environment.json | 2 +- handlers/api.go | 4 +++- notifiers/mobile.go | 2 +- notifiers/telegram.go | 2 +- notifiers/telegram_test.go | 2 +- source/tmpl/postman.json | 4 ++-- source/wiki.go | 2 +- statuper | 40 ++++++++++++++++++------------------ 16 files changed, 94 insertions(+), 33 deletions(-) create mode 100644 dev/Dockerfile-demo create mode 100755 dev/demo-script.sh create mode 100644 dev/play-with-docker.yml diff --git a/.dockerignore b/.dockerignore index b5ec493b..6d52828a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -13,6 +13,7 @@ vendor servers dev !dev/postman_environment.json +!dev/demo-script.sh !build/alpine-linux-amd64 config.yml statup.db diff --git a/cmd/cli.go b/cmd/cli.go index ae78a73c..a0db23fa 100644 --- a/cmd/cli.go +++ b/cmd/cli.go @@ -233,6 +233,7 @@ func HelpEcho() { fmt.Println(" ADMIN_USER - Username for administrator account (default: admin)") fmt.Println(" ADMIN_PASS - Password for administrator account (default: admin)") fmt.Println(" SASS - Set the absolute path to the sass binary location") + fmt.Println(" HTTP_PROXY - Use a HTTP Proxy for HTTP Requests") fmt.Println(" * You can insert environment variables into a '.env' file in root directory.") fmt.Println("Give Statping a Star at https://github.com/hunterlong/statping") } diff --git a/core/export.go b/core/export.go index 6990505f..7da36f42 100644 --- a/core/export.go +++ b/core/export.go @@ -51,9 +51,18 @@ type ExportData struct { Messages []*Message `json:"messages"` Checkins []*Checkin `json:"checkins"` Users []*User `json:"users"` + Groups []*Group `json:"groups"` Notifiers []types.AllNotifiers `json:"notifiers"` } +// ExportSettings will export a JSON file containing all of the settings below: +// - Core +// - Notifiers +// - Checkins +// - Users +// - Services +// - Groups +// - Messages func ExportSettings() ([]byte, error) { users, err := SelectAllUsers() messages, err := SelectMessages() @@ -66,6 +75,7 @@ func ExportSettings() ([]byte, error) { Checkins: AllCheckins(), Users: users, Services: CoreApp.Services, + Groups: SelectGroups(true, true), Messages: messages, } export, err := json.Marshal(data) diff --git a/core/sample.go b/core/sample.go index 3b6dc473..d92deb64 100644 --- a/core/sample.go +++ b/core/sample.go @@ -66,11 +66,11 @@ func InsertSampleData() error { Name: "JSON API Tester", Domain: "https://jsonplaceholder.typicode.com/posts", ExpectedStatus: 201, - Expected: types.NewNullString(`(title)": "((\\"|[statup])*)"`), + Expected: types.NewNullString(`(title)": "((\\"|[statping])*)"`), Interval: 30, Type: "http", Method: "POST", - PostData: types.NewNullString(`{ "title": "statup", "body": "bar", "userId": 19999 }`), + PostData: types.NewNullString(`{ "title": "statping", "body": "bar", "userId": 19999 }`), Timeout: 30, Order: 4, Public: types.NewNullBool(true), diff --git a/core/services.go b/core/services.go index d43f2683..a51ec869 100644 --- a/core/services.go +++ b/core/services.go @@ -355,9 +355,8 @@ func (s *Service) index() int { } // updateService will update a service in the []*core.Services slice -func updateService(service *Service) { - index := service.index() - CoreApp.Services[index] = service +func updateService(s *Service) { + CoreApp.Services[s.index()] = s } // Delete will remove a service from the database, it will also end the service checking go routine diff --git a/dev/Dockerfile-demo b/dev/Dockerfile-demo new file mode 100644 index 00000000..d3122cee --- /dev/null +++ b/dev/Dockerfile-demo @@ -0,0 +1,26 @@ +FROM alpine +MAINTAINER "Hunter Long (https://github.com/hunterlong)" + +ENV STATPING_VERSION=0.80.35 + +RUN apk add --no-cache ca-certificates linux-headers curl + +RUN curl -L -s https://assets.statping.com/sass -o /usr/local/bin/sass && \ + chmod +x /usr/local/bin/sass + +RUN curl -L -s https://github.com/hunterlong/statping/releases/download/v$STATPING_VERSION/statping-linux-alpine.tar.gz | tar -xz && \ + chmod +x statping && mv statping /usr/local/bin/statping + +ENV DB_CONN=sqlite +ENV NAME="Statping Demo" +ENV DESCRIPTION="An Awesome Demo of a Statping Server running on Docker" +ENV DOMAIN=demo.statping.com +ENV SASS=/usr/local/bin/sass + +ENV IS_DOCKER=true +ENV STATPING_DIR=/app +WORKDIR /app + +COPY ./dev/demo-script.sh /app/ + +ENTRYPOINT ./demo-script.sh diff --git a/dev/demo-script.sh b/dev/demo-script.sh new file mode 100755 index 00000000..82d1002d --- /dev/null +++ b/dev/demo-script.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env sh + +COMMAND="rm -rf /app/statping.db && reboot" + +echo "* * * * * echo $COMMAND >> /test_file 2>&1" > /etc/crontabs/root + +statping \ No newline at end of file diff --git a/dev/play-with-docker.yml b/dev/play-with-docker.yml new file mode 100644 index 00000000..79365363 --- /dev/null +++ b/dev/play-with-docker.yml @@ -0,0 +1,15 @@ +# Deploy Portainer demo (demo.portainer.io) in a play-with-docker playground +# +# - Go to http://play-with-docker.com/?stack=https://raw.githubusercontent.com/portainer/portainer-demo/master/play-with-docker/docker-stack.yml +# - Login and/or Start. +# - Wait until 'Your session is ready!' and 'Close' modal. +# - Refresh (if a shell is not shown). +# - Wait until a link with text '80' is shown. It is the link to the demo. +# - Visit https://github.com/portainer/portainer to check default credentials. +# +version: '3' +services: + trigger: + image: franela/dind + command: sh -c "git clone https://github.com/portainer/portainer-demo/ && ./portainer-demo/portainer-demo.sh && tail -f /dev/null" + volumes: [ '/var/run/docker.sock:/var/run/docker.sock' ] \ No newline at end of file diff --git a/dev/postman_environment.json b/dev/postman_environment.json index 5b59a5b8..66f82a87 100644 --- a/dev/postman_environment.json +++ b/dev/postman_environment.json @@ -1,6 +1,6 @@ { "id": "0ff1dcd6-54f3-44a7-9c18-cc3c8e7df357", - "name": "Local Statup", + "name": "Local Statping", "values": [ { "key": "endpoint", diff --git a/handlers/api.go b/handlers/api.go index 95bbb3bc..5c5ac291 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -40,8 +40,10 @@ func apiIndexHandler(w http.ResponseWriter, r *http.Request) { sendUnauthorizedJson(w, r) return } + coreClone := *core.CoreApp + coreClone.Started = utils.Timezoner(core.CoreApp.Started, core.CoreApp.Timezone) w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(core.CoreApp) + json.NewEncoder(w).Encode(coreClone) } func apiRenewHandler(w http.ResponseWriter, r *http.Request) { diff --git a/notifiers/mobile.go b/notifiers/mobile.go index d0a607d3..4bdee2a8 100644 --- a/notifiers/mobile.go +++ b/notifiers/mobile.go @@ -79,7 +79,7 @@ func dataJson(s *types.Service, f *types.Failure) map[string]interface{} { if f != nil { issue = f.Issue } - link := fmt.Sprintf("statup://service?id=%v", serviceId) + link := fmt.Sprintf("statping://service?id=%v", serviceId) out := map[string]interface{}{ "status": online, "id": serviceId, diff --git a/notifiers/telegram.go b/notifiers/telegram.go index edc1628b..6d092244 100644 --- a/notifiers/telegram.go +++ b/notifiers/telegram.go @@ -117,7 +117,7 @@ func (u *telegram) OnSave() error { // OnTest will test the Twilio SMS messaging func (u *telegram) OnTest() error { - msg := fmt.Sprintf("Testing the Twilio SMS Notifier on your Statup server") + msg := fmt.Sprintf("Testing the Twilio SMS Notifier on your Statping server") return u.Send(msg) } diff --git a/notifiers/telegram_test.go b/notifiers/telegram_test.go index 5e5a01c8..50aa7550 100644 --- a/notifiers/telegram_test.go +++ b/notifiers/telegram_test.go @@ -2,7 +2,7 @@ // Copyright (C) 2018. Hunter Long and the project contributors // Written by Hunter Long and the project contributors // -// https://github.com/hunterlong/statup +// https://github.com/hunterlong/statping // // The licenses for most software and other practical works are designed // to take away your freedom to share and change the works. By contrast, diff --git a/source/tmpl/postman.json b/source/tmpl/postman.json index 53d3117c..37acd3ec 100644 --- a/source/tmpl/postman.json +++ b/source/tmpl/postman.json @@ -2,7 +2,7 @@ "info": { "_postman_id": "94807b85-ef65-4370-9144-b1a74e04cb0e", "name": "Statping", - "description": "Statup API Requests", + "description": "Statping API Requests", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" }, "item": [ @@ -10,7 +10,7 @@ "name": "Main", "item": [ { - "name": "Statup Details", + "name": "Statping Details", "event": [ { "listen": "test", diff --git a/source/wiki.go b/source/wiki.go index 6c1ecb98..8862cc85 100644 --- a/source/wiki.go +++ b/source/wiki.go @@ -1,6 +1,6 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2019-01-03 22:14:02.567846 -0800 PST m=+0.846504189 +// 2019-01-04 02:40:51.133321 -0800 PST m=+0.790626621 // // This contains the most recently Markdown source for the Statping Wiki. package source diff --git a/statuper b/statuper index 22e8c889..c789345e 100755 --- a/statuper +++ b/statuper @@ -10,7 +10,7 @@ US_E_2="ami-cc7a40a9" AMI_IMAGE=$US_W_2 AWS_CLI=$(which aws) DOCKER_CLI=$(which docker) -DOCKER_IMG="hunterlong/statup" +DOCKER_IMG="hunterlong/statping" AWS_ECS="$AWS_CLI --output json" DOCKER_PORT=8080 @@ -20,7 +20,7 @@ cat < $FILE <<- EOM [Unit] Description=Statping Server @@ -202,7 +202,7 @@ After=network-online.target [Service] Type=simple Restart=always -ExecStart=/usr/local/bin/statup +ExecStart=/usr/local/bin/statping [Install] WantedBy=multi-user.target @@ -210,8 +210,8 @@ EOM echo "Installing systemctl service file to: /etc/systemd/system/$FILE" mv $FILE /etc/systemd/system/$FILE systemctl daemon-reload -systemctl enable statup.service -systemctl start statup +systemctl enable statping.service +systemctl start statping echo "Statping has been installed to SystemCTL and will start on boot" } @@ -220,21 +220,21 @@ function downloadBin { getOS getArch get_latest_release - GIT_DOWNLOAD="https://github.com/$DOCKER_IMG/releases/download/$STATUP_VERSION/statup-$OS-$ARCH.tar.gz" - echo "Downloading Statping $STATUP_VERSION from $GIT_DOWNLOAD" + GIT_DOWNLOAD="https://github.com/$DOCKER_IMG/releases/download/$STATPING_VERSION/statping-$OS-$ARCH.tar.gz" + echo "Downloading Statping $STATPING_VERSION from $GIT_DOWNLOAD" curl -L --silent $GIT_DOWNLOAD | tar xz echo "Download complete" } -# install statup locally from github +# install statping locally from github function localTask { downloadBin - echo "Try Statping by running 'statup version'!" + echo "Try Statping by running 'statping version'!" askInstallGlobal if [ $MOVEBIN == "y" ]; then moveToBin - echo "Statping can now be ran anywhere with command 'statup'" - echo "Install location: /usr/local/bin/statup" + echo "Statping can now be ran anywhere with command 'statping'" + echo "Install location: /usr/local/bin/statping" if [ $OS == "linux" ]; then askInstallSystemCTL if [ $SYSTEMCTL == "y" ]; then @@ -245,7 +245,7 @@ function localTask { } function uninstallTask { - rm -f /usr/local/bin/statup + rm -f /usr/local/bin/statping } # start the Statping docker image @@ -293,7 +293,7 @@ function getOS { function echoVersion { require jq get_latest_release - echo "Statping Latest: $STATUP_VERSION" + echo "Statping Latest: $STATPING_VERSION" echo "Statpinger Tool: v$VERSION" }