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/delete_assets", http.HandlerFunc(deleteAssetsHandler)).Methods("GET")
|
||||
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("/plugins/download/{name}", http.HandlerFunc(pluginsDownloadHandler))
|
||||
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)
|
||||
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;
|
||||
});
|
||||
|
||||
$('.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() {
|
||||
console.log(this);
|
||||
|
|
|
@ -181,9 +181,8 @@
|
|||
{{ range .Notifications }}
|
||||
{{$n := .Select}}
|
||||
<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 }}">
|
||||
{{if $n.Title}}<h4>{{$n.Title}}
|
||||
</h4>{{end}}
|
||||
<form method="POST" class="{{underscore $n.Method }}" action="/settings/notifier/{{ $n.Method }}">
|
||||
{{if $n.Title}}<h4>{{$n.Title}}</h4>{{end}}
|
||||
{{if $n.Description}}<p class="small text-muted">{{safe $n.Description}}</p>{{end}}
|
||||
{{range .Form}}
|
||||
<div class="form-group">
|
||||
|
@ -206,20 +205,20 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-3 col-sm-2 mt-1">
|
||||
<div class="col-3 col-sm-2 mt-1">
|
||||
<span class="switch">
|
||||
<input type="checkbox" name="enable" class="switch" id="switch-{{ $n.Method }}" {{if $n.Enabled}}checked{{end}}>
|
||||
<label for="switch-{{ $n.Method }}"></label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-12 col-sm-4 mb-2 mb-sm-0 mt-2 mt-sm-0">
|
||||
<button type="submit" class="btn btn-primary btn-block text-capitalize">Save</button>
|
||||
</div>
|
||||
|
||||
{{if $n.CanTest}}
|
||||
<div class="col-12 col-sm-4 float-right text-right">
|
||||
<button class="btn btn-secondary btn-block text-capitalize">Test</button>
|
||||
<div class="col-12 col-sm-12">
|
||||
<button class="test_notifier btn btn-secondary btn-block text-capitalize col-12 float-right">Test</button>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
|
|
Loading…
Reference in New Issue