Documentation
¶
Index ¶
- Constants
- Variables
- func DetectTimeLayout(logLine string) string
- func InferYear(now, t time.Time) time.Time
- type AuthMethodWMeta
- type BootstrapDetails
- type BootstrapIssue
- type BusyStage
- type ClientConfigWMeta
- type ConfigHost
- type ConfigLogStream
- type ConfigLogStreamOptions
- type ConfigLogStreamShellTransport
- type ConfigLogStreamShellTransportLocalhost
- type ConfigLogStreamShellTransportSSHBin
- type ConfigLogStreamShellTransportSSHLib
- type ConfigLogStreamWKey
- type ConfigLogStreams
- type ConnDetails
- type LStreamClient
- type LStreamClientParams
- type LStreamClientState
- type LStreamClientUpdate
- type LStreamClientUpdateState
- type LStreamsManager
- func (lsman *LStreamsManager) Close()
- func (lsman *LStreamsManager) Disconnect()
- func (lsman *LStreamsManager) Ping()
- func (lsman *LStreamsManager) QueryLogs(params QueryLogsParams)
- func (lsman *LStreamsManager) Reconnect()
- func (lsman *LStreamsManager) SetLStreams(logStreamsSpec string) error
- func (lsman *LStreamsManager) SetUseExternalSSH(useExternalSSH bool)
- func (lsman *LStreamsManager) Wait()
- type LStreamsManagerParams
- type LStreamsManagerState
- type LStreamsManagerUpdate
- type LStreamsResolver
- type LStreamsResolverParams
- type LogLevel
- type LogMsg
- type LogResp
- type LogRespTotal
- type LogStream
- type LogStreamOptions
- type LogstreamDebugInfo
- type MinuteStatsItem
- type QueryLogsParams
- type ShellConn
- type ShellConnDataKind
- type ShellConnDataRequest
- type ShellConnDebugInfo
- type ShellConnLocal
- type ShellConnResult
- type ShellConnSSH
- type ShellConnSSHBin
- type ShellConnUpdate
- type ShellTransport
- type ShellTransportLocal
- type ShellTransportLocalParams
- type ShellTransportSSHBin
- type ShellTransportSSHBinParams
- type ShellTransportSSHLib
- type ShellTransportSSHLibParams
- type SudoMode
- type TimeFormatAWKExpr
- type TimeFormatDescr
Constants ¶
const (
// MaxNumLinesDefault is a default for QueryLogsParams.MaxNumLines below.
MaxNumLinesDefault = 250
)
const SpecialFilenameJournalctl = "journalctl"
Variables ¶
var ErrBusyWithAnotherQuery = errors.Errorf("busy with another query")
var ErrNotYetConnected = errors.Errorf("not connected to all lstreams yet")
var ValidSudoModes = map[SudoMode]struct{}{ SudoModeNone: {}, SudoModeFull: {}, }
Functions ¶
func DetectTimeLayout ¶
DetectTimeLayout tries to detect a time format from a log line.
TODO: it's pretty simplistic and could be improved, even to avoid having a predefined set of known formats, but good enough for now.
Types ¶
type AuthMethodWMeta ¶ added in v1.4.0
type AuthMethodWMeta struct {
AuthMethod ssh.AuthMethod
// Descr is a human-readable string which is useful to include in any
// error messages about this SSH connection.
Descr string
}
type BootstrapDetails ¶
type BootstrapDetails struct {
// Err is an error message from the last bootstrap attempt.
Err string
// WarnJournalctlNoAdminAccess is set to true if journalctl is used and the
// user doesn't have access to all the system logs. It's a separate bool
// instead of a generic warning message to make it possible to suppress it
// with a flag.
WarnJournalctlNoAdminAccess bool
}
type BootstrapIssue ¶
type BootstrapIssue struct {
LStreamName string
Err string
// WarnJournalctlNoAdminAccess is set to true if journalctl is used and the
// user doesn't have access to all the system logs. It's a separate bool
// instead of a generic warning message to make it possible to suppress it
// with a flag.
WarnJournalctlNoAdminAccess bool
}
type BusyStage ¶
type BusyStage struct {
// Num is just a stage number. Its meaning depends on the kind of command the
// host is executing, but a general rule is that this number starts from 1
// and then increases, as the process goes on, so we can compare different
// nodes and e.g. find the slowest one.
Num int
// Title is just a human-readable description of the stage.
Title string
// ExtraInfo might contains some additional context, also just a
// human-readable string.
ExtraInfo string
// Percentage is a percentage of the current stage.
Percentage int
}
type ClientConfigWMeta ¶ added in v1.4.0
type ClientConfigWMeta struct {
// ClientConfig is the actual client config.
ClientConfig *ssh.ClientConfig
// Descr is a human-readable string which is useful to include in any
// error messages about this SSH connection.
Descr string
}
type ConfigHost ¶
type ConfigHost struct {
// Addr is the address to connect to, in the same format which is used by
// net.Dial. To copy-paste some docs from net.Dial: the address has the form
// "host:port". The host must be a literal IP address, or a host name that
// can be resolved to IP addresses. The port must be a literal port number or
// a service name.
//
// Examples: "golang.org:http", "192.0.2.1:http", "198.51.100.1:22".
Addr string
// User is the username to authenticate as.
User string
}
func (*ConfigHost) Key ¶
func (ch *ConfigHost) Key() string
type ConfigLogStream ¶
type ConfigLogStream struct {
// HostAddr is the actual host to connect to.
//
// If empty, we'll resort to the ssh config, and if there's no info for that
// host either, we'll try to get host addr from the key in
// ConfigLogStreams.LogStreams.
Hostname string `yaml:"hostname"`
// Port is the actual port to connect to. If empty, the same overriding rules
// apply.
Port string `yaml:"port"`
// User is the user to authenticate as. If empty, same overriding rules
// apply.
User string `yaml:"user"`
// LogFiles contains a list of files which are part of the logstream, like
// ["/var/log/syslog", "/var/log/syslog.1"]. The [0]th item is the latest log
// file [1]st is the previous one, etc.
//
// During the final usage (after resolving everything), it must contain at
// least a single item, otherwise LogStream is invalid. However in the configs,
// it's optional (and eventually, if empty, will be set to default values by
// the LStreamsResolver).
LogFiles []string `yaml:"log_files"`
Options ConfigLogStreamOptions `yaml:"options"`
}
type ConfigLogStreamOptions ¶ added in v1.2.0
type ConfigLogStreamOptions struct {
// Sudo is a shortcut for SudoMode: if Sudo is true, it's an equivalent of
// setting SudoMode to SudoModeFull.
Sudo bool `yaml:"sudo,omitempty"`
// SudoMode can be used to configure nerdlog to read log files with "sudo -n".
// See constants for the SudoMode type for more details.
SudoMode SudoMode `yaml:"sudo_mode,omitempty"`
// ShellInit can contain arbitrary shell commands which will be executed
// right after connecting to the host. A common use case is setting
// custom env vars for tests, like: "export TZ=America/New_York", but
// might be useful outside of tests as well.
ShellInit []string `yaml:"shell_init,omitempty"`
}
ConfigLogStreamOptions contains additional options for a particular logstream.
func (ConfigLogStreamOptions) EffectiveSudoMode ¶ added in v1.2.0
func (opts ConfigLogStreamOptions) EffectiveSudoMode() SudoMode
EffectiveSudoMode returns the SudoMode considering all fields that can affect it: Sudo and SudoMode.
type ConfigLogStreamShellTransport ¶ added in v1.3.0
type ConfigLogStreamShellTransport struct {
SSHLib *ConfigLogStreamShellTransportSSHLib
SSHBin *ConfigLogStreamShellTransportSSHBin
Localhost *ConfigLogStreamShellTransportLocalhost
}
type ConfigLogStreamShellTransportLocalhost ¶ added in v1.3.0
type ConfigLogStreamShellTransportLocalhost struct {
}
type ConfigLogStreamShellTransportSSHBin ¶ added in v1.10.0
type ConfigLogStreamShellTransportSSHBin struct {
// Host is just the hostname, like "myserver.com" or an IP address.
Host string
// Port is optional: if present, it'll be passed to the ssh binary using
// the -p flag, otherwise the -p flag will not be given at all.
Port string
// User is optional: if present, the destination param to the ssh binary
// will be prefixed with "<user>@", otherwise the destination will be just
// the Host.
User string
}
ConfigLogStreamShellTransportSSHBin contains params for the ssh transport using external ssh binary.
type ConfigLogStreamShellTransportSSHLib ¶ added in v1.10.0
type ConfigLogStreamShellTransportSSHLib struct {
Host ConfigHost
Jumphost *ConfigHost
}
ConfigLogStreamShellTransportSSHLib contains params for the ssh transport using internal ssh library.
type ConfigLogStreamWKey ¶
type ConfigLogStreamWKey struct {
// Key is the key at which the corresponding ConfigLogStream was
// stored in the ConfigLogStreams map.
Key string
ConfigLogStream
}
type ConfigLogStreams ¶
type ConfigLogStreams map[string]ConfigLogStream
func (ConfigLogStreams) Keys ¶
func (lss ConfigLogStreams) Keys() []string
type ConnDetails ¶
type ConnDetails struct {
// Messages contains human-readable messages received from shell transport
// regarding the connection.
Messages []string
// Err is an error message from the last connection attempt.
Err string
// Connected shows whether the connection has already succeeded. Unlike other
// fields in this struct, it's set by the LStreamsManager manually.
Connected bool
}
type LStreamClient ¶
type LStreamClient struct {
// contains filtered or unexported fields
}
func NewLStreamClient ¶
func NewLStreamClient(params LStreamClientParams) *LStreamClient
func (*LStreamClient) Close ¶
func (lsc *LStreamClient) Close(changeName string)
Close initiates the shutdown. It doesn't wait for the shutdown to complete; client code needs to wait for the corresponding event (with TornDown: true).
If changeName is non-empty, the LStreamClient's Name will be updated; it's useful to distinguish this LStreamClient from potentially-existing another one with the same (old) name.
func (*LStreamClient) EnqueueCmd ¶
func (lsc *LStreamClient) EnqueueCmd(cmd lstreamCmd)
func (*LStreamClient) Reconnect ¶
func (lsc *LStreamClient) Reconnect()
func (*LStreamClient) SendFoo ¶
func (lsc *LStreamClient) SendFoo()
type LStreamClientParams ¶
type LStreamClientParams struct {
LogStream LogStream
// SSHKeys specifies paths to ssh keys to try, in the given order, until
// an existing key is found.
SSHKeys []string
Logger *log.Logger
// ClientID is just an arbitrary string (should be filename-friendly though)
// which will be appended to the nerdlog_agent.sh and its index filenames.
//
// Needed to make sure that different clients won't get conflicts over those
// files when using the tool concurrently on the same nodes.
ClientID string
UpdatesCh chan<- *LStreamClientUpdate
Clock clock.Clock
}
type LStreamClientState ¶
type LStreamClientState string
const ( LStreamClientStateDisconnected LStreamClientState = "disconnected" LStreamClientStateConnecting LStreamClientState = "connecting" LStreamClientStateDisconnecting LStreamClientState = "disconnecting" LStreamClientStateConnectedIdle LStreamClientState = "connected_idle" LStreamClientStateConnectedBusy LStreamClientState = "connected_busy" )
type LStreamClientUpdate ¶
type LStreamClientUpdate struct {
Name string
State *LStreamClientUpdateState
ConnDetails *ConnDetails
BootstrapDetails *BootstrapDetails
BusyStage *BusyStage
DataRequest *ShellConnDataRequest
// If TornDown is true, it means it's the last update from that client.
TornDown bool
}
LStreamClientUpdate represents an update from logstream client. Name is always populated and it's the logstream's name, and from all the other fields, exactly one field must be non-nil.
type LStreamClientUpdateState ¶
type LStreamClientUpdateState struct {
OldState LStreamClientState
NewState LStreamClientState
}
type LStreamsManager ¶
type LStreamsManager struct {
// contains filtered or unexported fields
}
func NewLStreamsManager ¶
func NewLStreamsManager(params LStreamsManagerParams) *LStreamsManager
func (*LStreamsManager) Close ¶
func (lsman *LStreamsManager) Close()
Close initiates the shutdown. It doesn't wait for the shutdown to complete; use Wait for it.
func (*LStreamsManager) Disconnect ¶
func (lsman *LStreamsManager) Disconnect()
func (*LStreamsManager) Ping ¶
func (lsman *LStreamsManager) Ping()
func (*LStreamsManager) QueryLogs ¶
func (lsman *LStreamsManager) QueryLogs(params QueryLogsParams)
func (*LStreamsManager) Reconnect ¶
func (lsman *LStreamsManager) Reconnect()
func (*LStreamsManager) SetLStreams ¶
func (lsman *LStreamsManager) SetLStreams(logStreamsSpec string) error
func (*LStreamsManager) SetUseExternalSSH ¶ added in v1.10.0
func (lsman *LStreamsManager) SetUseExternalSSH(useExternalSSH bool)
func (*LStreamsManager) Wait ¶
func (lsman *LStreamsManager) Wait()
Wait waits for the LStreamsManager to tear down. Typically used after calling Close().
type LStreamsManagerParams ¶
type LStreamsManagerParams struct {
// ConfigLogStreams contains nerdlog-specific config, typically coming from
// ~/.config/nerdlog/logstreams.yaml.
ConfigLogStreams ConfigLogStreams
// SSHConfig contains the general ssh config, typically coming from
// ~/.ssh/config.
SSHConfig *ssh_config.Config
// SSHKeys specifies paths to ssh keys to try, in the given order, until
// an existing key is found.
SSHKeys []string
Logger *log.Logger
InitialLStreams string
InitialUseExternalSSH bool
// ClientID is just an arbitrary string (should be filename-friendly though)
// which will be appended to the nerdlog_agent.sh and its index filenames.
//
// Needed to make sure that different clients won't get conflicts over those
// files when using the tool concurrently on the same nodes.
ClientID string
UpdatesCh chan<- LStreamsManagerUpdate
Clock clock.Clock
}
type LStreamsManagerState ¶
type LStreamsManagerState struct {
NumLStreams int
LStreamsByState map[LStreamClientState]map[string]struct{}
// NumConnected is how many nodes are actually connected
NumConnected int
// NoMatchingLStreams is true when there are no matching lstreams.
NoMatchingLStreams bool
// Connected is true when all matching lstreams (which should be more than 0)
// are connected.
Connected bool
// Busy is true when a query is in progress.
Busy bool
ConnDetailsByLStream map[string]ConnDetails
BusyStageByLStream map[string]BusyStage
// TearingDown contains logstream names whic are in the process of teardown.
TearingDown []string
}
type LStreamsManagerUpdate ¶
type LStreamsManagerUpdate struct {
State *LStreamsManagerState
LogResp *LogRespTotal
BootstrapIssue *BootstrapIssue
DataRequest *ShellConnDataRequest
}
type LStreamsResolver ¶
type LStreamsResolver struct {
// contains filtered or unexported fields
}
func NewLStreamsResolver ¶
func NewLStreamsResolver(params LStreamsResolverParams) *LStreamsResolver
func (*LStreamsResolver) Resolve ¶
func (r *LStreamsResolver) Resolve(lstreamsStr string) (map[string]LogStream, error)
Resolve parses the given logstream spec, and returns the mapping from LogStream.Name to the corresponding LogStream. Examples of logstream spec are:
- "myuser@myserver.com:22:/var/log/syslog" - "myuser@myserver.com:22" - "myuser@myserver.com" - "myserver.com"
type LStreamsResolverParams ¶
type LStreamsResolverParams struct {
// CurOSUser is the current OS username, it's used as the last resort when
// determining the user for a particular host connection.
CurOSUser string
// If UseExternalSSH is true, we'll use external ssh binary instead of
// internal ssh library (i.e. ShellTransportSSHBin instead of
// ShellTransportSSHLib).
UseExternalSSH bool
// ConfigLogStreams is the nerdlog-specific config, typically coming from
// ~/.config/nerdlog/logstreams.yaml.
ConfigLogStreams ConfigLogStreams
// SSHConfig is the general SSH config, typically coming from ~/.ssh/config
SSHConfig *ssh_config.Config
}
type LogLevel ¶
type LogLevel string
const LogLevelDebug LogLevel = "debug"
const LogLevelError LogLevel = "error"
const LogLevelInfo LogLevel = "info"
const LogLevelUnknown LogLevel = ""
const LogLevelWarn LogLevel = "warn"
type LogMsg ¶
type LogMsg struct {
Time time.Time
DecreasedTimestamp bool
// LogFilename and LogLinenumber are file ane line number in that file
LogFilename string
LogLinenumber int
// CombinedLinenumber is the line number in pseudo-file: all (actually just
// two) log files concatenated. This is the linenumbers output by the
// nerdlog_agent.sh for every "msg:" line, and this is the linenumber
// which should be used for --lines-until param.
CombinedLinenumber int
Msg string
Context map[string]string
Level LogLevel
OrigLine string
}
type LogResp ¶
type LogResp struct {
// MinuteStats is a map from the unix timestamp (in seconds) to the stats for
// the minute starting at this timestamp.
MinuteStats map[int64]MinuteStatsItem
Logs []LogMsg
// NumMsgsTotal is the total number of messages in the time range (and
// included in MinuteStats). This number is usually larger than len(Logs).
NumMsgsTotal int
// DebugInfo contains info collected during this particular query.
DebugInfo LogstreamDebugInfo
}
LogResp is a log response from a single logstream
type LogRespTotal ¶
type LogRespTotal struct {
// If LoadedEarlier is true, it means we've just loaded more logs instead of replacing
// the logs (the Logs slice still contains everything though).
LoadedEarlier bool
// MinuteStats is a map from the unix timestamp (in seconds) to the stats for
// the minute starting at this timestamp.
MinuteStats map[int64]MinuteStatsItem
Logs []LogMsg
// NumMsgsTotal is the total number of messages in the time range (and
// included in MinuteStats). This number is usually larger than len(Logs).
NumMsgsTotal int
Errs []error
// DebugInfo is a map from the logstream name to the corresponding debug info
// collected during this particular query.
DebugInfo map[string]LogstreamDebugInfo
// QueryDur shows how long the query took.
QueryDur time.Duration
}
LogRespTotal is a log response from a LStreamsManager. It's merged from multiple LogResp's and it also contains some extra field(s), e.g. LoadedEarlier.
type LogStream ¶
type LogStream struct {
// Name is an arbitrary string which will be included in log messages as the
// "lstream" context tag; it must uniquely identify the LogStream.
Name string
// Transport specifies how we can get shell access to the host containing
// the logstream.
Transport ConfigLogStreamShellTransport
// LogFiles contains a list of files which are part of the logstream, like
// ["/var/log/syslog", "/var/log/syslog.1"]. The [0]th item is the latest log
// file [1]st is the previous one, etc. One special case here is journalctl:
// if [0]th item is "journalctl", then we won't use plain log files, and
// instead will get the data straight from journalctl.
//
// It must contain at least a single item, otherwise LogStream is invalid.
LogFiles []string
Options LogStreamOptions
}
func (LogStream) LogFileLast ¶
func (LogStream) LogFilePrev ¶
type LogStreamOptions ¶ added in v1.2.0
type LogStreamOptions struct {
SudoMode SudoMode
// ShellInit can contain arbitrary shell commands which will be executed
// right after connecting to the host. A common use case is setting
// custom env vars for tests, like: "export TZ=America/New_York", but
// might be useful outside of tests as well.
ShellInit []string
}
type LogstreamDebugInfo ¶ added in v1.8.0
type MinuteStatsItem ¶
type MinuteStatsItem struct {
NumMsgs int
}
type QueryLogsParams ¶
type QueryLogsParams struct {
// maxNumLines is how many log lines the nerdlog_agent.sh will return at
// most.
MaxNumLines int
From time.Time
To time.Time
Query string
// If LoadEarlier is true, it means we're only loading the logs _before_ the ones
// we already had.
LoadEarlier bool
// If DontAddHistoryItem is true, the browser-like history will not be
// populated with a new item (it should be used exactly when we're navigating
// this browser-like history back and forth)
DontAddHistoryItem bool
// If RefreshIndex is true, we'll drop the index file for all logstreams, and
// rebuild it from scratch (no-op for journalctl logstreams, because there's
// no nerdlog-maintained index for journalctl).
RefreshIndex bool
}
type ShellConn ¶ added in v1.3.0
type ShellConn interface {
Stdin() io.Writer
Stdout() io.Reader
Stderr() io.Reader
// Close should be called when the connection is not needed anymore.
Close()
}
ShellConn provides an abstraction of a shell connection; can be implemented by local shell, or SSH, or maybe something else.
type ShellConnDataKind ¶ added in v1.4.0
type ShellConnDataKind int
const (
ShellConnDataKindPassword ShellConnDataKind = iota
)
type ShellConnDataRequest ¶ added in v1.4.0
type ShellConnDataRequest struct {
// Title is a human-readable title to show on the data request dialog.
// If empty, will be "Data request".
Title string
// Message is a human-readable message to show to the user when asking for data.
Message string
// DataKind specifies what kind of data we're requesting from the user.
DataKind ShellConnDataKind
// ResponseCh is where the user response should be sent.
ResponseCh chan<- string
}
ShellConnDataRequest contains request for additional data from the user which might be needed during connection, e.g. the passphrase to decrypt ssh private key.
type ShellConnDebugInfo ¶ added in v1.10.0
type ShellConnDebugInfo struct {
// Message contains some arbitrary human-readable details about the connection.
Message string
}
ShellConnDebugInfo contains some debugging human-readable info about the connection.
type ShellConnLocal ¶ added in v1.3.0
type ShellConnLocal struct {
// contains filtered or unexported fields
}
func (*ShellConnLocal) Close ¶ added in v1.3.0
func (s *ShellConnLocal) Close()
func (*ShellConnLocal) Stderr ¶ added in v1.3.0
func (s *ShellConnLocal) Stderr() io.Reader
func (*ShellConnLocal) Stdin ¶ added in v1.3.0
func (s *ShellConnLocal) Stdin() io.Writer
func (*ShellConnLocal) Stdout ¶ added in v1.3.0
func (s *ShellConnLocal) Stdout() io.Reader
type ShellConnResult ¶ added in v1.3.0
ShellConnResult contains the connection result. If the connection is successful, Conn is non-nil; otherwise, Err is non-nil.
type ShellConnSSH ¶ added in v1.3.0
type ShellConnSSH struct {
// contains filtered or unexported fields
}
ShellConnSSH implements ShellConn for SSH.
func (*ShellConnSSH) Close ¶ added in v1.3.0
func (c *ShellConnSSH) Close()
Close closes underlying SSH connection.
func (*ShellConnSSH) Stderr ¶ added in v1.3.0
func (c *ShellConnSSH) Stderr() io.Reader
func (*ShellConnSSH) Stdin ¶ added in v1.3.0
func (c *ShellConnSSH) Stdin() io.Writer
func (*ShellConnSSH) Stdout ¶ added in v1.3.0
func (c *ShellConnSSH) Stdout() io.Reader
type ShellConnSSHBin ¶ added in v1.10.0
type ShellConnSSHBin struct {
// contains filtered or unexported fields
}
func (*ShellConnSSHBin) Close ¶ added in v1.10.0
func (s *ShellConnSSHBin) Close()
func (*ShellConnSSHBin) Stderr ¶ added in v1.10.0
func (s *ShellConnSSHBin) Stderr() io.Reader
func (*ShellConnSSHBin) Stdin ¶ added in v1.10.0
func (s *ShellConnSSHBin) Stdin() io.Writer
func (*ShellConnSSHBin) Stdout ¶ added in v1.10.0
func (s *ShellConnSSHBin) Stdout() io.Reader
type ShellConnUpdate ¶ added in v1.4.0
type ShellConnUpdate struct {
// Info contains some debugging info about the connection, typically sent
// before trying to connect.
DebugInfo *ShellConnDebugInfo
// DataRequest contains request for additional data from the user.
DataRequest *ShellConnDataRequest
// Result contains the final connection result. After receiving an update
// with non-nil Result, there will be no more messages to this channel.
Result *ShellConnResult
}
ShellConnUpdate contains the update from ssh connection. Exactly one field must be non-nil.
type ShellTransport ¶ added in v1.3.0
type ShellTransport interface {
// Connect attempts to connect to the shell. It just spawns a goroutine and
// returns immediately, and later on the result (or maybe requests for
// additional data such as passphrases) will be delivered to the provided
// channel.
Connect(resCh chan<- ShellConnUpdate)
}
ShellTransport provides an abstraction for getting shell access to a host; e.g. via SSH or just local shell. In the future, tsh (Teleport) might be supported as well, and maybe something else.
type ShellTransportLocal ¶ added in v1.3.0
type ShellTransportLocal struct {
// contains filtered or unexported fields
}
ShellTransportLocal is an implementation of ShellTransport that opens a local shell.
func NewShellTransportLocal ¶ added in v1.3.0
func NewShellTransportLocal(params ShellTransportLocalParams) *ShellTransportLocal
NewShellTransportLocal creates a new ShellTransportLocal with the given shell command.
func (*ShellTransportLocal) Connect ¶ added in v1.3.0
func (s *ShellTransportLocal) Connect(resCh chan<- ShellConnUpdate)
Connect starts the local shell and sends the result to the provided channel.
type ShellTransportLocalParams ¶ added in v1.3.0
type ShellTransportSSHBin ¶ added in v1.10.0
type ShellTransportSSHBin struct {
// contains filtered or unexported fields
}
ShellTransportSSHBin is an implementation of ShellTransport that opens an ssh session using external ssh binary.
func NewShellTransportSSHBin ¶ added in v1.10.0
func NewShellTransportSSHBin(params ShellTransportSSHBinParams) *ShellTransportSSHBin
NewShellTransportSSHBin creates a new ShellTransportSSHBin with the given shell command.
func (*ShellTransportSSHBin) Connect ¶ added in v1.10.0
func (s *ShellTransportSSHBin) Connect(resCh chan<- ShellConnUpdate)
Connect starts the local shell and sends the result to the provided channel.
type ShellTransportSSHBinParams ¶ added in v1.10.0
type ShellTransportSSHLib ¶ added in v1.10.0
type ShellTransportSSHLib struct {
// contains filtered or unexported fields
}
ShellTransportSSHLib implements ShellTransport over SSH.
func NewShellTransportSSHLib ¶ added in v1.10.0
func NewShellTransportSSHLib(params ShellTransportSSHLibParams) *ShellTransportSSHLib
func (*ShellTransportSSHLib) Connect ¶ added in v1.10.0
func (st *ShellTransportSSHLib) Connect(resCh chan<- ShellConnUpdate)
type ShellTransportSSHLibParams ¶ added in v1.10.0
type ShellTransportSSHLibParams struct {
// SSHKeys specifies paths to ssh keys to try, in the given order, until
// an existing key is found.
SSHKeys []string
ConnDetails ConfigLogStreamShellTransportSSHLib
Logger *log.Logger
}
type SudoMode ¶ added in v1.2.0
type SudoMode string
SudoMode can be used to configure nerdlog to read log files with "sudo -n". See constants below for more details.
const ( // SudoModeNone is the same as an empty string, and it obviously means that // no sudo will be used. It exists as a separate mode to make it possible to // override the mode to not use sudo even if some config specifies some // non-empty sudo mode. SudoModeNone SudoMode = "none" // SudoModeFull means that the whole nerdlog_agent.sh script will be executed // with "sudo -n". Useful for cases when the log files are owned by root but // sudo doesn't require a password. SudoModeFull SudoMode = "full" )
type TimeFormatAWKExpr ¶
type TimeFormatAWKExpr struct {
// Month is an AWK expression to get month number as a string, from "01" to
// "12". It may use `monthByName`, which is a map from a 3-char string like
// "Jan" to the corresponding string like "01".
//
// So e.g. for the traditional syslog format "Jan _2 15:04:05", it should be
// "monthByName[$1]".
//
// For the format "2006-01-02T15:04:05.000000Z07:00", it should rather be
// "substr($0, 6, 2)".
Month string
// Year is an AWK expression to get year string like "2024". If the format
// doesn't contain the year, it may use the already-computed `month` and
// `yearByMonth`, which is a mapping from the month (from "01" to "12") to
// the corresponding inferred year.
//
// So e.g. for the traditional syslog format "Jan _2 15:04:05", it should be
// "yearByMonth[month]".
//
// For the format "2006-01-02T15:04:05.000000Z07:00", it should rather be
// "substr($0, 1, 4)".
Year string
// Day is an AWK expression to get the day string like "05"; note the leading
// zero, it's important (TODO: make it possible to support spaces; it'd mean
// having spaces in the index and in the --from and --to args, which has issues)
//
// So e.g. for the traditional syslog format "Jan _2 15:04:05", it should be
// `(length($2) == 1) ? "0" $2 : $2`.
//
// For the format "2006-01-02T15:04:05.000000Z07:00", it should rather be
// "substr($0, 9, 2)".
Day string
// HHMM is an AWK expression to get the hours and minutes string like "14:38".
//
// So e.g. for the traditional syslog format "Jan _2 15:04:05", it should be
// "substr($3, 1, 5)".
//
// For the format "2006-01-02T15:04:05.000000Z07:00", it should rather be
// "substr($0, 12, 5)".
HHMM string
// MinuteKey is an AWK expression to get a string covering all timestamp
// components from minute and larger. It'll be used as a key to identify a
// particular minute (in the mapping from the minute to the amount of logs in
// that minute), hence the name; so it should not include seconds, and it
// should include minute+hour+day+month, maybe even year but that's optional,
// since Nerdlog is not designed to look at logs spanning more than one year.
//
// So e.g. for the traditional syslog format "Jan _2 15:04:05", it should be
// "substr($0, 1, 12)".
//
// For the format "2006-01-02T15:04:05.000000Z07:00", it should rather be
// "substr($0, 1, 16)" (to include the year) or "substr($0, 6, 11)" (to not
// include the year).
MinuteKey string
}
TimeFormatAWKExpr contains all the awk expressions which will be used by the nerdlog_agent.sh script to get the time components from logs.
type TimeFormatDescr ¶
type TimeFormatDescr struct {
// TimestampLayout is a Go-style time layout which should parse the entire
// timestamp in the log line, e.g. "Jan _2 15:04:05" or
// "2006-01-02T15:04:05.000000Z07:00".
TimestampLayout string
// MinuteKeyLayout is a Go-style time layout which should parse the time
// captured by the awk expression `TimeFormatAWKExpr.MinuteKey` (read there
// what "minute key" means in the first place).
//
// So e.g. for the traditional syslog format "Jan _2 15:04:05", it should be
// "Jan _2 15:04".
//
// For the format "2006-01-02T15:04:05.000000Z07:00", it should rather be
// "2006-01-02T15:04" (if we decided to include the year) or "01-02T15:04"
// (if we decided to not include the year).
MinuteKeyLayout string
// AWKExpr contains all the awk expressions which will be used by the
// nerdlog_agent.sh script to get the time components from logs.
AWKExpr TimeFormatAWKExpr
}
TimeFormatDescr contains all data necessary for Nerdlog to parse timestamps in the particular logstream. It contains info for both the awk script and Go client.
func GenerateTimeDescr ¶
func GenerateTimeDescr(layout string) (*TimeFormatDescr, error)
GenerateTimeDescr takes a Go-style time layout, and returns the full time format descriptor to be used for parsing all logs.
func GetTimeFormatDescrFromLogLines ¶
func GetTimeFormatDescrFromLogLines(logLines []string) (*TimeFormatDescr, error)