diff --git a/commands/netobserv b/commands/netobserv index cd66205d..bcb78b5f 100755 --- a/commands/netobserv +++ b/commands/netobserv @@ -1,8 +1,10 @@ #!/bin/bash source "./scripts/functions.sh" +source "./scripts/help.sh" source "./scripts/dependencies_check.sh" set +u + # e2e skips inputs if [ -z "${isE2E+x}" ]; then isE2E=false; fi # keep capture state @@ -46,7 +48,22 @@ maxTime="5m" # max bytes (default: 50MB) maxBytes=50000000 -function flows() { +if [[ ! "$*" =~ ^(.*)help|version(.*) ]]; then + required_yq_version="v0.0.0" + supported_archs="" + check_dependencies "$required_yq_version" "$supported_archs" +fi + +case "$1" in +*help) + help + exit 0 + ;; +*version) + version "$version" + exit 0 + ;; +*flows) case "$2" in "help") flows_usage @@ -59,9 +76,8 @@ function flows() { command="flows" ;; esac -} - -function packets() { + ;; +*packets) case "$2" in "help") packets_usage @@ -74,9 +90,8 @@ function packets() { command="packets" ;; esac -} - -function metrics() { + ;; +*metrics) case "$2" in "help") metrics_usage @@ -89,74 +104,58 @@ function metrics() { command="metrics" ;; esac -} - -if [[ ! "$*" =~ ^(.*)help|version(.*) ]]; then - required_yq_version="v0.0.0" - supported_archs="" - check_dependencies "$required_yq_version" "$supported_archs" -fi - -case "$1" in -"help") - # display Help - echo - echo "Netobserv allows you to capture flow, packets and metrics from your cluster." - echo "Find more information at: https://github.com/netobserv/network-observability-cli/" - echo - echo "Syntax: netobserv [flows|packets|metrics|follow|stop|copy|cleanup|version] [options]" - echo - echo "commands:" - echo " flows Capture flows information in JSON format using collector pod." - echo " Options:" - flows_usage - echo " packets Capture packets information in pcap format using collector pod." - echo " Options:" - packets_usage - echo " metrics Capture metrics information in Prometheus using a ServiceMonitor (OCP cluster only)." - echo " Options:" - metrics_usage - echo " follow Follow collector logs when running in background." - echo " stop Stop collection by removing agent daemonset." - echo " copy Copy collector generated files locally." - echo " cleanup Remove netobserv components and configurations." - echo " version Print software version." - echo - exit 0 ;; -"version") - # display version - echo "Netobserv CLI version $version" - exit 0 - ;; -"flows") - flows $* - ;; -"packets") - packets $* - ;; -"metrics") - metrics $* - ;; -"follow") - # run follow command - follow - exit 0 +*follow) + case "$2" in + "help") + follow_usage + exit 0 + ;; + *) + # run follow command + follow + exit 0 + ;; + esac ;; -"stop") - # run deleteDaemonset command - deleteDaemonset - exit 0 +*stop) + case "$2" in + "help") + stop_usage + exit 0 + ;; + *) + # run deleteDaemonset command + deleteDaemonset + exit 0 + ;; + esac ;; -"copy") - # run copy output command - copyOutput - exit 0 +*copy) + case "$2" in + "help") + copy_usage + exit 0 + ;; + *) + # run copy output command + copyOutput + exit 0 + ;; + esac ;; -"cleanup") - # run cleanup command - cleanup - exit 0 +*cleanup) + case "$2" in + "help") + cleanup_usage + exit 0 + ;; + *) + # run cleanup command + cleanup + exit 0 + ;; + esac ;; *) echo "Unknown command $1. Use 'netobserv help' to display options" diff --git a/docs/netobserv_cli.adoc b/docs/netobserv_cli.adoc index b26348b4..2f0e54ea 100644 --- a/docs/netobserv_cli.adoc +++ b/docs/netobserv_cli.adoc @@ -1,9 +1,12 @@ // Automatically generated by './scripts/generate-doc.sh'. Do not edit, or make the NETOBSERV team aware of the editions. :_mod-docs-content-type: REFERENCE + [id="network-observability-cli-usage_{context}"] = Network Observability CLI usage -You can use the The Network Observability CLI (`oc netobserv`) to pass command line arguments to capture flow data and packet data for further analysis, enable Network Observability Operator features or pass configuration options to the eBPF agent and flowlogs-pipeline. +You can use the The Network Observability CLI (`oc netobserv`) to pass command line arguments to capture flows data and packets data for further analysis, enable Network Observability Operator features or pass configuration options to the eBPF agent and `flowlogs-pipeline`. + +[id=cli-syntax_{context}] == Syntax The basic syntax for `oc netobserv` commands: @@ -14,15 +17,24 @@ $ oc netobserv [] [] [] <1> ---- <1> Feature options can only be used with the `oc netobserv flows` command. They cannot be used with the `oc netobserv packets` command. +[id=cli-basic-commands_{context}] == Basic commands [cols="3a,8a",options="header"] .Basic commands |=== | Command | Description | flows -| Capture flows information. For subcommands, see the "Flow capture subcommands" table. +| Capture flows information. For subcommands, see the "Flows capture options" table. | packets -| Capture packets data. For subcommands, see the "Packet capture subcommand" table. +| Capture packets data. For subcommands, see the "Packets capture options" table. +| metrics +| Capture metrics data. For subcommands, see the "Metrics capture options" table. +| follow +| Follow collector logs when running in background. +| stop +| Stop collection by removing agent daemonset. +| copy +| Copy collector generated files locally. | cleanup | Remove the Network Observability CLI components. | version @@ -31,8 +43,10 @@ $ oc netobserv [] [] [] <1> | Show help. |=== +[id=cli-reference-flows-capture-options_{context}] == Flows capture options -Flow capture has mandatory commands as well as additional options, such as enabling extra features about packet drops, DNS latencies, Round-trip time, and filtering. +flows capture has mandatory commands as well as additional options, such as enabling extra features about packet drops, DNS latencies, Round-trip time, and filtering. + .`oc netobserv flows` syntax [source,terminal] ---- @@ -52,7 +66,6 @@ $ oc netobserv flows [] [] |--background| run in background | false |--copy| copy the output files locally | prompt |--node-selector| capture on specific nodes | n/a -|--enable_filter| enable flow filter | false |--direction| filter direction | n/a |--cidr| filter CIDR | 0.0.0.0/0 |--protocol| filter protocol | n/a @@ -71,17 +84,19 @@ $ oc netobserv flows [] [] |--icmp_code| filter ICMP code | n/a |--peer_ip| filter peer IP | n/a |--drops| filter flows with only dropped packets | false -|--regexes| filter flows using regex | n/a +|--regexes| filter flows using regular expression | n/a |--interfaces| interfaces to monitor | n/a |=== -.Example running flow capture on TCP protocol and port 49051 with PacketDrop and RTT features enabled: +.Example running flows capture on TCP protocol and port 49051 with PacketDrop and RTT features enabled: [source,terminal] ---- $ oc netobserv flows --enable_pktdrop=true --enable_rtt=true --enable_filter=true --action=Accept --cidr=0.0.0.0/0 --protocol=TCP --port=49051 ---- +[id=cli-reference-packet-capture-options_{context}] == Packets capture options -You can filter packet capture data as same as flow capture using the filters. However, the features are not available here. +You can filter packets capture data as same as flows capture using the filters. +Note that the features, such as packets drop, dns, rtt, and network events, are only available for flows and metrics capture. .`oc netobserv packets` syntax [source,terminal] @@ -97,7 +112,6 @@ $ oc netobserv packets [