Skip to content

Commit

Permalink
add WEB ui
Browse files Browse the repository at this point in the history
  • Loading branch information
reddec committed Jun 28, 2018
1 parent 80140db commit 449454e
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "ui"]
path = ui
url = [email protected]:reddec/monexec-ui.git
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ It’s tool for controlling processes like a supervisord but with some important
* Support template-based email notification
* Support HTTP notification
* REST API (see swagger.yaml)
* Web UI (if REST API enabled)

![screencapture-127-0-0-1-9000-2018-06-28-20_46_16](https://user-images.githubusercontent.com/6597086/42038135-c961b11a-7b1c-11e8-9437-44de6b36510c.png)

## Installing

Expand Down
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ rest:

API documentation see in swagger.yaml file in repository

**WEB UI** enable on `/ui` path

![screencapture-127-0-0-1-9000-2018-06-28-20_46_16](https://user-images.githubusercontent.com/6597086/42038135-c961b11a-7b1c-11e8-9437-44de6b36510c.png)

## Commands

### run
Expand Down
28 changes: 27 additions & 1 deletion plugins/adp_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import (
"net/http"
"time"
"github.com/gin-gonic/gin"
"os"
"io"
"github.com/elazarl/go-bindata-assetfs"
)

const restApiStartupCheck = 1 * time.Second

//go:generate go-bindata -pkg plugins -prefix ../ui/dist/ ../ui/dist/
type RestPlugin struct {
Listen string `yaml:"listen"`
server *http.Server
Expand All @@ -19,7 +23,7 @@ type RestPlugin struct {
func (p *RestPlugin) Prepare(ctx context.Context, pl *pool.Pool) error {

router := gin.Default()

router.StaticFS("/ui/", &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, AssetInfo: AssetInfo, Prefix: ""})
router.GET("/supervisors", func(gctx *gin.Context) {
var names = make([]string, 0)
for _, sv := range pl.Supervisors() {
Expand All @@ -37,6 +41,28 @@ func (p *RestPlugin) Prepare(ctx context.Context, pl *pool.Pool) error {
}
gctx.AbortWithStatus(http.StatusNotFound)
})
router.GET("/supervisor/:name/log", func(gctx *gin.Context) {
name := gctx.Param("name")
for _, sv := range pl.Supervisors() {
if sv.Config().Name == name {
if sv.Config().LogFile == "" {
break
}
f, err := os.Open(sv.Config().LogFile)
if err != nil {
gctx.AbortWithError(http.StatusBadGateway, err)
return
}
defer f.Close()
gctx.Header("Content-Type", "text/plain")
gctx.Header("Content-Disposition", "attachment; filename=\""+sv.Config().Name+".log\"")
gctx.AbortWithStatus(http.StatusOK)
io.Copy(gctx.Writer, f)
return
}
}
gctx.AbortWithStatus(http.StatusNotFound)
})
router.POST("/supervisor/:name", func(gctx *gin.Context) {
name := gctx.Param("name")
for _, sv := range pl.Supervisors() {
Expand Down
258 changes: 258 additions & 0 deletions plugins/bindata.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ui
Submodule ui added at dc442c

0 comments on commit 449454e

Please sign in to comment.