summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Bütow <pbuetow@mimecast.com>2020-01-20 18:41:05 +0000
committerPaul Bütow <pbuetow@mimecast.com>2020-01-21 14:35:23 +0000
commitc128865c4c7411c29a59fca9a3a2f95537686d7b (patch)
tree193bccc70d942c8b70cc93fae2670263701e43aa
parent3755a9911ecb05886577095f2b8cc8b9e4066a3a (diff)
Move commands to cmd/ and move internal dependencies to internal/
-rw-r--r--Makefile22
-rw-r--r--clients/args.go26
-rw-r--r--cmd/dcat/main.go80
-rw-r--r--cmd/dgrep/main.go83
-rw-r--r--cmd/dmap/main.go85
-rw-r--r--cmd/dserver/main.go69
-rw-r--r--cmd/dtail/main.go108
-rw-r--r--doc/quickstart.md14
-rw-r--r--go.mod2
-rw-r--r--internal/clients/args.go18
-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.go37
-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.go17
-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.go24
-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.go250
77 files changed, 705 insertions, 449 deletions
diff --git a/Makefile b/Makefile
index 3d24800..456987d 100644
--- a/Makefile
+++ b/Makefile
@@ -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(&regex, "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(&regex, "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: connectionsPerCPU,
+ ServersStr: serversStr,
+ Discovery: discovery,
+ UserName: userName,
+ Files: files,
+ TrustAllHosts: trustAllHosts,
+ PingTimeout: pingTimeoutS,
+ Regex: regex,
+ Mode: omode.TailClient,
+ }
+
+ var client clients.Client
+ var err error
+
+ switch queryStr {
+ case "":
+ if client, err = clients.NewTailClient(args); err != nil {
+ panic(err)
+ }
+ default:
+ if client, err = clients.NewMaprClient(args, queryStr); err != nil {
+ panic(err)
+ }
+ }
+
+ client.Start()
+}
diff --git a/doc/quickstart.md b/doc/quickstart.md
index 57432c0..daaca35 100644
--- a/doc/quickstart.md
+++ b/doc/quickstart.md
@@ -13,15 +13,11 @@ To produce all DTail binaries run ``make``:
```console
workstation01 ~/git/dtail % make
-go build
-cp -pv ./dtail ./dcat
-./dtail -> ./dcat
-cp -pv ./dtail ./dgrep
-./dtail -> ./dgrep
-cp -pv ./dtail ./dmap
-./dtail -> ./dmap
-cp -pv ./dtail ./dserver
-./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
```
It produces the following executables:
diff --git a/go.mod b/go.mod
index 74685b3..bba791a 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module dtail
+module github.com/mimecast/dtail
go 1.13
diff --git a/internal/clients/args.go b/internal/clients/args.go
new file mode 100644
index 0000000..5fe0a72
--- /dev/null
+++ b/internal/clients/args.go
@@ -0,0 +1,18 @@
+package clients
+
+import (
+ "github.com/mimecast/dtail/internal/omode"
+)
+
+// Args is a helper struct to summarize common client arguments.
+type Args struct {
+ Mode omode.Mode
+ ServersStr string
+ UserName string
+ Files string
+ Regex string
+ TrustAllHosts bool
+ Discovery string
+ ConnectionsPerCPU int
+ PingTimeout int
+}
diff --git a/clients/baseclient.go b/internal/clients/baseclient.go
index 3a1b8f0..574ae94 100644
--- a/clients/baseclient.go
+++ b/internal/clients/baseclient.go
@@ -1,15 +1,16 @@
package clients
import (
- "dtail/clients/remote"
- "dtail/discovery"
- "dtail/logger"
- "dtail/omode"
- "dtail/ssh/client"
"regexp"
"sync"
"time"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/discovery"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/ssh/client"
+
gossh "golang.org/x/crypto/ssh"
)
@@ -64,14 +65,11 @@ func (c *baseClient) init(maker connectionMaker) {
go c.stats.periodicLogStats(c.throttleCh, c.stop)
}
-func (c *baseClient) Start(wg *sync.WaitGroup) (status int) {
- if wg != nil {
- defer wg.Done()
- }
+func (c *baseClient) Start() (status int) {
active := make(chan struct{}, len(c.connections))
- var wg2 sync.WaitGroup
- wg2.Add(len(c.connections))
+ var wg sync.WaitGroup
+ wg.Add(len(c.connections))
for i, conn := range c.connections {
go func(i int, conn *remote.Connection) {
@@ -80,7 +78,7 @@ func (c *baseClient) Start(wg *sync.WaitGroup) (status int) {
logger.Debug(conn.Server, "Disconnected completely...")
<-active
}()
- wg2.Done()
+ wg.Done()
for {
conn.Start(c.throttleCh, c.stats.connectionsEstCh)
@@ -95,7 +93,7 @@ func (c *baseClient) Start(wg *sync.WaitGroup) (status int) {
}(i, conn)
}
- wg2.Wait()
+ wg.Wait()
c.waitUntilDone(active)
return
diff --git a/clients/catclient.go b/internal/clients/catclient.go
index e3b873c..5ea701d 100644
--- a/clients/catclient.go
+++ b/internal/clients/catclient.go
@@ -1,13 +1,16 @@
package clients
import (
- "dtail/clients/handlers"
- "dtail/clients/remote"
- "dtail/ssh/client"
"errors"
"fmt"
+ "runtime"
"strings"
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/ssh/client"
+
gossh "golang.org/x/crypto/ssh"
)
@@ -23,13 +26,14 @@ func NewCatClient(args Args) (*CatClient, error) {
}
args.Regex = "."
+ args.Mode = omode.CatClient
c := CatClient{
baseClient: baseClient{
Args: args,
stop: make(chan struct{}),
stopped: make(chan struct{}),
- throttleCh: make(chan struct{}, args.MaxInitConnections),
+ throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
retry: false,
},
}
diff --git a/clients/client.go b/internal/clients/client.go
index e58f51d..85d1aae 100644
--- a/clients/client.go
+++ b/internal/clients/client.go
@@ -1,9 +1,7 @@
package clients
-import "sync"
-
// Client is the interface for the end user command line client.
type Client interface {
- Start(wg *sync.WaitGroup) int
+ Start() int
Stop()
}
diff --git a/clients/connectionmaker.go b/internal/clients/connectionmaker.go
index 9e08c2b..0617992 100644
--- a/clients/connectionmaker.go
+++ b/internal/clients/connectionmaker.go
@@ -1,8 +1,8 @@
package clients
import (
- "dtail/clients/remote"
- "dtail/ssh/client"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/ssh/client"
gossh "golang.org/x/crypto/ssh"
)
diff --git a/clients/grepclient.go b/internal/clients/grepclient.go
index dbae96c..c568f63 100644
--- a/clients/grepclient.go
+++ b/internal/clients/grepclient.go
@@ -1,13 +1,16 @@
package clients
import (
- "dtail/clients/handlers"
- "dtail/clients/remote"
- "dtail/ssh/client"
"errors"
"fmt"
+ "runtime"
"strings"
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/ssh/client"
+
gossh "golang.org/x/crypto/ssh"
)
@@ -21,13 +24,14 @@ func NewGrepClient(args Args) (*GrepClient, error) {
if args.Regex == "" {
return nil, errors.New("No regex specified, use '-regex' flag")
}
+ args.Mode = omode.GrepClient
c := GrepClient{
baseClient: baseClient{
Args: args,
stop: make(chan struct{}),
stopped: make(chan struct{}),
- throttleCh: make(chan struct{}, args.MaxInitConnections),
+ throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
retry: false,
},
}
diff --git a/clients/handlers/basehandler.go b/internal/clients/handlers/basehandler.go
index ce82aa2..19246f9 100644
--- a/clients/handlers/basehandler.go
+++ b/internal/clients/handlers/basehandler.go
@@ -1,7 +1,7 @@
package handlers
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"errors"
"fmt"
"io"
diff --git a/clients/handlers/clienthandler.go b/internal/clients/handlers/clienthandler.go
index e818b52..4738cd3 100644
--- a/clients/handlers/clienthandler.go
+++ b/internal/clients/handlers/clienthandler.go
@@ -1,7 +1,7 @@
package handlers
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
)
// ClientHandler is the basic client handler interface.
diff --git a/clients/handlers/handler.go b/internal/clients/handlers/handler.go
index 2013be0..2013be0 100644
--- a/clients/handlers/handler.go
+++ b/internal/clients/handlers/handler.go
diff --git a/clients/handlers/healthhandler.go b/internal/clients/handlers/healthhandler.go
index 4051e2c..4051e2c 100644
--- a/clients/handlers/healthhandler.go
+++ b/internal/clients/handlers/healthhandler.go
diff --git a/clients/handlers/maprhandler.go b/internal/clients/handlers/maprhandler.go
index 830a142..d76cdfd 100644
--- a/clients/handlers/maprhandler.go
+++ b/internal/clients/handlers/maprhandler.go
@@ -1,9 +1,9 @@
package handlers
import (
- "dtail/logger"
- "dtail/mapr"
- "dtail/mapr/client"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/mapr"
+ "github.com/mimecast/dtail/internal/mapr/client"
"strings"
)
diff --git a/clients/healthclient.go b/internal/clients/healthclient.go
index 1fae99c..ff13b83 100644
--- a/clients/healthclient.go
+++ b/internal/clients/healthclient.go
@@ -1,16 +1,16 @@
package clients
import (
- "dtail/clients/handlers"
- "dtail/clients/remote"
- "dtail/config"
- "dtail/omode"
"fmt"
"runtime"
"strings"
- "sync"
"time"
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/omode"
+
gossh "golang.org/x/crypto/ssh"
)
@@ -39,8 +39,7 @@ func NewHealthClient(mode omode.Mode) (*HealthClient, error) {
}
// Start the health client.
-func (c *HealthClient) Start(wg *sync.WaitGroup) (status int) {
- defer wg.Done()
+func (c *HealthClient) Start() (status int) {
receive := make(chan string)
throttleCh := make(chan struct{}, runtime.NumCPU())
diff --git a/clients/maprclient.go b/internal/clients/maprclient.go
index ad707c9..9070827 100644
--- a/clients/maprclient.go
+++ b/internal/clients/maprclient.go
@@ -1,18 +1,19 @@
package clients
import (
- "dtail/clients/handlers"
- "dtail/clients/remote"
- "dtail/logger"
- "dtail/mapr"
- "dtail/omode"
- "dtail/ssh/client"
"errors"
"fmt"
+ "runtime"
"strings"
- "sync"
"time"
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/mapr"
+ "github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/ssh/client"
+
gossh "golang.org/x/crypto/ssh"
)
@@ -40,7 +41,7 @@ func NewMaprClient(args Args, queryStr string) (*MaprClient, error) {
Args: args,
stop: make(chan struct{}),
stopped: make(chan struct{}),
- throttleCh: make(chan struct{}, args.MaxInitConnections),
+ throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
retry: args.Mode == omode.TailClient,
},
queryStr: queryStr,
@@ -87,15 +88,13 @@ func (c MaprClient) makeConnection(server string, sshAuthMethods []gossh.AuthMet
}
// Start starts the mapreduce client.
-func (c *MaprClient) Start(wg *sync.WaitGroup) (status int) {
- defer wg.Done()
-
+func (c *MaprClient) Start() (status int) {
if c.query.Outfile == "" {
// Only print out periodic results if we don't write an outfile
go c.periodicPrintResults()
}
- status = c.baseClient.Start(nil)
+ status = c.baseClient.Start()
if c.additative {
c.recievedFinalResult()
}
diff --git a/clients/remote/connection.go b/internal/clients/remote/connection.go
index bd93239..bfc7bc5 100644
--- a/clients/remote/connection.go
+++ b/internal/clients/remote/connection.go
@@ -1,10 +1,10 @@
package remote
import (
- "dtail/clients/handlers"
- "dtail/config"
- "dtail/logger"
- "dtail/ssh/client"
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/ssh/client"
"fmt"
"io"
"strconv"
diff --git a/clients/stats.go b/internal/clients/stats.go
index e5b9bed..d36cef6 100644
--- a/clients/stats.go
+++ b/internal/clients/stats.go
@@ -1,7 +1,7 @@
package clients
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"fmt"
"runtime"
"sync"
diff --git a/clients/tailclient.go b/internal/clients/tailclient.go
index cb93258..674ca36 100644
--- a/clients/tailclient.go
+++ b/internal/clients/tailclient.go
@@ -1,12 +1,15 @@
package clients
import (
- "dtail/clients/handlers"
- "dtail/clients/remote"
- "dtail/ssh/client"
"fmt"
+ "runtime"
"strings"
+ "github.com/mimecast/dtail/internal/clients/handlers"
+ "github.com/mimecast/dtail/internal/clients/remote"
+ "github.com/mimecast/dtail/internal/omode"
+ "github.com/mimecast/dtail/internal/ssh/client"
+
gossh "golang.org/x/crypto/ssh"
)
@@ -17,12 +20,14 @@ type TailClient struct {
// NewTailClient returns a new TailClient.
func NewTailClient(args Args) (*TailClient, error) {
+ args.Mode = omode.TailClient
+
c := TailClient{
baseClient: baseClient{
Args: args,
stop: make(chan struct{}),
stopped: make(chan struct{}),
- throttleCh: make(chan struct{}, args.MaxInitConnections),
+ throttleCh: make(chan struct{}, args.ConnectionsPerCPU*runtime.NumCPU()),
retry: true,
},
}
diff --git a/color/color.go b/internal/color/color.go
index 64e0d7f..0736199 100644
--- a/color/color.go
+++ b/internal/color/color.go
@@ -51,11 +51,6 @@ const (
// Colored DTail client output enabled.
var Colored bool
-// Init whether we want colored output or not.
-func Init(colored bool) {
- Colored = colored
-}
-
// Paint a given string in a given color.
func Paint(c Color, s string) string {
return fmt.Sprintf(seq, c, s, reset)
diff --git a/color/colorfy.go b/internal/color/colorfy.go
index 9ae46f5..9ae46f5 100644
--- a/color/colorfy.go
+++ b/internal/color/colorfy.go
diff --git a/config/client.go b/internal/config/client.go
index 1515aae..1515aae 100644
--- a/config/client.go
+++ b/internal/config/client.go
diff --git a/config/common.go b/internal/config/common.go
index 8c07710..8c07710 100644
--- a/config/common.go
+++ b/internal/config/common.go
diff --git a/config/config.go b/internal/config/config.go
index 5463c5f..0f26635 100644
--- a/config/config.go
+++ b/internal/config/config.go
@@ -43,30 +43,3 @@ func (c *configInitializer) parseConfig(configFile string) {
panic(err)
}
}
-
-// Init the DTail configuration.
-func Init(configFile string) {
- initializer := configInitializer{
- Common: newDefaultCommonConfig(),
- Server: newDefaultServerConfig(),
- Client: newDefaultClientConfig(),
- }
-
- if configFile == "" {
- configFile = "./cfg/dtail.json"
- }
-
- if _, err := os.Stat(configFile); !os.IsNotExist(err) {
- initializer.parseConfig(configFile)
- }
-
- // Assign pointers to global variables, so that we can access the
- // configuration from any place of the program.
- Common = initializer.Common
- Server = initializer.Server
- Client = initializer.Client
-
- if Server.MapreduceLogFormat == "" {
- Server.MapreduceLogFormat = "default"
- }
-}
diff --git a/internal/config/read.go b/internal/config/read.go
new file mode 100644
index 0000000..a4e605b
--- /dev/null
+++ b/internal/config/read.go
@@ -0,0 +1,37 @@
+package config
+
+import (
+ "os"
+)
+
+// Read the DTail configuration.
+func Read(configFile string, sshPort int) {
+ initializer := configInitializer{
+ Common: newDefaultCommonConfig(),
+ Server: newDefaultServerConfig(),
+ Client: newDefaultClientConfig(),
+ }
+
+ if configFile == "" {
+ configFile = "./cfg/dtail.json"
+ }
+
+ if _, err := os.Stat(configFile); !os.IsNotExist(err) {
+ initializer.parseConfig(configFile)
+ }
+
+ // Assign pointers to global variables, so that we can access the
+ // configuration from any place of the program.
+ Common = initializer.Common
+ Server = initializer.Server
+ Client = initializer.Client
+
+ if Server.MapreduceLogFormat == "" {
+ Server.MapreduceLogFormat = "default"
+ }
+
+ // If non-standard port specified, overwrite config
+ if sshPort != 2222 {
+ Common.SSHPort = sshPort
+ }
+}
diff --git a/config/server.go b/internal/config/server.go
index 7883b33..7883b33 100644
--- a/config/server.go
+++ b/internal/config/server.go
diff --git a/discovery/comma.go b/internal/discovery/comma.go
index c7c9d75..ad18be0 100644
--- a/discovery/comma.go
+++ b/internal/discovery/comma.go
@@ -1,7 +1,7 @@
package discovery
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"strings"
)
diff --git a/discovery/discovery.go b/internal/discovery/discovery.go
index 4150fd9..d76c1b2 100644
--- a/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -1,7 +1,7 @@
package discovery
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"fmt"
"math/rand"
"os"
diff --git a/discovery/file.go b/internal/discovery/file.go
index e02d6b4..2edc867 100644
--- a/discovery/file.go
+++ b/internal/discovery/file.go
@@ -2,7 +2,7 @@ package discovery
import (
"bufio"
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"os"
)
diff --git a/fs/catfile.go b/internal/fs/catfile.go
index 99f521f..99f521f 100644
--- a/fs/catfile.go
+++ b/internal/fs/catfile.go
diff --git a/fs/filereader.go b/internal/fs/filereader.go
index 5a08e27..5a08e27 100644
--- a/fs/filereader.go
+++ b/internal/fs/filereader.go
diff --git a/fs/lineread.go b/internal/fs/lineread.go
index 7ee558e..7ee558e 100644
--- a/fs/lineread.go
+++ b/internal/fs/lineread.go
diff --git a/fs/permissions/permission.go b/internal/fs/permissions/permission.go
index 7d242f1..6e83309 100644
--- a/fs/permissions/permission.go
+++ b/internal/fs/permissions/permission.go
@@ -3,7 +3,7 @@
package permissions
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
)
// ToRead is to check whether user has read permissions to a given file.
diff --git a/fs/permissions/permission_linux.c b/internal/fs/permissions/permission_linux.c
index cd10525..cd10525 100644
--- a/fs/permissions/permission_linux.c
+++ b/internal/fs/permissions/permission_linux.c
diff --git a/fs/permissions/permission_linux.go b/internal/fs/permissions/permission_linux.go
index feae729..feae729 100644
--- a/fs/permissions/permission_linux.go
+++ b/internal/fs/permissions/permission_linux.go
diff --git a/fs/permissions/permission_linux.h b/internal/fs/permissions/permission_linux.h
index a2c266e..a2c266e 100644
--- a/fs/permissions/permission_linux.h
+++ b/internal/fs/permissions/permission_linux.h
diff --git a/fs/permissions/permission_test.go b/internal/fs/permissions/permission_test.go
index d415ac2..d415ac2 100644
--- a/fs/permissions/permission_test.go
+++ b/internal/fs/permissions/permission_test.go
diff --git a/fs/readfile.go b/internal/fs/readfile.go
index 375378b..312447a 100644
--- a/fs/readfile.go
+++ b/internal/fs/readfile.go
@@ -3,7 +3,7 @@ package fs
import (
"bufio"
"compress/gzip"
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"errors"
"io"
"os"
diff --git a/fs/stats.go b/internal/fs/stats.go
index 4121ff7..4121ff7 100644
--- a/fs/stats.go
+++ b/internal/fs/stats.go
diff --git a/fs/tailfile.go b/internal/fs/tailfile.go
index a19d4e6..a19d4e6 100644
--- a/fs/tailfile.go
+++ b/internal/fs/tailfile.go
diff --git a/logger/logger.go b/internal/logger/logger.go
index 33ca911..ca85e32 100644
--- a/logger/logger.go
+++ b/internal/logger/logger.go
@@ -2,8 +2,6 @@ package logger
import (
"bufio"
- "dtail/color"
- "dtail/config"
"fmt"
"os"
"os/signal"
@@ -12,6 +10,9 @@ import (
"sync"
"syscall"
"time"
+
+ "github.com/mimecast/dtail/internal/color"
+ "github.com/mimecast/dtail/internal/config"
)
const (
@@ -101,11 +102,14 @@ type buf struct {
message string
}
-// Init logging.
-func Init(myServerEnable bool, mode LogMode, strategy LogStrategy) {
- stdoutWriter = bufio.NewWriter(os.Stdout)
-
+// Start logging.
+func Start(myServerEnable, debugEnable, silentEnable, nothingEnable bool) {
serverEnable = myServerEnable
+
+ mode := logMode(debugEnable, silentEnable, nothingEnable)
+ strategy := logStrategy()
+
+ stdoutWriter = bufio.NewWriter(os.Stdout)
Mode = mode
Strategy = strategy
@@ -152,6 +156,32 @@ func Init(myServerEnable bool, mode LogMode, strategy LogStrategy) {
}
}
+func logMode(debugEnable, silentEnable, nothingEnable bool) LogMode {
+ switch {
+ case debugEnable:
+ return DebugMode
+ case nothingEnable:
+ return NothingMode
+ case config.Common.TraceEnable:
+ return TraceMode
+ case config.Common.DebugEnable:
+ return DebugMode
+ case silentEnable:
+ return SilentMode
+ default:
+ }
+ return NormalMode
+}
+
+func logStrategy() LogStrategy {
+ switch config.Common.LogStrategy {
+ case "daily":
+ return DailyStrategy
+ default:
+ }
+ return StdoutStrategy
+}
+
// Info message logging.
func Info(args ...interface{}) string {
if serverEnable {
diff --git a/mapr/aggregateset.go b/internal/mapr/aggregateset.go
index 2096c3c..2096c3c 100644
--- a/mapr/aggregateset.go
+++ b/internal/mapr/aggregateset.go
diff --git a/mapr/client/aggregate.go b/internal/mapr/client/aggregate.go
index b9443bc..3f2b7a5 100644
--- a/mapr/client/aggregate.go
+++ b/internal/mapr/client/aggregate.go
@@ -1,8 +1,8 @@
package client
import (
- "dtail/logger"
- "dtail/mapr"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/mapr"
"strconv"
"strings"
)
diff --git a/mapr/globalgroupset.go b/internal/mapr/globalgroupset.go
index cfab506..cfab506 100644
--- a/mapr/globalgroupset.go
+++ b/internal/mapr/globalgroupset.go
diff --git a/mapr/groupset.go b/internal/mapr/groupset.go
index d8f9379..d8f9379 100644
--- a/mapr/groupset.go
+++ b/internal/mapr/groupset.go
diff --git a/mapr/logformat/default.go b/internal/mapr/logformat/default.go
index f0df5bc..f0df5bc 100644
--- a/mapr/logformat/default.go
+++ b/internal/mapr/logformat/default.go
diff --git a/mapr/logformat/default_test.go b/internal/mapr/logformat/default_test.go
index a3c47fb..a3c47fb 100644
--- a/mapr/logformat/default_test.go
+++ b/internal/mapr/logformat/default_test.go
diff --git a/mapr/logformat/parser.go b/internal/mapr/logformat/parser.go
index b7c8c5c..5730d29 100644
--- a/mapr/logformat/parser.go
+++ b/internal/mapr/logformat/parser.go
@@ -1,7 +1,7 @@
package logformat
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"errors"
"fmt"
"os"
diff --git a/mapr/query.go b/internal/mapr/query.go
index 8ed3c67..3805d15 100644
--- a/mapr/query.go
+++ b/internal/mapr/query.go
@@ -1,7 +1,7 @@
package mapr
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"errors"
"fmt"
"strconv"
diff --git a/mapr/query_test.go b/internal/mapr/query_test.go
index 6176461..6176461 100644
--- a/mapr/query_test.go
+++ b/internal/mapr/query_test.go
diff --git a/mapr/selectcondition.go b/internal/mapr/selectcondition.go
index 1882b7e..1882b7e 100644
--- a/mapr/selectcondition.go
+++ b/internal/mapr/selectcondition.go
diff --git a/mapr/server/aggregate.go b/internal/mapr/server/aggregate.go
index 316da67..900756e 100644
--- a/mapr/server/aggregate.go
+++ b/internal/mapr/server/aggregate.go
@@ -1,11 +1,11 @@
package server
import (
- "dtail/config"
- "dtail/fs"
- "dtail/logger"
- "dtail/mapr"
- "dtail/mapr/logformat"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/fs"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/mapr"
+ "github.com/mimecast/dtail/internal/mapr/logformat"
"os"
"strings"
"time"
diff --git a/mapr/token.go b/internal/mapr/token.go
index b8be4da..b8be4da 100644
--- a/mapr/token.go
+++ b/internal/mapr/token.go
diff --git a/mapr/wherecondition.go b/internal/mapr/wherecondition.go
index 515c8ad..e1f4e5b 100644
--- a/mapr/wherecondition.go
+++ b/internal/mapr/wherecondition.go
@@ -1,7 +1,7 @@
package mapr
import (
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"errors"
"fmt"
"strconv"
diff --git a/omode/mode.go b/internal/omode/mode.go
index 4bdfc45..4bdfc45 100644
--- a/omode/mode.go
+++ b/internal/omode/mode.go
diff --git a/internal/pprof/pprof.go b/internal/pprof/pprof.go
new file mode 100644
index 0000000..f78bcf6
--- /dev/null
+++ b/internal/pprof/pprof.go
@@ -0,0 +1,17 @@
+package pprof
+
+import (
+ "fmt"
+ "net/http"
+ _ "net/http"
+ _ "net/http/pprof"
+
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+)
+
+func Start() {
+ bindAddr := fmt.Sprintf("%s:%d", config.Common.PProfBindAddress, config.Common.PProfPort)
+ logger.Info("Starting PProf server", bindAddr)
+ go http.ListenAndServe(bindAddr, nil)
+}
diff --git a/prompt/prompt.go b/internal/prompt/prompt.go
index 395d4bd..76a2726 100644
--- a/prompt/prompt.go
+++ b/internal/prompt/prompt.go
@@ -2,7 +2,7 @@ package prompt
import (
"bufio"
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"fmt"
"os"
"strings"
diff --git a/server/handlers/controlhandler.go b/internal/server/handlers/controlhandler.go
index c09eb52..482f759 100644
--- a/server/handlers/controlhandler.go
+++ b/internal/server/handlers/controlhandler.go
@@ -1,12 +1,13 @@
package handlers
import (
- "dtail/logger"
- "dtail/server/user"
"fmt"
"io"
"os"
"strings"
+
+ "github.com/mimecast/dtail/internal/logger"
+ user "github.com/mimecast/dtail/internal/user/server"
)
// ControlHandler is used for control functions and health monitoring.
diff --git a/server/handlers/handler.go b/internal/server/handlers/handler.go
index 8b1f73e..8b1f73e 100644
--- a/server/handlers/handler.go
+++ b/internal/server/handlers/handler.go
diff --git a/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go
index e2466d4..bed8609 100644
--- a/server/handlers/serverhandler.go
+++ b/internal/server/handlers/serverhandler.go
@@ -1,13 +1,6 @@
package handlers
import (
- "dtail/config"
- "dtail/fs"
- "dtail/logger"
- "dtail/mapr/server"
- "dtail/omode"
- "dtail/server/user"
- "dtail/version"
"fmt"
"io"
"os"
@@ -15,6 +8,14 @@ import (
"strings"
"sync"
"time"
+
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/fs"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/mapr/server"
+ "github.com/mimecast/dtail/internal/omode"
+ user "github.com/mimecast/dtail/internal/user/server"
+ "github.com/mimecast/dtail/internal/version"
)
const (
diff --git a/server/server.go b/internal/server/server.go
index 4637458..27a98f5 100644
--- a/server/server.go
+++ b/internal/server/server.go
@@ -1,17 +1,17 @@
package server
import (
- "dtail/config"
- "dtail/logger"
- "dtail/server/handlers"
- "dtail/server/user"
- "dtail/ssh/server"
- "dtail/version"
"errors"
"fmt"
"io"
"net"
- "sync"
+
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/server/handlers"
+ "github.com/mimecast/dtail/internal/ssh/server"
+ user "github.com/mimecast/dtail/internal/user/server"
+ "github.com/mimecast/dtail/internal/version"
gossh "golang.org/x/crypto/ssh"
)
@@ -54,8 +54,7 @@ func New() *Server {
}
// Start the server.
-func (s *Server) Start(wg *sync.WaitGroup) int {
- defer wg.Done()
+func (s *Server) Start() int {
logger.Info("Starting server")
bindAt := fmt.Sprintf("%s:%d", config.Server.SSHBindAddress, config.Common.SSHPort)
diff --git a/server/stats.go b/internal/server/stats.go
index 01aa121..beb1885 100644
--- a/server/stats.go
+++ b/internal/server/stats.go
@@ -1,8 +1,8 @@
package server
import (
- "dtail/config"
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
"fmt"
"runtime"
"sync"
diff --git a/ssh/client/authmethods.go b/internal/ssh/client/authmethods.go
index 84b7ce3..3392eb1 100644
--- a/ssh/client/authmethods.go
+++ b/internal/ssh/client/authmethods.go
@@ -1,9 +1,9 @@
package client
import (
- "dtail/config"
- "dtail/logger"
- "dtail/ssh"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/ssh"
"os"
gossh "golang.org/x/crypto/ssh"
diff --git a/ssh/client/hostkeycallback.go b/internal/ssh/client/hostkeycallback.go
index 7279f5e..4023e59 100644
--- a/ssh/client/hostkeycallback.go
+++ b/internal/ssh/client/hostkeycallback.go
@@ -2,8 +2,8 @@ package client
import (
"bufio"
- "dtail/logger"
- "dtail/prompt"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/prompt"
"fmt"
"net"
"os"
diff --git a/ssh/server/hostkey.go b/internal/ssh/server/hostkey.go
index ff1eb82..7baa4aa 100644
--- a/ssh/server/hostkey.go
+++ b/internal/ssh/server/hostkey.go
@@ -1,9 +1,9 @@
package server
import (
- "dtail/config"
- "dtail/logger"
- "dtail/ssh"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+ "github.com/mimecast/dtail/internal/ssh"
"io/ioutil"
"os"
)
diff --git a/ssh/server/publickeycallback.go b/internal/ssh/server/publickeycallback.go
index 867f639..c6929d7 100644
--- a/ssh/server/publickeycallback.go
+++ b/internal/ssh/server/publickeycallback.go
@@ -1,14 +1,15 @@
package server
import (
- "dtail/config"
- "dtail/logger"
- "dtail/server/user"
"fmt"
"io/ioutil"
"os"
osUser "os/user"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/logger"
+ user "github.com/mimecast/dtail/internal/user/server"
+
gossh "golang.org/x/crypto/ssh"
)
diff --git a/ssh/ssh.go b/internal/ssh/ssh.go
index 6cd28a2..77cc341 100644
--- a/ssh/ssh.go
+++ b/internal/ssh/ssh.go
@@ -4,7 +4,7 @@ import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/logger"
"encoding/pem"
"fmt"
"io/ioutil"
diff --git a/internal/user/name.go b/internal/user/name.go
new file mode 100644
index 0000000..5171ec7
--- /dev/null
+++ b/internal/user/name.go
@@ -0,0 +1,24 @@
+package user
+
+import (
+ "os/user"
+ )
+
+
+func Name() string {
+ user, err := user.Current()
+ if err != nil {
+ panic(err)
+ }
+
+ if user.Uid == "0" {
+ panic("Not allowed to run as UID 0")
+ }
+
+ if user.Gid == "0" {
+ panic("Not allowed to run as GID 0")
+ }
+
+ return user.Username
+}
+
diff --git a/server/user/user.go b/internal/user/server/user.go
index 405dc55..fad38d8 100644
--- a/server/user/user.go
+++ b/internal/user/server/user.go
@@ -1,9 +1,9 @@
-package user
+package server
import (
- "dtail/config"
- "dtail/fs/permissions"
- "dtail/logger"
+ "github.com/mimecast/dtail/internal/config"
+ "github.com/mimecast/dtail/internal/fs/permissions"
+ "github.com/mimecast/dtail/internal/logger"
"fmt"
"os"
"path/filepath"
diff --git a/version/version.go b/internal/version/version.go
index 3c3b5e9..d036a68 100644
--- a/version/version.go
+++ b/internal/version/version.go
@@ -1,18 +1,20 @@
package version
import (
- "dtail/color"
"fmt"
+ "os"
+
+ "github.com/mimecast/dtail/internal/color"
)
// Name of DTail.
const Name = "DTail"
// Version of DTail.
-const Version = "1.0.0"
+const Version = "1.1.0"
// Additional information.
-const Additional = ""
+const Additional = "develop"
// String representation of the DTail version.
func String() string {
@@ -30,3 +32,9 @@ func PaintedString() string {
return fmt.Sprintf("%s %v %s", name, version, descr)
}
+
+// PrintAndExit prints the program version and exists.
+func PrintAndExit() {
+ fmt.Println(PaintedString())
+ os.Exit(0)
+}
diff --git a/main.go b/main.go
deleted file mode 100644
index e54d320..0000000
--- a/main.go
+++ /dev/null
@@ -1,250 +0,0 @@
-package main
-
-import (
- "dtail/clients"
- "dtail/color"
- "dtail/config"
- "dtail/logger"
- "dtail/omode"
- "dtail/server"
- "dtail/version"
- "flag"
- "fmt"
- "net/http"
- _ "net/http"
- _ "net/http/pprof"
- "os"
- "os/user"
- "runtime"
- "sync"
- "time"
-)
-
-// The evil begins here.
-func main() {
- var cfgFile, modeStr string
- var checkHealth bool
- var clientServerEnable bool
- var connectionsPerCPU int
- var debugEnable bool
- var discovery string
- var displayVersion bool
- var files string
- var grep, regex string
- var maxInitConnections int
- var noColor bool
- var pprofEnable bool
- var queryStr string
- var serversStr string
- var shutdownAfter int
- var silent bool
- var sshPort int
- var trustAllHosts bool
- var userName string
-
- user, err := user.Current()
- if err != nil {
- panic(err)
- }
-
- if user.Uid == "0" {
- panic("Not allowed to run as UID 0")
- }
-
- if user.Gid == "0" {
- panic("Not allowed to run as GID 0")
- }
-
- defaultMode := omode.Default()
- serverEnable := defaultMode == omode.Server
- clientEnable := !serverEnable
-
- // Based on the mode we have different default timeouts
- var pingTimeoutS int
- switch defaultMode {
- case omode.CatClient:
- fallthrough
- case omode.GrepClient:
- pingTimeoutS = 60
- case omode.MapClient:
- pingTimeoutS = 900
- default:
- pingTimeoutS = 5
- }
-
- flag.BoolVar(&checkHealth, "checkHealth", false, "Only check for server health")
- flag.BoolVar(&clientServerEnable, "clientServer", false, "Enable client and server (dev purposes)")
- 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(&serverEnable, "server", serverEnable, "Start as a DTail server")
- flag.BoolVar(&silent, "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(&maxInitConnections, "mic", 20, "Max cpc")
- flag.IntVar(&shutdownAfter, "shutdownAfter", 0, "Automatically shutdown after so many seconds")
- flag.IntVar(&sshPort, "port", 2222, "SSH server port")
- flag.IntVar(&pingTimeoutS, "pingTimeout", 10, "The server ping timeout (0 means disable pings)")
- flag.StringVar(&cfgFile, "cfg", "", "Config file path")
- flag.StringVar(&discovery, "discovery", "", "Server discovery method")
- flag.StringVar(&files, "files", "", "File(s) to read")
- flag.StringVar(&grep, "grep", "", "Regular expression (deprecated)")
- flag.StringVar(&modeStr, "mode", defaultMode.String(), "Operating mode (tail, grep, cat, map, server)")
- flag.StringVar(&queryStr, "query", "", "Map reduce query")
- flag.StringVar(&regex, "regex", "", "Regular expression")
- flag.StringVar(&serversStr, "servers", "", "Remote servers to connect")
- flag.StringVar(&userName, "user", user.Username, "Your system user name")
-
- mode := omode.New(modeStr)
-
- flag.Parse()
-
- config.Init(cfgFile)
- color.Init(!noColor)
-
- if displayVersion {
- fmt.Println(version.PaintedString())
- os.Exit(0)
- }
-
- // Figure out how many SSH sessions can be established concurrently.
- if connectionsPerCPU*runtime.NumCPU() < maxInitConnections {
- maxInitConnections = connectionsPerCPU * runtime.NumCPU()
- }
-
- // Figure out in which mode I am? Server or client or both (the latter for dev purposes)?
- if serverEnable {
- clientEnable = false
- }
- if clientServerEnable {
- clientEnable = true
- serverEnable = true
- }
-
- // If non-standard port specified, overwrite config
- if sshPort != 2222 {
- config.Common.SSHPort = sshPort
- }
-
- // Figure out the log level.
- var logMode logger.LogMode
- switch {
- case debugEnable:
- logMode = logger.DebugMode
- case checkHealth:
- logMode = logger.NothingMode
- case config.Common.TraceEnable:
- logMode = logger.TraceMode
- case config.Common.DebugEnable:
- logMode = logger.DebugMode
- case silent:
- logMode = logger.SilentMode
- default:
- logMode = logger.NormalMode
- }
-
- // Figure out the log strategy.
- var logStrategy logger.LogStrategy
- switch config.Common.LogStrategy {
- case "daily":
- logStrategy = logger.DailyStrategy
- case "stdout":
- fallthrough
- default:
- logStrategy = logger.StdoutStrategy
- }
-
- logger.Init(serverEnable, logMode, logStrategy)
-
- // Wait group for shutting down logger.
- var wg sync.WaitGroup
- if serverEnable {
- wg.Add(1)
- }
- if clientEnable {
- wg.Add(1)
- }
-
- logger.Debug("Common config", config.Common)
- logger.Debug("Client config", config.Client)
- logger.Debug("Server config", config.Server)
-
- if grep != "" {
- logger.Warn("Flag 'grep' is deprecated and may be removed in the future, please use 'regex' instead")
- if regex == "" {
- regex = grep
- }
- }
-
- if checkHealth {
- healthClient, _ := clients.NewHealthClient(omode.HealthClient)
- os.Exit(healthClient.Start(&wg))
- }
-
- 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 {
- bindAddr := fmt.Sprintf("%s:%d", config.Common.PProfBindAddress, config.Common.PProfPort)
- logger.Info("Starting PProf server", bindAddr)
- go http.ListenAndServe(bindAddr, nil)
- }
-
- if serverEnable {
- logger.Info("Launching server", mode, version.String())
- sshServer := server.New()
- go sshServer.Start(&wg)
- }
-
- if clientEnable {
- var client clients.Client
- var err error
-
- logger.Info("Launching client", mode, version.String())
-
- args := clients.Args{
- Mode: mode,
- ServersStr: serversStr,
- Discovery: discovery,
- UserName: userName,
- Files: files,
- Regex: regex,
- TrustAllHosts: trustAllHosts,
- MaxInitConnections: maxInitConnections,
- PingTimeout: pingTimeoutS,
- }
-
- switch mode {
- case omode.TailClient:
- switch queryStr {
- case "":
- client, err = clients.NewTailClient(args)
- default:
- client, err = clients.NewMaprClient(args, queryStr)
- }
- case omode.GrepClient:
- client, err = clients.NewGrepClient(args)
- case omode.CatClient:
- client, err = clients.NewCatClient(args)
- case omode.MapClient:
- client, err = clients.NewMaprClient(args, queryStr)
- }
-
- if err != nil {
- panic(err)
- }
-
- go client.Start(&wg)
- }
-
- wg.Wait()
- logger.Stop()
-}