Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OutputsWatch ¶ added in v0.2.0
func OutputsWatch(ctx context.Context, fcs outputs.Service_SubClient, cb OutputsWatchCallback, timeout time.Duration) error
OutputsWatch allows to watch and process a stream of *outputs.Response using a callback function of type OutputsWatchCallback.
The timeout parameter specifies the frequency of the watch operation.
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(context.Context, *Config)`.
Example ¶
The simplest use of a Client, just create and Close it.
package main
import (
"context"
"log"
"github.com/falcosecurity/client-go/pkg/client"
)
func main() {
//Set up a connection to the server.
c, err := client.NewForConfig(context.Background(), &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()
}
Example (OutputsGet) ¶
A client that is created and then used to get the Falco output events.
package main
import (
"context"
"fmt"
"io"
"log"
"github.com/falcosecurity/client-go/pkg/api/outputs"
"github.com/falcosecurity/client-go/pkg/client"
)
func main() {
// Set up a connection to the server.
c, err := client.NewForConfig(context.Background(), &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()
outputsClient, err := c.Outputs()
if err != nil {
log.Fatalf("unable to obtain an output client: %v", err)
}
ctx := context.Background()
fcs, err := outputsClient.Get(ctx, &outputs.Request{})
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)
}
}
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(context.Background(), &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)
}
func NewForConfig ¶
NewForConfig is used to create a new Falco gRPC client.
func (*Client) Outputs ¶ added in v0.2.0
func (c *Client) Outputs() (outputs.ServiceClient, error)
Outputs is the client for Falco Outputs. When using it you can use `Sub()` or `Get()` to receive a stream of Falco output events.
func (*Client) OutputsWatch ¶ added in v0.2.0
func (c *Client) OutputsWatch(ctx context.Context, cb OutputsWatchCallback, timeout time.Duration, opts ...grpc.CallOption) error
OutputsWatch subscribes to a stream of Falco outputs and allows to watch and process a stream of *outputs.Response using a callback function of type OutputsWatchCallback.
The timeout parameter specifies the frequency of the watch operation.
type Config ¶
type Config struct {
Hostname string
Port uint16
CertFile string
KeyFile string
CARootFile string
UnixSocketPath string
DialOptions []grpc.DialOption
InsecureSkipMutualTLSAuth bool
}
Config is the configuration definition for connecting to a Falco gRPC server.
type OutputsWatchCallback ¶ added in v0.2.0
OutputsWatchCallback is passed to OutputsWatch to perform an action for each *outputs.Response while retrieving a stream outputs