config('app.alert_logs_period'), ]); if (!$options['alert_logs_names']) { $this->error('['.date('Y-m-d H:i:s').'] No logs to monitor selected'); return; } if (!$options['alert_logs_period']) { $this->error('['.date('Y-m-d H:i:s').'] No logs monitoring period set'); return; } $logs = \App\ActivityLog::whereIn('log_name', $options['alert_logs_names']) ->where('created_at', '>=', \Carbon\Carbon::now()->modify('-1 '.$options['alert_logs_period'])->toDateTimeString()) ->where('created_at', '<', $now->toDateTimeString()) ->get(); if (!count($logs)) { $this->line('['.date('Y-m-d H:i:s').'] No new log records found for the last '.$options['alert_logs_period']); return; } $names = $logs->pluck('log_name')->unique()->toArray(); $text = 'Logs having new records for the last '.$options['alert_logs_period'].':'; foreach ($names as $name) { $text .= '
'.\App\ActivityLog::getLogTitle($name).'
'; foreach ($logs as $log) { if ($log->log_name != $name) { continue; } $text .= '● ['.$log->created_at.'] '.$log->getEventDescription().' '.$log->properties.'
'; } } // Send alert. \MailHelper::sendAlertMail($text, 'Logs Monitoring'); $this->line($text); $this->info('['.date('Y-m-d H:i:s').'] Monitoring finished'); } }