[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,43 +343,41 @@ jQuery(function($){
var ft_paging = ft.use(FooTable.Paging) var ft_paging = ft.use(FooTable.Paging)
return ft_paging.totalRows; return ft_paging.totalRows;
}) })
} $.ajax({
} url: '/api/v1/get/rspamd/actions',
}); success: function(data){
} var total = 0;
function plot_rspamd() { $(data).map(function(){total += this[1];})
$.ajax({ rspamd_labels = $.makeArray($(data).map(function(){return "<h5>" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%</h5>";}));
url: '/api/v1/get/rspamd/actions', rspamd_donut_plot = $.jqplot('rspamd_donut', [data],
success: function(data){ {
var total = 0; seriesDefaults: {
$(data).map(function(){total += this[1];}) renderer: jQuery.jqplot.DonutRenderer,
rspamd_labels = $.makeArray($(data).map(function(){return "<h5>" + this[0] + " (" + this[1] + ") " + Math.round(this[1]/total * 100) + "%</h5>";})); rendererOptions: {
rspamd_donut = $.jqplot('rspamd_donut', [data], showDataLabels: true,
{ dataLabels: rspamd_labels,
seriesDefaults: { dataLabelThreshold: 1,
renderer: jQuery.jqplot.DonutRenderer, sliceMargin: 5,
rendererOptions: { totalLabel: true
showDataLabels: true, },
dataLabels: rspamd_labels, shadow: false,
dataLabelThreshold: 1, seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C']
sliceMargin: 5, },
totalLabel: true legend: {
}, show:false,
shadow: false, },
seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C'] grid: {
}, drawGridLines: true,
legend: { gridLineColor: '#efefef',
show:false, background: '#ffffff',
}, borderWidth: 0,
grid: { shadow: false,
drawGridLines: true, }
gridLineColor: '#efefef', }
background: '#ffffff', );
borderWidth: 0,
shadow: false,
} }
} });
); }
} }
}); });
} }
@ -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);