feat: add report trigger
This allows users to quickly show the state of any configured application, as well as the state of their server. In doing so, we make it easy for them to provide information necessary for debugging in a single command.
This commit is contained in:
1
plugins/network/.gitignore
vendored
1
plugins/network/.gitignore
vendored
@@ -5,3 +5,4 @@
|
||||
/install
|
||||
/post-create
|
||||
/post-delete
|
||||
/report
|
||||
@@ -3,7 +3,7 @@ include ../../common.mk
|
||||
GO_ARGS ?= -a
|
||||
|
||||
SUBCOMMANDS = subcommands/rebuild subcommands/rebuildall subcommands/report subcommands/set
|
||||
TRIGGERS = triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-create triggers/post-delete
|
||||
TRIGGERS = triggers/install triggers/network-build-config triggers/network-compute-ports triggers/network-config-exists triggers/network-get-ipaddr triggers/network-get-listeners triggers/network-get-port triggers/network-get-property triggers/network-write-ipaddr triggers/network-write-port triggers/post-create triggers/post-delete triggers/report
|
||||
build-in-docker: clean
|
||||
docker run --rm \
|
||||
-v $$PWD/../..:$(GO_REPO_ROOT) \
|
||||
@@ -22,7 +22,7 @@ subcommands/%: src/subcommands/*/%.go
|
||||
go build $(GO_ARGS) -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -rf commands subcommands triggers network-* install post-create post-delete
|
||||
rm -rf commands subcommands triggers network-* install post-create post-delete report
|
||||
|
||||
src-clean:
|
||||
rm -rf .gitignore src triggers vendor Makefile *.go
|
||||
|
||||
@@ -3,7 +3,9 @@ package network
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -177,3 +179,50 @@ func HasNetworkConfig(appName string) bool {
|
||||
|
||||
return common.FileExists(ipfile) && common.FileExists(portfile)
|
||||
}
|
||||
|
||||
// ReportSingleApp is an internal function that displays the app report for one or more apps
|
||||
func ReportSingleApp(appName, infoFlag string) {
|
||||
if err := common.VerifyAppName(appName); err != nil {
|
||||
common.LogFail(err.Error())
|
||||
}
|
||||
|
||||
infoFlags := map[string]string{
|
||||
"--network-bind-all-interfaces": common.PropertyGet("network", appName, "bind-all-interfaces"),
|
||||
"--network-listeners": strings.Join(GetListeners(appName), " "),
|
||||
}
|
||||
|
||||
if len(infoFlag) == 0 {
|
||||
common.LogInfo2Quiet(fmt.Sprintf("%s network information", appName))
|
||||
for k, v := range infoFlags {
|
||||
key := common.UcFirst(strings.Replace(strings.TrimPrefix(k, "--"), "-", " ", -1))
|
||||
common.LogVerbose(fmt.Sprintf("%s%s", Right(fmt.Sprintf("%s:", key), 31, " "), v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range infoFlags {
|
||||
if infoFlag == k {
|
||||
fmt.Fprintln(os.Stdout, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
keys := reflect.ValueOf(infoFlags).MapKeys()
|
||||
strkeys := make([]string, len(keys))
|
||||
for i := 0; i < len(keys); i++ {
|
||||
strkeys[i] = keys[i].String()
|
||||
}
|
||||
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
|
||||
}
|
||||
|
||||
func times(str string, n int) (out string) {
|
||||
for i := 0; i < n; i++ {
|
||||
out += str
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Right right-pads the string with pad up to len runes
|
||||
func Right(str string, length int, pad string) string {
|
||||
return str + times(pad, length-len(str))
|
||||
}
|
||||
|
||||
@@ -2,45 +2,12 @@ package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/dokku/dokku/plugins/common"
|
||||
"github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
func reportSingleApp(appName, infoFlag string) {
|
||||
infoFlags := map[string]string{
|
||||
"--network-bind-all-interfaces": common.PropertyGet("network", appName, "bind-all-interfaces"),
|
||||
"--network-listeners": strings.Join(network.GetListeners(appName), " "),
|
||||
}
|
||||
|
||||
if len(infoFlag) == 0 {
|
||||
common.LogInfo2Quiet(fmt.Sprintf("%s network information", appName))
|
||||
for k, v := range infoFlags {
|
||||
key := common.UcFirst(strings.Replace(strings.TrimPrefix(k, "--"), "-", " ", -1))
|
||||
common.LogVerbose(fmt.Sprintf("%s: %s", key, v))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
for k, v := range infoFlags {
|
||||
if infoFlag == k {
|
||||
fmt.Fprintln(os.Stdout, v)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
keys := reflect.ValueOf(infoFlags).MapKeys()
|
||||
strkeys := make([]string, len(keys))
|
||||
for i := 0; i < len(keys); i++ {
|
||||
strkeys[i] = keys[i].String()
|
||||
}
|
||||
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
|
||||
}
|
||||
|
||||
// displays a network report for one or more apps
|
||||
func main() {
|
||||
flag.Parse()
|
||||
@@ -58,10 +25,10 @@ func main() {
|
||||
return
|
||||
}
|
||||
for _, appName := range apps {
|
||||
reportSingleApp(appName, infoFlag)
|
||||
network.ReportSingleApp(appName, infoFlag)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
reportSingleApp(appName, infoFlag)
|
||||
network.ReportSingleApp(appName, infoFlag)
|
||||
}
|
||||
|
||||
15
plugins/network/src/triggers/report/report.go
Normal file
15
plugins/network/src/triggers/report/report.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"github.com/dokku/dokku/plugins/network"
|
||||
)
|
||||
|
||||
// displays a network report for one or more apps
|
||||
func main() {
|
||||
flag.Parse()
|
||||
appName := flag.Arg(0)
|
||||
|
||||
network.ReportSingleApp(appName, "")
|
||||
}
|
||||
Reference in New Issue
Block a user