#!/bin/bash # Test Cross-Module Intelligence # Demonstrates how modules can reference session data SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" source "$SCRIPT_DIR/lib/common-functions.sh" source "$SCRIPT_DIR/lib/reference-db.sh" print_banner "Cross-Module Intelligence Test" if [ ! -f "$SYSREF_DB" ]; then print_error "Reference database not found. Run System Health Check first!" exit 1 fi print_section "Testing Health Metric Queries" # Test individual metrics echo "Memory Usage: $(db_get_health_metric 'MEMORY_USED_PERCENT')%" echo "CPU Load: $(db_get_health_metric 'CPU_LOAD_1MIN')" echo "Disk Usage: $(db_get_health_metric 'DISK_USED_PERCENT')%" echo "Network Interface: $(db_get_health_metric 'NETWORK_INTERFACE')" echo "Network MTU: $(db_get_health_metric 'NETWORK_MTU')" echo "TCP Retransmission: $(db_get_health_metric 'TCP_RETRANS_PERCENT')%" echo "SMART Status: $(db_get_health_metric 'DISK_SMART_STATUS')" echo "SSH Attacks Today: $(db_get_health_metric 'SSH_ATTACKS_TODAY')" echo "cPHulk Status: $(db_get_health_metric 'CPHULK_STATUS')" print_section "Testing Intelligence Functions" # Test system load check if db_is_system_under_load; then print_warning "System is currently under HIGH LOAD" echo " CPU Load: $(db_get_health_metric 'CPU_LOAD_1MIN') (cores: $(db_get_health_metric 'CPU_CORES'))" echo " Memory: $(db_get_health_metric 'MEMORY_USED_PERCENT')%" else print_success "System load is NORMAL" fi # Test network issues check if db_has_network_issues; then print_warning "Network issues DETECTED" echo " TCP Retransmission: $(db_get_health_metric 'TCP_RETRANS_PERCENT')%" echo " RX Errors: $(db_get_health_metric 'NETWORK_RX_ERRORS')" echo " TX Errors: $(db_get_health_metric 'NETWORK_TX_ERRORS')" else print_success "Network is HEALTHY" fi # Test attack detection if db_is_under_attack; then print_critical "System appears to be UNDER ATTACK" echo " Failed SSH attempts today: $(db_get_health_metric 'SSH_ATTACKS_TODAY')" echo " Total failed attempts: $(db_get_health_metric 'SSH_FAILED_ATTEMPTS_TOTAL')" else print_success "No active attacks detected" fi print_section "Cross-Module Intelligence Examples" echo "Example 1: Bot Analyzer can check if network is already problematic" echo " if db_has_network_issues; then" echo " # Adjust recommendations - network may be causing bot issues" echo " fi" echo "" echo "Example 2: MySQL Analyzer can check if system is under load" echo " if db_is_system_under_load; then" echo " # Slow queries might be due to overall system load, not just MySQL" echo " fi" echo "" echo "Example 3: Any module can check attack status" echo " if db_is_under_attack; then" echo " # Correlate findings with ongoing attacks" echo " fi" print_section "All Health Metrics" echo "Total health metrics stored: $(grep -c '^HEALTH|' "$SYSREF_DB")" echo "" echo "Sample (first 10):" db_get_all_health | head -10 print_success "Cross-module intelligence test complete!"