Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ClientCmd describes the skydive client root command ClientCmd = gclient.ClientCmd // CrudClient holds the client API CRUD client CrudClient *http.CrudClient )
var CaptureCmd = &cobra.Command{ Use: "capture", Short: "Manage captures", Long: "Manage captures", SilenceUsage: false, }
CaptureCmd skydive 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 captureQuery != "" { exitOnError(errors.New("Options --node and --gremlin are exclusive")) } captureQuery = fmt.Sprintf("g.V().Has('TID', '%s')", nodeTID) } }, Run: func(cmd *cobra.Command, args []string) { var layers flow.ExtraLayers if err := layers.Parse(extraLayers...); err != nil { exitOnError(err) } capture := api.NewCapture(captureQuery, bpfFilter) capture.Name = captureName capture.Description = captureDescription capture.Type = captureType capture.Port = port capture.SamplingRate = samplingRate capture.PollingInterval = pollingInterval capture.HeaderSize = headerSize capture.ExtraTCPMetric = extraTCPMetric capture.IPDefrag = ipDefrag capture.ReassembleTCP = reassembleTCP capture.LayerKeyMode = layerKeyMode capture.RawPacketLimit = rawPacketLimit capture.ExtraLayers = int(layers) capture.Target = target capture.TargetType = targetType if err := validator.Validate("capture", capture); err != nil { exitOnError(err) } var createOpts *http.CreateOptions if captureTTL != 0 { createOpts = &http.CreateOptions{ TTL: time.Duration(captureTTL) * time.Millisecond, } } if err := CrudClient.Create("capture", &capture, createOpts); err != nil { exitOnError(err) } 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) { for _, id := range args { if err := CrudClient.Delete("capture", id); err != nil { logging.GetLogger().Error(err) } } }, }
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 if err := CrudClient.Get("capture", args[0], &capture); err != nil { exitOnError(err) } 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 if err := CrudClient.List("capture", &captures); err != nil { exitOnError(err) } printJSON(captures) }, }
CaptureList skydive capture list command
var EdgeRuleCmd = &cobra.Command{ Use: "edge-rule", Short: "edge-rule", Long: "edge-rule", SilenceUsage: false, }
EdgeRuleCmd skydive edge rule root command
var EdgeRuleCreate = &cobra.Command{ Use: "create", Short: "create", Long: "create", SilenceUsage: false, PreRun: func(cmd *cobra.Command, args []string) { if relationType == "" { logging.GetLogger().Error("--relationtype is a required parameter") os.Exit(1) } }, Run: func(cmd *cobra.Command, args []string) { m, err := gclient.DefToMetadata(metadata, graph.Metadata{}) if err != nil { exitOnError(err) } m["RelationType"] = relationType edgeRule := &api.EdgeRule{ Name: name, Description: description, Src: src, Dst: dst, Metadata: m, } if err = validator.Validate("edgerule", edgeRule); err != nil { exitOnError(fmt.Errorf("Error while validating edge rule: %s", err)) } if err = CrudClient.Create("edgerule", &edgeRule, nil); err != nil { exitOnError(err) } printJSON(edgeRule) }, }
EdgeRuleCreate skydive edge create command
var EdgeRuleDelete = &cobra.Command{ Use: "delete", Short: "delete", Long: "delete", 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) { for _, id := range args { if err := CrudClient.Delete("edgerule", id); err != nil { logging.GetLogger().Error(err.Error()) } } }, }
EdgeRuleDelete skydive edge delete command
var EdgeRuleGet = &cobra.Command{ Use: "get", Short: "get", Long: "get", 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) { var edge api.EdgeRule if err := CrudClient.Get("edgerule", args[0], &edge); err != nil { exitOnError(err) } printJSON(&edge) }, }
EdgeRuleGet skydive edge get command
var EdgeRuleList = &cobra.Command{ Use: "list", Short: "list", Long: "list", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { var edges map[string]api.EdgeRule if err := CrudClient.List("edgerule", &edges); err != nil { exitOnError(err) } printJSON(edges) }, }
EdgeRuleList skydive edge list command
var NodeRuleCmd = &cobra.Command{ Use: "node-rule", Short: "node-rule", Long: "node-rule", SilenceUsage: false, }
NodeRuleCmd skydive node rule root command
var NodeRuleCreate = &cobra.Command{ Use: "create", Short: "create", Long: "create", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { m, err := gclient.DefToMetadata(metadata, graph.Metadata{}) if err != nil { exitOnError(err) } if action == "create" { if nodeName == "" || nodeType == "" { exitOnError(errors.New("Both --node-name and --node-type are required for 'create' node rules")) } m["Name"] = nodeName m["Type"] = nodeType } nodeRule := &api.NodeRule{ Name: name, Description: description, Metadata: m, Query: query, Action: action, } if err = validator.Validate("noderule", nodeRule); err != nil { exitOnError(fmt.Errorf("Error while validating node rule: %s", err)) } if err = CrudClient.Create("noderule", &nodeRule, nil); err != nil { exitOnError(err) } printJSON(nodeRule) }, }
NodeRuleCreate skydive node create command
var NodeRuleDelete = &cobra.Command{ Use: "delete", Short: "delete", Long: "delete", 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) { for _, id := range args { if err := CrudClient.Delete("noderule", id); err != nil { logging.GetLogger().Error(err.Error()) } } }, }
NodeRuleDelete skydive node delete command
var NodeRuleGet = &cobra.Command{ Use: "get", Short: "get", Long: "get", 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) { var node api.NodeRule if err := CrudClient.Get("noderule", args[0], &node); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(&node) }, }
NodeRuleGet skydive node get command
var NodeRuleList = &cobra.Command{ Use: "list", Short: "list", Long: "list", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { var nodes map[string]api.NodeRule if err := CrudClient.List("noderule", &nodes); err != nil { logging.GetLogger().Error(err.Error()) os.Exit(1) } printJSON(nodes) }, }
NodeRuleList skydive node list command
var PacketInjectionCreate = &cobra.Command{ Use: "create", Short: "create packet injection", Long: "create packet injection", SilenceUsage: false, Run: func(cmd *cobra.Command, args []string) { request, err := GetPacketInjectRequest() if err != nil { exitOnError(err) } packet := &api.PacketInjection{ Src: srcNode, Dst: dstNode, SrcPort: request.SrcPort, DstPort: request.DstPort, Type: request.Type, Payload: request.Payload, Pcap: request.Pcap, ICMPID: request.ICMPID, Count: request.Count, Interval: request.Interval, Mode: request.Mode, IncrementPayload: request.IncrementPayload, TTL: request.TTL, } if request.SrcIP != nil { packet.SrcIP = request.SrcIP.String() } if request.DstIP != nil { packet.DstIP = request.DstIP.String() } if request.SrcMAC != nil { packet.SrcMAC = request.SrcMAC.String() } if request.DstMAC != nil { packet.DstMAC = request.DstMAC.String() } if err = validator.Validate("packetinjection", packet); err != nil { exitOnError(err) } ttl := 5 * time.Second if packet.Interval != 0 { ttl = time.Duration(packet.Interval*packet.Count)*time.Millisecond + 5*time.Second } createOpts := &http.CreateOptions{TTL: ttl} if err := CrudClient.Create("injectpacket", &packet, createOpts); err != nil { exitOnError(err) } printJSON(packet) }, }
PacketInjectionCreate describes the command to create a packet injection
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) { for _, id := range args { if err := CrudClient.Delete("injectpacket", id); err != nil { logging.GetLogger().Error(err) } } }, }
PacketInjectionDelete describes the command to delete a packet injection
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.PacketInjection if err := CrudClient.Get("injectpacket", args[0], &injection); err != nil { exitOnError(err) } printJSON(&injection) }, }
PacketInjectionGet describes the command to retrieve a packet 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.PacketInjection if err := CrudClient.List("injectpacket", &injections); err != nil { exitOnError(err) } printJSON(injections) }, }
PacketInjectionList describes the command to list all the packet injections
var PacketInjectorCmd = &cobra.Command{ Use: "injection", Short: "Inject packets", Long: "Inject packets", Aliases: []string{"inject-packet"}, 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) { file, err := os.Open(pcapTrace) if err != nil { exitOnError(err) } defer file.Close() resp, err := CrudClient.Request("POST", "pcap", file, nil) if err != nil { exitOnError(err) } if resp.StatusCode == http.StatusAccepted { fmt.Printf("%s was successfully imported\n", pcapTrace) } else { content, _ := ioutil.ReadAll(resp.Body) exitOnError(fmt.Errorf("Failed to import %s: %s", pcapTrace, string(content))) } }, }
PcapCmd skydive pcap root command
var StatusCmd = &cobra.Command{ Use: "status", Short: "Show analyzer status", Long: "Show analyzer status", Run: func(cmd *cobra.Command, args []string) { resp, err := CrudClient.Request("GET", "status", nil, nil) if err != nil { exitOnError(err) } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { data, _ := ioutil.ReadAll(resp.Body) exitOnError(fmt.Errorf("Failed to get status, %s: %s", resp.Status, data)) } var status interface{} decoder := json.NewDecoder(resp.Body) if err := decoder.Decode(&status); err != nil { exitOnError(err) } printJSON(&status) }, }
StatusCmd implents the skydive 'status' command that return the status of an analyzer by quering its API
Functions ¶
func AddInjectPacketInjectFlags ¶ added in v0.27.0
AddInjectPacketInjectFlags add the command line flags for a packet injection
func GetPacketInjectRequest ¶ added in v0.27.0
func GetPacketInjectRequest() (*pi.PacketInjectionRequest, error)
GetPacketInjectRequest returns a packet injection request parsed from the command line flags
func RegisterClientCommands ¶ added in v0.16.0
RegisterClientCommands registers the 'client' CLI subcommands
Types ¶
This section is empty.