forked from falcosecurity/client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (47 loc) · 1.09 KB
/
main.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
package main
import (
"context"
"fmt"
"io"
"log"
"github.com/falcosecurity/client-go/pkg/api/outputs"
"github.com/falcosecurity/client-go/pkg/client"
"github.com/gogo/protobuf/jsonpb"
)
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 connect: %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)
}
out, err := (&jsonpb.Marshaler{}).MarshalToString(res)
if err != nil {
log.Fatal(err)
}
fmt.Println(out)
}
}