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

enh(ceip): Add additional statistics including modules if present #7328

Merged
merged 4 commits into from
Apr 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);

$returnData = $http->call(CENTREON_STATS_URL, 'POST', $data, array(), true);
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;
}
}
119 changes: 119 additions & 0 deletions www/class/centreonStatsModules.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?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
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
* @var array InstalledModules
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
* @var array ObjectModules
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
* @var array Statistics
*/
private $db;
private $installed_modules;
private $module_objects;
private $data;
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved

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

/**
* Get list of installed modules
*
* @return array
*/
public function getInstalledModules()
{
if (!is_null($this->installed_modules)) {
return $this->installed_modules;
}
$this->installed_modules = array();
$stmt = $this->db->prepare("SELECT name FROM modules_informations");
$stmt->execute();
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $value) {
$this->installed_modules[] = $value['name'];
}
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Get statistics module objects
*
* @return array
*/
public function getModuleObjects()
{
$this->getInstalledModules();
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved

foreach ($this->installed_modules as $module) {
if ($files = glob(_CENTREON_PATH_ . 'www/modules/' . $module . '/statistics/*.class.php')) {
foreach ($files as $full_file) {
require_once $full_file;
$file_name = str_replace('.class.php', '', basename($full_file));
if (class_exists(ucfirst($file_name))) {
$this->module_objects[] = ucfirst($file_name);
}
}
}
}
}

/**
* Get statistics from module
*
* @return array
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
*/
public function getModulesStatistics()
{
$data = array();
if (is_null($this->module_objects)) {
$this->getModuleObjects();
}

if (is_array($this->module_objects)) {
foreach ($this->module_objects as $module_object) {
$oModuleObject = new $module_object();
$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
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
* @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
lpinsivy marked this conversation as resolved.
Show resolved Hide resolved
*/
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;
}
}