Skip to tutorial content
Rate module Not yet rated

Collecting and Parsing Data

4 min read
On this page

In this lesson, you will learn:

  • How to read a configuration file
  • How to parse key and value lines
  • Handling missing values

πŸ” Quick look back: Last time: Designing the Identification Section. You learned how the archiver’s identification section finds the app.

1 The Problem: The Values Live in a Config File

The archiver’s version, port and archive path aren’t in any command output. They’re in /opt/snwr-archiver/archiver.conf. So:

  • The pattern must read the file.
  • Then pick out three values.

🎯 The problem: The values the CMDB needs live in a config file.

πŸ‘‰ The fix: Use Parse File with a key-and-value strategy.

Table of config lines and values.
Figure 1. What the pattern reads from archiver.conf.

2 Reading and parsing

  1. Add a Parse File step for /opt/snwr-archiver/archiver.conf.
  2. Use the key-and-value strategy with ‘=’ as the separator.
  3. Map each key to a variable.

The account needs read access to the file. Add it to the privilege matrix if needed.

3 Missing values

  • Decide what happens if a key is missing: leave the field empty, don’t guess.
  • Log a warning so it’s visible in debugging.

4 Project Clear View: How We Implemented It

πŸ“ Situation: The values were in archiver.conf.

🧭 Decision: Parse the file into variables.

πŸ› οΈ Steps we took:

  1. Added a Parse File step for archiver.conf.
  2. Used key and value with ‘=’.
  3. Mapped version, listen_port, archive_path and db_host.
  4. Confirmed snowdisc can read the file.

βœ… What we verified:

  • All four variables fill in Debug.
  • Priya added read access to the privilege matrix.

πŸ“ Evidence: The parse step, part of the archiver pattern.

5 Quick recap

  • Parse File reads a file on the target.
  • Key and value is simplest for ‘key=value’ lines.
  • The account needs read access to the file.
  • Leave missing values empty; don’t guess.

6 Check yourself

Think of your answer first. Then tap to check.

1 Which operation reads archiver.conf? Show answer

Parse File.

2 Which separator does the file use? Show answer

The equals sign (=).

3 What if a key is missing? Show answer

Leave the field empty and log a warning.

Nice work! The pattern collects the archiver’s values. πŸŽ‰
Next up: Populating Attributes and Relationships

Was this lesson helpful?

Have a question or doubt?

Ask here and get help from instructors and fellow learners.

0 / 300

Only logged-in learners can post.