-
Notifications
You must be signed in to change notification settings - Fork 419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Traceectl to Tracee #4396
base: main
Are you sure you want to change the base?
Add Traceectl to Tracee #4396
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments below.
In addition, please add documentation to traceectl.
As part of the documentation, please also refer to the way the user should start tracee "daemon" (e.g. using NONE output and setting the grpc server address)
@@ -0,0 +1,150 @@ | |||
package cmd | |||
|
|||
//TODO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
Short: "Event management for tracee", | ||
Long: `Event Management for tracee | ||
Let you enable and disable events in tracee. | ||
Get descriptions of events and run them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get descriptions of events and run them. | |
Get descriptions of events. |
listEventCmd.Flags().StringVarP(&eventFormatFlag, "format", "f", formatter.FormatTable, "Output format (json|table|template) ") | ||
listEventCmd.Flags().StringVarP(&eventOutputFlag, "output", "o", "stdout", "Output destination ") | ||
|
||
describeEventCmd.Flags().StringVarP(&eventFormatFlag, "format", "f", formatter.FormatTable, "Output format (json|table|template) ") | ||
describeEventCmd.Flags().StringVarP(&eventOutputFlag, "output", "o", "stdout", "Output destination ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Output can be made global instead of per command
|
||
type ServerInfo struct { | ||
ConnectionType string | ||
ADDR string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename to Addr
switch serverInfo.ConnectionType { | ||
case PROTOCOL_UNIX: | ||
address := fmt.Sprintf("unix://%s", serverInfo.ADDR) | ||
conn, err = grpc.NewClient(address, opts...) | ||
|
||
if err != nil { | ||
log.Fatalf("failed to connect to server: %v", err) | ||
return nil, err | ||
} | ||
case PROTOCOL_TCP: | ||
address := fmt.Sprintf(serverInfo.ADDR) | ||
conn, err = grpc.NewClient(address, opts...) | ||
|
||
if err != nil { | ||
log.Fatalf("failed to connect to server: %v", err) | ||
return nil, err | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch case should only initialize address, common code can be below
) | ||
|
||
func (f *Formatter) PrintStreamJSON(event *pb.Event) { | ||
f.CMD.Printf("%s", event.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use camelCase
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these functions are tightly coupled to the stream and events commands, I suggest to put them in their packages, and leave the formatter out at this stage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The methods in this file are coupled to the command - let's move them to the respective commands instead. In the future, we can think about extending traceectl with a formatter package
func initOutput(cmd *cobra.Command, output string) error { | ||
if (output != "") && (output != "stdout") { | ||
if output == "" || strings.TrimSpace(output) == "" { | ||
return fmt.Errorf("output file path is empty or invalid") | ||
} | ||
dir := filepath.Dir(output) | ||
if err := os.MkdirAll(dir, 0755); err != nil { | ||
return fmt.Errorf("failed to create directories for output file: %v", err) | ||
} | ||
file, err := os.Create(output) | ||
if err != nil { | ||
return fmt.Errorf("failed to open output file: %v", err) | ||
} | ||
|
||
cmd.SetOut(file) | ||
cmd.SetErr(file) | ||
cmd.PersistentPostRun = func(cmd *cobra.Command, args []string) { | ||
file.Close() | ||
} | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't seem to be part of the formatter package, considering it handles output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
Description
This PR introduces
traceectl
, a new CLI tool for interacting with Tracee. It implements basic commands for communication with Tracee via gRPC.Key Changes
traceectl
CLI tool.version
metrics
stream
event
Testing
Compile and run Tracee with gRPC:
Run
traceectl
:This displays the help command.
Current Limitations
metrics
: JSON output is not yet supported.stream
: Only the basestream
command is supported. Streams events directly from Tracee.Related Issues
Note: This PR was accidentally closed previously and is now being resubmitted.