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

Commit

Permalink
enh(ceip): Add additional statistics including modules if present (#7328
Browse files Browse the repository at this point in the history
)

* enh(ceip): Add additional statistics including modules if present
* enh(doc): add statistics modules & widgets usage
  • Loading branch information
lpinsivy authored Apr 9, 2019
1 parent 791cc11 commit 71606fb
Show file tree
Hide file tree
Showing 6 changed files with 193 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cron/centreon-send-stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
$versions = $oStatistics->getVersion();
$infos = $oStatistics->getPlatformInfo();
$timez = $oStatistics->getPlatformTimezone();
$additional = $oStatistics->getAdditionalData();

// Construct the object gathering datas
$data = array(
'timestamp' => "$timestamp",
'UUID' => $UUID,
'versions' => $versions,
'infos' => $infos,
'timezone' => $timez
'timezone' => $timez,
'additional' => $additional
);

try {
Expand Down
2 changes: 1 addition & 1 deletion doc/en/ceip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ voluntary and anonymous. Customers who choose to participate agree to share:

* Information such as the operating system version of the Centreon main server of the platform as well as the name and version of the DBMS.
* Centreon product information such as number of servers and version numbers of components installed on the Centreon main server (modules & widgets).
* Centreon information such as number of hosts, services, groups of hosts & services.
* Centreon information such as number of hosts, services, groups of hosts & services, and usage of modules and widgets.
* The timezone of the Centreon server.

During the installation or upgrade processus, you will be asked to participate in
Expand Down
2 changes: 1 addition & 1 deletion doc/fr/ceip.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ choisissent de participer acceptent de partager :

* Informations telles que la version du système d'exploitation du serveur principal Centreon de la plate-forme, ainsi que le nom et la version du SGBD
* Informations sur les produits Centreon, telles que le nombre de serveurs et le numéro de version des composants installés sur le serveur principal de Centreon (modules et widgets)
* Informations sur la configuration Centreon tels que le nombre d'hôtes, de services, de groupes d'hôtes et les services
* Informations sur la configuration Centreon tels que le nombre d'hôtes, de services, de groupes d'hôtes et les services, ainsi que l'usage des modules et widgets
* Le fuseau horaire du serveur Centreon

Au cours du processus d'installation ou de mise à jour, il vous sera demandé de
Expand Down
25 changes: 25 additions & 0 deletions www/class/centreonStatistics.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
require_once _CENTREON_PATH_ . "/www/class/centreonGMT.class.php";
require_once _CENTREON_PATH_ . "/www/class/centreonVersion.class.php";
require_once _CENTREON_PATH_ . "/www/class/centreonDB.class.php";
require_once _CENTREON_PATH_ . "/www/class/centreonStatsModules.class.php";

class CentreonStatistics
{
Expand Down Expand Up @@ -126,4 +127,28 @@ public function getPlatformTimezone()
'timezone' => $timezone
);
}

/**
* Get Additional data
*
* @return array
*/
public function getAdditionalData()
{
$centreonVersion = new CentreonVersion($this->dbConfig);

$data = array(
'extension' => array(
'widgets' => $centreonVersion->getWidgetsUsage()
),
);

$oModulesStats = new CentreonStatsModules();
$modulesData = $oModulesStats->getModulesStatistics();
foreach ($modulesData as $moduleData) {
$data['extension'] = array_merge($data['extension'], $moduleData);
}

return $data;
}
}
118 changes: 118 additions & 0 deletions www/class/centreonStatsModules.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<?php
/*
* Copyright 2005-2019 Centreon
* Centreon is developped 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
* the terms of the GNU General Public License as published by the Free Software
* Foundation ; either version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses>.
*
* Linking this program statically or dynamically with other modules is making a
* 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 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 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
* do not wish to do so, delete this exception statement from your version.
*
* For more information : contact@centreon.com
*
*/

require_once _CENTREON_PATH_ . "/www/class/centreonDB.class.php";

class CentreonStatsModules
{
/**
* @var \CentreonDB
*/
private $db;

/**
* Constructor
*/
public function __construct()
{
$this->db = new centreonDB();
}

/**
* Get list of installed modules
*
* @return array Return the names of installed modules [['name' => string], ...]
*/
private function getInstalledModules()
{
$installedModules = array();
$stmt = $this->db->prepare("SELECT name FROM modules_informations");
$stmt->execute();
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $value) {
$installedModules[] = $value['name'];
}

return $installedModules;
}

/**
* Get statistics module objects
*
* @param array $installedModules Names of installed modules for which you want
* to retrieve statistics module [['name' => string], ...]
*
* @return array Return a list of statistics module found
* @see CentreonStatsModules::getInstalledModules()
*/
private function getModuleObjects(array $installedModules)
{
$moduleObjects = array();

foreach ($installedModules as $module) {
if ($files = glob(_CENTREON_PATH_ . 'www/modules/' . $module . '/statistics/*.class.php')) {
foreach ($files as $full_file) {
include_once $full_file;
$file_name = str_replace('.class.php', '', basename($full_file));
if (class_exists(ucfirst($file_name))) {
$moduleObjects[] = ucfirst($file_name);
}
}
}
}

return $moduleObjects;
}

/**
* Get statistics from module
*
* @return array The statistics of each module
*/
public function getModulesStatistics()
{
$data = array();
$moduleObjects = $this->getModuleObjects(
$this->getInstalledModules()
);

if (is_array($moduleObjects)) {
foreach ($moduleObjects as $moduleObject) {
$oModuleObject = new $moduleObject();
$data[] = $oModuleObject->getStats();
}
}
return $data;
}
}
45 changes: 45 additions & 0 deletions www/class/centreonVersion.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,51 @@ public function getSystem()
$data['mysql'] = $row['Value'];
}

return array_merge($data, $this->getVersionSystem());
}

/**
* get system information
*
* @return array $data An array composed with the name and version of the OS
* @throws Exception
*/
public function getVersionSystem()
{
$data = array();

// Get OS version
if (function_exists("shell_exec") && is_readable("/etc/os-release")) {
$os = shell_exec('cat /etc/os-release');
if (preg_match_all('/ID=?"(.*)?"/', $os, $matches)) {
$data['OS_name'] = $matches[1][0];
$data['OS_version'] = $matches[1][1];
}
}
return $data;
}

/**
* Get all Centreon widgets
*
* @return array $data Widgets statistics
*/
public function getWidgetsUsage()
{
$data = array();

$query = 'SELECT wm.title AS name, version, COUNT(widget_id) AS count
FROM widgets AS w
INNER JOIN widget_models AS wm ON (w.widget_model_id = wm.widget_model_id)
GROUP BY name';
$result = $this->db->query($query);
while ($row = $result->fetch()) {
$data[] = array(
'name' => $row['name'],
'version' => $row['version'],
'used' => $row['count']
);
}
return $data;
}
}

0 comments on commit 71606fb

Please sign in to comment.