-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicola Strappazzon C
committed
Oct 15, 2023
1 parent
450a8c7
commit 71894f7
Showing
3 changed files
with
109 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package list | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/debeando/go-common/aws/rds" | ||
"github.com/debeando/go-common/table" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var filter string | ||
var sort bool | ||
|
||
func NewCommand() *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "list [IDENTIFIER] [FILENAME]", | ||
Short: "List all logs about database.", | ||
Example: ` | ||
# List logs of specific database instance: | ||
zenit aws database logs test-rds | ||
# List slow query logs of specific database instance: | ||
zenit aws database logs test-rds --filter=slowquery | ||
# Sort list slow query logs of specific database instance: | ||
zenit aws database logs test-rds --filter=slowquery --sort`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 || len(args) > 1 { | ||
cmd.Help() | ||
return | ||
} | ||
|
||
r := rds.Config{} | ||
r.Init() | ||
|
||
logs, err := r.Logs(args[0], filter) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
if sort { | ||
logs.SortBySize() | ||
} | ||
|
||
tbl := table.New("FILE", "SIZE") | ||
for _, log := range logs { | ||
tbl.AddRow(log.FileName, log.Size) | ||
} | ||
tbl.Print() | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&filter, "filter", "", "Filters the available log files for log file names that contain the specified string.") | ||
cmd.Flags().BoolVar(&sort, "sort", false, "Sort list of logs by file size.") | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,23 @@ | ||
package logs | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/debeando/go-common/aws/rds" | ||
"github.com/debeando/go-common/table" | ||
"zenit/aws/database/logs/list" | ||
"zenit/aws/database/logs/view" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "logs [IDENTIFIER] [FILENAME]", | ||
Short: "List all logs about database.", | ||
Example: ` | ||
# List logs of specific database instance: | ||
zenit aws database logs test-rds | ||
# Show logs to specific path and file name: | ||
zenit aws database logs test-rds error/mysql-error-running.log`, | ||
Use: "logs", | ||
Short: "Logs about database; error, slow logs, general log, ...", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 || len(args) > 2 { | ||
cmd.Help() | ||
return | ||
} | ||
|
||
r := rds.Config{} | ||
r.Init() | ||
|
||
if len(args) == 1 && len(args[0]) > 0 { | ||
logs, err := r.Logs(args[0]) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
tbl := table.New("FILE", "SIZE") | ||
for _, log := range logs { | ||
tbl.AddRow(log.FileName, log.Size) | ||
} | ||
tbl.Print() | ||
} | ||
|
||
if len(args) == 2 && len(args[0]) > 0 && len(args[1]) > 0 { | ||
data, err := r.PollLogs(args[0], args[1]) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
if len(data) > 0 { | ||
fmt.Println(data) | ||
} | ||
} | ||
cmd.Help() | ||
}, | ||
} | ||
|
||
cmd.AddCommand(list.NewCommand()) | ||
cmd.AddCommand(view.NewCommand()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package view | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/debeando/go-common/aws/rds" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand() *cobra.Command { | ||
var cmd = &cobra.Command{ | ||
Use: "view [IDENTIFIER] [FILENAME]", | ||
Short: "View logs details of specific database instance.", | ||
Example: ` | ||
# View logs details to specific path and file name: | ||
zenit aws database logs view test-rds error/mysql-error-running.log`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) != 2 { | ||
cmd.Help() | ||
return | ||
} | ||
|
||
r := rds.Config{} | ||
r.Init() | ||
|
||
if len(args) == 2 && len(args[0]) > 0 && len(args[1]) > 0 { | ||
data, err := r.PollLogs(args[0], args[1]) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
if len(data) > 0 { | ||
fmt.Println(data) | ||
} | ||
} | ||
}, | ||
} | ||
|
||
return cmd | ||
} |