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"`
|
||||
LocalIP string `yaml:"-" json:"-"`
|
||||
|
||||
DisableHTTP bool `yaml:"disable_http" json:"disable_http"`
|
||||
DemoMode bool `yaml:"demo_mode" json:"demo_mode"`
|
||||
DisableLogs bool `yaml:"disable_logs" json:"disable_logs"`
|
||||
UseAssets bool `yaml:"use_assets" json:"use_assets"`
|
||||
BasePath bool `yaml:"base_path" json:"base_path"`
|
||||
DisableHTTP bool `yaml:"disable_http" json:"disable_http"`
|
||||
DemoMode bool `yaml:"demo_mode" json:"demo_mode"`
|
||||
DisableLogs bool `yaml:"disable_logs" json:"disable_logs"`
|
||||
UseAssets bool `yaml:"use_assets" json:"use_assets"`
|
||||
BasePath string `yaml:"base_path" json:"base_path"`
|
||||
|
||||
AdminUser string `yaml:"admin_user" json:"admin_user"`
|
||||
AdminPassword string `yaml:"admin_password" json:"admin_password"`
|
||||
|
|
|
@ -2,7 +2,6 @@ package notifications
|
|||
|
||||
import (
|
||||
"github.com/statping/statping/database"
|
||||
"github.com/statping/statping/types/null"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -35,25 +34,11 @@ func Find(method string) (*Notification, error) {
|
|||
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 {
|
||||
var p Notification
|
||||
q := db.Where("method = ?", n.Method).Find(&p)
|
||||
if q.RecordNotFound() {
|
||||
log.Infof("Notifier %s was not found, adding into database...\n", n.Method)
|
||||
log.Infoln(n.Method, n.Id, n.Title, n.Host.String)
|
||||
log.Infof("Notifier '%s' was not found, adding into database...\n", n.Method)
|
||||
if err := db.Create(n).Error(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
package null
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"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
|
||||
func (i NullInt64) MarshalJSON() ([]byte, error) {
|
||||
if !i.Valid {
|
||||
|
@ -32,7 +44,7 @@ func (bb NullBool) MarshalJSON() ([]byte, error) {
|
|||
// MarshalJSON for NullString
|
||||
func (s NullString) MarshalJSON() ([]byte, error) {
|
||||
if !s.Valid {
|
||||
return []byte("null"), nil
|
||||
return json.Marshal(nil)
|
||||
}
|
||||
return json.Marshal(s.String)
|
||||
}
|
||||
|
|
|
@ -226,7 +226,6 @@ func SelectAllServices(start bool) (map[int64]*Service, error) {
|
|||
if len(allServices) > 0 {
|
||||
return allServices, nil
|
||||
}
|
||||
log.Infof("Preparing to monitor %d services...\n", len(allServices))
|
||||
for _, s := range all() {
|
||||
s.Failures = s.AllFailures().LastAmount(limitedFailures)
|
||||
s.prevOnline = true
|
||||
|
|
Loading…
Reference in New Issue