package main import ( "bytes" "encoding/json" "fmt" "io" "math" "os" "os/signal" "strings" "sync/atomic" "syscall" "text/template" "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/kinesis" "github.com/lestrrat-go/strftime" getopt "github.com/pborman/getopt/v2" ) const maxBackoff = time.Duration(10 * time.Second) const maxSleepWithoutSequence = time.Duration(60 * time.Second) // WriteUsageToStderr print usage information to os.Stderr. This is provided // for signature compatibility is getopt.SetUsage. func WriteUsageToStderr() { WriteUsage(os.Stderr) } // WriteUsage prints usage information to the specified Writer. func WriteUsage(w io.Writer) { fmt.Fprintf(w, `kinesis-log-watcher [options] Watch incoming log entries from a Kinesis stream. This is intended to be a companion to kinesis-log-streamer. Valid durations are a number followed by a unit abbreviation. Examples: 30s, 5m, 3h, 1d. The format string uses the Go template format; full documentation is available at https://golang.org/pkg/text/template/. Fields available are: {{.HostId}} {{.HostID}} -- The full ARN of the host generating the log. {{.ShortHostId}} {{.ShortHostID}} -- Short hostname (just the last part). {{.Timestamp}} -- The timestamp when the log was sent to Kinesis. {{.LogEntry}} -- The log entry in string format. {{.Log}} -- If the log entry could be parsed as JSON, the resulting JSON structure. You can get embedded fields using {{.Log.FieldName}}. To format the timestamp in different formats (e.g. ISO 8601), you can use either: {{.Timestamp Format "2005-01-02T15:04:05Z"}} or {{strftime "%%Y-%%m-%%dT%%H:%%M:%%S" .Timestamp}} `) getopt.PrintUsage(w) } func main() { getopt.BoolLong("help", 'h', "Show this usage information.") getopt.BoolLong("one-shot", 'O', "Display logs only once.") getopt.StringLong("format", 'f', `{{.ShortHostId}} {{.Timestamp}} {{.LogEntry}}`, "Format template for log entries.", "