Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a wrapper for the gRPC connection it allows to connect to a Falco gRPC server. It is created using the function NewForConfig(config *Config) .
Example ¶
The simplest use of a Client, just create and Close it.
package main import ( "log" "github.com/falcosecurity/client-go/pkg/client" ) func main() { //Set up a connection to the server. c, err := client.NewForConfig(&client.Config{ Hostname: "localhost", Port: 5060, CertFile: "/etc/falco/certs/client.crt", KeyFile: "/etc/falco/certs/client.key", CARootFile: "/etc/falco/certs/ca.crt", }) if err != nil { log.Fatalf("unable to create a Falco client: %v", err) } defer c.Close() }
Output:
Example (OutputSubscribe) ¶
A client that is created and then used to Subscribe to Falco output events
package main import ( "context" "fmt" "io" "log" "github.com/falcosecurity/client-go/pkg/api/output" "github.com/falcosecurity/client-go/pkg/client" ) func main() { // Set up a connection to the server. c, err := client.NewForConfig(&client.Config{ Hostname: "localhost", Port: 5060, CertFile: "/etc/falco/certs/client.crt", KeyFile: "/etc/falco/certs/client.key", CARootFile: "/etc/falco/certs/ca.crt", }) if err != nil { log.Fatalf("unable to create a Falco client: %v", err) } defer c.Close() outputClient, err := c.Output() if err != nil { log.Fatalf("unable to obtain an output client: %v", err) } ctx := context.Background() // Keepalive true means that the client will wait indefinitely for new events to come // Use keepalive false if you only want to receive the accumulated events and stop fcs, err := outputClient.Subscribe(ctx, &output.Request{Keepalive: true}) if err != nil { log.Fatalf("could not subscribe: %v", err) } for { res, err := fcs.Recv() if err == io.EOF { break } if err != nil { log.Fatalf("error closing stream after EOF: %v", err) } fmt.Printf("rule: %s\n", res.Rule) } }
Output:
Example (Version) ¶
package main import ( "context" "fmt" "log" "github.com/falcosecurity/client-go/pkg/api/version" "github.com/falcosecurity/client-go/pkg/client" ) func main() { // Set up a connection to the server. c, err := client.NewForConfig(&client.Config{ Hostname: "localhost", Port: 5060, CertFile: "/etc/falco/certs/client.crt", KeyFile: "/etc/falco/certs/client.key", CARootFile: "/etc/falco/certs/ca.crt", }) if err != nil { log.Fatalf("unable to create a Falco client: %v", err) } defer c.Close() versionClient, err := c.Version() if err != nil { log.Fatalf("unable to obtain a version client: %v", err) } ctx := context.Background() res, err := versionClient.Version(ctx, &version.Request{}) if err != nil { log.Fatalf("error obtaining the Falco version: %v", err) } fmt.Printf("%v\n", res) }
Output:
func NewForConfig ¶
NewForConfig is used to create a new Falco gRPC client.
Click to show internal directories.
Click to hide internal directories.