mirror of https://github.com/statping/statping
show messages on service page
parent
47bf0f379a
commit
035955c34f
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
VERSION=0.79.82
|
VERSION=0.79.83
|
||||||
BINARY_NAME=statup
|
BINARY_NAME=statup
|
||||||
GOPATH:=$(GOPATH)
|
GOPATH:=$(GOPATH)
|
||||||
GOCMD=go
|
GOCMD=go
|
||||||
|
|
|
@ -183,7 +183,7 @@ func (s *Service) checkHttp(record bool) *Service {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
response.Header.Set("Connection", "close")
|
response.Header.Set("Connection", "close")
|
||||||
response.Header.Set("user-Agent", "StatupMonitor")
|
response.Header.Set("User-Agent", "StatupMonitor")
|
||||||
t2 := time.Now()
|
t2 := time.Now()
|
||||||
s.Latency = t2.Sub(t1).Seconds()
|
s.Latency = t2.Sub(t1).Seconds()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -90,6 +90,13 @@ func (c *Checkin) CreateFailure() (int64, error) {
|
||||||
return fail.Id, row.Error
|
return fail.Id, row.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AllCheckins returns all checkin in system
|
||||||
|
func AllCheckins() []*Checkin {
|
||||||
|
var checkins []*Checkin
|
||||||
|
checkinDB().Find(&checkins)
|
||||||
|
return checkins
|
||||||
|
}
|
||||||
|
|
||||||
// SelectCheckin will find a Checkin based on the API supplied
|
// SelectCheckin will find a Checkin based on the API supplied
|
||||||
func SelectCheckin(api string) *Checkin {
|
func SelectCheckin(api string) *Checkin {
|
||||||
var checkin Checkin
|
var checkin Checkin
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrorResponse is used for HTTP errors to show to user
|
// ErrorResponse is used for HTTP errors to show to User
|
||||||
type ErrorResponse struct {
|
type ErrorResponse struct {
|
||||||
Error string
|
Error string
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ func (f *failure) AfterFind() (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AfterFind for USer will set the timezone
|
// AfterFind for USer will set the timezone
|
||||||
func (u *user) AfterFind() (err error) {
|
func (u *User) AfterFind() (err error) {
|
||||||
u.CreatedAt = utils.Timezoner(u.CreatedAt, CoreApp.Timezone)
|
u.CreatedAt = utils.Timezoner(u.CreatedAt, CoreApp.Timezone)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -149,8 +149,8 @@ func (f *failure) BeforeCreate() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeforeCreate for user will set CreatedAt to UTC
|
// BeforeCreate for User will set CreatedAt to UTC
|
||||||
func (u *user) BeforeCreate() (err error) {
|
func (u *User) BeforeCreate() (err error) {
|
||||||
if u.CreatedAt.IsZero() {
|
if u.CreatedAt.IsZero() {
|
||||||
u.CreatedAt = time.Now().UTC()
|
u.CreatedAt = time.Now().UTC()
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ func (db *DbConfig) Connect(retry bool, location string) error {
|
||||||
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
|
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
|
||||||
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC", Configs.DbUser, Configs.DbPass, host, Configs.DbData)
|
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC", Configs.DbUser, Configs.DbPass, host, Configs.DbData)
|
||||||
case "postgres":
|
case "postgres":
|
||||||
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v sslmode=disable", Configs.DbHost, Configs.DbPort, Configs.DbUser, Configs.DbData, Configs.DbPass)
|
conn = fmt.Sprintf("host=%v port=%v User=%v dbname=%v password=%v sslmode=disable", Configs.DbHost, Configs.DbPort, Configs.DbUser, Configs.DbData, Configs.DbPass)
|
||||||
case "mssql":
|
case "mssql":
|
||||||
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
|
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
|
||||||
conn = fmt.Sprintf("sqlserver://%v:%v@%v?database=%v", Configs.DbUser, Configs.DbPass, host, Configs.DbData)
|
conn = fmt.Sprintf("sqlserver://%v:%v@%v?database=%v", Configs.DbUser, Configs.DbPass, host, Configs.DbData)
|
||||||
|
|
|
@ -23,13 +23,13 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type user struct {
|
type User struct {
|
||||||
*types.User
|
*types.User
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReturnUser returns *core.user based off a *types.user
|
// ReturnUser returns *core.User based off a *types.User
|
||||||
func ReturnUser(u *types.User) *user {
|
func ReturnUser(u *types.User) *User {
|
||||||
return &user{u}
|
return &User{u}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CountUsers returns the amount of users
|
// CountUsers returns the amount of users
|
||||||
|
@ -39,35 +39,35 @@ func CountUsers() int64 {
|
||||||
return amount
|
return amount
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectUser returns the user based on the user's ID.
|
// SelectUser returns the User based on the User's ID.
|
||||||
func SelectUser(id int64) (*user, error) {
|
func SelectUser(id int64) (*User, error) {
|
||||||
var user user
|
var user User
|
||||||
err := usersDB().Where("id = ?", id).First(&user)
|
err := usersDB().Where("id = ?", id).First(&user)
|
||||||
return &user, err.Error
|
return &user, err.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectUsername returns the user based on the user's username
|
// SelectUsername returns the User based on the User's username
|
||||||
func SelectUsername(username string) (*user, error) {
|
func SelectUsername(username string) (*User, error) {
|
||||||
var user user
|
var user User
|
||||||
res := usersDB().Where("username = ?", username)
|
res := usersDB().Where("username = ?", username)
|
||||||
err := res.First(&user)
|
err := res.First(&user)
|
||||||
return &user, err.Error
|
return &user, err.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete will remove the user record from the database
|
// Delete will remove the User record from the database
|
||||||
func (u *user) Delete() error {
|
func (u *User) Delete() error {
|
||||||
return usersDB().Delete(u).Error
|
return usersDB().Delete(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update will update the user's record in database
|
// Update will update the User's record in database
|
||||||
func (u *user) Update() error {
|
func (u *User) Update() error {
|
||||||
u.ApiKey = utils.NewSHA1Hash(5)
|
u.ApiKey = utils.NewSHA1Hash(5)
|
||||||
u.ApiSecret = utils.NewSHA1Hash(10)
|
u.ApiSecret = utils.NewSHA1Hash(10)
|
||||||
return usersDB().Update(u).Error
|
return usersDB().Update(u).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create will insert a new user into the database
|
// Create will insert a new User into the database
|
||||||
func (u *user) Create() (int64, error) {
|
func (u *User) Create() (int64, error) {
|
||||||
u.CreatedAt = time.Now()
|
u.CreatedAt = time.Now()
|
||||||
u.Password = utils.HashPassword(u.Password)
|
u.Password = utils.HashPassword(u.Password)
|
||||||
u.ApiKey = utils.NewSHA1Hash(5)
|
u.ApiKey = utils.NewSHA1Hash(5)
|
||||||
|
@ -77,15 +77,15 @@ func (u *user) Create() (int64, error) {
|
||||||
return 0, db.Error
|
return 0, db.Error
|
||||||
}
|
}
|
||||||
if u.Id == 0 {
|
if u.Id == 0 {
|
||||||
utils.Log(3, fmt.Sprintf("Failed to create user %v. %v", u.Username, db.Error))
|
utils.Log(3, fmt.Sprintf("Failed to create User %v. %v", u.Username, db.Error))
|
||||||
return 0, db.Error
|
return 0, db.Error
|
||||||
}
|
}
|
||||||
return u.Id, db.Error
|
return u.Id, db.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectAllUsers returns all users
|
// SelectAllUsers returns all users
|
||||||
func SelectAllUsers() ([]*user, error) {
|
func SelectAllUsers() ([]*User, error) {
|
||||||
var users []*user
|
var users []*User
|
||||||
db := usersDB().Find(&users)
|
db := usersDB().Find(&users)
|
||||||
if db.Error != nil {
|
if db.Error != nil {
|
||||||
utils.Log(3, fmt.Sprintf("Failed to load all users. %v", db.Error))
|
utils.Log(3, fmt.Sprintf("Failed to load all users. %v", db.Error))
|
||||||
|
@ -94,9 +94,9 @@ func SelectAllUsers() ([]*user, error) {
|
||||||
return users, db.Error
|
return users, db.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthUser will return the user and a boolean if authentication was correct.
|
// AuthUser will return the User and a boolean if authentication was correct.
|
||||||
// AuthUser accepts username, and password as a string
|
// AuthUser accepts username, and password as a string
|
||||||
func AuthUser(username, password string) (*user, bool) {
|
func AuthUser(username, password string) (*User, bool) {
|
||||||
user, err := SelectUsername(username)
|
user, err := SelectUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Log(2, err)
|
utils.Log(2, err)
|
||||||
|
|
|
@ -69,7 +69,7 @@ func TestCreateUser2(t *testing.T) {
|
||||||
user := ReturnUser(&types.User{
|
user := ReturnUser(&types.User{
|
||||||
Username: "hunterlong",
|
Username: "hunterlong",
|
||||||
Password: "password123",
|
Password: "password123",
|
||||||
Email: "user@email.com",
|
Email: "User@email.com",
|
||||||
Admin: types.NewNullBool(true),
|
Admin: types.NewNullBool(true),
|
||||||
})
|
})
|
||||||
userId, err := user.Create()
|
userId, err := user.Create()
|
||||||
|
@ -87,7 +87,7 @@ func TestAuthUser(t *testing.T) {
|
||||||
user, auth := AuthUser("hunterlong", "password123")
|
user, auth := AuthUser("hunterlong", "password123")
|
||||||
assert.True(t, auth)
|
assert.True(t, auth)
|
||||||
assert.NotNil(t, user)
|
assert.NotNil(t, user)
|
||||||
assert.Equal(t, "user@email.com", user.Email)
|
assert.Equal(t, "User@email.com", user.Email)
|
||||||
assert.Equal(t, int64(4), user.Id)
|
assert.Equal(t, int64(4), user.Id)
|
||||||
assert.True(t, user.Admin.Bool)
|
assert.True(t, user.Admin.Bool)
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,12 @@ func logsLineHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type exportData struct {
|
type exportData struct {
|
||||||
Core *core.Core `json:"core"`
|
Core *types.Core `json:"core"`
|
||||||
Notifiers types.AllNotifiers `json:"notifiers"`
|
Services []types.ServiceInterface `json:"services"`
|
||||||
|
Messages []*types.Message `json:"messages"`
|
||||||
|
Checkins []*core.Checkin `json:"checkins"`
|
||||||
|
Users []*core.User `json:"users"`
|
||||||
|
Notifiers []types.AllNotifiers `json:"notifiers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func exportHandler(w http.ResponseWriter, r *http.Request) {
|
func exportHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -118,7 +122,15 @@ func exportHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
notifiers = append(notifiers, notifier.Select())
|
notifiers = append(notifiers, notifier.Select())
|
||||||
}
|
}
|
||||||
|
|
||||||
data := exportData{core.CoreApp, notifiers}
|
users, _ := core.SelectAllUsers()
|
||||||
|
|
||||||
|
data := exportData{
|
||||||
|
Core: core.CoreApp.Core,
|
||||||
|
Notifiers: core.CoreApp.Notifications,
|
||||||
|
Checkins: core.AllCheckins(),
|
||||||
|
Users: users,
|
||||||
|
Services: core.CoreApp.Services,
|
||||||
|
}
|
||||||
|
|
||||||
export, _ := json.Marshal(data)
|
export, _ := json.Marshal(data)
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,14 @@
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label for="notify_method" class="col-sm-4 col-form-label">Notification Method</label>
|
<label for="notify_method" class="col-sm-4 col-form-label">Notification Method</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<input type="text" name="notify_method" class="form-control" id="notify_method" value="{{.NotifyUsers.Bool}}" placeholder="email">
|
<input type="text" name="notify_method" class="form-control" id="notify_method" value="{{.NotifyMethod}}" placeholder="email">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="notify_method" class="col-sm-4 col-form-label">Notify Users</label>
|
||||||
|
<div class="col-sm-8">
|
||||||
|
<input type="text" name="notify_users" class="form-control" id="notify_method" value="{{.NotifyUsers.Bool}}" placeholder="">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<tr id="message_{{.Id}}">
|
<tr id="message_{{.Id}}">
|
||||||
<td>{{.Title}}</td>
|
<td>{{.Title}}</td>
|
||||||
<td>{{if .Service}}<a href="/service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
|
<td>{{if .Service}}<a href="/service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
|
||||||
<td>{{Duration 0}}</td>
|
<td>{{.StartOn}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<a href="/message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>
|
<a href="/message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>
|
||||||
|
|
|
@ -42,11 +42,15 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if $s.ActiveMessages}}
|
{{if $s.ActiveMessages}}
|
||||||
<div class="col-12 mb-4">
|
<div class="col-12 mb-5">
|
||||||
{{range $s.ActiveMessages}}
|
{{range $s.ActiveMessages}}
|
||||||
<div class="alert alert-warning" role="alert">
|
<div class="alert alert-warning" role="alert">
|
||||||
<h3>{{.Title}}</h3>
|
<h3>{{.Title}}</h3>
|
||||||
<span>{{safe .Description}}</span>
|
<span class="mb-3">{{safe .Description}}</span>
|
||||||
|
<div class="d-block mt-2 mb-4">
|
||||||
|
<span class="float-left small">Starts at {{.StartOn}}</span>
|
||||||
|
<span class="float-right small">Ends on {{.EndOn}}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue