mirror of https://github.com/statping/statping
grouping - http proxy
parent
0b7687aa85
commit
df2eb5c50a
|
@ -41,15 +41,29 @@ func (g *Group) Services() []*Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectGroups returns all groups
|
// SelectGroups returns all groups
|
||||||
func SelectGroups() []*Group {
|
func SelectGroups(includeAll bool, auth bool) []*Group {
|
||||||
var groups []*Group
|
var groups []*Group
|
||||||
|
var validGroups []*Group
|
||||||
groupsDb().Find(&groups).Order("id desc")
|
groupsDb().Find(&groups).Order("id desc")
|
||||||
return groups
|
if includeAll {
|
||||||
|
emptyGroup := &Group{&types.Group{Id: 0, Public: types.NewNullBool(true)}}
|
||||||
|
groups = append(groups, emptyGroup)
|
||||||
|
}
|
||||||
|
for _, g := range groups {
|
||||||
|
if !g.Public.Bool {
|
||||||
|
if auth {
|
||||||
|
validGroups = append(validGroups, g)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
validGroups = append(validGroups, g)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return validGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
// SelectGroup returns a *core.Group
|
// SelectGroup returns a *core.Group
|
||||||
func SelectGroup(id int64) *Group {
|
func SelectGroup(id int64) *Group {
|
||||||
for _, g := range SelectGroups() {
|
for _, g := range SelectGroups(false, false) {
|
||||||
if g.Id == id {
|
if g.Id == id {
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,11 +103,13 @@ func InsertSampleData() error {
|
||||||
|
|
||||||
func insertSampleGroups() error {
|
func insertSampleGroups() error {
|
||||||
group1 := &Group{&types.Group{
|
group1 := &Group{&types.Group{
|
||||||
Name: "Main Services",
|
Name: "Main Services",
|
||||||
|
Public: types.NewNullBool(true),
|
||||||
}}
|
}}
|
||||||
_, err := group1.Create()
|
_, err := group1.Create()
|
||||||
group2 := &Group{&types.Group{
|
group2 := &Group{&types.Group{
|
||||||
Name: "Linked Services",
|
Name: "Linked Services",
|
||||||
|
Public: types.NewNullBool(false),
|
||||||
}}
|
}}
|
||||||
_, err = group2.Create()
|
_, err = group2.Create()
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -24,16 +24,19 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// apiAllGroupHandler will show all the groups
|
||||||
func apiAllGroupHandler(w http.ResponseWriter, r *http.Request) {
|
func apiAllGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !IsReadAuthenticated(r) {
|
if !IsReadAuthenticated(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
groups := core.SelectGroups()
|
auth := IsUser(r)
|
||||||
|
groups := core.SelectGroups(false, auth)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
json.NewEncoder(w).Encode(groups)
|
json.NewEncoder(w).Encode(groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apiGroupHandler will show a single group
|
||||||
func apiGroupHandler(w http.ResponseWriter, r *http.Request) {
|
func apiGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !IsReadAuthenticated(r) {
|
if !IsReadAuthenticated(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
|
@ -49,6 +52,7 @@ func apiGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
json.NewEncoder(w).Encode(group)
|
json.NewEncoder(w).Encode(group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apiCreateGroupHandler accepts a POST method to create new groups
|
||||||
func apiCreateGroupHandler(w http.ResponseWriter, r *http.Request) {
|
func apiCreateGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !IsFullAuthenticated(r) {
|
if !IsFullAuthenticated(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
|
@ -69,6 +73,7 @@ func apiCreateGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
sendJsonAction(group, "create", w, r)
|
sendJsonAction(group, "create", w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// apiGroupDeleteHandler accepts a DELETE method to delete groups
|
||||||
func apiGroupDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
func apiGroupDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if !IsFullAuthenticated(r) {
|
if !IsFullAuthenticated(r) {
|
||||||
sendUnauthorizedJson(w, r)
|
sendUnauthorizedJson(w, r)
|
||||||
|
|
|
@ -192,8 +192,9 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
|
||||||
"Services": func() []types.ServiceInterface {
|
"Services": func() []types.ServiceInterface {
|
||||||
return core.CoreApp.Services
|
return core.CoreApp.Services
|
||||||
},
|
},
|
||||||
"Groups": func() []*core.Group {
|
"Groups": func(includeAll bool) []*core.Group {
|
||||||
return core.SelectGroups()
|
auth := IsUser(r)
|
||||||
|
return core.SelectGroups(includeAll, auth)
|
||||||
},
|
},
|
||||||
"len": func(g interface{}) int {
|
"len": func(g interface{}) int {
|
||||||
val := reflect.ValueOf(g)
|
val := reflect.ValueOf(g)
|
||||||
|
|
|
@ -53,7 +53,6 @@ func servicesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"Services": core.CoreApp.Services,
|
"Services": core.CoreApp.Services,
|
||||||
"Groups": core.SelectGroups(),
|
|
||||||
}
|
}
|
||||||
ExecuteResponse(w, r, "services.gohtml", data, nil)
|
ExecuteResponse(w, r, "services.gohtml", data, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,15 @@
|
||||||
<input type="text" name="name" class="form-control" value="{{.Name}}" id="title" placeholder="Group Name" required>
|
<input type="text" name="name" class="form-control" value="{{.Name}}" id="title" placeholder="Group Name" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group row">
|
||||||
|
<label for="order" class="col-sm-4 col-form-label">Public Group</label>
|
||||||
|
<div class="col-8 mt-1">
|
||||||
|
<span class="switch float-left">
|
||||||
|
<input type="checkbox" name="public" class="switch" id="switch-group-public" checked>
|
||||||
|
<label for="switch-group-public">Show group services to the public</label>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<button type="submit" class="btn btn-primary btn-block">{{if ne .Id 0}}Update Group{{else}}Create Group{{end}}</button>
|
<button type="submit" class="btn btn-primary btn-block">{{if ne .Id 0}}Update Group{{else}}Create Group{{end}}</button>
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
<div class="col-sm-8">
|
<div class="col-sm-8">
|
||||||
<select name="group_id" class="form-control" id="group_id">
|
<select name="group_id" class="form-control" id="group_id">
|
||||||
<option value="0" {{if eq $s.GroupId 0}}selected{{end}}>None</option>
|
<option value="0" {{if eq $s.GroupId 0}}selected{{end}}>None</option>
|
||||||
{{range Groups}}
|
{{range Groups false}}
|
||||||
<option value="{{.Id}}" {{if eq $s.GroupId .Id}}selected{{end}}>{{.Name}}</option>
|
<option value="{{.Id}}" {{if eq $s.GroupId .Id}}selected{{end}}>{{.Name}}</option>
|
||||||
{{end}}
|
{{end}}
|
||||||
</select>
|
</select>
|
||||||
|
|
|
@ -8,39 +8,23 @@
|
||||||
<h5 class="col-12 text-center mb-5 header-desc">{{ .Description }}</h5>
|
<h5 class="col-12 text-center mb-5 header-desc">{{ .Description }}</h5>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{if ne (len Groups) 0}}
|
{{ range Groups true }}
|
||||||
{{ range Groups }}
|
<div class="col-12 full-col-12">
|
||||||
<div class="col-12 full-col-12">
|
<h4>{{.Name}}</h4>
|
||||||
<h4>{{.Name}}</h4>
|
|
||||||
<div class="list-group online_list mb-3">
|
|
||||||
{{ range .Services }}
|
|
||||||
<a href="#" class="service_li list-group-item list-group-item-action {{if not .Online}}bg-danger text-white{{ end }}" data-id="{{.Id}}">
|
|
||||||
{{ .Name }}
|
|
||||||
{{if .Online}}
|
|
||||||
<span class="badge bg-success float-right pulse-glow">ONLINE</span>
|
|
||||||
{{ else }}
|
|
||||||
<span class="badge bg-white text-black-50 float-right pulse">OFFLINE</span>
|
|
||||||
{{end}}
|
|
||||||
</a>
|
|
||||||
{{ end }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
||||||
{{else}}
|
|
||||||
<div class="list-group online_list mb-3">
|
<div class="list-group online_list mb-3">
|
||||||
{{ range Services }}
|
{{ range .Services }}
|
||||||
<a href="#" class="service_li list-group-item list-group-item-action {{if not .Online}}bg-danger text-white{{ end }}" data-id="{{.Id}}">
|
<a href="#" class="service_li list-group-item list-group-item-action {{if not .Online}}bg-danger text-white{{ end }}" data-id="{{.Id}}">
|
||||||
{{ .Name }}
|
{{ .Name }}
|
||||||
{{if .Online}}
|
{{if .Online}}
|
||||||
<span class="badge bg-success float-right pulse-glow">ONLINE</span>
|
<span class="badge bg-success float-right pulse-glow">ONLINE</span>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
<span class="badge bg-white text-black-50 float-right pulse">OFFLINE</span>
|
<span class="badge bg-white text-black-50 float-right pulse">OFFLINE</span>
|
||||||
{{end}}
|
{{end}}
|
||||||
</a>
|
</a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
{{ if .Messages }}
|
{{ if .Messages }}
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col" class="d-none d-md-table-cell">Status</th>
|
<th scope="col" class="d-none d-md-table-cell">Status</th>
|
||||||
|
<th scope="col">Visibility</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
@ -18,7 +19,8 @@
|
||||||
{{range .Services}}
|
{{range .Services}}
|
||||||
<tr id="service_{{.Id}}" data-id="{{.Id}}">
|
<tr id="service_{{.Id}}" data-id="{{.Id}}">
|
||||||
<td><span class="drag_icon d-none d-md-inline"><i class="fas fa-bars"></i></span> {{.Name}}</td>
|
<td><span class="drag_icon d-none d-md-inline"><i class="fas fa-bars"></i></span> {{.Name}}</td>
|
||||||
<td class="d-none d-md-table-cell">{{if .Online}}<span class="badge badge-success">ONLINE</span>{{else}}<span class="badge badge-danger">OFFLINE</span>{{end}} </td>
|
<td class="d-none d-md-table-cell">{{if .Online}}<span class="badge badge-success">ONLINE</span>{{else}}<span class="badge badge-danger">OFFLINE</span>{{end}}</td>
|
||||||
|
<td class="d-none d-md-table-cell">{{if .Public.Bool}}<span class="badge badge-primary">PUBLIC</span>{{else}}<span class="badge badge-secondary">PRIVATE</span>{{end}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<a href="/service/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-chart-area"></i> View</a>
|
<a href="/service/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-chart-area"></i> View</a>
|
||||||
|
@ -43,14 +45,16 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col">Name</th>
|
<th scope="col">Name</th>
|
||||||
<th scope="col">Services</th>
|
<th scope="col">Services</th>
|
||||||
|
<th scope="col">Visibility</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody id="groups_table">
|
<tbody id="groups_table">
|
||||||
{{range .Groups}}
|
{{range Groups false}}
|
||||||
<tr id="group_{{.Id}}" data-id="{{.Id}}">
|
<tr id="group_{{.Id}}" data-id="{{.Id}}">
|
||||||
<td>{{.Name}}</td>
|
<td>{{.Name}}</td>
|
||||||
<td>{{len .Services}}</td>
|
<td>{{len .Services}}</td>
|
||||||
|
<td>{{if .Public.Bool}}<span class="badge badge-primary">PUBLIC</span>{{else}}<span class="badge badge-secondary">PRIVATE</span>{{end}}</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
{{if Auth}}<a href="/api/groups/{{.Id}}" class="ajax_delete btn btn-danger" data-method="DELETE" data-obj="group_{{.Id}}" data-id="{{.Id}}"><i class="fas fa-times"></i></a>{{end}}
|
{{if Auth}}<a href="/api/groups/{{.Id}}" class="ajax_delete btn btn-danger" data-method="DELETE" data-obj="group_{{.Id}}" data-id="{{.Id}}"><i class="fas fa-times"></i></a>{{end}}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by go generate; DO NOT EDIT.
|
// Code generated by go generate; DO NOT EDIT.
|
||||||
// This file was generated by robots at
|
// This file was generated by robots at
|
||||||
// 2019-01-03 11:12:03.7014 -0800 PST m=+0.913709962
|
// 2019-01-03 13:06:31.051097 -0800 PST m=+1.051596230
|
||||||
//
|
//
|
||||||
// This contains the most recently Markdown source for the Statping Wiki.
|
// This contains the most recently Markdown source for the Statping Wiki.
|
||||||
package source
|
package source
|
||||||
|
|
|
@ -6,6 +6,7 @@ import "time"
|
||||||
type Group struct {
|
type Group struct {
|
||||||
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
||||||
Name string `gorm:"column:name" json:"name"`
|
Name string `gorm:"column:name" json:"name"`
|
||||||
|
Public NullBool `gorm:"default:false;column:public" json:"public"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,6 +231,7 @@ func SaveFile(filename string, data []byte) error {
|
||||||
// // headers - An array of Headers to be sent (KEY=VALUE) []string{"Authentication=12345", ...}
|
// // headers - An array of Headers to be sent (KEY=VALUE) []string{"Authentication=12345", ...}
|
||||||
// // body - The body or form data to send with HTTP request
|
// // body - The body or form data to send with HTTP request
|
||||||
// // timeout - Specific duration to timeout on. time.Duration(30 * time.Seconds)
|
// // timeout - Specific duration to timeout on. time.Duration(30 * time.Seconds)
|
||||||
|
// // You can use a HTTP Proxy if you HTTP_PROXY environment variable
|
||||||
func HttpRequest(url, method string, content interface{}, headers []string, body io.Reader, timeout time.Duration) ([]byte, *http.Response, error) {
|
func HttpRequest(url, method string, content interface{}, headers []string, body io.Reader, timeout time.Duration) ([]byte, *http.Response, error) {
|
||||||
var err error
|
var err error
|
||||||
transport := &http.Transport{
|
transport := &http.Transport{
|
||||||
|
@ -240,6 +241,7 @@ func HttpRequest(url, method string, content interface{}, headers []string, body
|
||||||
DisableKeepAlives: true,
|
DisableKeepAlives: true,
|
||||||
ResponseHeaderTimeout: timeout,
|
ResponseHeaderTimeout: timeout,
|
||||||
TLSHandshakeTimeout: timeout,
|
TLSHandshakeTimeout: timeout,
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
}
|
}
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
Transport: transport,
|
Transport: transport,
|
||||||
|
|
Loading…
Reference in New Issue