-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The existing osquery plist table does not work well with complex nested data. It's especially bad for the array-of-dict style structure. This introduces a library to parse that kind of data structure; a table based on it; and a simple command line tool for testing.
- Loading branch information
1 parent
752fa6e
commit 6cb383a
Showing
16 changed files
with
1,723 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
"strings" | ||
"text/tabwriter" | ||
|
||
"github.com/kolide/kit/logutil" | ||
"github.com/kolide/launcher/pkg/dataflatten" | ||
"github.com/peterbourgon/ff" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
func checkError(err error) { | ||
if err != nil { | ||
fmt.Printf("Got Error: %v\nStack:\n%+v\n", err, err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func main() { | ||
|
||
flagset := flag.NewFlagSet("plist", flag.ExitOnError) | ||
|
||
var ( | ||
flPlist = flagset.String("plist", "", "Path to plist") | ||
flJson = flagset.String("json", "", "Path to json file") | ||
flQuery = flagset.String("q", "", "query") | ||
|
||
flDebug = flagset.Bool("debug", false, "use a debug logger") | ||
) | ||
|
||
if err := ff.Parse(flagset, os.Args[1:], | ||
ff.WithConfigFileFlag("config"), | ||
ff.WithConfigFileParser(ff.PlainParser), | ||
); err != nil { | ||
checkError(errors.Wrap(err, "parsing flags")) | ||
} | ||
|
||
logger := logutil.NewCLILogger(*flDebug) | ||
|
||
opts := []dataflatten.FlattenOpts{ | ||
dataflatten.WithLogger(logger), | ||
} | ||
|
||
if *flQuery != "" { | ||
opts = append(opts, dataflatten.WithQuery(strings.Split(*flQuery, `/`))) | ||
} | ||
|
||
rows := []dataflatten.Row{} | ||
|
||
if *flPlist != "" { | ||
data, err := dataflatten.PlistFile(*flPlist, opts...) | ||
checkError(errors.Wrap(err, "flattening plist file")) | ||
rows = append(rows, data...) | ||
} | ||
|
||
if *flJson != "" { | ||
data, err := dataflatten.JsonFile(*flJson, opts...) | ||
checkError(errors.Wrap(err, "flattening json file")) | ||
rows = append(rows, data...) | ||
} | ||
|
||
w := tabwriter.NewWriter(os.Stdout, 0, 4, 2, ' ', 0) | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", "path", "parent key", "key", "value") | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", "----", "----------", "---", "-----") | ||
|
||
for _, row := range rows { | ||
p, k := row.ParentKey("/") | ||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", row.StringPath("/"), p, k, row.Value) | ||
} | ||
w.Flush() | ||
|
||
return | ||
} |
Oops, something went wrong.