#!/bin/bash # Agent H5 Validation Script - Prometheus Alerting # Validates all deliverables and success criteria set -euo pipefail GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}========================================${NC}" echo -e "${BLUE}Agent H5 Validation - Prometheus Alerting${NC}" echo -e "${BLUE}========================================${NC}" echo "" PASS=0 FAIL=0 WARN=0 check() { local name=$1 local command=$2 local expected=$3 result=$(eval "$command" 2>/dev/null || echo "ERROR") if [[ "$result" == "$expected" ]] || [[ "$result" =~ $expected ]]; then echo -e "${GREEN}✓${NC} $name" PASS=$((PASS + 1)) return 0 else echo -e "${RED}✗${NC} $name (Expected: $expected, Got: $result)" FAIL=$((FAIL + 1)) return 1 fi } check_exists() { local name=$1 local file=$2 if [[ -f "$file" ]]; then echo -e "${GREEN}✓${NC} $name exists" PASS=$((PASS + 1)) return 0 else echo -e "${RED}✗${NC} $name does not exist: $file" FAIL=$((FAIL + 1)) return 1 fi } check_contains() { local name=$1 local file=$2 local pattern=$3 if grep -q "$pattern" "$file" 2>/dev/null; then echo -e "${GREEN}✓${NC} $name contains '$pattern'" PASS=$((PASS + 1)) return 0 else echo -e "${RED}✗${NC} $name does not contain '$pattern'" FAIL=$((FAIL + 1)) return 1 fi } echo -e "${BLUE}1. File Deliverables${NC}" echo "--------------------" check_exists "Production alerts file" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" check_exists "AlertManager config" "/home/jgrusewski/Work/foxhunt/config/prometheus/alertmanager-production.yml" check_exists "Test suite script" "/home/jgrusewski/Work/foxhunt/scripts/test_alerting.sh" check_exists "Completion report" "/home/jgrusewski/Work/foxhunt/AGENT_H5_PROMETHEUS_ALERTING_COMPLETE.md" check_exists "Quick reference" "/home/jgrusewski/Work/foxhunt/PROMETHEUS_ALERTING_QUICK_REFERENCE.md" echo "" echo -e "${BLUE}2. Critical Alert Definitions${NC}" echo "------------------------------" check_contains "P99 Latency API Gateway alert" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "CriticalP99LatencyAPIGateway" check_contains "P99 Latency Trading Service alert" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "CriticalP99LatencyTradingService" check_contains "Service Down alert" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "CriticalServiceDown" check_contains "Memory Growth alert" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "CriticalMemoryGrowth" check_contains "PostgreSQL Down alert" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "CriticalPostgreSQLDown" echo "" echo -e "${BLUE}3. Alert Threshold Configuration${NC}" echo "--------------------------------" check_contains "P99 >100ms threshold" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "> 0.1" check_contains "Error rate >1% threshold" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "> 0.01" check_contains "Memory growth >10% threshold" "/home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml" "> 0.10" echo "" echo -e "${BLUE}4. AlertManager Configuration${NC}" echo "------------------------------" check_contains "Critical latency receiver" "/home/jgrusewski/Work/foxhunt/config/prometheus/alertmanager-production.yml" "critical-latency" check_contains "Critical service down receiver" "/home/jgrusewski/Work/foxhunt/config/prometheus/alertmanager-production.yml" "critical-service-down" check_contains "Critical memory receiver" "/home/jgrusewski/Work/foxhunt/config/prometheus/alertmanager-production.yml" "critical-memory" check_contains "Slack notification config" "/home/jgrusewski/Work/foxhunt/config/prometheus/alertmanager-production.yml" "slack_configs" check_contains "Inhibition rules" "/home/jgrusewski/Work/foxhunt/config/prometheus/alertmanager-production.yml" "inhibit_rules" echo "" echo -e "${BLUE}5. Prometheus Integration${NC}" echo "-------------------------" check "Prometheus is running" "curl -s http://localhost:9090/-/healthy" "Prometheus Server is Healthy" check "Alert rules loaded" "curl -s http://localhost:9090/api/v1/rules | jq '.data.groups | length' | tr -d ' '" "[0-9]+" PRODUCTION_GROUPS=$(curl -s http://localhost:9090/api/v1/rules | jq '.data.groups[] | select(.file | contains("production-alerts")) | .name' | wc -l) if [[ $PRODUCTION_GROUPS -ge 8 ]]; then echo -e "${GREEN}✓${NC} Production alert groups loaded: $PRODUCTION_GROUPS" PASS=$((PASS + 1)) else echo -e "${RED}✗${NC} Production alert groups loaded: $PRODUCTION_GROUPS (expected: 8)" FAIL=$((FAIL + 1)) fi echo "" echo -e "${BLUE}6. Alert Count Verification${NC}" echo "---------------------------" LATENCY_ALERTS=$(grep -c "CriticalP99Latency" /home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml || echo 0) ERROR_ALERTS=$(grep -c "ErrorRate" /home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml || echo 0) MEMORY_ALERTS=$(grep -c "Memory" /home/jgrusewski/Work/foxhunt/config/prometheus/rules/production-alerts.yml || echo 0) echo "Latency alerts defined: $LATENCY_ALERTS" echo "Error rate alerts defined: $ERROR_ALERTS" echo "Memory alerts defined: $MEMORY_ALERTS" if [[ $LATENCY_ALERTS -ge 3 && $ERROR_ALERTS -ge 3 && $MEMORY_ALERTS -ge 3 ]]; then echo -e "${GREEN}✓${NC} Sufficient alert coverage" PASS=$((PASS + 1)) else echo -e "${YELLOW}⚠${NC} Alert coverage may be insufficient" WARN=$((WARN + 1)) fi echo "" echo -e "${BLUE}7. Test Suite Validation${NC}" echo "------------------------" if [[ -x /home/jgrusewski/Work/foxhunt/scripts/test_alerting.sh ]]; then echo -e "${GREEN}✓${NC} Test suite is executable" PASS=$((PASS + 1)) else echo -e "${RED}✗${NC} Test suite is not executable" FAIL=$((FAIL + 1)) fi TEST_SECTIONS=$(grep -c "echo -e.*BLUE.*[0-9]\\." /home/jgrusewski/Work/foxhunt/scripts/test_alerting.sh || echo 0) if [[ $TEST_SECTIONS -ge 8 ]]; then echo -e "${GREEN}✓${NC} Test suite has $TEST_SECTIONS test sections" PASS=$((PASS + 1)) else echo -e "${YELLOW}⚠${NC} Test suite has only $TEST_SECTIONS test sections (expected: 8)" WARN=$((WARN + 1)) fi echo "" echo -e "${BLUE}8. False Positive Check${NC}" echo "-----------------------" FIRING_ALERTS=$(curl -s http://localhost:9090/api/v1/alerts | jq '[.data.alerts[] | select(.state == "firing")] | length') if [[ $FIRING_ALERTS -eq 0 ]]; then echo -e "${GREEN}✓${NC} No false positive alerts firing (system healthy)" PASS=$((PASS + 1)) else echo -e "${YELLOW}⚠${NC} $FIRING_ALERTS alert(s) currently firing - review required" WARN=$((WARN + 1)) fi echo "" echo -e "${BLUE}9. Documentation Completeness${NC}" echo "------------------------------" COMPLETION_LINES=$(wc -l < /home/jgrusewski/Work/foxhunt/AGENT_H5_PROMETHEUS_ALERTING_COMPLETE.md) REFERENCE_LINES=$(wc -l < /home/jgrusewski/Work/foxhunt/PROMETHEUS_ALERTING_QUICK_REFERENCE.md) if [[ $COMPLETION_LINES -ge 300 ]]; then echo -e "${GREEN}✓${NC} Completion report is comprehensive ($COMPLETION_LINES lines)" PASS=$((PASS + 1)) else echo -e "${YELLOW}⚠${NC} Completion report may be incomplete ($COMPLETION_LINES lines)" WARN=$((WARN + 1)) fi if [[ $REFERENCE_LINES -ge 200 ]]; then echo -e "${GREEN}✓${NC} Quick reference is comprehensive ($REFERENCE_LINES lines)" PASS=$((PASS + 1)) else echo -e "${YELLOW}⚠${NC} Quick reference may be incomplete ($REFERENCE_LINES lines)" WARN=$((WARN + 1)) fi echo "" echo -e "${BLUE}========================================${NC}" echo -e "${BLUE}Validation Summary${NC}" echo -e "${BLUE}========================================${NC}" echo -e "${GREEN}Passed:${NC} $PASS" echo -e "${YELLOW}Warnings:${NC} $WARN" echo -e "${RED}Failed:${NC} $FAIL" echo "" TOTAL=$((PASS + WARN + FAIL)) SCORE=$(echo "scale=1; $PASS * 100 / $TOTAL" | bc) echo -e "Score: ${SCORE}%" echo "" if [[ $FAIL -eq 0 ]]; then echo -e "${GREEN}✓ VALIDATION PASSED${NC}" echo "Agent H5 successfully delivered production alerting system" exit 0 else echo -e "${RED}✗ VALIDATION FAILED${NC}" echo "Review failed checks above" exit 1 fi