-
Notifications
You must be signed in to change notification settings - Fork 103
/
launcher-extension.go
65 lines (54 loc) · 1.72 KB
/
launcher-extension.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
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/go-kit/kit/log/level"
"github.com/kolide/kit/logutil"
"github.com/kolide/kit/version"
"github.com/kolide/launcher/pkg/osquery/table"
osquery "github.com/kolide/osquery-go"
)
func main() {
var (
flSocketPath = flag.String("socket", "", "")
flTimeout = flag.Int("timeout", 0, "")
flVerbose = flag.Bool("verbose", false, "")
flVersion = flag.Bool("version", false, "Print version and exit")
_ = flag.Int("interval", 0, "")
)
flag.Parse()
if *flVersion {
version.PrintFull()
os.Exit(0)
}
logger := logutil.NewServerLogger(*flVerbose)
timeout := time.Duration(*flTimeout) * time.Second
// allow for osqueryd to create the socket path
time.Sleep(2 * time.Second)
// create an extension server
server, err := osquery.NewExtensionManagerServer(
"com.kolide.standalone_extension",
*flSocketPath,
osquery.ServerTimeout(timeout),
)
if err != nil {
level.Debug(logger).Log("err", err, "msg", "creating osquery extension server", "stack", fmt.Sprintf("%+v", err))
logutil.Fatal(logger, "err", err, "msg", "creating osquery extension server")
}
client, err := osquery.NewClient(*flSocketPath, timeout)
if err != nil {
level.Debug(logger).Log("err", err, "creating osquery extension client", "stack", fmt.Sprintf("%+v", err))
logutil.Fatal(logger, "err", err, "creating osquery extension client")
}
var plugins []osquery.OsqueryPlugin
for _, tablePlugin := range table.PlatformTables(client, logger) {
plugins = append(plugins, tablePlugin)
}
server.RegisterPlugin(plugins...)
if err := server.Run(); err != nil {
level.Debug(logger).Log("err", err, "stack", fmt.Sprintf("%+v", err))
logutil.Fatal(logger, "err", err)
}
}