Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrContinue parser error continue input ErrContinue = errors.New("<continue input>") // ErrQuit parser error quit session ErrQuit = errors.New("<quit session>") )
var AddMetadata = &cobra.Command{ Use: "add", Short: "add user metadata", Long: "add user metadata", SilenceUsage: false, PreRun: func(cmd *cobra.Command, args []string) { if gremlinQuery == "" || key == "" || value == "" { logging.GetLogger().Error("All parameters are mantatory") os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err) os.Exit(1) } metadata := api.NewUserMetadata(gremlinQuery, key, value) if err := validator.Validate(metadata); err != nil { logging.GetLogger().Error(err) os.Exit(1) } if err := client.Create("usermetadata", &metadata); err != nil { logging.GetLogger().Error(err) os.Exit(1) } printJSON(metadata) }, }
AddMetadata skydive user-metadata add command
var AlertCmd = &cobra.Command{ Use: "alert", Short: "Manage alerts", Long: "Manage alerts", SilenceUsage: false, }
AlertCmd skydive alert root command
var AlertCreate = &cobra.Command{ Use: "create", Short: "Create alert", Long: "Create alert", Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } alert := types.NewAlert() alert.Name = alertName alert.Description = alertDescription alert.Expression = alertExpression alert.Trigger = alertTrigger alert.Action = alertAction if err := validator.Validate(alert); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } if err := client.Create("alert", &alert); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&alert) }, }
AlertCreate skydive alert creates command
var AlertDelete = &cobra.Command{ Use: "delete [alert]", Short: "Delete alert", Long: "Delete alert", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } if err := client.Delete("alert", args[0]); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } }, }
AlertDelete skydive alert delete command
var AlertGet = &cobra.Command{ Use: "get [alert]", Short: "Display alert", Long: "Display alert", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { var alert types.Alert client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.Get("alert", args[0], &alert); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&alert) }, }
AlertGet skydive alert get command
var AlertList = &cobra.Command{ Use: "list", Short: "List alerts", Long: "List alerts", Run: func(cmd *cobra.Command, args []string) { var alerts map[string]types.Alert client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } if err := client.List("alert", &alerts); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(alerts) }, }
AlertList skydive alert list command
var (
AuthenticationOpts shttp.AuthenticationOpts
)
AuthenticationOpts Authentication options
var CaptureCmd = &cobra.Command{ Use: "capture", Short: "Manage captures", Long: "Manage captures", SilenceUsage: false, }
CaptureCmd skdyive capture root command
var CaptureCreate = &cobra.Command{ Use: "create", Short: "Create capture", Long: "Create capture", PreRun: func(cmd *cobra.Command, args []string) { if nodeTID != "" { if gremlinQuery != "" { logging.GetLogger().Error("Options --node and --gremlin are exclusive") os.Exit(1) } gremlinQuery = fmt.Sprintf("g.V().Has('TID', '%s')", nodeTID) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } capture := api.NewCapture(gremlinQuery, bpfFilter) capture.Name = captureName capture.Description = captureDescription capture.Type = captureType capture.Port = port capture.HeaderSize = headerSize capture.RawPacketLimit = rawPacketLimit capture.ExtraTCPMetric = extraTCPMetric capture.SocketInfo = socketInfo if err := validator.Validate(capture); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } if err := client.Create("capture", &capture); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&capture) }, }
CaptureCreate skydive capture creates command
var CaptureDelete = &cobra.Command{ Use: "delete [capture]", Short: "Delete capture", Long: "Delete capture", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.Delete("capture", args[0]); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } }, }
CaptureDelete skydive capture delete command
var CaptureGet = &cobra.Command{ Use: "get [capture]", Short: "Display capture", Long: "Display capture", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { var capture api.Capture client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.Get("capture", args[0], &capture); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&capture) }, }
CaptureGet skydive capture get command
var CaptureList = &cobra.Command{ Use: "list", Short: "List captures", Long: "List captures", Run: func(cmd *cobra.Command, args []string) { var captures map[string]api.Capture client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.List("capture", &captures); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(captures) }, }
CaptureList skydive capture list command
var ClientCmd = &cobra.Command{ Use: "client", Short: "Skydive client", Long: "Skydive client", SilenceUsage: true, PersistentPreRun: func(cmd *cobra.Command, args []string) { cmd.Root().PersistentPreRun(cmd.Root(), args) if analyzerAddr != "" { config.GetConfig().Set("analyzers", analyzerAddr) } else { config.GetConfig().SetDefault("analyzers", "localhost:8082") } }, }
Client skydive client root command
var DeleteMetadata = &cobra.Command{ Use: "delete", Short: "delete user metadata", Long: "delete user metadata", SilenceUsage: false, PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err) os.Exit(1) } if err := client.Delete("usermetadata", args[0]); err != nil { logging.GetLogger().Error(err) } }, }
DeleteMetadata skydive user-metadata delete command
var PacketInjectionCreate = &cobra.Command{ Use: "create", Short: "create packet injection", Long: "create packet injection", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } packet := &api.PacketParamsReq{ Src: srcNode, Dst: dstNode, SrcIP: srcIP, SrcMAC: srcMAC, SrcPort: srcPort, DstIP: dstIP, DstMAC: dstMAC, DstPort: dstPort, Type: packetType, Payload: payload, ICMPID: id, Count: count, Interval: interval, } if err = validator.Validate(packet); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } if err := client.Create("injectpacket", &packet); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(packet) }, }
var PacketInjectionDelete = &cobra.Command{ Use: "delete [injection]", Short: "Delete injection", Long: "Delete packet injection", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.Delete("injectpacket", args[0]); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } }, }
var PacketInjectionGet = &cobra.Command{ Use: "get", Short: "get packet injection", Long: "get packet injection", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { var injection api.PacketParamsReq client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.Get("injectpacket", args[0], &injection); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&injection) }, }
var PacketInjectionList = &cobra.Command{ Use: "list", Short: "list packet injections", Long: "list packet injections", Run: func(cmd *cobra.Command, args []string) { var injections map[string]api.PacketParamsReq client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err.Error()) os.Exit(1) } if err := client.List("injectpacket", &injections); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(injections) }, }
var PacketInjectorCmd = &cobra.Command{ Use: "inject-packet", Short: "Inject packets", Long: "Inject packets", SilenceUsage: false, }
PacketInjectorCmd skydive inject-packet root command
var PcapCmd = &cobra.Command{ Use: "pcap", Short: "Import flows from PCAP file", Long: "Import flows from PCAP file", PreRun: func(cmd *cobra.Command, args []string) { if pcapTrace == "" { logging.GetLogger().Error("You need to specify a PCAP file") cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err) os.Exit(1) } file, err := os.Open(pcapTrace) if err != nil { logging.GetLogger().Critical(err) os.Exit(1) } defer file.Close() resp, err := client.Request("POST", "pcap", file, nil) if err != nil { logging.GetLogger().Critical(err) os.Exit(1) } if resp.StatusCode == http.StatusOK { fmt.Printf("%s was successfully imported\n", pcapTrace) } else { content, _ := ioutil.ReadAll(resp.Body) logging.GetLogger().Errorf("Failed to import %s: %s", pcapTrace, string(content)) os.Exit(1) } }, }
PcapCmd skydive pcap root command
var QueryCmd = &cobra.Command{ Use: "query [gremlin]", Short: "Issue Gremlin queries", Long: "Issue Gremlin queries", PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 || args[0] == "" { cmd.Usage() os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { gremlinQuery = args[0] queryHelper := client.NewGremlinQueryHelper(&AuthenticationOpts) switch outputFormat { case "json": data, err := queryHelper.QueryRaw(gremlinQuery) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } var out bytes.Buffer json.Indent(&out, data, "", "\t") out.WriteTo(os.Stdout) case "dot": header := make(http.Header) header.Set("Accept", "vnd.graphviz") resp, err := queryHelper.Request(gremlinQuery, header) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { data, _ := ioutil.ReadAll(resp.Body) logging.GetLogger().Errorf("%s: %s", resp.Status, string(data)) os.Exit(1) } bufio.NewReader(resp.Body).WriteTo(os.Stdout) case "pcap": header := make(http.Header) header.Set("Accept", "vnd.tcpdump.pcap") resp, err := queryHelper.Request(gremlinQuery, header) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { data, _ := ioutil.ReadAll(resp.Body) logging.GetLogger().Errorf("%s: %s", resp.Status, string(data)) os.Exit(1) } bufio.NewReader(resp.Body).WriteTo(os.Stdout) default: logging.GetLogger().Errorf("Invalid output format %s", outputFormat) os.Exit(1) } }, }
QueryCmd skydive topology query command
var ShellCmd = &cobra.Command{ Use: "shell", Short: "Shell Command Line Interface", Long: "Skydive Shell Command Line Interface, yet another shell", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { shellMain() }, }
ShellCmd skydive shell root command
var StatusCmd = &cobra.Command{ Use: "status", Short: "Show analyzer status", Long: "Show analyzer status", Run: func(cmd *cobra.Command, args []string) { client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } resp, err := client.Request("GET", "status", nil, nil) if err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { data, _ := ioutil.ReadAll(resp.Body) logging.GetLogger().Errorf("Failed to get status, %s: %s", resp.Status, data) os.Exit(1) } var status types.AnalyzerStatus if err := common.JSONDecode(resp.Body, &status); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&status) }, }
StatusShow shows an analyzer status
var TopologyCmd = &cobra.Command{ Use: "topology", Short: "Request on topology", Long: "Request on topology", SilenceUsage: false, }
TopologyCmd skydive topology root command
var TopologyRequest = &cobra.Command{ Use: "query", Short: "query topology [deprecated: use 'client query' instead]", Long: "query topology", Run: func(cmd *cobra.Command, args []string) { fmt.Fprintln(os.Stderr, "The 'client topology query' command is deprecated. Please use 'client query' instead") QueryCmd.Run(cmd, []string{gremlinQuery}) }, }
TopologyRequest skydive topology query command
var UserMetadataCmd = &cobra.Command{ Use: "user-metadata", Short: "Manage user metadata", Long: "Manage user metadata", SilenceUsage: false, }
UserMetadataCmd skydive user-metadata root command
var UserMetadataList = &cobra.Command{ Use: "list", Short: "List user metadata", Long: "List user metadata", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { var metadata map[string]api.UserMetadata client, err := client.NewCrudClientFromConfig(&AuthenticationOpts) if err != nil { logging.GetLogger().Critical(err) os.Exit(1) } if err := client.List("usermetadata", &metadata); err != nil { logging.GetLogger().Error(err) os.Exit(1) } printJSON(metadata) }, }
UserMetadataList skydive user-metadata list command
Functions ¶
func RegisterClientCommands ¶ added in v0.16.0
Types ¶
type Session ¶ added in v0.7.0
type Session struct {
// contains filtered or unexported fields
}
Session describes a shell session
func NewSession ¶ added in v0.7.0
NewSession creates a new shell session