191 lines
8.1 KiB
PHP
191 lines
8.1 KiB
PHP
<?php
|
|
/**
|
|
* @api-readonly
|
|
* Returns WeldLog trigger execution information from logs
|
|
*/
|
|
|
|
function getLatestLogFile() {
|
|
$date = date('Y-m-d');
|
|
$logFile = storage_path("logs/truncgil-{$date}.log");
|
|
if (!file_exists($logFile)) {
|
|
// Fallback to laravel.log if specific one doesn't exist
|
|
$logFile = storage_path("logs/laravel.log");
|
|
}
|
|
return $logFile;
|
|
}
|
|
|
|
$logFile = getLatestLogFile();
|
|
$entries = [];
|
|
|
|
if (file_exists($logFile)) {
|
|
// Read the last 2000 lines to find relevant entries
|
|
$command = "tail -n 2000 " . escapeshellarg($logFile);
|
|
$lines = shell_exec($command);
|
|
$lines = explode("\n", $lines);
|
|
$lines = array_reverse($lines); // Start from latest
|
|
|
|
foreach ($lines as $line) {
|
|
if (count($entries) >= 50) break; // Increased limit for general triggers
|
|
if (empty(trim($line))) continue;
|
|
|
|
// Try to extract timestamp - generic approach
|
|
$timestamp = 'N/A';
|
|
if (preg_match('/^\[(.*?)\]/', $line, $timeMatch)) {
|
|
$timestamp = $timeMatch[1];
|
|
} elseif (preg_match('/^(\d{1,2}\/\d{1,2}\/\d{4}, \d{1,2}:\d{2}\s?[AP]M)/', $line, $timeMatch)) {
|
|
$timestamp = $timeMatch[1];
|
|
}
|
|
|
|
// Pattern 1: Any Trigger Summary completion
|
|
if (preg_match('/=== (.*?) TRIGGER COMPLETED === (\{.*\})/', $line, $matches)) {
|
|
$triggerType = $matches[1];
|
|
$data = json_decode($matches[2], true);
|
|
$entries[] = [
|
|
'type' => 'SUMMARY',
|
|
'timestamp' => $data['timestamp'] ?? $timestamp,
|
|
'trigger_id' => $data['weld_log_id'] ?? ($data['id'] ?? 'N/A'),
|
|
'status' => 'COMPLETED',
|
|
'message' => "{$triggerType} Trigger execution completed",
|
|
'details' => $data
|
|
];
|
|
}
|
|
// Pattern 2: Individual trigger execution (WeldLog or others)
|
|
elseif (preg_match('/(?:WeldLog|System|Batch)?\s?Trigger\s?\[(.*?)\] (.*?) - (STARTED|COMPLETED) (\{.*\})/i', $line, $matches)) {
|
|
$order = $matches[1];
|
|
$process = $matches[2];
|
|
$status = $matches[3];
|
|
$data = json_decode($matches[4], true);
|
|
|
|
$entries[] = [
|
|
'type' => 'TRIGGER',
|
|
'timestamp' => $timestamp,
|
|
'trigger_id' => $data['weld_log_id'] ?? ($data['id'] ?? 'N/A'),
|
|
'status' => $status,
|
|
'message' => "({$order}) {$process}",
|
|
'details' => $data
|
|
];
|
|
}
|
|
// Pattern 3: Simple Trigger Start/Stop
|
|
elseif (preg_match('/Trigger (.*?) - (STARTED|COMPLETED) (\{.*\})/i', $line, $matches)) {
|
|
$process = $matches[1];
|
|
$status = $matches[2];
|
|
$data = json_decode($matches[3], true);
|
|
$entries[] = [
|
|
'type' => 'TRIGGER',
|
|
'timestamp' => $timestamp,
|
|
'trigger_id' => $data['weld_log_id'] ?? ($data['id'] ?? 'N/A'),
|
|
'status' => $status,
|
|
'message' => $process,
|
|
'details' => $data
|
|
];
|
|
}
|
|
// Pattern 4: Skipping trigger
|
|
elseif (stripos($line, 'Skipping trigger:') !== false) {
|
|
preg_match('/Skipping trigger: (.*?) (\{.*\})/i', $line, $matches);
|
|
if (count($matches) >= 3) {
|
|
$process = $matches[1];
|
|
$data = json_decode($matches[2], true);
|
|
$entries[] = [
|
|
'type' => 'SKIP',
|
|
'timestamp' => $timestamp,
|
|
'trigger_id' => $data['weld_log_id'] ?? ($data['id'] ?? 'N/A'),
|
|
'status' => 'SKIPPED',
|
|
'message' => "Skipped: {$process}",
|
|
'details' => $data
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="block block-rounded block-bordered">
|
|
<div class="block-header block-header-default">
|
|
<h3 class="block-title">
|
|
<i class="fa fa-bolt text-warning mr-5"></i> Recent Trigger Activities
|
|
</h3>
|
|
<div class="block-options">
|
|
<span class="badge badge-primary">Last 50 operations</span>
|
|
<button type="button" class="btn-block-option" onclick="fetchWeldLogTriggers()">
|
|
<i class="si si-refresh"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="block-content p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover table-vcenter mb-0" id="weld-log-triggers-table">
|
|
<thead>
|
|
<tr>
|
|
<th style="width: 180px;">Timestamp</th>
|
|
<th style="width: 100px;">Related ID</th>
|
|
<th>Process / Message</th>
|
|
<th style="width: 120px;" class="text-center">Status</th>
|
|
<th style="width: 100px;" class="text-center">Details</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
@forelse($entries as $index => $entry)
|
|
@php
|
|
$statusClass = 'secondary';
|
|
$status = strtoupper($entry['status']);
|
|
if ($status === 'COMPLETED' || $status === 'SUCCESS' || $status === 'EXECUTED') $statusClass = 'success';
|
|
if ($status === 'STARTED') $statusClass = 'info';
|
|
if ($status === 'SKIPPED') $statusClass = 'warning';
|
|
if ($status === 'FAILED') $statusClass = 'danger';
|
|
if ($status === 'QUEUED') $statusClass = 'gray';
|
|
|
|
$rowClass = $entry['type'] === 'SUMMARY' ? 'table-info font-w700' : '';
|
|
@endphp
|
|
<tr class="{{ $rowClass }}">
|
|
<td class="font-size-sm">{{ $entry['timestamp'] }}</td>
|
|
<td>
|
|
@if($entry['trigger_id'] !== 'N/A')
|
|
<span class="badge badge-light">#{{ $entry['trigger_id'] }}</span>
|
|
@else
|
|
-
|
|
@endif
|
|
</td>
|
|
<td>
|
|
@if($entry['type'] === 'SUMMARY')
|
|
<i class="fa fa-flag-checkered mr-5 text-info"></i>
|
|
@endif
|
|
{{ $entry['message'] }}
|
|
</td>
|
|
<td class="text-center">
|
|
<span class="badge badge-{{ $statusClass }} px-10">{{ $status }}</span>
|
|
</td>
|
|
<td class="text-center">
|
|
<button type="button" class="btn btn-sm btn-alt-secondary"
|
|
data-toggle="collapse" data-target="#details-{{ $index }}">
|
|
<i class="fa fa-search"></i>
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<tr class="collapse" id="details-{{ $index }}">
|
|
<td colspan="5" class="bg-gray-lighter">
|
|
<pre class="mb-0 font-size-xs text-dark" style="max-height: 250px; overflow: auto;">{{ json_encode($entry['details'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) }}</pre>
|
|
</td>
|
|
</tr>
|
|
@empty
|
|
<tr>
|
|
<td colspan="5" class="text-center py-4 text-muted">
|
|
<i class="fa fa-info-circle fa-2x mb-2"></i><br>
|
|
No recent trigger log entries found for today.
|
|
</td>
|
|
</tr>
|
|
@endforelse
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
#weld-log-triggers-table td {
|
|
vertical-align: middle;
|
|
}
|
|
.table-info {
|
|
background-color: #e3f2fd !important;
|
|
}
|
|
</style>
|