-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
66 lines (55 loc) · 1.61 KB
/
Copy pathmain.go
File metadata and controls
66 lines (55 loc) · 1.61 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"context"
"flag"
"log"
"time"
"github.com/osquery/osquery-go"
"github.com/osquery/osquery-go/plugin/table"
"github.com/zentralopensource/osquery-extension/tables/fleetdm/orbit/pkg/table/mcp_listening_servers"
)
var (
name = "zentral_extension"
// version is overridden at build time via `-X main.version=...` ldflag
// (see .goreleaser.yml). Defaults to "dev" for local builds.
version = "dev"
)
func main() {
var (
socket = flag.String("socket", "", "Path to the extensions UNIX domain socket")
timeout = flag.Int("timeout", 3, "Seconds to wait for autoloaded extensions")
interval = flag.Int("interval", 3, "Seconds delay between connectivity checks")
)
flag.Parse()
if *socket == "" {
log.Fatalln("Missing required --socket argument")
}
serverTimeout := osquery.ServerTimeout(
time.Second * time.Duration(*timeout),
)
serverPingInterval := osquery.ServerPingInterval(
time.Second * time.Duration(*interval),
)
server, err := osquery.NewExtensionManagerServer(
name,
*socket,
serverTimeout,
serverPingInterval,
)
if err != nil {
log.Fatalf("Error creating extension: %s\n", err)
}
// platform agnostic plugins
plugins := []osquery.OsqueryPlugin{
table.NewPlugin("mcp_listening_servers", mcp_listening_servers.Columns(), func(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
return mcp_listening_servers.Generate(ctx, queryContext, *socket)
}),
}
plugins = append(plugins, platformPlugins(*socket)...)
for _, p := range plugins {
server.RegisterPlugin(p)
}
if err := server.Run(); err != nil {
log.Fatalln(err)
}
}