Unverified Commit f07dc864 authored by sc979's avatar sc979 Committed by GitHub
Browse files

enh(chore): add CI requirements for github violation (#26)

parent 671d682b
/vendor
/build
\ No newline at end of file
......@@ -41,6 +41,55 @@ stage('Source') {
}
try {
stage('Unit tests') {
parallel 'centos7': {
node {
sh 'setup_centreon_build.sh'
sh "./centreon-build/jobs/widgets/${serie}/widget-unittest.sh centos7"
if (currentBuild.result == 'UNSTABLE')
currentBuild.result = 'FAILURE'
if (env.CHANGE_ID) { // pull request to comment with coding style issues
ViolationsToGitHub([
repositoryName: 'centreon-widget-global-health',
pullRequestId: env.CHANGE_ID,
createSingleFileComments: true,
commentOnlyChangedContent: true,
commentOnlyChangedFiles: true,
keepOldComments: false,
commentTemplate: "**{{violation.severity}}**: {{violation.message}}",
violationConfigs: [
[parser: 'CHECKSTYLE', pattern: '.*/codestyle-be.xml$', reporter: 'Checkstyle']
]
])
}
recordIssues(
enabledForFailure: true,
failOnError: true,
qualityGates: [[threshold: 1, type: 'DELTA', unstable: false]],
tools: [
checkStyle(pattern: 'codestyle-be.xml')
],
trendChartType: 'NONE',
referenceJobName: 'centreon-widget-global-health/master'
)
if ((env.BUILD == 'RELEASE') || (env.BUILD == 'REFERENCE')) {
withSonarQubeEnv('SonarQube') {
sh "./centreon-build/jobs/widgets/${serie}/widget-analysis.sh"
}
}
}
}
if ((currentBuild.result ?: 'SUCCESS') != 'SUCCESS') {
error('Unit tests stage failure.');
}
}
stage('Package') {
parallel 'centos7': {
node {
......
{
"name": "centreon/centreon-widget-global-health",
"description": "Pie chart widget to display the resource distribution by status",
"version": "21.04.0",
"type": "project",
"license": "GPL-2.0-only",
"scripts": {
"codestyle": "phpcs --extensions=php --standard=./ruleset.xml ./",
"codestyle:ci": "@codestyle --report=checkstyle --report-file=./build/checkstyle.xml --no-cache"
},
"require-dev": {
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.5"
},
"config": {
"secure-http": false,
"platform": {
"php": "7.2"
}
}
}
This diff is collapsed.
<?php
/**
* Copyright 2005-2011 MERETHIS
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
/*
* Copyright 2005-2020 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
......@@ -19,11 +20,11 @@
* combined work based on this program. Thus, the terms and conditions of the GNU
* General Public License cover the whole combination.
*
* As a special exception, the copyright holders of this program give MERETHIS
* As a special exception, the copyright holders of this program give Centreon
* permission to link this program with independent modules to produce an executable,
* regardless of the license terms of these independent modules, and to copy and
* distribute the resulting executable under terms of MERETHIS choice, provided that
* MERETHIS also meet, for each linked independent module, the terms and conditions
* distribute the resulting executable under terms of Centreon choice, provided that
* Centreon also meet, for each linked independent module, the terms and conditions
* of the license of that module. An independent module is a module which is not
* derived from this program. If you modify this program, you may extend this
* exception to your version of the program, but you are not obliged to do so. If you
......@@ -32,6 +33,7 @@
* For more information : contact@centreon.com
*
*/
require_once "../require.php";
require_once $centreon_path . 'bootstrap.php';
require_once $centreon_path . 'www/class/centreon.class.php';
......@@ -43,7 +45,7 @@ if (!isset($_SESSION['centreon']) || !isset($_REQUEST['widgetId'])) {
exit;
}
$centreon = $_SESSION['centreon'];
$widgetId = filter_var($_REQUEST['widgetId'], FILTER_VALIDATE_INT);
$widgetId = filter_var($_REQUEST['widgetId'], FILTER_VALIDATE_INT);
try {
if ($widgetId === false) {
......@@ -53,7 +55,7 @@ try {
$db = $dependencyInjector['configuration_db'];
$widgetObj = new CentreonWidget($centreon, $db);
$preferences = $widgetObj->getWidgetPreferences($widgetId);
$autoRefresh = filter_var($preferences['refresh_interval'], FILTER_VALIDATE_INT);
if ($autoRefresh === false || $autoRefresh < 5) {
$autoRefresh = 30;
......@@ -72,46 +74,46 @@ try {
exit;
}
?>
<html>
<head>
<title></title>
<link href="../../Themes/Centreon-2/style.css" rel="stylesheet" type="text/css"/>
<link href="../../Themes/Centreon-2/jquery-ui/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link href="../../Themes/Centreon-2/jquery-ui/jquery-ui-centreon.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../include/common/javascript/jquery/jquery.js"></script>
<script type="text/javascript" src="../../include/common/javascript/jquery/jquery-ui.js"></script>
<script type="text/javascript"
src="../../include/common/javascript/jquery/plugins/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="../../include/common/javascript/widgetUtils.js"></script>
<script type="text/javascript"
src="../../include/common/javascript/jquery/plugins/treeTable/jquery.treeTable.min.js"></script>
<script src="./lib/apexcharts.min.js" language="javascript"></script>
</head>
<body>
<div id='global_health'></div>
</body>
<HTML>
<HEAD>
<TITLE></TITLE>
<link href="../../Themes/Centreon-2/style.css" rel="stylesheet" type="text/css"/>
<link href="../../Themes/Centreon-2/jquery-ui/jquery-ui.css" rel="stylesheet" type="text/css"/>
<link href="../../Themes/Centreon-2/jquery-ui/jquery-ui-centreon.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../include/common/javascript/jquery/jquery.js"></script>
<script type="text/javascript" src="../../include/common/javascript/jquery/jquery-ui.js"></script>
<script type="text/javascript"
src="../../include/common/javascript/jquery/plugins/pagination/jquery.pagination.js"></script>
<script type="text/javascript" src="../../include/common/javascript/widgetUtils.js"></script>
<script type="text/javascript"
src="../../include/common/javascript/jquery/plugins/treeTable/jquery.treeTable.min.js"></script>
<script src="./lib/apexcharts.min.js" language="javascript"></script>
</HEAD>
<BODY>
<DIV id='global_health'></DIV>
</BODY>
<script type="text/javascript">
var widgetId = <?php echo $widgetId; ?>;
var autoRefresh = <?php echo $autoRefresh;?>;
var timeout;
var pageNumber = 0;
var broker = '<?php echo $broker;?>';
let widgetId = <?= $widgetId; ?>;
let autoRefresh = <?= $autoRefresh;?>;
let timeout;
let pageNumber = 0;
let broker = '<?= $broker;?>';
jQuery(function () {
loadPage();
});
function loadPage() {
var indexPage = "global_health";
let indexPage = "global_health";
jQuery.ajax("./src/" + indexPage + ".php?widgetId=" + widgetId, {
success: function (htmlData) {
jQuery("#global_health").html("");
jQuery("#global_health").html(htmlData);
var h = jQuery("#global_health").prop("scrollHeight") + 36;
let h = jQuery("#global_health").prop("scrollHeight") + 36;
parent.iResize(window.name, h);
jQuery("#global_health").find("img, style, script, link").load(function () {
var h = jQuery("#global_health").prop("scrollHeight") + 36;
let h = jQuery("#global_health").prop("scrollHeight") + 36;
parent.iResize(window.name, h);
});
}
......@@ -124,4 +126,4 @@ try {
}
}
</script>
</html>
</HTML>
<?php
/**
* Copyright 2005-2015 Centreon
/*
* Copyright 2005-2020 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
......@@ -126,17 +127,16 @@ if (!empty($preferences['hostgroup'])) {
}
if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == 'hosts') {
$innerjoingroup = '';
$wheregroup = '';
$innerJoinGroup = '';
if ($hgName) {
$innerjoingroup = ' INNER JOIN hosts_hostgroups hhg ON h.host_id = hhg.host_id ' .
$innerJoinGroup = ' INNER JOIN hosts_hostgroups hhg ON h.host_id = hhg.host_id ' .
' INNER JOIN hostgroups hg ON hhg.hostgroup_id = hg.hostgroup_id and hg.name = \'' . $hgName . '\' ';
}
$rq1 = ' SELECT count(DISTINCT h.name) cnt, h.state, SUM(h.acknowledged) as acknowledged, ' .
'SUM(CASE WHEN h.scheduled_downtime_depth >= 1 THEN 1 ELSE 0 END) AS downtime ' .
'FROM `hosts` h ' .
$innerjoingroup .
$innerJoinGroup .
'WHERE h.enabled = 1 ' .
$oreon->user->access->queryBuilder('AND', 'h.name', $oreon->user->access->getHostsString('NAME', $dbb)) .
' AND h.name NOT LIKE \'_Module_%\' ' .
......@@ -151,9 +151,6 @@ if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == '
$data[$ndo['state']]['count'] = $ndo['cnt'];
$data[$ndo['state']]['acknowledged'] = $ndo['acknowledged'];
$data[$ndo['state']]['downtime'] = $ndo['downtime'];
//$data[] = $ndo['cnt'];
//$legend[] = $tabStatusHost[$ndo['state']];
//$color[] = $oreon->optGen['color_'.strtolower($tabStatusHost[$ndo['state']])];
$counter += $ndo['cnt'];
}
$dbResult->closeCursor();
......@@ -165,13 +162,11 @@ if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == '
$hostArray[$tabStatusHost[$key]]['percent'] = $valuePercent;
$hostArray[$tabStatusHost[$key]]['acknowledged'] = $value['acknowledged'];
$hostArray[$tabStatusHost[$key]]['downtime'] = $value['downtime'];
//$hostArray[$tabStatusHost[$key]]['color'] = $oreon->optGen['color_'.strtolower($tabStatusHost[$key])];
}
$template->assign('hosts', $hostArray);
$template->display('global_health_host.ihtml');
} else if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == 'services') {
} elseif (isset($preferences['hosts_services']) && $preferences['hosts_services'] == 'services') {
$sgName = false;
if (!empty($preferences['servicegroup'])) {
$sql = 'select sg.sg_name from servicegroup sg where sg.sg_id = ' . $dbb->escape($preferences['servicegroup']);
......@@ -180,14 +175,15 @@ if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == '
$sgName = $row['sg_name'];
}
$innerjoingroup = '';
$innerJoinGroup = '';
if ($sgName) {
$innerjoingroup = ' INNER JOIN services_servicegroups ssg ON ssg.service_id = s.service_id and ssg.host_id = s.host_id ' .
' INNER JOIN servicegroups sg ON ssg.servicegroup_id = sg.servicegroup_id and sg.name = \'' . $sgName . '\' ';
$innerJoinGroup = ' INNER JOIN services_servicegroups ssg ON ssg.service_id = s.service_id ' .
'and ssg.host_id = s.host_id INNER JOIN servicegroups sg ON ssg.servicegroup_id = sg.servicegroup_id ' .
'and sg.name = \'' . $sgName . '\' ';
}
if ($hgName){
$innerjoingroup .= ' INNER JOIN hosts_hostgroups hhg ON h.host_id = hhg.host_id ' .
if ($hgName) {
$innerJoinGroup .= ' INNER JOIN hosts_hostgroups hhg ON h.host_id = hhg.host_id ' .
' INNER JOIN hostgroups hg ON hhg.hostgroup_id = hg.hostgroup_id and hg.name = \'' . $hgName . '\' ';
}
......@@ -206,7 +202,7 @@ if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == '
' FROM services s ' .
' INNER JOIN centreon_acl acl ON s.host_id = acl.host_id AND s.service_id = acl.service_id ' .
' INNER JOIN hosts h ON s.host_id = h.host_id ' .
$innerjoingroup .
$innerJoinGroup .
' WHERE h.name NOT LIKE \'_Module_%\' ' .
' AND h.enabled = 1 ' .
' AND s.enabled = 1 ' .
......@@ -218,7 +214,7 @@ if (isset($preferences['hosts_services']) && $preferences['hosts_services'] == '
' SUM(CASE WHEN s.scheduled_downtime_depth >= 1 THEN 1 ELSE 0 END) AS downtime ' .
' FROM services s' .
' INNER JOIN hosts h ON s.host_id = h.host_id ' .
$innerjoingroup .
$innerJoinGroup .
' WHERE h.name NOT LIKE \'_Module_%\' ' .
' AND h.enabled = 1 ' .
' AND s.enabled = 1 ' .
......
<?xml version="1.0"?>
<ruleset name="Centreon Widget Global Health">
<description>Custom rules defined by Centreon</description>
<exclude-pattern>vendor</exclude-pattern>
<rule ref="PSR12"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>global-health/src</exclude-pattern>
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace">
<exclude-pattern>global-health/src</exclude-pattern>
</rule>
</ruleset>
\ No newline at end of file
sonar.projectKey=centreon-widget-global-health-21.04
sonar.projectName=Centreon Widget Global Health 21.04
sonar.sources=./global-health
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment