/
main.go
70 lines (57 loc) · 1.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
)
func main() {
var (
region = ""
profile = ""
logGroup = "/var/log/messages"
follow = false
limit = 100
startStr string
startTime time.Time
endStr string
endTime time.Time
config aws.Config
)
flag.StringVar(®ion, "region", region, "AWS region name")
flag.StringVar(&profile, "profile", profile, "AWS config profile")
flag.StringVar(&logGroup, "group", logGroup, "log group name")
flag.BoolVar(&follow, "f", follow, "output appended data as the logs grow (conflicts with -t and -T)")
flag.IntVar(&limit, "n", limit, "specify the number of lines to output (conflicts with -T)")
flag.StringVar(&startStr, "t", startStr, "load messages since YYYY-MM-DDTHH:MM:SS@TZ (conflicts with -f)")
flag.StringVar(&endStr, "T", endStr, "load messages until YYYY-MM-DDTHH:MM:SS@TZ (conflicts with -n)")
flag.Parse()
if startStr != "" {
startTime = parseTime(startStr)
}
if endStr != "" {
endTime = parseTime(endStr)
}
if region != "" {
config.Region = ®ion
}
if profile != "" {
config.Credentials = credentials.NewSharedCredentials("", profile)
}
sess := session.New(&config)
if err := Run(sess, logGroup, flag.Args(), follow, limit, startTime, endTime); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func parseTime(s string) (t time.Time) {
var err error
if t, err = time.Parse("2006-01-02T15:04:05@MST", s); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(2)
}
return
}