/
recent_event_log_panel.go
90 lines (64 loc) · 2.17 KB
/
recent_event_log_panel.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package RDS
import (
"fmt"
"log"
"github.com/Appkube-awsx/awsx-common/authenticate"
"github.com/Appkube-awsx/awsx-common/model"
"github.com/Appkube-awsx/awsx-getelementdetails/comman-function"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/spf13/cobra"
)
var AwsxRecentEventLogsCmd = &cobra.Command{
Use: "recent_event_logs",
Short: "Get recent event logs",
Long: `Command to retrieve recent event logs`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Running from child command")
var authFlag bool
var clientAuth *model.Auth
var err error
authFlag, clientAuth, err = authenticate.AuthenticateCommand(cmd)
if err != nil {
log.Printf("Error during authentication: %v\n", err)
err := cmd.Help()
if err != nil {
return
}
return
}
if authFlag {
data, err := GetRecentEventLogsPanel(cmd, clientAuth, nil)
if err != nil {
return
}
fmt.Println(data)
}
},
}
// type RecentEventLogEntry struct {
// Timestamp string // Change type to string
// EventName string // No changes here
// SourceIPAddress string // No changes here
// EventSource string // No changes here
// UserAgent string // No changes here
// }
func GetRecentEventLogsPanel(cmd *cobra.Command, clientAuth *model.Auth, cloudWatchLogs *cloudwatchlogs.CloudWatchLogs) ([]*cloudwatchlogs.GetQueryResultsOutput, error) {
logGroupName, _ := cmd.PersistentFlags().GetString("logGroupName")
startTime, endTime, err := comman_function.ParseTimes(cmd)
if err != nil {
return nil, fmt.Errorf("Error parsing time: %v", err)
}
logGroupName, err = comman_function.GetCmdbLogsData(cmd)
if err != nil {
return nil, fmt.Errorf("error getting instance ID: %v", err)
}
results, err := comman_function.GetLogsData(clientAuth, startTime, endTime, logGroupName,`fields @timestamp, eventName, sourceIPAddress, eventSource, userAgent| filter eventSource = 'rds.amazonaws.com' | limit 1000`, cloudWatchLogs)
if err != nil {
return nil, nil
}
processedResults := comman_function.ProcessQueryResult(results)
return processedResults, nil
}
func init() {
comman_function.InitAwsCmdFlags(AwsxRecentEventLogsCmd)
}