show messages on service page

pull/109/head
Hunter Long 2018-11-16 08:42:49 -08:00
parent 47bf0f379a
commit 035955c34f
11 changed files with 67 additions and 37 deletions

View File

@ -1,4 +1,4 @@
VERSION=0.79.82
VERSION=0.79.83
BINARY_NAME=statup
GOPATH:=$(GOPATH)
GOCMD=go

View File

@ -183,7 +183,7 @@ func (s *Service) checkHttp(record bool) *Service {
return s
}
response.Header.Set("Connection", "close")
response.Header.Set("user-Agent", "StatupMonitor")
response.Header.Set("User-Agent", "StatupMonitor")
t2 := time.Now()
s.Latency = t2.Sub(t1).Seconds()
if err != nil {

View File

@ -90,6 +90,13 @@ func (c *Checkin) CreateFailure() (int64, 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
func SelectCheckin(api string) *Checkin {
var checkin Checkin

View File

@ -25,7 +25,7 @@ import (
"os"
)
// ErrorResponse is used for HTTP errors to show to user
// ErrorResponse is used for HTTP errors to show to User
type ErrorResponse struct {
Error string
}

View File

@ -116,7 +116,7 @@ func (f *failure) AfterFind() (err error) {
}
// 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)
return
}
@ -149,8 +149,8 @@ func (f *failure) BeforeCreate() (err error) {
return
}
// BeforeCreate for user will set CreatedAt to UTC
func (u *user) BeforeCreate() (err error) {
// BeforeCreate for User will set CreatedAt to UTC
func (u *User) BeforeCreate() (err error) {
if u.CreatedAt.IsZero() {
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)
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC", Configs.DbUser, Configs.DbPass, host, Configs.DbData)
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":
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)

View File

@ -23,13 +23,13 @@ import (
"time"
)
type user struct {
type User struct {
*types.User
}
// ReturnUser returns *core.user based off a *types.user
func ReturnUser(u *types.User) *user {
return &user{u}
// ReturnUser returns *core.User based off a *types.User
func ReturnUser(u *types.User) *User {
return &User{u}
}
// CountUsers returns the amount of users
@ -39,35 +39,35 @@ func CountUsers() int64 {
return amount
}
// SelectUser returns the user based on the user's ID.
func SelectUser(id int64) (*user, error) {
var user user
// SelectUser returns the User based on the User's ID.
func SelectUser(id int64) (*User, error) {
var user User
err := usersDB().Where("id = ?", id).First(&user)
return &user, err.Error
}
// SelectUsername returns the user based on the user's username
func SelectUsername(username string) (*user, error) {
var user user
// SelectUsername returns the User based on the User's username
func SelectUsername(username string) (*User, error) {
var user User
res := usersDB().Where("username = ?", username)
err := res.First(&user)
return &user, err.Error
}
// Delete will remove the user record from the database
func (u *user) Delete() error {
// Delete will remove the User record from the database
func (u *User) Delete() error {
return usersDB().Delete(u).Error
}
// Update will update the user's record in database
func (u *user) Update() error {
// Update will update the User's record in database
func (u *User) Update() error {
u.ApiKey = utils.NewSHA1Hash(5)
u.ApiSecret = utils.NewSHA1Hash(10)
return usersDB().Update(u).Error
}
// Create will insert a new user into the database
func (u *user) Create() (int64, error) {
// Create will insert a new User into the database
func (u *User) Create() (int64, error) {
u.CreatedAt = time.Now()
u.Password = utils.HashPassword(u.Password)
u.ApiKey = utils.NewSHA1Hash(5)
@ -77,15 +77,15 @@ func (u *user) Create() (int64, error) {
return 0, db.Error
}
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 u.Id, db.Error
}
// SelectAllUsers returns all users
func SelectAllUsers() ([]*user, error) {
var users []*user
func SelectAllUsers() ([]*User, error) {
var users []*User
db := usersDB().Find(&users)
if db.Error != nil {
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
}
// 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
func AuthUser(username, password string) (*user, bool) {
func AuthUser(username, password string) (*User, bool) {
user, err := SelectUsername(username)
if err != nil {
utils.Log(2, err)

View File

@ -69,7 +69,7 @@ func TestCreateUser2(t *testing.T) {
user := ReturnUser(&types.User{
Username: "hunterlong",
Password: "password123",
Email: "user@email.com",
Email: "User@email.com",
Admin: types.NewNullBool(true),
})
userId, err := user.Create()
@ -87,7 +87,7 @@ func TestAuthUser(t *testing.T) {
user, auth := AuthUser("hunterlong", "password123")
assert.True(t, auth)
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.True(t, user.Admin.Bool)
}

View File

@ -102,8 +102,12 @@ func logsLineHandler(w http.ResponseWriter, r *http.Request) {
}
type exportData struct {
Core *core.Core `json:"core"`
Notifiers types.AllNotifiers `json:"notifiers"`
Core *types.Core `json:"core"`
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) {
@ -118,7 +122,15 @@ func exportHandler(w http.ResponseWriter, r *http.Request) {
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)

View File

@ -45,7 +45,14 @@
<div class="form-group row">
<label for="notify_method" class="col-sm-4 col-form-label">Notification Method</label>
<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>

View File

@ -19,7 +19,7 @@
<tr id="message_{{.Id}}">
<td>{{.Title}}</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">
<div class="btn-group">
<a href="/message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>

View File

@ -42,11 +42,15 @@
</div>
{{if $s.ActiveMessages}}
<div class="col-12 mb-4">
<div class="col-12 mb-5">
{{range $s.ActiveMessages}}
<div class="alert alert-warning" role="alert">
<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>
{{end}}
</div>