github.com/Uptycs/basequery-go@v0.8.0/cmd/examples/query/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) != 3 {
    13  		fmt.Printf(`Usage: %s SOCKET_PATH QUERY\n
    14  
    15  Requests osqueryd to run the provided query and prints the results.
    16  `, os.Args[0])
    17  		os.Exit(1)
    18  	}
    19  
    20  	client, err := osquery.NewClient(os.Args[1], 10*time.Second)
    21  	if err != nil {
    22  		fmt.Println("Error creating Thrift client: " + err.Error())
    23  		os.Exit(1)
    24  	}
    25  	defer client.Close()
    26  
    27  	resp, err := client.Query(os.Args[2])
    28  	if err != nil {
    29  		fmt.Println("Error communicating with osqueryd: " + err.Error())
    30  		os.Exit(1)
    31  	}
    32  	if resp.Status.Code != 0 {
    33  		fmt.Println("osqueryd returned error: " + resp.Status.Message)
    34  		os.Exit(1)
    35  	}
    36  
    37  	fmt.Printf("Got results:\n%#v\n", resp.Response)
    38  }