[Web] Fix Rspamd plot

master
André 2018-06-08 09:13:26 +02:00
parent 07c1a0bcd3
commit 82209196f5
2 changed files with 56 additions and 38 deletions

View File

@ -343,18 +343,13 @@ jQuery(function($){
var ft_paging = ft.use(FooTable.Paging) var ft_paging = ft.use(FooTable.Paging)
return ft_paging.totalRows; return ft_paging.totalRows;
}) })
}
}
});
}
function plot_rspamd() {
$.ajax({ $.ajax({
url: '/api/v1/get/rspamd/actions', url: '/api/v1/get/rspamd/actions',
success: function(data){ success: function(data){
var total = 0; var total = 0;
$(data).map(function(){total += this[1];}) $(data).map(function(){total += this[1];})
rspamd_labels = $.makeArray($(data).map(function(){return "<h5>" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%</h5>";})); rspamd_labels = $.makeArray($(data).map(function(){return "<h5>" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%</h5>";}));
rspamd_donut = $.jqplot('rspamd_donut', [data], rspamd_donut_plot = $.jqplot('rspamd_donut', [data],
{ {
seriesDefaults: { seriesDefaults: {
renderer: jQuery.jqplot.DonutRenderer, renderer: jQuery.jqplot.DonutRenderer,
@ -383,6 +378,9 @@ jQuery(function($){
} }
}); });
} }
}
});
}
function process_table_data(data, table) { function process_table_data(data, table) {
if (table == 'rspamd_history') { if (table == 'rspamd_history') {
$.each(data, function (i, item) { $.each(data, function (i, item) {
@ -538,8 +536,8 @@ jQuery(function($){
var timer; var timer;
clearTimeout(timer); clearTimeout(timer);
timer = setTimeout(function () { timer = setTimeout(function () {
if (typeof rspamd_donut !== 'undefined') { if (typeof rspamd_donut_plot !== 'undefined') {
rspamd_donut.replot({}); rspamd_donut_plot.replot({});
} }
}, 500); }, 500);
}); });

View File

@ -158,6 +158,26 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
switch ($category) { switch ($category) {
case "rspamd": case "rspamd":
switch ($object) { switch ($object) {
case "actions":
$curl = curl_init();
curl_setopt($curl, CURLOPT_UNIX_SOCKET_PATH, '/rspamd-sock/rspamd.sock');
curl_setopt($curl, CURLOPT_URL,"http://rspamd/stat");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
if ($data) {
$return = array();
$stats_array = json_decode($data, true)['actions'];
$stats_array['soft reject'] = $stats_array['soft reject'] + $stats_array['greylist'];
unset($stats_array['greylist']);
foreach ($stats_array as $action => $count) {
$return[] = array($action, $count);
}
echo json_encode($return, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
}
elseif (!isset($data) || empty($data)) {
echo '{}';
}
break;
case "stat": case "stat":
$data = file_get_contents('http://rspamd-mailcow:11334/stat'); $data = file_get_contents('http://rspamd-mailcow:11334/stat');
process_get_return($data); process_get_return($data);