mirror of https://github.com/statping/statping
grouping - public option
parent
47493c8f19
commit
5e60b5578b
|
@ -1,10 +1,49 @@
|
|||
package core
|
||||
|
||||
import "github.com/hunterlong/statping/types"
|
||||
import (
|
||||
"github.com/hunterlong/statping/types"
|
||||
"time"
|
||||
)
|
||||
|
||||
// SelectGroups returns all messages
|
||||
func SelectGroups() ([]*types.Group, error) {
|
||||
var groups []*types.Group
|
||||
db := groupsDb().Find(&groups).Order("id desc")
|
||||
return groups, db.Error
|
||||
type Group struct {
|
||||
*types.Group
|
||||
}
|
||||
|
||||
// Delete will remove a group
|
||||
func (g *Group) Delete() error {
|
||||
err := messagesDb().Delete(g)
|
||||
if err.Error != nil {
|
||||
return err.Error
|
||||
}
|
||||
return err.Error
|
||||
}
|
||||
|
||||
// Update will update a group in the database
|
||||
func (g *Group) Update() error {
|
||||
err := servicesDB().Update(&g)
|
||||
return err.Error
|
||||
}
|
||||
|
||||
// Create will create a group and insert it into the database
|
||||
func (g *Group) Create() (int64, error) {
|
||||
g.CreatedAt = time.Now()
|
||||
db := groupsDb().Create(g)
|
||||
return g.Id, db.Error
|
||||
}
|
||||
|
||||
// SelectGroups returns all groups
|
||||
func SelectGroups() []*Group {
|
||||
var groups []*Group
|
||||
groupsDb().Find(&groups).Order("id desc")
|
||||
return groups
|
||||
}
|
||||
|
||||
// SelectGroup returns a *core.Group
|
||||
func SelectGroup(id int64) *Group {
|
||||
for _, g := range SelectGroups() {
|
||||
if g.Id == id {
|
||||
return g
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -86,11 +86,25 @@ func InsertSampleData() error {
|
|||
|
||||
insertMessages()
|
||||
|
||||
insertSampleGroups()
|
||||
|
||||
utils.Log(1, "Sample data has finished importing")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertSampleGroups() error {
|
||||
group1 := &Group{&types.Group{
|
||||
Name: "Main Services",
|
||||
}}
|
||||
_, err := group1.Create()
|
||||
group2 := &Group{&types.Group{
|
||||
Name: "Linked Services",
|
||||
}}
|
||||
_, err = group2.Create()
|
||||
return err
|
||||
}
|
||||
|
||||
// insertSampleCheckins will create 2 checkins with 60 successful hits per Checkin
|
||||
func insertSampleCheckins() error {
|
||||
s1 := SelectService(1)
|
||||
|
|
|
@ -88,6 +88,12 @@ func sendJsonAction(obj interface{}, method string, w http.ResponseWriter, r *ht
|
|||
case *core.User:
|
||||
objName = "user"
|
||||
objId = v.Id
|
||||
case *types.Group:
|
||||
objName = "group"
|
||||
objId = v.Id
|
||||
case *core.Group:
|
||||
objName = "group"
|
||||
objId = v.Id
|
||||
case *core.Checkin:
|
||||
objName = "checkin"
|
||||
objId = v.Id
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
// Statup
|
||||
// Copyright (C) 2018. Hunter Long and the project contributors
|
||||
// Written by Hunter Long <info@socialeck.com> and the project contributors
|
||||
//
|
||||
// https://github.com/hunterlong/statup
|
||||
//
|
||||
// The licenses for most software and other practical works are designed
|
||||
// to take away your freedom to share and change the works. By contrast,
|
||||
// the GNU General Public License is intended to guarantee your freedom to
|
||||
// share and change all versions of a program--to make sure it remains free
|
||||
// software for all its users.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/hunterlong/statping/core"
|
||||
"github.com/hunterlong/statping/utils"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func apiAllGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !IsReadAuthenticated(r) {
|
||||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
groups := core.SelectGroups()
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(groups)
|
||||
}
|
||||
|
||||
func apiGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !IsReadAuthenticated(r) {
|
||||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
vars := mux.Vars(r)
|
||||
group := core.SelectGroup(utils.ToInt(vars["id"]))
|
||||
if group == nil {
|
||||
sendErrorJson(errors.New("group not found"), w, r)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(group)
|
||||
}
|
||||
|
||||
func apiCreateGroupHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !IsFullAuthenticated(r) {
|
||||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
var group *core.Group
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
err := decoder.Decode(&group)
|
||||
if err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
_, err = group.Create()
|
||||
if err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
sendJsonAction(group, "create", w, r)
|
||||
}
|
||||
|
||||
func apiGroupUpdateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !IsFullAuthenticated(r) {
|
||||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
vars := mux.Vars(r)
|
||||
group := core.SelectGroup(utils.ToInt(vars["id"]))
|
||||
if group == nil {
|
||||
sendErrorJson(errors.New("group not found"), w, r)
|
||||
return
|
||||
}
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
decoder.Decode(&group)
|
||||
err := group.Update()
|
||||
if err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
sendJsonAction(group, "update", w, r)
|
||||
}
|
||||
|
||||
func apiGroupDeleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if !IsFullAuthenticated(r) {
|
||||
sendUnauthorizedJson(w, r)
|
||||
return
|
||||
}
|
||||
vars := mux.Vars(r)
|
||||
group := core.SelectGroup(utils.ToInt(vars["id"]))
|
||||
if group == nil {
|
||||
sendErrorJson(errors.New("group not found"), w, r)
|
||||
return
|
||||
}
|
||||
err := group.Delete()
|
||||
if err != nil {
|
||||
sendErrorJson(err, w, r)
|
||||
return
|
||||
}
|
||||
sendJsonAction(group, "delete", w, r)
|
||||
}
|
|
@ -192,6 +192,9 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
|
|||
"Services": func() []types.ServiceInterface {
|
||||
return core.CoreApp.Services
|
||||
},
|
||||
"Groups": func() []*core.Group {
|
||||
return core.SelectGroups()
|
||||
},
|
||||
"len": func(g []types.ServiceInterface) int {
|
||||
return len(g)
|
||||
},
|
||||
|
@ -259,6 +262,9 @@ var handlerFuncs = func(w http.ResponseWriter, r *http.Request) template.FuncMap
|
|||
"NewMessage": func() *types.Message {
|
||||
return new(types.Message)
|
||||
},
|
||||
"NewGroup": func() *types.Group {
|
||||
return new(types.Group)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,7 +282,7 @@ func ExecuteResponse(w http.ResponseWriter, r *http.Request, file string, data i
|
|||
w.Header().Add("Strict-Transport-Security", "max-age=63072000; includeSubDomains")
|
||||
}
|
||||
|
||||
templates := []string{"base.gohtml", "head.gohtml", "nav.gohtml", "footer.gohtml", "scripts.gohtml", "form_service.gohtml", "form_notifier.gohtml", "form_user.gohtml", "form_checkin.gohtml", "form_message.gohtml"}
|
||||
templates := []string{"base.gohtml", "head.gohtml", "nav.gohtml", "footer.gohtml", "scripts.gohtml", "form_service.gohtml", "form_notifier.gohtml", "form_group.gohtml", "form_user.gohtml", "form_checkin.gohtml", "form_message.gohtml"}
|
||||
javascripts := []string{"charts.js", "chart_index.js"}
|
||||
|
||||
render, err := source.TmplBox.String(file)
|
||||
|
|
|
@ -85,6 +85,13 @@ func Router() *mux.Router {
|
|||
r.Handle("/service/{id}/edit", http.HandlerFunc(servicesViewHandler))
|
||||
r.Handle("/service/{id}/delete_failures", http.HandlerFunc(servicesDeleteFailuresHandler)).Methods("GET")
|
||||
|
||||
// API GROUPS Routes
|
||||
r.Handle("/api/groups", http.HandlerFunc(apiAllGroupHandler)).Methods("GET")
|
||||
r.Handle("/api/groups", http.HandlerFunc(apiCreateGroupHandler)).Methods("POST")
|
||||
r.Handle("/api/groups/{id}", http.HandlerFunc(apiGroupHandler)).Methods("GET")
|
||||
r.Handle("/api/groups/{id}", http.HandlerFunc(apiGroupUpdateHandler)).Methods("POST")
|
||||
r.Handle("/api/groups/{id}", http.HandlerFunc(apiGroupDeleteHandler)).Methods("DELETE")
|
||||
|
||||
// API Routes
|
||||
r.Handle("/api", http.HandlerFunc(apiIndexHandler))
|
||||
r.Handle("/api/renew", http.HandlerFunc(apiRenewHandler))
|
||||
|
|
|
@ -53,7 +53,7 @@ func servicesHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
data := map[string]interface{}{
|
||||
"Services": core.CoreApp.Services,
|
||||
"Groups": core.CoreApp.Services,
|
||||
"Groups": core.SelectGroups(),
|
||||
}
|
||||
ExecuteResponse(w, r, "services.gohtml", data, nil)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
{{define "form_group"}}
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
{{$message := .}}
|
||||
{{if ne .Id 0}}
|
||||
<form class="ajax_form" action="/api/groups/{{.Id}}" data-redirect="/services" method="POST">
|
||||
{{else}}
|
||||
<form class="ajax_form" action="/api/groups" data-redirect="/services" method="POST">
|
||||
{{end}}
|
||||
<div class="form-group row">
|
||||
<label for="username" class="col-sm-4 col-form-label">Group Name</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="name" class="form-control" value="{{.Name}}" id="title" placeholder="Group Name" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="alert alert-danger d-none" id="alerter" role="alert"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
|
@ -104,20 +104,21 @@
|
|||
<div class="form-group row">
|
||||
<label for="service_type" class="col-sm-4 col-form-label">Group</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="group_id" class="form-control" id="group_id" value="{{.GroupId}}" {{if ne .GroupId ""}}readonly{{end}}>
|
||||
<option value="http" {{if eq .GroupId "http"}}selected{{end}}>HTTP Service</option>
|
||||
<option value="tcp" {{if eq .GroupId "tcp"}}selected{{end}}>TCP Service</option>
|
||||
<option value="udp" {{if eq .GroupId "udp"}}selected{{end}}>UDP Service</option>
|
||||
<select name="group_id" class="form-control" id="group_id" value="{{.GroupId}}">
|
||||
<option value="0" {{if eq .GroupId 0}}selected{{end}}>None</option>
|
||||
{{range Groups}}
|
||||
<option value="{{.Id}}">{{.Name}}</option>
|
||||
{{end}}
|
||||
</select>
|
||||
<small class="form-text text-muted">Use HTTP if you are checking a website or use TCP if you are checking a server</small>
|
||||
<small class="form-text text-muted">Attach this service to a group</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="order" class="col-sm-4 col-form-label">Visible</label>
|
||||
<div class="col-8 mt-1">
|
||||
<span class="switch float-left">
|
||||
<input type="checkbox" name="public" class="switch" id="switch-service" {{if eq .Id 0}}checked{{end}}{{if .AllowNotifications.Bool}}checked{{end}}>
|
||||
<label for="switch-service">Show Failures and service endpoint information to the public</label>
|
||||
<input type="checkbox" name="public" class="switch" id="switch-public" {{if .Public.Bool}}checked{{end}}>
|
||||
<label for="switch-public">Show service details to the public</label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -769,6 +769,490 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Groups",
|
||||
"item": [
|
||||
{
|
||||
"name": "All Groups",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "d87f8a4e-7640-45b8-9d45-4f6e6f2463ee",
|
||||
"exec": [
|
||||
"pm.test(\"View All Groups\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.length).to.eql(2);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{api_key}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/groups",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"groups"
|
||||
]
|
||||
},
|
||||
"description": "View an array of all Services added to your Statping instance."
|
||||
},
|
||||
"response": []
|
||||
},
|
||||
{
|
||||
"name": "View Group",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "023c5643-6cb1-4cd0-b775-566f232d68f8",
|
||||
"exec": [
|
||||
"pm.test(\"View Group\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.name).to.eql(\"Main Services\");",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{api_key}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"name": "Content-Type",
|
||||
"type": "text",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/groups/1",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"groups",
|
||||
"1"
|
||||
]
|
||||
},
|
||||
"description": "View a specific service, this will include the service's failures and checkins."
|
||||
},
|
||||
"response": [
|
||||
{
|
||||
"name": "View Service",
|
||||
"originalRequest": {
|
||||
"method": "GET",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"name": "Content-Type",
|
||||
"value": "application/json",
|
||||
"type": "text"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/services/1",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"services",
|
||||
"1"
|
||||
]
|
||||
}
|
||||
},
|
||||
"status": "OK",
|
||||
"code": 200,
|
||||
"_postman_previewlanguage": "json",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
},
|
||||
{
|
||||
"key": "Date",
|
||||
"value": "Mon, 10 Dec 2018 19:31:19 GMT"
|
||||
},
|
||||
{
|
||||
"key": "Content-Length",
|
||||
"value": "482"
|
||||
}
|
||||
],
|
||||
"cookie": [],
|
||||
"body": "{\n \"id\": 1,\n \"name\": \"Google\",\n \"domain\": \"https://google.com\",\n \"expected\": null,\n \"expected_status\": 200,\n \"check_interval\": 10,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": null,\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 1,\n \"allow_notifications\": false,\n \"created_at\": \"2018-12-10T11:15:42.24769-08:00\",\n \"updated_at\": \"2018-12-10T11:15:42.247837-08:00\",\n \"online\": true,\n \"latency\": 0.190599816,\n \"ping_time\": 0.00476598,\n \"online_24_hours\": 0,\n \"avg_response\": \"\",\n \"status_code\": 200,\n \"last_success\": \"2018-12-10T11:31:13.511139-08:00\"\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Create Group",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "d4eb16fe-8495-40e5-9ca3-be20951e5133",
|
||||
"exec": [
|
||||
"pm.test(\"Create Group\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.output.name).to.eql(\"New Group\");",
|
||||
" pm.globals.set(\"group_id\", jsonData.output.id);",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{api_key}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\": \"New Group\"\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/groups",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"groups"
|
||||
]
|
||||
},
|
||||
"description": "Create a new service and begin monitoring."
|
||||
},
|
||||
"response": [
|
||||
{
|
||||
"name": "Create Service",
|
||||
"originalRequest": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\": \"New Service\",\n \"domain\": \"https://statping.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 30,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 30,\n \"order_id\": 0\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/services",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"services"
|
||||
]
|
||||
}
|
||||
},
|
||||
"status": "OK",
|
||||
"code": 200,
|
||||
"_postman_previewlanguage": "json",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
},
|
||||
{
|
||||
"key": "Date",
|
||||
"value": "Mon, 10 Dec 2018 19:31:47 GMT"
|
||||
},
|
||||
{
|
||||
"key": "Content-Length",
|
||||
"value": "528"
|
||||
}
|
||||
],
|
||||
"cookie": [],
|
||||
"body": "{\n \"status\": \"success\",\n \"type\": \"service\",\n \"method\": \"create\",\n \"id\": 10,\n \"output\": {\n \"id\": 10,\n \"name\": \"New Service\",\n \"domain\": \"https://statping.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 30,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 30,\n \"order_id\": 0,\n \"allow_notifications\": false,\n \"created_at\": \"2018-12-10T11:31:47.535086-08:00\",\n \"updated_at\": \"2018-12-10T11:31:47.535184-08:00\",\n \"online\": false,\n \"latency\": 0,\n \"ping_time\": 0,\n \"online_24_hours\": 0,\n \"avg_response\": \"\",\n \"status_code\": 0,\n \"last_success\": \"0001-01-01T00:00:00Z\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Update Group",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "b5a67a19-fd08-40b0-a961-3e9474ab78c6",
|
||||
"exec": [
|
||||
"pm.test(\"Update Service\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.output.name).to.eql(\"Updated Group\");",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{api_key}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\": \"Updated Group\"\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/groups/{{group_id}}",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"groups",
|
||||
"{{group_id}}"
|
||||
]
|
||||
},
|
||||
"description": "Update a service with new values and begin monitoring."
|
||||
},
|
||||
"response": [
|
||||
{
|
||||
"name": "Update Service",
|
||||
"originalRequest": {
|
||||
"method": "POST",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
}
|
||||
],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": "{\n \"name\": \"Updated New Service\",\n \"domain\": \"https://google.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 60,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 0\n}"
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/services/{{service_id}}",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"services",
|
||||
"{{service_id}}"
|
||||
]
|
||||
}
|
||||
},
|
||||
"status": "OK",
|
||||
"code": 200,
|
||||
"_postman_previewlanguage": "json",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
},
|
||||
{
|
||||
"key": "Date",
|
||||
"value": "Mon, 10 Dec 2018 19:31:54 GMT"
|
||||
},
|
||||
{
|
||||
"key": "Content-Length",
|
||||
"value": "567"
|
||||
}
|
||||
],
|
||||
"cookie": [],
|
||||
"body": "{\n \"status\": \"success\",\n \"type\": \"service\",\n \"method\": \"update\",\n \"id\": 10,\n \"output\": {\n \"id\": 10,\n \"name\": \"Updated New Service\",\n \"domain\": \"https://google.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 60,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 0,\n \"allow_notifications\": false,\n \"created_at\": \"2018-12-10T11:31:47.535086-08:00\",\n \"updated_at\": \"2018-12-10T11:31:47.535184-08:00\",\n \"online\": true,\n \"latency\": 0.550636193,\n \"ping_time\": 0.073339805,\n \"online_24_hours\": 0,\n \"avg_response\": \"\",\n \"status_code\": 200,\n \"last_success\": \"2018-12-10T11:31:49.161389-08:00\"\n }\n}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Delete Group",
|
||||
"event": [
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "dd4d721d-d874-448b-abc9-59c1afceb58e",
|
||||
"exec": [
|
||||
"pm.test(\"Delete Service\", function () {",
|
||||
" var jsonData = pm.response.json();",
|
||||
" pm.expect(jsonData.status).to.eql(\"success\");",
|
||||
" pm.expect(jsonData.type).to.eql(\"group\");",
|
||||
" pm.expect(jsonData.method).to.eql(\"delete\");",
|
||||
"});"
|
||||
],
|
||||
"type": "text/javascript"
|
||||
}
|
||||
}
|
||||
],
|
||||
"request": {
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{api_key}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"method": "DELETE",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/groups/{{group_id}}",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"groups",
|
||||
"{{group_id}}"
|
||||
]
|
||||
},
|
||||
"description": "Delete a group"
|
||||
},
|
||||
"response": [
|
||||
{
|
||||
"name": "Delete Service",
|
||||
"originalRequest": {
|
||||
"method": "DELETE",
|
||||
"header": [],
|
||||
"body": {
|
||||
"mode": "raw",
|
||||
"raw": ""
|
||||
},
|
||||
"url": {
|
||||
"raw": "{{endpoint}}/api/services/{{service_id}}",
|
||||
"host": [
|
||||
"{{endpoint}}"
|
||||
],
|
||||
"path": [
|
||||
"api",
|
||||
"services",
|
||||
"{{service_id}}"
|
||||
]
|
||||
}
|
||||
},
|
||||
"status": "OK",
|
||||
"code": 200,
|
||||
"_postman_previewlanguage": "json",
|
||||
"header": [
|
||||
{
|
||||
"key": "Content-Type",
|
||||
"value": "application/json"
|
||||
},
|
||||
{
|
||||
"key": "Date",
|
||||
"value": "Mon, 10 Dec 2018 19:32:06 GMT"
|
||||
},
|
||||
{
|
||||
"key": "Content-Length",
|
||||
"value": "567"
|
||||
}
|
||||
],
|
||||
"cookie": [],
|
||||
"body": "{\n \"status\": \"success\",\n \"type\": \"service\",\n \"method\": \"delete\",\n \"id\": 10,\n \"output\": {\n \"id\": 10,\n \"name\": \"Updated New Service\",\n \"domain\": \"https://google.com\",\n \"expected\": \"\",\n \"expected_status\": 200,\n \"check_interval\": 60,\n \"type\": \"http\",\n \"method\": \"GET\",\n \"post_data\": \"\",\n \"port\": 0,\n \"timeout\": 10,\n \"order_id\": 0,\n \"allow_notifications\": false,\n \"created_at\": \"2018-12-10T11:31:47.535086-08:00\",\n \"updated_at\": \"2018-12-10T11:31:47.535184-08:00\",\n \"online\": true,\n \"latency\": 0.203382878,\n \"ping_time\": 0.001664491,\n \"online_24_hours\": 0,\n \"avg_response\": \"\",\n \"status_code\": 200,\n \"last_success\": \"2018-12-10T11:31:55.455091-08:00\"\n }\n}"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"auth": {
|
||||
"type": "bearer",
|
||||
"bearer": [
|
||||
{
|
||||
"key": "token",
|
||||
"value": "{{api_key}}",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
},
|
||||
"event": [
|
||||
{
|
||||
"listen": "prerequest",
|
||||
"script": {
|
||||
"id": "4cd2ab82-e60d-45cd-9b74-cb4b5d893f4d",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"listen": "test",
|
||||
"script": {
|
||||
"id": "c7cb2b6d-289a-4073-b291-202bbec8cb44",
|
||||
"type": "text/javascript",
|
||||
"exec": [
|
||||
""
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Users",
|
||||
"item": [
|
||||
|
|
|
@ -43,19 +43,17 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col" class="d-none d-md-table-cell">Status</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="sortable" id="services_table">
|
||||
{{range .Groups}}
|
||||
<tr id="service_{{.Id}}" data-id="{{.Id}}">
|
||||
<tr id="group_{{.Id}}" data-id="{{.Id}}">
|
||||
<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="text-right">
|
||||
<div class="btn-group">
|
||||
<a href="/service/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-chart-area"></i> View</a>
|
||||
{{if Auth}}<a href="/api/services/{{.Id}}" class="ajax_delete btn btn-danger" data-method="DELETE" data-obj="service_{{.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="groups_{{.Id}}" data-id="{{.Id}}"><i class="fas fa-times"></i></a>{{end}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -64,8 +62,8 @@
|
|||
</table>
|
||||
{{end}}
|
||||
{{if Auth}}
|
||||
<h3>Create Service</h3>
|
||||
{{template "form_service" NewService}}
|
||||
<h3>Create Group</h3>
|
||||
{{template "form_group" NewGroup}}
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2018-12-31 03:39:26.710899 -0800 PST m=+0.479547222
|
||||
// 2018-12-31 13:16:43.415892 -0800 PST m=+1.140052566
|
||||
//
|
||||
// This contains the most recently Markdown source for the Statping Wiki.
|
||||
package source
|
||||
|
|
Loading…
Reference in New Issue