summaryrefslogtreecommitdiff
path: root/cmd/dgrep/main.go
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2021-10-21 21:28:49 +0300
committerPaul Buetow <pbuetow@mimecast.com>2021-10-21 21:28:49 +0300
commitf4207a55f71bfbcfdc532d5cdd3befaa3474a157 (patch)
treeea5e4a2d2a67035f645bdee496ae55a52034178a /cmd/dgrep/main.go
parentd80d6070557e3a800e3a54967af9eced518f116b (diff)
parent739205206d63bf42f4e843b39d04d4c8cd8207c3 (diff)
merge develop
Diffstat (limited to 'cmd/dgrep/main.go')
-rw-r--r--cmd/dgrep/main.go74
1 files changed, 41 insertions, 33 deletions
diff --git a/cmd/dgrep/main.go b/cmd/dgrep/main.go
index 123d061..02b2463 100644
--- a/cmd/dgrep/main.go
+++ b/cmd/dgrep/main.go
@@ -4,68 +4,74 @@ import (
"context"
"flag"
"os"
+ "sync"
+
+ "net/http"
+ _ "net/http"
+ _ "net/http/pprof"
"github.com/mimecast/dtail/internal/clients"
- "github.com/mimecast/dtail/internal/color"
"github.com/mimecast/dtail/internal/config"
- "github.com/mimecast/dtail/internal/io/logger"
+ "github.com/mimecast/dtail/internal/io/dlog"
"github.com/mimecast/dtail/internal/io/signal"
+ "github.com/mimecast/dtail/internal/source"
"github.com/mimecast/dtail/internal/user"
"github.com/mimecast/dtail/internal/version"
)
// The evil begins here.
func main() {
- var args clients.Args
- var cfgFile string
- var debugEnable bool
+ var args config.Args
var displayVersion bool
var grep string
- var noColor bool
- var sshPort int
-
+ var pprof string
userName := user.Name()
+ flag.BoolVar(&args.NoColor, "noColor", false, "Disable ANSII terminal colors")
+ flag.BoolVar(&args.Quiet, "quiet", false, "Quiet output mode")
flag.BoolVar(&args.RegexInvert, "invert", false, "Invert regex")
- flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Auto trust all unknown host keys")
- flag.BoolVar(&debugEnable, "debug", false, "Activate debug messages")
+ flag.BoolVar(&args.Spartan, "spartan", false, "Spartan output mode")
+ flag.BoolVar(&args.TrustAllHosts, "trustAllHosts", false, "Trust all unknown host keys")
flag.BoolVar(&displayVersion, "version", false, "Display version")
- flag.BoolVar(&noColor, "noColor", false, "Disable ANSII terminal colors")
- flag.BoolVar(&args.Quiet, "quiet", false, "Quiet output mode")
- flag.IntVar(&args.ConnectionsPerCPU, "cpc", 10, "How many connections established per CPU core concurrently")
- flag.IntVar(&sshPort, "port", 2222, "SSH server port")
+ flag.IntVar(&args.ConnectionsPerCPU, "cpc", config.DefaultConnectionsPerCPU,
+ "How many connections established per CPU core concurrently")
+ flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines")
+ flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines")
+ flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines")
+ flag.IntVar(&args.SSHPort, "port", config.DefaultSSHPort, "SSH server port")
+ flag.StringVar(&args.ConfigFile, "cfg", "", "Config file path")
flag.StringVar(&args.Discovery, "discovery", "", "Server discovery method")
+ flag.StringVar(&args.LogDir, "logDir", "~/log", "Log dir")
+ flag.StringVar(&args.Logger, "logger", config.DefaultClientLogger, "Logger name")
+ flag.StringVar(&args.LogLevel, "logLevel", config.DefaultLogLevel, "Log level")
flag.StringVar(&args.PrivateKeyPathFile, "key", "", "Path to private key")
+ flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect")
flag.StringVar(&args.UserName, "user", userName, "Your system user name")
flag.StringVar(&args.What, "files", "", "File(s) to read")
- flag.StringVar(&cfgFile, "cfg", "", "Config file path")
-
- // Line context awareness.
- flag.StringVar(&args.RegexStr, "regex", ".", "Regular expression")
flag.StringVar(&grep, "grep", "", "Alias for -regex")
- flag.IntVar(&args.LContext.BeforeContext, "before", 0, "Print lines of leading context before matching lines")
- flag.IntVar(&args.LContext.AfterContext, "after", 0, "Print lines of trailing context after matching lines")
- flag.IntVar(&args.LContext.MaxCount, "max", 0, "Stop reading file after NUM matching lines")
+ flag.StringVar(&pprof, "pprof", "", "Start PProf server this address")
flag.Parse()
+ config.Setup(source.Client, &args, flag.Args())
- if grep != "" {
- args.RegexStr = grep
+ if displayVersion {
+ version.PrintAndExit()
}
- config.Read(cfgFile, sshPort)
- color.Colored = !noColor
+ ctx, cancel := context.WithCancel(context.Background())
+ var wg sync.WaitGroup
+ wg.Add(1)
+ dlog.Start(ctx, &wg, source.Client)
- if displayVersion {
- version.PrintAndExit()
+ if grep != "" {
+ args.RegexStr = grep
}
- ctx := context.TODO()
- logger.Start(ctx, logger.Modes{
- Debug: debugEnable || config.Common.DebugEnable,
- Quiet: args.Quiet,
- })
+ if pprof != "" {
+ go http.ListenAndServe(pprof, nil)
+ dlog.Client.Info("Started PProf", pprof)
+ }
client, err := clients.NewGrepClient(args)
if err != nil {
@@ -73,6 +79,8 @@ func main() {
}
status := client.Start(ctx, signal.InterruptCh(ctx))
- logger.Flush()
+ cancel()
+
+ wg.Wait()
os.Exit(status)
}