#!/usr/bin/env php
<?php
// Monitor existing weather polling system  
$warning_patterns = ['ERROR', 'FAILED', 'TIMEOUT', 'API_ERROR', 'EXCEPTION'];
$log_file = '/var/www/weather-alerts/logs/weather_poll.log';

// Check last hour for weather data (runs every 5 min, so more tolerant)
$recent = shell_exec("tail -100 $log_file | grep '" . date('Y-m-d H:', strtotime('-1 hour')) . "'");

$error_count = 0;
foreach($warning_patterns as $pattern) {
    $error_count += substr_count($recent, $pattern);
}

// Only alert if multiple errors (weather can tolerate some hiccups)
if($error_count > 3) {
    mail('support@datanetwork.tech', 
         'Weather System Warning', 
         "Weather monitoring detected $error_count issues in the last hour.\n\nRecent log entries:\n\n$recent");
}
?>