mirror of https://github.com/statping/statping
notifier test
parent
277594f212
commit
6864cd067e
|
@ -74,6 +74,7 @@ func Router() *mux.Router {
|
||||||
r.Handle("/settings/build", http.HandlerFunc(saveAssetsHandler)).Methods("GET")
|
r.Handle("/settings/build", http.HandlerFunc(saveAssetsHandler)).Methods("GET")
|
||||||
r.Handle("/settings/delete_assets", http.HandlerFunc(deleteAssetsHandler)).Methods("GET")
|
r.Handle("/settings/delete_assets", http.HandlerFunc(deleteAssetsHandler)).Methods("GET")
|
||||||
r.Handle("/settings/notifier/{method}", http.HandlerFunc(saveNotificationHandler)).Methods("POST")
|
r.Handle("/settings/notifier/{method}", http.HandlerFunc(saveNotificationHandler)).Methods("POST")
|
||||||
|
r.Handle("/settings/notifier/{method}/test", http.HandlerFunc(testNotificationHandler)).Methods("POST")
|
||||||
r.Handle("/settings/export", http.HandlerFunc(exportHandler)).Methods("GET")
|
r.Handle("/settings/export", http.HandlerFunc(exportHandler)).Methods("GET")
|
||||||
r.Handle("/plugins/download/{name}", http.HandlerFunc(pluginsDownloadHandler))
|
r.Handle("/plugins/download/{name}", http.HandlerFunc(pluginsDownloadHandler))
|
||||||
r.Handle("/plugins/{name}/save", http.HandlerFunc(pluginSavedHandler)).Methods("POST")
|
r.Handle("/plugins/{name}/save", http.HandlerFunc(pluginSavedHandler)).Methods("POST")
|
||||||
|
|
|
@ -196,3 +196,68 @@ func saveNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
notifier.OnSave(notifer.Method)
|
notifier.OnSave(notifer.Method)
|
||||||
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testNotificationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var err error
|
||||||
|
if !IsAuthenticated(r) {
|
||||||
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
form := parseForm(r)
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
method := vars["method"]
|
||||||
|
enabled := form.Get("enable")
|
||||||
|
host := form.Get("host")
|
||||||
|
port := int(utils.StringInt(form.Get("port")))
|
||||||
|
username := form.Get("username")
|
||||||
|
password := form.Get("password")
|
||||||
|
var1 := form.Get("var1")
|
||||||
|
var2 := form.Get("var2")
|
||||||
|
apiKey := form.Get("api_key")
|
||||||
|
apiSecret := form.Get("api_secret")
|
||||||
|
limits := int(utils.StringInt(form.Get("limits")))
|
||||||
|
|
||||||
|
notifer, notif, err := notifier.SelectNotifier(method)
|
||||||
|
if err != nil {
|
||||||
|
utils.Log(3, fmt.Sprintf("issue saving notifier %v: %v", method, err))
|
||||||
|
executeResponse(w, r, "settings.html", core.CoreApp, "/settings")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if host != "" {
|
||||||
|
notifer.Host = host
|
||||||
|
}
|
||||||
|
if port != 0 {
|
||||||
|
notifer.Port = port
|
||||||
|
}
|
||||||
|
if username != "" {
|
||||||
|
notifer.Username = username
|
||||||
|
}
|
||||||
|
if password != "" && password != "##########" {
|
||||||
|
notifer.Password = password
|
||||||
|
}
|
||||||
|
if var1 != "" {
|
||||||
|
notifer.Var1 = var1
|
||||||
|
}
|
||||||
|
if var2 != "" {
|
||||||
|
notifer.Var2 = var2
|
||||||
|
}
|
||||||
|
if apiKey != "" {
|
||||||
|
notifer.ApiKey = apiKey
|
||||||
|
}
|
||||||
|
if apiSecret != "" {
|
||||||
|
notifer.ApiSecret = apiSecret
|
||||||
|
}
|
||||||
|
if limits != 0 {
|
||||||
|
notifer.Limits = limits
|
||||||
|
}
|
||||||
|
notifer.Enabled = enabled == "on"
|
||||||
|
|
||||||
|
ok, err := notif.(notifier.Tester).OnTest(*notifer)
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
w.Write([]byte("ok"))
|
||||||
|
} else {
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,23 @@ $('.service_li').on('click', function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.test_notifier').on('click', function(e) {
|
||||||
|
var form = $(this).parents('form:first');
|
||||||
|
var values = form.serialize();
|
||||||
|
|
||||||
|
console.log(form);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: form.attr("action")+"/test",
|
||||||
|
type: 'POST',
|
||||||
|
data: values,
|
||||||
|
success: function(data) {
|
||||||
|
alert(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
$('form').submit(function() {
|
$('form').submit(function() {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
|
|
|
@ -181,9 +181,8 @@
|
||||||
{{ range .Notifications }}
|
{{ range .Notifications }}
|
||||||
{{$n := .Select}}
|
{{$n := .Select}}
|
||||||
<div class="tab-pane" id="v-pills-{{underscore $n.Method}}" role="tabpanel" aria-labelledby="v-pills-{{underscore $n.Method }}-tab">
|
<div class="tab-pane" id="v-pills-{{underscore $n.Method}}" role="tabpanel" aria-labelledby="v-pills-{{underscore $n.Method }}-tab">
|
||||||
<form method="POST" action="/settings/notifier/{{ $n.Method }}">
|
<form method="POST" class="{{underscore $n.Method }}" action="/settings/notifier/{{ $n.Method }}">
|
||||||
{{if $n.Title}}<h4>{{$n.Title}}
|
{{if $n.Title}}<h4>{{$n.Title}}</h4>{{end}}
|
||||||
</h4>{{end}}
|
|
||||||
{{if $n.Description}}<p class="small text-muted">{{safe $n.Description}}</p>{{end}}
|
{{if $n.Description}}<p class="small text-muted">{{safe $n.Description}}</p>{{end}}
|
||||||
{{range .Form}}
|
{{range .Form}}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -218,8 +217,8 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{if $n.CanTest}}
|
{{if $n.CanTest}}
|
||||||
<div class="col-12 col-sm-4 float-right text-right">
|
<div class="col-12 col-sm-12">
|
||||||
<button class="btn btn-secondary btn-block text-capitalize">Test</button>
|
<button class="test_notifier btn btn-secondary btn-block text-capitalize col-12 float-right">Test</button>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue