diff options
| author | Paul Bütow <pbuetow@mimecast.com> | 2020-01-20 18:41:05 +0000 |
|---|---|---|
| committer | Paul Bütow <pbuetow@mimecast.com> | 2020-01-21 14:35:23 +0000 |
| commit | c128865c4c7411c29a59fca9a3a2f95537686d7b (patch) | |
| tree | 193bccc70d942c8b70cc93fae2670263701e43aa | |
| parent | 3755a9911ecb05886577095f2b8cc8b9e4066a3a (diff) | |
Move commands to cmd/ and move internal dependencies to internal/
| -rw-r--r-- | Makefile | 22 | ||||
| -rw-r--r-- | clients/args.go | 26 | ||||
| -rw-r--r-- | cmd/dcat/main.go | 80 | ||||
| -rw-r--r-- | cmd/dgrep/main.go | 83 | ||||
| -rw-r--r-- | cmd/dmap/main.go | 85 | ||||
| -rw-r--r-- | cmd/dserver/main.go | 69 | ||||
| -rw-r--r-- | cmd/dtail/main.go | 108 | ||||
| -rw-r--r-- | doc/quickstart.md | 14 | ||||
| -rw-r--r-- | go.mod | 2 | ||||
| -rw-r--r-- | internal/clients/args.go | 18 | ||||
| -rw-r--r-- | internal/clients/baseclient.go (renamed from clients/baseclient.go) | 24 | ||||
| -rw-r--r-- | internal/clients/catclient.go (renamed from clients/catclient.go) | 12 | ||||
| -rw-r--r-- | internal/clients/client.go (renamed from clients/client.go) | 4 | ||||
| -rw-r--r-- | internal/clients/connectionmaker.go (renamed from clients/connectionmaker.go) | 4 | ||||
| -rw-r--r-- | internal/clients/grepclient.go (renamed from clients/grepclient.go) | 12 | ||||
| -rw-r--r-- | internal/clients/handlers/basehandler.go (renamed from clients/handlers/basehandler.go) | 2 | ||||
| -rw-r--r-- | internal/clients/handlers/clienthandler.go (renamed from clients/handlers/clienthandler.go) | 2 | ||||
| -rw-r--r-- | internal/clients/handlers/handler.go (renamed from clients/handlers/handler.go) | 0 | ||||
| -rw-r--r-- | internal/clients/handlers/healthhandler.go (renamed from clients/handlers/healthhandler.go) | 0 | ||||
| -rw-r--r-- | internal/clients/handlers/maprhandler.go (renamed from clients/handlers/maprhandler.go) | 6 | ||||
| -rw-r--r-- | internal/clients/healthclient.go (renamed from clients/healthclient.go) | 13 | ||||
| -rw-r--r-- | internal/clients/maprclient.go (renamed from clients/maprclient.go) | 23 | ||||
| -rw-r--r-- | internal/clients/remote/connection.go (renamed from clients/remote/connection.go) | 8 | ||||
| -rw-r--r-- | internal/clients/stats.go (renamed from clients/stats.go) | 2 | ||||
| -rw-r--r-- | internal/clients/tailclient.go (renamed from clients/tailclient.go) | 13 | ||||
| -rw-r--r-- | internal/color/color.go (renamed from color/color.go) | 5 | ||||
| -rw-r--r-- | internal/color/colorfy.go (renamed from color/colorfy.go) | 0 | ||||
| -rw-r--r-- | internal/config/client.go (renamed from config/client.go) | 0 | ||||
| -rw-r--r-- | internal/config/common.go (renamed from config/common.go) | 0 | ||||
| -rw-r--r-- | internal/config/config.go (renamed from config/config.go) | 27 | ||||
| -rw-r--r-- | internal/config/read.go | 37 | ||||
| -rw-r--r-- | internal/config/server.go (renamed from config/server.go) | 0 | ||||
| -rw-r--r-- | internal/discovery/comma.go (renamed from discovery/comma.go) | 2 | ||||
| -rw-r--r-- | internal/discovery/discovery.go (renamed from discovery/discovery.go) | 2 | ||||
| -rw-r--r-- | internal/discovery/file.go (renamed from discovery/file.go) | 2 | ||||
| -rw-r--r-- | internal/fs/catfile.go (renamed from fs/catfile.go) | 0 | ||||
| -rw-r--r-- | internal/fs/filereader.go (renamed from fs/filereader.go) | 0 | ||||
| -rw-r--r-- | internal/fs/lineread.go (renamed from fs/lineread.go) | 0 | ||||
| -rw-r--r-- | internal/fs/permissions/permission.go (renamed from fs/permissions/permission.go) | 2 | ||||
| -rw-r--r-- | internal/fs/permissions/permission_linux.c (renamed from fs/permissions/permission_linux.c) | 0 | ||||
| -rw-r--r-- | internal/fs/permissions/permission_linux.go (renamed from fs/permissions/permission_linux.go) | 0 | ||||
| -rw-r--r-- | internal/fs/permissions/permission_linux.h (renamed from fs/permissions/permission_linux.h) | 0 | ||||
| -rw-r--r-- | internal/fs/permissions/permission_test.go (renamed from fs/permissions/permission_test.go) | 0 | ||||
| -rw-r--r-- | internal/fs/readfile.go (renamed from fs/readfile.go) | 2 | ||||
| -rw-r--r-- | internal/fs/stats.go (renamed from fs/stats.go) | 0 | ||||
| -rw-r--r-- | internal/fs/tailfile.go (renamed from fs/tailfile.go) | 0 | ||||
| -rw-r--r-- | internal/logger/logger.go (renamed from logger/logger.go) | 42 | ||||
| -rw-r--r-- | internal/mapr/aggregateset.go (renamed from mapr/aggregateset.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/client/aggregate.go (renamed from mapr/client/aggregate.go) | 4 | ||||
| -rw-r--r-- | internal/mapr/globalgroupset.go (renamed from mapr/globalgroupset.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/groupset.go (renamed from mapr/groupset.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/logformat/default.go (renamed from mapr/logformat/default.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/logformat/default_test.go (renamed from mapr/logformat/default_test.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/logformat/parser.go (renamed from mapr/logformat/parser.go) | 2 | ||||
| -rw-r--r-- | internal/mapr/query.go (renamed from mapr/query.go) | 2 | ||||
| -rw-r--r-- | internal/mapr/query_test.go (renamed from mapr/query_test.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/selectcondition.go (renamed from mapr/selectcondition.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/server/aggregate.go (renamed from mapr/server/aggregate.go) | 10 | ||||
| -rw-r--r-- | internal/mapr/token.go (renamed from mapr/token.go) | 0 | ||||
| -rw-r--r-- | internal/mapr/wherecondition.go (renamed from mapr/wherecondition.go) | 2 | ||||
| -rw-r--r-- | internal/omode/mode.go (renamed from omode/mode.go) | 0 | ||||
| -rw-r--r-- | internal/pprof/pprof.go | 17 | ||||
| -rw-r--r-- | internal/prompt/prompt.go (renamed from prompt/prompt.go) | 2 | ||||
| -rw-r--r-- | internal/server/handlers/controlhandler.go (renamed from server/handlers/controlhandler.go) | 5 | ||||
| -rw-r--r-- | internal/server/handlers/handler.go (renamed from server/handlers/handler.go) | 0 | ||||
| -rw-r--r-- | internal/server/handlers/serverhandler.go (renamed from server/handlers/serverhandler.go) | 15 | ||||
| -rw-r--r-- | internal/server/server.go (renamed from server/server.go) | 17 | ||||
| -rw-r--r-- | internal/server/stats.go (renamed from server/stats.go) | 4 | ||||
| -rw-r--r-- | internal/ssh/client/authmethods.go (renamed from ssh/client/authmethods.go) | 6 | ||||
| -rw-r--r-- | internal/ssh/client/hostkeycallback.go (renamed from ssh/client/hostkeycallback.go) | 4 | ||||
| -rw-r--r-- | internal/ssh/server/hostkey.go (renamed from ssh/server/hostkey.go) | 6 | ||||
| -rw-r--r-- | internal/ssh/server/publickeycallback.go (renamed from ssh/server/publickeycallback.go) | 7 | ||||
| -rw-r--r-- | internal/ssh/ssh.go (renamed from ssh/ssh.go) | 2 | ||||
| -rw-r--r-- | internal/user/name.go | 24 | ||||
| -rw-r--r-- | internal/user/server/user.go (renamed from server/user/user.go) | 8 | ||||
| -rw-r--r-- | internal/version/version.go (renamed from version/version.go) | 14 | ||||
| -rw-r--r-- | main.go | 250 |
77 files changed, 705 insertions, 449 deletions
@@ -2,19 +2,19 @@ GO ?= go all: build build: ${GO} version - ${GO} build - cp -pv ./dtail ./dcat - cp -pv ./dtail ./dgrep - cp -pv ./dtail ./dmap - cp -pv ./dtail ./dserver + ${GO} build -o dtail ./cmd/dtail/main.go + ${GO} build -o dcat ./cmd/dcat/main.go + ${GO} build -o dgrep ./cmd/dgrep/main.go + ${GO} build -o dmap ./cmd/dmap/main.go + ${GO} build -o dserver ./cmd/dserver/main.go clean: rm -v dtail dgrep dcat dmap dserver 2>/dev/null -install: - ${GO} install - cp -pv ${GOPATH}/bin/dtail ${GOPATH}/bin/dcat - cp -pv ${GOPATH}/bin/dtail ${GOPATH}/bin/dgrep - cp -pv ${GOPATH}/bin/dtail ${GOPATH}/bin/dmap - cp -pv ${GOPATH}/bin/dtail ${GOPATH}/bin/dserver +install: build + cp -pv dtail ${GOPATH}/bin/dtail + cp -pv dcat ${GOPATH}/bin/dcat + cp -pv dgrep ${GOPATH}/bin/dgrep + cp -pv dmap ${GOPATH}/bin/dmap + cp -pv dserver ${GOPATH}/bin/dserver vet: find . -type d | while read dir; do \ echo ${GO} vet $$dir; \ diff --git a/clients/args.go b/clients/args.go deleted file mode 100644 index 4d5a029..0000000 --- a/clients/args.go +++ /dev/null @@ -1,26 +0,0 @@ -package clients - -import ( - "dtail/omode" -) - -// Args is a helper struct to summarize common client arguments. -type Args struct { - // The operating mode (tail, grep, ...) - Mode omode.Mode - // The raw server string - ServersStr string - // SSH user name (e.g. 'pbuetow') - UserName string - // The files to follow. - Files string - // Regex for filtering. - Regex string - // Trust all unknown host keys? - TrustAllHosts bool - // Server discovery method - Discovery string - MaxInitConnections int - // Server ping timeout (0 means pings disabled) - PingTimeout int -} diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go new file mode 100644 index 0000000..b02d369 --- /dev/null +++ b/cmd/dcat/main.go @@ -0,0 +1,80 @@ +package main + +import ( + "flag" + + "github.com/mimecast/dtail/internal/clients" + "github.com/mimecast/dtail/internal/color" + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/logger" + "github.com/mimecast/dtail/internal/pprof" + "github.com/mimecast/dtail/internal/user" + "github.com/mimecast/dtail/internal/version" +) + +// The evil begins here. +func main() { + var cfgFile string + var connectionsPerCPU int + var debugEnable bool + var discovery string + var displayVersion bool + var files string + var noColor bool + var pprofEnable bool + var serversStr string + var silentEnable bool + var sshPort int + var trustAllHosts bool + + pingTimeoutS := 60 + userName := user.Name() + + flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages") + flag.BoolVar(&displayVersion, "version", false, "Display version") + flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors") + flag.BoolVar(&pprofEnable, "pprofEnable", false, "Enable pprof server") + flag.BoolVar(&silentEnable, "silent", false, "Reduce output") + flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys") + flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently") + flag.IntVar(&pingTimeoutS, "pingTimeout", 10, "The server ping timeout (0 means disable pings)") + flag.IntVar(&sshPort, "port", 2222, "SSH server port") + flag.StringVar(&cfgFile, "cfg", "", "Config file path") + flag.StringVar(&discovery, "discovery", "", "Server discovery method") + flag.StringVar(&files, "files", "", "File(s) to read") + flag.StringVar(&serversStr, "servers", "", "Remote servers to connect") + flag.StringVar(&userName, "user", userName, "Your system user name") + + flag.Parse() + + config.Read(cfgFile, sshPort) + color.Colored = !noColor + + if displayVersion { + version.PrintAndExit() + } + + serverEnable := false + logger.Start(serverEnable, debugEnable, silentEnable, silentEnable) + defer logger.Stop() + + if pprofEnable || config.Common.PProfEnable { + pprof.Start() + } + + args := clients.Args{ + ConnectionsPerCPU: connectionsPerCPU, + ServersStr: serversStr, + Discovery: discovery, + UserName: userName, + Files: files, + TrustAllHosts: trustAllHosts, + PingTimeout: pingTimeoutS, + } + + client, err := clients.NewCatClient(args) + if err != nil { + panic(err) + } + client.Start() +} diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go new file mode 100644 index 0000000..d1a7d52 --- /dev/null +++ b/cmd/dgrep/main.go @@ -0,0 +1,83 @@ +package main + +import ( + "flag" + + "github.com/mimecast/dtail/internal/clients" + "github.com/mimecast/dtail/internal/color" + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/logger" + "github.com/mimecast/dtail/internal/pprof" + "github.com/mimecast/dtail/internal/user" + "github.com/mimecast/dtail/internal/version" +) + +// The evil begins here. +func main() { + var cfgFile string + var connectionsPerCPU int + var debugEnable bool + var discovery string + var displayVersion bool + var files string + var noColor bool + var pprofEnable bool + var regex string + var serversStr string + var silentEnable bool + var sshPort int + var trustAllHosts bool + + pingTimeoutS := 60 + userName := user.Name() + + flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages") + flag.BoolVar(&displayVersion, "version", false, "Display version") + flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors") + flag.BoolVar(&pprofEnable, "pprofEnable", false, "Enable pprof server") + flag.BoolVar(&silentEnable, "silent", false, "Reduce output") + flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys") + flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently") + flag.IntVar(&pingTimeoutS, "pingTimeout", 10, "The server ping timeout (0 means disable pings)") + flag.IntVar(&sshPort, "port", 2222, "SSH server port") + flag.StringVar(&cfgFile, "cfg", "", "Config file path") + flag.StringVar(&discovery, "discovery", "", "Server discovery method") + flag.StringVar(&files, "files", "", "File(s) to read") + flag.StringVar(®ex, "regex", ".", "Regular expression") + flag.StringVar(&serversStr, "servers", "", "Remote servers to connect") + flag.StringVar(&userName, "user", userName, "Your system user name") + + flag.Parse() + + config.Read(cfgFile, sshPort) + color.Colored = !noColor + + if displayVersion { + version.PrintAndExit() + } + + serverEnable := false + logger.Start(serverEnable, debugEnable, silentEnable, silentEnable) + defer logger.Stop() + + if pprofEnable || config.Common.PProfEnable { + pprof.Start() + } + + args := clients.Args{ + ConnectionsPerCPU: connectionsPerCPU, + ServersStr: serversStr, + Discovery: discovery, + UserName: userName, + Files: files, + TrustAllHosts: trustAllHosts, + PingTimeout: pingTimeoutS, + Regex: regex, + } + + client, err := clients.NewGrepClient(args) + if err != nil { + panic(err) + } + client.Start() +} diff --git a/cmd/dmap/main.go b/cmd/dmap/main.go new file mode 100644 index 0000000..83dad50 --- /dev/null +++ b/cmd/dmap/main.go @@ -0,0 +1,85 @@ +package main + +import ( + "flag" + + "github.com/mimecast/dtail/internal/omode" + "github.com/mimecast/dtail/internal/clients" + "github.com/mimecast/dtail/internal/color" + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/logger" + "github.com/mimecast/dtail/internal/pprof" + "github.com/mimecast/dtail/internal/user" + "github.com/mimecast/dtail/internal/version" +) + +// The evil begins here. +func main() { + var cfgFile string + var connectionsPerCPU int + var debugEnable bool + var discovery string + var displayVersion bool + var files string + var noColor bool + var pprofEnable bool + var queryStr string + var serversStr string + var silentEnable bool + var sshPort int + var trustAllHosts bool + + pingTimeoutS := 900 + userName := user.Name() + + flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages") + flag.BoolVar(&displayVersion, "version", false, "Display version") + flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors") + flag.BoolVar(&pprofEnable, "pprofEnable", false, "Enable pprof server") + flag.BoolVar(&silentEnable, "silent", false, "Reduce output") + flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys") + flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently") + flag.IntVar(&pingTimeoutS, "pingTimeout", 10, "The server ping timeout (0 means disable pings)") + flag.IntVar(&sshPort, "port", 2222, "SSH server port") + flag.StringVar(&cfgFile, "cfg", "", "Config file path") + flag.StringVar(&discovery, "discovery", "", "Server discovery method") + flag.StringVar(&files, "files", "", "File(s) to read") + flag.StringVar(&queryStr, "query", "", "Map reduce query") + flag.StringVar(&serversStr, "servers", "", "Remote servers to connect") + flag.StringVar(&userName, "user", userName, "Your system user name") + + flag.Parse() + + config.Read(cfgFile, sshPort) + color.Colored = !noColor + + if displayVersion { + version.PrintAndExit() + } + + serverEnable := false + logger.Start(serverEnable, debugEnable, silentEnable, silentEnable) + defer logger.Stop() + + if pprofEnable || config.Common.PProfEnable { + pprof.Start() + } + + args := clients.Args{ + ConnectionsPerCPU: connectionsPerCPU, + ServersStr: serversStr, + Discovery: discovery, + UserName: userName, + Files: files, + TrustAllHosts: trustAllHosts, + PingTimeout: pingTimeoutS, + Mode: omode.MapClient, + } + + client, err := clients.NewMaprClient(args, queryStr) + if err != nil { + panic(err) + } + + client.Start() +} diff --git a/cmd/dserver/main.go b/cmd/dserver/main.go new file mode 100644 index 0000000..489910b --- /dev/null +++ b/cmd/dserver/main.go @@ -0,0 +1,69 @@ +package main + +import ( + "flag" + "os" + "time" + + "github.com/mimecast/dtail/internal/color" + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/logger" + "github.com/mimecast/dtail/internal/pprof" + "github.com/mimecast/dtail/internal/server" + "github.com/mimecast/dtail/internal/user" + "github.com/mimecast/dtail/internal/version" +) + +// The evil begins here. +func main() { + var cfgFile string + var debugEnable bool + var displayVersion bool + var noColor bool + var pprofEnable bool + var shutdownAfter int + var sshPort int + + userName := user.Name() + + flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages") + flag.BoolVar(&displayVersion, "version", false, "Display version") + flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors") + flag.BoolVar(&pprofEnable, "pprofEnable", false, "Enable pprof server") + flag.IntVar(&shutdownAfter, "shutdownAfter", 0, "Automatically shutdown after so many seconds") + flag.IntVar(&sshPort, "port", 2222, "SSH server port") + flag.StringVar(&cfgFile, "cfg", "", "Config file path") + + flag.Parse() + + config.Read(cfgFile, sshPort) + color.Colored = !noColor + + if displayVersion { + version.PrintAndExit() + } + + serverEnable := true + silentEnable := false + nothingEnable := false + logger.Start(serverEnable, debugEnable, silentEnable, nothingEnable) + defer logger.Stop() + + if shutdownAfter > 0 { + go func() { + defer os.Exit(1) + + logger.Info("Enabling auto shutdown timer", shutdownAfter) + time.Sleep(time.Duration(shutdownAfter) * time.Second) + logger.Info("Auto shutdown timer reached, shutting down now") + }() + } + + if pprofEnable || config.Common.PProfEnable { + pprof.Start() + } + + logger.Info("Launching server", version.String(), userName) + sshServer := server.New() + sshServer.Start() +} diff --git a/cmd/dtail/main.go b/cmd/dtail/main.go new file mode 100644 index 0000000..1bf77c7 --- /dev/null +++ b/cmd/dtail/main.go @@ -0,0 +1,108 @@ +package main + +import ( + "flag" + "os" + + "github.com/mimecast/dtail/internal/clients" + "github.com/mimecast/dtail/internal/color" + "github.com/mimecast/dtail/internal/config" + "github.com/mimecast/dtail/internal/logger" + "github.com/mimecast/dtail/internal/omode" + "github.com/mimecast/dtail/internal/pprof" + "github.com/mimecast/dtail/internal/user" + "github.com/mimecast/dtail/internal/version" +) + +// The evil begins here. +func main() { + var cfgFile string + var checkHealth bool + var connectionsPerCPU int + var debugEnable bool + var discovery string + var displayVersion bool + var files string + var noColor bool + var pprofEnable bool + var queryStr string + var regex string + var serversStr string + var silentEnable bool + var sshPort int + var trustAllHosts bool + + pingTimeoutS := 5 + userName := user.Name() + + flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health") + flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages") + flag.BoolVar(&displayVersion, "version", false, "Display version") + flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors") + flag.BoolVar(&pprofEnable, "pprofEnable", false, "Enable pprof server") + flag.BoolVar(&silentEnable, "silent", false, "Reduce output") + flag.BoolVar(&trustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys") + flag.IntVar(&connectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently") + flag.IntVar(&pingTimeoutS, "pingTimeout", 10, "The server ping timeout (0 means disable pings)") + flag.IntVar(&sshPort, "port", 2222, "SSH server port") + flag.StringVar(&cfgFile, "cfg", "", "Config file path") + flag.StringVar(&discovery, "discovery", "", "Server discovery method") + flag.StringVar(&files, "files", "", "File(s) to read") + flag.StringVar(&queryStr, "query", "", "Map reduce query") + flag.StringVar(®ex, "regex", ".", "Regular expression") + flag.StringVar(&serversStr, "servers", "", "Remote servers to connect") + flag.StringVar(&userName, "user", userName, "Your system user name") + + flag.Parse() + + config.Read(cfgFile, sshPort) + color.Colored = !noColor + + if displayVersion { + version.PrintAndExit() + } + + if checkHealth { + healthClient, _ := clients.NewHealthClient(omode.HealthClient) + os.Exit(healthClient.Start()) + } + + serverEnable := false + if checkHealth { + silentEnable = true + } + logger.Start(serverEnable, debugEnable, silentEnable, silentEnable) + defer logger.Stop() + + if pprofEnable || config.Common.PProfEnable { + pprof.Start() + } + + args := clients.Args{ + ConnectionsPerCPU: connect |
