Skip to content

Commit

Permalink
Added common code for Kolide tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
getvictor committed Oct 17, 2023
1 parent ed10db3 commit 2f11940
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions orbit/pkg/table/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ type Extension interface {
// Opt allows configuring a Runner.
type Opt func(*Runner)

// Global variables for osquery extension manager client and logger for Kolide tables
var (
serverClient *osquery.ExtensionManagerClient

Check failure on line 46 in orbit/pkg/table/extension.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 1.21.1)

var `serverClient` is unused (unused)

Check failure on line 46 in orbit/pkg/table/extension.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest, 1.21.1)

var `serverClient` is unused (unused)
kolideLogger *Logger

Check failure on line 47 in orbit/pkg/table/extension.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 1.21.1)

var `kolideLogger` is unused (unused)

Check failure on line 47 in orbit/pkg/table/extension.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest, 1.21.1)

var `kolideLogger` is unused (unused)
)

// WithExtension registers the given Extension on the Runner.
func WithExtension(t Extension) Opt {
return func(r *Runner) {
Expand All @@ -61,6 +67,8 @@ func NewRunner(socket string, opts ...Opt) *Runner {
func (r *Runner) Execute() error {
log.Debug().Msg("start osquery extension")

kolideLogger = NewKolideLogger()

if err := waitExtensionSocket(r.socket, 1*time.Minute); err != nil {
return err
}
Expand Down Expand Up @@ -123,6 +131,9 @@ func OrbitDefaultTables() []osquery.OsqueryPlugin {

// Orbit extensions.
table.NewPlugin("sntp_request", sntp_request.Columns(), sntp_request.GenerateFunc),

// Kolide extensions.

}
return plugins
}
Expand Down
37 changes: 37 additions & 0 deletions orbit/pkg/table/extension_kolide_logger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package table

import (
"fmt"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)

// Logger is a wrapper around zerolog, which we use for Kolide tables.
// Kolide uses a go-kit logger, while we are using zerolog.
type Logger struct {
zerolog.Logger
}

// Fatal logs a fatal message, just like Kolide's logutil.Fatal.
func (l *Logger) Fatal(args ...interface{}) {
l.Logger.Fatal().Msg(fmt.Sprintln(args...))
}

// Log logs a message, implementing log.Logger interface
func (l *Logger) Log(keyValuePairs ...interface{}) error {
log.Logger.Info().Msg(fmt.Sprint(keyValuePairs))

Check failure on line 22 in orbit/pkg/table/extension_kolide_logger.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest, ^1.21.1, mysql:5.7.21)

missing ... in args forwarded to print-like function

Check failure on line 22 in orbit/pkg/table/extension_kolide_logger.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest, 1.21.1)

printf: missing ... in args forwarded to print-like function (govet)

Check failure on line 22 in orbit/pkg/table/extension_kolide_logger.go

View workflow job for this annotation

GitHub Actions / test-go (ubuntu-latest, ^1.21.1, mysql:8.0.28)

missing ... in args forwarded to print-like function

Check failure on line 22 in orbit/pkg/table/extension_kolide_logger.go

View workflow job for this annotation

GitHub Actions / lint (macos-latest, 1.21.1)

printf: missing ... in args forwarded to print-like function (govet)
return nil
}

// SetLevelKey sets the level key, just like Kolide's logutil.SetLevelKey.
func (l *Logger) SetLevelKey(key interface{}) *Logger {
// Note: zerolog doesn't support changing the level key dynamically like logutil, so we just log it as a warning.
l.Logger.Warn().Msgf("Attempted to set level key to: %v", key)
return l
}

// NewKolideLogger returns the Logger struct.
func NewKolideLogger() *Logger {
// Return a Logger struct with our global logger, and use the existing global config for the log level.
return &Logger{log.Logger}
}

0 comments on commit 2f11940

Please sign in to comment.