added http headers for outgoing requests, removed mobile notifier inputs, added Pushover notifier fields

pull/688/head
hunterlong 2020-06-24 18:58:21 -07:00
parent 1044337ec6
commit 7be131d0cf
6 changed files with 50 additions and 14 deletions

View File

@ -12,7 +12,12 @@
<div class="card-body"> <div class="card-body">
<p class="small text-muted" v-html="notifier.description"/> <p class="small text-muted" v-html="notifier.description"/>
<div v-for="(form, index) in notifier.form" v-bind:key="index" class="form-group"> <div v-if="notifier.method==='mobile'" class="col-6 offset-3">
<img :src="qrcode" class="img-thumbnail">
<span class="text-muted small center">Scan this QR Code on the Statping Mobile App for quick setup</span>
</div>
<div v-if="notifier.method!=='mobile'" v-for="(form, index) in notifier.form" v-bind:key="index" class="form-group">
<label class="text-capitalize">{{form.title}}</label> <label class="text-capitalize">{{form.title}}</label>
<input v-if="formVisible(['text', 'number', 'password', 'email'], form)" v-model="notifier[form.field.toLowerCase()]" :type="form.type" class="form-control" :placeholder="form.placeholder" > <input v-if="formVisible(['text', 'number', 'password', 'email'], form)" v-model="notifier[form.field.toLowerCase()]" :type="form.type" class="form-control" :placeholder="form.placeholder" >
@ -172,7 +177,13 @@ export default {
} }
}, },
computed: { computed: {
core() {
return this.$store.getters.core
},
qrcode() {
const u = `statping://setup?domain=${this.core.domain}&api=${this.core.api_secret}`
return "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=" + encodeURIComponent(u)
}
}, },
methods: { methods: {
formVisible(want, form) { formVisible(want, form) {

View File

@ -68,12 +68,33 @@ var Pushover = &pushover{&notifications.Notification{
}}, }},
} }
func priority(val string) string {
switch strings.ToLower(val) {
case "lowest":
return "-2"
case "low":
return "-1"
case "normal":
return "0"
case "high":
return "1"
case "emergency":
return "2"
default:
return "1"
}
}
// Send will send a HTTP Post to the Pushover API. It accepts type: string // Send will send a HTTP Post to the Pushover API. It accepts type: string
func (t *pushover) sendMessage(message string) (string, error) { func (t *pushover) sendMessage(message string) (string, error) {
v := url.Values{} v := url.Values{}
v.Set("token", t.ApiSecret) v.Set("token", t.ApiSecret)
v.Set("user", t.ApiKey) v.Set("user", t.ApiKey)
v.Set("message", message) v.Set("message", message)
v.Set("priority", priority(t.Var1))
if t.Var2 != "" {
v.Set("sound", t.Var2)
}
rb := strings.NewReader(v.Encode()) rb := strings.NewReader(v.Encode())
content, _, err := utils.HttpRequest(pushoverUrl, "POST", "application/x-www-form-urlencoded", nil, rb, time.Duration(10*time.Second), true, nil) content, _, err := utils.HttpRequest(pushoverUrl, "POST", "application/x-www-form-urlencoded", nil, rb, time.Duration(10*time.Second), true, nil)

View File

@ -31,9 +31,9 @@ var Webhook = &webhooker{&notifications.Notification{
Author: "Hunter Long", Author: "Hunter Long",
AuthorUrl: "https://github.com/hunterlong", AuthorUrl: "https://github.com/hunterlong",
Icon: "fas fa-code-branch", Icon: "fas fa-code-branch",
Delay: time.Duration(1 * time.Second), Delay: time.Duration(3 * time.Second),
SuccessData: `{"id": {{.Service.Id}}, "online": true}`, SuccessData: `{"id": "{{.Service.Id}}", "online": true}`,
FailureData: `{"id": {{.Service.Id}}, "online": false}`, FailureData: `{"id": "{{.Service.Id}}", "online": false}`,
DataType: "json", DataType: "json",
Limits: 180, Limits: 180,
Form: []notifications.NotificationForm{{ Form: []notifications.NotificationForm{{
@ -83,8 +83,7 @@ func (w *webhooker) sendHttpWebhook(body string) (*http.Response, error) {
utils.Log.Infoln(fmt.Sprintf("sending body: '%v' to %v as a %v request", body, w.Host, w.Var1)) utils.Log.Infoln(fmt.Sprintf("sending body: '%v' to %v as a %v request", body, w.Host, w.Var1))
client := new(http.Client) client := new(http.Client)
client.Timeout = time.Duration(10 * time.Second) client.Timeout = time.Duration(10 * time.Second)
var buf *bytes.Buffer buf := bytes.NewBuffer(nil)
buf = bytes.NewBuffer(nil)
if w.Var2 != "" { if w.Var2 != "" {
buf = bytes.NewBuffer([]byte(body)) buf = bytes.NewBuffer([]byte(body))
} }
@ -103,6 +102,7 @@ func (w *webhooker) sendHttpWebhook(body string) (*http.Response, error) {
req.Header.Add("Content-Type", w.ApiKey) req.Header.Add("Content-Type", w.ApiKey)
} }
req.Header.Set("User-Agent", "Statping") req.Header.Set("User-Agent", "Statping")
req.Header.Set("Statping-Version", utils.Version)
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -24,7 +24,7 @@ func InitEnvs() {
Log.Errorln(err) Log.Errorln(err)
defaultDir = "." defaultDir = "."
} }
Params.Set("VERSION", version) Params.Set("VERSION", Version)
Params.SetDefault("DISABLE_HTTP", false) Params.SetDefault("DISABLE_HTTP", false)
Params.SetDefault("STATPING_DIR", defaultDir) Params.SetDefault("STATPING_DIR", defaultDir)
Params.SetDefault("GO_ENV", "production") Params.SetDefault("GO_ENV", "production")

View File

@ -21,7 +21,7 @@ var (
LastLines []*logRow LastLines []*logRow
LockLines sync.Mutex LockLines sync.Mutex
VerboseMode int VerboseMode int
version string Version string
allowReports bool allowReports bool
) )
@ -36,7 +36,7 @@ func SentryInit(v *string, allow bool) {
if *v == "" { if *v == "" {
*v = "development" *v = "development"
} }
version = *v Version = *v
} }
goEnv := Params.GetString("GO_ENV") goEnv := Params.GetString("GO_ENV")
allowReports := Params.GetBool("ALLOW_REPORTS") allowReports := Params.GetBool("ALLOW_REPORTS")
@ -44,7 +44,7 @@ func SentryInit(v *string, allow bool) {
if err := sentry.Init(sentry.ClientOptions{ if err := sentry.Init(sentry.ClientOptions{
Dsn: errorReporter, Dsn: errorReporter,
Environment: goEnv, Environment: goEnv,
Release: version, Release: Version,
AttachStacktrace: true, AttachStacktrace: true,
}); err != nil { }); err != nil {
Log.Errorln(err) Log.Errorln(err)
@ -63,7 +63,7 @@ func SentryErr(err error) {
func SentryLogEntry(entry *Logger.Entry) { func SentryLogEntry(entry *Logger.Entry) {
e := sentry.NewEvent() e := sentry.NewEvent()
e.Message = entry.Message e.Message = entry.Message
e.Release = version e.Release = Version
e.Contexts = entry.Data e.Contexts = entry.Data
sentry.CaptureEvent(e) sentry.CaptureEvent(e)
} }

View File

@ -217,6 +217,10 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
} }
} }
} }
req.Header.Set("User-Agent", "Statping")
req.Header.Set("Statping-Version", Version)
var resp *http.Response var resp *http.Response
dialer := &net.Dialer{ dialer := &net.Dialer{