From 66bad65550ed26f14fed967be14b2578a6e961f4 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Date: Fri, 11 Oct 2019 14:55:20 +0200 Subject: [PATCH] refactoriced diagnostics pandoraFMS --- pandora_console/godmode/menu.php | 6 +- .../include/class/Diagnostics.class.php | 312 ++++++++++++++++++ pandora_console/tools/diagnostics.php | 71 ++++ 3 files changed, 386 insertions(+), 3 deletions(-) create mode 100644 pandora_console/include/class/Diagnostics.class.php create mode 100644 pandora_console/tools/diagnostics.php diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 7175081912..edf7be1873 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -339,13 +339,13 @@ if (check_acl($config['id_user'], 0, 'PM') || check_acl($config['id_user'], 0, ' $sub = []; if (check_acl($config['id_user'], 0, 'PM')) { - // Audit //meter en extensiones + // Audit //meter en extensiones. $sub['godmode/admin_access_logs']['text'] = __('System audit log'); $sub['godmode/admin_access_logs']['id'] = 'System audit log'; $sub['godmode/setup/links']['text'] = __('Links'); $sub['godmode/setup/links']['id'] = 'Links'; - $sub['extras/pandora_diag']['text'] = __('Diagnostic info'); - $sub['extras/pandora_diag']['id'] = 'Diagnostic info'; + $sub['tools/diagnostics']['text'] = __('Diagnostic info'); + $sub['tools/diagnostics']['id'] = 'Diagnostic info'; $sub['godmode/setup/news']['text'] = __('Site news'); $sub['godmode/setup/news']['id'] = 'Site news'; $sub['godmode/setup/file_manager']['text'] = __('File manager'); diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php new file mode 100644 index 0000000000..f38a21e8d8 --- /dev/null +++ b/pandora_console/include/class/Diagnostics.class.php @@ -0,0 +1,312 @@ +getStatusInfo(); + + /* + * Print table in this case info. + */ + + $this->printTable($statusInfo); + + /* + * PHP setup. + */ + + $phpSetup = $this->getPHPSetup(); + + /* + * Print table in this case PHP SETUP. + */ + + $this->printTable($phpSetup); + + /* + * Database size stats. + */ + + $dataBaseSizeStats = $this->getDatabaseSizeStats(); + + /* + * Print table in this case Database size stats. + */ + + $this->printTable($dataBaseSizeStats); + } + + + /** + * Info status pandoraFms. + * + * @return string + */ + public function getStatusInfo(): string + { + global $config; + global $build_version; + global $pandora_version; + + $sql = sprintf( + "SELECT `key`, `value` + FROM `tupdate_settings` + WHERE `key` = '%s' + OR `key` = '%s' + OR `key` = '%s'", + 'current_update', + 'customer_key', + 'updating_code_path' + ); + + $values_key = db_get_all_rows_sql($sql); + $values_key = array_reduce( + $values_key, + function ($carry, $item) { + if ($item['key'] === 'customer_key') { + $customer = substr($item['value'], 0, 5); + $customer .= '...'; + $customer .= substr($item['value'], -5); + $item['value'] = $customer; + } + + $carry[$item['key']] = $item['value']; + return $carry; + } + ); + + $result = [ + 'error' => false, + 'data' => [ + 'buildVersion' => [ + 'name' => __('Pandora FMS Build'), + 'value' => $build_version, + ], + 'version' => [ + 'name' => __('Pandora FMS Version'), + 'value' => $pandora_version, + ], + 'mr' => [ + 'name' => __('Minor Release'), + 'value' => $config['MR'], + ], + 'homeDir' => [ + 'name' => __('Homedir'), + 'value' => $config['homedir'], + ], + 'homeUrl' => [ + 'name' => __('HomeUrl'), + 'value' => $config['homeurl'], + ], + 'isEnterprise' => [ + 'name' => __('Enterprise installed'), + 'value' => (enterprise_installed()) ? __('true') : __('false'), + ], + 'customerKey' => [ + 'name' => __('Update Key'), + 'value' => $values_key['customer_key'], + ], + 'updatingCode' => [ + 'name' => __('Updating code path'), + 'value' => $values_key['updating_code_path'], + ], + 'currentUpdate' => [ + 'name' => __('Current Update #'), + 'value' => $values_key['current_update'], + ], + + ], + ]; + + return json_encode($result); + } + + + /** + * PHP Status. + * + * @return string + */ + public function getPHPSetup(): string + { + global $config; + + $result = [ + 'error' => false, + 'data' => [ + 'phpVersion' => [ + 'name' => __('PHP Version'), + 'value' => phpversion(), + ], + 'maxExecutionTime' => [ + 'name' => __('PHP Max execution time'), + 'value' => ini_get('max_execution_time'), + ], + 'maxInputTime' => [ + 'name' => __('PHP Max input time'), + 'value' => ini_get('max_input_time'), + ], + 'memoryLimit' => [ + 'name' => __('PHP Memory limit'), + 'value' => ini_get('memory_limit'), + ], + 'sessionLifetime' => [ + 'name' => __('Session cookie lifetime'), + 'value' => ini_get('session.cookie_lifetime'), + ], + ], + ]; + + return json_encode($result); + } + + + /** + * Database size stats. + * + * @return string + */ + public function getDatabaseSizeStats(): string + { + global $config; + + $countAgents = db_get_value_sql('SELECT COUNT(*) FROM tagente'); + $countModules = db_get_value_sql('SELECT COUNT(*) FROM tagente_modulo'); + $countGroups = db_get_value_sql('SELECT COUNT(*) FROM tgrupo'); + $countModuleData = db_get_value_sql( + 'SELECT COUNT(*) FROM tagente_datos' + ); + $countAgentAccess = db_get_value_sql( + 'SELECT COUNT(*) FROM tagent_access' + ); + $countEvents = db_get_value_sql('SELECT COUNT(*) FROM tevento'); + + if (enterprise_installed() === true) { + $countTraps = db_get_value_sql('SELECT COUNT(*) FROM ttrap'); + } + + $countUsers = db_get_value_sql('SELECT COUNT(*) FROM tusuario'); + $countSessions = db_get_value_sql('SELECT COUNT(*) FROM tsesion'); + + $result = [ + 'error' => false, + 'data' => [ + 'countAgents' => [ + 'name' => __('Total agentsy'), + 'value' => $countAgents, + ], + 'countModules' => [ + 'name' => __('Total modules'), + 'value' => $countModules, + ], + 'countGroups' => [ + 'name' => __('Total groups'), + 'value' => $countGroups, + ], + 'countModuleData' => [ + 'name' => __('Total module data records'), + 'value' => $countModuleData, + ], + 'countAgentAccess' => [ + 'name' => __('Total agent access record'), + 'value' => $countAgentAccess, + ], + 'countEvents' => [ + 'name' => __('Total events'), + 'value' => $countEvents, + ], + 'countTraps' => [ + 'name' => __('Total traps'), + 'value' => $countTraps, + ], + 'countUsers' => [ + 'name' => __('Total users'), + 'value' => $countUsers, + ], + 'countSessions' => [ + 'name' => __('Total sessions'), + 'value' => $countSessions, + ], + ], + ]; + + return json_encode($result); + } + + + /** + * Paint table. + * + * @param string $statusInfo Json width status info. + * + * @return void + */ + public function printTable(string $statusInfo): void + { + global $config; + + hd($statusInfo); + } + + +} diff --git a/pandora_console/tools/diagnostics.php b/pandora_console/tools/diagnostics.php new file mode 100644 index 0000000000..ad97d8b742 --- /dev/null +++ b/pandora_console/tools/diagnostics.php @@ -0,0 +1,71 @@ + '[Diagnostics]'.$e->getMessage() ]); + exit; + } else { + echo '[Diagnostics]'.$e->getMessage(); + } + + // Stop this execution, but continue 'globally'. + return; +} + +// AJAX controller. +if (is_ajax()) { + $method = get_parameter('method'); + + if (method_exists($cs, $method) === true) { + if ($cs->ajaxMethod($method) === true) { + $cs->{$method}(); + } else { + $cs->error('Unavailable method.'); + } + } else { + $cs->error('Method not found. ['.$method.']'); + } + + // Stop any execution. + exit; +} else { + // Run. + $cs->run(); +}