From 23641e45bbfad477824fd772162bb71e1fbf43ab Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Fri, 10 Jul 2020 13:38:42 +0200 Subject: [PATCH 1/4] Entity with enterprise capabilites --- pandora_console/include/constants.php | 3 ++ pandora_console/include/lib/Agent.php | 9 ++++-- pandora_console/include/lib/Entity.php | 39 +++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 0104a1fd5a..d32dacb1fe 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -372,6 +372,9 @@ define('MODULE_PREDICTION_CLUSTER_AP', 7); // Forced agent OS ID for cluster agents. define('CLUSTER_OS_ID', 100); +// Forced agent OS ID for satellite agents. +define('SATELLITE_OS_ID', 19); + // Type of Webserver Modules. define('MODULE_WEBSERVER_CHECK_LATENCY', 30); define('MODULE_WEBSERVER_CHECK_SERVER_RESPONSE', 31); diff --git a/pandora_console/include/lib/Agent.php b/pandora_console/include/lib/Agent.php index 8758e16095..5ff80609f9 100644 --- a/pandora_console/include/lib/Agent.php +++ b/pandora_console/include/lib/Agent.php @@ -63,11 +63,16 @@ class Agent extends Entity ) { $table = 'tagente'; $filter = ['id_agente' => $id_agent]; + $enterprise_class = '\PandoraFMS\Enterprise\Agent'; if (is_numeric($id_agent) === true && $id_agent > 0 ) { - parent::__construct($table, $filter); + parent::__construct( + $table, + $filter, + $enterprise_class + ); if ($load_modules === true) { $rows = \db_get_all_rows_filter( 'tagente_modulo', @@ -84,7 +89,7 @@ class Agent extends Entity } } else { // Create empty skel. - parent::__construct($table); + parent::__construct($table, null, $enterprise_class); // New agent has no modules. $this->modulesLoaded = true; diff --git a/pandora_console/include/lib/Entity.php b/pandora_console/include/lib/Entity.php index 3031a1336f..221752ea99 100644 --- a/pandora_console/include/lib/Entity.php +++ b/pandora_console/include/lib/Entity.php @@ -50,17 +50,28 @@ abstract class Entity */ protected $table = ''; + /** + * Enterprise capabilities object. + * + * @var object + */ + private $enterprise; + /** * Defines a generic constructor to extract information of the object. * - * @param string $table Table. - * @param array $filters Filters, for instance ['id' => $id]. + * @param string $table Table. + * @param array|null $filters Filters, for instance ['id' => $id]. + * @param string|null $enterprise Enterprise class name. * * @throws \Exception On error. */ - public function __construct(string $table, ?array $filters=null) - { + public function __construct( + string $table, + ?array $filters=null, + ?string $enterprise_class=null + ) { if (empty($table) === true) { throw new \Exception( get_class($this).' error, table name is not defined' @@ -96,6 +107,12 @@ abstract class Entity $this->fields[$row['Field']] = null; } } + + if (\enterprise_installed() === true + && $enterprise_class !== null + ) { + $this->enterprise = new $enterprise_class($this); + } } @@ -115,6 +132,20 @@ abstract class Entity return $this->{$methodName}($params); } + // Enterprise capabilities. + if (\enterprise_installed() === true + && $this->enterprise !== null + && method_exists($this->enterprise, $methodName) === true + ) { + return call_user_func_array( + [ + $this->enterprise, + $methodName, + ], + $params + ); + } + if (array_key_exists($methodName, $this->fields) === true) { if (empty($params) === true) { return $this->fields[$methodName]; From dc5767705f40a1ae11b579ee0635f30b99ee59eb Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 13 Jul 2020 13:56:41 +0200 Subject: [PATCH 2/4] minor fixes --- pandora_console/include/lib/Entity.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/lib/Entity.php b/pandora_console/include/lib/Entity.php index 221752ea99..92c204c50d 100644 --- a/pandora_console/include/lib/Entity.php +++ b/pandora_console/include/lib/Entity.php @@ -61,9 +61,9 @@ abstract class Entity /** * Defines a generic constructor to extract information of the object. * - * @param string $table Table. - * @param array|null $filters Filters, for instance ['id' => $id]. - * @param string|null $enterprise Enterprise class name. + * @param string $table Table. + * @param array|null $filters Filters, for instance ['id' => $id]. + * @param string|null $enterprise_class Enterprise class name. * * @throws \Exception On error. */ From 45062874ce36f6944432fb69233c8041b6a37558 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 13 Jul 2020 14:06:52 +0200 Subject: [PATCH 3/4] minor fix disabled textareas --- pandora_console/include/functions_html.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 61d86d222a..b547d1375d 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -4357,7 +4357,8 @@ function html_print_input($data, $wrapper='div', $input_only=false) ((isset($data['value']) === true) ? $data['value'] : ''), ((isset($data['attributes']) === true) ? $data['attributes'] : ''), ((isset($data['return']) === true) ? $data['return'] : false), - ((isset($data['class']) === true) ? $data['class'] : '') + ((isset($data['class']) === true) ? $data['class'] : ''), + ((isset($data['disabled']) === true) ? $data['disabled'] : false) ); break; From c8d86a4bdb977e0b407f10b89979900b1421e416 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 15 Jul 2020 13:46:51 +0200 Subject: [PATCH 4/4] minor fix --- pandora_console/include/lib/Agent.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pandora_console/include/lib/Agent.php b/pandora_console/include/lib/Agent.php index 5ff80609f9..f7a39bdab6 100644 --- a/pandora_console/include/lib/Agent.php +++ b/pandora_console/include/lib/Agent.php @@ -413,11 +413,12 @@ class Agent extends Entity /** * Search for modules into this agent. * - * @param array $filter Filters. + * @param array $filter Filters. + * @param integer $limit Limit search results. * * @return PandoraFMS\Module Module found. */ - public function searchModules(array $filter) + public function searchModules(array $filter, int $limit=0) { $filter['id_agente'] = $this->id_agente(); @@ -428,7 +429,7 @@ class Agent extends Entity foreach ($this->modules as $module) { $found = true; foreach ($filter as $field => $value) { - if ($module->{$field}() !== $value) { + if ($module->{$field}() != $value) { $found = false; break; } @@ -442,7 +443,7 @@ class Agent extends Entity return $results; } else { // Search in db. - return Module::search($filter); + return Module::search($filter, $limit); } }