===============================================================================
LABORATORY EXERCISE 04: STEP-BY-STEP EXECUTION GUIDE
===============================================================================

ENVIRONMENT INITIALIZATION:
---------------------------
1. Extract all files from this archive into a dedicated folder.
2. Open a terminal in that folder and run:
      docker compose up -d --build
3. Ensure all 4 containers are UP:
      docker compose ps


-------------------------------------------------------------------------------
TASK 1: Add Monitored Host & Verify Agent Availability (2 Marks)
-------------------------------------------------------------------------------
1. Access Zabbix Web UI in your browser: http://localhost:8080
   - Username: Admin
   - Password: zabbix
2. Verify target application is responding:
   - Open http://localhost:5000 in browser or run: curl http://localhost:5000
3. Add Monitored Host in Zabbix:
   - Go to: Data collection -> Hosts -> Create host
   - Host name: target-app-server
   - Templates: Linux by Zabbix agent
   - Host groups: Linux servers
   - Interfaces: Click 'Add' -> Select 'Agent'
       * Interface type: DNS
       * DNS name: target-app-server
       * Port: 10050
4. Verification:
   - Click 'Add'.
   - Wait 30-60 seconds and refresh 'Data collection -> Hosts'.
   - Confirm the 'ZBX' green indicator light is illuminated for 'target-app-server'.


-------------------------------------------------------------------------------
TASK 2: Configure Monitoring Items for CPU, RAM, & Network (3 Marks)
-------------------------------------------------------------------------------
1. In Zabbix Web UI, navigate to: Monitoring -> Latest data
2. In the Host filter, select: target-app-server
3. Verify metrics actively being reported by the template items:
   - CPU Utilization:     system.cpu.util
   - Memory Utilization:  vm.memory.utilization
   - Network In Traffic:  net.if.in[eth0]
   - Network Out Traffic: net.if.out[eth0]
4. Click 'Graph' next to any metric to display real-time performance curves.


-------------------------------------------------------------------------------
TASK 3: Analyze Supplied Anomaly & Identify Bottleneck (3 Marks)
-------------------------------------------------------------------------------
1. Trigger a bottleneck anomaly via application HTTP endpoints:
   - For CPU Bottleneck:    http://localhost:5000/anomaly/cpu
   - For Memory Bottleneck: http://localhost:5000/anomaly/memory
   (You can open these URLs in your browser or run: curl http://localhost:5000/anomaly/cpu)

2. Analyze Anomaly in Zabbix:
   - Go to: Monitoring -> Hosts -> Graphs (or Latest Data).
   - Observe performance graphs over the 3-minute window.

3. Identify Resource Bottleneck:
   - If CPU graph spikes near 100% while RAM remains flat: 
     Bottleneck identified as CPU Saturation.
   - If RAM graph spikes above 85% while CPU load remains low: 
     Bottleneck identified as RAM Exhaustion.


-------------------------------------------------------------------------------
TASK 4: Configure Trigger & Demonstrate Problem Event (2 Marks)
-------------------------------------------------------------------------------
1. Configure Custom Trigger in Zabbix:
   - Navigate to: Data collection -> Hosts -> target-app-server -> Triggers
   - Click 'Create trigger' (top right).
   - Name: High CPU Utilization Detected (>75%)
   - Severity: High
   - Expression: last(/target-app-server/system.cpu.util) > 75
   - Click 'Add'.

2. Demonstrate Problem Event:
   - Trigger the test workload endpoint:
     http://localhost:5000/trigger/test 
     (or run: curl http://localhost:5000/trigger/test)
   
3. Verify Alert Activation:
   - Go to: Monitoring -> Problems
   - Within 30 seconds, a red "PROBLEM" event titled 
     'High CPU Utilization Detected (>75%)' will appear.
   - After 120 seconds (test duration ends), verify that the event automatically 
     clears and transitions to "RESOLVED".
===============================================================================
