diff options
Diffstat (limited to 'clients/tailclient.go')
| -rw-r--r-- | clients/tailclient.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/clients/tailclient.go b/clients/tailclient.go new file mode 100644 index 0000000..cb93258 --- /dev/null +++ b/clients/tailclient.go @@ -0,0 +1,44 @@ +package clients + +import ( + "dtail/clients/handlers" + "dtail/clients/remote" + "dtail/ssh/client" + "fmt" + "strings" + + gossh "golang.org/x/crypto/ssh" +) + +// TailClient is used for tailing remote log files (opening, seeking to the end and returning only new incoming lines). +type TailClient struct { + baseClient +} + +// NewTailClient returns a new TailClient. +func NewTailClient(args Args) (*TailClient, error) { + c := TailClient{ + baseClient: baseClient{ + Args: args, + stop: make(chan struct{}), + stopped: make(chan struct{}), + throttleCh: make(chan struct{}, args.MaxInitConnections), + retry: true, + }, + } + + c.init(c) + + return &c, nil +} + +func (c TailClient) makeConnection(server string, sshAuthMethods []gossh.AuthMethod, hostKeyCallback *client.HostKeyCallback) *remote.Connection { + conn := remote.NewConnection(server, c.UserName, sshAuthMethods, hostKeyCallback) + conn.Handler = handlers.NewClientHandler(server, c.PingTimeout) + + for _, file := range strings.Split(c.Files, ",") { + conn.Commands = append(conn.Commands, fmt.Sprintf("%s %s regex %s", c.Mode.String(), file, c.Regex)) + } + + return conn +} |
