Challenge

Problem

Configuration files are essential for managing infrastructure. This drill teaches you to parse nested JSON configuration data, navigate complex structures, extract attributes, filter by status, and transform data for reporting. You'll learn nested hash navigation, filtering, grouping, and data transformation—essential skills for building DevOps tools and configuration management systems.

Difficulty: Intermediate

Instructions

  1. Read server configuration from servers.json
  2. Parse JSON document
  3. Extract server information:
    • hostname
    • ip_address
    • port
    • status
    • environment (from parent structure)
  4. Filter to only include servers where status='active'
  5. Group servers by environment
  6. Sort environments alphabetically, and servers within each environment by hostname
  7. Print formatted report with summary

Files

Editable
Read-only

Hints

Hint 1

JSON.parse(File.read(file)) parses the JSON file

Hint 2

Navigate with data['environments'].each

Hint 3

Access nested values: server['hostname'], server['ip']

Hint 4

Use 'next unless condition' to filter servers

Hint 5

Hash.new { |h, k| h[k] = [] } creates hash with array defaults

Hint 6

array.sort_by! { |item| item[:key] } sorts array in place

Hint 7

hash.keys.sort sorts environment names alphabetically

Ruby 3.4

Provided Files (Read-only)

1. Correct server report

Input:
parse_server_config('servers.json')
Expected Output:
SERVER CONFIGURATION REPORT
==================================================
Environment: production
  web-prod-01 - 192.168.1.10:8080
  web-prod-02 - 192.168.1.11:8080

Environment: staging
  db-stage-01 - 10.0.1.20:5432
  web-stage-01 - 10.0.1.10:8080

--------------------------------------------------
Total Active Servers: 4
Environments: 2

2. Filters inactive servers

Input:
parse_server_config('servers.json')
puts 'Filtered OK'
Expected Output:
SERVER CONFIGURATION REPORT
==================================================
Environment: production
  web-prod-01 - 192.168.1.10:8080
  web-prod-02 - 192.168.1.11:8080

Environment: staging
  db-stage-01 - 10.0.1.20:5432
  web-stage-01 - 10.0.1.10:8080

--------------------------------------------------
Total Active Servers: 4
Environments: 2
Filtered OK

3. Servers sorted by hostname

Input:
parse_server_config('servers.json')
puts 'Sorted OK'
Expected Output:
SERVER CONFIGURATION REPORT
==================================================
Environment: production
  web-prod-01 - 192.168.1.10:8080
  web-prod-02 - 192.168.1.11:8080

Environment: staging
  db-stage-01 - 10.0.1.20:5432
  web-stage-01 - 10.0.1.10:8080

--------------------------------------------------
Total Active Servers: 4
Environments: 2
Sorted OK
+ 2 hidden test cases