[Web] Fix Rspamd plot

This commit is contained in:
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)
return ft_paging.totalRows;
})
}
}
});
}
function plot_rspamd() {
$.ajax({
url: '/api/v1/get/rspamd/actions',
success: function(data){
var total = 0;
$(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_donut = $.jqplot('rspamd_donut', [data],
{
seriesDefaults: {
renderer: jQuery.jqplot.DonutRenderer,
rendererOptions: {
showDataLabels: true,
dataLabels: rspamd_labels,
dataLabelThreshold: 1,
sliceMargin: 5,
totalLabel: true
},
shadow: false,
seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C']
},
legend: {
show:false,
},
grid: {
drawGridLines: true,
gridLineColor: '#efefef',
background: '#ffffff',
borderWidth: 0,
shadow: false,
$.ajax({
url: '/api/v1/get/rspamd/actions',
success: function(data){
var total = 0;
$(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_donut_plot = $.jqplot('rspamd_donut', [data],
{
seriesDefaults: {
renderer: jQuery.jqplot.DonutRenderer,
rendererOptions: {
showDataLabels: true,
dataLabels: rspamd_labels,
dataLabelThreshold: 1,
sliceMargin: 5,
totalLabel: true
},
shadow: false,
seriesColors: ['#FF4136', '#75CAEB', '#FF851B', '#FF851B', '#28B62C']
},
legend: {
show:false,
},
grid: {
drawGridLines: true,
gridLineColor: '#efefef',
background: '#ffffff',
borderWidth: 0,
shadow: false,
}
}
);
}
}
);
});
}
}
});
}
@ -538,8 +536,8 @@ jQuery(function($){
var timer;
clearTimeout(timer);
timer = setTimeout(function () {
if (typeof rspamd_donut !== 'undefined') {
rspamd_donut.replot({});
if (typeof rspamd_donut_plot !== 'undefined') {
rspamd_donut_plot.replot({});
}
}, 500);
});

View File

@ -158,6 +158,26 @@ if (isset($_SESSION['mailcow_cc_role']) || isset($_SESSION['pending_mailcow_cc_u
switch ($category) {
case "rspamd":
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":
$data = file_get_contents('http://rspamd-mailcow:11334/stat');
process_get_return($data);