mirror of https://github.com/statping/statping
fixed notifier panic
parent
a43d7834b9
commit
3051206a7a
|
@ -29,11 +29,11 @@ type DbConfig struct {
|
||||||
LetsEncryptEnable bool `yaml:"letsencrypt_enable,omitempty" json:"letsencrypt_enable"`
|
LetsEncryptEnable bool `yaml:"letsencrypt_enable,omitempty" json:"letsencrypt_enable"`
|
||||||
LocalIP string `yaml:"-" json:"-"`
|
LocalIP string `yaml:"-" json:"-"`
|
||||||
|
|
||||||
DisableHTTP bool `yaml:"disable_http" json:"disable_http"`
|
DisableHTTP bool `yaml:"disable_http" json:"disable_http"`
|
||||||
DemoMode bool `yaml:"demo_mode" json:"demo_mode"`
|
DemoMode bool `yaml:"demo_mode" json:"demo_mode"`
|
||||||
DisableLogs bool `yaml:"disable_logs" json:"disable_logs"`
|
DisableLogs bool `yaml:"disable_logs" json:"disable_logs"`
|
||||||
UseAssets bool `yaml:"use_assets" json:"use_assets"`
|
UseAssets bool `yaml:"use_assets" json:"use_assets"`
|
||||||
BasePath bool `yaml:"base_path" json:"base_path"`
|
BasePath string `yaml:"base_path" json:"base_path"`
|
||||||
|
|
||||||
AdminUser string `yaml:"admin_user" json:"admin_user"`
|
AdminUser string `yaml:"admin_user" json:"admin_user"`
|
||||||
AdminPassword string `yaml:"admin_password" json:"admin_password"`
|
AdminPassword string `yaml:"admin_password" json:"admin_password"`
|
||||||
|
|
|
@ -2,7 +2,6 @@ package notifications
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/statping/statping/database"
|
"github.com/statping/statping/database"
|
||||||
"github.com/statping/statping/types/null"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -35,25 +34,11 @@ func Find(method string) (*Notification, error) {
|
||||||
return &n, nil
|
return &n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BeforeCreate is a NULL constraint fix for postgres
|
|
||||||
func (n *Notification) BeforeCreate() error {
|
|
||||||
n.Host = null.NewNullString("")
|
|
||||||
n.Port = null.NewNullInt64(0)
|
|
||||||
n.Username = null.NewNullString("")
|
|
||||||
n.Password = null.NewNullString("")
|
|
||||||
n.Var1 = null.NewNullString("")
|
|
||||||
n.Var2 = null.NewNullString("")
|
|
||||||
n.ApiKey = null.NewNullString("")
|
|
||||||
n.ApiSecret = null.NewNullString("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Notification) Create() error {
|
func (n *Notification) Create() error {
|
||||||
var p Notification
|
var p Notification
|
||||||
q := db.Where("method = ?", n.Method).Find(&p)
|
q := db.Where("method = ?", n.Method).Find(&p)
|
||||||
if q.RecordNotFound() {
|
if q.RecordNotFound() {
|
||||||
log.Infof("Notifier %s was not found, adding into database...\n", n.Method)
|
log.Infof("Notifier '%s' was not found, adding into database...\n", n.Method)
|
||||||
log.Infoln(n.Method, n.Id, n.Title, n.Host.String)
|
|
||||||
if err := db.Create(n).Error(); err != nil {
|
if err := db.Create(n).Error(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
package null
|
package null
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s NullString) Scan(value interface{}) error {
|
||||||
|
if s.Valid {
|
||||||
|
s.String = value.(string)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s NullString) Value() (driver.Value, error) {
|
||||||
|
return s.String, nil
|
||||||
|
}
|
||||||
|
|
||||||
// MarshalJSON for NullInt64
|
// MarshalJSON for NullInt64
|
||||||
func (i NullInt64) MarshalJSON() ([]byte, error) {
|
func (i NullInt64) MarshalJSON() ([]byte, error) {
|
||||||
if !i.Valid {
|
if !i.Valid {
|
||||||
|
@ -32,7 +44,7 @@ func (bb NullBool) MarshalJSON() ([]byte, error) {
|
||||||
// MarshalJSON for NullString
|
// MarshalJSON for NullString
|
||||||
func (s NullString) MarshalJSON() ([]byte, error) {
|
func (s NullString) MarshalJSON() ([]byte, error) {
|
||||||
if !s.Valid {
|
if !s.Valid {
|
||||||
return []byte("null"), nil
|
return json.Marshal(nil)
|
||||||
}
|
}
|
||||||
return json.Marshal(s.String)
|
return json.Marshal(s.String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,6 @@ func SelectAllServices(start bool) (map[int64]*Service, error) {
|
||||||
if len(allServices) > 0 {
|
if len(allServices) > 0 {
|
||||||
return allServices, nil
|
return allServices, nil
|
||||||
}
|
}
|
||||||
log.Infof("Preparing to monitor %d services...\n", len(allServices))
|
|
||||||
for _, s := range all() {
|
for _, s := range all() {
|
||||||
s.Failures = s.AllFailures().LastAmount(limitedFailures)
|
s.Failures = s.AllFailures().LastAmount(limitedFailures)
|
||||||
s.prevOnline = true
|
s.prevOnline = true
|
||||||
|
|
Loading…
Reference in New Issue