Skip to content

Commit

Permalink
enh(api) New real time monitoring API for services and hosts (centreo…
Browse files Browse the repository at this point in the history
…n#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
  • Loading branch information
callapa authored Sep 24, 2019
1 parent 6403883 commit b1d00ad
Show file tree
Hide file tree
Showing 99 changed files with 15,548 additions and 1,655 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
APP_ENV=prod
APP_SECRET=%APP_SECRET%
8 changes: 8 additions & 0 deletions .env.local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

// This file was generated by running "composer dump-env prod"

return array (
'APP_ENV' => 'prod',
'APP_SECRET' => '%APP_SECRET%',
);
4 changes: 4 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# define your env variables for the test env here
KERNEL_CLASS='App\Kernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ config/centreon.config.php
coverage-report/
centreon-build/
secret

###> symfony/framework-bundle ###
/.env.local
/.env.local.php
/.env.*.local
/public/bundles/
/var/
###< symfony/framework-bundle ###
/bin/.phpunit/
/doc/en/_build/
45 changes: 45 additions & 0 deletions api/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*
* Copyright 2005 - 2019 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : [email protected]
*
*/

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
42 changes: 42 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!@PHP_BIN@
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;

if (false === in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) {
echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.\PHP_SAPI.' SAPI'.\PHP_EOL;
}

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

$input = new ArgvInput();
if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) {
putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env);
}

if ($input->hasParameterOption('--no-debug', true)) {
putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0');
}

require dirname(__DIR__).'/config/bootstrap.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

if (class_exists(Debug::class)) {
Debug::enable();
}
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
79 changes: 1 addition & 78 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
*
*/

// Calling PHP-DI
use Pimple\Container;

set_include_path(implode(PATH_SEPARATOR, array(
realpath(__DIR__ . '/www/class'),
realpath(__DIR__ . '/www/lib'),
Expand Down Expand Up @@ -65,78 +62,4 @@ function loadDependencyInjector()
// require composer file
require __DIR__ . '/vendor/autoload.php';

// Creating container
$dependencyInjector = new Container();

// Define Centreon Configuration Database Connection
$dependencyInjector['configuration_db'] = function ($c) {
return new \CentreonDB('centreon');
};

// Define Centreon Realtime Database Connection
$dependencyInjector['realtime_db'] = function ($c) {
return new \CentreonDB('centstorage');
};

// Define Centreon Rest Http Client
$dependencyInjector['rest_http'] = function ($c) {
return new \CentreonRestHttp();
};

// Define filesystem
$dependencyInjector['filesystem'] = function ($c) {
return new \Symfony\Component\Filesystem\Filesystem();
};

// Utils
$dependencyInjector['utils'] = function ($c) use ($dependencyInjector) {
return $dependencyInjector[CentreonLegacy\ServiceProvider::CENTREON_LEGACY_UTILS];
};

// Define finder
$dependencyInjector['finder'] = $dependencyInjector->factory(function ($c) {
return new \Symfony\Component\Finder\Finder();
});

// Define Language translator
$dependencyInjector['translator'] = $dependencyInjector->factory(function ($c) {
global $centreon;
$translator = new CentreonLang(_CENTREON_PATH_, $centreon);
$translator->bindLang();
$translator->bindLang('help');
return $translator;
});

$dependencyInjector['path.files_generation'] = _CENTREON_CACHEDIR_ . '/config/';

// Defines the web service that will transform the translation files into one json file
$dependencyInjector[CentreonI18n::class] = function ($container) {
require_once _CENTREON_PATH_ . '/www/api/class/centreon_i18n.class.php';
$lang = getenv('LANG');
if ($lang === false) {
// Initialize the language translator
$container['translator'];
$lang = getenv('LANG');
}
if (strstr($lang, '.UTF-8') === false) {
$lang .= '.UTF-8';
}
$translationFile = _CENTREON_PATH_ . "www/locale/{$lang}/LC_MESSAGES/messages.ser";
$translation = new CentreonI18n();
$translation->setFilesGenerationPath($translationFile);
return $translation;
};

// Centreon configuration files
$configFiles = $dependencyInjector['finder']
->files()
->name('*.config.php')
->depth('== 0')
->in(__DIR__ . '/config');
foreach ($configFiles as $configFile) {
$configFileName = $configFile->getBasename();
require __DIR__ . '/config/' . $configFileName;
}

// Dynamically register service provider
\Centreon\Infrastructure\Provider\AutoloadServiceProvider::register($dependencyInjector);
require_once __DIR__ . "/container.php";
52 changes: 41 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
},
"require-dev": {
"behat/behat": "^3.3",
"behat/mink": "^1.7",
"phpunit/phpunit": "^5.7",
"behat/mink": "dev-master#a534fe7dac9525e8e10ca68e737c3d7e5058ec83",
"phpunit/phpunit": "^7.5",
"squizlabs/php_codesniffer": "^2.9",
"phing/phing": "^2.16",
"phing/phing": "3.0.0-alpha3",
"behat/mink-extension": "^2.2",
"behat/mink-selenium2-driver": "^1.3",
"centreon/centreon-test-lib": "dev-master",
"adlawson/vfs": "^0.12.1",
"zircote/swagger-php": "^3.0"
"zircote/swagger-php": "^3.0",
"symfony/phpunit-bridge": "^4.3",
"centreon/centreon-test-lib": "dev-master"
},
"require": {
"php": ">=7.1.3",
Expand All @@ -31,21 +32,33 @@
"pimple/pimple": "^3.2",
"symfony/filesystem": "^4.1",
"symfony/finder": "^4.1",
"symfony/yaml": "^4.2",
"openpsa/quickform": "3.3.*",
"smarty/smarty": "~2.6",
"curl/curl" : "^1.5",
"symfony/serializer": "4.3.*",
"ext-ctype": "*",
"ext-iconv": "*",
"friendsofsymfony/rest-bundle": "^2.5",
"jms/serializer-bundle": "^2.4",
"sensio/framework-extra-bundle": "^5.3",
"symfony/console": "4.3.*",
"symfony/dotenv": "4.3.*",
"symfony/flex": "^1.1",
"symfony/framework-bundle": "4.3.*",
"symfony/security-bundle": "^4.3",
"symfony/yaml": "4.3.*",
"symfony/options-resolver": "4.3.*",
"symfony/serializer-pack": "^1.0",
"symfony/maker-bundle": "^1.11",
"nelmio/cors-bundle": "^1.5",
"symfony/validator": "4.3.*",
"symfony/translation": "4.3.*",
"symfony/property-access": "4.3.*",
"symfony/property-info": "4.3.*",
"symfony/expression-language": "4.3.*"
},
"autoload": {
"psr-4": {
"": "src/",
"ConfigGenerateRemote\\": "www/class/config-generate-remote/"
"ConfigGenerateRemote\\": "www/class/config-generate-remote/",
"App\\": "src/",
"Tests\\": "tests/php/"
},
"classmap": ["www/class/"],
"files" : [
Expand All @@ -62,5 +75,22 @@
"www/lib/HTML/QuickForm/selectoptgroup.php",
"www/class/centreon-clapi/centreonACL.class.php"
]
},
"replace": {
"paragonie/random_compat": "2.*",
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php71": "*",
"symfony/polyfill-php70": "*",
"symfony/polyfill-php56": "*"
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": true,
"require": "4.3.*"
}
}
}
Loading

0 comments on commit b1d00ad

Please sign in to comment.