From 3dc57f8a8ce732305fc2ac606cfe28770fd40ad0 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 6 Apr 2022 14:29:24 +0200 Subject: [PATCH 001/197] some fixes in version control and php memory usage --- .../include/class/ConsoleSupervisor.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php index 767722931d..ae61026fb3 100644 --- a/pandora_console/include/class/ConsoleSupervisor.php +++ b/pandora_console/include/class/ConsoleSupervisor.php @@ -1528,7 +1528,7 @@ class ConsoleSupervisor $this->cleanNotifications('NOTIF.PHP.UPLOAD_MAX_FILESIZE'); } - if ($PHPmemory_limit < $PHPmemory_limit_min && $PHPmemory_limit !== '-1') { + if ($PHPmemory_limit < $PHPmemory_limit_min && (int) $PHPmemory_limit !== -1) { $url = 'http://php.net/manual/en/ini.core.php#ini.memory-limit'; if ($config['language'] == 'es') { $url = 'http://php.net/manual/es/ini.core.php#ini.memory-limit'; @@ -2490,7 +2490,7 @@ class ConsoleSupervisor foreach ($server_version_list as $server) { if (strpos( $server['version'], - $config['current_package'] + floor($config['current_package']) ) === false ) { $missed++; @@ -2511,6 +2511,8 @@ class ConsoleSupervisor 'url' => '__url__/index.php?sec=messages&sec2=godmode/update_manager/update_manager&tab=online', ] ); + + break; } } } @@ -2532,18 +2534,19 @@ class ConsoleSupervisor global $config; $message = 'If AllowOverride is disabled, .htaccess will not works.'; - if (PHP_OS == 'FreeBSD') { - $message .= '
Please check /usr/local/etc/apache24/httpd.conf to resolve this problem.';
-	} else {
+        if (PHP_OS == 'FreeBSD') {
+            $message .= '
Please check /usr/local/etc/apache24/httpd.conf to resolve this problem.';
+        } else {
             $message .= '
Please check /etc/httpd/conf/httpd.conf to resolve this problem.';
-	}
+        }
 
         // Get content file.
-	if (PHP_OS == 'FreeBSD') {
-	    $file = file_get_contents('/usr/local/etc/apache24/httpd.conf');
-	} else {
+        if (PHP_OS == 'FreeBSD') {
+            $file = file_get_contents('/usr/local/etc/apache24/httpd.conf');
+        } else {
             $file = file_get_contents('/etc/httpd/conf/httpd.conf');
-	}
+        }
+
         $file_lines = preg_split("#\r?\n#", $file, -1, PREG_SPLIT_NO_EMPTY);
         $is_none = false;
 

From ab9557c681c329cc741e36bf7dc3a0f594583d36 Mon Sep 17 00:00:00 2001
From: "alejandro.campos@artica.es" 
Date: Thu, 21 Apr 2022 18:09:26 +0200
Subject: [PATCH 002/197] prevent registration dialog from showing up in update
 manager of metaconsole nodes

---
 pandora_console/godmode/update_manager/update_manager.php | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/pandora_console/godmode/update_manager/update_manager.php b/pandora_console/godmode/update_manager/update_manager.php
index da9eb8543d..991491843a 100644
--- a/pandora_console/godmode/update_manager/update_manager.php
+++ b/pandora_console/godmode/update_manager/update_manager.php
@@ -107,7 +107,11 @@ switch ($tab) {
 
     case 'online':
     default:
-        $mode = \UpdateManager\UI\Manager::MODE_ONLINE;
-        include $config['homedir'].'/godmode/um_client/index.php';
+        if ($config['node_metaconsole'] === 0) {
+            $mode = \UpdateManager\UI\Manager::MODE_ONLINE;
+            include $config['homedir'].'/godmode/um_client/index.php';
+        } else {
+            ui_print_warning_message(__('Please register on metaconsole.'));
+        }
     break;
 }

From 1a8a90a82f464490cd8c30b9d51347c36325d5ac Mon Sep 17 00:00:00 2001
From: Rafael 
Date: Mon, 25 Apr 2022 20:22:42 +0200
Subject: [PATCH 003/197] fix os check for rhel8

---
 extras/deploy-scripts/pandora_agent_deploy.sh | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/extras/deploy-scripts/pandora_agent_deploy.sh b/extras/deploy-scripts/pandora_agent_deploy.sh
index 74db9d7c72..9be1edf00f 100644
--- a/extras/deploy-scripts/pandora_agent_deploy.sh
+++ b/extras/deploy-scripts/pandora_agent_deploy.sh
@@ -4,7 +4,7 @@
 
 # define variables
 PANDORA_AGENT_CONF=/etc/pandora/pandora_agent.conf
-S_VERSION='2021100601'
+S_VERSION='2022042501'
 LOGFILE="/tmp/pandora-agent-deploy-$(date +%F).log"
 
 # Ansi color code variables
@@ -83,6 +83,7 @@ execute_cmd  "[ $PANDORA_SERVER_IP ]" 'Check Server IP Address' 'Please define e
 OS=$([[ $(grep '^ID_LIKE=' /etc/os-release) ]] && grep ^ID_LIKE= /etc/os-release | cut -d '=' -f2 | tr -d '"' || grep ^ID= /etc/os-release | cut -d '=' -f2 | tr -d '"')
 
 [[ $OS =~ 'rhel' ]] &&  OS_RELEASE=$OS
+[[ $OS =~ 'fedora' ]] &&  OS_RELEASE=$OS
 [[ $OS =~ 'debian' ]] &&  OS_RELEASE=$OS
 #[[ $OS == 'rhel fedora' ]] &&  OS_RELEASE=$OS
 #[[ $OS == 'centos rhel fedora' ]] &&  OS_RELEASE=$OS
@@ -113,7 +114,7 @@ execute_cmd "cd $HOME/pandora_deploy_tmp" "Moving to workspace:  $HOME/pandora_d
 
 # Downloading and installing packages
 
-if [[ $OS_RELEASE =~ 'rhel' ]]; then
+if [[ $OS_RELEASE =~ 'rhel' ]] || [[ $OS_RELEASE =~ 'fedora' ]]; then
     yum install -y perl wget curl perl-Sys-Syslog unzip &>> $LOGFILE 
     echo -e "${cyan}Instaling agent dependencies...${reset}" ${green}OK${reset}
     

From 5c029effdb47dadd83015540979c6fe7f74f29e1 Mon Sep 17 00:00:00 2001
From: "alejandro.campos@artica.es" 
Date: Thu, 28 Apr 2022 11:51:48 +0200
Subject: [PATCH 004/197] minor fix

---
 pandora_server/lib/PandoraFMS/DataServer.pm | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pandora_server/lib/PandoraFMS/DataServer.pm b/pandora_server/lib/PandoraFMS/DataServer.pm
index 232361a50f..083fb77f8e 100644
--- a/pandora_server/lib/PandoraFMS/DataServer.pm
+++ b/pandora_server/lib/PandoraFMS/DataServer.pm
@@ -583,6 +583,11 @@ sub process_xml_data ($$$$$) {
 							
 				$module_data->{'data'} = $data->{'value'};
 				my $data_timestamp = get_tag_value ($data, 'timestamp', $timestamp);
+
+				if ($pa_config->{'use_xml_timestamp'} eq '0' && defined($timestamp)) {
+					$data_timestamp = $timestamp;
+				}
+
 				process_module_data ($pa_config, $module_data, $server_id, $agent, $module_name,
 									 $module_type, $interval, $data_timestamp, $dbh, $new_agent);
 			}

From 9fd4e415c0f1911d579bb5e0d8d2057d843b4f60 Mon Sep 17 00:00:00 2001
From: Daniel Maya 
Date: Tue, 3 May 2022 10:02:39 +0200
Subject: [PATCH 005/197] #8899 Fixed pass with entities

---
 pandora_console/include/functions_config.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php
index 07537de173..c934a7aea7 100644
--- a/pandora_console/include/functions_config.php
+++ b/pandora_console/include/functions_config.php
@@ -1607,7 +1607,7 @@ function config_update_config()
                                 'port' => $config['history_db_port'],
                                 'name' => $config['history_db_name'],
                                 'user' => $config['history_db_user'],
-                                'pass' => $config['history_db_pass'],
+                                'pass' => io_output_password($config['history_db_pass']),
                             ]
                         );
 

From e685cf729473fafd334283af2342be28d1442d44 Mon Sep 17 00:00:00 2001
From: Calvo 
Date: Wed, 4 May 2022 18:42:56 +0200
Subject: [PATCH 006/197] Api create agent meta support

---
 pandora_console/include/functions_api.php | 231 +++++++++-------------
 pandora_console/include/lib/Agent.php     |  23 ++-
 2 files changed, 119 insertions(+), 135 deletions(-)

diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php
index 71128946c5..1f3dd91045 100644
--- a/pandora_console/include/functions_api.php
+++ b/pandora_console/include/functions_api.php
@@ -53,8 +53,10 @@ enterprise_include_once('include/functions_clusters.php');
 enterprise_include_once('include/functions_alerts.php');
 
 // Clases.
+use PandoraFMS\Agent;
 use PandoraFMS\Module;
 use PandoraFMS\Enterprise\Cluster;
+use PandoraFMS\Enterprise\Metaconsole\Node;
 use PandoraFMS\SpecialDay;
 
 
@@ -1826,18 +1828,18 @@ function api_set_update_agent_field($id_agent, $use_agent_alias, $params)
 /**
  * Create a new agent, and print the id for new agent.
  *
- * @param $thrash1 Don't use.
+ * @param $id_node Id_node target (if metaconsole)
  * @param $thrash2 Don't use.
- * @param array             $other it's array, $other as param is ;;;;
- *              ;;;;;;; in this order
- *              and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_)
- *              example:
+ * @param array                                   $other it's array, $other as param is ;;;;
+ *                                    ;;;;;;; in this order
+ *                                    and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_)
+ *                                    example:
  *
- *              api.php?op=set&op2=new_agent&other=pepito|1.1.1.1|0|4|0|30|8|10||0|0|nose%20nose&other_mode=url_encode_separator_|
+ *                                    api.php?op=set&op2=new_agent&other=pepito|1.1.1.1|0|4|0|30|8|10||0|0|nose%20nose&other_mode=url_encode_separator_|
  *
  * @param $thrash3 Don't use.
  */
-function api_set_new_agent($thrash1, $thrash2, $other, $thrash3)
+function api_set_new_agent($id_node, $thrash2, $other, $trhash3)
 {
     global $config;
 
@@ -1846,146 +1848,104 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3)
         return;
     }
 
-    if (defined('METACONSOLE')) {
-        return;
-    }
-
     if ((int) $other['data'][3] == 0) {
         returnError('For security reasons, the agent was not created. Use a group other than 0.');
         return;
     }
 
-    $alias                     = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $other['data'][0])));
-    $direccion_agente          = io_safe_input($other['data'][1]);
-    $nombre_agente             = hash('sha256', $direccion_agente.'|'.$direccion_agente.'|'.time().'|'.sprintf('%04d', rand(0, 10000)));
-    $id_parent                 = (int) $other['data'][2];
-    $grupo                     = (int) $other['data'][3];
-    $cascade_protection        = (int) $other['data'][4];
-    $cascade_protection_module = (int) $other['data'][5];
-    $intervalo                 = (string) $other['data'][6];
-    $id_os                     = (int) $other['data'][7];
-    $server_name               = (string) $other['data'][8];
-    $custom_id                 = (string) $other['data'][9];
-    $modo                      = (int) $other['data'][10];
-    $disabled                  = (int) $other['data'][11];
-    $comentarios               = (string) $other['data'][12];
-    $alias_as_name             = (int) $other['data'][13];
-    $update_module_count       = (int) $config['metaconsole_agent_cache'] == 1;
+    try {
+        $agent = new Agent();
 
-    if ($cascade_protection == 1) {
-        if (($id_parent != 0) && (db_get_value_sql(
-            'SELECT id_agente_modulo
-            FROM tagente_modulo
-            WHERE id_agente = '.$id_parent.' AND id_agente_modulo = '.$cascade_protection_module
-        ) === false)
-        ) {
-                returnError('Cascade protection is not applied because it is not a parent module.');
-                return;
-        }
-    } else {
-        $cascadeProtectionModule = 0;
-    }
-
-    $server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$server_name.'"');
-
-    // Check if agent exists (BUG WC-50518-2).
-    if ($alias == '' && $alias_as_name === 0) {
-        returnError('No agent alias specified');
-    } else if (agents_get_agent_id($nombre_agente)) {
-        returnError('The agent name already exists in DB.');
-    } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) {
-        returnError('The group does not exist.');
-    } else if (group_allow_more_agents($grupo, true, 'create') === false) {
-        returnError('Agent cannot be created due to the maximum agent limit for this group');
-    } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) {
-        returnError('The OS does not exist.');
-    } else if ($server_name === false) {
-        returnError('The '.get_product_name().' Server does not exist.');
-    } else {
-        if ($alias_as_name === 1) {
-            $exists_alias  = db_get_row_sql('SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"');
-            $nombre_agente = $alias;
-        }
-
-        $exists_ip = false;
-
-        if ($config['unique_ip'] && $direccion_agente != '') {
-            $exists_ip = db_get_row_sql('SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"');
-        }
-
-        if (!$exists_alias && !$exists_ip) {
-            $id_agente = db_process_sql_insert(
-                'tagente',
-                [
-                    'nombre'                    => $nombre_agente,
-                    'alias'                     => $alias,
-                    'alias_as_name'             => $alias_as_name,
-                    'direccion'                 => $direccion_agente,
-                    'id_grupo'                  => $grupo,
-                    'intervalo'                 => $intervalo,
-                    'comentarios'               => $comentarios,
-                    'modo'                      => $modo,
-                    'id_os'                     => $id_os,
-                    'disabled'                  => $disabled,
-                    'cascade_protection'        => $cascade_protection,
-                    'cascade_protection_module' => $cascade_protection_module,
-                    'server_name'               => $server_name,
-                    'id_parent'                 => $id_parent,
-                    'custom_id'                 => $custom_id,
-                    'os_version'                => '',
-                    'agent_version'             => '',
-                    'timezone_offset'           => 0,
-                    'icon_path'                 => '',
-                    'url_address'               => '',
-                    'update_module_count'       => $update_module_count,
-                ]
-            );
-            enterprise_hook('update_agent', [$id_agente]);
-        } else {
-            $id_agente = false;
-        }
-
-        if ($id_agente !== false) {
-            // Create address for this agent in taddress.
-            if ($direccion_agente != '') {
-                agents_add_address($id_agente, $direccion_agente);
+        if (is_metaconsole() === true) {
+            if ($id_node <= 0) {
+                throw new Exception('No node id specified');
             }
 
-            $info = '{"Name":"'.$nombre_agente.'",
-                "IP":"'.$direccion_agente.'",
-                "Group":"'.$grupo.'",
-                "Interval":"'.$intervalo.'",
-                "Comments":"'.$comentarios.'",
-                "Mode":"'.$modo.'",
-                "ID_parent:":"'.$id_parent.'",
-                "Server":"'.$server_name.'",
-                "ID os":"'.$id_os.'",
-                "Disabled":"'.$disabled.'",
-                "Custom ID":"'.$custom_id.'",
-                "Cascade protection":"'.$cascade_protection.'",
-                "Cascade protection module":"'.$cascade_protection_module.'"}';
-
-            $unsafe_alias = io_safe_output($alias);
-            db_pandora_audit(
-                AUDIT_LOG_AGENT_MANAGEMENT,
-                'Created agent '.$unsafe_alias,
-                false,
-                true,
-                $info
+            $node = new Node($id_node);
+            $id_agente = $node->callApi(
+                'new_agent',
+                'set',
+                null,
+                null,
+                $other['data'],
+                null
             );
         } else {
-            $id_agente = 0;
+            $alias                     = io_safe_input(trim(preg_replace('/[\/\\\|%#&$]/', '', $other['data'][0])));
+            $direccion_agente          = io_safe_input($other['data'][1]);
+            $id_parent                 = (int) $other['data'][2];
+            $grupo                     = (int) $other['data'][3];
+            $cascade_protection        = (int) $other['data'][4];
+            $cascade_protection_module = (int) $other['data'][5];
+            $intervalo                 = (string) $other['data'][6];
+            $id_os                     = (int) $other['data'][7];
+            $server_name               = (string) $other['data'][8];
+            $custom_id                 = (string) $other['data'][9];
+            $modo                      = (int) $other['data'][10];
+            $disabled                  = (int) $other['data'][11];
+            $comentarios               = (string) html_entity_decode($other['data'][12]);
+            $alias_as_name             = (int) $other['data'][13];
+            $update_module_count       = (int) $config['metaconsole_agent_cache'] == 1;
 
-            if ($exists_alias) {
-                $agent_creation_error = 'Could not be created because name already exists';
-            } else if ($exists_ip) {
-                $agent_creation_error = 'Could not be created because IP already exists';
+            $agent->nombre($alias);
+            $agent->alias($alias);
+            $agent->alias_as_name($alias_as_name);
+            $agent->direccion($direccion_agente);
+            $agent->id_grupo($grupo);
+            $agent->intervalo($intervalo);
+            $agent->comentarios($comentarios);
+            $agent->modo($modo);
+            $agent->id_os($id_os);
+            $agent->disabled($disabled);
+            $agent->cascade_protection($cascade_protection);
+            $agent->cascade_protection_module($cascade_protection_module);
+            $agent->server_name($server_name);
+            $agent->id_parent($id_parent);
+            $agent->custom_id($custom_id);
+            $agent->timezone_offset(0);
+            $agent->update_module_count($update_module_count);
+
+            if ($cascade_protection == 1) {
+                if ($id_parent != 0) {
+                    try {
+                        $parent = new Agent($id_parent);
+                    } catch (\Exception $e) {
+                        returnError('Cascade protection is not applied because it is not a parent module.');
+                    }
+                }
+            }
+
+            $server_name = db_get_value_sql('SELECT name FROM tserver WHERE BINARY name LIKE "'.$server_name.'"');
+
+            // Check if agent exists (BUG WC-50518-2).
+            if ($alias == '' && $alias_as_name === 0) {
+                returnError('No agent alias specified');
+            } else if (agents_get_agent_id($nombre_agente)) {
+                returnError('The agent name already exists in DB.');
+            } else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = '.$grupo) === false) {
+                returnError('The group does not exist.');
+            } else if (group_allow_more_agents($grupo, true, 'create') === false) {
+                returnError('Agent cannot be created due to the maximum agent limit for this group');
+            } else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = '.$id_os) === false) {
+                returnError('The OS does not exist.');
+            } else if ($server_name === false) {
+                returnError('The '.get_product_name().' Server does not exist.');
             } else {
-                $agent_creation_error = 'Could not be created for unknown reason';
-            }
+                if ($alias_as_name === 1) {
+                    $exists_alias  = db_get_row_sql('SELECT nombre FROM tagente WHERE nombre = "'.$alias.'"');
+                    $nombre_agente = $alias;
+                }
 
-            returnError($agent_creation_error);
-            return;
+                $exists_ip = false;
+
+                if ($config['unique_ip'] && $direccion_agente != '') {
+                    $exists_ip = db_get_row_sql('SELECT direccion FROM tagente WHERE direccion = "'.$direccion_agente.'"');
+                }
+
+                $agent->save((bool) $alias_as_name);
+                $id_agente = $agent->id_agente();
+                $agent->updateFromCache();
+            }
         }
 
         returnData(
@@ -1995,6 +1955,9 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3)
                 'data' => $id_agente,
             ]
         );
+    } catch (\Exception $e) {
+        returnError($e->getMessage());
+        return;
     }
 }
 
diff --git a/pandora_console/include/lib/Agent.php b/pandora_console/include/lib/Agent.php
index d561bba6f7..888cba6970 100644
--- a/pandora_console/include/lib/Agent.php
+++ b/pandora_console/include/lib/Agent.php
@@ -248,7 +248,7 @@ class Agent extends Entity
 
 
     /**
-     * Calculates cascade protection service value for this service.
+     * Calculates cascade protection _nameice value for this service.
      *
      * @param integer|null $id_node Meta searching node will use this field.
      *
@@ -621,4 +621,25 @@ class Agent extends Entity
     }
 
 
+    /**
+     * Update agent in metaconsole
+     *
+     * @return void
+     */
+    public function updateFromCache()
+    {
+        $res = (bool) \enterprise_hook(
+            'agent_update_from_cache',
+            [
+                $this->id_agente(),
+                $this->toArray(),
+                $this->server_name(),
+            ]
+        );
+
+        return $res;
+
+    }
+
+
 }

From f3272eb3dfca58b216f57841c41c998c4e017f0d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= 
Date: Thu, 5 May 2022 17:36:07 +0200
Subject: [PATCH 007/197] Applied fix for snmp

---
 pandora_console/include/class/AgentWizard.class.php | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php
index bc34fa5258..df9299078f 100644
--- a/pandora_console/include/class/AgentWizard.class.php
+++ b/pandora_console/include/class/AgentWizard.class.php
@@ -3572,7 +3572,12 @@ class AgentWizard extends HTML
                 if ($full_output === true) {
                     $output[] = $key.' = '.$oid_unit;
                 } else {
-                    preg_match('/\.\d+$/', $key, $index);
+                    $index = [];
+                    $index[] = preg_replace('/^'.$oid.'/', '', $key);
+                    if (empty($index) === true) {
+                        preg_match('/\.\d+$/', $key, $index);
+                    }
+
                     $tmp = explode(': ', $oid_unit);
                     $output[$index[0]] = str_replace('"', '', ($tmp[1] ?? ''));
                 }

From 1b3994d32ccafc006c949cf838c6a0c8a5179b3e Mon Sep 17 00:00:00 2001
From: Daniel Maya 
Date: Fri, 6 May 2022 11:54:17 +0200
Subject: [PATCH 008/197] #8730 Fixed console server version

---
 pandora_console/godmode/um_client/index.php         | 2 +-
 pandora_console/include/class/ConsoleSupervisor.php | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pandora_console/godmode/um_client/index.php b/pandora_console/godmode/um_client/index.php
index d700a05e9b..3cbf584109 100644
--- a/pandora_console/godmode/um_client/index.php
+++ b/pandora_console/godmode/um_client/index.php
@@ -224,7 +224,7 @@ if (is_ajax() !== true) {
         if ($server_version !== false
             && preg_match('/NG\.(\d\.*\d*?) /', $server_version, $matches) > 0
         ) {
-            if ((float) $matches[1]  !== (float) $current_package) {
+            if ((float) $matches[1] !== floor((float) $current_package)) {
                 ui_print_warning_message(
                     __(
                         'Master server version %s does not match console version %s.',
diff --git a/pandora_console/include/class/ConsoleSupervisor.php b/pandora_console/include/class/ConsoleSupervisor.php
index ae61026fb3..c4a43105b3 100644
--- a/pandora_console/include/class/ConsoleSupervisor.php
+++ b/pandora_console/include/class/ConsoleSupervisor.php
@@ -2490,7 +2490,7 @@ class ConsoleSupervisor
             foreach ($server_version_list as $server) {
                 if (strpos(
                     $server['version'],
-                    floor($config['current_package'])
+                    (string) floor($config['current_package'])
                 ) === false
                 ) {
                     $missed++;

From dfc4786ef187a9063412c91bbac995e6c177ff8f Mon Sep 17 00:00:00 2001
From: Calvo 
Date: Fri, 6 May 2022 13:35:04 +0200
Subject: [PATCH 009/197] Changed snmpwalk parameters for wizard

---
 .../modules/manage_network_components_form_wizard.php |  1 +
 pandora_console/include/class/AgentWizard.class.php   |  3 ++-
 pandora_console/include/functions.php                 | 11 ++++++-----
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/pandora_console/godmode/modules/manage_network_components_form_wizard.php b/pandora_console/godmode/modules/manage_network_components_form_wizard.php
index 0fa9d763c5..15b8f2a508 100644
--- a/pandora_console/godmode/modules/manage_network_components_form_wizard.php
+++ b/pandora_console/godmode/modules/manage_network_components_form_wizard.php
@@ -178,6 +178,7 @@ switch ($type) {
     break;
 }
 
+$query_filter = [];
 if (empty($query_filter) === false) {
     $query_filter = json_decode($query_filter, true);
 }
diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php
index bc34fa5258..671142817f 100644
--- a/pandora_console/include/class/AgentWizard.class.php
+++ b/pandora_console/include/class/AgentWizard.class.php
@@ -3559,7 +3559,8 @@ class AgentWizard extends HTML
             $this->targetPort,
             $this->server,
             $this->extraArguments,
-            (($full_output === false) ? '-Oa -On' : '-Oa')
+            (($full_output === false) ? '-On' : '-Oa'),
+            ''
         );
 
         if ($pure === true) {
diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php
index ca0c9dad7d..172b8de169 100644
--- a/pandora_console/include/functions.php
+++ b/pandora_console/include/functions.php
@@ -1993,7 +1993,8 @@ function get_snmpwalk(
     $snmp_port='',
     $server_to_exec=0,
     $extra_arguments='',
-    $format='-Oa'
+    $format='-Oa',
+    $load_mibs='-m ALL'
 ) {
     global $config;
 
@@ -2057,15 +2058,15 @@ function get_snmpwalk(
         case '3':
             switch ($snmp3_security_level) {
                 case 'authNoPriv':
-                    $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
+                    $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
                 break;
 
                 case 'noAuthNoPriv':
-                    $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
+                    $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
                 break;
 
                 default:
-                    $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
+                    $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
                 break;
             }
         break;
@@ -2074,7 +2075,7 @@ function get_snmpwalk(
         case '2c':
         case '1':
         default:
-            $command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
+            $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir;
         break;
     }
 

From 758933a2117c68bf6f33891a4246964295251d8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= 
Date: Fri, 6 May 2022 14:23:24 +0200
Subject: [PATCH 010/197] Fix black theme issues

---
 pandora_console/include/graphs/pandora.d3.js  | 15 +++++++--
 .../operation/netflow/nf_live_view.php        | 33 +++++++++++++------
 2 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/pandora_console/include/graphs/pandora.d3.js b/pandora_console/include/graphs/pandora.d3.js
index 8495a8728b..5f30f7379b 100644
--- a/pandora_console/include/graphs/pandora.d3.js
+++ b/pandora_console/include/graphs/pandora.d3.js
@@ -29,6 +29,12 @@ function chordDiagram(recipient, elements, matrix, width) {
     var width = 700;
     var margin = 150;
     var padding = 0.02;
+    var consoleStyle = document.getElementById("hidden-selected_style_theme")
+      .value;
+    var textColor =
+      consoleStyle === "pandora_black" ? "rgb(240, 240, 240)" : "rgb(0, 0, 0)";
+    var tooltipColor =
+      consoleStyle === "pandora_black" ? "rgb(0, 0, 0)" : "rgb(240, 240, 240)";
 
     function chart(selection) {
       selection.each(function(data) {
@@ -103,7 +109,6 @@ function chordDiagram(recipient, elements, matrix, width) {
               const chords = chord.chords();
               let aux = 0;
               $.each(chords, function(key, value) {
-                console.log(aux);
                 if (aux < 5) {
                   if (
                     (value.source.index == i && value.target.subindex == i) ||
@@ -159,6 +164,7 @@ function chordDiagram(recipient, elements, matrix, width) {
           .attr("text-anchor", function(d) {
             return d.angle > Math.PI ? "end" : null;
           })
+          .attr("style", "fill: " + textColor)
           .attr("transform", function(d) {
             return (
               "rotate(" +
@@ -266,7 +272,12 @@ function chordDiagram(recipient, elements, matrix, width) {
 
           $("#tooltip").attr(
             "style",
-            "background: #fff;" +
+            "background: " +
+              tooltipColor +
+              ";" +
+              "color: " +
+              textColor +
+              ";" +
               "position: absolute;" +
               "display: inline-block;" +
               "width: auto;" +
diff --git a/pandora_console/operation/netflow/nf_live_view.php b/pandora_console/operation/netflow/nf_live_view.php
index 442b1b2fa5..e717d92bfb 100644
--- a/pandora_console/operation/netflow/nf_live_view.php
+++ b/pandora_console/operation/netflow/nf_live_view.php
@@ -2,20 +2,28 @@
 /**
  * Netflow live view
  *
- * @package    Pandora FMS open.
- * @subpackage UI file.
+ * @category   Netflow
+ * @package    Pandora FMS
+ * @subpackage Community
+ * @version    1.0.0
+ * @license    See below
  *
- * Pandora FMS - http://pandorafms.com
- * ==================================================
- * Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
+ *    ______                 ___                    _______ _______ ________
+ *   |   __ \.-----.--.--.--|  |.-----.----.-----. |    ___|   |   |     __|
+ *  |    __/|  _  |     |  _  ||  _  |   _|  _  | |    ___|       |__     |
+ * |___|   |___._|__|__|_____||_____|__| |___._| |___|   |__|_|__|_______|
+ *
+ * ============================================================================
+ * Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
  * Please see http://pandorafms.org for full contribution list
  * 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; version 2
+ * as published by the Free Software Foundation for version 2.
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
+ * ============================================================================
  */
 
 global $config;
@@ -40,7 +48,7 @@ if (! check_acl($config['id_user'], 0, 'AR') && ! check_acl($config['id_user'],
 $pure = get_parameter('pure', 0);
 
 // Ajax callbacks.
-if (is_ajax()) {
+if (is_ajax() === true) {
     $get_filter_type = get_parameter('get_filter_type', 0);
     $get_filter_values = get_parameter('get_filter_values', 0);
 
@@ -117,7 +125,7 @@ $draw = get_parameter('draw_button', '');
 $save = get_parameter('save_button', '');
 $update = get_parameter('update_button', '');
 
-if (!is_metaconsole()) {
+if (is_metaconsole() === false) {
     // Header.
     ui_print_page_header(
         __('Netflow live view'),
@@ -505,7 +513,7 @@ if (is_metaconsole()) {
 
     echo '';
 
-    if ($draw != '') {
+    if (empty($draw) === false) {
         // Draw.
         echo '
'; @@ -513,6 +521,11 @@ if (is_metaconsole()) { if ($netflow_disable_custom_lvfilters && $filter_selected == 0) { ui_print_error_message(__('No filter selected')); } else { + // Hidden input for handle properly the text colors. + html_print_input_hidden( + 'selected_style_theme', + $config['style'] + ); // Draw the netflow chart. echo netflow_draw_item( $start_date, From 5c789125f2b561017a7fab325da91764eb8cf462 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 9 May 2022 12:40:36 +0200 Subject: [PATCH 011/197] changed id_user field length from tusuario --- pandora_console/extras/mr/55.sql | 15 +++++++++++++++ .../extras/pandoradb_migrate_6.0_to_759.mysql.sql | 15 +++++++++++++++ pandora_console/pandoradb.sql | 12 ++++++------ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 pandora_console/extras/mr/55.sql diff --git a/pandora_console/extras/mr/55.sql b/pandora_console/extras/mr/55.sql new file mode 100644 index 0000000000..b00619d357 --- /dev/null +++ b/pandora_console/extras/mr/55.sql @@ -0,0 +1,15 @@ +START TRANSACTION; + +ALTER TABLE `tuser_double_auth` DROP FOREIGN KEY `tuser_double_auth_ibfk_1`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_user` DROP FOREIGN KEY `tnotification_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_user` DROP FOREIGN KEY `tnotification_source_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_group_user` DROP FOREIGN KEY `tnotification_source_group_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tvisual_console_elements_cache` DROP FOREIGN KEY `tvisual_console_elements_cache_ibfk_3`, MODIFY `user_id` VARCHAR(255) DEFAULT NULL; +ALTER TABLE `tusuario` MODIFY `id_user` VARCHAR(255) NOT NULL DEFAULT '0'; +ALTER TABLE `tuser_double_auth` ADD CONSTRAINT `tuser_double_auth_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE; +ALTER TABLE `tnotification_user` ADD CONSTRAINT `tnotification_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_user` ADD CONSTRAINT `tnotification_source_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_group_user` ADD CONSTRAINT `tnotification_source_group_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tvisual_console_elements_cache` ADD CONSTRAINT `tvisual_console_elements_cache_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; + +COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql index ca68a5472a..242e7d42c6 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_759.mysql.sql @@ -4338,3 +4338,18 @@ ALTER TABLE `talert_special_days` DROP COLUMN `same_day`; ALTER TABLE `talert_special_days` ADD FOREIGN KEY (`id_calendar`) REFERENCES `talert_calendar`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; UPDATE `tconfig` c1 JOIN (select count(*) as n FROM `tconfig` c2 WHERE (c2.`token` = "node_metaconsole" AND c2.`value` = 1) OR (c2.`token` = "centralized_management" AND c2.`value` = 1) ) v SET c1. `value` = 0 WHERE c1.token = "autocreate_remote_users" AND v.n = 2; + +-- ---------------------------------------------------------------------- +-- Table `tusuario` +-- ---------------------------------------------------------------------- +ALTER TABLE `tuser_double_auth` DROP FOREIGN KEY `tuser_double_auth_ibfk_1`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_user` DROP FOREIGN KEY `tnotification_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_user` DROP FOREIGN KEY `tnotification_source_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tnotification_source_group_user` DROP FOREIGN KEY `tnotification_source_group_user_ibfk_2`, MODIFY `id_user` VARCHAR(255) NOT NULL; +ALTER TABLE `tvisual_console_elements_cache` DROP FOREIGN KEY `tvisual_console_elements_cache_ibfk_3`, MODIFY `user_id` VARCHAR(255) DEFAULT NULL; +ALTER TABLE `tusuario` MODIFY `id_user` VARCHAR(255) NOT NULL DEFAULT '0'; +ALTER TABLE `tuser_double_auth` ADD CONSTRAINT `tuser_double_auth_ibfk_1` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE; +ALTER TABLE `tnotification_user` ADD CONSTRAINT `tnotification_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_user` ADD CONSTRAINT `tnotification_source_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tnotification_source_group_user` ADD CONSTRAINT `tnotification_source_group_user_ibfk_2` FOREIGN KEY (`id_user`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `tvisual_console_elements_cache` ADD CONSTRAINT `tvisual_console_elements_cache_ibfk_3` FOREIGN KEY (`user_id`) REFERENCES `tusuario` (`id_user`) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 29ec6e572b..bb98a706e3 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1260,7 +1260,7 @@ CREATE TABLE IF NOT EXISTS `tevent_filter` ( -- Table `tusuario` -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tusuario` ( - `id_user` VARCHAR(60) NOT NULL DEFAULT '0', + `id_user` VARCHAR(255) NOT NULL DEFAULT '0', `fullname` VARCHAR(255) NOT NULL, `firstname` VARCHAR(255) NOT NULL, `lastname` VARCHAR(255) NOT NULL, @@ -1328,7 +1328,7 @@ CREATE TABLE IF NOT EXISTS `tusuario_perfil` ( -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tuser_double_auth` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `id_user` VARCHAR(60) NOT NULL, + `id_user` VARCHAR(255) NOT NULL, `secret` VARCHAR(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE (`id_user`), @@ -1388,7 +1388,7 @@ CREATE TABLE IF NOT EXISTS `tmensajes` ( -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tnotification_user` ( `id_mensaje` INT UNSIGNED NOT NULL, - `id_user` VARCHAR(60) NOT NULL, + `id_user` VARCHAR(255) NOT NULL, `utimestamp_read` BIGINT, `utimestamp_erased` BIGINT, `postpone` INT, @@ -1415,7 +1415,7 @@ CREATE TABLE IF NOT EXISTS `tnotification_group` ( -- ---------------------------------------------------------------------- CREATE TABLE IF NOT EXISTS `tnotification_source_user` ( `id_source` BIGINT UNSIGNED NOT NULL, - `id_user` VARCHAR(60), + `id_user` VARCHAR(255), `enabled` INT DEFAULT NULL, `also_mail` INT DEFAULT NULL, PRIMARY KEY (`id_source`,`id_user`), @@ -1443,7 +1443,7 @@ CREATE TABLE IF NOT EXISTS `tnotification_source_group` ( CREATE TABLE IF NOT EXISTS `tnotification_source_group_user` ( `id_source` BIGINT UNSIGNED NOT NULL, `id_group` MEDIUMINT UNSIGNED NOT NULL, - `id_user` VARCHAR(60), + `id_user` VARCHAR(255), `enabled` INT DEFAULT NULL, `also_mail` INT DEFAULT NULL, PRIMARY KEY (`id_source`,`id_user`), @@ -3836,7 +3836,7 @@ CREATE TABLE IF NOT EXISTS `tvisual_console_elements_cache` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `vc_id` INT UNSIGNED NOT NULL, `vc_item_id` INT UNSIGNED NOT NULL, - `user_id` VARCHAR(60) DEFAULT NULL, + `user_id` VARCHAR(255) DEFAULT NULL, `data` TEXT, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `expiration` INT UNSIGNED NOT NULL COMMENT 'Seconds to expire', From 15d92d5cd6c8ecfac04dfaf645f5dc215386d151 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 11 May 2022 13:51:16 +0200 Subject: [PATCH 012/197] #8517 Fixed module name --- pandora_server/lib/PandoraFMS/Recon/Base.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index f0b70cd0df..66d47a782a 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1628,9 +1628,14 @@ sub database_scan($$$) { $self->{'summary'}->{'discovered'} += 1; $self->{'summary'}->{'alive'} += 1; + my $name = $type . ' connection'; + if (defined $obj->{'prefix_module_name'} && $obj->{'prefix_module_name'} ne '') { + $name = $obj->{'prefix_module_name'} . $type . ' connection'; + } + push @modules, { - name => $type . ' connection', + name => $name, type => 'generic_proc', data => 1, description => $type . ' availability' @@ -1778,8 +1783,14 @@ sub app_scan($) { # Update progress $self->call('update_progress', $global_percent + (90 / (scalar @targets))); $self->{'summary'}->{'not_alive'} += 1; + + my $name = $type . ' connection'; + if (defined $obj->{'prefix_module_name'} && $obj->{'prefix_module_name'} ne '') { + $name = $obj->{'prefix_module_name'} . $type . ' connection'; + } + push @modules, { - name => $type . ' connection', + name => $name, type => 'generic_proc', data => 0, description => $type . ' availability' From 4589a7c298de516a1503b0c29ce08210da8bf799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Thu, 12 May 2022 18:31:24 +0200 Subject: [PATCH 013/197] Added control for WMI binary --- pandora_console/godmode/setup/performance.php | 10 ++++++++++ .../include/class/AgentWizard.class.php | 18 +++++++++++++----- pandora_console/include/functions_config.php | 8 ++++++++ pandora_console/include/functions_wmi.php | 6 +++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/setup/performance.php b/pandora_console/godmode/setup/performance.php index ad74c490c2..a2851b568c 100644 --- a/pandora_console/godmode/setup/performance.php +++ b/pandora_console/godmode/setup/performance.php @@ -661,6 +661,16 @@ $tip = ui_print_help_tip( true ); +$table_other->data[$i][0] = __('WMI binary'); +$table_other->data[$i++][1] = html_print_input_text( + 'wmiBinary', + $config['wmiBinary'], + '', + 50, + 10, + true +); + if (enterprise_installed() === true) { $table_other->data[$i][0] = __('PhantomJS cache cleanup ').$tip; $table_other->data[$i++][1] = html_print_input( diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 2d7f2f37da..0cf4afaeab 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -278,6 +278,13 @@ class AgentWizard extends HTML */ private $extraArguments = ''; + /** + * Binary of wmic. + * + * @var string + */ + private $wmiBinary = ''; + /** * Constructor @@ -291,7 +298,7 @@ class AgentWizard extends HTML // Check access. check_login(); - if (!check_acl($config['id_user'], 0, 'AR')) { + if ((bool) check_acl($config['id_user'], 0, 'AR') === false) { db_pandora_audit( AUDIT_LOG_ACL_VIOLATION, 'Trying to access event viewer' @@ -311,6 +318,7 @@ class AgentWizard extends HTML $this->idAgent = get_parameter('id_agente', ''); $this->idPolicy = get_parameter('id', ''); $this->targetIp = get_parameter('targetIp', ''); + $this->wmiBinary = $config['wmiBinary']; if (empty($this->idAgent) === false) { $array_aux = db_get_all_rows_sql( @@ -1044,7 +1052,7 @@ class AgentWizard extends HTML $oidExplore = '.1.3.6.1.2.1.1.2.0'; } - // Explore general or interfaces + // Explore general or interfaces. $receivedOid = $this->snmpWalkValues( $oidExplore, false, @@ -1080,7 +1088,7 @@ class AgentWizard extends HTML // Capture the parameters. // Call WMI Explorer function. $this->wmiCommand = wmi_compose_query( - 'wmic', + $this->wmiBinary, $this->usernameWMI, $this->passwordWMI, $this->targetIp, @@ -5717,7 +5725,7 @@ class AgentWizard extends HTML $(this).removeClass('hidden'); return; } - + if (this.id.match(regex)) { $(this).removeClass('hidden'); } else { @@ -5729,7 +5737,7 @@ class AgentWizard extends HTML $(this).addClass('hidden'); } } - + if (filter_up == true) { if ($(this).attr('operstatus') != 1) { $(this).addClass('hidden'); diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 07537de173..b730d9cfe0 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -928,6 +928,10 @@ function config_update_config() $error_update[] = __('SNMP walk binary path (fallback for v1)'); } + if (config_update_value('wmiBinary', get_parameter('wmiBinary'), true) === false) { + $error_update[] = __('Default WMI Binary'); + } + $pjs = get_parameter('phantomjs_cache_interval'); switch ($pjs) { case $config['phantomjs_cache_interval']: @@ -2088,6 +2092,10 @@ function config_process_config() config_update_value('snmpwalk_fallback', 'snmpwalk'); } + if (isset($config['wmiBinary']) === false) { + config_update_value('wmiBinary', 'pandorawmic'); + } + if (!isset($config['event_purge'])) { config_update_value('event_purge', 15); } diff --git a/pandora_console/include/functions_wmi.php b/pandora_console/include/functions_wmi.php index 7148233957..7f01e3f2bd 100644 --- a/pandora_console/include/functions_wmi.php +++ b/pandora_console/include/functions_wmi.php @@ -32,13 +32,13 @@ function wmi_compose_query($wmi_client, $user, $password, $host, $namespace='') { $wmi_command = ''; - if (!empty($password)) { - $wmi_command = $wmi_client.' -U "'.$user.'"%"'.$password.'"'; + if (empty($password) === false) { + $wmi_command = $wmi_client.' -U \''.$user.'\'%\''.$password.'\''; } else { $wmi_command = $wmi_client.' -U "'.$user.'"'; } - if (!empty($namespace)) { + if (empty($namespace) === false) { $namespace = str_replace('"', "'", $namespace); $wmi_command .= ' --namespace="'.$namespace.'"'; } From ececdca0b6ddf7f1d2e161b34f7e5891e025b406 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Fri, 13 May 2022 12:54:58 +0200 Subject: [PATCH 014/197] Not orientation CV view mobile pandora_enterprise#8888 --- pandora_console/general/logon_ok.php | 2 +- .../godmode/setup/setup_visuals.php | 61 ++++++++++++++++--- pandora_console/include/class/HTML.class.php | 2 + .../include/class/WelcomeWindow.class.php | 2 +- pandora_console/include/functions_config.php | 8 +++ pandora_console/include/functions_html.php | 2 +- .../include/functions_tactical.php | 17 ++++-- .../include/functions_visual_map.php | 28 ++++++--- .../include/javascript/pandora_dashboards.js | 54 ++++++++-------- .../Dashboard/Widgets/maps_made_by_user.php | 27 ++++---- .../include/rest-api/models/Model.php | 13 +++- .../VisualConsole/Items/StaticGraph.php | 8 +++ .../style/jquery.mobile-1.5.0-rc1.min.css | 2 +- pandora_console/mobile/include/ui.class.php | 4 ++ .../mobile/operation/visualmap.php | 29 ++++++--- 15 files changed, 184 insertions(+), 75 deletions(-) diff --git a/pandora_console/general/logon_ok.php b/pandora_console/general/logon_ok.php index d836d9f22c..7cb8f1d81b 100644 --- a/pandora_console/general/logon_ok.php +++ b/pandora_console/general/logon_ok.php @@ -288,7 +288,7 @@ foreach ($sessions as $session) { array_push($table->data, $data); } -$activity .= html_print_table($table, true); +$activity = html_print_table($table, true); unset($table); ui_toggle( diff --git a/pandora_console/godmode/setup/setup_visuals.php b/pandora_console/godmode/setup/setup_visuals.php index 9a36b3ac1c..d425c13b14 100755 --- a/pandora_console/godmode/setup/setup_visuals.php +++ b/pandora_console/godmode/setup/setup_visuals.php @@ -11,7 +11,7 @@ // 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. -// Load global vars +// Load global vars. global $config; check_login(); @@ -181,7 +181,8 @@ $backgrounds_list = array_merge($backgrounds_list_jpg, $backgrounds_list_png); $backgrounds_list = array_merge($backgrounds_list, $backgrounds_list_gif); asort($backgrounds_list); -if (!enterprise_installed()) { +$open = false; +if (enterprise_installed() === false) { $open = true; } @@ -953,7 +954,7 @@ $options_full_escale[2] = __('On Boolean graphs'); $table_chars->data[$row][1] = html_print_select( $options_full_escale, 'full_scale_option', - $config['full_scale_option'], + (isset($config['full_scale_option']) === true) ? $config['full_scale_option'] : 0, '', '', 0, @@ -973,7 +974,7 @@ $options_soft_graphs[1] = __('Show MAX/AVG/MIN by default'); $table_chars->data[$row][1] = html_print_select( $options_soft_graphs, 'type_mode_graph', - $config['type_mode_graph'], + (isset($config['type_mode_graph']) === true) ? $config['type_mode_graph'] : 0, '', '', 0, @@ -1053,13 +1054,31 @@ $table_vc->data[$row][1] = html_print_extended_select_for_time( $row++; $table_vc->data[$row][0] = __('Default interval for refresh on Visual Console'); -$table_vc->data[$row][1] = html_print_select($values, 'vc_refr', (int) $config['vc_refr'], '', 'N/A', 0, true, false, false); +$table_vc->data[$row][1] = html_print_select( + $values, + 'vc_refr', + (int) $config['vc_refr'], + '', + 'N/A', + 0, + true, + false, + false +); $row++; $vc_favourite_view_array[0] = __('Classic view'); $vc_favourite_view_array[1] = __('View of favorites'); $table_vc->data[$row][0] = __('Type of view of visual consoles'); -$table_vc->data[$row][1] = html_print_select($vc_favourite_view_array, 'vc_favourite_view', $config['vc_favourite_view'], '', '', 0, true); +$table_vc->data[$row][1] = html_print_select( + $vc_favourite_view_array, + 'vc_favourite_view', + $config['vc_favourite_view'], + '', + '', + 0, + true +); $row++; $table_vc->data[$row][0] = __('Number of favorite visual consoles to show in the menu'); @@ -1067,7 +1086,23 @@ $table_vc->data[$row][1] = " $visualConsoleData, - 'items' => $visualConsoleItems, - 'baseUrl' => ui_get_full_url('/', false, false, false), - 'ratio' => $ratio, - 'size' => $size, - 'cellId' => $this->cellId, - 'hash' => User::generatePublicHash(), - 'id_user' => $config['id_user'], - 'page' => 'include/ajax/visual_console.ajax', - 'uniq' => $uniq, + 'props' => $visualConsoleData, + 'items' => $visualConsoleItems, + 'baseUrl' => ui_get_full_url( + '/', + false, + false, + false + ), + 'ratio' => $ratio, + 'size' => $size, + 'cellId' => $this->cellId, + 'hash' => User::generatePublicHash(), + 'id_user' => $config['id_user'], + 'page' => 'include/ajax/visual_console.ajax', + 'uniq' => $uniq, + 'mobile_view_orientation_vc' => false, ] ); @@ -507,7 +513,6 @@ class MapsMadeByUser extends Widget }, dataType: 'JSON', success: function(data) { - console.log(data); $('#vcId').empty(); Object.entries(data).forEach(e => { key = e[0]; diff --git a/pandora_console/include/rest-api/models/Model.php b/pandora_console/include/rest-api/models/Model.php index fda301983a..c257c05b9f 100644 --- a/pandora_console/include/rest-api/models/Model.php +++ b/pandora_console/include/rest-api/models/Model.php @@ -223,6 +223,7 @@ abstract class Model */ public function adjustToViewport($size, $mode='') { + global $config; $ratio_visualconsole = $this->getRatio(); $ratio_w = ($size['width'] / $this->data['width']); $ratio_h = ($size['height'] / $this->data['height']); @@ -232,8 +233,16 @@ abstract class Model $ratio = $ratio_w; if ($mode === 'mobile') { - if ($this->data['height'] < $this->data['width']) { - if ($this->data['height'] > $size['height']) { + if ((bool) $config['mobile_view_orientation_vc'] === true) { + if ($this->data['height'] < $this->data['width']) { + if ($this->data['height'] > $size['height']) { + $ratio = $ratio_h; + $this->data['height'] = $size['height']; + $this->data['width'] = ($size['height'] / $ratio_visualconsole); + } + } + } else { + if ($this->data['height'] > $this->data['width']) { $ratio = $ratio_h; $this->data['height'] = $size['height']; $this->data['width'] = ($size['height'] / $ratio_visualconsole); diff --git a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php index 2bc262103a..adeaa9c29e 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Items/StaticGraph.php @@ -174,6 +174,14 @@ final class StaticGraph extends Item throw new \InvalidArgumentException('missing module Id'); } + if (isset($data['agentDisabled']) === false) { + $data['agentDisabled'] = false; + } + + if (isset($data['moduleDisabled']) === false) { + $data['moduleDisabled'] = false; + } + if ((bool) $data['agentDisabled'] === false && (bool) $data['moduleDisabled'] === false ) { diff --git a/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css b/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css index 60cf0cf83a..e543176676 100644 --- a/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css +++ b/pandora_console/mobile/include/style/jquery.mobile-1.5.0-rc1.min.css @@ -1396,7 +1396,7 @@ div.ui-mobile-viewport { overflow: visible; overflow-x: hidden; padding: 1em; - min-height: calc(100vh - 60px); + /*min-height: calc(100vh - 60px);*/ } .ui-corner-all > .ui-toolbar-header:first-child, .ui-corner-all > .ui-content:first-child, diff --git a/pandora_console/mobile/include/ui.class.php b/pandora_console/mobile/include/ui.class.php index 31d841d353..a08d29a208 100755 --- a/pandora_console/mobile/include/ui.class.php +++ b/pandora_console/mobile/include/ui.class.php @@ -1003,6 +1003,10 @@ class Ui $(document).ready(function () { dashboardLoadVC(settings); + if(settings.mobile_view_orientation_vc === false) { + $(".container-center").css("transform", "rotate(90deg)"); + $(".container-center").css("margin-top", "40px"); + } }); ' ); diff --git a/pandora_console/mobile/operation/visualmap.php b/pandora_console/mobile/operation/visualmap.php index 754afe9c0f..5ec1f6f25b 100644 --- a/pandora_console/mobile/operation/visualmap.php +++ b/pandora_console/mobile/operation/visualmap.php @@ -216,6 +216,7 @@ class Visualmap */ private function show_visualmap() { + global $config; $ui = Ui::getInstance(); $system = System::getInstance(); @@ -279,6 +280,13 @@ class Visualmap 'height' => $this->height, ]; + if ((bool) $config['mobile_view_orientation_vc'] === true) { + $size = [ + 'width' => $this->height, + 'height' => $this->width, + ]; + } + $ratio_t = $visualConsole->adjustToViewport($size, 'mobile'); $visualConsoleData = $visualConsole->toArray(); @@ -340,16 +348,17 @@ class Visualmap $settings = \json_encode( [ - 'props' => $visualConsoleData, - 'items' => $visualConsoleItems, - 'baseUrl' => ui_get_full_url('/', false, false, false), - 'page' => 'include/ajax/visual_console.ajax', - 'ratio' => $ratio_t, - 'size' => $size, - 'cellId' => $uniq, - 'uniq' => $uniq, - 'mobile' => true, - 'vcId' => $visualConsoleId, + 'props' => $visualConsoleData, + 'items' => $visualConsoleItems, + 'baseUrl' => ui_get_full_url('/', false, false, false), + 'page' => 'include/ajax/visual_console.ajax', + 'ratio' => $ratio_t, + 'size' => $size, + 'cellId' => $uniq, + 'uniq' => $uniq, + 'mobile' => true, + 'vcId' => $visualConsoleId, + 'mobile_view_orientation_vc' => (bool) !$config['mobile_view_orientation_vc'], ] ); From 0775b12caabf1285019c60f803782c698bae4fc5 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 13 May 2022 14:23:48 +0200 Subject: [PATCH 015/197] Description and unit on discovery network snmp interfaces --- .../lib/PandoraFMS/DiscoveryServer.pm | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index fcc1c8ca47..72d7a9b014 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -713,7 +713,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOPERSTATUS.$if_index", + 'unit' => '' + } ); @@ -741,7 +743,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCINOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') + } ); } else { @@ -766,7 +770,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFINOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') + } ); } @@ -795,7 +801,9 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFHCOUTOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') + } ); } else { @@ -820,7 +828,8 @@ sub PandoraFMS::Recon::Base::create_interface_modules($$) { 'plugin_user' => $self->{'task_data'}{'snmp_auth_user'}, 'plugin_pass' => $self->{'task_data'}{'snmp_auth_pass'}, 'snmp_community' => $community, - 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index" + 'snmp_oid' => "$PandoraFMS::Recon::Base::IFOUTOCTECTS.$if_index", + 'unit' => safe_input('bytes/s') } ); } @@ -1253,9 +1262,13 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { $id_tipo_modulo = get_module_id($self->{'dbh'}, $module->{'type'}) if is_empty($id_tipo_modulo); - my $description = safe_output($module->{'description'}); + my $description = safe_output($module->{'descripcion'}); $description = '' if is_empty($description); + my $unit = safe_output($module->{'unit'}); + $unit = '' if is_empty($unit); + + if (is_enabled($module->{'__module_component'})) { # Module from network component. delete $module->{'__module_component'}; @@ -1275,6 +1288,11 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { } else { # Create module - Direct. my $name = $module->{'name'}; + my $description = safe_output($module->{'descripcion'}); + + my $unit = safe_output($module->{'unit'}); + $unit = '' if is_empty($unit); + delete $module->{'name'}; delete $module->{'description'}; $agentmodule_id = pandora_create_module_from_hash( @@ -1286,7 +1304,8 @@ sub PandoraFMS::Recon::Base::report_scanned_agents($;$) { 'nombre' => safe_input($name), 'descripcion' => safe_input($description), 'id_agente' => $agent_id, - 'ip_target' => $data->{'agent'}{'direccion'} + 'ip_target' => $data->{'agent'}{'direccion'}, + 'unit' => safe_input($unit) }, $self->{'dbh'} ); From c437b894a3b451d6ef2b505f2062f965ee044bfb Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 18 May 2022 12:55:10 +0200 Subject: [PATCH 016/197] fixed modal size configuration widgets pandora_enterprise#8827 --- pandora_console/include/functions_html.php | 4 +- .../include/javascript/pandora_dashboards.js | 38 ++++++++++++++----- .../include/lib/Dashboard/Manager.php | 19 ++++++++++ .../include/lib/Dashboard/Widget.php | 20 +++++++++- .../lib/Dashboard/Widgets/agent_module.php | 28 +++++++++++--- .../lib/Dashboard/Widgets/alerts_fired.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/clock.php | 16 ++++++++ .../lib/Dashboard/Widgets/custom_graph.php | 16 ++++++++ .../lib/Dashboard/Widgets/events_list.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/example.php | 16 ++++++++ .../Widgets/graph_module_histogram.php | 16 ++++++++ .../lib/Dashboard/Widgets/groups_status.php | 16 ++++++++ .../Dashboard/Widgets/maps_made_by_user.php | 16 ++++++++ .../lib/Dashboard/Widgets/maps_status.php | 16 ++++++++ .../lib/Dashboard/Widgets/module_icon.php | 16 ++++++++ .../lib/Dashboard/Widgets/module_status.php | 16 ++++++++ .../Dashboard/Widgets/module_table_value.php | 16 ++++++++ .../lib/Dashboard/Widgets/module_value.php | 18 ++++++++- .../lib/Dashboard/Widgets/monitor_health.php | 16 ++++++++ .../lib/Dashboard/Widgets/network_map.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/post.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/reports.php | 16 ++++++++ .../lib/Dashboard/Widgets/service_map.php | 21 ++++++++++ .../lib/Dashboard/Widgets/service_view.php | 16 ++++++++ .../lib/Dashboard/Widgets/single_graph.php | 16 ++++++++ .../lib/Dashboard/Widgets/sla_percent.php | 16 ++++++++ .../Dashboard/Widgets/system_group_status.php | 16 ++++++++ .../lib/Dashboard/Widgets/tactical.php | 16 ++++++++ .../lib/Dashboard/Widgets/tree_view.php | 16 ++++++++ .../include/lib/Dashboard/Widgets/url.php | 16 ++++++++ .../lib/Dashboard/Widgets/wux_transaction.php | 18 ++++++++- .../Widgets/wux_transaction_stats.php | 16 ++++++++ 32 files changed, 531 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 10539fae91..633e928852 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1685,7 +1685,9 @@ function html_print_select_multiple_modules_filtered(array $data):string ); } - if ($data['mAgents'] !== null) { + if (empty($data['mAgents']) === false + && empty($data['mModuleGroup'] === false) + ) { $all_modules = get_modules_agents( $data['mModuleGroup'], explode(',', $data['mAgents']), diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 6e5a87b169..03b7be02a7 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -266,7 +266,7 @@ function initialiceLayout(data) { }); $("#configure-widget-" + id).click(function() { - configurationWidget(id, widgetId); + getSizeModalConfiguration(id, widgetId); }); }, error: function(error) { @@ -275,6 +275,29 @@ function initialiceLayout(data) { }); } + function getSizeModalConfiguration(cellId, widgetId) { + $.ajax({ + method: "post", + url: data.url, + data: { + page: data.page, + method: "getSizeModalConfiguration", + dashboardId: data.dashboardId, + cellId: cellId, + widgetId: widgetId + }, + dataType: "json", + success: function(size) { + configurationWidget(cellId, widgetId, size); + }, + error: function(error) { + console.log(error); + return []; + } + }); + return false; + } + function saveLayout() { var items = $(".grid-stack > .grid-stack-item:visible") .map(function(i, el) { @@ -370,7 +393,7 @@ function initialiceLayout(data) { }); } - function configurationWidget(cellId, widgetId) { + function configurationWidget(cellId, widgetId, size) { load_modal({ target: $("#modal-config-widget"), form: "form-config-widget", @@ -388,12 +411,9 @@ function initialiceLayout(data) { dashboardId: data.dashboardId, widgetId: widgetId }, - width: - widgetId == 14 || widgetId == 2 || widgetId == 23 || widgetId == 16 - ? 750 - : 450, - maxHeight: 650, - minHeight: widgetId == 16 ? 450 : 400 + width: size.width, + maxHeight: size.height, + minHeight: size.height }, onsubmit: { page: data.page, @@ -710,7 +730,7 @@ function initialiceLayout(data) { }); $("#configure-widget-" + cellId).click(function() { - configurationWidget(cellId, widgetId); + getSizeModalConfiguration(cellId, widgetId); }); saveLayout(); diff --git a/pandora_console/include/lib/Dashboard/Manager.php b/pandora_console/include/lib/Dashboard/Manager.php index 33cd0a3c2c..56dc0b2caf 100644 --- a/pandora_console/include/lib/Dashboard/Manager.php +++ b/pandora_console/include/lib/Dashboard/Manager.php @@ -180,6 +180,7 @@ class Manager implements PublicLogin 'imageIconDashboardAjax', 'formSlides', 'callWidgetMethod', + 'getSizeModalConfiguration', ]; @@ -1524,4 +1525,22 @@ class Manager implements PublicLogin } + /** + * Size configuration modal (ajax only). + * + * @return void. + */ + public function getSizeModalConfiguration():void + { + $result = []; + $widget = $this->instanceWidget(); + $result = $widget->getSizeModalConfiguration(); + + echo json_encode($result); + + return; + + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 320280718b..cf0aa9e74d 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -512,7 +512,9 @@ class Widget if (empty($values['background']) === true) { $values['background'] = '#ffffff'; - if ($config['style'] === 'pandora_black' && !is_metaconsole()) { + if ($config['style'] === 'pandora_black' + && is_metaconsole() === false + ) { $values['background'] = '#222222'; } } @@ -759,4 +761,20 @@ class Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration():array + { + $size = [ + 'width' => 400, + 'height' => 650, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php index dbc0c1dcf5..1a1d147f49 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/agent_module.php +++ b/pandora_console/include/lib/Dashboard/Widgets/agent_module.php @@ -285,12 +285,12 @@ class AgentModuleWidget extends Widget 'arguments' => [ 'type' => 'select_multiple_modules_filtered', 'uniqId' => $this->cellId, - 'mGroup' => $this->values['mGroup'], - 'mRecursion' => $this->values['mRecursion'], - 'mModuleGroup' => $this->values['mModuleGroup'], - 'mAgents' => $this->values['mAgents'], - 'mShowCommonModules' => $this->values['mShowCommonModules'], - 'mModules' => $this->values['mModules'], + 'mGroup' => (isset($this->values['mGroup']) === true) ? $this->values['mGroup'] : '', + 'mRecursion' => (isset($this->values['mRecursion']) === true) ? $this->values['mRecursion'] : '', + 'mModuleGroup' => (isset($this->values['mModuleGroup']) === true) ? $this->values['mModuleGroup'] : '', + 'mAgents' => (isset($this->values['mAgents']) === true) ? $this->values['mAgents'] : '', + 'mShowCommonModules' => (isset($this->values['mShowCommonModules']) === true) ? $this->values['mShowCommonModules'] : '', + 'mModules' => (isset($this->values['mModules']) === true) ? $this->values['mModules'] : '', 'mShowSelectedOtherGroups' => true, 'mReturnAllGroup' => $return_all_group, 'mMetaFields' => ((bool) is_metaconsole()), @@ -852,4 +852,20 @@ class AgentModuleWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 800, + 'height' => 600, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php b/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php index fdb5c3648a..ad9fcb0c2a 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php +++ b/pandora_console/include/lib/Dashboard/Widgets/alerts_fired.php @@ -372,4 +372,20 @@ class AlertsFiredWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 370, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/clock.php b/pandora_console/include/lib/Dashboard/Widgets/clock.php index 5d90f0f863..d06e1c8958 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/clock.php +++ b/pandora_console/include/lib/Dashboard/Widgets/clock.php @@ -322,4 +322,20 @@ class ClockWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php index c2515d1088..cdb6075d51 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/custom_graph.php @@ -533,4 +533,20 @@ class CustomGraphWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 480, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/events_list.php b/pandora_console/include/lib/Dashboard/Widgets/events_list.php index e0c1bfe3cf..1a381db8af 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/events_list.php +++ b/pandora_console/include/lib/Dashboard/Widgets/events_list.php @@ -822,4 +822,20 @@ class EventsListWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 700, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/example.php b/pandora_console/include/lib/Dashboard/Widgets/example.php index 3a4ec40fb6..3281c4a660 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/example.php +++ b/pandora_console/include/lib/Dashboard/Widgets/example.php @@ -289,4 +289,20 @@ class WelcomeWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 250, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php index dba9035877..570f2ea8b2 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php +++ b/pandora_console/include/lib/Dashboard/Widgets/graph_module_histogram.php @@ -443,4 +443,20 @@ class GraphModuleHistogramWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 500, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/groups_status.php b/pandora_console/include/lib/Dashboard/Widgets/groups_status.php index af25b2c056..cfa4d99c8f 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/groups_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/groups_status.php @@ -493,4 +493,20 @@ class GroupsStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php index 7c874954cb..24ce8adc7c 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php +++ b/pandora_console/include/lib/Dashboard/Widgets/maps_made_by_user.php @@ -530,4 +530,20 @@ class MapsMadeByUser extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 360, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/maps_status.php b/pandora_console/include/lib/Dashboard/Widgets/maps_status.php index 2f59a29f0a..3da581f2fc 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/maps_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/maps_status.php @@ -400,4 +400,20 @@ class MapsStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 450, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_icon.php b/pandora_console/include/lib/Dashboard/Widgets/module_icon.php index cb3d8086e8..a4ec3a09c6 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_icon.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_icon.php @@ -552,4 +552,20 @@ class ModuleIconWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 700, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_status.php b/pandora_console/include/lib/Dashboard/Widgets/module_status.php index 0a0fe65615..2c3c87cc24 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_status.php @@ -550,4 +550,20 @@ class ModuleStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 700, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php b/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php index 0039768a30..d77a0cb9e2 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_table_value.php @@ -409,4 +409,20 @@ class ModuleTableValueWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 460, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_value.php b/pandora_console/include/lib/Dashboard/Widgets/module_value.php index b005863b24..05a74c1ef1 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_value.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_value.php @@ -378,7 +378,7 @@ class ModuleValueWidget extends Widget { global $config; - $output .= ''; + $output = ''; $id_agent = $this->values['agentId']; $id_group = agents_get_agent_group($id_agent); @@ -445,4 +445,20 @@ class ModuleValueWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 500, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php b/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php index c8a62feafa..e01ae72843 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php +++ b/pandora_console/include/lib/Dashboard/Widgets/monitor_health.php @@ -349,4 +349,20 @@ class MonitorHealthWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 250, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/network_map.php b/pandora_console/include/lib/Dashboard/Widgets/network_map.php index c07e09758f..61a099f902 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/network_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/network_map.php @@ -490,4 +490,20 @@ class NetworkMapWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 470, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/post.php b/pandora_console/include/lib/Dashboard/Widgets/post.php index 584c1af782..e497568093 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/post.php +++ b/pandora_console/include/lib/Dashboard/Widgets/post.php @@ -288,4 +288,20 @@ class PostWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 520, + 'height' => 520, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/reports.php b/pandora_console/include/lib/Dashboard/Widgets/reports.php index 8611665128..cf471c037a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/reports.php +++ b/pandora_console/include/lib/Dashboard/Widgets/reports.php @@ -499,4 +499,20 @@ class ReportsWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 360, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_map.php b/pandora_console/include/lib/Dashboard/Widgets/service_map.php index a2122c6dca..b0230c89e9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_map.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_map.php @@ -254,6 +254,9 @@ class ServiceMapWidget extends Widget $inputs = parent::getFormInputs(); $services_res = services_get_services(); + if ($services_res === false) { + $services_res = []; + } // If currently selected report is not included in fields array (it belongs to a group over which user has no permissions), then add it to fields array. // This is aimed to avoid overriding this value when a user with narrower permissions edits widget configuration. @@ -341,6 +344,8 @@ class ServiceMapWidget extends Widget $size = parent::getSize(); + $output = ''; + if (check_acl($config['id_user'], 0, 'AR') === 0) { $output .= '
'; $output .= \ui_print_error_message( @@ -461,4 +466,20 @@ class ServiceMapWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_view.php b/pandora_console/include/lib/Dashboard/Widgets/service_view.php index d838861659..aa77312a38 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_view.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_view.php @@ -468,4 +468,20 @@ class ServiceViewWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 400, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index bc92ade1f8..3ab23e7e87 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -406,4 +406,20 @@ class SingleGraphWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 480, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php index ae1434891e..33d89b7489 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php +++ b/pandora_console/include/lib/Dashboard/Widgets/sla_percent.php @@ -494,4 +494,20 @@ class SLAPercentWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 550, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php b/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php index 57b4f90fb3..f0bb617a22 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/system_group_status.php @@ -634,4 +634,20 @@ class SystemGroupStatusWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 600, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/tactical.php b/pandora_console/include/lib/Dashboard/Widgets/tactical.php index 74d72d0c5c..3b60acaaea 100755 --- a/pandora_console/include/lib/Dashboard/Widgets/tactical.php +++ b/pandora_console/include/lib/Dashboard/Widgets/tactical.php @@ -494,4 +494,20 @@ class TacticalWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 400, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/tree_view.php b/pandora_console/include/lib/Dashboard/Widgets/tree_view.php index fe76b94ec0..095bd8dc0a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/tree_view.php +++ b/pandora_console/include/lib/Dashboard/Widgets/tree_view.php @@ -726,4 +726,20 @@ class TreeViewWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 520, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/url.php b/pandora_console/include/lib/Dashboard/Widgets/url.php index 41a3420d0a..b0d4d7efd9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/url.php +++ b/pandora_console/include/lib/Dashboard/Widgets/url.php @@ -298,4 +298,20 @@ class UrlWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 300, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php index 5026a240f5..3222c980d9 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php +++ b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction.php @@ -176,7 +176,7 @@ class WuxWidget extends Widget // Must be configured before using. $this->configurationRequired = false; if (empty($this->options) === true) { - $this->configuration_required = true; + $this->configurationRequired = true; } $this->overflow_scrollbars = false; @@ -430,4 +430,20 @@ class WuxWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 360, + ]; + + return $size; + } + + } diff --git a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php index e75a0012d3..5acc972d32 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php +++ b/pandora_console/include/lib/Dashboard/Widgets/wux_transaction_stats.php @@ -390,4 +390,20 @@ class WuxStatsWidget extends Widget } + /** + * Get size Modal Configuration. + * + * @return array + */ + public function getSizeModalConfiguration(): array + { + $size = [ + 'width' => 450, + 'height' => 400, + ]; + + return $size; + } + + } From d0a04177c0fa7dc523255f6168222b16e8a3a046 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 18 May 2022 17:17:31 +0200 Subject: [PATCH 017/197] add treshold pdf pandora_enterprise#1419 --- .../reporting_builder.item_editor.php | 21 +++++++++++++++ .../godmode/reporting/reporting_builder.php | 6 +++++ .../include/ajax/custom_fields.php | 2 +- .../include/class/AgentWizard.class.php | 2 +- pandora_console/include/functions_api.php | 2 +- pandora_console/include/functions_graph.php | 10 +++---- .../include/functions_reporting.php | 6 +++++ .../include/graphs/flot/pandora.flot.js | 26 +++++++++---------- 8 files changed, 54 insertions(+), 21 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 724d695f6a..eff8d41220 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -135,6 +135,7 @@ $current_month = true; // Only avg is selected by default for the simple graphs. $fullscale = false; $percentil = false; +$image_threshold = false; $time_compare_overlapped = false; // Added for events items. @@ -307,6 +308,7 @@ switch ($action) { case 'simple_graph': $fullscale = isset($style['fullscale']) ? (bool) $style['fullscale'] : 0; $percentil = isset($style['percentil']) ? (bool) $style['percentil'] : 0; + $image_threshold = (isset($style['image_threshold']) === true) ? (bool) $style['image_threshold'] : false; $graph_render = $item['graph_render']; // The break hasn't be forgotten. case 'simple_baseline_graph': @@ -2501,6 +2503,23 @@ $class = 'databox filters'; + + + + + + + + + head = []; $table_modules->head[0] = __('Module name'); $table_modules->head[1] = __('Data'); - $table_modules->head[2] = __('Treshold'); + $table_modules->head[2] = __('Threshold'); $table_modules->head[3] = __('Current interval'); $table_modules->head[4] = __('Timestamp'); $table_modules->head[5] = __('Status'); diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index 1600aab4b6..36c5d36c75 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -1181,7 +1181,7 @@ class AgentWizard extends HTML $table->head[1] = ''.__('Server').''; $table->head[2] = ''.__('Type').''; $table->head[3] = ''.__('Description').''; - $table->head[4] = ''.__('Treshold').''; + $table->head[4] = ''.__('Threshold').''; $table->data = []; diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 71128946c5..8155e22415 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -14855,7 +14855,7 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) 'type_graph' => $config['type_module_charts'], 'fullscale' => false, 'return_img_base_64' => true, - 'image_treshold' => $graph_threshold, + 'image_threshold' => $graph_threshold, 'graph_font_size' => $graph_font_size, ]; diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d9493a99b2..df7440754b 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -626,7 +626,7 @@ function grafico_modulo_sparse_data( * 'show_legend' => true, * 'show_overview' => true, * 'return_img_base_64' => false, - * 'image_treshold' => false, + * 'image_threshold' => false, * 'graph_combined' => false, * 'graph_render' => 0, * 'zoom' => 1, @@ -782,8 +782,8 @@ function grafico_modulo_sparse($params) $params['return_img_base_64'] = false; } - if (isset($params['image_treshold']) === false) { - $params['image_treshold'] = false; + if (isset($params['image_threshold']) === false) { + $params['image_threshold'] = false; } if (isset($params['graph_combined']) === false) { @@ -1305,8 +1305,8 @@ function graphic_combined_module( $params['return_img_base_64'] = false; } - if (isset($params['image_treshold']) === false) { - $params['image_treshold'] = false; + if (isset($params['image_threshold']) === false) { + $params['image_threshold'] = false; } if (isset($params['show_unknown']) === false) { diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6bf29c1235..12ff161603 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -10157,6 +10157,11 @@ function reporting_simple_graph( $fullscale = (bool) $content['style']['fullscale']; } + $image_threshold = false; + if (isset($content['style']['image_threshold'])) { + $image_threshold = (bool) $content['style']['image_threshold']; + } + $return['chart'] = ''; // Get chart. @@ -10211,6 +10216,7 @@ function reporting_simple_graph( 'backgroundColor' => 'transparent', 'return_img_base_64' => true, 'graph_render' => $content['graph_render'], + 'image_threshold' => $image_threshold, ]; if ($only_image === false) { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index bdd3aa3038..b30d9e487b 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -1003,7 +1003,7 @@ function pandoraFlotArea( var max_x = date_array["final_date"] * 1000; var type = parseInt(params.stacked); var show_legend = params.show_legend; - var image_treshold = params.image_treshold; + var image_threshold = params.image_threshold; var short_data = params.short_data != "" ? params.short_data : 3; var grid_color = params.grid_color; var background_color = params.backgroundColor; @@ -2198,7 +2198,7 @@ function pandoraFlotArea( } if (thresholded) { - var data_base_treshold = add_threshold( + var data_base_threshold = add_threshold( data_base, threshold_data, ranges.yaxis.from, @@ -2211,7 +2211,7 @@ function pandoraFlotArea( plot = $.plot( $("#" + graph_id), - data_base_treshold, + data_base_threshold, $.extend(true, {}, options, { grid: { borderWidth: 1, @@ -2597,7 +2597,7 @@ function pandoraFlotArea( $("#overview_" + graph_id).bind("mouseout", resetInteractivity); } - if (image_treshold) { + if (image_threshold) { var y_recal = plot.getAxes().yaxis.max; if (!thresholded) { // Recalculate the y axis @@ -2611,7 +2611,7 @@ function pandoraFlotArea( ); } - var datas_treshold = add_threshold( + var datas_threshold = add_threshold( data_base, threshold_data, plot.getAxes().yaxis.min, @@ -2624,7 +2624,7 @@ function pandoraFlotArea( plot = $.plot( $("#" + graph_id), - datas_treshold, + datas_threshold, $.extend(true, {}, options, { yaxis: { max: y_recal.max @@ -2758,7 +2758,7 @@ function pandoraFlotArea( ); } - datas_treshold = add_threshold( + datas_threshold = add_threshold( data_base, threshold_data, plot.getAxes().yaxis.min, @@ -2771,7 +2771,7 @@ function pandoraFlotArea( plot = $.plot( $("#" + graph_id), - datas_treshold, + datas_threshold, $.extend(true, {}, options, { yaxis: { min: max_draw["min"], @@ -3115,7 +3115,7 @@ function axis_thresholded( return y; } -//add treshold +//add threshold function add_threshold( data_base, threshold_data, @@ -3235,13 +3235,13 @@ function add_threshold( } }); - var extreme_treshold_array = []; + var extreme_threshold_array = []; var i = 0; var flag = true; $.each(threshold_array, function(index, value) { flag = true; - extreme_treshold_array[i] = { + extreme_threshold_array[i] = { below: value["max"], color: value["color"] }; @@ -3252,7 +3252,7 @@ function add_threshold( } }); if (flag) { - extreme_treshold_array[i] = { + extreme_threshold_array[i] = { below: value["min"], color: datas[0].color }; @@ -3260,7 +3260,7 @@ function add_threshold( } }); - datas[0].threshold = extreme_treshold_array; + datas[0].threshold = extreme_threshold_array; return datas; } From f253ea561a7a869c23ce16bc8369e92c2afaae0b Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 19 May 2022 10:14:41 +0200 Subject: [PATCH 018/197] fixed query filter --- .../godmode/reporting/reporting_builder.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 608f2f6a54..7073ce1702 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -743,8 +743,9 @@ switch ($action) { $search = trim(get_parameter('search', '')); $search_sql = ''; - if ($search != '') { - $search_name = '%'.$search."%' OR description LIKE '%".$search.'%'; + + if ($search !== '') { + $search_name = "(name LIKE '%".$search."%' OR description LIKE '%".$search."%')"; } $table_aux = new stdClass(); @@ -830,13 +831,10 @@ switch ($action) { $return_all_group = false; } - if ($search != '') { - $filter = [ - 'name' => $search_name, - 'order' => 'name', - ]; - } else { - $filter = ['order' => 'name']; + $filter = ['order' => 'name']; + + if ($search !== '') { + $filter[] = $search_name; } // Fix : group filter was not working From 9d2c1794239303da49547adbecc5cdf97984ad4b Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Thu, 19 May 2022 18:00:49 +0200 Subject: [PATCH 019/197] add new widget color tabs module pandora_enterprise#8621 --- .../images/widgets/ColorModuleTabs.png | Bin 0 -> 3597 bytes pandora_console/include/functions_html.php | 102 +++++ pandora_console/include/functions_modules.php | 34 ++ pandora_console/include/javascript/pandora.js | 63 ++- .../include/lib/Dashboard/Widget.php | 4 + .../lib/Dashboard/Widgets/ColorModuleTabs.php | 404 ++++++++++++++++++ .../lib/Dashboard/Widgets/single_graph.php | 11 +- pandora_console/include/styles/dashboards.css | 71 +++ 8 files changed, 682 insertions(+), 7 deletions(-) create mode 100644 pandora_console/images/widgets/ColorModuleTabs.png create mode 100644 pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php diff --git a/pandora_console/images/widgets/ColorModuleTabs.png b/pandora_console/images/widgets/ColorModuleTabs.png new file mode 100644 index 0000000000000000000000000000000000000000..02c0e17987ecfad5ebdd2c77ec3e5e4dba09632f GIT binary patch literal 3597 zcmV+o4)XDdP)KC*1B+eMr@VHPlkc{CtzaPp28oHj|GA z({Uzq(c^RjBZ<)gPYlR58WO7sSCacrNE23#SkkN_P{RXsd4K?-TF&^7FJYr-f~M01 zq5}k|K>$d-CpGv{G=L%;SB?N$(115xf;55>H%35^k}~jS9bz;kVv_*n08mcAstFhx z3y=kJZMQSTna*Xn_-qpc2P-eujLJxMibpR8@c=`T%1MGL9jMs=NSz1b13<-&=<)yo z#7Ig|0}Wdbqyo@{HvkO|BrA6y8BBCK#sUO^4){P!RwS6aNC4QgFsVs|6ab5CqANpC z0!B{6`072p^&qGiAfy4k6oB#F)XRvqumI+>dSW!dEPz#5Am8n}*+r}e`x$8&S6GWS ze8m9B^`HU>RMEpgsnZdRx*MbpUyy?AU_s)8lIVO~K?f=xe*o)z5P10R4A`QN-=8tq zD`zsi_8{C#1_9*x@?)a4Eda`Vv|&6Ipa!fcb1aF*-mN!7Kq`5`1}{q^3Hy zR`{&rVI;Lhh_(#WdI$LiRFNY0oC(xplyyQDolb`PMqk>G_B|euZ$LFPEDmXE83-J_ zJDt1+4?X~kBjg4TOboe!gB+J+TLy|FP&*MegaS&DATbb-;6tR&i%&Nav<%j|62#YI z*>t5AWmE-bDSA`<=Bxd<#&rad+l?Ral^W>531WjR1vTkF31!ilWN@N^jRj#Tj6a|c zM3B<3AqBu2L3FKR2Cnj?b+dp8kHQON+H-)U1`pkva<~Sn&}#HXpan!XCjbJlYyB(@ z#BekRE^a-C4lWfOx>nFlgmZK3;^Ly4WBnX1g?gYE*FcBmcr4d_b&PUc`sSoSLA9S`h<^FTCxOA^6r~gVw4CPw1J0*Uup?P4b4jJ zvl$r@LfPpB6hd=OpEa=nW@r)m*wgW*rhUUmOuHb3)(b5bRAVRJCNJroXfl0~bKdCi z4IYqs`+O43D*DR3%~Ntd-qmhQ)?yN5q*7OZf+kre0I|dM;v%!PLJ69x+z)Jmw5kpc zSy-g5K^6qzl|%O1C~*U9{91~xQ##@d);Kg46u%DLc0vw&Lo4-f&>1I@tJo?6_x=%I z`FMnXV&M)M$J&aIbj%6C7=k4K_V%%BV5#IsH$M-S2Vayme5An&` zF8ZFeVMoFqMVT-$5p(z7uiegRx)Cn2j-LMrrw8NiKG$ZY0h5Y#hOeoD4oz^f{VA88 zN7FMH7g_SITq<1-uUB#^+r^}J}bnHkUD^=_0;Nnts1{Oy~0 zf98E}o_@xLrpAZrPRSdyRCjMVCFT)Zl|YvKtjVxY zUx7L)j!hCseeF5>Sn8HlJ&WzQoLQ|c_p&IlA!YfY>i=d;q+-a0?6JYsVQW6HzVA5k1l~h6d>m?NRy zS&4swDzw{UmWI2nX;BEDvyxzM)wukzQ48E&S(|z+OPcP5`_6uMpOQh_V5*gE__BE4 zHXLd=6>}?@7Ry$$VGWj{OwzePR};rl!KuuuEJfK%c*kuM4mcKZDk7?`vJ^`~n(3i? z>F&>M9b&pPDGFo`xPHjF_8m(RM^mHWE*7hj7a}u)ATGXpHv>zMA#~m^>_Dc~i2*Fa z(&X+4iEZpboJLpBQWB!`c%dpnvJWh`zqTBnv!-~(wAe!R04&5@iZtPCLM*mYJt1Y5 zDFwZV#CCC9Fj0>b*~BPCL`DQ$q7&RZ@5wxv>+ibP0hAyXz0X=D&F{1O+>ip(9Bva3 zq>&_{;Mvo}5J9^V=vYOLSzy?R&Eqrq=WXIELQ3vCA_sJ(O}KqumH{CijO)so0L&i{ zTW`AP^7i|$voGP$ioLQRP9FdqM`d{BNgAfmfkYFzF2*+_!WRGD1Vv+>ggIBNH zdJCPsE$b(axhiNOvQfw#r5q!yY;jD$r$-;X@n!ka>^Yu#cmIg0t(z~Jui2-jCO@Id zKC;HKoOs3)X8DMh#8Jp=A%^Vl`sV8X3KtxWFL;wnUhC=gnE2%*7Br_nFg&=2<5B1p zgGXJJ9+Vy{DJL=A%$|>c*N3f1uwzN0ZrdLysfAC&9MY;?)-FU7u(i=1+FbuPCQ`wf zhu)y8v5<;Nsq_b)?~v3!iQ*GRgNaO6Ni8+#KRHjo)9E1b}PF<7dPjKMB0PUSUZ`42#hBtwpP!T~vQXnBw zgh-)<3l%hc{D4RxM2S#-L6l!`AW9Snh(3e{sB%zHMdCoBjwljA0lFX|J}Uh9c8`tY zZ+q=s$FE{R6rXkS>lx3^&b-t9IEFEozr5Np62r|R-Hd1C@0jxEKw6|P1DJkGSh-~I z(!j4?5c_4AO#&Z{GFs0X2~*n$ljJN(VkRtneg=}r<+@26tC66`B4kd5Ls+eYz_AKR zx+Y1Q5X}Rm-At>SY%O7OoxLXPP2QP6Uy|2%hOmnA1umfU_TVy80%f%^HW7t$H>DD0 zp*mq>i7VPmTb0OX)3BJQ=p;8`GMLzCXvA0L+HN-MvS2)?RlRS?Dh%%5R@UaItUcW} z@2@+(6iBOYmZevHtFmnjs!)Zd9KsS1Os0i^n~Y^_k6NV8h& zO^GB^w3#%T&ew4~{a?p1&1YOBEh*@*LSEpHHYY~)hzFYju`UX}DK+L_tdjGnsW#nD zZXg(mtX4i0V_mgp)49=94nxMLFR#SUzu)|Na9m#8d?fzr$jXiIgoudh3|Qi?b}??Ppjl#^qHrnKlw#6C65D3`co!?)d) zJux&R6m9xeTEjH9Dt!Zv0zETTpqpr6Huesv-~(W7bY>N`4uTXqOjP@f#X-uRzKAfw z!bVwJ0jxpw{y~`E$3$9`=Ne)C0)Ru%<-@py^y%0OY+!6=A+! z%^e))*AZ@MPx+)l9ygr`aNWDpf=qOTkYG%sng$V&Rc3k#qBzJgo;-TaCy(n#2{oA@ zD_B((m94L2`q1Fl_UL8pO-yv(b1@glW%af+pl2hdA$4WV$bBkvK{dvD6Z z7v@%~w61+T#7(irEp|PQi>Bv??R9^RgbdQt&0Av1d#cIOn{iOX zrjae<|GL$sb%{JMkj6tW+UAkNt1DV~hYpV)j|nBIOf}vy&Jzp)+&oBwEHV~)7GAj^ z&gGmmSr6Q(FMsV3!%Yqfc_qEKAPdVvKMR>{4z9`dl&duC3PXdxG*wfT)Xl3sFJ(=7 z(4hw}+_ZIxZ2@UD=p~IgPAgwD zEt)e3+EzSIGm|=tEE5;I*WOnnSk^~5$03j0R7W_r$!R%ev$WS1k!IBF%z2w@s=tl8GY!ERLV zOQK5MUo@_SBXg2V2gK?iXE7?R{fV_cRM^&;$txe5MMwnekmj __('Show common modules'), + 1 => __('Show all modules'), + ]; + + $output .= '
  • '; + $output .= html_print_label(__('Type'), '', true); + $output .= html_print_select( + $selection, + $data['selectionModulesNameId'], + $data['selectionModules'], + 'selection_multiple_change(\''.base64_encode(json_encode($data)).'\')', + '', + 0, + true, + false, + true, + '', + false, + 'min-width: 180px' + ); + $output .= '
  • '; + + $all_modules = []; + if (empty($data['agent_ids']) === false) { + $all_modules = get_modules_agents( + 0, + $data['agent_ids'], + $data['selectionModules'], + true + ); + } + + $output .= '
  • '; + $output .= html_print_label(__('Modules'), '', true); + $output .= html_print_select( + $all_modules, + $data['modules_name'], + $data['modules_ids'], + '', + '', + 0, + true, + true, + true, + '', + false, + 'min-width: 150px; max-width: 500px; max-height: 100px', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true, + true + ); + $output .= '
  • '; + + // $output .= html_print_input_hidden( + // 'module-multiple-text', + // json_encode($agents_select) + // ); + break; + default: // Ignore. break; diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index f94a8b687d..dcd3c6ebe7 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -2820,6 +2820,40 @@ function modules_get_color_status($status, $force_module=false) } +/** + * Text color status. + * + * @param string $status Type status. + * + * @return string Color. + */ +function modules_get_textcolor_status($status) +{ + $result = '#ffffff'; + switch ($status) { + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + case AGENT_MODULE_STATUS_WARNING_ALERT: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + $result = '#000000'; + break; + + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_NOT_NORMAL: + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_ALL: + case AGENT_MODULE_STATUS_UNKNOWN: + default: + $result = '#ffffff'; + break; + } + + return $result; +} + + /** * Gets a module status an modify the status and title reference variables * diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index 740ff0f265..0119cfa822 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -1,4 +1,4 @@ -/* global $ */ +/* global $ jQuery */ /* exported load_modal */ var ENTERPRISE_DIR = "enterprise"; @@ -2027,3 +2027,64 @@ function inArray(needle, haystack) { } return false; } + +// eslint-disable-next-line no-unused-vars +function agent_multiple_change(e, info) { + info = JSON.parse(atob(info)); + jQuery.post( + "ajax.php", + { + page: "operation/agentes/ver_agente", + get_modules_group_json: 1, + selection: $("#" + info.selectionModulesNameId).val(), + id_agents: $("#" + info.agent_name.replace("[]", "")).val(), + select_mode: 1 + }, + function(data) { + var name = info.modules_name.replace("[]", ""); + if (JSON.stringify($(e).val()) !== JSON.stringify(info.agent_ids)) { + $("#" + name).html(""); + $("#checkbox-" + name + "-check-all").prop("checked", false); + if (data) { + jQuery.each(data, function(id, value) { + var option = $("") + .attr("value", id) + .html(value); + $("#" + name).append(option); + }); + } + } + }, + "json" + ); +} + +// eslint-disable-next-line no-unused-vars +function selection_multiple_change(info) { + info = JSON.parse(atob(info)); + jQuery.post( + "ajax.php", + { + page: "operation/agentes/ver_agente", + get_modules_group_json: 1, + id_agents: $("#" + info.agent_name.replace("[]", "")).val(), + selection: $("#" + info.selectionModulesNameId).val(), + select_mode: 1 + }, + function(data) { + var name = info.modules_name.replace("[]", ""); + $("#" + name).html(""); + // Check module all. + $("#checkbox-" + name + "-check-all").prop("checked", false); + if (data) { + jQuery.each(data, function(id, value) { + var option = $("") + .attr("value", id) + .html(value); + $("#" + name).append(option); + }); + } + }, + "json" + ); +} diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 320280718b..776e0a837f 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -412,6 +412,10 @@ class Widget $className .= '\WuxWidget'; break; + case 'ColorModuleTabs': + $className .= '\\'.$name; + break; + default: $className = false; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php b/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php new file mode 100644 index 0000000000..a6e9cfed2a --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php @@ -0,0 +1,404 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Cell Id. + $this->cellId = $cellId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Positions. + $this->position = $this->getPositionWidget(); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Color tabs modules'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'single_graph'; + } + + // This forces at least a first configuration. + $this->configurationRequired = false; + if (empty($this->values['moduleColorModuleTabs']) === true) { + $this->configurationRequired = true; + } + + $this->overflow_scrollbars = false; + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + $values['agentsColorModuleTabs'] = []; + if (isset($decoder['agentsColorModuleTabs']) === true) { + if (isset($decoder['agentsColorModuleTabs'][0]) === true + && empty($decoder['agentsColorModuleTabs']) === false + ) { + $values['agentsColorModuleTabs'] = explode( + ',', + $decoder['agentsColorModuleTabs'][0] + ); + } + } + + if (isset($decoder['selectionColorModuleTabs']) === true) { + $values['selectionColorModuleTabs'] = $decoder['selectionColorModuleTabs']; + } + + $values['moduleColorModuleTabs'] = []; + if (isset($decoder['moduleColorModuleTabs']) === true) { + if (isset($decoder['moduleColorModuleTabs'][0]) === true + && empty($decoder['moduleColorModuleTabs']) === false + ) { + $values['moduleColorModuleTabs'] = explode( + ',', + $decoder['moduleColorModuleTabs'][0] + ); + } + } + + if (isset($decoder['formatData']) === true) { + $values['formatData'] = $decoder['formatData']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + $inputs[] = [ + 'arguments' => [ + 'type' => 'select_multiple_modules_filtered_select2', + 'agent_values' => agents_get_agents_selected(0), + 'agent_name' => 'agentsColorModuleTabs[]', + 'agent_ids' => $values['agentsColorModuleTabs'], + 'selectionModules' => true, + 'selectionModulesNameId' => 'selectionColorModuleTabs', + 'modules_ids' => $values['moduleColorModuleTabs'], + 'modules_name' => 'moduleColorModuleTabs[]', + ], + ]; + + // Format Data. + $inputs[] = [ + 'label' => __('Format Data'), + 'arguments' => [ + 'name' => 'formatData', + 'id' => 'formatData', + 'type' => 'switch', + 'value' => $values['formatData'], + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost():array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['agentsColorModuleTabs'] = \get_parameter('agentsColorModuleTabs', []); + $values['selectionColorModuleTabs'] = \get_parameter('selectionColorModuleTabs', 0); + $values['moduleColorModuleTabs'] = \get_parameter('moduleColorModuleTabs', []); + $values['formatData'] = \get_parameter_switch('formatData', 0); + + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + $size = parent::getSize(); + + $sql = sprintf( + 'SELECT tagente_modulo.id_agente_modulo AS `id`, + tagente_modulo.nombre AS `name`, + tagente_modulo.unit AS `unit`, + tagente_estado.datos AS `data`, + tagente_estado.timestamp AS `timestamp`, + tagente_estado.estado AS `status` + FROM tagente_modulo + LEFT JOIN tagente_estado + ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo + WHERE tagente_modulo.id_agente_modulo IN (%s)', + implode(',', $this->values['moduleColorModuleTabs']) + ); + + $modules = db_get_all_rows_sql($sql); + + $output = '
    '; + foreach ($modules as $module) { + $output .= $this->drawTabs($module); + } + + $output .= '
    '; + return $output; + } + + + /** + * Draw tab module. + * + * @param array $data Info module. + * + * @return string Output. + */ + private function drawTabs(array $data):string + { + global $config; + + $background = modules_get_color_status($data['status'], true); + $color = modules_get_textcolor_status($data['status']); + + $style = 'background-color:'.$background.'; color:'.$color.';'; + $output = '
    '; + $output .= ''; + $output .= $data['name']; + $output .= ''; + $output .= ''; + if ($data['data'] !== null && $data['data'] !== '') { + if (isset($this->values['formatData']) === true + && (bool) $this->values['formatData'] === true + ) { + $output .= format_for_graph( + $data['data'], + $config['graph_precision'] + ); + } else { + $output .= sla_truncate( + $data['data'], + $config['graph_precision'] + ); + } + } else { + $output .= '--'; + } + + $output .= ''; + $output .= ' '.$data['unit']; + $output .= ''; + $output .= ''; + $output .= '
    '; + + return $output; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Color tabs modules'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'ColorModuleTabs'; + } + + +} diff --git a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php index bc92ade1f8..6c3bf6102a 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/single_graph.php +++ b/pandora_console/include/lib/Dashboard/Widgets/single_graph.php @@ -1,10 +1,10 @@ __('Module'), 'arguments' => [ 'type' => 'autocomplete_module', - 'fields' => $fields, 'name' => 'moduleId', 'selected' => $values['moduleId'], 'return' => true, @@ -353,8 +352,8 @@ class SingleGraphWidget extends Widget include_once $config['homedir'].'/include/functions_agents.php'; include_once $config['homedir'].'/include/functions_modules.php'; - $module_name = \modules_get_agentmodule_name($id_module); - $units_name = \modules_get_unit($id_module); + $module_name = \modules_get_agentmodule_name($this->values['moduleId']); + $units_name = \modules_get_unit($this->values['moduleId']); $trickHight = 10; if ($this->values['showLegend'] === 1) { diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index b6b774c208..dad32d5ac0 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -572,3 +572,74 @@ div#main_pure { #main_page > .ui-content div.label > p { margin: 0; } + +form.modal-dashboard ul.wizard li label { + max-width: 30%; +} + +form.modal-dashboard ul.wizard li.agents_select2, +form.modal-dashboard ul.wizard li.modules_select2 { + align-items: center; + justify-content: center; +} + +form.modal-dashboard + ul.wizard + li.agents_select2 + div.flex-row-center + div.flex-column, +form.modal-dashboard + ul.wizard + li.modules_select2 + div.flex-row-center + div.flex-column { + flex: 0; + height: 45px; +} + +.ui-dialog .ui-dialog-title { + top: -3px !important; +} + +.select2-container--default + .select2-selection--multiple + .select2-selection__choice { + margin: 0px; +} + +.container-tabs { + width: 100%; + height: calc(100% + 80px); + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + align-content: space-around; + flex-wrap: wrap; +} + +.widget-module-tabs { + flex: 1; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + min-width: 100px; + min-height: 95px; + margin: 2px; + padding: 5px; +} + +.widget-module-tabs-title { + word-break: break-word; +} + +.widget-module-tabs-data { + font-size: larger; + font-weight: bolder; +} + +.widget-module-tabs-unit { + font-size: smaller; + font-style: italic; +} From 31ef3f537566a265d299a203a13c38034fe7a0c0 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 23 May 2022 12:20:50 +0200 Subject: [PATCH 020/197] add new widget color tabs module pandora_enterprise#8621 --- pandora_console/include/functions_modules.php | 2 +- .../lib/Dashboard/Widgets/ColorModuleTabs.php | 125 +++++++++++++++--- 2 files changed, 108 insertions(+), 19 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index dcd3c6ebe7..686efe8b11 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -3664,7 +3664,7 @@ function get_modules_agents($id_module_group, $id_agents, $selection, $select_mo } } - if (!$selection) { + if (!$selection && $useName === true) { // Common modules. $final_modules = []; $nodes_consulted = count($modules); diff --git a/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php b/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php index a6e9cfed2a..f1907af532 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php +++ b/pandora_console/include/lib/Dashboard/Widgets/ColorModuleTabs.php @@ -28,6 +28,8 @@ namespace PandoraFMS\Dashboard; +use PandoraFMS\Enterprise\Metaconsole\Node; + global $config; /** @@ -215,13 +217,8 @@ class ColorModuleTabs extends Widget $values['moduleColorModuleTabs'] = []; if (isset($decoder['moduleColorModuleTabs']) === true) { - if (isset($decoder['moduleColorModuleTabs'][0]) === true - && empty($decoder['moduleColorModuleTabs']) === false - ) { - $values['moduleColorModuleTabs'] = explode( - ',', - $decoder['moduleColorModuleTabs'][0] - ); + if (empty($decoder['moduleColorModuleTabs']) === false) { + $values['moduleColorModuleTabs'] = $decoder['moduleColorModuleTabs']; } } @@ -253,7 +250,7 @@ class ColorModuleTabs extends Widget 'agent_values' => agents_get_agents_selected(0), 'agent_name' => 'agentsColorModuleTabs[]', 'agent_ids' => $values['agentsColorModuleTabs'], - 'selectionModules' => true, + 'selectionModules' => $values['selectionColorModuleTabs'], 'selectionModulesNameId' => 'selectionColorModuleTabs', 'modules_ids' => $values['moduleColorModuleTabs'], 'modules_name' => 'moduleColorModuleTabs[]', @@ -285,9 +282,24 @@ class ColorModuleTabs extends Widget // Retrieve global - common inputs. $values = parent::getPost(); - $values['agentsColorModuleTabs'] = \get_parameter('agentsColorModuleTabs', []); - $values['selectionColorModuleTabs'] = \get_parameter('selectionColorModuleTabs', 0); - $values['moduleColorModuleTabs'] = \get_parameter('moduleColorModuleTabs', []); + $values['agentsColorModuleTabs'] = \get_parameter( + 'agentsColorModuleTabs', + [] + ); + $values['selectionColorModuleTabs'] = \get_parameter( + 'selectionColorModuleTabs', + 0 + ); + + $values['moduleColorModuleTabs'] = \get_parameter( + 'moduleColorModuleTabs' + ); + + $values['moduleColorModuleTabs'] = get_same_modules_all( + explode(',', $values['agentsColorModuleTabs'][0]), + explode(',', $values['moduleColorModuleTabs'][0]) + ); + $values['formatData'] = \get_parameter_switch('formatData', 0); return $values; @@ -305,6 +317,80 @@ class ColorModuleTabs extends Widget $size = parent::getSize(); + $output = ''; + + if (is_metaconsole() === true) { + $modules_nodes = array_reduce( + $this->values['moduleColorModuleTabs'], + function ($carry, $item) { + $explode = explode('|', $item); + $carry[$explode[0]][] = $explode[1]; + return $carry; + }, + [] + ); + + $modules = []; + foreach ($modules_nodes as $n => $mod) { + try { + $node = new Node((int) $n); + $node->connect(); + $node_mods = $this->getInfoModules($mod); + if (empty($node_mods) === false) { + foreach ($node_mods as $value) { + $value['id_node'] = $n; + $value['server_name'] = $node->toArray()['server_name']; + $modules[] = $value; + } + } + + $node->disconnect(); + } catch (\Exception $e) { + // Unexistent agent. + $node->disconnect(); + } + } + } else { + $modules = $this->getInfoModules( + $this->values['moduleColorModuleTabs'] + ); + } + + if ($modules !== false && empty($modules) === false) { + $output .= '
    '; + foreach ($modules as $module) { + $output .= $this->drawTabs($module); + } + + $output .= '
    '; + } else { + $output .= '
    '; + $output .= \ui_print_info_message( + __('Not found modules'), + '', + true + ); + $output .= '
    '; + } + + return $output; + } + + + /** + * Get info modules. + * + * @param array $modules Modules. + * + * @return array Data. + */ + private function getInfoModules(array $modules): array + { + $where = sprintf( + 'tagente_modulo.id_agente_modulo IN (%s)', + implode(',', $modules) + ); + $sql = sprintf( 'SELECT tagente_modulo.id_agente_modulo AS `id`, tagente_modulo.nombre AS `name`, @@ -315,19 +401,17 @@ class ColorModuleTabs extends Widget FROM tagente_modulo LEFT JOIN tagente_estado ON tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo - WHERE tagente_modulo.id_agente_modulo IN (%s)', - implode(',', $this->values['moduleColorModuleTabs']) + WHERE %s', + $where ); $modules = db_get_all_rows_sql($sql); - $output = '
    '; - foreach ($modules as $module) { - $output .= $this->drawTabs($module); + if ($modules === false) { + $modules = []; } - $output .= '
    '; - return $output; + return $modules; } @@ -348,6 +432,11 @@ class ColorModuleTabs extends Widget $style = 'background-color:'.$background.'; color:'.$color.';'; $output = '
    '; $output .= ''; + if (is_metaconsole() === true) { + $output .= $data['server_name']; + $output .= '
    '; + } + $output .= $data['name']; $output .= '
    '; $output .= ''; From c2fe3c5d34850a7d768d4f631b6ac7381de0ff27 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 23 May 2022 16:03:37 +0200 Subject: [PATCH 021/197] #9009 Fixed icon --- .../include/lib/Dashboard/Widgets/module_status.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/lib/Dashboard/Widgets/module_status.php b/pandora_console/include/lib/Dashboard/Widgets/module_status.php index 0a0fe65615..8efdd62936 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/module_status.php +++ b/pandora_console/include/lib/Dashboard/Widgets/module_status.php @@ -478,7 +478,7 @@ class ModuleStatusWidget extends Widget case 4: // Critical (ALERT). - $icon = '4'.$icon.'_bad.png'; + $icon = $icon.'_bad.png'; break; case 0: @@ -493,7 +493,7 @@ class ModuleStatusWidget extends Widget case 10: // Warning (ALERT). - $icon = '4'.$icon.'_warning.png'; + $icon = $icon.'_warning.png'; break; case 3: From 1379ca43b0f33091ebf122b70696f8d81547594a Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 23 May 2022 17:10:00 +0200 Subject: [PATCH 022/197] #8984 Fixed pagination --- pandora_console/godmode/alerts/alert_templates.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/alerts/alert_templates.php b/pandora_console/godmode/alerts/alert_templates.php index 4833ef8b55..17f281571c 100644 --- a/pandora_console/godmode/alerts/alert_templates.php +++ b/pandora_console/godmode/alerts/alert_templates.php @@ -352,14 +352,15 @@ if ($search_string) { $filter[] = "(name LIKE '%".$search_string."%' OR description LIKE '%".$search_string."%' OR value LIKE '%".$search_string."%')"; } -$total_templates = alerts_get_alert_templates($filter, ['COUNT(*) AS total']); -$total_templates = $total_templates[0]['total']; $filter['offset'] = (int) get_parameter('offset'); $filter['limit'] = (int) $config['block_size']; if (!is_user_admin($config['id_user'])) { $filter['id_group'] = array_keys(users_get_groups(false, 'LM')); } +$total_templates = alerts_get_alert_templates($filter, ['COUNT(*) AS total']); +$total_templates = $total_templates[0]['total']; + $templates = alerts_get_alert_templates( $filter, [ From 8d04570989d86899699e1c3f9b1b9ae6d2d20e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 24 May 2022 10:59:41 +0200 Subject: [PATCH 023/197] Set new mode for manage properly the restarting of snmptrap process --- pandora_server/lib/PandoraFMS/SNMPServer.pm | 31 +++++++++++++-------- pandora_server/util/pandora_manage.pl | 17 ++++++++++- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/SNMPServer.pm b/pandora_server/lib/PandoraFMS/SNMPServer.pm index 492dfdfa60..581c1b441d 100644 --- a/pandora_server/lib/PandoraFMS/SNMPServer.pm +++ b/pandora_server/lib/PandoraFMS/SNMPServer.pm @@ -40,6 +40,7 @@ use PandoraFMS::ProducerConsumerServer; # Inherits from PandoraFMS::ProducerConsumerServer our @ISA = qw(PandoraFMS::ProducerConsumerServer); +our @EXPORT = qw(start_snmptrapd); # Global variables my @TaskQueue :shared; @@ -442,26 +443,29 @@ sub start_snmptrapd ($) { # Manual start of snmptrapd if ($config->{'snmp_trapd'} eq 'manual') { - logger ($config, "No SNMP trap daemon configured. Start snmptrapd manually.", 1); - print_message ($config, " [*] No SNMP trap daemon configured. Start snmptrapd manually.", 1); + my $noSNMPTrap = "No SNMP trap daemon configured. Start snmptrapd manually."; + logger ($config, $noSNMPTrap, 1); + print_message ($config, " [*] $noSNMPTrap", 1); if (! -f $config->{'snmp_logfile'}) { - logger ($config, "SNMP log file " . $config->{'snmp_logfile'} . " not found.", 1); - print_message ($config, " [E] SNMP log file " . $config->{'snmp_logfile'} . " not found.", 1); + my $noLogFile = "SNMP log file " . $config->{'snmp_logfile'} . " not found."; + logger ($config, $noLogFile, 1); + print_message ($config, " [E] $noLogFile", 1); return 1; } - + return 0; } - + if ( -e $pid_file && open (PIDFILE, $pid_file)) { my $pid = + 0; - close PIDFILE; + close PIDFILE; # Check if snmptrapd is running if ($snmptrapd_running = kill (0, $pid)) { - logger ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1); - print_message ($config, "snmptrapd (pid $pid) is already running, attempting to kill it...", 1); + my $alreadyRunning = "snmptrapd (pid $pid) is already running, attempting to kill it..."; + logger ($config, $alreadyRunning, 1); + print_message ($config, " [*] $alreadyRunning ", 1); kill (9, $pid); } } @@ -471,17 +475,20 @@ sub start_snmptrapd ($) { # Select agent-addr field of the PDU or PDU source address for V1 traps my $address_format = ($config->{'snmp_pdu_address'} eq '0' ? '%a' : '%b'); - + my $snmptrapd_args = ' -t -On -n' . $snmp_ignore_authfailure . ' -Lf ' . $config->{'snmp_logfile'} . ' -p ' . $pid_file; $snmptrapd_args .= ' --format1=SNMPv1[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]' . $address_format . '[**]%N[**]%w[**]%W[**]%q[**]%v\\\n'; $snmptrapd_args .= ' --format2=SNMPv2[**]%4y-%02.2m-%l[**]%02.2h:%02.2j:%02.2k[**]%b[**]%v\\\n'; if (system ($config->{'snmp_trapd'} . $snmptrapd_args . " >$DEVNULL 2>&1") != 0) { - logger ($config, " [E] Could not start snmptrapd.", 1); - print_message ($config, " [E] Could not start snmptrapd.", 1); + my $showError = "Could not start snmptrapd."; + logger ($config, $showError, 1); + print_message ($config, " [E] $showError ", 1); return 1; } + print_message ($config, " [*] snmptrapd started and running.", 1); + return 0; } diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 26f0b847c7..57a4036875 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -231,6 +231,7 @@ sub help_screen{ print "\nTOOLS:\n\n" unless $param ne ''; help_screen_line('--exec_from_file', ' ', "Execute any CLI option \n\t with macros from CSV file"); help_screen_line('--create_snmp_trap', ' ', "Create a new trap definition. \n\tSeverity 0 (Maintenance), 1(Info) , 2 (Normal), 3 (Warning), 4 (Critical), 5 (Minor) and 6 (Major)"); + help_screen_line('--start_snmptrapd', '[no parameters needed]', "Start the snmptrap process or restart if it is running"); print "\nSETUP:\n\n" unless $param ne ''; help_screen_line('--set_event_storm_protection', '', "Enable (1) or disable (0) event \n\t storm protection"); @@ -279,7 +280,7 @@ sub api_call($$$;$$$$) { my $ua = new LWP::UserAgent; my $url = $pa_config->{"console_api_url"}; my $response = $ua->post($url, $params); - + if ($response->is_success) { $content = $response->decoded_content(); } @@ -1163,6 +1164,16 @@ sub cli_enable_group() { pandora_enable_group ($conf, $dbh, $id_group); } +############################################################################## +# Start snmptrap process. +# Related option: --start_snmptrapd +############################################################################## +sub cli_start_snmptrapd() { + use PandoraFMS::SNMPServer; + print_log "[INFO] Starting snmptrap process. \n"; + PandoraFMS::SNMPServer::start_snmptrapd(\%conf); +} + ############################################################################## # Create an agent. # Related option: --created_agent @@ -7505,6 +7516,10 @@ sub pandora_manage_main ($$$) { param_check($ltotal, 1); cli_enable_group(); } + elsif ($param eq '--start_snmptrapd') { + #param_check($ltotal, 0); + cli_start_snmptrapd(); + } elsif ($param eq '--create_agent') { param_check($ltotal, 8, 4); cli_create_agent(); From 3623849ce4495553fc7debc268dc1f6ce99edd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Tue, 24 May 2022 11:04:29 +0200 Subject: [PATCH 024/197] Fix logrotate --- pandora_server/util/pandora_logrotate | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora_server/util/pandora_logrotate b/pandora_server/util/pandora_logrotate index 3ac2623122..08d999d556 100644 --- a/pandora_server/util/pandora_logrotate +++ b/pandora_server/util/pandora_logrotate @@ -55,5 +55,8 @@ rotate 1 maxage 30 notifempty + postrotate + /usr/local/bin/pandora_manage /etc/pandora/pandora_server.conf --start_snmptrapd > /dev/null 2>/dev/null || true copytruncate + endscript } From 4f27aba72c4f6ab4581e2543593bcd2ebb95b370 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Wed, 25 May 2022 09:06:22 +0200 Subject: [PATCH 025/197] new widget block histogram pandora_enterprise#8618 --- pandora_console/include/functions_graph.php | 5 +- .../include/functions_reporting.php | 15 +- .../include/functions_reporting_html.php | 4 +- .../include/functions_treeview.php | 2 +- .../include/graphs/flot/pandora.flot.js | 6 +- .../include/lib/Dashboard/Widget.php | 1 + .../lib/Dashboard/Widgets/BlockHistogram.php | 632 ++++++++++++++++++ pandora_console/include/styles/dashboards.css | 22 +- 8 files changed, 675 insertions(+), 12 deletions(-) create mode 100644 pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index d9493a99b2..ffd905fe95 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -3015,7 +3015,7 @@ function graph_sla_slicebar( true, $ttl, false, - false, + true, $date ); } @@ -4024,7 +4024,7 @@ function graph_graphic_agentevents( EVENT_CRIT_CRITICAL => COL_CRITICAL, ]; - // Draw slicebar graph + // Draw slicebar graph. $out = flot_slicesbar_graph( $data, $period, @@ -4043,6 +4043,7 @@ function graph_graphic_agentevents( $not_interactive, 1, $widgets, + true, $server_id ); diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 6bf29c1235..9d1c898255 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -14702,6 +14702,16 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) ); } + $showLabelTicks = true; + if (isset($content['showLabelTicks']) === true) { + $showLabelTicks = $content['showLabelTicks']; + } + + $height_graph = 80; + if (isset($content['height_graph']) === true) { + $height_graph = $content['height_graph']; + } + $return['title'] = $title; $return['landscape'] = $content['landscape']; $return['pagebreak'] = $content['pagebreak']; @@ -14948,7 +14958,6 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) ]; $width_graph = 100; - $height_graph = 80; if (empty($array_result) === false) { $return['chart'] = flot_slicesbar_graph( $array_result, @@ -14959,7 +14968,7 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) $colors, $config['fontpath'], $config['round_corner'], - $homeurl, + $config['homeurl'], '', '', false, @@ -14968,7 +14977,7 @@ function reporting_module_histogram_graph($report, $content, $pdf=0) true, $ttl, $content['sizeForTicks'], - true, + $showLabelTicks, $report['datetime'] ); } else { diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index cd6af07794..9e8416655a 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -5873,7 +5873,7 @@ function reporting_get_event_histogram($events, $text_header_event=false) true, 1, false, - false + true ); $table->data[0][0] = $slicebar; @@ -6058,7 +6058,7 @@ function reporting_get_event_histogram_meta($width) true, 1, false, - false + true ); $table->data[0][0] = $slicebar; diff --git a/pandora_console/include/functions_treeview.php b/pandora_console/include/functions_treeview.php index f0bdbbc613..f0f3d921ff 100755 --- a/pandora_console/include/functions_treeview.php +++ b/pandora_console/include/functions_treeview.php @@ -817,7 +817,7 @@ function treeview_printTable($id_agente, $server_data=[], $no_head=false) $events_graph .= graph_graphic_agentevents( $id_agente, '340px;margin:0', - '130px', + '60px', SECONDS_1DAY, '', true, diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index bdd3aa3038..7779616cbc 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -802,13 +802,13 @@ function pandoraFlotSlicebar( } }, grid: { - borderWidth: 1, - borderColor: "#C1C1C1", + borderWidth: 0, + borderColor: "transparent", tickColor: "#fff" }, xaxes: [ { - show: true, + show: show_date, tickFormatter: xFormatter, color: "", tickSize: intervaltick, diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 776e0a837f..a0e31db78f 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -413,6 +413,7 @@ class Widget break; case 'ColorModuleTabs': + case 'BlockHistogram': $className .= '\\'.$name; break; diff --git a/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php new file mode 100644 index 0000000000..e0f7446a6a --- /dev/null +++ b/pandora_console/include/lib/Dashboard/Widgets/BlockHistogram.php @@ -0,0 +1,632 @@ +width = $width; + + // Height. + $this->height = $height; + + // Grid Width. + $this->gridWidth = $gridWidth; + + // Cell Id. + $this->cellId = $cellId; + + // Options. + $this->values = $this->decoders($this->getOptionsWidget()); + + // Positions. + $this->position = $this->getPositionWidget(); + + // Page. + $this->page = basename(__FILE__); + + // ClassName. + $class = new \ReflectionClass($this); + $this->className = $class->getShortName(); + + // Title. + $this->title = __('Block histogram'); + + // Name. + if (empty($this->name) === true) { + $this->name = 'single_graph'; + } + + // This forces at least a first configuration. + $this->configurationRequired = false; + if (empty($this->values['moduleBlockHistogram']) === true) { + $this->configurationRequired = true; + } + + $this->overflow_scrollbars = false; + } + + + /** + * Decoders hack for retrocompability. + * + * @param array $decoder Values. + * + * @return array Returns the values ​​with the correct key. + */ + public function decoders(array $decoder): array + { + $values = []; + // Retrieve global - common inputs. + $values = parent::decoders($decoder); + + $values['agentsBlockHistogram'] = []; + if (isset($decoder['agentsBlockHistogram']) === true) { + if (isset($decoder['agentsBlockHistogram'][0]) === true + && empty($decoder['agentsBlockHistogram']) === false + ) { + $values['agentsBlockHistogram'] = explode( + ',', + $decoder['agentsBlockHistogram'][0] + ); + } + } + + if (isset($decoder['selectionBlockHistogram']) === true) { + $values['selectionBlockHistogram'] = $decoder['selectionBlockHistogram']; + } + + $values['moduleBlockHistogram'] = []; + if (isset($decoder['moduleBlockHistogram']) === true) { + if (empty($decoder['moduleBlockHistogram']) === false) { + $values['moduleBlockHistogram'] = $decoder['moduleBlockHistogram']; + } + } + + if (isset($decoder['period']) === true) { + $values['period'] = $decoder['period']; + } + + if (isset($decoder['fontColor']) === true) { + $values['fontColor'] = $decoder['fontColor']; + } + + if (isset($decoder['label']) === true) { + $values['label'] = $decoder['label']; + } + + return $values; + } + + + /** + * Generates inputs for form (specific). + * + * @return array Of inputs. + * + * @throws Exception On error. + */ + public function getFormInputs(): array + { + $values = $this->values; + + // Retrieve global - common inputs. + $inputs = parent::getFormInputs(); + + // Default values. + if (isset($values['period']) === false) { + $values['period'] = SECONDS_1DAY; + } + + if (empty($values['fontColor']) === true) { + $values['fontColor'] = '#2c3e50'; + } + + $inputs[] = [ + 'label' => __('Font color'), + 'arguments' => [ + 'wrapper' => 'div', + 'name' => 'fontColor', + 'type' => 'color', + 'value' => $values['fontColor'], + 'return' => true, + ], + ]; + + // Type clock. + $fields = [ + 'agent' => __('Agent'), + 'module' => __('Module'), + 'agent_module' => __('Agent / module'), + ]; + + $inputs[] = [ + 'label' => __('Label'), + 'arguments' => [ + 'type' => 'select', + 'fields' => $fields, + 'name' => 'label', + 'selected' => $values['label'], + 'return' => true, + ], + ]; + + // Periodicity. + $inputs[] = [ + 'label' => __('Interval'), + 'arguments' => [ + 'name' => 'period', + 'type' => 'interval', + 'value' => $values['period'], + 'nothing' => __('None'), + 'nothing_value' => 0, + 'style_icon' => 'flex-grow: 0', + + ], + ]; + + $inputs[] = [ + 'arguments' => [ + 'type' => 'select_multiple_modules_filtered_select2', + 'agent_values' => agents_get_agents_selected(0), + 'agent_name' => 'agentsBlockHistogram[]', + 'agent_ids' => $values['agentsBlockHistogram'], + 'selectionModules' => $values['selectionBlockHistogram'], + 'selectionModulesNameId' => 'selectionBlockHistogram', + 'modules_ids' => $values['moduleBlockHistogram'], + 'modules_name' => 'moduleBlockHistogram[]', + ], + ]; + + return $inputs; + } + + + /** + * Get Post for widget. + * + * @return array + */ + public function getPost():array + { + // Retrieve global - common inputs. + $values = parent::getPost(); + + $values['agentsBlockHistogram'] = \get_parameter( + 'agentsBlockHistogram', + [] + ); + $values['selectionBlockHistogram'] = \get_parameter( + 'selectionBlockHistogram', + 0 + ); + + $values['moduleBlockHistogram'] = \get_parameter( + 'moduleBlockHistogram' + ); + + $values['moduleBlockHistogram'] = get_same_modules_all( + explode(',', $values['agentsBlockHistogram'][0]), + explode(',', $values['moduleBlockHistogram'][0]) + ); + + $values['period'] = \get_parameter('period', 0); + + $values['fontColor'] = \get_parameter('fontColor', '#2c3e50'); + + $values['label'] = \get_parameter('label', 'agent'); + return $values; + } + + + /** + * Draw widget. + * + * @return string; + */ + public function load() + { + global $config; + + $size = parent::getSize(); + + $output = ''; + + if (is_metaconsole() === true) { + $modules_nodes = array_reduce( + $this->values['moduleBlockHistogram'], + function ($carry, $item) { + $explode = explode('|', $item); + $carry[$explode[0]][] = $explode[1]; + return $carry; + }, + [] + ); + + $modules = []; + foreach ($modules_nodes as $n => $mod) { + try { + $node = new Node((int) $n); + $node->connect(); + $node_mods = $this->getInfoModules($mod); + if (empty($node_mods) === false) { + foreach ($node_mods as $value) { + $value['id_node'] = $n; + $value['server_name'] = $node->toArray()['server_name']; + $modules[] = $value; + } + } + + $node->disconnect(); + } catch (\Exception $e) { + // Unexistent agent. + $node->disconnect(); + } + } + } else { + $modules = $this->getInfoModules( + $this->values['moduleBlockHistogram'] + ); + } + + if ($modules !== false && empty($modules) === false) { + $total_modules = count($modules); + $output .= '
    '; + $output .= ''; + foreach ($modules as $key => $module) { + $last = false; + if (($total_modules - 1) === $key) { + $last = true; + } + + if (is_metaconsole() === true) { + try { + $node = new Node((int) $module['id_node']); + $node->connect(); + $output .= $this->drawHistograms($module, $last); + + $node->disconnect(); + } catch (\Exception $e) { + // Unexistent agent. + $node->disconnect(); + } + } else { + $output .= $this->drawHistograms($module, $last); + } + } + + $output .= '
    '; + $output .= '
    '; + } else { + $output .= '
    '; + $output .= \ui_print_info_message( + __('Not found modules'), + '', + true + ); + $output .= '
    '; + } + + return $output; + } + + + /** + * Get info modules. + * + * @param array $modules Modules. + * + * @return array Data. + */ + private function getInfoModules(array $modules): array + { + $where = sprintf( + 'tagente_modulo.id_agente_modulo IN (%s)', + implode(',', $modules) + ); + + $sql = sprintf( + 'SELECT tagente_modulo.id_agente_modulo AS `id`, + tagente_modulo.nombre AS `name`, + tagente_modulo.unit AS `unit`, + tagente.alias AS `agent_alias`, + tagente.id_agente AS `agent_id` + FROM tagente_modulo + INNER JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + WHERE %s', + $where + ); + + $modules = db_get_all_rows_sql($sql); + + if ($modules === false) { + $modules = []; + } + + return $modules; + } + + + /** + * Draw histogram module. + * + * @param array $data Info module. + * @param boolean $last Last histogram. + * + * @return string + */ + private function drawHistograms(array $data, bool $last):string + { + global $config; + + $size = parent::getSize(); + + // Desactive scroll bars only this item. + $id_agent = $data['agent_id']; + $id_module = $data['id']; + $period = $this->values['period']; + switch ($this->values['label']) { + case 'module': + $label = ui_print_truncate_text( + $data['name'], + 25, + false, + true, + true, + '[…]', + '' + ); + break; + + case 'agent_module': + $label = ui_print_truncate_text( + $data['agent_alias'].' / '.$data['name'], + 25, + false, + true, + true, + ); + break; + + default: + case 'agent': + $label = ui_print_truncate_text( + $data['agent_alias'], + 25, + false, + true, + true, + '[…]', + '' + ); + break; + } + + $size_label = 10; + + $id_group = \agents_get_agent_group($id_agent); + + $height_graph = 30; + if ($last === true) { + if ($period > 86500) { + $height_graph = 60; + } else { + $height_graph = 50; + } + } + + $content = [ + 'id_agent_module' => $id_module, + 'period' => $period, + 'time_from' => '00:00:00', + 'time_to' => '00:00:00', + 'id_group' => $id_group, + 'sizeForTicks' => ($size['width'] - 200), + 'showLabelTicks' => ($last === true) ? true : false, + 'height_graph' => $height_graph, + [ + ['id_agent_module' => $id_module], + ] + ]; + + $graph = \reporting_module_histogram_graph( + ['datetime' => time()], + $content + ); + + $style = 'min-width:200px;'; + if ($last === false) { + if ($period > 86500) { + $style .= 'width:calc(100% - 24px); margin-left: 12px;'; + } else { + $style .= 'width:calc(100% - 16px); margin-left: 8px;'; + } + } else { + $style .= 'height:60px;'; + } + + $st = 'font-size:'.$size_label.'px;'; + if (is_metaconsole() === false) { + $st .= 'height: 28px;'; + } + + $output = ''; + $output .= ''; + $output .= '
    '; + $output .= $label; + $output .= '
    '; + $output .= ''; + $output .= ''; + $output .= '
    '; + $output .= $graph['chart']; + $output .= '
    '; + $output .= ''; + $output .= ''; + + return $output; + } + + + /** + * Get description. + * + * @return string. + */ + public static function getDescription() + { + return __('Block histogram'); + } + + + /** + * Get Name. + * + * @return string. + */ + public static function getName() + { + return 'BlockHistogram'; + } + + +} diff --git a/pandora_console/include/styles/dashboards.css b/pandora_console/include/styles/dashboards.css index dad32d5ac0..9b113dea21 100644 --- a/pandora_console/include/styles/dashboards.css +++ b/pandora_console/include/styles/dashboards.css @@ -635,7 +635,7 @@ form.modal-dashboard } .widget-module-tabs-data { - font-size: larger; + font-size: 1.5em; font-weight: bolder; } @@ -643,3 +643,23 @@ form.modal-dashboard font-size: smaller; font-style: italic; } + +.container-histograms { + min-width: 400px; + height: 100%; + display: flex; + flex-direction: column; + justify-content: center; +} +.table-container-histograms { + width: 100%; +} + +.container-histograms .widget-histogram-chart { + height: 28px; +} + +.container-histograms .widget-histogram-label { + padding-top: 10px; + text-align: initial; +} From 0a99b608c5d04477b36a94f32b7fdb6552708ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 25 May 2022 17:53:58 +0200 Subject: [PATCH 026/197] Fix several issues with SNMP Alert view --- .../godmode/snmpconsole/snmp_alert.php | 782 ++++++++++-------- pandora_console/include/styles/pandora.css | 7 + 2 files changed, 449 insertions(+), 340 deletions(-) diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 6829d445e1..35fcaf172c 100755 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -1,8 +1,20 @@ __('Other'), ]; -// Form submitted -// ============= +// Form submitted. $update_alert = (bool) get_parameter('update_alert', false); $create_alert = (bool) get_parameter('create_alert', false); $save_alert = (bool) get_parameter('save_alert', false); $modify_alert = (bool) get_parameter('modify_alert', false); $delete_alert = (bool) get_parameter('delete_alert', false); $multiple_delete = (bool) get_parameter('multiple_delete', false); -$add_action = (bool) get_parameter('add_alert', 0); +$add_action = (bool) get_parameter('add_alert', false); $delete_action = get_parameter('delete_action', 0); $duplicate_alert = get_parameter('duplicate_alert', 0); -if ($add_action) { +if ($add_action === true) { $values['id_alert_snmp'] = (int) get_parameter('id_alert_snmp'); $values['alert_type'] = (int) get_parameter('alert_type'); $values[db_escape_key_identifier('al_field1')] = get_parameter('field1_value'); @@ -79,37 +91,41 @@ if ($delete_action) { } if ($update_alert || $modify_alert) { - ui_print_page_header( - __('SNMP Console').' » '.__('Update alert'), - 'images/op_snmp.png', - false, - 'snmp_alert_update_tab', - false - ); + $subTitle = __('Update alert'); + $helpString = 'snmp_alert_update_tab'; } else if ($create_alert || $save_alert) { - ui_print_page_header( - __('SNMP Console').' » '.__('Create alert'), - 'images/op_snmp.png', - false, - 'snmp_alert_overview_tab', - false - ); + $subTitle = __('Create alert'); + $helpString = 'snmp_alert_overview_tab'; } else { - ui_print_page_header( - __('SNMP Console').' » '.__('Alert overview'), - 'images/op_snmp.png', - false, - '', - false - ); + $subTitle = __('Alert overview'); + $helpString = ''; } +ui_print_standard_header( + $subTitle, + 'images/op_snmp.png', + false, + $helpString, + false, + [], + [ + [ + 'link' => '', + 'label' => __('Alerts'), + ], + [ + 'link' => '', + 'label' => __('SNMP Console'), + ], + ] +); + if ($save_alert || $modify_alert) { $id_as = (int) get_parameter('id_alert_snmp', -1); $source_ip = (string) get_parameter_post('source_ip'); $alert_type = (int) get_parameter_post('alert_type'); - // Event, e-mail + // Event, e-mail. $description = (string) get_parameter_post('description'); $oid = (string) get_parameter_post('oid'); $custom_value = (string) get_parameter_post('custom_value'); @@ -269,7 +285,7 @@ if ($save_alert || $modify_alert) { $result = db_process_sql_insert('talert_snmp', $values); - if (!$result) { + if ((bool) $result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, 'Fail try to create snmp alert' @@ -278,7 +294,10 @@ if ($save_alert || $modify_alert) { } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Create snmp alert #$result" + sprintf( + 'Create snmp alert #%s', + $result + ) ); ui_print_success_message(__('Successfully created')); } @@ -405,24 +424,29 @@ if ($save_alert || $modify_alert) { $result = db_process_sql($sql); - if (!$result) { + if ((bool) $result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to update snmp alert #$id_as" + sprintf( + 'Fail try to update snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem updating the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Update snmp alert #$id_as" + sprintf( + 'Update snmp alert #%s', + $id_as + ) ); ui_print_success_message(__('Successfully updated')); } } } -// From variable init -// ================== +// From variable init. if ($update_alert || $duplicate_alert) { $id_as = (int) get_parameter('id_alert_snmp', -1); @@ -516,11 +540,11 @@ if ($update_alert || $duplicate_alert) { return; } } else if ($create_alert) { - // Variable init + // Variable init. $id_as = -1; $source_ip = ''; $alert_type = 1; - // Event, e-mail + // Event, e-mail. $description = ''; $oid = ''; $custom_value = ''; @@ -595,40 +619,46 @@ if ($update_alert || $duplicate_alert) { $group = 0; } -// Duplicate alert snmp +// Duplicate alert snmp. if ($duplicate_alert) { $values_duplicate = $alert; - if (!empty($values_duplicate)) { + if (empty($values_duplicate) === false) { unset($values_duplicate['id_as']); $result = db_process_sql_insert('talert_snmp', $values_duplicate); if (!$result) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to duplicate snmp alert #$id_as" + sprintf( + 'Fail try to duplicate snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem duplicating the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Duplicate snmp alert #$id_as" + sprintf( + 'Duplicate snmp alert #%s', + $id_as + ) ); ui_print_success_message(__('Successfully Duplicate')); } } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to duplicate snmp alert #$id_as" + sprintf( + 'Fail try to duplicate snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem duplicating the alert')); } } -// Header -// Alert Delete -// ============= if ($delete_alert) { - // Delete alert + // Delete alert. $alert_delete = (int) get_parameter_get('delete_alert', 0); $result = db_process_sql_delete( @@ -639,13 +669,19 @@ if ($delete_alert) { if ($result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to delete snmp alert #$alert_delete" + sprintf( + 'Fail try to delete snmp alert #%s', + $alert_delete + ) ); ui_print_error_message(__('There was a problem deleting the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Delete snmp alert #$alert_delete" + sprintf( + 'Delete snmp alert #%s', + $alert_delete + ) ); ui_print_success_message(__('Successfully deleted')); } @@ -666,18 +702,24 @@ if ($multiple_delete) { if ($result !== false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Delete snmp alert #$alert_delete" + sprintf( + 'Delete snmp alert #%s', + $alert_delete + ) ); $count++; } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to delete snmp alert #$alert_delete" + sprintf( + 'Fail try to delete snmp alert #%s', + $alert_delete + ) ); } } - if ($count == $total) { + if ($count === $total) { ui_print_success_message( __('Successfully deleted alerts (%s / %s)', $count, $total) ); @@ -692,7 +734,7 @@ $user_groups = users_get_groups($config['id_user'], 'AR', true); $str_user_groups = ''; $i = 0; foreach ($user_groups as $id => $name) { - if ($i == 0) { + if ($i === 0) { $str_user_groups .= $id; } else { $str_user_groups .= ','.$id; @@ -701,10 +743,9 @@ foreach ($user_groups as $id => $name) { $i++; } -// Alert form +// Alert form. if ($create_alert || $update_alert) { - // if (isset ($_GET["update_alert"])) { - // the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated + // The update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated. echo '
    '; html_print_input_hidden('id_alert_snmp', $id_as); @@ -717,32 +758,39 @@ if ($create_alert || $update_alert) { html_print_input_hidden('modify_alert', 1); } - // SNMP alert filters + // SNMP alert filters. echo ''; - // Description - echo ''.''.''.''; + // Description. + echo ''; + echo ''; + echo ''; + echo ''; - // echo ''; - // OID - echo ''.''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Custom + // Custom. echo ''; + echo ''; + echo ''; - // SNMP Agent + // SNMP Agent. echo ''; + echo ''; + echo ''; $return_all_group = false; @@ -750,7 +798,7 @@ if ($create_alert || $update_alert) { $return_all_group = true; } - // Group + // Group. echo ''; + echo ''; + echo ''; - // Trap type + // Trap type. echo ''; + echo ''; + echo ''; - // Single value + // Single value. echo ''; + echo ''; + echo ''; - // Variable bindings/Data #1 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #2 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #3 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #4 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #5 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #6 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #7 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #8 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #9 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #10 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #11 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #12 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #13 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #14 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #15 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #16 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #17 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #18 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #19 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #20 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Alert fields + // Alert fields. $al = [ 'al_field1' => $al_field1, 'al_field2' => $al_field2, @@ -974,7 +1061,7 @@ if ($create_alert || $update_alert) { 'al_field20' => $al_field20, ]; - // Hidden div with help hint to fill with javascript + // Hidden div with help hint to fill with javascript. html_print_div(['id' => 'help_snmp_alert_hint', 'content' => ui_print_help_icon('snmp_alert_field1', true), 'hidden' => true]); for ($i = 1; $i <= $config['max_macro_fields']; $i++) { @@ -984,7 +1071,7 @@ if ($create_alert || $update_alert) { echo ''; } - // Max / Min alerts + // Max / Min alerts. echo ''; - // Time Threshold + // Time Threshold. echo ''; - // Priority + // Priority. echo ''; @@ -1048,10 +1135,11 @@ if ($create_alert || $update_alert) { echo "
    '.__('Description').''; - html_print_textarea('description', 3, 2, $description, 'class="w400px"'); - echo '
    '.__('Description').''; + html_print_textarea('description', 3, 2, $description, 'class="w400px"'); + echo '
    ' . __('Alert filters') . ui_print_help_icon("snmp_alert_filters", true) . '
    '.__('Enterprise String').ui_print_help_tip(__('Matches substrings. End the string with $ for exact matches.'), true).''; + // OID. + echo '
    '.__('Enterprise String').ui_print_help_tip(__('Matches substrings. End the string with $ for exact matches.'), true).''; html_print_input_text('oid', $oid, '', 50, 255); - echo '
    '.__('Custom Value/OID'); echo ''; html_print_textarea('custom_value', 2, 2, $custom_value, 'class="w400px"'); - echo '
    '.__('SNMP Agent').' (IP)'; html_print_input_text('source_ip', $source_ip, '', 20); - echo '
    '.__('Group').''; echo '
    '; html_print_select_groups( @@ -774,183 +822,222 @@ if ($create_alert || $update_alert) { false ); echo '
    '; - echo '
    '.__('Trap type').''; echo html_print_select($trap_types, 'trap_type', $trap_type, '', '', '', false, false, false); - echo '
    '.__('Single value').''; html_print_input_text('single_value', $single_value, '', 20); - echo '
    '.__('Variable bindings/Data').''; + // Variable bindings/Data #1. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_1', $order_1, '', 4); html_print_input_text('custom_oid_data_1', $custom_oid_data_1, '', 60); - echo '
    '.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #2. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_2', $order_2, '', 4); html_print_input_text('custom_oid_data_2', $custom_oid_data_2, '', 60); - echo '
    '.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #3. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_3', $order_3, '', 4); html_print_input_text('custom_oid_data_3', $custom_oid_data_3, '', 60); - echo '
    '.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #4. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_4', $order_4, '', 4); html_print_input_text('custom_oid_data_4', $custom_oid_data_4, '', 60); - echo '
    '.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #5. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_5', $order_5, '', 4); html_print_input_text('custom_oid_data_5', $custom_oid_data_5, '', 60); - echo '
    '.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #6. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_6', $order_6, '', 4); html_print_input_text('custom_oid_data_6', $custom_oid_data_6, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #7. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_7', $order_7, '', 4); html_print_input_text('custom_oid_data_7', $custom_oid_data_7, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #8. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_8', $order_8, '', 4); html_print_input_text('custom_oid_data_8', $custom_oid_data_8, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #9. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_9', $order_9, '', 4); html_print_input_text('custom_oid_data_9', $custom_oid_data_9, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #10. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_10', $order_10, '', 4); html_print_input_text('custom_oid_data_10', $custom_oid_data_10, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #11. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_11', $order_11, '', 4); html_print_input_text('custom_oid_data_11', $custom_oid_data_11, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #12. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_12', $order_12, '', 4); html_print_input_text('custom_oid_data_12', $custom_oid_data_12, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #13. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_13', $order_13, '', 4); html_print_input_text('custom_oid_data_13', $custom_oid_data_13, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #14. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_14', $order_14, '', 4); html_print_input_text('custom_oid_data_14', $custom_oid_data_14, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #15. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_15', $order_15, '', 4); html_print_input_text('custom_oid_data_15', $custom_oid_data_15, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #16. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_16', $order_16, '', 4); html_print_input_text('custom_oid_data_16', $custom_oid_data_16, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #17. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_17', $order_17, '', 4); html_print_input_text('custom_oid_data_17', $custom_oid_data_17, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #18. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_18', $order_18, '', 4); html_print_input_text('custom_oid_data_18', $custom_oid_data_18, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #19. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_19', $order_19, '', 4); html_print_input_text('custom_oid_data_19', $custom_oid_data_19, '', 60); - echo '
    '.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #20. + echo '
    '.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_20', $order_20, '', 4); html_print_input_text('custom_oid_data_20', $custom_oid_data_20, '', 60); - echo '
    '.__('Min. number of alerts').''; html_print_input_text('min_alerts', $min_alerts, '', 3); @@ -992,7 +1079,7 @@ if ($create_alert || $update_alert) { html_print_input_text('max_alerts', $max_alerts, '', 3); echo '
    '.__('Time threshold').''; $fields = []; @@ -1014,7 +1101,7 @@ if ($create_alert || $update_alert) { html_print_input_text('time_other', 0, '', 6); echo ' '.__('seconds').'
    '.__('Priority').''; echo html_print_select(get_priorities(), 'priority', $priority, '', '', '0', false, false, false); echo '
    "; echo '
    '; + html_print_button(__('Back'), 'button_back', false, '', 'class="sub cancel margin-right-05"'); if ($id_as > 0) { - html_print_submit_button(__('Update'), 'submit', false, 'class="sub upd"', false); + html_print_submit_button(__('Update'), 'submit', false, 'class="sub upd"'); } else { - html_print_submit_button(__('Create'), 'submit', false, 'class="sub wand"', false); + html_print_submit_button(__('Create'), 'submit', false, 'class="sub wand"'); } echo '
    '; @@ -1089,119 +1177,68 @@ if ($create_alert || $update_alert) { $form_filter .= '
    '; $form_filter .= ''; - // echo "
    "; ui_toggle($form_filter, __('Alert SNMP control filter'), __('Toggle filter(s)')); $filter = []; $offset = (int) get_parameter('offset'); $limit = (int) $config['block_size']; if ($filter_param) { - // Move the first page + // Move the first page. $offset = 0; - $url_pagination = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'free_search='.$free_search.'&'.'trap_type_filter='.$trap_type_filter.'&'.'priority_filter='.$priority_filter; + $url_pagination = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&free_search='.$free_search.'&trap_type_filter='.$trap_type_filter.'&priority_filter='.$priority_filter; } else { - $url_pagination = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'free_search='.$free_search.'&'.'trap_type_filter='.$trap_type_filter.'&'.'priority_filter='.$priority_filter.'&'.'offset='.$offset; + $url_pagination = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&free_search='.$free_search.'&trap_type_filter='.$trap_type_filter.'&priority_filter='.$priority_filter.'&offset='.$offset; } $where_sql = ''; - if (!empty($free_search)) { - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - // $where_sql = ' 1 = 1'; - if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { - $where_sql .= ' AND `trap_type` = '.$trap_type_filter; - } - - if ($priority_filter != -1) { - $where_sql .= ' AND `priority` = '.$priority_filter; - } - - $where_sql .= " AND (`single_value` LIKE '%".$free_search."%' - OR `_snmp_f10_` LIKE '%".$free_search."%' - OR `_snmp_f9_` LIKE '%".$free_search."%' - OR `_snmp_f8_` LIKE '%".$free_search."%' - OR `_snmp_f7_` LIKE '%".$free_search."%' - OR `_snmp_f6_` LIKE '%".$free_search."%' - OR `_snmp_f5_` LIKE '%".$free_search."%' - OR `_snmp_f4_` LIKE '%".$free_search."%' - OR `_snmp_f3_` LIKE '%".$free_search."%' - OR `_snmp_f2_` LIKE '%".$free_search."%' - OR `_snmp_f1_` LIKE '%".$free_search."%' - OR `oid` LIKE '%".$free_search."%' - OR `custom_oid` LIKE '%".$free_search."%' - OR `agent` LIKE '%".$free_search."%' - OR `description` LIKE '%".$free_search."%')"; - break; - - case 'oracle': - // $where_sql = ' 1 = 1'; - if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { - $where_sql .= ' AND trap_type = '.$trap_type_filter; - } - - if ($priority_filter != -1) { - $where_sql .= ' AND priority = '.$priority_filter; - } - - $where_sql .= " AND (single_value LIKE '%".$free_search."%' - OR \"_snmp_f10_\" LIKE '%".$free_search."%' - OR \"_snmp_f9_\" LIKE '%".$free_search."%' - OR \"_snmp_f8_\" LIKE '%".$free_search."%' - OR \"_snmp_f7_\" LIKE '%".$free_search."%' - OR \"_snmp_f6_\" LIKE '%".$free_search."%' - OR \"_snmp_f5_\" LIKE '%".$free_search."%' - OR \"_snmp_f4_\" LIKE '%".$free_search."%' - OR \"_snmp_f3_\" LIKE '%".$free_search."%' - OR \"_snmp_f2_\" LIKE '%".$free_search."%' - OR \"_snmp_f1_\" LIKE '%".$free_search."%' - OR oid LIKE '%".$free_search."%' - OR custom_oid LIKE '%".$free_search."%' - OR agent LIKE '%".$free_search."%' - OR description LIKE '%".$free_search."%')"; - break; + if (empty($free_search) === false) { + if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { + $where_sql .= ' AND `trap_type` = '.$trap_type_filter; } + + if ($priority_filter != -1) { + $where_sql .= ' AND `priority` = '.$priority_filter; + } + + $where_sql .= " AND (`single_value` LIKE '%".$free_search."%' + OR `_snmp_f10_` LIKE '%".$free_search."%' + OR `_snmp_f9_` LIKE '%".$free_search."%' + OR `_snmp_f8_` LIKE '%".$free_search."%' + OR `_snmp_f7_` LIKE '%".$free_search."%' + OR `_snmp_f6_` LIKE '%".$free_search."%' + OR `_snmp_f5_` LIKE '%".$free_search."%' + OR `_snmp_f4_` LIKE '%".$free_search."%' + OR `_snmp_f3_` LIKE '%".$free_search."%' + OR `_snmp_f2_` LIKE '%".$free_search."%' + OR `_snmp_f1_` LIKE '%".$free_search."%' + OR `oid` LIKE '%".$free_search."%' + OR `custom_oid` LIKE '%".$free_search."%' + OR `agent` LIKE '%".$free_search."%' + OR `description` LIKE '%".$free_search."%')"; } - $count = db_get_value_sql( - "SELECT COUNT(*) - FROM talert_snmp WHERE id_group IN ($str_user_groups) ".$where_sql + $count = (int) db_get_value_sql( + 'SELECT COUNT(*) + FROM talert_snmp WHERE id_group IN ('.$str_user_groups.') '.$where_sql ); $result = []; - // Overview - if ($count == 0) { + // Overview. + if ($count === 0) { $result = []; ui_print_info_message(['no_close' => true, 'message' => __('There are no SNMP alerts') ]); } else { ui_pagination($count, $url_pagination); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $where_sql .= ' LIMIT '.$limit.' OFFSET '.$offset; - $result = db_get_all_rows_sql( - "SELECT * - FROM talert_snmp - WHERE id_group IN ($str_user_groups) ".$where_sql - ); - break; - case 'oracle': - $sql = "SELECT * - FROM talert_snmp - WHERE id_group IN ($str_user_groups) ".$where_sql; - $set = []; - if (isset($offset) && isset($limit)) { - $set['limit'] = $limit; - $set['offset'] = $offset; - } - - $result = oracle_recode_query($sql, $set, 'AND', false); - break; - } + $where_sql .= ' LIMIT '.$limit.' OFFSET '.$offset; + $result = db_get_all_rows_sql( + 'SELECT * + FROM talert_snmp + WHERE id_group IN ('.$str_user_groups.') '.$where_sql + ); } $table = new stdClass(); @@ -1250,7 +1287,7 @@ if ($create_alert || $update_alert) { $data = []; $data[0] = $row['position']; - $url = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'id_alert_snmp='.$row['id_as'].'&'.'update_alert=1'; + $url = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&id_alert_snmp='.$row['id_as'].'&update_alert=1'; $data[1] = ''; $data[1] .= ''; @@ -1281,50 +1318,86 @@ if ($create_alert || $update_alert) { } $data[1] .= '
    '; - - $data[2] = $row['agent']; $data[3] = $row['oid']; $data[4] = $row['custom_oid']; $data[5] = $row['description']; $data[6] = $row['times_fired']; - if (($row['last_fired'] != '1970-01-01 00:00:00') and ($row['last_fired'] != '01-01-1970 00:00:00')) { + if (($row['last_fired'] !== '1970-01-01 00:00:00') && ($row['last_fired'] !== '01-01-1970 00:00:00')) { $data[7] = ui_print_timestamp($row['last_fired'], true); } else { $data[7] = __('Never'); } - if (check_acl_restricted_all($config['id_user'], $row['id_group'], 'LW')) { - $data[8] = ''.html_print_image( - 'images/copy.png', - true, - [ - 'alt' => __('Duplicate'), - 'title' => __('Duplicate'), - ] - ).''.''.html_print_image( - 'images/config.png', - true, - [ - 'border' => '0', - 'alt' => __('Update'), - ] - ).''.''.html_print_image( - 'images/add.png', - true, - [ - 'title' => __('Add action'), - ] - ).''.''.html_print_image( - 'images/cross.png', - true, - [ - 'border' => '0', - 'alt' => __('Delete'), - ] - ).''; + $data[8] = ''; + $data[9] = ''; + if ((bool) check_acl_restricted_all($config['id_user'], $row['id_group'], 'LW') === true) { + $data[8] = html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&duplicate_alert=1&id_alert_snmp=%s', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/copy.png', + true, + [ + 'alt' => __('Duplicate'), + 'title' => __('Duplicate'), + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&update_alert=1&id_alert_snmp=%s', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/config.png', + true, + [ + 'alt' => __('Update'), + 'border' => 0, + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => sprintf( + 'javascript:show_add_action_snmp(\'%s\');"', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/add.png', + true, + [ + 'title' => __('Add action'), + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => 'javascript: ', + 'content' => html_print_image( + 'images/cross.png', + true, + [ + 'title' => __('Delete action'), + ] + ), + 'onClick' => 'delete_snmp_alert('.$row['id_as'].')', + ], + true + ); $data[9] = html_print_checkbox_extended( 'delete_ids[]', @@ -1335,71 +1408,47 @@ if ($create_alert || $update_alert) { 'class="chk_delete"', true ); - } else { - $data[8] = ''; - $data[9] = ''; } $idx = count($table->data); - // The current index of the table is 1 less than the count of table data so we count before adding to table->data + // The current index of the table is 1 less than the count of table data so we count before adding to table->data. array_push($table->data, $data); $table->rowclass[$idx] = get_priority_class($row['priority']); } - // DIALOG ADD MORE ACTIONS + // DIALOG ADD MORE ACTIONS. echo '