1
0
mirror of https://github.com/mailcow/mailcow-dockerized.git synced 2025-01-08 04:05:03 +02:00

[Web] add crontasks logs

This commit is contained in:
FreddleSpl0it 2023-07-06 15:53:33 +02:00 committed by DerLinkman
parent f8647bb15e
commit b176585a9c
No known key found for this signature in database
GPG Key ID: F109FD97469550A2
4 changed files with 110 additions and 0 deletions

View File

@ -2537,6 +2537,20 @@ function get_logs($application, $lines = false) {
return $data_array;
}
}
if ($application == "cron-mailcow") {
if (isset($from) && isset($to)) {
$data = $redis->lRange('CRON_LOG', $from - 1, $to - 1);
}
else {
$data = $redis->lRange('CRON_LOG', 0, $lines);
}
if ($data) {
foreach ($data as $json_line) {
$data_array[] = json_decode($json_line, true);
}
return $data_array;
}
}
if ($application == "postfix-mailcow") {
if (isset($from) && isset($to)) {
$data = $redis->lRange('POSTFIX_MAILLOG', $from - 1, $to - 1);

View File

@ -814,6 +814,66 @@ jQuery(function($){
hideTableExpandCollapseBtn('#tab-dovecot-logs', '#dovecot_log');
});
}
function draw_cron_logs() {
// just recalc width if instance already exists
if ($.fn.DataTable.isDataTable('#cron_log') ) {
$('#cron_log').DataTable().columns.adjust().responsive.recalc();
return;
}
var table = $('#cron_log').DataTable({
responsive: true,
processing: true,
serverSide: false,
stateSave: true,
pageLength: log_pagination_size,
dom: "<'row'<'col-sm-12 col-md-6'f><'col-sm-12 col-md-6'l>>" +
"tr" +
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
language: lang_datatables,
order: [[0, 'desc']],
initComplete: function(){
hideTableExpandCollapseBtn('#tab-cron-logs', '#cron_log');
},
ajax: {
type: "GET",
url: "/api/v1/get/logs/cron",
dataSrc: function(data){
return process_table_data(data, 'general_syslog');
}
},
columns: [
{
title: lang.time,
data: 'time',
defaultContent: '',
createdCell: function(td, cellData) {
createSortableDate(td, cellData)
}
},
{
title: lang.task,
data: 'task',
defaultContent: ''
},
{
title: lang.priority,
data: 'priority',
defaultContent: ''
},
{
title: lang.message,
data: 'message',
defaultContent: '',
className: 'dtr-col-md text-break'
}
]
});
table.on('responsive-resize', function (e, datatable, columns){
hideTableExpandCollapseBtn('#tab-cron-logs', '#cron_log');
});
}
function rspamd_pie_graph() {
$.ajax({
url: '/api/v1/get/rspamd/actions',
@ -1219,6 +1279,7 @@ jQuery(function($){
onVisible("[id^=ui_logs]", () => draw_ui_logs());
onVisible("[id^=sasl_logs]", () => draw_sasl_logs());
onVisible("[id^=netfilter_log]", () => draw_netfilter_logs());
onVisible("[id^=cron_log]", () => draw_cron_logs());
onVisible("[id^=rspamd_history]", () => draw_rspamd_history());
onVisible("[id^=rspamd_donut]", () => rspamd_pie_graph());

View File

@ -947,6 +947,17 @@ if (isset($_GET['query'])) {
}
echo (isset($logs) && !empty($logs)) ? json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) : '{}';
break;
case "cron":
// 0 is first record, so empty is fine
if (isset($extra)) {
$extra = preg_replace('/[^\d\-]/i', '', $extra);
$logs = get_logs('cron-mailcow', $extra);
}
else {
$logs = get_logs('cron-mailcow');
}
echo (isset($logs) && !empty($logs)) ? json_encode($logs, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) : '{}';
break;
case "postfix":
// 0 is first record, so empty is fine
if (isset($extra)) {

View File

@ -16,6 +16,7 @@
<li role="presentation"><button class="dropdown-item" data-bs-target="#tab-acme-logs" aria-selected="false" aria-controls="tab-acme-logs" role="tab" data-bs-toggle="tab">ACME</button></li>
<li role="presentation"><button class="dropdown-item" data-bs-target="#tab-api-logs" aria-selected="false" aria-controls="tab-api-logs" role="tab" data-bs-toggle="tab">API</button></li>
<li role="presentation"><button class="dropdown-item" data-bs-target="#tab-api-rl" aria-selected="false" aria-controls="tab-api-rl" role="tab" data-bs-toggle="tab">Ratelimits</button></li>
<li role="presentation"><button class="dropdown-item" data-bs-target="#tab-cron-logs" aria-selected="false" aria-controls="tab-api-rl" role="tab" data-bs-toggle="tab">Crontasks</button></li>
<li role="presentation"><span class="dropdown-header fs-6">{{ lang.debug.external_logs }}</span></li>
<li role="presentation"><button class="dropdown-item" data-bs-target="#tab-rspamd-history" aria-selected="false" aria-controls="tab-rspamd-history" role="tab" data-bs-toggle="tab">Rspamd</button></li>
<li role="presentation"><span class="dropdown-header fs-6">{{ lang.debug.static_logs }}</span></li>
@ -625,6 +626,29 @@
</div>
</div>
<div role="tabpanel" class="tab-pane" id="tab-cron-logs">
<div class="debug-log-info">{{ lang.debug.log_info|format(log_lines+1)|raw }}</div>
<div class="card">
<div class="card-header d-flex align-items-center fs-5">
<span class="mt-2 ms-2">Crontasks</span>
<div class="btn-group ms-auto">
<button class="btn btn-sm btn-secondary refresh_table" data-draw="draw_cron_logs" data-table="cron_log">{{ lang.admin.refresh }}</button>
</div>
</div>
<div class="card-body">
<a class="btn btn-sm btn-secondary dropdown-toggle mb-4" data-bs-toggle="dropdown" href="#">{{ lang.mailbox.quick_actions }}</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item add_log_lines" data-post-process="general_syslog" data-table="cron_log" data-log-url="cron" data-nrows="100" href="#">+ 100</a></li>
<li><a class="dropdown-item add_log_lines" data-post-process="general_syslog" data-table="cron_log" data-log-url="cron" data-nrows="1000" href="#">+ 1000</a></li>
<li class="table_collapse_option"><hr class="dropdown-divider"></li>
<li class="table_collapse_option"><a class="dropdown-item" data-datatables-expand="cron_log" data-table="cron_log" href="#">{{ lang.datatables.expand_all }}</a></li>
<li class="table_collapse_option"><a class="dropdown-item" data-datatables-collapse="cron_log" data-table="cron_log" href="#">{{ lang.datatables.collapse_all }}</a></li>
</ul>
<table id="cron_log" class="table table-striped dt-responsive w-100"></table>
</div>
</div>
</div>
</div> <!-- /tab-content -->
</div> <!-- /col-md-12 -->
</div> <!-- /row -->