Suggested Steps

The CLI: Toolkit contains built-in steps that can help you to process data in most scenarios to get the correct data you need.

In this section, we will give you hints on combining the available parser steps with selector steps you could use immediately right after.

Note

A parser step converts a data structure into a consumable format for a selector step. That means that the output of a parser is the input of a selector. Make sure you know the output of a given step, to choose correctly the next one.

CLI Parser Steps:

Parse Ifconfig

The Parse Ifconfig has the following input/output data flow:

Input: str | List[str]
Output: dict

The selector steps that can take a dictionary as an input are:

Parse Line

The Parse Line has the following input/output data flow:

Input: str
Output: Iterable[Any]

If you provide arguments while using the Parse Line, you will get a dictionary. The selector steps that can take a dictionary as an input are:

Parse Proc/net/snmp

The Parse Proc/net/snmp has the following input/output data flow:

Input: List[str] | str
Output: dict

The selector steps that can take a dictionary as an input are:

Parse Sectional Rows

The Parse Sectional Rows has the following input/output data flow:

Input: List[str] | dict
Output: dict

The selector steps that can take a dictionary as an input are:

Parse Netstat

The Parse Netstat has the following input/output data flow:

Input: str | List[str]
Output: dict

The selector steps that can take a dictionary as an input are:

Parse Table Column

The Parse Table Column has the following input/output data flow:

Input: str | List[str]
Output: List[dict]

The selector step that can take a list of dictionaries as an input is:

Parse Table Row

The Parse Table Row has the following input/output data flow:

Input: List[str]
Output: dict

The selector steps that can take a dictionary as an input are:

JC

The JC should be your preferred parser when you use the CLI: Toolkit. It converts the output of many standard Unix command outputs to dictionaries or lists of dictionaries. It has the following input/output data flow:

Input: str | bytes | Iterable
Output: dict | list[dict] | Iterable[dict]

The selector steps that take a dictionary as an input are:

Some Examples of Steps Combinations

Next, you can see some examples on how to combine steps to retrive especific data.

Example using the Parse Proc/net/snmp step

Let’s say you need to execute the following command:

cat /proc/net/snmp

Since this command returns the output of the snmp stats, you could parse the data using the Parse Proc/net/snmp and select some specific information by using the JSONPath selector and get the IcmpMsg data.

low_code:
  id: procnet
  version: 2
  steps:
    - ssh:
        command: cat /proc/net/snmp
    - parse_proc_net_snmp
    - jsonpath:
        value: $..IcmpMsg

Example using the Parse Table Column step

Let’s say you need to execute the following command:

netstat -rn

You could parse the data using the Parse Table Column and select some specific information by using the Select Table Item selector to the Gateway item.

low_code:
  id: netstat
  version: 2
  steps:
    - ssh:
        command: netstat -rn
    - parse_table_column:
        skip_lines_start: 1
        skip_lines_end: 0
        columns: 7
    - select_table_item:
        index:
          - 1

Example using the Parse Line

Let’s say you need to execute the following command:

/usr/bin/lscpu

You could parse the data using the Parse Line and select some specific information by using the Select Table Item selector to the Model information.

low_code:
  id: regex_parse_line
  version: 2
  steps:
    - ssh:
        command: /usr/bin/lscpu
    - parse_line:
        split_type: colon
        key: from_output
    - regex_select_table:
        regex: "Model"