-
+
24 Hours
-
+
View Service
+ View Service
+
+
+
@@ -44,12 +58,13 @@
-
diff --git a/frontend/src/routes.js b/frontend/src/routes.js
index df31db98..15c57b09 100644
--- a/frontend/src/routes.js
+++ b/frontend/src/routes.js
@@ -27,7 +27,6 @@ const routes = [
},
{
path: '/dashboard',
- name: 'Dashboard',
component: Dashboard,
meta: {
requiresAuth: true
diff --git a/frontend/src/store.js b/frontend/src/store.js
index fb3fafcd..5b64ec25 100644
--- a/frontend/src/store.js
+++ b/frontend/src/store.js
@@ -25,8 +25,7 @@ export default new Vuex.Store({
groups: [],
messages: [],
users: [],
- notifiers: [],
- integrations: []
+ notifiers: []
},
getters: {
hasAllData: state => state.hasAllData,
@@ -38,13 +37,19 @@ export default new Vuex.Store({
messages: state => state.messages,
users: state => state.users,
notifiers: state => state.notifiers,
- integrations: state => state.integrations,
servicesInOrder: state => state.services.sort((a, b) => a.order_id - b.order_id),
groupsInOrder: state => state.groups.sort((a, b) => a.order_id - b.order_id),
groupsClean: state => state.groups.filter(g => g.name !== '').sort((a, b) => a.order_id - b.order_id),
groupsCleanInOrder: state => state.groups.filter(g => g.name !== '').sort((a, b) => a.order_id - b.order_id).sort((a, b) => a.order_id - b.order_id),
+ serviceByAll: (state) => (element) => {
+ if (element % 1 === 0) {
+ return state.services.find(s => s.id == element)
+ } else {
+ return state.services.find(s => s.permalink === element)
+ }
+ },
serviceById: (state) => (id) => {
return state.services.find(s => s.id == id)
},
@@ -100,12 +105,13 @@ export default new Vuex.Store({
},
setNotifiers (state, notifiers) {
state.notifiers = notifiers
- },
- setIntegrations (state, integrations) {
- state.integrations = integrations
}
},
actions: {
+ async getAllServices(context) {
+ const services = await Api.services()
+ context.commit("setServices", services);
+ },
async loadRequired(context) {
const core = await Api.core()
context.commit("setCore", core);
@@ -140,8 +146,6 @@ export default new Vuex.Store({
context.commit("setNotifiers", notifiers);
const users = await Api.users()
context.commit("setUsers", users);
- const integrations = await Api.integrations()
- context.commit("setIntegrations", integrations);
}
}
});
diff --git a/handlers/services.go b/handlers/services.go
index eea4b37b..4c1d2126 100644
--- a/handlers/services.go
+++ b/handlers/services.go
@@ -128,7 +128,11 @@ func apiServiceDataHandler(w http.ResponseWriter, r *http.Request) {
return
}
- groupQuery := database.ParseQueries(r, service.AllHits())
+ groupQuery, err := database.ParseQueries(r, service.AllHits())
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
objs, err := groupQuery.GraphData(database.ByAverage("latency", 1000))
if err != nil {
@@ -146,7 +150,11 @@ func apiServiceFailureDataHandler(w http.ResponseWriter, r *http.Request) {
return
}
- groupQuery := database.ParseQueries(r, service.AllFailures())
+ groupQuery, err := database.ParseQueries(r, service.AllFailures())
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
objs, err := groupQuery.GraphData(database.ByCount)
if err != nil {
@@ -164,7 +172,11 @@ func apiServicePingDataHandler(w http.ResponseWriter, r *http.Request) {
return
}
- groupQuery := database.ParseQueries(r, service.AllHits())
+ groupQuery, err := database.ParseQueries(r, service.AllHits())
+ if err != nil {
+ sendErrorJson(err, w, r)
+ return
+ }
objs, err := groupQuery.GraphData(database.ByAverage("ping_time", 1000))
if err != nil {
@@ -216,7 +228,11 @@ func apiServiceFailuresHandler(r *http.Request) interface{} {
}
var fails []*failures.Failure
- database.ParseQueries(r, service.AllFailures()).Find(&fails)
+ query, err := database.ParseQueries(r, service.AllFailures())
+ if err != nil {
+ return err
+ }
+ query.Find(&fails)
return fails
}
@@ -228,6 +244,10 @@ func apiServiceHitsHandler(r *http.Request) interface{} {
}
var hts []*hits.Hit
- database.ParseQueries(r, service.AllHits()).Find(&hts)
+ query, err := database.ParseQueries(r, service.AllHits())
+ if err != nil {
+ return err
+ }
+ query.Find(&hts)
return hts
}
diff --git a/types/configs/latest_sql.go b/types/configs/latest_sql.go
new file mode 100644
index 00000000..6d381fdb
--- /dev/null
+++ b/types/configs/latest_sql.go
@@ -0,0 +1,64 @@
+package configs
+
+import (
+ "fmt"
+ "github.com/statping/statping/utils"
+ "os"
+)
+
+const latestMigration = 1583860000
+
+func init() {
+ os.Setenv("MIGRATION_ID", utils.ToString(latestMigration))
+}
+
+func (c *DbConfig) genericMigration(alterStr string) error {
+ if err := c.Db.Exec(fmt.Sprintf("ALTER TABLE hits %s COLUMN latency TYPE BIGINT;", alterStr)).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(fmt.Sprintf("ALTER TABLE hits %s COLUMN ping_time TYPE BIGINT;", alterStr)).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(fmt.Sprintf("ALTER TABLE failures %s COLUMN latency TYPE BIGINT;", alterStr)).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec("UPDATE hits SET latency = CAST(latency * 1000000 AS bigint);").Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec("UPDATE hits SET ping_time = CAST(ping_time * 1000000 AS bigint);").Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec("UPDATE failures SET ping_time = CAST(ping_time * 1000000 AS bigint);").Error(); err != nil {
+ return err
+ }
+ return nil
+}
+
+func (c *DbConfig) sqliteMigration() error {
+ if err := c.Db.Exec(`ALTER TABLE hits RENAME TO hits_backup;`).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(`CREATE TABLE hits (id INTEGER PRIMARY KEY AUTOINCREMENT, service bigint, latency bigint, ping_time bigint, created_at datetime);`).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(`INSERT INTO hits (id, service, latency, ping_time, created_at) SELECT id, service, CAST(latency * 1000000 AS bigint), CAST(ping_time * 1000000 AS bigint), created_at FROM hits_backup;`).Error(); err != nil {
+ return err
+ }
+ // failures table
+ if err := c.Db.Exec(`ALTER TABLE failures RENAME TO failures_backup;`).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(`CREATE TABLE failures (id INTEGER PRIMARY KEY AUTOINCREMENT, issue varchar(255), method varchar(255), method_id bigint, service bigint, ping_time bigint, checkin bigint, error_code bigint, created_at datetime);`).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(`INSERT INTO failures (id, issue, method, method_id, service, ping_time, checkin, created_at) SELECT id, issue, method, method_id, service, CAST(ping_time * 1000000 AS bigint), checkin, created_at FROM failures_backup;`).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(`DROP TABLE hits_backup;`).Error(); err != nil {
+ return err
+ }
+ if err := c.Db.Exec(`DROP TABLE failures_backup;`).Error(); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/types/configs/migration.go b/types/configs/migration.go
index 7d3ac98b..b9fe0d83 100644
--- a/types/configs/migration.go
+++ b/types/configs/migration.go
@@ -2,6 +2,9 @@ package configs
import (
"fmt"
+ _ "github.com/jinzhu/gorm/dialects/mysql"
+ _ "github.com/jinzhu/gorm/dialects/postgres"
+ _ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/statping/statping/types/checkins"
"github.com/statping/statping/types/core"
"github.com/statping/statping/types/failures"
@@ -12,53 +15,36 @@ import (
"github.com/statping/statping/types/notifications"
"github.com/statping/statping/types/services"
"github.com/statping/statping/types/users"
-
- _ "github.com/jinzhu/gorm/dialects/mysql"
- _ "github.com/jinzhu/gorm/dialects/postgres"
- _ "github.com/jinzhu/gorm/dialects/sqlite"
)
-// InsertNotifierDB inject the Statping database instance to the Notifier package
-//func (c *DbConfig) InsertNotifierDB() error {
-// if !database.Available() {
-// err := c.Connect()
-// if err != nil {
-// return errors.New("database connection has not been created")
-// }
-// }
-// notifiers.SetDB(database.DB())
-// return nil
-//}
+func (c *DbConfig) DatabaseChanges() error {
+ var cr core.Core
+ c.Db.Model(&core.Core{}).Find(&cr)
-// InsertIntegratorDB inject the Statping database instance to the Integrations package
-//func (c *DbConfig) InsertIntegratorDB() error {
-// if !database.Available() {
-// err := c.Connect()
-// if err != nil {
-// return errors.Wrap(err,"database connection has not been created")
-// }
-// }
-// integrations.SetDB(database.DB())
-// return nil
-//}
+ if latestMigration > cr.MigrationId {
+ log.Infof("Statping database is out of date, migrating to: %d", latestMigration)
-func (c *DbConfig) VerifyMigration() error {
+ switch c.Db.DbType() {
+ case "mysql":
+ if err := c.genericMigration("MODIFY"); err != nil {
+ return err
+ }
+ case "postgres":
+ if err := c.genericMigration("ALTER"); err != nil {
+ return err
+ }
+ default:
+ if err := c.sqliteMigration(); err != nil {
+ return err
+ }
+ }
- query := `
-BEGIN TRANSACTION;
-ALTER TABLE hits ALTER COLUMN latency BIGINT;
-ALTER TABLE hits ALTER COLUMN ping_time BIGINT;
-ALTER TABLE failures ALTER COLUMN ping_time BIGINT;
-UPDATE hits SET latency = CAST(latency * 10000 AS BIGINT);
-UPDATE hits SET ping_time = CAST(ping_time * 100000 AS BIGINT);
-UPDATE failures SET ping_time = CAST(ping_time * 100000 AS BIGINT);
-COMMIT;`
+ if err := c.Db.Exec(fmt.Sprintf("UPDATE core SET migration_id = %d", latestMigration)).Error(); err != nil {
+ return err
+ }
- fmt.Println(c.Db.DbType())
-
- q := c.Db.Raw(query).Debug()
-
- return q.Error()
+ }
+ return nil
}
//MigrateDatabase will migrate the database structure to current version.
diff --git a/types/core/samples.go b/types/core/samples.go
index 5fc77e22..6837eccf 100644
--- a/types/core/samples.go
+++ b/types/core/samples.go
@@ -3,12 +3,11 @@ package core
import (
"github.com/statping/statping/types/null"
"github.com/statping/statping/utils"
- "time"
)
func Samples() error {
- apiKey := utils.Getenv("API_KEY", "samplekey")
- apiSecret := utils.Getenv("API_SECRET", "samplesecret")
+ apiKey := utils.Getenv("API_KEY", utils.RandomString(16))
+ apiSecret := utils.Getenv("API_SECRET", utils.RandomString(16))
core := &Core{
Name: "Statping Sample Data",
@@ -16,10 +15,10 @@ func Samples() error {
ApiKey: apiKey.(string),
ApiSecret: apiSecret.(string),
Domain: "http://localhost:8080",
- Version: "test",
- CreatedAt: time.Now().UTC(),
+ CreatedAt: utils.Now(),
UseCdn: null.NewNullBool(false),
Footer: null.NewNullString(""),
+ MigrationId: utils.Now().Unix(),
}
return core.Create()