Skip to content

Commit f495439

Browse files
committed
patch
1 parent 41342f4 commit f495439

2 files changed

Lines changed: 40 additions & 13 deletions

File tree

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<?php
2+
use \Controllers\Host\Package\Package;
3+
use \Controllers\Host\Package\Event;
4+
25
$hostController = new \Controllers\Host\Host();
36
$hostListingController = new \Controllers\Host\Listing();
47
$datasets = [];
58
$labels = [];
69
$options = [];
710
$totalNotUptodate = 0;
811
$totalUptodate = 0;
12+
$totalCompliant = 0;
13+
$totalNotCompliant = 0;
914

1015
// Getting hosts list
1116
$hosts = $hostListingController->get();
@@ -16,32 +21,51 @@
1621
// Threshold of the maximum number of available update above which the host is considered as 'not up to date' (but not critical)
1722
$complianceThresholdCount = $hostsSettings['compliance_threshold_count'];
1823

24+
// Threshold of the maximum number of days since the last update above which the host is considered as 'not up to date' (but not critical)
25+
$complianceThresholdDays = $hostsSettings['compliance_threshold_days'];
26+
1927
// Loop through the list of hosts to determine the number of hosts up to date and not up to date
2028
foreach ($hosts as $host) {
2129
// Open the dedicated database of the host from its ID to be able to retrieve additional information
22-
$hostPackageController = new \Controllers\Host\Package\Package($host['Id']);
30+
$hostPackageController = new Package($host['Id']);
31+
$hostPackageEventController = new Event($host['Id']);
32+
33+
$upToDate = true;
2334

2435
// Retrieve the total number of available packages
2536
$packagesAvailableTotal = count($hostPackageController->getAvailable());
2637

27-
// Retrieve the total number of installed packages
28-
$packagesInstalledTotal = count($hostPackageController->getInstalled());
38+
// Retrieve the date of the last package upgrade event
39+
$latestUpdate = $hostPackageEventController->getLastPackageUpgradeEventDate()['Date'] ?? null;
2940

30-
/**
31-
* If the total number of available packages retrieved previously is > $complianceThresholdCount (threshold defined by the user) then we increment $totalNotUptodate (counts the number of hosts that are not up to date in the chartjs)
32-
* Else it's $totalUptodate that we increment.
33-
*/
41+
// The host is not compliant if the available updates count is >= threshold
3442
if ($packagesAvailableTotal >= $complianceThresholdCount) {
35-
$totalNotUptodate++;
36-
} else {
43+
$upToDate = false;
44+
}
45+
46+
// The host is not compliant if the latest update is older than the threshold in days
47+
if ($latestUpdate and strtotime($latestUpdate) < strtotime('-' . $complianceThresholdDays . ' days')) {
48+
$upToDate = false;
49+
}
50+
51+
if ($upToDate) {
3752
$totalUptodate++;
53+
} else {
54+
$totalNotUptodate++;
3855
}
56+
57+
// Calculate % compliance
58+
$totalCompliant = round(($totalUptodate / ($totalUptodate + $totalNotUptodate)) * 100, 2);
59+
3960
}
4061

41-
$labels[] = 'Up to date';
42-
$labels[] = 'Need update';
62+
$labels[] = 'Compliant';
63+
$labels[] = 'Not compliant';
4364
$datasets[0]['data'][] = $totalUptodate;
4465
$datasets[0]['data'][] = $totalNotUptodate;
4566
$datasets[0]['colors'] = ['#24d794', '#F32F63'];
67+
$options['title']['text'] = $totalCompliant . '% compliant';
68+
$options['title']['align'] = 'left';
69+
$options['title']['fontSize'] = 12;
4670

47-
unset($hostController, $hostListingController, $hostPackageController, $hosts, $hostsSettings, $totalUptodate, $totalNotUptodate, $complianceThresholdCount, $packagesAvailableTotal, $packagesInstalledTotal);
71+
unset($hostController, $hostListingController, $hostPackageController, $hosts, $hostsSettings, $totalUptodate, $totalNotUptodate, $complianceThresholdCount, $packagesAvailableTotal);

www/public/resources/js/classes/EChart.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class EChart
536536
type: 'pie',
537537
roseType: 'radius',
538538
radius: [innerRadius, outerRadius], // Configurable radius values
539-
center: ['50%', '50%'],
539+
center: this.chartOptions?.title?.text ? ['50%', '57%'] : ['50%', '50%'],
540540
itemStyle: {
541541
borderRadius: 2
542542
},
@@ -1004,6 +1004,9 @@ class EChart
10041004
if (this.chartOptions.title?.text) {
10051005
options.title.text = this.chartOptions.title.text;
10061006
options.title.left = this.chartOptions.title.align || 'left';
1007+
if (this.chartOptions.title.fontSize !== undefined) {
1008+
options.title.textStyle.fontSize = this.chartOptions.title.fontSize;
1009+
}
10071010
}
10081011

10091012
// Y-axis features

0 commit comments

Comments
 (0)