Skip to content
This repository was archived by the owner on Dec 13, 2022. It is now read-only.

Commit b1d00ad

Browse files
authored
enh(api) New real time monitoring API for services and hosts (#7821)
This PR add a new version of the real time monitoring for services and hosts. The technical stack use Symfony 4 and FOSRestBundle. The new uri format is http[s]://_yourdomain.tld_/api/[**latest**|**v2**|**beta**]/monitoring/... See API documentation for more information: https://github.com/centreon/centreon/blob/MON-4113/doc/API/centreon-api-v2.html https://github.com/centreon/centreon/blob/MON-4113/doc/API/centreon-api-v2.yaml
1 parent 6403883 commit b1d00ad

File tree

99 files changed

+15548
-1655
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+15548
-1655
lines changed

.env

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
APP_ENV=prod
2+
APP_SECRET=%APP_SECRET%

.env.local.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
// This file was generated by running "composer dump-env prod"
4+
5+
return array (
6+
'APP_ENV' => 'prod',
7+
'APP_SECRET' => '%APP_SECRET%',
8+
);

.env.test

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# define your env variables for the test env here
2+
KERNEL_CLASS='App\Kernel'
3+
APP_SECRET='$ecretf0rt3st'
4+
SYMFONY_DEPRECATIONS_HELPER=999999

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ config/centreon.config.php
3434
coverage-report/
3535
centreon-build/
3636
secret
37+
38+
###> symfony/framework-bundle ###
39+
/.env.local
40+
/.env.local.php
41+
/.env.*.local
42+
/public/bundles/
43+
/var/
44+
###< symfony/framework-bundle ###
45+
/bin/.phpunit/
46+
/doc/en/_build/

api/index.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*
3+
* Copyright 2005 - 2019 Centreon (https://www.centreon.com/)
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
* For more information : [email protected]
18+
*
19+
*/
20+
21+
use App\Kernel;
22+
use Symfony\Component\Debug\Debug;
23+
use Symfony\Component\HttpFoundation\Request;
24+
25+
require dirname(__DIR__).'/config/bootstrap.php';
26+
27+
if ($_SERVER['APP_DEBUG']) {
28+
umask(0000);
29+
30+
Debug::enable();
31+
}
32+
33+
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
34+
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
35+
}
36+
37+
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
38+
Request::setTrustedHosts([$trustedHosts]);
39+
}
40+
41+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
42+
$request = Request::createFromGlobals();
43+
$response = $kernel->handle($request);
44+
$response->send();
45+
$kernel->terminate($request, $response);

bin/console

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!@PHP_BIN@
2+
<?php
3+
4+
use App\Kernel;
5+
use Symfony\Bundle\FrameworkBundle\Console\Application;
6+
use Symfony\Component\Console\Input\ArgvInput;
7+
use Symfony\Component\Debug\Debug;
8+
9+
if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
10+
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
11+
}
12+
13+
set_time_limit(0);
14+
15+
require dirname(__DIR__).'/vendor/autoload.php';
16+
17+
if (!class_exists(Application::class)) {
18+
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
19+
}
20+
21+
$input = new ArgvInput();
22+
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
23+
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
24+
}
25+
26+
if ($input->hasParameterOption('--no-debug', true)) {
27+
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
28+
}
29+
30+
require dirname(__DIR__).'/config/bootstrap.php';
31+
32+
if ($_SERVER['APP_DEBUG']) {
33+
umask(0000);
34+
35+
if (class_exists(Debug::class)) {
36+
Debug::enable();
37+
}
38+
}
39+
40+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
41+
$application = new Application($kernel);
42+
$application->run($input);

bootstrap.php

+1-78
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
*
3434
*/
3535

36-
// Calling PHP-DI
37-
use Pimple\Container;
38-
3936
set_include_path(implode(PATH_SEPARATOR, array(
4037
realpath(__DIR__ . '/www/class'),
4138
realpath(__DIR__ . '/www/lib'),
@@ -65,78 +62,4 @@ function loadDependencyInjector()
6562
// require composer file
6663
require __DIR__ . '/vendor/autoload.php';
6764

68-
// Creating container
69-
$dependencyInjector = new Container();
70-
71-
// Define Centreon Configuration Database Connection
72-
$dependencyInjector['configuration_db'] = function ($c) {
73-
return new \CentreonDB('centreon');
74-
};
75-
76-
// Define Centreon Realtime Database Connection
77-
$dependencyInjector['realtime_db'] = function ($c) {
78-
return new \CentreonDB('centstorage');
79-
};
80-
81-
// Define Centreon Rest Http Client
82-
$dependencyInjector['rest_http'] = function ($c) {
83-
return new \CentreonRestHttp();
84-
};
85-
86-
// Define filesystem
87-
$dependencyInjector['filesystem'] = function ($c) {
88-
return new \Symfony\Component\Filesystem\Filesystem();
89-
};
90-
91-
// Utils
92-
$dependencyInjector['utils'] = function ($c) use ($dependencyInjector) {
93-
return $dependencyInjector[CentreonLegacy\ServiceProvider::CENTREON_LEGACY_UTILS];
94-
};
95-
96-
// Define finder
97-
$dependencyInjector['finder'] = $dependencyInjector->factory(function ($c) {
98-
return new \Symfony\Component\Finder\Finder();
99-
});
100-
101-
// Define Language translator
102-
$dependencyInjector['translator'] = $dependencyInjector->factory(function ($c) {
103-
global $centreon;
104-
$translator = new CentreonLang(_CENTREON_PATH_, $centreon);
105-
$translator->bindLang();
106-
$translator->bindLang('help');
107-
return $translator;
108-
});
109-
110-
$dependencyInjector['path.files_generation'] = _CENTREON_CACHEDIR_ . '/config/';
111-
112-
// Defines the web service that will transform the translation files into one json file
113-
$dependencyInjector[CentreonI18n::class] = function ($container) {
114-
require_once _CENTREON_PATH_ . '/www/api/class/centreon_i18n.class.php';
115-
$lang = getenv('LANG');
116-
if ($lang === false) {
117-
// Initialize the language translator
118-
$container['translator'];
119-
$lang = getenv('LANG');
120-
}
121-
if (strstr($lang, '.UTF-8') === false) {
122-
$lang .= '.UTF-8';
123-
}
124-
$translationFile = _CENTREON_PATH_ . "www/locale/{$lang}/LC_MESSAGES/messages.ser";
125-
$translation = new CentreonI18n();
126-
$translation->setFilesGenerationPath($translationFile);
127-
return $translation;
128-
};
129-
130-
// Centreon configuration files
131-
$configFiles = $dependencyInjector['finder']
132-
->files()
133-
->name('*.config.php')
134-
->depth('== 0')
135-
->in(__DIR__ . '/config');
136-
foreach ($configFiles as $configFile) {
137-
$configFileName = $configFile->getBasename();
138-
require __DIR__ . '/config/' . $configFileName;
139-
}
140-
141-
// Dynamically register service provider
142-
\Centreon\Infrastructure\Provider\AutoloadServiceProvider::register($dependencyInjector);
65+
require_once __DIR__ . "/container.php";

composer.json

+41-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
},
1515
"require-dev": {
1616
"behat/behat": "^3.3",
17-
"behat/mink": "^1.7",
18-
"phpunit/phpunit": "^5.7",
17+
"behat/mink": "dev-master#a534fe7dac9525e8e10ca68e737c3d7e5058ec83",
18+
"phpunit/phpunit": "^7.5",
1919
"squizlabs/php_codesniffer": "^2.9",
20-
"phing/phing": "^2.16",
20+
"phing/phing": "3.0.0-alpha3",
2121
"behat/mink-extension": "^2.2",
2222
"behat/mink-selenium2-driver": "^1.3",
23-
"centreon/centreon-test-lib": "dev-master",
2423
"adlawson/vfs": "^0.12.1",
25-
"zircote/swagger-php": "^3.0"
24+
"zircote/swagger-php": "^3.0",
25+
"symfony/phpunit-bridge": "^4.3",
26+
"centreon/centreon-test-lib": "dev-master"
2627
},
2728
"require": {
2829
"php": ">=7.1.3",
@@ -31,21 +32,33 @@
3132
"pimple/pimple": "^3.2",
3233
"symfony/filesystem": "^4.1",
3334
"symfony/finder": "^4.1",
34-
"symfony/yaml": "^4.2",
3535
"openpsa/quickform": "3.3.*",
3636
"smarty/smarty": "~2.6",
3737
"curl/curl" : "^1.5",
38-
"symfony/serializer": "4.3.*",
38+
"ext-ctype": "*",
39+
"ext-iconv": "*",
40+
"friendsofsymfony/rest-bundle": "^2.5",
41+
"jms/serializer-bundle": "^2.4",
42+
"sensio/framework-extra-bundle": "^5.3",
43+
"symfony/console": "4.3.*",
44+
"symfony/dotenv": "4.3.*",
45+
"symfony/flex": "^1.1",
46+
"symfony/framework-bundle": "4.3.*",
47+
"symfony/security-bundle": "^4.3",
48+
"symfony/yaml": "4.3.*",
49+
"symfony/options-resolver": "4.3.*",
50+
"symfony/serializer-pack": "^1.0",
51+
"symfony/maker-bundle": "^1.11",
52+
"nelmio/cors-bundle": "^1.5",
3953
"symfony/validator": "4.3.*",
40-
"symfony/translation": "4.3.*",
41-
"symfony/property-access": "4.3.*",
42-
"symfony/property-info": "4.3.*",
4354
"symfony/expression-language": "4.3.*"
4455
},
4556
"autoload": {
4657
"psr-4": {
4758
"": "src/",
48-
"ConfigGenerateRemote\\": "www/class/config-generate-remote/"
59+
"ConfigGenerateRemote\\": "www/class/config-generate-remote/",
60+
"App\\": "src/",
61+
"Tests\\": "tests/php/"
4962
},
5063
"classmap": ["www/class/"],
5164
"files" : [
@@ -62,5 +75,22 @@
6275
"www/lib/HTML/QuickForm/selectoptgroup.php",
6376
"www/class/centreon-clapi/centreonACL.class.php"
6477
]
78+
},
79+
"replace": {
80+
"paragonie/random_compat": "2.*",
81+
"symfony/polyfill-ctype": "*",
82+
"symfony/polyfill-iconv": "*",
83+
"symfony/polyfill-php71": "*",
84+
"symfony/polyfill-php70": "*",
85+
"symfony/polyfill-php56": "*"
86+
},
87+
"conflict": {
88+
"symfony/symfony": "*"
89+
},
90+
"extra": {
91+
"symfony": {
92+
"allow-contrib": true,
93+
"require": "4.3.*"
94+
}
6595
}
6696
}

0 commit comments

Comments
 (0)