github.com/Uptycs/basequery-go@v0.8.0/cmd/examples/call/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "time" 7 8 "github.com/Uptycs/basequery-go" 9 ) 10 11 func main() { 12 if len(os.Args) != 5 { 13 fmt.Printf(`Usage: %s SOCKET_PATH REGISTRY_NAME PLUGIN_NAME ACTION 14 15 Calls the provided action for the plugin with the given registry and plugin 16 name. 17 `, os.Args[0]) 18 os.Exit(1) 19 } 20 21 socketPath := os.Args[1] 22 registryName := os.Args[2] 23 pluginName := os.Args[3] 24 action := os.Args[4] 25 26 client, err := osquery.NewClient(socketPath, 10*time.Second) 27 if err != nil { 28 fmt.Println("Error creating Thrift client: " + err.Error()) 29 os.Exit(1) 30 } 31 defer client.Close() 32 33 resp, err := client.Call(registryName, pluginName, map[string]string{"action": action}) 34 if err != nil { 35 fmt.Println("Error communicating with osqueryd: " + err.Error()) 36 os.Exit(1) 37 } 38 if resp.Status.Code != 0 { 39 fmt.Println("osqueryd returned error: " + resp.Status.Message) 40 os.Exit(1) 41 } 42 43 fmt.Printf("Got results:\n%#v\n", resp.Response) 44 }