/
logs.go
64 lines (57 loc) · 1.47 KB
/
logs.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
package cmd
import (
"fmt"
"strconv"
"github.com/francois2metz/caleen/config"
baleen "github.com/francois2metz/steampipe-plugin-baleen/baleen/client"
"github.com/spf13/cobra"
)
var (
start string
end string
logsCmd = &cobra.Command{
Use: "logs",
Short: "Get access logs",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
client := config.GetClient()
startParam, err := strconv.Atoi(start)
if err != nil {
return
}
endParam, err := strconv.Atoi(end)
if err != nil {
return
}
params := baleen.AccessLogParams{
Start: startParam,
End: endParam,
Size: 100,
Page: 0,
}
for {
accessLogs, pagination, err := client.GetAccessLogs(namespace, params)
if err != nil {
fmt.Println(err)
return
}
for _, accessLog := range accessLogs {
fmt.Println(accessLog.Timestamp, accessLog.Status, accessLog.RequestMethod, accessLog.Scheme, accessLog.RequestUri)
}
params.Page += 1
if params.Page > pagination.TotalCount/100 {
break
}
}
},
}
)
func init() {
rootCmd.AddCommand(logsCmd)
logsCmd.PersistentFlags().StringVarP(&namespace, "namespace", "n", "", "The namespace")
logsCmd.MarkPersistentFlagRequired("namespace")
logsCmd.PersistentFlags().StringVarP(&start, "start", "s", "", "Start timestamp")
logsCmd.MarkPersistentFlagRequired("start")
logsCmd.PersistentFlags().StringVarP(&end, "end", "e", "", "End timestamp")
logsCmd.MarkPersistentFlagRequired("end")
}