Lab Info in CLI

Contents


Why Am I Doing All this?


Some time ago I decided to try to decrease my context(task) switching between different tools and programs when I am working.

I see that most of my colleagues rely on the browser or third party applications heavily for certain tasks. In my opinion, some of those tasks can be performed from the CLI.

For example:

  • For managing different networking devices, RoyalTX seems to be one of their favorite tools.
  • For navigating a bunch of folders and files, some have opted to use the browser with a third-party application.

The second example is a bit “crazy” for me, although I understand a newcomer or “junior” engineer opting for this option, my advice would be to start as soon as possible sharpening those Linux/CLI skills to accomplish such task.

Anyway, coming back to my main point, I dislike adding more more tools that increase context switching.

Therefore, my motivation to do as much as I can from my local terminal.

And, although there may already be Linux tools that can help me with all this, I chose to actually code with the purpose of practicing and improving.



Lab Info in CLI


Golang script for visualizing in a table format the devices in your lab.

The script is meant to be used for anyone who has a pool of devices that need frequent access.

The drive behind this was/is to automate repetitive and tedious tasks that are part of the role of a technical support engineer, such as:

  • Reviewing different webpages to know the IP addresses and credentials from my routers, switches and firewalls.
  • Having to copy and paste the information from those webpages into my terminal.

To accomplish this, the script is executed as a command-line-tool tool.

NOTES:

  • I am still working on making the script interactive so that I can SSH/ping by specifying a device (by item position) from the displayed table.

  • Yes, I could have copied that to my SSH config or DNS host file, but then, what do I learn? Where is the fun? :)



Requirements


  • Being able to compile Go source code. (Go installed on PC)
  • Being able to execute scripts in your local terminal.

NOTE:

I know, I know. Shame on me. It should come as a Docker image… I will complete it later on. Sorry about this one, I really wanted to post this asap since I have postponed it for loo long.



TLDR (Execution with Source Code)


  1. Make sure the source code and lab YAML file are in the same directory:
> ls
main.go    mylabfile.yaml
  1. Do the needful with the “go module”:
> go mod init labinfo
go: creating new go.mod: module labinfo
go: to add module requirements and sums:
	go mod tidy

> go mod tidy
go: finding module for package gopkg.in/yaml.v3
go: finding module for package github.com/olekukonko/tablewriter
go: found github.com/olekukonko/tablewriter in github.com/olekukonko/tablewriter v0.0.5
go: found gopkg.in/yaml.v3 in gopkg.in/yaml.v3 v3.0.1
  1. Compile your source code:
> go build -o labinfo
> ls
go.mod    go.sum    labinfo    main.go    mylabfile.yaml
  1. Execute your binary:
> ./labinfo
+----------+--------------------+---------+--------+---------+-------------+------------------+---------------+----------+----------+--------------+--------------+----------+----------+--------------+
|   TYPE   |        NAME        |   HW    |   SW   | VERSION |     IP      |      NOTES       | CLI-PROTOCOL  | CLI-PORT | CLI-USER | CLI-PASSWORD | GUI-PROTOCOL | GUI-PORT | GUI-USER | GUI-PASSWORD |
+----------+--------------------+---------+--------+---------+-------------+------------------+---------------+----------+----------+--------------+--------------+----------+----------+--------------+
| firewall | my-asa-gw          | FPR9300 | FTD    | 6.6     | 10.10.10.10 |  wrong_password  | ssh           | 22       | admin    | Admin123     | https        | 443      | admin    | Admin        |
| firewall | ANOTHER-ASA-FW     | FPR9300 | FTD    | 6.6     | 10.10.10.10 |  wrong_password  | ssh           | 22       | admin    | Admin123     | https        | 443      | admin    | Admin        |
| router   | my-router-calo     | ISR4431 | IOS-XE | 6.6     | 10.10.10.20 |  needs_a_reimage | ssh           | 22       | admin    | Admin123     | https        | 443      | admin    | Admin        |
| router   | my-router-brussels | ISR4431 | IOS-XE | 6.10    | 10.10.20.20 |  Booting loop    | ssh           | 22       | admin    | Admin123     | https        | 443      | admin    | Admin        |
| firewall | my-ftd             | ISR4432 | IOS-XE | 6.10    | 10.10.20.20 |  Booting loop    | ssh           | 22       | admin    | Admin123     | https        | 443      | admin    | Admin        |
| router   | my-router-krk      | ISR4432 | IOS-XE | 6.10    | 10.10.20.20 |  Booting loop    | ssh           | 22       | admin    | Admin123     | https        | 443      | admin    | Admin        |
+----------+--------------------+---------+--------+---------+-------------+------------------+---------------+----------+----------+--------------+--------------+----------+----------+--------------+


Current State


The source code parses successfully a local YAML file (mylabfile.yaml) and displays the lab info in a table format.

Of course, first, the user must create this YAML file that describes the lab(as inventory).

Once the lab inventory is represented in YAML, then the script can be used.

NOTE:

See the example below for the YAML file:

> cat mylabfile.yaml
- device:
  type: firewall
  name: my-asa-gw
  hardware: FPR9300
  software: FTD
  version: "6.6"
  ip: 10.10.10.10
  notes: " wrong_password"
  cli:
    - ssh
    - "22"
    - admin
    - Admin123
  gui:
    - https
    - "443"
    - admin
    - Admin

- device:
  type: firewall
  name: ANOTHER-ASA-FW
  hardware: FPR9300
  software: FTD
  version: "6.6"
  ip: 10.10.10.10
  notes: " wrong_password"
  cli:
    - ssh
    - "22"
    - admin
    - Admin123
  gui:
    - https
    - "443"
    - admin
    - Admin

- device:
  type: router
  name: my-router-calo
  hardware: ISR4431
  software: IOS-XE
  version: "6.6"
  ip: 10.10.10.20
  notes: " needs_a_reimage"
  cli:
    - ssh
    - "22"
    - admin
    - Admin123
  gui:
    - https
    - "443"
    - admin
    - Admin

- device:
  type: router
  name: my-router-brussels
  hardware: ISR4431
  software: IOS-XE
  version: "6.10"
  ip: 10.10.20.20
  notes: " Booting loop"
  cli:
    - ssh
    - "22"
    - admin
    - Admin123
  gui:
    - https
    - "443"
    - admin
    - Admin

- device:
  type: firewall
  name: my-ftd
  hardware: ISR4432
  software: IOS-XE
  version: "6.10"
  ip: 10.10.20.20
  notes: " Booting loop"
  cli:
    - ssh
    - "22"
    - admin
    - Admin123
  gui:
    - https
    - "443"
    - admin
    - Admin


- device:
  type: router
  name: my-router-krk
  hardware: ISR4432
  software: IOS-XE
  version: "6.10"
  ip: 10.10.20.20
  notes: " Booting loop"
  cli:
    - ssh
    - "22"
    - admin
    - Admin123
  gui:
    - https
    - "443"
    - admin
    - Admin


Execution Flow


  • The user creates a YAML file where the pool of devices is described. (See above example)

  • The user compiles the source code and gets a binary file to execute.

  • The user executes the binary and the pool of devices is displayed in a table format.



Caveats


  • The filename is currently hardcoded. (I have been busy lately, so I gotta fix it eventually)


Progress and Roadmap


  • Parse the YAML file from the local host. [DONE]
  • Display the parsed information in a table. [DONE]
  • Pass the YAML filename using flags instead of hardcoding it in the source code.

NOTE: I complete this script some weeks ago but since it is potentially part of a bigger project, that is why I have postpone some of the features (wow) mentioned in the above roadmap.


What Did I Learn?


  • How to parse YAML files that are stored locally.

  • How to work with some standard Go libraries.

  • How to work with some non-standard libraries. (Like one for table visualization)

  • “Perfect is the enemy of good”. It is not that I learned it, but I did not want to post this because it was incomplete, not meeting certain standards that I set for myself xD. So, I friend of mine “pinged” me with something similar in Python and he asked me to share mine as well with our colleagues. Thanks for the push Paisa!.



What Is Next?


Continue working, learning, improving on my solo coding journey… :)

 Share!

 
comments powered by Disqus