From 57eec94c42745492389490482520d0c093b725f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Fri, 28 Jul 2023 09:32:30 -0600 Subject: [PATCH 001/397] Add OS, server and interval. --- pandora_server/util/pandora_manage.pl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_server/util/pandora_manage.pl b/pandora_server/util/pandora_manage.pl index 71fd0db43e..2b0f20f244 100755 --- a/pandora_server/util/pandora_manage.pl +++ b/pandora_server/util/pandora_manage.pl @@ -4508,7 +4508,9 @@ sub cli_create_event() { # exist_check($id_agent,'agent',$agent_name); if($id_agent == -1){ if($force_create_agent == 1){ - pandora_create_agent ($conf, '', $agent_name, '', $id_group, '', '', 'Created by cli_create_event', '', $dbh); + my $target_os = pandora_get_os($dbh, 'other'); + my $target_server = $conf{'servername'}; + pandora_create_agent ($conf, $target_server, $agent_name, '', $id_group, '', $target_os, 'Created by cli_create_event', '300', $dbh); print_log "[INFO] Adding agent '$agent_name' \n\n"; $id_agent = get_agent_id($dbh,$agent_name); } From 9c9467c2da9961f32606cabe098839eb437caa94 Mon Sep 17 00:00:00 2001 From: alejandro Date: Mon, 14 Aug 2023 13:57:14 +0200 Subject: [PATCH 002/397] fix in plugin output --- pandora_server/util/plugin/wizard_wmi_module.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_server/util/plugin/wizard_wmi_module.pl b/pandora_server/util/plugin/wizard_wmi_module.pl index 23e49a7f83..d9c1b3d1aa 100755 --- a/pandora_server/util/plugin/wizard_wmi_module.pl +++ b/pandora_server/util/plugin/wizard_wmi_module.pl @@ -172,5 +172,6 @@ foreach my $k (keys %{$fields_values}){ # Get operation result my $result = eval $operation; if (defined($result)){ - print $result . "\n"; + + print $result, "\n"; } From 682494f51fa15479cdefacbf6347838e3423fa19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20S=C3=A1nchez?= Date: Mon, 14 Aug 2023 11:59:41 +0000 Subject: [PATCH 003/397] remove clear line --- pandora_server/util/plugin/wizard_wmi_module.pl | 1 - 1 file changed, 1 deletion(-) diff --git a/pandora_server/util/plugin/wizard_wmi_module.pl b/pandora_server/util/plugin/wizard_wmi_module.pl index d9c1b3d1aa..fa25c26d0b 100755 --- a/pandora_server/util/plugin/wizard_wmi_module.pl +++ b/pandora_server/util/plugin/wizard_wmi_module.pl @@ -172,6 +172,5 @@ foreach my $k (keys %{$fields_values}){ # Get operation result my $result = eval $operation; if (defined($result)){ - print $result, "\n"; } From 94315147cfeb8d88daeeb53c1c062f9babd7b052 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Fri, 1 Sep 2023 10:12:03 +0200 Subject: [PATCH 004/397] #11750 module_data name file add module id --- pandora_console/include/functions_api.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 7e22befbee..95e3e47919 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -10299,8 +10299,7 @@ function api_set_module_data($id, $thrash2, $other, $trash1) modules_get_type_name($agentModule['id_tipo_modulo']), $data ); - - if (false === @file_put_contents($config['remote_config'].'/'.io_safe_output($agent['nombre']).'.'.$time.'.data', $xml)) { + if (false === @file_put_contents($config['remote_config'].'/'.io_safe_output($agent['nombre']).'.'.$idAgentModule.'.'.$time.'.data', $xml)) { returnError(sprintf('XML file could not be generated in path: %s', $config['remote_config'])); } else { echo __('XML file was generated successfully in path: ').$config['remote_config']; From 3af1981b9360cd09e2ce0c23b021c295d794facd Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Mon, 4 Sep 2023 13:21:57 +0200 Subject: [PATCH 005/397] #11510 Fix agent filter on inventory view --- pandora_console/operation/inventory/inventory.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index 536f470fe6..5f57b5f397 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -615,8 +615,8 @@ $params['show_helptip'] = true; $params['input_name'] = 'agent'; $params['value'] = $inventory_agent; $params['selectbox_id'] = 'module_inventory_general_view'; -$params['javascript_is_function_select'] = true; -$params['javascript_function_action_after_select'] = 'this.form.submit'; +// $params['javascript_is_function_select'] = true; +// $params['javascript_function_action_after_select'] = 'this.form.submit'; $params['use_hidden_input_idagent'] = true; $params['print_hidden_input_idagent'] = true; $params['hidden_input_idagent_id'] = 'hidden-autocomplete_id_agent'; From b8e8a16e7dfe1dd422a66c04476d5c7489ecae4e Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 5 Sep 2023 10:11:15 +0200 Subject: [PATCH 006/397] #11537 Fix search with space entitites --- .../include/class/ConfigPEN.class.php | 3 ++- .../include/functions_custom_graphs.php | 4 ++-- .../include/functions_inventory.php | 6 ++--- .../operation/inventory/inventory.php | 5 ++++ .../operation/search_agents.getdata.php | 22 ++++++++--------- .../operation/search_alerts.getdata.php | 20 ++++++++-------- .../operation/search_graphs.getdata.php | 2 +- pandora_console/operation/search_main.php | 20 ++++++++-------- .../operation/search_maps.getdata.php | 2 +- .../operation/search_modules.getdata.php | 12 +++++----- .../operation/search_policies.getdata.php | 2 +- .../operation/search_reports.getdata.php | 8 +++---- .../operation/search_users.getdata.php | 24 +++++++++---------- 13 files changed, 68 insertions(+), 62 deletions(-) diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index cea6123f08..4e4975e64d 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -118,7 +118,7 @@ class ConfigPEN extends HTML if (is_array($filter)) { if (!empty($filter['free_search'])) { $sql_filters[] = vsprintf( - ' AND (lower(`manufacturer`) like lower("%%%s%%") + ' AND (lower(REPLACE(manufacturer, " ", " ")) like lower("%%%s%%") OR pen = "%s") ', array_fill(0, 2, $filter['free_search']) ); @@ -184,6 +184,7 @@ class ConfigPEN extends HTML return db_get_value_sql($sql); } + hd($sql, true); return db_get_all_rows_sql($sql); } diff --git a/pandora_console/include/functions_custom_graphs.php b/pandora_console/include/functions_custom_graphs.php index 500b668a24..f76dc7c0f7 100644 --- a/pandora_console/include/functions_custom_graphs.php +++ b/pandora_console/include/functions_custom_graphs.php @@ -194,11 +194,11 @@ function custom_graphs_get_user($id_user=0, $only_names=false, $returnAllGroup=t function custom_graphs_search($id_group, $search) { if ($id_group != '' && $search != '') { - $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (name LIKE "%'.$search.'%" OR description LIKE "'.$search.'")'); + $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.' AND (REPLACE(name, " ", " ") LIKE "%'.$search.'%" OR REPLACE(description, " ", " ") LIKE "'.$search.'")'); } else if ($id_group != '') { $all_graphs = db_get_all_rows_sql('select * from tgraph where id_group = '.$id_group.''); } else { - $all_graphs = db_get_all_rows_sql('select * from tgraph where name LIKE "%'.$search.'%" OR description LIKE "'.$search.'"'); + $all_graphs = db_get_all_rows_sql('select * from tgraph where REPLACE(name, " ", " ") LIKE "%'.$search.'%" OR REPLACE(description, " ", " ") LIKE "'.$search.'"'); } if ($all_graphs === false) { diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 8e69da7445..aac94a9b52 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -77,7 +77,7 @@ function inventory_get_data( } if ($inventory_search_string != '') { - array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'"); + array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } $offset = (int) get_parameter('offset'); @@ -746,7 +746,7 @@ function inventory_get_datatable( } if ($inventory_search_string != '') { - array_push($where, "tagent_module_inventory.data LIKE '%".$inventory_search_string."%'"); + array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } if ($utimestamp > 0) { @@ -889,7 +889,7 @@ function get_data_basic_info_sql($params, $count=false) if ($params['search'] > 0) { $where .= sprintf( - ' AND ( alias LIKE "%%%s%%" )', + ' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )', $params['search'] ); } diff --git a/pandora_console/operation/inventory/inventory.php b/pandora_console/operation/inventory/inventory.php index c753bd599b..e9d2e312d9 100755 --- a/pandora_console/operation/inventory/inventory.php +++ b/pandora_console/operation/inventory/inventory.php @@ -1280,6 +1280,10 @@ if ($inventory_module !== 'basic') { $style = 'width: 100%'; $ordering = true; $searching = false; + $search = []; + if (strlen($inventory_search_string) > 0) { + $search['value'] = $inventory_search_string; + } $columns = [ 'alias', @@ -1329,6 +1333,7 @@ if ($inventory_module !== 'basic') { 'get_data_basic_info' => 1, 'id_agent' => $id_agente, 'id_group' => $inventory_id_group, + 'search' => $search, ], 'zeroRecords' => __('Agent info not found'), 'emptyTable' => __('Agent info not found'), diff --git a/pandora_console/operation/search_agents.getdata.php b/pandora_console/operation/search_agents.getdata.php index ea63506fa4..9809f0f3d9 100644 --- a/pandora_console/operation/search_agents.getdata.php +++ b/pandora_console/operation/search_agents.getdata.php @@ -74,15 +74,15 @@ if ($searchAgents) { $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress INNER JOIN taddress_agent ON taddress.id_a = taddress_agent.id_a - WHERE taddress.ip LIKE '$stringSearchSQL'"; + WHERE LOWER(REPLACE(taddress.ip, ' ', ' ')) LIKE LOWER('$stringSearchSQL')"; $id = db_get_all_rows_sql($sql); if ($id != '') { $aux = $id[0]['id_agent']; - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR + $search_sql = " LOWER(REPLACE(t1.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t2.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.alias, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.comentarios, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR t1.id_agente =".$aux; $idCount = count($id); @@ -94,16 +94,16 @@ if ($searchAgents) { } } } else { - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.direccion LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."'"; + $search_sql = " LOWER(REPLACE(t1.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t2.nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.direccion, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.comentarios, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."') OR + LOWER(REPLACE(t1.alias, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."')"; } if ($has_secondary === true) { $search_sql .= " OR (tasg.id_group IS NOT NULL AND - tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '".$stringSearchSQL."'))"; + tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE LOWER(REPLACE(nombre, ' ', ' ')) LIKE LOWER('".$stringSearchSQL."')))"; } $sql = " diff --git a/pandora_console/operation/search_alerts.getdata.php b/pandora_console/operation/search_alerts.getdata.php index cebb13919c..eea9f70324 100644 --- a/pandora_console/operation/search_alerts.getdata.php +++ b/pandora_console/operation/search_alerts.getdata.php @@ -139,64 +139,64 @@ if ($searchAlerts) { switch ($config['dbtype']) { case 'mysql': $whereAlerts = 'AND ( - id_alert_template IN (SELECT id FROM talert_templates WHERE name LIKE "%'.$stringSearchSQL.'%") OR + id_alert_template IN (SELECT id FROM talert_templates WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%") OR id_alert_template IN ( SELECT id FROM talert_templates WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE name LIKE "%'.$stringSearchSQL.'%")) OR + WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%")) OR talert_template_modules.id IN ( SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE name LIKE "%'.$stringSearchSQL.'%")) OR + WHERE REPLACE(name, " ", " ") LIKE "%'.$stringSearchSQL.'%")) OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo - WHERE nombre LIKE "%'.$stringSearchSQL.'%") OR + WHERE REPLACE(nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%") OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ( SELECT id_agente FROM tagente - WHERE nombre LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.')) + WHERE REPLACE(nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%" '.$extra_sql.')) )'; break; case 'postgresql': case 'oracle': $whereAlerts = 'AND ( - id_alert_template IN (SELECT id FROM talert_templates WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR + id_alert_template IN (SELECT id FROM talert_templates WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR id_alert_template IN ( SELECT id FROM talert_templates WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR + WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR talert_template_modules.id IN ( SELECT id_alert_template_module FROM talert_template_module_actions WHERE id_alert_action IN ( SELECT id FROM talert_actions - WHERE upper(name) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR + WHERE upper(REPLACE(name, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')) OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo - WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR + WHERE upper(REPLACE(nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\') OR id_agent_module IN ( SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente IN ( SELECT id_agente FROM tagente - WHERE upper(nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.')) + WHERE upper(REPLACE(nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\' '.$extra_sql.')) )'; $agents = false; break; diff --git a/pandora_console/operation/search_graphs.getdata.php b/pandora_console/operation/search_graphs.getdata.php index f4b5fdf171..7037274b08 100644 --- a/pandora_console/operation/search_graphs.getdata.php +++ b/pandora_console/operation/search_graphs.getdata.php @@ -31,7 +31,7 @@ if ($searchGraphs) { } $filter = []; - $filter[] = "(upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(description) LIKE '%$".strtolower($stringSearchSQL)."%')"; + $filter[] = "(upper(REPLACE(name, ' ', ' ')) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(REPLACE(description, ' ', ' ')) LIKE '%$".strtolower($stringSearchSQL)."%')"; $filter['id_graph'] = $usergraphs_id; $columns = [ diff --git a/pandora_console/operation/search_main.php b/pandora_console/operation/search_main.php index e5f136f457..ac841fa703 100644 --- a/pandora_console/operation/search_main.php +++ b/pandora_console/operation/search_main.php @@ -62,10 +62,10 @@ $sql = "SELECT DISTINCT taddress_agent.id_agent FROM taddress $id = db_get_all_rows_sql($sql); if ($id != '') { $aux = $id[0]['id_agent']; - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR + $search_sql = " REPLACE(t1.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t2.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.alias, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.comentarios, ' ', ' ') LIKE '".$stringSearchSQL."' OR t1.id_agente =".$aux; $idCount = count($id); @@ -77,16 +77,16 @@ if ($id != '') { } } } else { - $search_sql = " t1.nombre LIKE '".$stringSearchSQL."' OR - t2.nombre LIKE '".$stringSearchSQL."' OR - t1.direccion LIKE '".$stringSearchSQL."' OR - t1.comentarios LIKE '".$stringSearchSQL."' OR - t1.alias LIKE '".$stringSearchSQL."'"; + $search_sql = " REPLACE(t1.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t2.nombre, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.direccion, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.comentarios, ' ', ' ') LIKE '".$stringSearchSQL."' OR + REPLACE(t1.alias, ' ', ' ') LIKE '".$stringSearchSQL."'"; } if ($has_secondary === true) { $search_sql .= " OR (tasg.id_group IS NOT NULL AND - tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE nombre LIKE '".$stringSearchSQL."'))"; + tasg.id_group IN (SELECT id_grupo FROM tgrupo WHERE REPLACE(nombre, ' ', ' ') LIKE '".$stringSearchSQL."'))"; } $sql = " diff --git a/pandora_console/operation/search_maps.getdata.php b/pandora_console/operation/search_maps.getdata.php index 6f3456ef5b..60cd83f556 100644 --- a/pandora_console/operation/search_maps.getdata.php +++ b/pandora_console/operation/search_maps.getdata.php @@ -32,7 +32,7 @@ if ((bool) $searchMaps === true) { FROM tlayout tl LEFT JOIN tlayout_data tld ON tl.id = tld.id_layout - WHERE tl.name LIKE "%%%s%%" + WHERE REPLACE(tl.name, " ", " ") LIKE "%%%s%%" AND tl.id_group IN (%s) GROUP BY tl.id, tl.name, tl.id_group', $stringSearchSQL, diff --git a/pandora_console/operation/search_modules.getdata.php b/pandora_console/operation/search_modules.getdata.php index e83c6035ef..f4f3f896df 100644 --- a/pandora_console/operation/search_modules.getdata.php +++ b/pandora_console/operation/search_modules.getdata.php @@ -134,8 +134,8 @@ if ($searchModules) { ) ) AND - (t1.nombre LIKE "%'.$stringSearchSQL.'%" OR - t3.nombre LIKE "%'.$stringSearchSQL.'%") + (REPLACE(t1.nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%" OR + REPLACE(t3.nombre, " ", " ") LIKE "%'.$stringSearchSQL.'%") AND t1.disabled = 0'; break; @@ -164,8 +164,8 @@ if ($searchModules) { ) ) ) AND - (t1.nombre LIKE \'%'.$stringSearchSQL.'%\' OR - t3.nombre LIKE \'%'.$stringSearchSQL.'%\')'; + (REPLACE(t1.nombre, " ", " ") LIKE \'%'.$stringSearchSQL.'%\' OR + REPLACE(t3.nombre, " ", " ") LIKE \'%'.$stringSearchSQL.'%\')'; break; case 'oracle': @@ -193,8 +193,8 @@ if ($searchModules) { ) ) ) AND - (LOWER(t1.nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\' OR - LOWER(t3.nombre) LIKE \'%'.strtolower($stringSearchSQL).'%\')'; + (LOWER(REPLACE(t1.nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\' OR + LOWER(REPLACE(t3.nombre, " ", " ")) LIKE \'%'.strtolower($stringSearchSQL).'%\')'; break; } diff --git a/pandora_console/operation/search_policies.getdata.php b/pandora_console/operation/search_policies.getdata.php index cc6f0dca45..cc4c844ea0 100644 --- a/pandora_console/operation/search_policies.getdata.php +++ b/pandora_console/operation/search_policies.getdata.php @@ -207,7 +207,7 @@ if ($searchpolicies === true) { $sql = "SELECT id, name, description, id_group, status FROM tpolicies - WHERE name LIKE '$stringSearchSQL' + WHERE REPLACE(name, ' ', ' ') LIKE '$stringSearchSQL' AND id_group IN ($id_user_groups_str) "; } diff --git a/pandora_console/operation/search_reports.getdata.php b/pandora_console/operation/search_reports.getdata.php index 082d9914cc..3cf83bacbc 100644 --- a/pandora_console/operation/search_reports.getdata.php +++ b/pandora_console/operation/search_reports.getdata.php @@ -46,13 +46,13 @@ if ($searchReports) { case 'postgresql': $sql = "SELECT id_report, name, description FROM treport - WHERE (name LIKE '%".$stringSearchSQL."%' OR description LIKE '%".$stringSearchSQL."%')".$reports_condition; + WHERE (REPLACE(name, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR REPLACE(description, ' ', ' ') LIKE '%".$stringSearchSQL."%')".$reports_condition; break; case 'oracle': $sql = "SELECT id_report, name, description FROM treport - WHERE (upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR description LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; + WHERE (upper(REPLACE(name, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR REPLACE(description, ' ', ' ') LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; break; } @@ -77,13 +77,13 @@ if ($searchReports) { case 'postgresql': $sql_count = "SELECT COUNT(id_report) AS count FROM treport - WHERE (name LIKE '%".$stringSearchSQL."%' OR description LIKE '%".$stringSearchSQL."%')".$reports_condition; + WHERE (REPLACE(name, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR REPLACE(description, ' ', ' ') LIKE '%".$stringSearchSQL."%')".$reports_condition; break; case 'oracle': $sql_count = "SELECT COUNT(id_report) AS count FROM treport - WHERE (upper(name) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(description) LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; + WHERE (upper(REPLACE(name, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR upper(REPLACE(description, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%')".$reports_condition; break; } diff --git a/pandora_console/operation/search_users.getdata.php b/pandora_console/operation/search_users.getdata.php index 212eb8a493..1e8932c4bc 100644 --- a/pandora_console/operation/search_users.getdata.php +++ b/pandora_console/operation/search_users.getdata.php @@ -179,23 +179,23 @@ if ($searchUsers) { case 'mysql': case 'postgresql': $sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario - WHERE fullname LIKE '%".$stringSearchSQL."%' OR - id_user LIKE '%".$stringSearchSQL."%' OR - firstname LIKE '%".$stringSearchSQL."%' OR - lastname LIKE '%".$stringSearchSQL."%' OR - middlename LIKE '%".$stringSearchSQL."%' OR - email LIKE '%".$stringSearchSQL."%' + WHERE REPLACE(fullname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(id_user, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(firstname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(lastname, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(middlename, ' ', ' ') LIKE '%".$stringSearchSQL."%' OR + REPLACE(email, ' ', ' ') LIKE '%".$stringSearchSQL."%' ORDER BY ".$order['field'].' '.$order['order']; break; case 'oracle': $sql = "SELECT id_user, fullname, firstname, lastname, middlename, email, last_connect, is_admin, comments FROM tusuario - WHERE upper(fullname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(id_user) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(firstname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(lastname) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(middlename) LIKE '%".strtolower($stringSearchSQL)."%' OR - upper(email) LIKE '%".strtolower($stringSearchSQL)."%' + WHERE upper(REPLACE(fullname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(id_user, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(firstname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(lastname, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(middlename, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' OR + upper(REPLACE(email, ' ', ' ') ) LIKE '%".strtolower($stringSearchSQL)."%' ORDER BY ".$order['field'].' '.$order['order']; break; } From 25175ce22e8bf4486d735e988b5d11ae876d4a10 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 5 Sep 2023 13:05:12 +0200 Subject: [PATCH 007/397] #11537 Fix inventory --- pandora_console/include/functions_inventory.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index aac94a9b52..0becb94fec 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -77,6 +77,8 @@ function inventory_get_data( } if ($inventory_search_string != '') { + hd(1, true); + hd($inventory_search_string, true); array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } @@ -746,7 +748,9 @@ function inventory_get_datatable( } if ($inventory_search_string != '') { - array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); + hd(2, true); + hd($inventory_search_string, true); + array_push($where, "REPLACE(tagente_datos_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } if ($utimestamp > 0) { @@ -786,7 +790,6 @@ function inventory_get_datatable( } $rows = db_get_all_rows_sql($sql); - if ($order_by_agent === false) { $modules = []; foreach ($rows as $row) { @@ -796,7 +799,7 @@ function inventory_get_datatable( $data_rows = explode(PHP_EOL, $row['data_inventory']); foreach ($data_rows as $data_key => $data_value) { - if (empty($data_value) === false) { + if (empty($data_value) === false && strpos(str_replace(' ', ' ', $data_value), $inventory_search_string)) { $row['data'] = $data_value; $modules[$row['name']][$row['name_agent'].'-'.$data_key.'-'.$data_value] = $row; } @@ -892,6 +895,8 @@ function get_data_basic_info_sql($params, $count=false) ' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )', $params['search'] ); + hd(3, true); + hd($params['search'], true); } if ($params['utimestamp'] > 0 && $count === false) { From 3bb4567dc3051d5734538c9417ed92f57951a4f9 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 5 Sep 2023 13:44:54 +0200 Subject: [PATCH 008/397] #11537 Fix searchs --- .../godmode/agentes/modificar_agente.php | 16 ++++++++-------- .../godmode/agentes/module_manager.php | 2 +- .../modules/manage_network_components.php | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pandora_console/godmode/agentes/modificar_agente.php b/pandora_console/godmode/agentes/modificar_agente.php index a14bff4b92..17596b28ab 100644 --- a/pandora_console/godmode/agentes/modificar_agente.php +++ b/pandora_console/godmode/agentes/modificar_agente.php @@ -566,10 +566,10 @@ if ($search != '') { if ($id != '') { $aux = $id[0]['id_agent']; $search_sql = sprintf( - ' AND ( nombre LIKE "%%%s%%" - OR alias LIKE "%%%s%%" - OR comentarios LIKE "%%%s%%" - OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND description LIKE "%%%s%%") + ' AND ( REPLACE(nombre, " ", " ") LIKE "%%%s%%" + OR REPLACE(alias, " ", " ") LIKE "%%%s%%" + OR REPLACE(comentarios, " ", " ") LIKE "%%%s%%" + OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND REPLACE(description, " ", " ") LIKE "%%%s%%") OR tagente.id_agente = %d', $search, $search, @@ -591,10 +591,10 @@ if ($search != '') { $search_sql .= ')'; } else { $search_sql = sprintf( - ' AND ( nombre - LIKE "%%%s%%" OR alias - LIKE "%%%s%%" OR comentarios LIKE "%%%s%%" - OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND description LIKE "%%%s%%"))', + ' AND ( REPLACE(nombre, " ", " ") + LIKE "%%%s%%" OR REPLACE(alias, " ", " ") + LIKE "%%%s%%" OR REPLACE(comentarios, " ", " ") LIKE "%%%s%%" + OR EXISTS (SELECT * FROM tagent_custom_data WHERE id_agent = id_agente AND REPLACE(description, " ", " ") LIKE "%%%s%%"))', $search, $search, $search, diff --git a/pandora_console/godmode/agentes/module_manager.php b/pandora_console/godmode/agentes/module_manager.php index 5c21fa71a0..60739b792a 100644 --- a/pandora_console/godmode/agentes/module_manager.php +++ b/pandora_console/godmode/agentes/module_manager.php @@ -574,7 +574,7 @@ $where = sprintf('delete_pending = 0 AND id_agente = %s', $id_agente); $search_string_entities = io_safe_input($search_string); $basic_where = sprintf( - "(nombre LIKE '%%%s%%' OR nombre LIKE '%%%s%%' OR descripcion LIKE '%%%s%%' OR descripcion LIKE '%%%s%%') AND", + "(REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(nombre, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%' OR REPLACE(descripcion, ' ', ' ') LIKE '%%%s%%') AND", $search_string, $search_string_entities, $search_string, diff --git a/pandora_console/godmode/modules/manage_network_components.php b/pandora_console/godmode/modules/manage_network_components.php index 53318517d7..d1d5f5687f 100644 --- a/pandora_console/godmode/modules/manage_network_components.php +++ b/pandora_console/godmode/modules/manage_network_components.php @@ -729,7 +729,7 @@ if ($search_id_group) { } if ($search_string != '') { - $filter[] = '(name LIKE '."'%".$search_string."%'".'OR description LIKE '."'%".$search_string."%'".'OR tcp_send LIKE '."'%".$search_string."%'".'OR tcp_rcv LIKE '."'%".$search_string."%'".')'; + $filter[] = '(REPLACE(name, " ", " ") LIKE '."'%".$search_string."%'".' OR REPLACE(REPLACE(description, " ", " "), " ", " ")LIKE '."'%".$search_string."%'".' OR REPLACE(tcp_send, " ", " ") LIKE '."'%".$search_string."%'".'OR REPLACE(tcp_rcv, " ", " ") LIKE '."'%".$search_string."%'".')'; } $total_components = network_components_get_network_components( From f8f13227f87096a15c7fc431c64bf278079704e5 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 6 Sep 2023 10:28:44 +0200 Subject: [PATCH 009/397] #11537 Fix metaconsole inventory and hd traces --- pandora_console/include/class/ConfigPEN.class.php | 1 - pandora_console/include/functions_inventory.php | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/class/ConfigPEN.class.php b/pandora_console/include/class/ConfigPEN.class.php index 4e4975e64d..6e2f7ec1f6 100644 --- a/pandora_console/include/class/ConfigPEN.class.php +++ b/pandora_console/include/class/ConfigPEN.class.php @@ -184,7 +184,6 @@ class ConfigPEN extends HTML return db_get_value_sql($sql); } - hd($sql, true); return db_get_all_rows_sql($sql); } diff --git a/pandora_console/include/functions_inventory.php b/pandora_console/include/functions_inventory.php index 0becb94fec..afa61c3811 100644 --- a/pandora_console/include/functions_inventory.php +++ b/pandora_console/include/functions_inventory.php @@ -77,8 +77,6 @@ function inventory_get_data( } if ($inventory_search_string != '') { - hd(1, true); - hd($inventory_search_string, true); array_push($where, "REPLACE(tagent_module_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } @@ -748,8 +746,6 @@ function inventory_get_datatable( } if ($inventory_search_string != '') { - hd(2, true); - hd($inventory_search_string, true); array_push($where, "REPLACE(tagente_datos_inventory.data, ' ', ' ') LIKE '%".$inventory_search_string."%'"); } @@ -799,7 +795,13 @@ function inventory_get_datatable( $data_rows = explode(PHP_EOL, $row['data_inventory']); foreach ($data_rows as $data_key => $data_value) { - if (empty($data_value) === false && strpos(str_replace(' ', ' ', $data_value), $inventory_search_string)) { + if (empty($inventory_search_string) !== true) { + $search_check = strpos(str_replace(' ', ' ', $data_value), $inventory_search_string); + } else { + $search_check = true; + } + + if (empty($data_value) === false && $search_check !== false) { $row['data'] = $data_value; $modules[$row['name']][$row['name_agent'].'-'.$data_key.'-'.$data_value] = $row; } @@ -895,8 +897,6 @@ function get_data_basic_info_sql($params, $count=false) ' AND ( REPLACE(alias, " ", " ") LIKE "%%%s%%" )', $params['search'] ); - hd(3, true); - hd($params['search'], true); } if ($params['utimestamp'] > 0 && $count === false) { From 142624fdd5c0c54f6e865936f55373755ee0fd76 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 8 Sep 2023 11:17:57 +0200 Subject: [PATCH 010/397] Added display of the default Netflow starting from the last hour --- .../operation/network/network_usage_map.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pandora_console/operation/network/network_usage_map.php b/pandora_console/operation/network/network_usage_map.php index 709213507a..048aca141d 100644 --- a/pandora_console/operation/network/network_usage_map.php +++ b/pandora_console/operation/network/network_usage_map.php @@ -87,6 +87,7 @@ $action = get_parameter('action', 'talkers'); // Calculate range dates. $custom_date = get_parameter('custom_date', '0'); $date = get_parameter('date', SECONDS_1DAY); +$default_date_netflow = false; if ($custom_date === '1') { $date_init = get_parameter('date_init'); $time_init = get_parameter('time_init'); @@ -99,11 +100,11 @@ if ($custom_date === '1') { $date_units = get_parameter('date_units'); $period = ($date_text * $date_units); $date_to = strtotime(date('Y-m-d H:i:s')); - $date_from = (strtotime($date_to) - $period); + $date_from = ($date_to - $period); } else if (in_array($date, ['this_week', 'this_month', 'past_week', 'past_month'])) { if ($date === 'this_week') { $date_from = strtotime('last monday'); - $date_to = strtotime($date_from.' +6 days'); + $date_to = strtotime(date('Y/m/d h:i:s', $date_from).' +6 days'); } else if ($date === 'this_month') { $date_from = strtotime('first day of this month'); $date_to = strtotime('last day of this month'); @@ -116,7 +117,10 @@ if ($custom_date === '1') { } } else { $date_to = strtotime(date('Y-m-d H:i:s')); - $date_from = ($date_to - $date); + // Set last hour by default. + $date_from = strtotime(date('Y-m-d H:i:s').'- 1 hour'); + $top = 10; + $default_date_netflow = true; } $advanced_filter = get_parameter('advanced_filter', ''); @@ -313,7 +317,7 @@ ui_toggle( $has_data = false; -if ((bool) get_parameter('update_netflow') === true) { +if ((bool) get_parameter('update_netflow') === true || $default_date_netflow === true) { $map_data = netflow_build_map_data( $date_from, $date_to, From d4cdd4be516b16498bfde3aaf687b659f2146454 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Tue, 12 Sep 2023 11:31:05 +0200 Subject: [PATCH 011/397] The menu_print_menu function is adjusted to take the menu text as the title instead of the id. --- pandora_console/include/functions_menu.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index a1927bb60a..a4762cf1aa 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -324,7 +324,7 @@ function menu_print_menu(&$menu) if (isset($sub['type']) && $sub['type'] == 'direct') { // This is an external link. - $submenu_output .= '
  • '; + $submenu_output .= '
  • '; if (isset($sub['subtype']) && $sub['subtype'] == 'nolink') { $submenu_output .= ''; From 1247b5f69591441ac2bdfa378e2c4014caf1bbe5 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Tue, 12 Sep 2023 16:04:13 +0200 Subject: [PATCH 012/397] #11495 Create function for service level data --- pandora_console/include/functions_modules.php | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index e82fca400b..fd8461156c 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -4762,3 +4762,98 @@ function export_agents_module_csv($filters) return $result; } + + +/** + * Function to return Mean Time Between Failure, Mean Time To Solution (in seconds) + * and Availability of a module + * + * @param string $interval_start Start time of the interval. + * + * @param string $interval_end End time of the interval. + * + * @param string $id_agentmodule id_agentmodule of the module + * + * @return array Returns an array with the data + */ +function service_level_module_data($interval_start, $interval_end, $id_agentmodule) +{ + $data = []; + $data['mtbf'] = false; + $data['mtrs'] = false; + $data['availability'] = false; + + $interval_time = ($interval_end - $interval_start); + $current_time = time(); + $sql = 'SELECT utimestamp, event_type FROM tevento + WHERE id_agentmodule = '.$id_agentmodule.' + AND utimestamp >= '.$interval_start.' + AND utimestamp <= '.$interval_end.' + ORDER BY utimestamp DESC'; + + $events_time = db_get_all_rows_sql($sql); + if ($events_time !== false && count($events_time) > 0) { + $failed_event = []; + $normal_event = []; + foreach ($events_time as $event) { + if ($event['event_type'] === 'going_up_critical') { + $failed_event[] = $event['utimestamp']; + } + + if ($event['event_type'] === 'going_down_normal') { + $normal_event[] = $event['utimestamp']; + } + } + + $mtrs_array = []; + if (empty($normal_event) === true) { + $mtrs_array[] = ($current_time - $failed_event[0]); + } else if (empty($failed_event) === true) { + $mtrs_array[] = 0; + } else { + foreach ($normal_event as $key => $value) { + if (($failed_event[$key] - $normal_event[$key]) < 0) { + $mtrs_array[] = ($normal_event[$key] - $failed_event[$key]); + } else { + $mtrs_array[] = ($failed_event[$key] - $normal_event[$key]); + } + } + } + + $mtbf_array = []; + if (!empty($failed_event) === true) { + if (count($failed_event) > 1) { + for ($i = 1; $i <= array_key_last($failed_event); $i++) { + $mtbf_array[] = ($failed_event[($i - 1)] - $failed_event[$i]); + } + } else { + $mtbf_array[] = ($current_time - $failed_event[0]); + } + } else { + $mtbf_array[] = 0; + } + + $total_time_failed = array_sum($mtbf_array); + $total_time_ok = ($interval_time - $total_time_failed); + if (count($events_time) === 1) { + if ($events_time[0]['event_type'] === 'going_up_critical') { + $availability = '0'; + } + + if ($events_time[0]['event_type'] === 'going_down_normal') { + $availability = '100'; + } + } else { + $availability = round((($total_time_ok / $interval_time) * 100), 2); + } + + $mtbf = round(( $total_time_failed / count($mtbf_array))); + $mtrs = round((array_sum($mtrs_array) / count($mtrs_array))); + + $data['mtbf'] = $mtbf; + $data['mtrs'] = $mtrs; + $data['availability'] = $availability; + } + + return $data; +} From 6966ebf96b4c4300d4cd17ee91d8e6510e37e0ca Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 13 Sep 2023 10:09:05 +0200 Subject: [PATCH 013/397] #11495 Fix service_level_module_data function --- pandora_console/include/functions_modules.php | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index fd8461156c..410cc036f7 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -4768,27 +4768,45 @@ function export_agents_module_csv($filters) * Function to return Mean Time Between Failure, Mean Time To Solution (in seconds) * and Availability of a module * - * @param string $interval_start Start time of the interval. + * @param string $datetime_from Start time of the interval. * - * @param string $interval_end End time of the interval. + * @param string $datetime_to End time of the interval. * * @param string $id_agentmodule id_agentmodule of the module * * @return array Returns an array with the data */ -function service_level_module_data($interval_start, $interval_end, $id_agentmodule) +function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule) { $data = []; $data['mtbf'] = false; $data['mtrs'] = false; $data['availability'] = false; - $interval_time = ($interval_end - $interval_start); + $availability = 0; + + $uncompressed_data = db_uncompress_module_data( + $id_agentmodule, + $datetime_from, + $datetime_to + ); + + $first_utimestamp = 0; + foreach ($uncompressed_data as $data_module) { + foreach ($data_module['data'] as $subdata) { + if (!empty($subdata['datos'])) { + $first_utimestamp = $subdata['utimestamp']; + break; + } + } + } + + $interval_time = ($datetime_to - $datetime_from); $current_time = time(); $sql = 'SELECT utimestamp, event_type FROM tevento WHERE id_agentmodule = '.$id_agentmodule.' - AND utimestamp >= '.$interval_start.' - AND utimestamp <= '.$interval_end.' + AND utimestamp >= '.$datetime_from.' + AND utimestamp <= '.$datetime_to.' ORDER BY utimestamp DESC'; $events_time = db_get_all_rows_sql($sql); @@ -4836,17 +4854,14 @@ function service_level_module_data($interval_start, $interval_end, $id_agentmodu $total_time_failed = array_sum($mtbf_array); $total_time_ok = ($interval_time - $total_time_failed); if (count($events_time) === 1) { - if ($events_time[0]['event_type'] === 'going_up_critical') { - $availability = '0'; - } - - if ($events_time[0]['event_type'] === 'going_down_normal') { - $availability = '100'; + if ((string) $first_utimestamp !== '0') { + $availability = round((($total_time_ok / $interval_time) * 100), 2); } } else { $availability = round((($total_time_ok / $interval_time) * 100), 2); } + // hd($availability, true); $mtbf = round(( $total_time_failed / count($mtbf_array))); $mtrs = round((array_sum($mtrs_array) / count($mtrs_array))); From 8dcace04e7290630474f4daaece400ac19b49f6c Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 13 Sep 2023 10:10:39 +0200 Subject: [PATCH 014/397] #11495 Add service level detailed report --- .../reporting_builder.item_editor.php | 50 +++++++++++++++++++ pandora_console/include/functions_reports.php | 4 ++ 2 files changed, 54 insertions(+) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 6343fabe1d..53be2c1f07 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -591,6 +591,16 @@ switch ($action) { ); break; + case 'service_level': + $description = $item['description']; + $idAgentModule = $item['id_agent_module']; + $idAgent = db_get_value_filter( + 'id_agente', + 'tagente_modulo', + ['id_agente_modulo' => $idAgentModule] + ); + break; + case 'alert_report_module': $description = $item['description']; $idAgentModule = $item['id_agent_module']; @@ -870,6 +880,25 @@ switch ($action) { $idAgentModule = $module; break; + case 'service_level': + $description = $item['description']; + // Decode agents and modules. + $id_agents = json_decode( + io_safe_output(base64_decode($es['id_agents'])), + true + ); + $module = json_decode( + io_safe_output(base64_decode($es['module'])), + true + ); + + $recursion = $item['recursion']; + + $group = $item['id_group']; + $modulegroup = $item['id_module_group']; + $idAgentModule = $module; + break; + case 'alert_report_actions': $description = $item['description']; $es = json_decode($item['external_source'], true); @@ -1035,6 +1064,7 @@ switch ($action) { case 'sumatory': case 'database_serialized': case 'last_value': + case 'service_level': case 'monitor_report': case 'min_value': case 'max_value': @@ -5367,8 +5397,13 @@ $(document).ready (function () { switch (type){ case 'agent_module': case 'agent_module_status': + case 'service_level': case 'alert_report_actions': var agents_multiple = $('#id_agents2').val(); + if (agents_multiple.length == 0) { + dialog_message('#message_no_agent'); + return false; + } var modules_multiple = $('#module').val(); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); $('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple)); @@ -5394,6 +5429,7 @@ $(document).ready (function () { case 'agent_configuration': case 'module_histogram_graph': case 'increment': + case 'service_level': if ($("#hidden-id_agent").val() == 0) { dialog_message('#message_no_agent'); return false; @@ -5508,8 +5544,13 @@ $(document).ready (function () { switch (type){ case 'agent_module': case 'agent_module_status': + case 'service_level': case 'alert_report_actions': var agents_multiple = $('#id_agents2').val(); + if (agents_multiple.length == 0) { + dialog_message('#message_no_agent'); + return false; + } var modules_multiple = $('#module').val(); $('#hidden-id_agents2-multiple-text').val(JSON.stringify(agents_multiple)); $('#hidden-module-multiple-text').val(JSON.stringify(modules_multiple)); @@ -5535,6 +5576,7 @@ $(document).ready (function () { case 'agent_configuration': case 'module_histogram_graph': case 'increment': + case 'service_level': if ($("#hidden-id_agent").val() == 0) { dialog_message('#message_no_agent'); return false; @@ -6946,6 +6988,14 @@ function chooseType() { $("#row_agent").show(); $("#row_module").show(); break; + + case 'service_level': + $("#row_description").show(); + $("#row_group").show(); + $("#select_agent_modules").show(); + $("#agents_modules_row").show(); + $("#modules_row").show(); + break; case 'alert_report_module': $("#row_description").show(); diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index f13e935b6a..a450675cd6 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -777,6 +777,10 @@ function reports_get_report_types($template=false, $not_editor=false) 'optgroup' => __('Modules'), 'name' => __('Last value'), ]; + $types['service_level'] = [ + 'optgroup' => __('Modules'), + 'name' => __('Service Level Detailed'), + ]; $types['general'] = [ 'optgroup' => __('Grouped'), From 35b5de57f15e359b9ee3c837be319e4f622a1731 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Wed, 13 Sep 2023 11:12:11 +0200 Subject: [PATCH 015/397] The filter group is added in the Service View Widget settings. --- pandora_console/include/ajax/tree.ajax.php | 3 ++- pandora_console/include/class/Tree.class.php | 6 ++++- .../include/class/TreeService.class.php | 17 +++++++++--- .../include/javascript/pandora_dashboards.js | 2 +- .../include/lib/Dashboard/Widget.php | 1 + .../lib/Dashboard/Widgets/service_view.php | 26 +++++++++++++++++++ 6 files changed, 49 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 319b98e168..e9dbbecd52 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -187,7 +187,8 @@ if (is_ajax() === true) { $serverID, $childrenMethod, $access, - $metaID + $metaID, + $filter['groupID'] ); break; diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index b4a41c494d..41868748f5 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -32,6 +32,8 @@ class Tree protected $rootType = null; + protected $idGroup = null; + protected $id = -1; protected $rootID = -1; @@ -87,13 +89,15 @@ class Tree $serverID=false, $childrenMethod='on_demand', $access='AR', - $id_meta_server=0 + $id_meta_server=0, + $id_group=0 ) { $this->type = $type; $this->rootType = !empty($rootType) ? $rootType : $type; $this->id = $id; $this->rootID = !empty($rootID) ? $rootID : $id; $this->serverID = $serverID; + $this->idGroup = $id_group; if (is_metaconsole() && $id_meta_server == 0) { $this->serverName = metaconsole_get_server_by_id($serverID); } diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index b30877a5b5..a2f9257d14 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -88,7 +88,8 @@ class TreeService extends Tree $serverID=false, $childrenMethod='on_demand', $access='AR', - $id_server_meta=0 + $id_server_meta=0, + $id_group=0 ) { global $config; @@ -105,7 +106,8 @@ class TreeService extends Tree $serverID, $childrenMethod, $access, - $id_server_meta + $id_server_meta, + $id_group ); $this->L1fieldName = 'id_group'; @@ -268,6 +270,13 @@ class TreeService extends Tree $groups_acl = 'AND ts.id_group IN ('.implode(',', $this->userGroupsArray).')'; } + // Filter group. + if ((int) $this->idGroup !== 0) { + $filter_group = 'AND ts.id_group = '.$this->idGroup; + } else { + $filter_group = ''; + } + $exclude_children = 'ts.id NOT IN ( SELECT DISTINCT id_service_child FROM tservice_element @@ -300,11 +309,13 @@ class TreeService extends Tree %s %s %s + %s GROUP BY ts.id', $exclude_children, $is_favourite, $service_search, - $groups_acl + $groups_acl, + $filter_group ); $stats = db_get_all_rows_sql($sql); diff --git a/pandora_console/include/javascript/pandora_dashboards.js b/pandora_console/include/javascript/pandora_dashboards.js index 79fde538b4..a669b22719 100644 --- a/pandora_console/include/javascript/pandora_dashboards.js +++ b/pandora_console/include/javascript/pandora_dashboards.js @@ -1058,7 +1058,7 @@ function processServiceTree(settings) { parameters["filter"]["statusAgent"] = ""; parameters["filter"]["searchModule"] = ""; parameters["filter"]["statusModule"] = ""; - parameters["filter"]["groupID"] = ""; + parameters["filter"]["groupID"] = settings.id_group; parameters["filter"]["tagID"] = ""; parameters["filter"]["searchHirearchy"] = 1; parameters["filter"]["show_not_init_agents"] = 1; diff --git a/pandora_console/include/lib/Dashboard/Widget.php b/pandora_console/include/lib/Dashboard/Widget.php index 9bedc71f50..876e8aacc6 100644 --- a/pandora_console/include/lib/Dashboard/Widget.php +++ b/pandora_console/include/lib/Dashboard/Widget.php @@ -642,6 +642,7 @@ class Widget $values = []; $values['title'] = \get_parameter('title', ''); $values['background'] = \get_parameter('background', '#ffffff'); + $values['id_group'] = \get_parameter('id_group', ''); if ((bool) \is_metaconsole() === true) { if ($this->shouldSelectNode() === true) { $values['node'] = \get_parameter('node', null); diff --git a/pandora_console/include/lib/Dashboard/Widgets/service_view.php b/pandora_console/include/lib/Dashboard/Widgets/service_view.php index 7e5607af47..b81fbd67ae 100644 --- a/pandora_console/include/lib/Dashboard/Widgets/service_view.php +++ b/pandora_console/include/lib/Dashboard/Widgets/service_view.php @@ -218,6 +218,10 @@ class ServiceViewWidget extends Widget $values['type'] = $decoder['type']; } + if (isset($decoder['id_group']) === true) { + $values['id_group'] = $decoder['id_group']; + } + return $values; } @@ -239,6 +243,13 @@ class ServiceViewWidget extends Widget $values['type'] = 'tree'; } + // Groups. + $return_all_group = false; + + if (users_can_manage_group_all('AR') === true) { + $return_all_group = true; + } + // Type services view. $fields = [ 'tree' => __('Tree'), @@ -256,6 +267,20 @@ class ServiceViewWidget extends Widget ], ]; + $inputs[] = [ + 'label' => __('Group'), + 'arguments' => [ + 'name' => 'id_group', + 'id' => 'id_group', + 'input_class' => 'flex-row', + 'type' => 'select_groups', + 'returnAllGroup' => $return_all_group, + 'selected' => $values['id_group'], + 'return' => true, + 'class' => 'w50p', + ], + ]; + return $inputs; } @@ -335,6 +360,7 @@ class ServiceViewWidget extends Widget $settings['cellId'] = $this->cellId; $settings['baseURL'] = \ui_get_full_url('/', false, false, false); $settings['ajaxURL'] = \ui_get_full_url('ajax.php', false, false, false); + $settings['id_group'] = (empty($values['type']) === false) ? $values['id_group'] : 0; // Show the modal window of an module. $output .= '
    '; From 355de3b9bd4d451bd2fccfa78315f8d205ac9725 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 13 Sep 2023 11:41:41 +0200 Subject: [PATCH 016/397] #11495 Fix service level detail function --- pandora_console/include/functions_modules.php | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 410cc036f7..07690151e4 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -4784,6 +4784,7 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule $data['availability'] = false; $availability = 0; + $type = ''; $uncompressed_data = db_uncompress_module_data( $id_agentmodule, @@ -4796,6 +4797,10 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule foreach ($data_module['data'] as $subdata) { if (!empty($subdata['datos'])) { $first_utimestamp = $subdata['utimestamp']; + if (isset($subdata['type'])) { + $type = $subdata['type']; + } + break; } } @@ -4862,8 +4867,19 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule } // hd($availability, true); - $mtbf = round(( $total_time_failed / count($mtbf_array))); - $mtrs = round((array_sum($mtrs_array) / count($mtrs_array))); + if (count($mtbf_array) > 1) { + $mtbf = round(( $total_time_failed / count($mtbf_array))); + } else { + $mtbf = false; + } + + if (count($mtrs_array) === 1 && (string) $first_utimestamp !== '0' && $type === 0) { + $mtrs = round($total_time_failed / count($mtrs_array)); + } else if (count($mtrs_array) > 1 && (string) $first_utimestamp !== '0') { + $mtrs = round((array_sum($mtrs_array) / count($mtrs_array))); + } else { + $mtrs = false; + } $data['mtbf'] = $mtbf; $data['mtrs'] = $mtrs; From 5dcc2704cbd7810ab07584f938adeb8c9b151bd7 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 14 Sep 2023 13:49:56 +0200 Subject: [PATCH 017/397] #11495 Fix service level detailed report --- .../reporting_builder.item_editor.php | 88 +++++++++++++++---- .../godmode/reporting/reporting_builder.php | 32 ++++++- pandora_console/include/functions.php | 26 ++++-- pandora_console/include/functions_modules.php | 78 +++++++++++++++- .../include/functions_reporting.php | 61 +++++++++++++ .../include/functions_reporting_html.php | 81 ++++++++++++++++- 6 files changed, 337 insertions(+), 29 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index 53be2c1f07..724c5f6772 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -117,6 +117,8 @@ $exception_condition = REPORT_EXCEPTION_CONDITION_EVERYTHING; $exception_condition_value = 10; $modulegroup = 0; $period = SECONDS_1DAY; +$period_time_service_level = '28800'; +$show_agents = false; $search = ''; $full_text = 0; $log_number = 1000; @@ -591,16 +593,6 @@ switch ($action) { ); break; - case 'service_level': - $description = $item['description']; - $idAgentModule = $item['id_agent_module']; - $idAgent = db_get_value_filter( - 'id_agente', - 'tagente_modulo', - ['id_agente_modulo' => $idAgentModule] - ); - break; - case 'alert_report_module': $description = $item['description']; $idAgentModule = $item['id_agent_module']; @@ -882,6 +874,9 @@ switch ($action) { case 'service_level': $description = $item['description']; + $es = json_decode($item['external_source'], true); + $period_time_service_level = $es['period_time_service_level']; + $show_agents = $es['show_agents']; // Decode agents and modules. $id_agents = json_decode( io_safe_output(base64_decode($es['id_agents'])), @@ -1493,6 +1488,53 @@ if (is_metaconsole() === true) { + + + + + + __('1 week'), + '172800' => __('48 hours'), + '86400' => __('24 hours'), + '43200' => __('12 hours'), + '28800' => __('8 hours'), + + ]; + html_print_select( + $fields_time_service_level, + 'period_time_service_level', + $period_time_service_level, + ); + ?> + + + + + + + + + + + + 0) { - $ret .= "$days days "; + if ($size_text === 'short') { + $ret .= str_replace(' ', '', "$days d").' '; + } else { + $ret .= "$days days "; + } } // get the hours $hours = ((intval($seconds) / 360000) % 24); if ($hours > 0) { - $ret .= "$hours hours "; + if ($size_text === 'short') { + $ret .= str_replace(' ', '', "$hours h").' '; + } else { + $ret .= "$hours hours "; + } } // get the minutes $minutes = ((intval($seconds) / 6000) % 60); if ($minutes > 0) { - $ret .= "$minutes minutes "; + if ($size_text === 'short') { + $ret .= str_replace(' ', '', "$minutes m").' '; + } else { + $ret .= "$minutes minutes "; + } } // get the seconds $seconds = ((intval($seconds) / 100) % 60); if ($seconds > 0) { - $ret .= "$seconds seconds"; + if ($size_text === 'short') { + $ret .= str_replace(' ', '', "$seconds s").' '; + } else { + $ret .= "$seconds seconds "; + } } return $ret; diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 07690151e4..a953d66ac1 100755 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -4782,10 +4782,29 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule $data['mtbf'] = false; $data['mtrs'] = false; $data['availability'] = false; + $data['critical_events'] = false; + $data['warning_events'] = false; + $data['last_status_change'] = false; + $data['module_name'] = false; $availability = 0; $type = ''; + if ((bool) is_metaconsole() === true) { + if (enterprise_include_once('include/functions_metaconsole.php') !== ENTERPRISE_NOT_HOOK) { + $server_id = []; + $server_id['id'] = explode('|', $id_agentmodule)[0]; + $id_agentmodule = explode('|', $id_agentmodule)[1]; + $server_name = db_get_row_filter('tmetaconsole_setup', $server_id, 'server_name'); + $connection = metaconsole_get_connection($server_name); + if (metaconsole_load_external_db($connection) !== NOERR) { + // Restore db connection. + metaconsole_restore_db(); + return $data; + } + } + } + $uncompressed_data = db_uncompress_module_data( $id_agentmodule, $datetime_from, @@ -4815,6 +4834,24 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule ORDER BY utimestamp DESC'; $events_time = db_get_all_rows_sql($sql); + + // Count events. + $sql = 'SELECT COUNT(*) as critical_events FROM tevento + WHERE id_agentmodule= '.$id_agentmodule.' + AND utimestamp >= '.$datetime_from.' + AND utimestamp <= '.$datetime_to.' + AND (event_type = "going_up_critical" OR event_type = "going_down_critical")'; + + $critical_events = db_get_sql($sql); + + $sql = 'SELECT COUNT(*) as warning_events FROM tevento + WHERE id_agentmodule= '.$id_agentmodule.' + AND utimestamp >= '.$datetime_from.' + AND utimestamp <= '.$datetime_to.' + AND (event_type = "going_up_warning" OR event_type = "going_down_warning")'; + + $warning_events = db_get_sql($sql); + if ($events_time !== false && count($events_time) > 0) { $failed_event = []; $normal_event = []; @@ -4844,6 +4881,7 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule } $mtbf_array = []; + if (!empty($failed_event) === true) { if (count($failed_event) > 1) { for ($i = 1; $i <= array_key_last($failed_event); $i++) { @@ -4866,9 +4904,8 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule $availability = round((($total_time_ok / $interval_time) * 100), 2); } - // hd($availability, true); - if (count($mtbf_array) > 1) { - $mtbf = round(( $total_time_failed / count($mtbf_array))); + if ($critical_events > 1) { + $mtbf = round(( $total_time_failed / $critical_events)); } else { $mtbf = false; } @@ -4884,6 +4921,41 @@ function service_level_module_data($datetime_from, $datetime_to, $id_agentmodule $data['mtbf'] = $mtbf; $data['mtrs'] = $mtrs; $data['availability'] = $availability; + } else { + $data['mtbf'] = false; + $data['mtrs'] = false; + $data['availability'] = false; + } + + // Get last status change. + $sql = 'SELECT last_status_change FROM tagente_estado + WHERE id_agente_modulo = '.$id_agentmodule.' '; + + $last_status_change = db_get_sql($sql); + + // Get module name. + /* + $sql = 'SELECT nombre FROM tagente_modulo + WHERE id_agente_modulo = '.$id_agentmodule;*/ + + $sql = 'SELECT tagente_modulo.nombre as nombre, tagente.alias as alias + FROM tagente_modulo INNER JOIN tagente + ON tagente_modulo.id_agente = tagente.id_agente + WHERE id_agente_modulo = '.$id_agentmodule.' '; + $sql_query = db_get_all_rows_sql($sql); + + $data['critical_events'] = $critical_events; + $data['warning_events'] = $warning_events; + $data['last_status_change'] = $last_status_change; + $data['module_name'] = $sql_query[0]['nombre']; + if ((bool) is_metaconsole() === true) { + $data['agent_alias'] = $server_name['server_name'].' » '.$sql_query[0]['alias']; + } else { + $data['agent_alias'] = $sql_query[0]['alias']; + } + + if ((bool) is_metaconsole() === true) { + metaconsole_restore_db(); } return $data; diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index ee1f04b952..94585ee455 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -778,6 +778,13 @@ function reporting_make_reporting_data( ); break; + case 'service_level': + $report['contents'][] = reporting_service_level_detail( + $report, + $content + ); + break; + case 'alert_report_actions': $report['contents'][] = reporting_alert_report_actions( $report, @@ -3567,6 +3574,60 @@ function reporting_agent_module_status($report, $content) } +/** + * Service level detail + * + * @param array $report Info Report. + * @param array $content Info content. + * + * @return array + */ +function reporting_service_level_detail($report, $content) +{ + global $config; + $return['type'] = 'service_level'; + + $module_data = []; + $interval_range = []; + $service_level_data = []; + $current_timestamp = time(); + + $return['title'] = io_safe_output($content['name']); + $return['landscape'] = $content['landscape']; + $return['pagebreak'] = $content['pagebreak']; + + $return['description'] = io_safe_output($content['description']); + $return['label'] = (isset($content['style']['label'])) ? $content['style']['label'] : ''; + $es = json_decode($content['external_source'], true); + $return['date'] = []; + $return['date']['date'] = false; + $return['date']['period'] = $es['period_time_service_level']; + $return['show_agents'] = $es['show_agents']; + + $modules = json_decode(base64_decode($es['module']), true); + $agents = json_decode(base64_decode($es['id_agents']), true); + $interval_range['start'] = ($current_timestamp - $es['period_time_service_level']); + $interval_range['end'] = $current_timestamp; + + foreach ($modules as $module) { + $service_level_data = service_level_module_data($interval_range['start'], $interval_range['end'], $module); + $module_data[$module] = []; + $module_data[$module]['mtrs'] = ($service_level_data['mtrs'] !== false) ? human_milliseconds_to_string(($service_level_data['mtrs'] * 100), 'short') : '-'; + $module_data[$module]['mtbf'] = ($service_level_data['mtbf'] !== false) ? human_milliseconds_to_string(($service_level_data['mtbf'] * 100), 'short') : '-'; + $module_data[$module]['availability'] = ($service_level_data['availability'] !== false) ? $service_level_data['availability'] : '100'; + $module_data[$module]['warning_events'] = ($service_level_data['warning_events'] !== false) ? $service_level_data['warning_events'] : '0'; + $module_data[$module]['critical_events'] = ($service_level_data['critical_events'] !== false) ? $service_level_data['critical_events'] : '0'; + $module_data[$module]['last_status_change'] = ($service_level_data['last_status_change'] !== false) ? $service_level_data['last_status_change'] : ''; + $module_data[$module]['module_name'] = ($service_level_data['module_name'] !== false) ? $service_level_data['module_name'] : ''; + $module_data[$module]['agent_alias'] = ($service_level_data['agent_alias'] !== false) ? $service_level_data['agent_alias'] : ''; + } + + $return['data'] = $module_data; + + return reporting_check_structure_content($return); +} + + function reporting_exception( $report, $content, diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 719ddfd7a3..cd5e1b5e23 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -260,7 +260,6 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust } $table->colspan['description_row']['description'] = 3; - switch ($item['type']) { case 'availability': default: @@ -403,6 +402,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust reporting_html_agent_module_status($table, $item); break; + case 'service_level': + reporting_html_service_level($table, $item); + break; + case 'alert_report_actions': reporting_html_alert_report_actions($table, $item); break; @@ -2452,6 +2455,82 @@ function reporting_html_agent_module_status($table, $item, $pdf=0) } +function reporting_html_service_level($table, $item, $pdf=0) +{ + global $config; + + $return_pdf = ''; + + if (empty($item['data']) === true) { + if ($pdf !== 0) { + $return_pdf .= __('No items'); + } else { + $table->colspan['group_report']['cell'] = 3; + $table->cellstyle['group_report']['cell'] = 'text-align: center;'; + $table->data['group_report']['cell'] = __('No items'); + } + } else { + $table_info = new stdClass(); + $table_info->width = '99%'; + if ($item['show_agents'] === '1') { + $show_agents = 'on'; + } else { + $show_agents = 'off'; + } + + if ($show_agents === 'on') { + $table_info->head[0] = __('Agent / Module'); + } else { + $table_info->head[0] = __('Module'); + } + + $table_info->head[1] = __('% Av.'); + $table_info->head[2] = __('MTBF'); + $table_info->head[3] = __('MTRS'); + $table_info->head[4] = __('Crit. Events'); + $table_info->head[5] = __('Warn. Events'); + $table_info->head[6] = __('Last change'); + $table_info->data = []; + $row = 0; + + foreach ($item['data'] as $agentmodule_id => $module_data) { + if ($show_agents === 'on') { + $table_info->data[$row][0] = $module_data['agent_alias'].' / '.$module_data['module_name']; + } else { + $table_info->data[$row][0] = $module_data['module_name']; + } + + $table_info->data[$row][1] = $module_data['availability'].'%'; + $table_info->data[$row][2] = $module_data['mtbf']; + $table_info->data[$row][3] = $module_data['mtrs']; + $table_info->data[$row][4] = $module_data['critical_events']; + $table_info->data[$row][5] = $module_data['warning_events']; + if ($module_data['last_status_change'] !== '') { + $table_info->data[$row][6] = date(TIME_FORMAT, $module_data['last_status_change']); + } + + // $table_info->data[$row][6] = date(TIME_FORMAT, $module_data['last_status_change']); + $row++; + } + + if ($pdf !== 0) { + $table_info->title = $item['title']; + $table_info->titleclass = 'title_table_pdf'; + $table_info->titlestyle = 'text-align:left;'; + $return_pdf .= html_print_table($table_info, true); + } else { + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: center;'; + $table->data['data']['cell'] = html_print_table($table_info, true); + } + } + + if ($pdf !== 0) { + return $return_pdf; + } +} + + /** * Function to print to HTML Exception report. * From 55edc30564a68ea222f40c54a9d70aea330cbf41 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 14 Sep 2023 17:11:00 +0200 Subject: [PATCH 018/397] #12065 fix icons --- .../include/javascript/pandora_events.js | 12 +++++++----- .../include/styles/js/jquery-ui_custom.css | 14 ++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 940fd3ce5d..4ff055a9ae 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1520,8 +1520,9 @@ $(document).ajaxSend(function(event, jqXHR, ajaxOptions) { // Add the minimize icon to the minimize button $("", { - class: "ui-button-icon ui-icon ui-icon-minusthick", - style: "background-color: #fff;" + class: "ui-button-icon ui-icon", + style: + "background-color: rgb(51, 51, 51); -webkit-mask: url('images/arrow-down-white.png') no-repeat right / contain !important;" }).appendTo(minimizeButton); $("", { @@ -1536,13 +1537,14 @@ $(document).ajaxSend(function(event, jqXHR, ajaxOptions) { "ui-corner-all ui-widget ui-button-icon-only ui-dialog-titlebar-disengage", type: "button", title: "Disengage", - style: "float: right;margin-right: 0.5em; position:relative;" + style: "float: right; position:relative;" }).insertBefore(minimizeButton); // Add the disengage icon to the disengage button $("", { - class: "ui-button-icon ui-icon ui-icon-circle-triangle-n", - style: "background-color: #fff;" + class: "ui-button-icon ui-icon", + style: + "background-color: rgb(51, 51, 51); -webkit-mask: url('images/dashboard.menu.png') no-repeat right / contain !important;" }).appendTo(disengageButton); $("", { diff --git a/pandora_console/include/styles/js/jquery-ui_custom.css b/pandora_console/include/styles/js/jquery-ui_custom.css index 9ee92c54d3..16ee9547f0 100644 --- a/pandora_console/include/styles/js/jquery-ui_custom.css +++ b/pandora_console/include/styles/js/jquery-ui_custom.css @@ -53,7 +53,7 @@ padding: 1px; height: 20px; bottom: 30%; - top: 2em; + top: 5px; background-color: #fff !important; } @@ -62,17 +62,15 @@ } .ui-dialog .ui-dialog-titlebar-disengage { - position: relative; - right: 1.5em; - width: 21px; + position: absolute !important; + right: 60px; + top: 5px; + width: 25px; margin: 0px 0 0 0; padding: 1px; - height: 20px; + height: 25px; bottom: 30%; background-color: #fff !important; - -ms-transform: scale(1.2); - -webkit-transform: scale(1.2); - transform: scale(1.2); } .ui-dialog .ui-dialog-titlebar-disengage:hover { From 2066907deddef784c7792c6fe4f746d971c16a7e Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Thu, 21 Sep 2023 14:36:57 +0200 Subject: [PATCH 019/397] #12058 Added database version in diagnostic information and about --- pandora_console/include/class/Diagnostics.class.php | 12 ++++++++++++ pandora_console/include/functions_menu.php | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/pandora_console/include/class/Diagnostics.class.php b/pandora_console/include/class/Diagnostics.class.php index 7d7532189c..492a444815 100644 --- a/pandora_console/include/class/Diagnostics.class.php +++ b/pandora_console/include/class/Diagnostics.class.php @@ -708,6 +708,10 @@ class Diagnostics extends Wizard { global $config; + // Get version comment DB. + $sql_version_comment = 'select @@version_comment as version_comment'; + $version_comment = db_get_sql($sql_version_comment); + $result = [ 'error' => false, 'data' => [ @@ -723,6 +727,14 @@ class Diagnostics extends Wizard 'name' => __('DB Schema Build'), 'value' => $config['db_scheme_build'], ], + 'dbVersion' => [ + 'name' => __('Engine version'), + 'value' => $config['dbconnection']->server_info, + ], + 'dbVersionComment' => [ + 'name' => __('Version comment'), + 'value' => $version_comment, + ], ], ]; diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index a1927bb60a..b637a7a7ed 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -1107,6 +1107,14 @@ if (is_ajax()) {

    '.$db_info->data->dbSize->value.'

    + + +

    '.$db_info->data->dbVersion->name.'

    + + +

    '.$db_info->data->dbVersion->value.'

    + + From 1d5b4ebc0fe5ad17993ddedfe2e0a10899506212 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 21 Sep 2023 16:26:44 +0200 Subject: [PATCH 020/397] #12096 Fix apos in welcome window --- pandora_console/include/class/WelcomeWindow.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 5e66268403..8b374b44a2 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -606,7 +606,7 @@ class WelcomeWindow extends Wizard ], [ 'arguments' => [ - 'label' => __("Let's do it!"), + 'label' => __('Let's do it!'), 'type' => 'button', 'attributes' => [ 'class' => 'secondary', From 4cddecb9ff085944f7537a1f2513a325a9c4934b Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 22 Sep 2023 13:20:27 +0200 Subject: [PATCH 021/397] #12058 Delete item db size --- pandora_console/include/functions_menu.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index b637a7a7ed..6036d16710 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -1099,14 +1099,6 @@ if (is_ajax()) {

    '.$db_info->data->dbSchemeBuild->value.'

    - - -

    '.$db_info->data->dbSize->name.'

    - - -

    '.$db_info->data->dbSize->value.'

    - -

    '.$db_info->data->dbVersion->name.'

    From 5d41cf7d04e95c59ee6bab6e1143c964e8d87e05 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 27 Sep 2023 15:47:44 +0200 Subject: [PATCH 022/397] #12139 Fix new_agent api request --- pandora_console/include/functions_api.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index 7e22befbee..068c5409f6 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -2014,7 +2014,7 @@ function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false, } returnError('No agent alias specified'); - } else if (agents_get_agent_id($nombre_agente)) { + } else if (agents_get_agent_id($agent->nombre())) { if ($message === true) { return 'The agent name already exists in DB.'; } @@ -2062,7 +2062,7 @@ function api_set_new_agent($id_node, $thrash2, $other, $trhash3, $return=false, } } - if ($return === false) { + if ($return !== true) { returnData( 'string', [ From 813a5ecd0d8850ed86fb723b647d9cf051071796 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Tue, 10 Oct 2023 11:34:47 +0200 Subject: [PATCH 023/397] #12168 Fixed filter to show the service genealogy --- .../include/class/TreeService.class.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/TreeService.class.php b/pandora_console/include/class/TreeService.class.php index b30877a5b5..d45ce50573 100644 --- a/pandora_console/include/class/TreeService.class.php +++ b/pandora_console/include/class/TreeService.class.php @@ -731,7 +731,26 @@ class TreeService extends Tree if (isset($this->filter['searchService']) === true && empty($this->filter['searchService']) === false ) { - return " AND (ts.name LIKE '%".$this->filter['searchService']."%' OR ts.description LIKE '%".$this->filter['searchService']."%')"; + $sqlFilter = 'SELECT ts.id FROM tservice ts + where ts.name LIKE "%'.$this->filter['searchService'].'%" + OR ts.description LIKE "%'.$this->filter['searchService'].'%"'; + + $filterResult = db_get_all_rows_sql($sqlFilter); + + foreach ($filterResult as $key => $result) { + $ancestors = services_get_services_ancestors($result['id']); + $idAncestors = implode(',', $ancestors); + $numAncestors = count($ancestors); + if ($numAncestors > 1) { + $whereAncestors = ' AND tse.id_service_child in ('.$idAncestors.')'; + } else if ($numAncestors == 1) { + $whereAncestors = ' AND ts.id ='.$idAncestors; + } else { + $whereAncestors = ' AND ts.id ='.$result['id']; + } + } + + return $whereAncestors; } return ''; From c9966ed9999947744e1c52eeb6add9bc8f9b0312 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 11 Oct 2023 16:16:22 +0200 Subject: [PATCH 024/397] #12132 Limit tips --- pandora_console/include/javascript/tipsWindow.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/javascript/tipsWindow.js b/pandora_console/include/javascript/tipsWindow.js index 94d28c9339..c68e7c9b05 100644 --- a/pandora_console/include/javascript/tipsWindow.js +++ b/pandora_console/include/javascript/tipsWindow.js @@ -134,8 +134,9 @@ function render_counter() { $(".counter-tips img:eq(0)").after( "" ); + var limitRound = totalTips > 28 ? 28 : totalTips; if (totalTips > 1) { - for (let i = 1; i <= totalTips - 1; i++) { + for (let i = 1; i <= limitRound - 1; i++) { $(".count-round-tip:eq(0)").after( "" ); From 9a57cc550ec99fbe9b063124dbecdc46e7ec1233 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Wed, 11 Oct 2023 16:31:48 +0200 Subject: [PATCH 025/397] #12192 Fix pandora itsm url --- pandora_console/godmode/setup/setup_ITSM.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandora_console/godmode/setup/setup_ITSM.php b/pandora_console/godmode/setup/setup_ITSM.php index 3196ef677c..50aee8631e 100644 --- a/pandora_console/godmode/setup/setup_ITSM.php +++ b/pandora_console/godmode/setup/setup_ITSM.php @@ -558,7 +558,7 @@ $table_cr_settings->data[4][0] = html_print_label_input_block( // Print. echo ''; From a456912dd7457fdd39284c965755a6b667c5b297 Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Mon, 16 Oct 2023 12:17:42 +0200 Subject: [PATCH 026/397] #12132 Fix welcome tips --- pandora_console/extras/mr/68.sql | 7 +++++++ pandora_console/include/class/TipsWindow.class.php | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 pandora_console/extras/mr/68.sql diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql new file mode 100644 index 0000000000..3095941187 --- /dev/null +++ b/pandora_console/extras/mr/68.sql @@ -0,0 +1,7 @@ +START TRANSACTION; + +DELETE FROM `twelcome_tip` WHERE `title` = 'Automatic agent provision system'; + +INSERT INTO `twelcome_tip` (`id_lang`,`id_profile`,`title`,`text`,`url`,`enable`) VALUES ('en_GB',0,'Automatic agent provision system','The agent self-provisioning system allows an agent recently entered into the system to automatically apply changes to their configuration (such as moving them from group, assigning them certain values in custom fields) and of course applying certain monitoring policies. It is one of the most powerful functionalities, aimed at managing very large system parks.','https://pandorafms.com/manual/start?id=en/documentation/02_installation/05_configuration_agents#conf',1); + +COMMIT; \ No newline at end of file diff --git a/pandora_console/include/class/TipsWindow.class.php b/pandora_console/include/class/TipsWindow.class.php index ae4271fba9..56082611ea 100644 --- a/pandora_console/include/class/TipsWindow.class.php +++ b/pandora_console/include/class/TipsWindow.class.php @@ -744,7 +744,7 @@ class TipsWindow ); $table->data[1][1] = html_print_label_input_block( __('Url'), - html_print_input_text('url', '', '', 35, 100, true) + html_print_input_text('url', '', '', 35, 255, true) ); $table->data[2][0] = html_print_label_input_block( __('Text'), @@ -911,7 +911,7 @@ class TipsWindow ); $table->data[1][1] = html_print_label_input_block( __('Url'), - html_print_input_text('url', $tip['url'], '', 35, 100, true) + html_print_input_text('url', $tip['url'], '', 35, 255, true) ); $table->data[2][0] = html_print_label_input_block( __('Text'), From 08bccce67367b92acc1250d72d7d28e9279da755 Mon Sep 17 00:00:00 2001 From: "felix.suarez" Date: Tue, 17 Oct 2023 08:28:38 -0600 Subject: [PATCH 027/397] Remove root validation --- pandora_agents/pc/pandora_agent | 11 +---------- pandora_agents/unix/pandora_agent | 9 +-------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/pandora_agents/pc/pandora_agent b/pandora_agents/pc/pandora_agent index aa8208f5d0..04b7de51a5 100644 --- a/pandora_agents/pc/pandora_agent +++ b/pandora_agents/pc/pandora_agent @@ -2185,16 +2185,7 @@ sub configure ($) { #Launch tentacle server in proxy mode if configured if ($Conf{'proxy_mode'}) { - - #Check if user is root - if ($> != 0) { - if (launch_tentacle_proxy() != 0) { - return 1; - } - } else { - error ('Proxy mode can not be launched as root'); - return 1; - } + return 1 if (launch_tentacle_proxy() != 0); } # Add the plugins directory to the PATH diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index de7a2e6946..d0b7c22ede 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -4183,14 +4183,7 @@ my $PID = $$; #Launch tentacle server in proxy mode if configured if ($Conf{'proxy_mode'}) { - - #Check if user is root - if ($> != 0) { - launch_tentacle_proxy(); - } else { - log_message ('error', 'Proxy mode can not be launched as root'); - exit 1; - } + launch_tentacle_proxy(); } # Advice if YAML::Tiny is allowed in this system From 4fb7e1719b1d8cc53d5c8e61c90bd76a37eb747f Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 18 Oct 2023 12:49:47 +0200 Subject: [PATCH 028/397] add periodicity graph pandora_enterprise#9640 --- pandora_console/extensions/agents_modules.php | 2 +- pandora_console/include/ajax/module.php | 17 +- pandora_console/include/functions_graph.php | 537 ++++++++++++++++ pandora_console/include/graphs/fgraph.php | 67 +- pandora_console/include/styles/pandora.css | 33 +- .../operation/agentes/stat_win.php | 572 +++++++----------- pandora_console/operation/search_modules.php | 2 +- 7 files changed, 845 insertions(+), 385 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index d6c4f3bb32..f372f45812 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -1007,7 +1007,7 @@ function mainAgentsModules() echo ""; $win_handle = dechex(crc32($module_id.$module['name'])); $graph_type = return_graphtype(modules_get_agentmodule_type($module_id)); - $link = "winopeng_var('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&'.'id='.$module_id.'&'.'refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."', 800, 480)"; + $link = "winopeng_var('".'operation/agentes/stat_win.php?'."type=$graph_type&".'period='.SECONDS_1DAY.'&id='.$module_id.'&period_graph=0&refresh='.SECONDS_10MINUTES."', 'day_".$win_handle."', 800, 480)"; echo ''; diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php index 78daacb0a0..2951ad495a 100755 --- a/pandora_console/include/ajax/module.php +++ b/pandora_console/include/ajax/module.php @@ -1283,7 +1283,7 @@ if (check_login()) { } if (is_snapshot_data($module['datos']) === false) { - $link = 'winopeng_var(\'operation/agentes/stat_win.php?type='.$graph_type.'&period='.SECONDS_1DAY.'&id='.$module['id_agente_modulo'].'&refresh='.SECONDS_10MINUTES.'&draw_events='.$draw_events.'\', \'day_'.$win_handle.'\', 800, 480)'; + $link = 'winopeng_var(\'operation/agentes/stat_win.php?type='.$graph_type.'&period='.SECONDS_1DAY.'&id='.$module['id_agente_modulo'].'&refresh='.SECONDS_10MINUTES.'&period_graph=0&draw_events='.$draw_events.'\', \'day_'.$win_handle.'\', 800, 480)'; $graphButtons[] = html_print_anchor( [ 'href' => 'javascript:'.$link, @@ -1499,9 +1499,14 @@ if (check_login()) { $output = ''; $graph_data = get_parameter('graph_data', ''); $params = json_decode(base64_decode($graph_data), true); + $form_data = json_decode(base64_decode(get_parameter('form_data', [])), true); $server_id = (int) get_parameter('server_id', 0); include_once $config['homedir'].'/include/functions_graph.php'; + $tab_active = get_parameter('active', 'tabs-chart-module-graph'); + + $output .= draw_form_stat_win($form_data, $tab_active); + // Metaconsole connection to the node. if (is_metaconsole() === true && empty($server_id) === false) { $server = metaconsole_get_connection_by_id($server_id); @@ -1553,7 +1558,15 @@ if (check_login()) { $output .= $graph['chart']; $output .= '
    '; } else { - $output .= grafico_modulo_sparse($params); + if ($tab_active === 'tabs-chart-module-graph') { + $output .= grafico_modulo_sparse($params); + } else { + $output .= graphic_periodicity_module($params); + if ($params['compare'] === 'separated') { + $params['date'] = ($params['date'] - $params['period']); + $output .= graphic_periodicity_module($params); + } + } } } diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index e6605a488b..006870757e 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -2422,6 +2422,147 @@ function graphic_combined_module( } +/** + * Draw periodicity graph + * + * @param array $params Params for draw chart. + * + * @return string Html output. + */ +function graphic_periodicity_module(array $params): string +{ + $date_array = []; + $date_array['period'] = $params['period']; + $date_array['final_date'] = $params['date']; + $date_array['start_date'] = ($params['date'] - $params['period']); + + $array_data = fullscale_data( + $params['agent_module_id'], + $date_array, + false, + false, + 1, + false, + $params['period_slice_chart'], + 0 + ); + + if (empty($array_data) === false) { + $graph_labels = []; + $multiple_labels = []; + foreach ($array_data['sum1']['slice_data'] as $time => $array_data) { + $graph_labels[] = date('H:i', ($time / 1000)); + + $avg = [ + 'y' => $array_data['avg'], + 'x' => $time, + ]; + + $max = [ + 'y' => $array_data['max'], + 'x' => $time, + ]; + + $min = [ + 'y' => $array_data['min'], + 'x' => $time, + ]; + + $sum = [ + 'y' => $array_data['sum'], + 'x' => $time, + ]; + if ((int) $params['period_mode'] === CUSTOM_GRAPH_HBARS) { + $avg = [ + 'x' => $array_data['avg'], + 'y' => $time, + ]; + + $max = [ + 'x' => $array_data['max'], + 'y' => $time, + ]; + + $min = [ + 'x' => $array_data['min'], + 'y' => $time, + ]; + + $sum = [ + 'x' => $array_data['sum'], + 'y' => $time, + ]; + } + + $graph_values_avg[] = $avg; + $graph_values_max[] = $max; + $graph_values_min[] = $min; + $graph_values_sum[] = $sum; + } + + if ((bool) $params['period_average'] === true) { + $graph_values['avg'] = $graph_values_avg; + $multiple_labels['avg'] = [ + 'label' => __('Average'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + + if ((bool) $params['period_maximum'] === true) { + $graph_values['max'] = $graph_values_max; + $multiple_labels['max'] = [ + 'label' => __('Maximun'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + + if ((bool) $params['period_minimum'] === true) { + $graph_values['min'] = $graph_values_min; + $multiple_labels['min'] = [ + 'label' => __('Minimum'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + + if ((bool) $params['period_summatory'] === true) { + $graph_values['sum'] = $graph_values_sum; + $multiple_labels['sum'] = [ + 'label' => __('Summatory'), + 'fill' => ((int) $params['period_mode'] === CUSTOM_GRAPH_AREA) ? true : false, + ]; + } + } + + $options = [ + 'height' => 200, + 'waterMark' => true, + 'legend' => ['display' => true], + 'labels' => $graph_labels, + 'multiple' => $multiple_labels, + ]; + + $output = '
    '; + $output .= '
    '; + if ((int) $params['period_mode'] === CUSTOM_GRAPH_HBARS + || (int) $params['period_mode'] === CUSTOM_GRAPH_VBARS + ) { + if ((int) $params['period_mode'] === CUSTOM_GRAPH_HBARS) { + $options['axis'] = 'y'; + } + + $output .= vbar_graph($graph_values, $options); + } else { + $output .= line_graph($graph_values, $options); + } + + $output .= '
    '; + $output .= '
    '; + + return $output; + +} + + /** * Function for convert data summatory. * @@ -3909,6 +4050,7 @@ function fullscale_data( } $data['sum'.$series_suffix]['slice_data'][$real_date]['avg'] = ($sum_data / $count_data); + $data['sum'.$series_suffix]['slice_data'][$real_date]['sum'] = $sum_data; if ($max_value != (-PHP_INT_MAX)) { $data['sum'.$series_suffix]['slice_data'][$real_date]['max'] = $max_value; @@ -4174,6 +4316,7 @@ function fullscale_data( $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = 0; if (isset($count_data) === true) { $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['avg'] = ($sum_data / $count_data); + $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['sum'] = $sum_data; } $data['sum'.$series_suffix]['slice_data'][($date_array['final_date'] * 1000)]['max'] = $max_value; @@ -5351,3 +5494,397 @@ function graph_analytics_filter_select() return $result; } + + +function draw_form_stat_win(array $form_data, string $tab_active) +{ + $table = html_get_predefined_table('transparent', 2); + $table->width = '100%'; + $table->id = 'stat_win_form_div'; + $table->style[0] = 'text-align:left;font-weight: bold;font-size:8.5pt;line-height:30pt;'; + $table->style[1] = 'text-align:left;font-weight: bold;line-height:30pt;'; + $table->style[2] = 'text-align:left;font-weight: bold;line-height:30pt;'; + $table->style[3] = 'text-align:left;font-weight: bold;line-height:30pt;'; + $table->class = 'table_modal_alternate'; + $table->data = []; + + if ((bool) $form_data['histogram'] === true || $tab_active === 'tabs-chart-period-graph') { + $table->data[0][0] = __('Refresh time'); + $table->data[0][1] = '
    '.html_print_extended_select_for_time( + 'refresh', + $form_data['refresh'], + '', + '', + 0, + 7, + true + ).'
    '; + + $table->data[0][2] = ''; + $table->data[0][3] = ''; + + $table->data[1][0] = __('Begin date'); + $table->data[1][1] = html_print_input_text( + 'start_date', + $form_data['start_date'], + '', + 10, + 20, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[1][2] = __('Begin time'); + $table->data[1][3] = html_print_input_text( + 'start_time', + $form_data['start_time'], + '', + 10, + 10, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[2][0] = __('Time range'); + $table->data[2][1] = '
    '.html_print_extended_select_for_time( + 'period', + $form_data['period'], + '', + '', + 0, + 7, + true + ).'
    '; + + $table->data[3][0] = __('Time compare (Separated)'); + $table->data[3][1] = html_print_checkbox_switch( + 'time_compare_separated', + 1, + (bool) $form_data['time_compare_separated'], + true + ); + + $table->data[3][2] = ''; + $table->data[3][3] = ''; + + if ($tab_active === 'tabs-chart-period-graph') { + $table->data[4][0] = __('Maximum'); + $table->data[4][1] = html_print_checkbox_switch( + 'period_maximum', + 1, + (bool) $form_data['period_maximum'], + true + ); + + $table->data[4][2] = __('Minimum'); + $table->data[4][3] = html_print_checkbox_switch( + 'period_minimum', + 1, + (bool) $form_data['period_minimum'], + true + ); + + $table->data[5][0] = __('Average'); + $table->data[5][1] = html_print_checkbox_switch( + 'period_average', + 1, + (bool) $form_data['period_average'], + true + ); + + $table->data[5][2] = __('Summatory'); + $table->data[5][3] = html_print_checkbox_switch( + 'period_summatory', + 1, + (bool) $form_data['period_summatory'], + true + ); + + $table->data[6][0] = __('Slice'); + $table->data[6][1] = '
    '.html_print_extended_select_for_time( + 'period_slice_chart', + (string) $form_data['period_slice_chart'], + '', + '', + 0, + 7, + true, + false, + true, + '', + false, + [ + SECONDS_1HOUR => __('1 hour'), + SECONDS_1DAY => __('1 day'), + SECONDS_1WEEK => __('1 week'), + SECONDS_1MONTH => __('1 month'), + ] + ).'
    '; + + $table->data[6][2] = __('Mode'); + $options_period_mode = [ + CUSTOM_GRAPH_AREA => __('Area'), + CUSTOM_GRAPH_LINE => __('Line'), + // CUSTOM_GRAPH_HBARS => __('Horizontal bars'), + CUSTOM_GRAPH_VBARS => __('Vertical bars'), + ]; + + $table->data[6][3] = '
    '.html_print_select( + $options_period_mode, + 'period_mode', + $form_data['period_mode'], + '', + '', + 0, + true, + false, + false + ).'
    '; + } + } else { + $table->data[0][0] = __('Refresh time'); + $table->data[0][1] = '
    '.html_print_extended_select_for_time( + 'refresh', + $form_data['refresh'], + '', + '', + 0, + 7, + true + ).'
    '; + + $table->data[0][2] = __('Show events'); + $disabled = false; + + $table->data[0][3] = html_print_checkbox_switch( + 'draw_events', + 1, + (bool) $form_data['draw_events'], + true, + $disabled + ); + + $table->data[1][0] = __('Begin date'); + $table->data[1][1] = html_print_input_text( + 'start_date', + $form_data['start_date'], + '', + 10, + 20, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[1][2] = __('Show alerts'); + $table->data[1][3] = html_print_checkbox_switch( + 'draw_alerts', + 1, + (bool) $form_data['draw_alerts'], + true + ); + + $table->data[2][0] = __('Begin time'); + $table->data[2][1] = html_print_input_text( + 'start_time', + $form_data['start_time'], + '', + 10, + 10, + true, + false, + false, + '', + 'small-input' + ); + + $table->data[2][2] = __('Show unknown graph'); + $table->data[2][3] = html_print_checkbox_switch( + 'unknown_graph', + 1, + (bool) $form_data['unknown_graph'], + true + ); + + $table->data[3][0] = __('Time range'); + $table->data[3][1] = '
    '.html_print_extended_select_for_time( + 'period', + $form_data['period'], + '', + '', + 0, + 7, + true + ).'
    '; + + $table->data[3][2] = ''; + $table->data[3][3] = ''; + + if (!modules_is_boolean($form_data['id'])) { + $table->data[4][0] = __('Zoom'); + $options = []; + $options[$form_data['zoom']] = 'x'.$form_data['zoom']; + $options[1] = 'x1'; + $options[2] = 'x2'; + $options[3] = 'x3'; + $options[4] = 'x4'; + $options[5] = 'x5'; + $table->data[4][1] = '
    '.html_print_select( + $options, + 'zoom', + $form_data['zoom'], + '', + '', + 0, + true, + false, + false + ).'
    '; + + $table->data[4][2] = __('Show percentil'); + $table->data[4][3] = html_print_checkbox_switch( + 'show_percentil', + 1, + (bool) $form_data['show_percentil'], + true + ); + } + + $table->data[5][0] = __('Time compare (Overlapped)'); + $table->data[5][1] = html_print_checkbox_switch( + 'time_compare_overlapped', + 1, + (bool) $form_data['time_compare_overlapped'], + true + ); + + $table->data[5][2] = __('Time compare (Separated)'); + $table->data[5][3] = html_print_checkbox_switch( + 'time_compare_separated', + 1, + (bool) $form_data['time_compare_separated'], + true + ); + + $table->data[6][0] = __('Show AVG/MAX/MIN data series in graph'); + $table->data[6][1] = html_print_checkbox_switch( + 'type_mode_graph', + 1, + (bool) $form_data['type_mode_graph'], + true, + false + ); + + $table->data[6][2] = __('Show full scale graph (TIP)'); + $table->data[6][2] .= ui_print_help_tip( + __('TIP mode charts do not support average - maximum - minimum series, you can only enable TIP or average, maximum or minimum series'), + true + ); + $table->data[6][3] = html_print_checkbox_switch( + 'fullscale', + 1, + (bool) $form_data['fullscale'], + true, + false + ); + + $table->data[7][0] = __('Projection graph'); + $table->data[7][0] .= ui_print_help_tip( + __('Projection graph take as begin date the current time'), + true + ); + $table->data[7][1] = html_print_checkbox_switch( + 'enable_projected_period', + 1, + (bool) $form_data['enable_projected_period'], + true + ); + + $table->data[7][2] = __('Projection period'); + $table->data[7][3] = '
    '.html_print_extended_select_for_time( + 'period_projected', + $form_data['period_projected'], + '', + '', + 0, + 7, + true + ).'
    '; + } + + $form_table = html_print_table($table, true); + $form_table .= html_print_div( + [ + 'class' => 'action-buttons-right-forced margin-top-10', + 'content' => html_print_submit_button( + __('Reload'), + 'submit', + false, + [ + 'icon' => 'search', + 'mode' => 'secondary mini', + 'class' => 'float-right', + ], + true + ), + ], + true + ); + + $output = '
    '; + $output .= html_print_input_hidden('id', $form_data['id'], true); + $output .= html_print_input_hidden('label', $form_data['label'], true); + + if (empty($server_id) === false) { + $output .= html_print_input_hidden('server', $form_data['server_id'], true); + } + + $output .= html_print_input_hidden('histogram', $form_data['histogram'], true); + $output .= html_print_input_hidden('period_graph', $form_data['period_graph'], true); + $output .= html_print_input_hidden('type', $form_data['type'], true); + + $output .= ui_toggle( + $form_table, + ''.__('Graph configuration menu').''.ui_print_help_tip( + __('In Pandora FMS, data is stored compressed. The data visualization in database, charts or CSV exported data won\'t match, because is interpreted at runtime. Please check \'Pandora FMS Engineering\' chapter from documentation.'), + true + ), + '', + '', + true, + true, + '', + 'white-box-content', + 'box-flat pdd_10px', + 'images/arrow@svg.svg', + 'images/arrow@svg.svg', + true + ); + $output .= '
    '; + + return $output; +} + + +function draw_container_chart_stat_win(?string $name='stat-win-module-graph') +{ + $output = '
    '; + $output .= '
    '; + $output .= html_print_image('images/spinner_charts.gif', true); + $output .= '
    '; + + $output .= '
    '; + $output .= '
    '; + + $output .= '
    '; + + return $output; +} diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 494ec9c010..9cf7b5621d 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -1220,11 +1220,24 @@ function get_build_setup_charts($type, $options, $data) break; case 'BAR': - $setData->setLabel('data')->setBackgroundColor($colors); - $setData->setLabel('data')->setBorderColor($borders); - $setData->setLabel('data')->setBorderWidth(2); - - $setData->setLabel('data')->data()->exchangeArray(array_values($data)); + if (isset($options['multiple']) === true && empty($options['multiple']) === false) { + $i = 0; + foreach ($options['multiple'] as $key_label => $info) { + $dataSet = $chart->createDataSet(); + $dataSet->setLabel(($info['label'] ?? '--')); + $dataSet->setBackgroundColor(($info['backgroundColor'] ?? $colors[$i])); + $dataSet->setBorderColor(($info['borderColor'] ?? $borders[$i])); + $dataSet->setBorderWidth(($info['borderWidth'] ?? 2)); + $dataSet->data()->exchangeArray(array_values($data[$key_label])); + $chart->addDataSet($dataSet); + $i++; + } + } else { + $setData->setLabel('data')->setBackgroundColor($colors); + $setData->setLabel('data')->setBorderColor($borders); + $setData->setLabel('data')->setBorderWidth(2); + $setData->setLabel('data')->data()->exchangeArray(array_values($data)); + } // Para las horizontales. if (isset($options['axis']) === true @@ -1250,19 +1263,32 @@ function get_build_setup_charts($type, $options, $data) break; case 'LINE': - $chart->labels()->exchangeArray($options['labels']); - - foreach ($data as $key => $dataset) { - $dataSet1 = $chart->createDataSet(); - $dataSet1->setLabel($dataset['label']); - $dataSet1->setBackgroundColor($dataset['backgroundColor']); - $dataSet1->setBorderColor($dataset['borderColor']); - $dataSet1->setPointBackgroundColor($dataset['pointBackgroundColor']); - $dataSet1->setPointBorderColor($dataset['pointBorderColor']); - $dataSet1->setPointHoverBackgroundColor($dataset['pointHoverBackgroundColor']); - $dataSet1->setPointHoverBorderColor($dataset['pointHoverBorderColor']); - $dataSet1->data()->exchangeArray($dataset['data']); - $chart->addDataSet($dataSet1); + if (isset($options['multiple']) === true && empty($options['multiple']) === false) { + $i = 0; + foreach ($options['multiple'] as $key_label => $info) { + $dataSet = $chart->createDataSet(); + $dataSet->setLabel(($info['label'] ?? '--')); + $dataSet->setBackgroundColor(($info['backgroundColor'] ?? $colors[$i])); + $dataSet->setBorderColor(($info['borderColorColor'] ?? $borders[$i])); + $dataSet->setFill(($info['fill'] ?? false)); + $dataSet->data()->exchangeArray(array_values($data[$key_label])); + $chart->addDataSet($dataSet); + $i++; + } + } else { + $chart->labels()->exchangeArray($options['labels']); + foreach ($data as $key => $dataset) { + $dataSet = $chart->createDataSet(); + $dataSet->setLabel($dataset['label']); + $dataSet->setBackgroundColor($dataset['backgroundColor']); + $dataSet->setBorderColor($dataset['borderColor']); + $dataSet->setPointBackgroundColor($dataset['pointBackgroundColor']); + $dataSet->setPointBorderColor($dataset['pointBorderColor']); + $dataSet->setPointHoverBackgroundColor($dataset['pointHoverBackgroundColor']); + $dataSet->setPointHoverBorderColor($dataset['pointHoverBorderColor']); + $dataSet->data()->exchangeArray($dataset['data']); + $chart->addDataSet($dataSet); + } } break; @@ -1271,7 +1297,10 @@ function get_build_setup_charts($type, $options, $data) break; } - if ($type !== 'RADAR' && $type !== 'LINE') { + if ($type !== 'RADAR' + && $type !== 'LINE' + && ((isset($options['multiple']) === false || empty($options['multiple']) === true)) + ) { $chart->addDataSet($setData); } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 1e89e83243..87b2c9d89e 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -9572,9 +9572,19 @@ div.stat-win-spinner img { } .stat_win_histogram { - width: 95%; margin: 0 auto; - margin-top: 18%; +} + +.bg_general { + background-color: #ffffff; +} + +#tabs-chart-modal { + border: 0px; +} + +#tabs-chart-ul-graphs li a img { + margin-left: 20px; } #stat-win-module-graph .stat_win_histogram div.nodata_container { @@ -12787,3 +12797,22 @@ tr.shown td.details-control { position: relative; top: -92px; } + +.container-periodicity-graph { + display: flex; + flex-direction: row; + justify-content: center; + align-items: center; + align-content: center; + border: 1px solid #e5e9ed; + border-radius: 10px; + margin-top: 25px; + padding: 10px; +} + +.container-periodicity-graph > div { + flex: 0 0 auto; + width: 100%; + height: 300px; + background-color: transparent; +} diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index a16d4c6e65..0f8b7e707b 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -127,6 +127,7 @@ ui_print_message_dialog( + '; +echo '
    '; +echo ''.__('Configure demo data').''; +html_print_input_hidden('update_config', 1); +html_print_table($table_aux); +echo '
    '; + +$actionButtons = []; + +$actionButtons[] = html_print_submit_button( + __('Create demo data'), + 'update_button', + false, + [ 'icon' => 'update' ], + true +); + +$actionButtons[] = html_print_button( + __('Delete demo data'), + 'delete_session_users', + false, + '', + [ + 'icon' => 'delete', + 'mode' => 'secondary', + ], + true +); + +html_print_action_buttons( + implode('', $actionButtons) +); + +echo ''; + +?> + + \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php new file mode 100644 index 0000000000..1016903e57 --- /dev/null +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -0,0 +1,386 @@ + 0) { + // Read all ini files. + $parsed_ini[] = parse_ini_file($config['homedir'].'/extras/demodata/agents/linux.ini', true, INI_SCANNER_TYPED); +hd($parsed_ini, true); + $ag_groups_num = ($agents_num / 10); + + // Create new group per group of ten agents that are to be created. + for ($i=0; $i<$ag_groups_num; $i++) { + $group_name = db_get_value_sql( + 'SELECT tg.nombre + FROM tdemo_data tdd INNER JOIN tgrupo tg ON tdd.item_id = tg.id_grupo + WHERE tdd.table_name = "tgrupo" + ORDER BY tdd.id DESC' + ); + + if ($group_name === false) { + $group_last_id = 0; + } else { + $group_last_id = (int) explode(' ', $group_name)[2]; + } + + if (!($group_last_id > -1)) { + echo json_encode(['msg' => 'Demo group ID not valid']); + return; + } + + $demo_group_name = 'Demo group '.($i + $group_last_id + 1); + + $created_group_id = groups_create_group($demo_group_name, []); + + if ($created_group_id > 0) { + $demo_group_ids[] = $created_group_id; + + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_group_id, + 'table_name' => 'tgrupo', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback group creation. + db_process_sql_delete('tgrupo', ['id_grupo' => $created_group_id]); + } + } else { + echo json_encode(['msg' => 'Could not create demo agent group']); + return; + } + } + + $agents_created_count = 0; + $group_idx = 0; + + $agent_alias = db_get_value_sql('SELECT ta.alias FROM tdemo_data tdd INNER JOIN tagente ta ON tdd.item_id = ta.id_agente WHERE tdd.table_name="tagente" ORDER BY tdd.id DESC'); + + if ($agent_alias === false) { + $agent_last_id = 0; + } else { + $agent_last_id = (int) explode(' ', $agent_alias)[1]; + } + + foreach ($parsed_ini as $ini_so_data) { + $agent_data = $ini_so_data['agent_data']; + $modules_data = $ini_so_data['modules']; + $inventory = $ini_so_data['inventory']; + $inventory_values = $ini_so_data['inventory_values']; + + $address_network = $agent_data['address_network']; + $os_versions = $agent_data['os_versions']; + $os_name = $agent_data['os_name']; + + // Get OS id given OS name. + $id_os = db_get_value_filter('id_os', 'tconfig_os', ['name' => $os_name]); + + if ($id_os === false) { + // Create OS if does not exist. + $values = ['name' => $os_name]; + $id_os = (bool) db_process_sql_insert('tconfig_os', $values); + + if ($id_os === false) { + continue; + } + } + + // Define agents to be created per group of 10. + $agents_per_os = [ + 'Linux' => 5, + 'Windows' => 2, + 'MAC OS' => 1, + 'BSD' => 1, + 'Cisco' => 1, + ]; + + $agents_to_create = ($ag_groups_num * $agents_per_os[$os_name]); + + for ($i=0; $i < $agents_to_create; $i++) { + $next_ip_address = calculateNextHostAddress($address_network); + + $os_version = current($os_versions); + next($os_versions); + + if (current($os_versions) === false) { + reset($os_versions); + } + + $agent_last_id++; + + $created_agent_id = agents_create_agent( + $agent_data['agent_alias'].' '.$agent_last_id, + $demo_group_ids[$group_idx], + // Default interval. + 300, + $next_ip_address, + false, + false, + $id_os, + $os_version + ); + + if ($created_agent_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_agent_id, + 'table_name' => 'tagente', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback agent creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente', ['id_agente' => $created_agent_id]); + continue; + } + } + + $agents_created_count++; + + if (($agents_created_count % 10) === 0) { + $group_idx++; + } + + // Create agent modules. + $module_access_idx = 1; + + while (1) { + $modules_array = []; + foreach ($modules_data as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $test_empty_array = array_filter($modules_array); + + if (empty($test_empty_array) === true) { + break; + } + + $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + + $values = [ + 'unit' => $modules_array['unit'], + 'descripcion' => $modules_array['description'], + 'id_tipo_modulo' => $id_tipo, + 'id_module_group' => ($modules_array['group'] ?? 0), + ]; + + $created_mod_id = modules_create_agent_module( + $created_agent_id, + io_safe_input($modules_array['name']), + $values + ); + + if ($created_mod_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_mod_id, + 'table_name' => 'tagente_modulo', + ]; + + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback agent module creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_mod_id]); + continue; + } + + // Insert module data. + $parsed = explode(';', $modules_array['values']); + + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); + } else if ((string) $parsed[0] === 'PROC') { + $probability = (int) $parsed[1]; + + $data = 0; + + if ($probability > 0) { + $randomNumber = rand(1, 100); + + if ($randomNumber <= $probability) { + $data = 1; + } + } + } + + $agent_data_values = [ + 'id_agente_modulo' => $created_mod_id, + 'datos' => $data, + 'utimestamp' => time(), + ]; + + db_process_sql_insert('tagente_datos', $agent_data_values); + } + + $module_access_idx++; + }; + + // Create inventory modules. + $module_access_idx = 1; + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + + while (1) { + $modules_array = []; + foreach ($inventory as $key => $value) { + $modules_array[$key] = ($value[$module_access_idx] ?? null); + } + + $test_empty_array = array_filter($modules_array); + + if (empty($test_empty_array) === true) { + break; + } + + $values = [ + 'name' => $modules_array['name'], + 'data_format' => $modules_array['format'], + 'id_os' => 1, + ]; + + // STEP 1: tmodule_inventory. + $created_inventory_mod_id = inventory_create_inventory_module($values); + + if ($created_inventory_mod_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_inventory_mod_id, + 'table_name' => 'tmodule_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $created_inventory_mod_id]); + continue; + } + } + + $module_access_idx++; + + // STEP 2: tagent_module_inventory. + $values = [ + 'id_agente' => $created_agent_id, + 'id_module_inventory' => $created_inventory_mod_id, + 'interval' => 300, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + ]; + + + + // STEP 3: Create inventory values (tagente_datos_inventory). + $field_idx = 1; + $values_array = explode(';', $modules_array['values']); + + $selected_inventory_values = array_filter( + $inventory_values, + function ($key) use ($values_array) { + return in_array($key, $values_array); + }, + ARRAY_FILTER_USE_KEY + ); + + hd("INV VALUES", true); + hd($selected_inventory_values, true); + + $data_lines = []; + while (1) { + $line_values = array_column($selected_inventory_values, $field_idx); + + if (empty(array_filter($line_values)) === true) { + break; + } + + $data_lines[] = implode(';', $line_values); + $field_idx++; + } + + $data_str = implode('\n', $data_lines); + + hd("DATA STR",true); + hd($data_str, true); + + $inventory_data_values = [ + 'data' => $data_str, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + ]; + + $created_inventory_data = db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); + hd("CID",true); + hd($inventory_data_values, true); + hd($created_inventory_data, true); + + if ($created_inventory_data > 0) { + // Register created inventory data element in tdemo_data. + $values = [ + 'item_id' => $created_inventory_data, + 'table_name' => 'tagente_datos_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete( + 'tagente_datos_inventory', + ['id_agent_module_inventory' => $created_inventory_data] + ); + + continue; + } + } + }; + } + } + } + + return; +} + + +function calculateNextHostAddress($ip) { + list($network, $subnet) = explode('/', $ip); + + // Convert the network address to an array of octets. + $octets = explode('.', $network); + + // Convert the last octet to an integer. + $lastOctet = (int)$octets[3]; + + // Increment the last octet, and wrap around if it exceeds 255. + $lastOctet = ($lastOctet + 1) % 256; + + // Assemble the next host address. + $nextHost = implode('.', array($octets[0], $octets[1], $octets[2], $lastOctet)); + + return $nextHost . '/' . $subnet; +} \ No newline at end of file diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index 5e66268403..cd057414d0 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -581,6 +581,7 @@ class WelcomeWindow extends Wizard ], ]; + $fields['load_demo_data'] = __('Load demo data'); $fields['wizard_agent'] = __('Agent installation wizard'); $fields['check_web'] = __('Create WEB monitoring'); $fields['check_connectivity'] = __('Create network monitoring'); @@ -1112,6 +1113,9 @@ class WelcomeWindow extends Wizard alert(""); } else { switch($('#task_to_perform :selected').val()) { + case 'load_demo_data': + loadDemoDataPage(); + break; case 'wizard_agent': deployAgent(); break; @@ -1152,6 +1156,11 @@ class WelcomeWindow extends Wizard window.location = ''; } + // Task to do actions. + function loadDemoDataPage() { + window.location = ''; + } + function openCreateModulesDialog() { $('#dialog_goliat').dialog({ title: '', diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 720b0e6e55..04174569a1 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -207,6 +207,8 @@ function agents_get_next_contact_time_left(int $id_agente) * @param string $ip_address Agent IP. * @param mixed $values Other tagente fields. * @param boolean $alias_as_name True to not assign an alias as name. + * @param mixed $os OS ID. + * @param mixed $os_version OS version. * * @return integer New agent id if created. False if it could not be created. */ @@ -216,7 +218,9 @@ function agents_create_agent( $interval, $ip_address, $values=false, - $alias_as_name=false + $alias_as_name=false, + $os=false, + $os_version=false ) { global $config; @@ -250,6 +254,14 @@ function agents_create_agent( $values['direccion'] = $ip_address; } + if (empty($os) === false) { + $values['id_os'] = $os; + } + + if (empty($os_version) === false) { + $values['os_version'] = $os_version; + } + // Check if group has limit or overrides the agent limit. if (group_allow_more_agents($id_group, true, 'create') === false) { return false; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 141ab4344d..86533ed028 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4516,4 +4516,15 @@ CREATE TABLE IF NOT EXISTS `tgraph_analytics_filter` ( `graph_modules` TEXT NULL, `interval` INT NULL, PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- --------------------------------------------------------------------- +-- Table `tdemo_data` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tdemo_data` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `item_id` INT UNSIGNED NULL DEFAULT NULL, + `table_name` VARCHAR(64) NULL DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + From fc82a04a58ffbddf38fdf8521b2e0e60d979f553 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 27 Oct 2023 08:42:07 +0200 Subject: [PATCH 043/397] change location of file --- .../{update_manager_client => }/required_um_versions.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename pandora_console/{update_manager_client => }/required_um_versions.php (100%) diff --git a/pandora_console/update_manager_client/required_um_versions.php b/pandora_console/required_um_versions.php similarity index 100% rename from pandora_console/update_manager_client/required_um_versions.php rename to pandora_console/required_um_versions.php From 407a505a3e2f20bf185364cc89c90fae6a4e60d3 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 27 Oct 2023 14:32:48 +0200 Subject: [PATCH 044/397] #8365 Added reports for ncm backups. --- .../reporting_builder.item_editor.php | 111 ++++++++++++++++++ .../godmode/reporting/reporting_builder.php | 31 ++++- pandora_console/include/functions_reports.php | 5 + .../operation/agentes/ver_agente.php | 26 ++++ 4 files changed, 169 insertions(+), 4 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index e6032de2f6..d13071c60a 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1039,6 +1039,11 @@ switch ($action) { $idAgent = $item['id_agent']; break; + case 'ncm_backups': + $id_agent_ncm = $item['id_agent']; + $ncm_group = $item['id_group']; + break; + case 'top_n_agents_sh': $group = $item['id_group']; $recursion = $item['recursion']; @@ -1928,6 +1933,71 @@ if (is_metaconsole() === true) { ?> + + + + '; + $url = ui_get_full_url('ajax.php'); + html_print_input_hidden('url_ajax', $url, false, false, false, 'url_ajax'); + if (check_acl($config['id_user'], 0, 'RW')) { + html_print_select_groups( + $config['id_user'], + 'RW', + true, + 'ncm_group', + $ncm_group, + 'filterNcmAgentChange()', + ); + } else if (check_acl($config['id_user'], 0, 'RM')) { + html_print_select_groups( + $config['id_user'], + 'RM', + true, + 'ncm_group', + $ncm_group, + 'filterNcmAgentChange()', + ); + } + + echo ''; + ?> + + + + + + '; + $all_agents = agents_get_agents_selected($ncm_group); + html_print_select( + $all_agents, + 'agent_ncm', + $id_agent_ncm, + '', + __('Any'), + 0, + false, + true, + true, + '', + false, + 'width: 100%;', + false, + false, + false, + '', + false, + false, + false, + false, + true, + true, + ); + echo ''; + ?> + + @@ -6915,6 +6985,10 @@ function chooseType() { $('#agent_autocomplete_events').show(); + // NCM fields. + $("#row_ncm_group").hide(); + $("#row_ncm_agent").hide(); + switch (type) { case 'event_report_group': $("#row_description").show(); @@ -7764,6 +7838,11 @@ function chooseType() { $("#row_agent").show(); break; + case 'ncm_backups': + $("#row_ncm_group").show(); + $("#row_ncm_agent").show(); + break; + case 'top_n_agents_sh': $("#row_group").show(); $("#row_max_items").show(); @@ -8046,4 +8125,36 @@ $(document).ready(function () { }); }); +// Ncm agent filter by group. +function filterNcmAgentChange() { + var idGroup = $("#ncm_group").val(); + const url_ajax = $("#url_ajax").val(); + + $.ajax({ + url: url_ajax, + type: "POST", + dataType: "json", + async: false, + data: { + page: "operation/agentes/ver_agente", + get_ncm_agents: 1, + id_group: idGroup, + privilege: "AW", + keys_prefix: "_" + }, + success: function(data) { + $("#agent_ncm").empty(); + data.map(item => { + var option = $("") + .attr("value", item.id_agent) + .html(item.alias); + $("#agent_ncm").append(option); + }); + }, + error: function(err) { + console.error(err); + } + }); +} + diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 095f79b14a..349bad535e 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2045,6 +2045,12 @@ switch ($action) { $good_format = true; break; + case 'ncm_backups': + $values['id_agent'] = get_parameter('agent_ncm'); + $values['id_group'] = get_parameter('ncm_group'); + $good_format = true; + break; + default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter( @@ -2065,7 +2071,10 @@ switch ($action) { break; } - $values['id_agent'] = get_parameter('id_agent'); + if (isset($values['id_agent']) === false) { + $values['id_agent'] = get_parameter('id_agent'); + } + $values['id_gs'] = get_parameter('id_custom_graph'); $values['id_agent_module'] = ''; @@ -2181,7 +2190,10 @@ switch ($action) { $values['id_module_group'] = get_parameter( 'combo_modulegroup' ); - $values['id_group'] = get_parameter('combo_group'); + + if (isset($values['id_group']) === false) { + $values['id_group'] = get_parameter('combo_group'); + } if ($values['server_name'] == '') { $values['server_name'] = get_parameter( @@ -2977,6 +2989,12 @@ switch ($action) { $good_format = true; break; + case 'ncm_backups': + $values['id_agent'] = get_parameter('agent_ncm'); + $values['id_group'] = get_parameter('ncm_group'); + $good_format = true; + break; + default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter( @@ -3003,7 +3021,10 @@ switch ($action) { ); } - $values['id_agent'] = get_parameter('id_agent'); + if (isset($values['id_agent']) === false) { + $values['id_agent'] = get_parameter('id_agent'); + } + $values['id_gs'] = get_parameter('id_custom_graph'); if (($values['type'] == 'alert_report_agent') || ($values['type'] == 'event_report_agent') @@ -3117,7 +3138,9 @@ switch ($action) { $values['id_module_group'] = get_parameter( 'combo_modulegroup' ); - $values['id_group'] = get_parameter('combo_group'); + if (isset($values['id_group']) === false) { + $values['id_group'] = get_parameter('combo_group'); + } if ((($values['type'] == 'custom_graph') diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 3da9993933..8956e3adc9 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -968,6 +968,11 @@ function reports_get_report_types($template=false, $not_editor=false) 'name' => __('Network configuration changes'), ]; + $types['ncm_backups'] = [ + 'optgroup' => __('NCM'), + 'name' => __('Network backups'), + ]; + if (enterprise_installed() === true) { $types['top_n_agents_sh'] = [ 'optgroup' => __('Security hardening'), diff --git a/pandora_console/operation/agentes/ver_agente.php b/pandora_console/operation/agentes/ver_agente.php index 383a3b40d5..b050ba3b31 100644 --- a/pandora_console/operation/agentes/ver_agente.php +++ b/pandora_console/operation/agentes/ver_agente.php @@ -28,6 +28,7 @@ use PandoraFMS\Enterprise\Metaconsole\Node; use PandoraFMS\ITSM\ITSM; +use PandoraFMS\Enterprise\NetworkManager; global $config; @@ -72,6 +73,7 @@ if (is_ajax()) { $get_node_agent = (bool) get_parameter('get_node_agent', false); $get_agent_inventory_modules = (bool) get_parameter('get_agent_inventory_modules', false); $get_agent_inventory_dates = (bool) get_parameter('get_agent_inventory_dates', false); + $get_ncm_agents = (bool) get_parameter('get_ncm_agents', false); $refresh_contact = get_parameter('refresh_contact', 0); @@ -213,6 +215,30 @@ if (is_ajax()) { return; } + + // Get ncm Agent. + if ($get_ncm_agents === true) { + $fields = [ + '`tncm_agent`.id_agent', + '`tagente`.alias', + ]; + $id_group = (int) get_parameter('id_group'); + + $filter['filter_id_group'] = $id_group; + // Retrieve data. + $ncm_data = NetworkManager::agents( + // Fields. + $fields, + // Filter. + $filter, + ); + + echo json_encode($ncm_data); + return; + } + + + if ($get_modules_group_json === true) { $id_group = (int) get_parameter('id_module_group', 0); $id_agents = get_parameter('id_agents', null); From e062db2439ca1499f6ab6e93dd6fd5a456fec88d Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 30 Oct 2023 08:39:20 +0100 Subject: [PATCH 045/397] #8365 NCM add backup id to ncm queue --- pandora_console/pandoradb.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 1d7374bc03..8a4fca2917 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4226,6 +4226,7 @@ CREATE TABLE IF NOT EXISTS `tncm_agent_data` ( `id` SERIAL, `id_agent` INT UNSIGNED NOT NULL, `script_type` INT UNSIGNED NOT NULL, + `id_agent_data` INT NOT NULL DEFAULT 0, `data` LONGBLOB, `status` INT NOT NULL DEFAULT 5, `updated_at` BIGINT NOT NULL DEFAULT 0, From 63c74e2aa958355b0471de1b38ebd608dc4f38dc Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 30 Oct 2023 08:55:21 +0100 Subject: [PATCH 046/397] #8365 recovery after vscode revert error --- pandora_console/extras/mr/67.sql | 6 +-- pandora_console/pandoradb.sql | 4 +- pandora_server/lib/PandoraFMS/Tools.pm | 61 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index aa44ceea56..d15e49cf38 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,7 +1,7 @@ START TRANSACTION; ALTER TABLE `tncm_queue` -ADD COLUMN `id_agent_data` INT NOT NULL DEFAULT 0 AFTER `id_script`; +ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`, +ADD CONSTRAINT `fk_tncm_queue_tncm_agent_data` FOREIGN KEY (`id_agent_data`) REFERENCES `tncm_agent_data`(`id`) ON UPDATE CASCADE ON DELETE SET NULL; - -COMMIT; \ No newline at end of file +COMMIT; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 8a4fca2917..de34968f68 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4240,10 +4240,12 @@ CREATE TABLE IF NOT EXISTS `tncm_queue` ( `id` SERIAL, `id_agent` INT UNSIGNED NOT NULL, `id_script` BIGINT UNSIGNED NOT NULL, + `id_agent_data` bigint unsigned, `utimestamp` INT UNSIGNED NOT NULL, `scheduled` INT UNSIGNED DEFAULT NULL, FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, - FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE + FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_agent_data`) REFERENCES `tncm_agent_data`(`id`) ON UPDATE CASCADE ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ---------------------------------------------------------------------- diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 70d697dab4..a0cc1c15ac 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -30,6 +30,9 @@ use Scalar::Util qw(looks_like_number); use LWP::UserAgent; use threads; use threads::shared; +use MIME::Base64; +use Crypt::CBC; +use Digest::SHA qw(hmac_sha256_base64); use JSON; use Encode qw/decode_utf8 encode_utf8/; @@ -181,6 +184,7 @@ our @EXPORT = qw( check_cron_value check_cron_element cron_check + decrypt_AES ); # ID of the different servers @@ -2983,6 +2987,63 @@ sub get_server_name { return "UNKNOWN"; } +############################################################################### +# Encrypt with AES cypher +############################################################################### +sub encrypt_AES { + my ($str_to_encrypt, $password) = @_; + + if (!defined($password)) { + $password = "default_salt"; + } + my $cipher = _get_cipher($password); + + my $cipher_text = $cipher->encrypt($str_to_encrypt); + my $b64str = encode_base64($cipher_text, ''); + + return $b64str; +} + +############################################################################### +# Decrypt with AES cypher +############################################################################### +sub decrypt_AES { + my ($str_to_decrypt, $password) = @_; + + if (!defined($password)) { + $password = "default_salt"; + } + my $cipher = _get_cipher($password); + + my $cipher_text = decode_base64($str_to_decrypt); + my $decrypted_str = $cipher->decrypt($cipher_text); + + return $decrypted_str; +} + +############################################################################### +# Get cipher for AES encrypt and decrypt +############################################################################### +sub _get_cipher { + my ($password) = @_; + + my $hash_base64 = substr(Digest::SHA::hmac_sha256_base64($password,''), 0, 16); + + my $iv = '0000000000000000'; + + my $cipher = Crypt::CBC->new( + -key => $hash_base64, + -cipher => 'Cipher::AES', + -iv => $iv, + -header => 'none', + -padding => 'standard', # PKCS7 padding + -keysize => 16, + -literal_key => 1 + ); + + return $cipher; +} + 1; __END__ From 84b9ac14fb66f5942637c819aef09475a598df00 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Mon, 30 Oct 2023 10:18:29 +0100 Subject: [PATCH 047/397] #8365Added viewer report for ncm backups --- pandora_console/include/functions_reporting.php | 8 ++++++++ pandora_console/operation/reporting/reporting_viewer.php | 1 + 2 files changed, 9 insertions(+) diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 39f1642fa0..19c3f80b10 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -972,6 +972,14 @@ function reporting_make_reporting_data( ); break; + case 'ncm_backups': + $report['contents'][] = reporting_ncm_backups( + $report, + $content, + $pdf + ); + break; + case 'top_n_agents_sh': $report['contents'][] = reporting_top_n_agents_sh( $report, diff --git a/pandora_console/operation/reporting/reporting_viewer.php b/pandora_console/operation/reporting/reporting_viewer.php index cc42d7e6ac..4bc5a05b61 100755 --- a/pandora_console/operation/reporting/reporting_viewer.php +++ b/pandora_console/operation/reporting/reporting_viewer.php @@ -335,6 +335,7 @@ $table2->data[0][3] = $html_menu_export; $searchForm = '
    '; $searchForm .= html_print_table($table2, true); $searchForm .= html_print_input_hidden('id_report', $id_report, true); +$Actionbuttons = ''; if ((bool) is_metaconsole() === true) { $Actionbuttons .= html_print_submit_button( From 307fd7b8cb66e0c2cd35821ccbc9c25a8062e04e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 30 Oct 2023 10:52:13 +0100 Subject: [PATCH 048/397] #8365 remove fk tncm_queue --- pandora_console/extras/mr/67.sql | 3 +-- pandora_console/pandoradb.sql | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index d15e49cf38..2f6824f1f2 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -1,7 +1,6 @@ START TRANSACTION; ALTER TABLE `tncm_queue` -ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`, -ADD CONSTRAINT `fk_tncm_queue_tncm_agent_data` FOREIGN KEY (`id_agent_data`) REFERENCES `tncm_agent_data`(`id`) ON UPDATE CASCADE ON DELETE SET NULL; +ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`; COMMIT; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index de34968f68..65e2459bdb 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4244,8 +4244,7 @@ CREATE TABLE IF NOT EXISTS `tncm_queue` ( `utimestamp` INT UNSIGNED NOT NULL, `scheduled` INT UNSIGNED DEFAULT NULL, FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, - FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, - FOREIGN KEY (`id_agent_data`) REFERENCES `tncm_agent_data`(`id`) ON UPDATE CASCADE ON DELETE SET NULL + FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ---------------------------------------------------------------------- From 7db3e3bb2b52c03290523778e550416ddb761d8e Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Mon, 30 Oct 2023 17:20:58 +0100 Subject: [PATCH 049/397] #8365 Added html report for ncm backups --- .../include/functions_reporting_html.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 99f3af63ad..8fc6f3cf79 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -480,6 +480,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust reporting_html_ncm_config($table, $item); break; + case 'ncm_backups': + reporting_html_ncm_backups($table, $item); + break; + case 'top_n_agents_sh': reporting_html_top_n_agents_sh($table, $item); break; @@ -7380,3 +7384,49 @@ function reporting_html_ncm_config($table, $item, $pdf=0) return $content; } } + + +/** + * HTML content for ncm backup report. + * + * @param array $item Content generated by reporting_ncm_config. + * + * @return string HTML code. + */ +function reporting_html_ncm_backups($table, $item, $pdf=0) +{ + ui_require_javascript_file('diff2html-ui.min'); + ui_require_css_file('diff2html.min'); + ui_require_css_file('highlight.min'); + ui_require_css_file('highlight/vs.min'); + ui_require_javascript_file('highlight.min'); + ui_require_javascript_file('highlightjs-line-numbers.min'); + ui_require_javascript_file('languages/plaintext.min'); + ui_require_javascript_file('functions_ncm', ENTERPRISE_DIR.'/include/javascript/'); + + // Create table info. + $table_ncm = new stdClass(); + $table_ncm->width = '100%'; + $table_ncm->class = 'info_table'; + $table_ncm->styleTable = 'table-layout: fixed;'; + $table_ncm->rowstyle['title'] = 'text-align: center; font-weight: bolder'; + $table_ncm->head = []; + $table_ncm->head[0] = __('Date'); + $table_ncm->head[1] = __('Diff'); + + $table_ncm->data = []; + foreach ($item['data'] as $key => $row) { + $table_ncm->data[] = [ + $row['updated_at'], + $row['diff'], + ]; + } + + if ($pdf === 0) { + return $table->data[] = html_print_table( + $table_ncm, + true + ); + } + +} From b327c824da86c620a3aa383dff7e7c5be9d43ca4 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 31 Oct 2023 13:45:26 +0100 Subject: [PATCH 050/397] #8365 NCM new special templates --- pandora_console/extras/mr/67.sql | 27 +++++++++++++++++++++++++++ pandora_console/pandoradb.sql | 26 ++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 2f6824f1f2..9da40c6829 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -3,4 +3,31 @@ START TRANSACTION; ALTER TABLE `tncm_queue` ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`; +CREATE TABLE IF NOT EXISTS `tncm_special_template` ( + `id` SERIAL, + `name` TEXT, + `vendors` TEXT, + `models` TEXT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +ALTER TABLE `tncm_agent` +ADD COLUMN `id_special_template` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `id_template`; + +CREATE TABLE IF NOT EXISTS `tncm_special_template_scripts` ( + `id` SERIAL, + `id_special_template` BIGINT UNSIGNED NOT NULL, + `id_script` BIGINT UNSIGNED NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_special_template`) REFERENCES `tncm_special_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +ALTER TABLE `tncm_agent` +ADD COLUMN `special_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_interval`; + +ALTER TABLE `tncm_agent` +ADD COLUMN `special_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`; + + COMMIT; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 65e2459bdb..24020ffb0f 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4191,6 +4191,29 @@ CREATE TABLE IF NOT EXISTS `tncm_template_scripts` ( FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +-- ---------------------------------------------------------------------- +-- Table `tncm_special_template` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tncm_special_template` ( + `id` SERIAL, + `name` TEXT, + `vendors` TEXT, + `models` TEXT, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- ---------------------------------------------------------------------- +-- Table `tncm_special_template_scripts` +-- ---------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tncm_special_template_scripts` ( + `id` SERIAL, + `id_special_template` BIGINT UNSIGNED NOT NULL, + `id_script` BIGINT UNSIGNED NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_special_template`) REFERENCES `tncm_special_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + -- ---------------------------------------------------------------------- -- Table `tncm_agent` -- ---------------------------------------------------------------------- @@ -4206,10 +4229,13 @@ CREATE TABLE IF NOT EXISTS `tncm_agent` ( `updated_at` BIGINT NOT NULL DEFAULT 0, `config_backup_id` BIGINT UNSIGNED DEFAULT NULL, `id_template` BIGINT UNSIGNED, + `id_special_template` BIGINT UNSIGNED, `execute_type` INT UNSIGNED NOT NULL DEFAULT 0, `execute` INT UNSIGNED NOT NULL DEFAULT 0, `cron_interval` VARCHAR(100) DEFAULT '', + `special_cron_interval` VARCHAR(100) DEFAULT '', `event_on_change` INT UNSIGNED DEFAULT null, + `special_event_on_change` INT UNSIGNED DEFAULT null, `last_error` TEXT, PRIMARY KEY (`id_agent`), FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, From 98332d728e9e84c80639e1f7cd989c7195ec1eac Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 31 Oct 2023 16:55:35 +0100 Subject: [PATCH 051/397] #8365 change name ncm agent data --- pandora_console/extras/mr/67.sql | 14 +++++++------- pandora_console/pandoradb.sql | 18 +++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 9da40c6829..b2b34e5ce4 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -3,7 +3,7 @@ START TRANSACTION; ALTER TABLE `tncm_queue` ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`; -CREATE TABLE IF NOT EXISTS `tncm_special_template` ( +CREATE TABLE IF NOT EXISTS `tncm_agent_data_template` ( `id` SERIAL, `name` TEXT, `vendors` TEXT, @@ -12,22 +12,22 @@ CREATE TABLE IF NOT EXISTS `tncm_special_template` ( ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; ALTER TABLE `tncm_agent` -ADD COLUMN `id_special_template` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `id_template`; +ADD COLUMN `id_agent_data_template` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `id_template`; -CREATE TABLE IF NOT EXISTS `tncm_special_template_scripts` ( +CREATE TABLE IF NOT EXISTS `tncm_agent_data_template_scripts` ( `id` SERIAL, - `id_special_template` BIGINT UNSIGNED NOT NULL, + `id_agent_data_template` BIGINT UNSIGNED NOT NULL, `id_script` BIGINT UNSIGNED NOT NULL, PRIMARY KEY (`id`), - FOREIGN KEY (`id_special_template`) REFERENCES `tncm_special_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_agent_data_template`) REFERENCES `tncm_agent_data_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; ALTER TABLE `tncm_agent` -ADD COLUMN `special_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_interval`; +ADD COLUMN `agent_data_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_interval`; ALTER TABLE `tncm_agent` -ADD COLUMN `special_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`; +ADD COLUMN `agent_data_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`; COMMIT; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 24020ffb0f..8b83b26011 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4192,9 +4192,9 @@ CREATE TABLE IF NOT EXISTS `tncm_template_scripts` ( ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ---------------------------------------------------------------------- --- Table `tncm_special_template` +-- Table `tncm_agent_data_template` -- ---------------------------------------------------------------------- -CREATE TABLE IF NOT EXISTS `tncm_special_template` ( +CREATE TABLE IF NOT EXISTS `tncm_agent_data_template` ( `id` SERIAL, `name` TEXT, `vendors` TEXT, @@ -4203,14 +4203,14 @@ CREATE TABLE IF NOT EXISTS `tncm_special_template` ( ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -- ---------------------------------------------------------------------- --- Table `tncm_special_template_scripts` +-- Table `tncm_agent_data_template_scripts` -- ---------------------------------------------------------------------- -CREATE TABLE IF NOT EXISTS `tncm_special_template_scripts` ( +CREATE TABLE IF NOT EXISTS `tncm_agent_data_template_scripts` ( `id` SERIAL, - `id_special_template` BIGINT UNSIGNED NOT NULL, + `id_agent_data_template` BIGINT UNSIGNED NOT NULL, `id_script` BIGINT UNSIGNED NOT NULL, PRIMARY KEY (`id`), - FOREIGN KEY (`id_special_template`) REFERENCES `tncm_special_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`id_agent_data_template`) REFERENCES `tncm_agent_data_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; @@ -4229,13 +4229,13 @@ CREATE TABLE IF NOT EXISTS `tncm_agent` ( `updated_at` BIGINT NOT NULL DEFAULT 0, `config_backup_id` BIGINT UNSIGNED DEFAULT NULL, `id_template` BIGINT UNSIGNED, - `id_special_template` BIGINT UNSIGNED, + `id_agent_data_template` BIGINT UNSIGNED, `execute_type` INT UNSIGNED NOT NULL DEFAULT 0, `execute` INT UNSIGNED NOT NULL DEFAULT 0, `cron_interval` VARCHAR(100) DEFAULT '', - `special_cron_interval` VARCHAR(100) DEFAULT '', + `agent_data_cron_interval` VARCHAR(100) DEFAULT '', `event_on_change` INT UNSIGNED DEFAULT null, - `special_event_on_change` INT UNSIGNED DEFAULT null, + `agent_data_event_on_change` INT UNSIGNED DEFAULT null, `last_error` TEXT, PRIMARY KEY (`id_agent`), FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, From f5e7ac8d4af9a6aa6ac39b44f1e1313748f8a225 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Tue, 31 Oct 2023 17:27:28 +0100 Subject: [PATCH 052/397] #8365 PDF report added for ncm backups --- .../include/functions_reporting_html.php | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 8fc6f3cf79..76f0920e34 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -7389,44 +7389,57 @@ function reporting_html_ncm_config($table, $item, $pdf=0) /** * HTML content for ncm backup report. * - * @param array $item Content generated by reporting_ncm_config. + * @param array $item Content generated by reporting_ncm_backups. * * @return string HTML code. */ function reporting_html_ncm_backups($table, $item, $pdf=0) { - ui_require_javascript_file('diff2html-ui.min'); ui_require_css_file('diff2html.min'); ui_require_css_file('highlight.min'); ui_require_css_file('highlight/vs.min'); + ui_require_javascript_file('diff2html-ui.min'); ui_require_javascript_file('highlight.min'); ui_require_javascript_file('highlightjs-line-numbers.min'); ui_require_javascript_file('languages/plaintext.min'); ui_require_javascript_file('functions_ncm', ENTERPRISE_DIR.'/include/javascript/'); - // Create table info. + // Create table diff. $table_ncm = new stdClass(); $table_ncm->width = '100%'; $table_ncm->class = 'info_table'; $table_ncm->styleTable = 'table-layout: fixed;'; - $table_ncm->rowstyle['title'] = 'text-align: center; font-weight: bolder'; + $table_ncm->headstyle[0] = 'width: 250px'; $table_ncm->head = []; $table_ncm->head[0] = __('Date'); $table_ncm->head[1] = __('Diff'); $table_ncm->data = []; - foreach ($item['data'] as $key => $row) { - $table_ncm->data[] = [ - $row['updated_at'], - $row['diff'], - ]; - } if ($pdf === 0) { + foreach ($item['data'] as $key => $row) { + $table_ncm->data[] = [ + $row['updated_at'], + $row['diff'], + ]; + } + return $table->data[] = html_print_table( $table_ncm, true ); + } else { + foreach ($item['data'] as $key => $row) { + $table_ncm->data[] = [ + $row['updated_at'], + ($row['diffstr'] === '') ? $row['diff'] : str_replace("\n", '
    ', $row['diffstr']), + ]; + } + + return html_print_table( + $table_ncm, + true + ); } } From 3031e7ddbddb52a6a7aea8381904bd4cf92825b5 Mon Sep 17 00:00:00 2001 From: "felix.suarez" Date: Wed, 1 Nov 2023 10:13:44 -0600 Subject: [PATCH 053/397] Add export Encrypt AES to tools --- pandora_server/lib/PandoraFMS/Tools.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index a0cc1c15ac..48a46ea740 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -185,6 +185,7 @@ our @EXPORT = qw( check_cron_element cron_check decrypt_AES + encrypt_AES ); # ID of the different servers From 1a021c96899c1cd6af25eb09421445d0baa490c1 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 2 Nov 2023 11:24:50 +0100 Subject: [PATCH 054/397] Added Rijndael encryption for python pandoraPlugintools and PandoraFMS::Tools --- .../extras/pandoraPlugintools/encryption.py | 89 +++++++++++++++++- pandora_server/lib/PandoraFMS/Tools.pm | 92 +++++++++---------- 2 files changed, 132 insertions(+), 49 deletions(-) diff --git a/pandora_server/extras/pandoraPlugintools/encryption.py b/pandora_server/extras/pandoraPlugintools/encryption.py index b1ec3c9315..576ae31ae3 100644 --- a/pandora_server/extras/pandoraPlugintools/encryption.py +++ b/pandora_server/extras/pandoraPlugintools/encryption.py @@ -39,7 +39,7 @@ def _print_debug( #### # Internal use only: Get AES cipher ######################################################################################### -def _get_cipher( +def _get_cipher_AES( password: str = _PASSWORD ) -> AES: ''' @@ -78,7 +78,7 @@ def encrypt_AES( Returns: str: The encrypted string in base64 encoding. ''' - cipher = _get_cipher(password) + cipher = _get_cipher_AES(password) try: msg_padded = pad(str_to_encrypt.encode(), AES.block_size, style='pkcs7') @@ -106,11 +106,94 @@ def decrypt_AES( Returns: str: The decrypted string. ''' - cipher = _get_cipher(password) + cipher = _get_cipher_AES(password) try: decrypted_str = unpad(cipher.decrypt(base64.b64decode(str_to_decrypt)), AES.block_size, style='pkcs7').decode().strip() except: decrypted_str = '' + return decrypted_str + +#### +# Internal use only: Get Rijndael cipher +######################################################################################### +def _get_cipher_Rijndael( + password: str = _PASSWORD + ) -> AES: + ''' + Internal use only: Get Rijndael cipher for encryption and decryption. + + Args: + password (str): The password used to derive the encryption key. + + Returns: + AES: An AES cipher instance for encryption and decryption. + ''' + key = b'' + msg = password.encode('utf-8') + hash_obj = hmac.new(key, msg, hashlib.sha256) + hash_result = hash_obj.digest() + hash_base64 = base64.b64encode(hash_result)[:16].decode() + + iv = b'0000000000000000' + + return AES.new(hash_base64.encode(), AES.MODE_CBC, iv) + +#### +# Return encrypted string +######################################################################################### +def encrypt_Rijndael( + str_to_encrypt: str = "", + password: str = _PASSWORD + ) -> str: + ''' + Encrypt a string using Rijndael encryption. + + Args: + str_to_encrypt (str): The string to be encrypted. + password (str): The password used to derive the encryption key. + + Returns: + str: The encrypted string in base64 encoding. + ''' + cipher = _get_cipher_Rijndael(password) + + block_size = 16 # Rijndael block size is 16 bytes + padding_length = block_size - (len(str_to_encrypt) % block_size) + padded_data = str_to_encrypt + chr(padding_length) * padding_length + + try: + b64str = base64.b64encode(cipher.encrypt(padded_data.encode())).decode() + except Exception as e: + b64str = '' + + return b64str + +#### +# Return decrypted string +######################################################################################### +def decrypt_Rijndael( + str_to_decrypt: str = "", + password: str = _PASSWORD + ) -> str: + ''' + Decrypt an encrypted string using Rijndael decryption. + + Args: + str_to_decrypt (str): The encrypted string to be decrypted. + password (str): The password used to derive the encryption key. + + Returns: + str: The decrypted string. + ''' + cipher = _get_cipher_Rijndael(password) + + try: + decrypted_data = cipher.decrypt(base64.b64decode(str_to_decrypt)).decode().strip() + padding_length = ord(decrypted_data[-1]) + decrypted_str = decrypted_data[:-padding_length] + except: + decrypted_str = '' + return decrypted_str \ No newline at end of file diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 48a46ea740..cb9ca7c86e 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -31,7 +31,7 @@ use LWP::UserAgent; use threads; use threads::shared; use MIME::Base64; -use Crypt::CBC; +use Crypt::Rijndael; use Digest::SHA qw(hmac_sha256_base64); use JSON; @@ -2989,62 +2989,62 @@ sub get_server_name { } ############################################################################### -# Encrypt with AES cypher +# Get cipher for Rijndael encrypt and decrypt ############################################################################### -sub encrypt_AES { - my ($str_to_encrypt, $password) = @_; - - if (!defined($password)) { - $password = "default_salt"; - } - my $cipher = _get_cipher($password); - - my $cipher_text = $cipher->encrypt($str_to_encrypt); - my $b64str = encode_base64($cipher_text, ''); - - return $b64str; -} - -############################################################################### -# Decrypt with AES cypher -############################################################################### -sub decrypt_AES { - my ($str_to_decrypt, $password) = @_; - - if (!defined($password)) { - $password = "default_salt"; - } - my $cipher = _get_cipher($password); - - my $cipher_text = decode_base64($str_to_decrypt); - my $decrypted_str = $cipher->decrypt($cipher_text); - - return $decrypted_str; -} - -############################################################################### -# Get cipher for AES encrypt and decrypt -############################################################################### -sub _get_cipher { +sub _get_cipher_Rijndael { my ($password) = @_; my $hash_base64 = substr(Digest::SHA::hmac_sha256_base64($password,''), 0, 16); my $iv = '0000000000000000'; - my $cipher = Crypt::CBC->new( - -key => $hash_base64, - -cipher => 'Cipher::AES', - -iv => $iv, - -header => 'none', - -padding => 'standard', # PKCS7 padding - -keysize => 16, - -literal_key => 1 - ); + my $cipher = Crypt::Rijndael->new($hash_base64, Crypt::Rijndael::MODE_CBC()); + $cipher->set_iv($iv); return $cipher; } +############################################################################### +# Encrypt with Rijndael cypher +############################################################################### +sub encrypt_Rijndael { + my ($str_to_encrypt, $password) = @_; + + if (!defined($password)) { + $password = "default_salt"; + } + my $cipher = _get_cipher_Rijndael($password); + + my $block_size = 16; # Rijndael block size is 16 bytes + my $padding_length = $block_size - (length($str_to_encrypt) % $block_size); + my $padded_data = $str_to_encrypt . chr($padding_length) x $padding_length; + + my $cipher_text = $cipher->encrypt($padded_data); + my $b64str = encode_base64($cipher_text, ''); + + return $b64str; +} + +############################################################################### +# Decrypt with Rijndael cypher +############################################################################### +sub decrypt_Rijndael { + my ($str_to_decrypt, $password) = @_; + + if (!defined($password)) { + $password = "default_salt"; + } + my $cipher = _get_cipher_Rijndael($password); + + my $cipher_text = decode_base64($str_to_decrypt); + my $decrypted_data = $cipher->decrypt($cipher_text); + + my $padding_length = ord(substr($decrypted_data, -1)); + my $decrypted_str = substr($decrypted_data, 0, -$padding_length); + + return $decrypted_str; +} + 1; __END__ From dc648167631d38a19f70c66b3617d33399b7d25f Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 2 Nov 2023 11:26:20 +0100 Subject: [PATCH 055/397] Exported encrypt and decrypt functions in Tools.pm --- pandora_server/lib/PandoraFMS/Tools.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index cb9ca7c86e..cb9b78e1b4 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -184,8 +184,8 @@ our @EXPORT = qw( check_cron_value check_cron_element cron_check - decrypt_AES - encrypt_AES + decrypt_Rijndael + encrypt_Rijndael ); # ID of the different servers From 9e4ba18f49287c18ee108856052281cfc86374f7 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 2 Nov 2023 12:52:31 +0100 Subject: [PATCH 056/397] Changed pandoraPlugintools encryption funcion and removed encryption functions from Tools.pm --- .../extras/pandoraPlugintools/encryption.py | 21 +++--- pandora_server/lib/PandoraFMS/Tools.pm | 64 +------------------ 2 files changed, 11 insertions(+), 74 deletions(-) diff --git a/pandora_server/extras/pandoraPlugintools/encryption.py b/pandora_server/extras/pandoraPlugintools/encryption.py index 576ae31ae3..6e456d2fcd 100644 --- a/pandora_server/extras/pandoraPlugintools/encryption.py +++ b/pandora_server/extras/pandoraPlugintools/encryption.py @@ -136,9 +136,7 @@ def _get_cipher_Rijndael( hash_result = hash_obj.digest() hash_base64 = base64.b64encode(hash_result)[:16].decode() - iv = b'0000000000000000' - - return AES.new(hash_base64.encode(), AES.MODE_CBC, iv) + return AES.new(hash_base64.encode(), AES.MODE_ECB) #### # Return encrypted string @@ -159,13 +157,13 @@ def encrypt_Rijndael( ''' cipher = _get_cipher_Rijndael(password) - block_size = 16 # Rijndael block size is 16 bytes - padding_length = block_size - (len(str_to_encrypt) % block_size) - padded_data = str_to_encrypt + chr(padding_length) * padding_length - try: - b64str = base64.b64encode(cipher.encrypt(padded_data.encode())).decode() - except Exception as e: + padded_data = str_to_encrypt.encode() + missing = 16 - (len(padded_data) % 16) + padded_data += bytes([0] * missing) if missing != 16 else b'' + + b64str = base64.b64encode(cipher.encrypt(padded_data)).decode() + except: b64str = '' return b64str @@ -190,9 +188,8 @@ def decrypt_Rijndael( cipher = _get_cipher_Rijndael(password) try: - decrypted_data = cipher.decrypt(base64.b64decode(str_to_decrypt)).decode().strip() - padding_length = ord(decrypted_data[-1]) - decrypted_str = decrypted_data[:-padding_length] + decrypted_data = cipher.decrypt(base64.b64decode(str_to_decrypt)) + decrypted_str = decrypted_data.rstrip(b'\x00').decode() except: decrypted_str = '' diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index cb9b78e1b4..61b68cd2ce 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -30,9 +30,6 @@ use Scalar::Util qw(looks_like_number); use LWP::UserAgent; use threads; use threads::shared; -use MIME::Base64; -use Crypt::Rijndael; -use Digest::SHA qw(hmac_sha256_base64); use JSON; use Encode qw/decode_utf8 encode_utf8/; @@ -184,8 +181,8 @@ our @EXPORT = qw( check_cron_value check_cron_element cron_check - decrypt_Rijndael - encrypt_Rijndael + decrypt_AES + encrypt_AES ); # ID of the different servers @@ -2988,63 +2985,6 @@ sub get_server_name { return "UNKNOWN"; } -############################################################################### -# Get cipher for Rijndael encrypt and decrypt -############################################################################### -sub _get_cipher_Rijndael { - my ($password) = @_; - - my $hash_base64 = substr(Digest::SHA::hmac_sha256_base64($password,''), 0, 16); - - my $iv = '0000000000000000'; - - my $cipher = Crypt::Rijndael->new($hash_base64, Crypt::Rijndael::MODE_CBC()); - $cipher->set_iv($iv); - - return $cipher; -} - -############################################################################### -# Encrypt with Rijndael cypher -############################################################################### -sub encrypt_Rijndael { - my ($str_to_encrypt, $password) = @_; - - if (!defined($password)) { - $password = "default_salt"; - } - my $cipher = _get_cipher_Rijndael($password); - - my $block_size = 16; # Rijndael block size is 16 bytes - my $padding_length = $block_size - (length($str_to_encrypt) % $block_size); - my $padded_data = $str_to_encrypt . chr($padding_length) x $padding_length; - - my $cipher_text = $cipher->encrypt($padded_data); - my $b64str = encode_base64($cipher_text, ''); - - return $b64str; -} - -############################################################################### -# Decrypt with Rijndael cypher -############################################################################### -sub decrypt_Rijndael { - my ($str_to_decrypt, $password) = @_; - - if (!defined($password)) { - $password = "default_salt"; - } - my $cipher = _get_cipher_Rijndael($password); - - my $cipher_text = decode_base64($str_to_decrypt); - my $decrypted_data = $cipher->decrypt($cipher_text); - - my $padding_length = ord(substr($decrypted_data, -1)); - my $decrypted_str = substr($decrypted_data, 0, -$padding_length); - - return $decrypted_str; -} - 1; __END__ From e6f505da5422b0ff60ed98857df396928bcebe6c Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 2 Nov 2023 12:53:38 +0100 Subject: [PATCH 057/397] Removed encryption functions from Tools.pm exporting --- pandora_server/lib/PandoraFMS/Tools.pm | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 61b68cd2ce..70d697dab4 100755 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -181,8 +181,6 @@ our @EXPORT = qw( check_cron_value check_cron_element cron_check - decrypt_AES - encrypt_AES ); # ID of the different servers From 513a0bc2965ac9c547dd1c3fc8427b2b666713bb Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 3 Nov 2023 14:25:44 +0100 Subject: [PATCH 058/397] #8365 Added csv report for device lists. Fixed overlay for modals --- .../reporting_builder.item_editor.php | 6 +- .../godmode/reporting/reporting_builder.php | 12 +++ .../include/functions_reporting.php | 2 +- .../include/functions_reporting_html.php | 93 +++++++++++++------ pandora_console/include/functions_reports.php | 12 +-- .../include/javascript/pandora_ui.js | 9 +- .../include/styles/js/jquery-ui_custom.css | 6 ++ 7 files changed, 96 insertions(+), 44 deletions(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index d13071c60a..f50b451683 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1036,7 +1036,8 @@ switch ($action) { break; case 'ncm': - $idAgent = $item['id_agent']; + $id_agent_ncm = $item['id_agent']; + $ncm_group = $item['id_group']; break; case 'ncm_backups': @@ -7835,7 +7836,8 @@ function chooseType() { break; case 'ncm': - $("#row_agent").show(); + $("#row_ncm_group").show(); + $("#row_ncm_agent").show(); break; case 'ncm_backups': diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 349bad535e..f155a89831 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2051,6 +2051,12 @@ switch ($action) { $good_format = true; break; + case 'ncm': + $values['id_agent'] = get_parameter('agent_ncm'); + $values['id_group'] = get_parameter('ncm_group'); + $good_format = true; + break; + default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter( @@ -2995,6 +3001,12 @@ switch ($action) { $good_format = true; break; + case 'ncm': + $values['id_agent'] = get_parameter('agent_ncm'); + $values['id_group'] = get_parameter('ncm_group'); + $good_format = true; + break; + default: $values['period'] = get_parameter('period'); $values['top_n'] = get_parameter( diff --git a/pandora_console/include/functions_reporting.php b/pandora_console/include/functions_reporting.php index 19c3f80b10..54f1284a2c 100755 --- a/pandora_console/include/functions_reporting.php +++ b/pandora_console/include/functions_reporting.php @@ -965,7 +965,7 @@ function reporting_make_reporting_data( break; case 'ncm': - $report['contents'][] = reporting_ncm_config( + $report['contents'][] = reporting_ncm_list( $report, $content, $pdf diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 76f0920e34..a74fcb4a47 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -477,7 +477,7 @@ function reporting_html_print_report($report, $mini=false, $report_info=1, $cust break; case 'ncm': - reporting_html_ncm_config($table, $item); + reporting_html_ncm_list($table, $item); break; case 'ncm_backups': @@ -7347,41 +7347,76 @@ function reporting_html_permissions($table, $item, $pdf=0) /** - * HTML content for ncm configuration diff report. + * HTML content for ncm devices list. * - * @param array $item Content generated by reporting_ncm_config. + * @param array $item Content generated by reporting_ncm_list. * * @return string HTML code. */ -function reporting_html_ncm_config($table, $item, $pdf=0) +function reporting_html_ncm_list($table, $item, $pdf=0) { - $key = uniqid(); + // Create table diff. + $table_ncm = new stdClass(); + $table_ncm->width = '100%'; + $table_ncm->class = 'info_table'; + $table_ncm->styleTable = 'table-layout: fixed;'; + $table_ncm->titleclass = 'title_table_pdf'; + + $table_ncm->align = []; + $table_ncm->align['name'] = 'left'; + $table_ncm->align['ip'] = 'left'; + $table_ncm->align['vendor'] = 'left'; + $table_ncm->align['model'] = 'left'; + $table_ncm->align['firmware'] = 'left'; + $table_ncm->align['last_backup_date'] = 'left'; + + $table_ncm->headstyle['name'] = 'text-align: left'; + $table_ncm->headstyle['ip'] = 'text-align: left'; + $table_ncm->headstyle['vendor'] = 'text-align: left'; + $table_ncm->headstyle['model'] = 'text-align: left'; + $table_ncm->headstyle['firmware'] = 'text-align: left'; + $table_ncm->headstyle['last_backup_date'] = 'text-align: left'; + + $table_ncm->head = []; + $table_ncm->head['name'] = __('Name'); + $table_ncm->head['ip'] = __('Ip'); + $table_ncm->head['vendor'] = __('Vendor'); + $table_ncm->head['model'] = __('Model'); + $table_ncm->head['firmware'] = __('Firmware'); + $table_ncm->head['last_backup_date'] = __('Last backup date'); + + $table_ncm->data = []; + foreach ($item['data'] as $key => $row) { + $title = $row['last_error']; + if (empty($title) === true) { + $title = null; + } + + $table_ncm->data[] = [ + $row['alias'], + $row['direccion'], + $row['vendor'], + $row['model'], + $row['firmware'], + $row['last_backup_date'], + ]; + } + if ($pdf === 0) { - ui_require_javascript_file('diff2html-ui.min'); - ui_require_css_file('diff2html.min'); - $script = "$(document).ready(function() { - const configuration = { - drawFileList: false, - collapsed: true, - matching: 'lines', - outputFormat: 'side-by-side', - }; - const diff2htmlUi = new Diff2HtmlUI( - document.getElementById('".$key."'), - atob('".base64_encode($item['data'])."'), - configuration - ); - diff2htmlUi.draw(); - });"; - $content = '
    '; - $content .= ''; - $table->data[1] = $content; - $table->colspan[1][0] = 2; + $table->colspan['data']['cell'] = 3; + $table->cellstyle['data']['cell'] = 'text-align: left;'; + $table->data['data']['cell'] = html_print_table( + $table_ncm, + true + ); } else { - $content = '
    '; - $content .= str_replace("\n", '
    ', $item['data']); - $content .= '
    '; - return $content; + $table_ncm->titleclass = 'title_table_pdf'; + $table_ncm->titlestyle = 'text-align:left;'; + + return html_print_table( + $table_ncm, + true + ); } } diff --git a/pandora_console/include/functions_reports.php b/pandora_console/include/functions_reports.php index 8956e3adc9..c3f6427ac2 100755 --- a/pandora_console/include/functions_reports.php +++ b/pandora_console/include/functions_reports.php @@ -963,14 +963,14 @@ function reports_get_report_types($template=false, $not_editor=false) ]; } - $types['ncm'] = [ - 'optgroup' => __('NCM'), - 'name' => __('Network configuration changes'), - ]; - $types['ncm_backups'] = [ 'optgroup' => __('NCM'), - 'name' => __('Network backups'), + 'name' => __('NCM configuration changes'), + ]; + + $types['ncm'] = [ + 'optgroup' => __('NCM'), + 'name' => __('NCM devices list'), ]; if (enterprise_installed() === true) { diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js index 45ca47e92b..80ddfd06f5 100644 --- a/pandora_console/include/javascript/pandora_ui.js +++ b/pandora_console/include/javascript/pandora_ui.js @@ -104,11 +104,8 @@ function load_modal(settings) { width = settings.onshow.width; } - if (settings.modal.overlay == undefined) { - settings.modal.overlay = { - opacity: 0.5, - background: "black" - }; + if (settings.modal.overlay === true) { + $("body").append(""); } if (settings.beforeClose == undefined) { @@ -496,7 +493,6 @@ function load_modal(settings) { settings.onshow.maxHeight != undefined ? settings.onshow.maxHeight : "auto", - overlay: settings.modal.overlay, position: { my: "top+20%", at: "top", @@ -518,6 +514,7 @@ function load_modal(settings) { if (settings.cleanup != undefined) { settings.cleanup(); } + $("#modal_overlay").removeClass("ui-widget-overlay"); }, beforeClose: settings.beforeClose() }); diff --git a/pandora_console/include/styles/js/jquery-ui_custom.css b/pandora_console/include/styles/js/jquery-ui_custom.css index 9c17d7fdab..905c3d5d67 100644 --- a/pandora_console/include/styles/js/jquery-ui_custom.css +++ b/pandora_console/include/styles/js/jquery-ui_custom.css @@ -371,3 +371,9 @@ input[type="submit"].ui-button-dialog { .ui_tpicker_time { margin-left: 10px !important; } + +.ui-widget-overlay { + background: #aaa !important; + opacity: 0.3 !important; + z-index: 1114; +} From 92ee718f918c4730e784a089f02b4417661ad5df Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 3 Nov 2023 17:48:15 +0100 Subject: [PATCH 059/397] Optimiized monitors view --- .../operation/agentes/status_monitor.php | 115 +++++++++--------- 1 file changed, 60 insertions(+), 55 deletions(-) diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 046fbc5222..5868b73707 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -27,6 +27,7 @@ */ // Begin. +use PandoraFMS\Enterprise\Metaconsole\Node; global $config; check_login(); @@ -188,7 +189,7 @@ $sql_from = ' FROM tagente_modulo INNER JOIN tagente ON tagente_modulo.id_agente = tagente.id_agente LEFT JOIN tagent_secondary_group tasg - ON tagente.id_agente = tasg.id_agent + ON tagente_modulo.id_agente = tasg.id_agent INNER JOIN tagente_estado ON tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo INNER JOIN tmodule @@ -436,12 +437,22 @@ if ($moduletype != '') { // Freestring selector. if ($ag_freestring != '') { - $sql_conditions .= ' AND (tagente.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' - OR tagente.alias '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' - OR tagente_modulo.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' - OR tagente_modulo.descripcion '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\')'; + $sql_conditions .= ' AND EXISTS ( + SELECT 1 + FROM tagente + WHERE tagente.id_agente = tagente_modulo.id_agente + AND ( + tagente.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' OR tagente.alias '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' + ) + AND ( + tagente_modulo.nombre '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\' + OR tagente_modulo.descripcion '.$not_condition.' LIKE \'%%'.$ag_freestring.'%%\') + )'; } + + + // Status selector. if ($status == AGENT_MODULE_STATUS_NORMAL) { // Normal. @@ -1348,15 +1359,10 @@ $sql = 'SELECT tagente.nombre AS agent_name, tagente_modulo.nombre AS module_name, tagente_modulo.history_data, - tagente_modulo.flag AS flag, tagente.id_grupo AS id_group, tagente.id_agente AS id_agent, tagente_modulo.id_tipo_modulo AS module_type, tagente_modulo.module_interval, - tagente_modulo.tcp_send, - tagente_modulo.ip_target, - tagente_modulo.snmp_community, - tagente_modulo.snmp_oid, tagente_estado.datos, tagente_estado.estado, tagente_estado.last_status_change, @@ -1370,13 +1376,12 @@ $sql = 'SELECT tagente_modulo.extended_info, tagente_modulo.critical_inverse, tagente_modulo.warning_inverse, - tagente_modulo.critical_instructions, - tagente_modulo.warning_instructions, - tagente_modulo.unknown_instructions, tagente_estado.utimestamp AS utimestamp'.$sql_from.$sql_conditions_all.' GROUP BY tagente_modulo.id_agente_modulo ORDER BY '.$order['field'].' '.$order['order'].' - LIMIT '.$offset.','.$limit_sql; + LIMIT '.$limit_sql.' OFFSET '.$offset; + + hd($sql); // We do not show the modules until the user searches with the filter. if ($autosearch) { @@ -1402,53 +1407,53 @@ if ($autosearch) { $result = []; $count_modules = 0; foreach ($servers as $server) { - // If connection was good then retrieve all data server. - if (metaconsole_connect($server) === NOERR) { - $connection = true; - } else { - $connection = false; - } + try { + $node = new Node((int) $server['id']); + $node->connect(); - $result_server = db_get_all_rows_sql($sql); + $result_server = db_get_all_rows_sql($sql); - if (empty($result_server) === false) { - // Create HASH login info. - $pwd = $server['auth_token']; - $auth_serialized = json_decode($pwd, true); + if (empty($result_server) === false) { + // Create HASH login info. + $pwd = $server['auth_token']; + $auth_serialized = json_decode($pwd, true); - if (is_array($auth_serialized)) { - $pwd = $auth_serialized['auth_token']; - $api_password = $auth_serialized['api_password']; - $console_user = $auth_serialized['console_user']; - $console_password = $auth_serialized['console_password']; + if (is_array($auth_serialized)) { + $pwd = $auth_serialized['auth_token']; + $api_password = $auth_serialized['api_password']; + $console_user = $auth_serialized['console_user']; + $console_password = $auth_serialized['console_password']; + } + + $user = $config['id_user']; + $user_rot13 = str_rot13($config['id_user']); + $hashdata = $user.$pwd; + $hashdata = md5($hashdata); + + foreach ($result_server as $result_element_key => $result_element_value) { + $result_server[$result_element_key]['server_id'] = $server['id']; + $result_server[$result_element_key]['server_name'] = $server['server_name']; + $result_server[$result_element_key]['server_url'] = $server['server_url'].'/'; + $result_server[$result_element_key]['hashdata'] = $hashdata; + $result_server[$result_element_key]['user'] = $config['id_user']; + $result_server[$result_element_key]['groups_in_server'] = agents_get_all_groups_agent( + $result_element_value['id_agent'], + $result_element_value['id_group'] + ); + + $count_modules++; + } + + $result = array_merge($result, $result_server); } - $user = $config['id_user']; - $user_rot13 = str_rot13($config['id_user']); - $hashdata = $user.$pwd; - $hashdata = md5($hashdata); - $url_hash = '&'.'loginhash=auto&'.'loginhash_data='.$hashdata.'&'.'loginhash_user='.$user_rot13; - - foreach ($result_server as $result_element_key => $result_element_value) { - $result_server[$result_element_key]['server_id'] = $server['id']; - $result_server[$result_element_key]['server_name'] = $server['server_name']; - $result_server[$result_element_key]['server_url'] = $server['server_url'].'/'; - $result_server[$result_element_key]['hashdata'] = $hashdata; - $result_server[$result_element_key]['user'] = $config['id_user']; - $result_server[$result_element_key]['groups_in_server'] = agents_get_all_groups_agent( - $result_element_value['id_agent'], - $result_element_value['id_group'] - ); - - $count_modules++; - } - - $result = array_merge($result, $result_server); + usort($result, arrayOutputSorting($sort, $fieldForSorting)); + } catch (\Exception $e) { + $node->disconnect(); + return; + } finally { + $node->disconnect(); } - - usort($result, arrayOutputSorting($sort, $fieldForSorting)); - - metaconsole_restore_db(); } if ($count_modules > $config['block_size']) { From 3506ba1b5a3e6ffe37beb33f0d72d6b65c0bb5bd Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Mon, 6 Nov 2023 15:06:16 +0100 Subject: [PATCH 060/397] Added default NCM templates --- pandora_console/extras/mr/67.sql | 1007 ++++++++++++++++++++++++++++ pandora_console/pandoradb_data.sql | 146 +++- 2 files changed, 1148 insertions(+), 5 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index b2b34e5ce4..2a604941e0 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -29,5 +29,1012 @@ ADD COLUMN `agent_data_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_i ALTER TABLE `tncm_agent` ADD COLUMN `agent_data_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`; +-- Add new vendor and model +SET @vendor_name = 'Cisco'; +SET @model_name = 'Cisco-Generic'; +SET @template_name = 'Cisco-Generic'; +SET @agent_data_template_name = 'Cisco-Generic'; +SET @script_test = 'enable\n expect:Password:\s* _enablepass_\n exit\n'; +SET @script_get_config = 'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show running-config\n exit\n'; +SET @script_set_config = 'enable\n expect:Password:\s* _enablepass_\n term length 0\n config terminal\n _applyconfigbackup_\n exit\n'; +SET @script_get_firmware = 'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show version | i IOS Software\n exit\n'; +SET @script_set_firmware = 'copy tftp flash\n expect:\]\? _TFTP_SERVER_IP_\n expect:\]\? _SOURCE_FILE_NAME_\n expect:\]\? _DESTINATION_FILE_NAME_\n show flash\n reload\n expect:confirm y\n config terminal\n boot system _DESTINATION_FILE_NAME_\n'; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); + +-- Add new vendor and model +SET @vendor_name = 'Juniper'; +SET @model_name = 'Juniper-Generic'; +SET @template_name = 'Juniper-Generic'; +SET @agent_data_template_name = 'Juniper-Generic'; +SET @script_test = 'expect:root@% cli\n exit\n'; +SET @script_get_config = 'expect:root@% cli\n expect:root> capture:show configuration\n capture:\n quit\n expect:root@% exit\n'; +SET @script_set_config = 'expect:root@% cli\n expect:root> configure\n load override terminal\n _applyconfigbackup_\n commit\n exit\n'; +SET @script_get_firmware = 'expect:root@% cli\n expect:root> capture:show version|match Junos:\n capture: \n quit\n expect:root@% exit\n'; +SET @script_set_firmware = 'expect:root@% cli\n expect:root> save software from tftp _TFTP_SERVER_IP_ _FIRMWARE_NAME_ to flash\n reset\n exit\n'; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); + +-- Add new vendor and model +SET @vendor_name = 'Palo Alto'; +SET @model_name = 'Palo Alto-Generic'; +SET @template_name = 'Palo Alto-Generic'; +SET @agent_data_template_name = 'Palo Alto-Generic'; +SET @script_test = 'sleep:1 exit\n'; +SET @script_get_config = 'set cli pager off \n capture:show config running\n exit\n'; +SET @script_set_config = 'set cli terminal width 500\n set cli scripting-mode on\n configure\n _applyconfigbackup_\n commit\n'; +SET @script_get_firmware = 'set cli pager off \n capture:show system info | match app-version:\n sleep:1 expect:app-version:\s* exit \n'; +SET @script_set_firmware = 'tftp import software from _TFTP_SERVER_IP_ file _FIRMWARE_NAME_\n request system software install version\n reboot\n exit\n'; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); + +-- Add new vendor and model +SET @vendor_name = 'A10'; +SET @model_name = 'A10-Generic'; +SET @template_name = 'A10-Generic'; +SET @agent_data_template_name = 'A10-Generic'; +SET @script_test = 'sleep:1 enable\n expect:Password:\s* _enablepass_\n'; +SET @script_get_config = 'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'; +SET @script_set_config = 'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n _applyconfigbackup_\n exit\n'; +SET @script_get_firmware = 'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'; +SET @script_set_firmware = 'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n expect:(config) restore _TFTP_SERVER_IP_/_FIRMWARE_NAME_\n expect:Password:\s* _enablepass_\n expect:skip port map yes\n expect: see the diff yes\n sleep:1 expect:Proceed with reboot yes\n expect:eof'; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); + +-- Add new vendor and model +SET @vendor_name = 'Alcatel-Lucent Enterprise'; +SET @model_name = 'Alcatel-Generic'; +SET @template_name = 'Alcatel-Generic'; +SET @agent_data_template_name = 'Alcatel-Generic'; +SET @script_test = 'enable\n expect:Password:\s* _enablepass_\n exit\n'; +SET @script_get_config = 'enable\n expect:Password:\s* _enablepass_\n capture:admin display-config\n logout\n'; +SET @script_set_config = ''; +SET @script_get_firmware = 'enable\n expect:Password:\s* _enablepass_\n capture:show version\n logout\n'; +SET @script_set_firmware = ''; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); + +-- Add new vendor and model +SET @vendor_name = 'Aruba'; +SET @model_name = 'Aruba-Generic'; +SET @template_name = 'Aruba-Generic'; +SET @agent_data_template_name = 'Aruba-Generic'; +SET @script_test = 'enable\n expect:Password:\s* _enablepass_\n exit\n'; +SET @script_get_config = 'enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'; +SET @script_set_config = 'configure terminal\n load replace /var/tmp/file.conf\n end\n write memory\n exit\n'; +SET @script_get_firmware = 'enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'; +SET @script_set_firmware = 'copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_.swi secondary\n boot system flash secondary\n copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_ primary\n boot system flash primary\n'; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); + +-- Add new vendor and model +SET @vendor_name = 'Mikrotik'; +SET @model_name = 'Mikrotik-Generic'; +SET @template_name = 'Mikrotik-Generic'; +SET @agent_data_template_name = 'Mikrotik-Generic'; +SET @script_test = 'sleep:1 exit\n\r'; +SET @script_get_config = 'sleep:1 capture:system resource print\n\r exit\n\r'; +SET @script_set_config = 'sleep:1 system backup load name=_nameBackup_ password=_passwordBackup_\n\r expect:Restore yes\n\r exit\n\r'; +SET @script_get_firmware = 'sleep:1 capture:/system package print\n\r exit\n\r'; +SET @script_set_firmware = 'sleep:1 /system routerboard upgrade\n\r expect:Do yes\n\r exit\n\r'; +SET @script_custom = ''; +SET @script_os_version = @script_get_firmware; + +-- Try to insert vendor +INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, ''); +-- Get vendor ID +SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name; + +-- Try to insert model +INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name); +-- Get model ID +SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name; + +-- Get template ID if exists +SET @id_template = NULL; +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; +-- Try to insert template +INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get template ID again if inserted +SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name; + +-- Get agent data template ID if exists +SET @id_agent_data_template = NULL; +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; +-- Try to insert agent data template +INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']')); +-- Get agent data template ID again if inserted +SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name; + +-- Get test script ID if exists +SET @id_script_test = NULL; +SET @script_type = 0; +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; +-- Try to insert test script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test); +-- Get test script ID again if inserted +SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test; + +-- Get get_config script ID if exists +SET @id_script_get_config = NULL; +SET @script_type = 1; +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; +-- Try to insert get_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config); +-- Get get_config script ID again if inserted +SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config; + +-- Get set_config script ID if exists +SET @id_script_set_config = NULL; +SET @script_type = 2; +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; +-- Try to insert set_config script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config); +-- Get set_config script ID again if inserted +SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config; + +-- Get get_firmware script ID if exists +SET @id_script_get_firmware = NULL; +SET @script_type = 3; +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; +-- Try to insert get_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware); +-- Get get_firmware script ID again if inserted +SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware; + +-- Get set_firmware script ID if exists +SET @id_script_set_firmware = NULL; +SET @script_type = 4; +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; +-- Try to insert set_firmware script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware); +-- Get set_firmware script ID again if inserted +SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware; + +-- Get custom script ID if exists +SET @id_script_custom = NULL; +SET @script_type = 5; +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; +-- Try to insert custom script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom); +-- Get custom script ID again if inserted +SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom; + +-- Get os_version script ID if exists +SET @id_script_os_version = NULL; +SET @script_type = 7; +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; +-- Try to insert os_version script +INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version); +-- Get os_version script ID again if inserted +SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version; + +-- Get template scripts ID if exists +SET @id_ts_test = NULL; +SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test); + +-- Get template scripts ID if exists +SET @id_ts_get_config = NULL; +SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config); + +-- Get template scripts ID if exists +SET @id_ts_set_config = NULL; +SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config); + +-- Get template scripts ID if exists +SET @id_ts_get_firmware = NULL; +SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware); + +-- Get template scripts ID if exists +SET @id_ts_set_firmware = NULL; +SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware); + +-- Get template scripts ID if exists +SET @id_ts_custom = NULL; +SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom; +-- Try to insert +INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom); + +-- Get template scripts ID if exists +SET @id_ts_os_version = NULL; +SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version; +-- Try to insert +INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version); COMMIT; diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 47365fcc6e..8229c96ee7 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -2512,11 +2512,32 @@ INSERT INTO `tncm_vendor` (`id`, `name`) VALUES (11, 'Netlink'), (12, 'Ascom'), (13, 'Synology Inc.'), - (14, 'Fujitsu Network Communications, Inc.'); + (14, 'Fujitsu Network Communications, Inc.'), + (15, 'Juniper'), + (16, 'Palo Alto'), + (17, 'A10'), + (18, 'Aruba'), + (19, 'Mikrotik'); -INSERT INTO `tncm_model` VALUES (1,1,'7200'); +INSERT INTO `tncm_model` VALUES + (1,1,'7200'), + (2,1,'Cisco-Generic'), + (3,15,'Juniper-Generic'), + (4,16,'Palo Alto-Generic'), + (5,17,'A10-Generic'), + (6,4,'Alcatel-Generic'), + (7,18,'Aruba-Generic'), + (8,19,'Mikrotik-Generic'); -INSERT INTO `tncm_template` VALUES (1,'cisco-base','[\"1\"]','[\"1\"]'); +INSERT INTO `tncm_template` VALUES + (1,'cisco-base','[\"1\"]','[\"1\"]'), + (2,'Cisco-Generic','[\"1\"]','[\"2\"]'), + (3,'Juniper-Generic','[\"15\"]','[\"3\"]'), + (4,'Palo Alto-Generic','[\"16\"]','[\"4\"]'), + (5,'A10-Generic','[\"17\"]','[\"5\"]'), + (6,'Alcatel-Generic','[\"4\"]','[\"6\"]'), + (7,'Aruba-Generic','[\"18\"]','[\"7\"]'), + (8,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); INSERT INTO `tncm_script` VALUES (1,0,'enable expect:Password:\s* _enablepass_ exit'), @@ -2524,9 +2545,124 @@ INSERT INTO `tncm_script` VALUES (3,2,'enable expect:Password:\s* _enablepass_ term length 0 config terminal _applyconfigbackup_ exit '), (4,3,'enable expect:Password:\s* _enablepass_ term length 0 capture:show version | i IOS Software exit '), (5,5,'enable expect:Password:\s* _enablepass_ term length 0 config term end end exit '), - (6,4,'copy tftp flash expect:\]\? _TFTP_SERVER_IP_ expect:\]\? _SOURCE_FILE_NAME_ expect:\]\? _DESTINATION_FILE_NAME_ show flash reload expect:confirm y config terminal boot system _DESTINATION_FILE_NAME_'); + (6,4,'copy tftp flash expect:\]\? _TFTP_SERVER_IP_ expect:\]\? _SOURCE_FILE_NAME_ expect:\]\? _DESTINATION_FILE_NAME_ show flash reload expect:confirm y config terminal boot system _DESTINATION_FILE_NAME_'), + (7,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), + (8,1,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show running-config\n exit\n'), + (9,2,'enable\n expect:Password:\s* _enablepass_\n term length 0\n config terminal\n _applyconfigbackup_\n exit\n'), + (10,3,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show version | i IOS Software\n exit\n'), + (11,4,'copy tftp flash\n expect:\]\? _TFTP_SERVER_IP_\n expect:\]\? _SOURCE_FILE_NAME_\n expect:\]\? _DESTINATION_FILE_NAME_\n show flash\n reload\n expect:confirm y\n config terminal\n boot system _DESTINATION_FILE_NAME_\n'), + (12,5,''), + (13,7,''), + (14,0,'expect:root@% cli\n exit\n'), + (15,1,'expect:root@% cli\n expect:root> capture:show configuration\n capture:\n quit\n expect:root@% exit\n'), + (16,2,'expect:root@% cli\n expect:root> configure\n load override terminal\n _applyconfigbackup_\n commit\n exit\n'), + (17,3,'expect:root@% cli\n expect:root> capture:show version|match Junos:\n capture: \n quit\n expect:root@% exit\n'), + (18,4,'expect:root@% cli\n expect:root> save software from tftp _TFTP_SERVER_IP_ _FIRMWARE_NAME_ to flash\n reset\n exit\n'), + (19,5,''), + (20,7,''), + (21,0,'sleep:1 exit\n'), + (22,1,'set cli pager off \n capture:show config running\n exit\n'), + (23,2,'set cli terminal width 500\n set cli scripting-mode on\n configure\n _applyconfigbackup_\n commit\n'), + (24,3,'set cli pager off \n capture:show system info | match app-version:\n sleep:1 expect:app-version:\s* exit \n'), + (25,4,'tftp import software from _TFTP_SERVER_IP_ file _FIRMWARE_NAME_\n request system software install version\n reboot\n exit\n'), + (26,5,''), + (27,7,''), + (28,0,'sleep:1 enable\n expect:Password:\s* _enablepass_\n'), + (29,1,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), + (30,2,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n _applyconfigbackup_\n exit\n'), + (31,3,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), + (32,4,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n expect:(config) restore _TFTP_SERVER_IP_/_FIRMWARE_NAME_\n expect:Password:\s* _enablepass_\n expect:skip port map yes\n expect: see the diff yes\n sleep:1 expect:Proceed with reboot yes\n expect:eof'), + (33,5,''), + (34,7,''), + (35,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), + (36,1,'enable\n expect:Password:\s* _enablepass_\n capture:admin display-config\n logout\n'), + (37,2,''), + (38,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n logout\n'), + (39,4,''), + (40,5,''), + (41,7,''), + (42,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), + (43,1,'enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), + (44,2,'configure terminal\n load replace /var/tmp/file.conf\n end\n write memory\n exit\n'), + (45,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), + (46,4,'copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_.swi secondary\n boot system flash secondary\n copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_ primary\n boot system flash primary\n'), + (47,5,''), + (48,7,''), + (49,0,'sleep:1 exit\n\r'), + (50,1,'sleep:1 capture:system resource print\n\r exit\n\r'), + (51,2,'sleep:1 system backup load name=_nameBackup_ password=_passwordBackup_\n\r expect:Restore yes\n\r exit\n\r'), + (52,3,'sleep:1 capture:/system package print\n\r exit\n\r'), + (53,4,'sleep:1 /system routerboard upgrade\n\r expect:Do yes\n\r exit\n\r'), + (54,5,''), + (55,7,''); -INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES (1,1),(1,2),(1,3),(1,4),(1,5),(1,6); +INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES + (1,1), + (1,2), + (1,3), + (1,4), + (1,5), + (1,6), + (2,7), + (2,8), + (2,9), + (2,10), + (2,11), + (2,12), + (3,14), + (3,15), + (3,16), + (3,17), + (3,18), + (3,19), + (4,21), + (4,22), + (4,23), + (4,24), + (4,25), + (4,26), + (5,28), + (5,29), + (5,30), + (5,31), + (5,32), + (5,33), + (6,35), + (6,36), + (6,37), + (6,38), + (6,39), + (6,40), + (7,42), + (7,43), + (7,44), + (7,45), + (7,46), + (7,47), + (8,49), + (8,50), + (8,51), + (8,52), + (8,53), + (8,54); + +INSERT INTO `tncm_agent_data_template` VALUES + (1,'Cisco-Generic','[\"1\"]','[\"2\"]'), + (2,'Juniper-Generic','[\"15\"]','[\"3\"]'), + (3,'Palo Alto-Generic','[\"16\"]','[\"4\"]'), + (4,'A10-Generic','[\"17\"]','[\"5\"]'), + (5,'Alcatel-Generic','[\"4\"]','[\"6\"]'), + (6,'Aruba-Generic','[\"18\"]','[\"7\"]'), + (7,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); + +INSERT INTO `tncm_agent_data_template_scripts`(`id_agent_data_template`, `id_script`) VALUES + (1,13), + (2,20), + (3,27), + (4,34), + (5,41), + (6,48), + (7,55), INSERT INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); From c266640f39c64c1b747ff6cb8f934b4c8972dadc Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Mon, 6 Nov 2023 15:07:43 +0100 Subject: [PATCH 061/397] Fixed syntax error in SQL --- pandora_console/pandoradb_data.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 8229c96ee7..7f3664620a 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -2662,7 +2662,7 @@ INSERT INTO `tncm_agent_data_template_scripts`(`id_agent_data_template`, `id_scr (4,34), (5,41), (6,48), - (7,55), + (7,55); INSERT INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); From 26ed76b82109a765bfda684fb0bd98932178bf0f Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Mon, 6 Nov 2023 16:41:37 +0100 Subject: [PATCH 062/397] Fixed SQL issue --- pandora_console/pandoradb_data.sql | 302 ++++++++++++++--------------- 1 file changed, 151 insertions(+), 151 deletions(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 7f3664620a..7e4bee1954 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -369,11 +369,11 @@ INSERT INTO `tusuario_perfil` (`id_up`, `id_usuario`, `id_perfil`, `id_grupo`, ` -- INSERT INTO `tperfil` VALUES - (1,'Operator (Read)',1,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0), - (2,'Operator (Write)',1,0,0,0,0,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,0,0), - (3,'Chief Operator',1,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,0), - (4,'Group coordinator',1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0), - (5,'Pandora Administrator',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); + (1,'Operator (Read)',1,0,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0), + (2,'Operator (Write)',1,0,0,0,0,0,0,1,1,0,1,1,0,0,1,1,0,1,1,0,0,0,0), + (3,'Chief Operator',1,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,1,1,0,0,0), + (4,'Group coordinator',1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0), + (5,'Pandora Administrator',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); -- -- Dumping data for table `tnews` @@ -388,7 +388,7 @@ INSERT INTO tmodule VALUES (5,'Prediction module'); INSERT INTO tmodule VALUES (6,'WMI module'); INSERT INTO tmodule VALUES (7, 'Web module'); INSERT INTO tmodule VALUES (8, 'Wux module'); -INSERT INTO tmodule VALUES (9, 'Wizard module'); +INSERT INTO tmodule VALUES (9, 'Wizard module'); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (1,'OS Total process','Total process in Operating System (UNIX MIB)',13,15,0,0,300,0,'','','public','HOST-RESOURCES-MIB::hrSystemProcesses.0 ',4,2,0,NULL,NULL,NULL,0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); @@ -732,11 +732,11 @@ INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `t INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (513,'MSDTC TransactionsPersec','Transactions performed per second.',22,1,0,0,300,0,'','','','select TransactionsPersec from Win32_PerfRawData_MSDTC_DistributedTransactionCoordinator',3,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (514,'c2900InfoPeakBuffersUsed','ftp://ftp.cisco.com/pub/mibs/oid/CISCO-C2900-MIB.oid',23,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.9.87.1.1.2.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (515,'c2900InfoTotalBufferDepth','ftp://ftp.cisco.com/pub/mibs/oid/CISCO-C2900-MIB.oid',23,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.9.87.1.1.3.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); -INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (516,'c2900BandwidthUsageCurrent ','ftp://ftp.cisco.com/pub/mibs/oid/CISCO-C2900-MIB.oid',23,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.9.87.1.5.1.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); +INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (516,'c2900BandwidthUsageCurrent ','ftp://ftp.cisco.com/pub/mibs/oid/CISCO-C2900-MIB.oid',23,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.9.87.1.5.1.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (517,'Latest Message ','Get the last message sent in Syslog',2,17,0,0,300,0,'','','public','1.3.6.1.4.1.9.9.41.1.2.3.1.5.12',1,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (518,'Latest Message date','',2,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.9.41.1.2.3.1.6.12',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); -INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (519,'CPU avgBusy1min ','',2,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.2.1.57.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); -INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (520,'CPU avgBusy5min ','',2,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.2.1.58.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); +INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (519,'CPU avgBusy1min ','',2,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.2.1.57.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); +INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (520,'CPU avgBusy5min ','',2,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.2.1.58.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (521,'Software Image running ','',2,17,0,0,1800,0,'','','public','1.3.6.1.4.1.9.2.1.73.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (522,'nvRAMUsed','',2,15,0,0,300,0,'','','public','1.3.6.1.4.1.9.3.6.8.0',2,2,0,'','','0',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (523,'Printers BytesPrintedPersec','Number of bytes per second printed on a print queue.',24,1,0,0,300,0,'','','','select BytesPrintedPersec from Win32_PerfRawData_Spooler_PrintQueue where NAME = '_total'',5,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); @@ -748,7 +748,7 @@ INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `t INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (529,'Printers OutofPaperErrors','Total number of out-of-paper errors in a print queue after the last restart.',24,1,0,0,300,0,'','','','select OutofPaperErrors from Win32_PerfRawData_Spooler_PrintQueue where NAME = '_total'',5,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (530,'Printers TotalJobsPrinted','Total number of jobs printed on a print queue after the last restart.',24,1,0,0,300,0,'','','','select TotalJobsPrinted from Win32_PerfRawData_Spooler_PrintQueue where NAME = '_total'',5,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (531,'Printers TotalPagesPrinted','Total number of pages printed through GDI on a print queue after the last restart.',24,1,0,0,300,0,'','','','select TotalPagesPrinted from Win32_PerfRawData_Spooler_PrintQueue where NAME = '_total'',5,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); -INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (532,'Printers Availability','Availability and status of the device\r\n\r\nValue Meaning\r\n\r\n10x1 Other\r\n\r\n20x2 Unknown\r\n\r\n30x3 Running or Full Power\r\n\r\n40x4 Warning\r\n\r\n50x5 In Test\r\n\r\n60x6 Not Applicable\r',24,3,0,0,300,0,'','','','select Availability from Win32_Printer',5,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); +INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (532,'Printers Availability','Availability and status of the device\r\n\r\nValue Meaning\r\n\r\n10x1 Other\r\n\r\n20x2 Unknown\r\n\r\n30x3 Running or Full Power\r\n\r\n40x4 Warning\r\n\r\n50x5 In Test\r\n\r\n60x6 Not Applicable\r',24,3,0,0,300,0,'','','','select Availability from Win32_Printer',5,6,0,'','','10',0,1,0.00,0.00,NULL,0.00,0.00,NULL,0,NULL,NULL,NULL,0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (533,'Serv_IISAdmin','IIS Administration Server service status.',26,2,0,0,300,0,'','','Running','Select State from Win32_Service WHERE name = 'IISAdmin'',3,6,0,'Administrador','6683','',0,1,0.00,0.00,'',0.00,0.00,'',0,'','','',0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (534,'Serv_MSSQL_server','Displays if MS SQL SERVER is running',27,2,0,0,0,0,'','','Running','select state from Win32_Service where name = "MSSQLSERVER"',7,6,0,'','','',0,1,0.00,0.00,'',0.00,0.00,'',0,'','','',0,0,0.0000000000000,'basic','','','','','',''); INSERT INTO `tnetwork_component` (`id_nc`, `name`, `description`, `id_group`, `type`, `max`, `min`, `module_interval`, `tcp_port`, `tcp_send`, `tcp_rcv`, `snmp_community`, `snmp_oid`, `id_module_group`, `id_modulo`, `id_plugin`, `plugin_user`, `plugin_pass`, `plugin_parameter`, `max_timeout`, `history_data`, `min_warning`, `max_warning`, `str_warning`, `min_critical`, `max_critical`, `str_critical`, `min_ff_event`, `custom_string_1`, `custom_string_2`, `custom_string_3`, `custom_integer_1`, `custom_integer_2`, `post_process`, `wizard_level`, `critical_instructions`, `warning_instructions`, `unknown_instructions`, `tags`, `disabled_types_event`, `module_macros`) VALUES (535,'SQLServer_DataFilesSizeKB','Sql database size in kb ',27,1,0,0,0,0,'','','','select state from Win32_Service where name = "MSSQLSERVER"',7,6,0,'','','',0,1,0.00,0.00,'',0.00,0.00,'',0,'','','',0,0,0.0000000000000,'basic','','','','','',''); @@ -1290,8 +1290,8 @@ INSERT INTO `tcontainer` SET `name` = 'Default graph container'; -- Dumping data for table `tlog_graph_models` -- INSERT INTO tlog_graph_models VALUES (1, 'Apache log model', - '^.*?\s+.*".*?\s(\/.*?)\?.*1.1"\s+(.*?)\s+(.*?)\s+', - 'pagina, html_err_code, _tiempo_', 1); + '^.*?\s+.*".*?\s(\/.*?)\?.*1.1"\s+(.*?)\s+(.*?)\s+', + 'pagina, html_err_code, _tiempo_', 1); INSERT INTO tlog_graph_models VALUES (2, 'Apache accesses per client and status', '(.*?)\ -.*1.1"\ (\d+)\ \d+', @@ -1347,13 +1347,13 @@ UPDATE `tnotification_source` SET `enabled`=1 WHERE `description` = 'System INSERT INTO `tpen` VALUES - (9,'cisco','Cisco System'), - (11,'hp','Hewlett Packard'), - (2021,'general_snmp','U.C. Davis, ECE Dept. Tom'), - (2636,'juniper','Juniper Networks'), - (3375,'f5','F5 Labs'), - (8072,'general_snmp','Net SNMP'), - (12356,'fortinet','Fortinet') + (9,'cisco','Cisco System'), + (11,'hp','Hewlett Packard'), + (2021,'general_snmp','U.C. Davis, ECE Dept. Tom'), + (2636,'juniper','Juniper Networks'), + (3375,'f5','F5 Labs'), + (8072,'general_snmp','Net SNMP'), + (12356,'fortinet','Fortinet') ; -- @@ -2500,7 +2500,7 @@ INSERT IGNORE INTO `tpen` VALUES (171,'dlink','D-Link Systems, Inc.'),(14988,'mi INSERT INTO `tncm_vendor` (`id`, `name`) VALUES (1,'Cisco'), - (2, 'D-Link Systems, Inc.'), + (2, 'D-Link Systems, Inc.'), (3, 'MikroTik'), (4, 'Alcatel-Lucent Enterprise'), (5, 'Ubiquiti Networks, Inc.'), @@ -2520,149 +2520,149 @@ INSERT INTO `tncm_vendor` (`id`, `name`) VALUES (19, 'Mikrotik'); INSERT INTO `tncm_model` VALUES - (1,1,'7200'), - (2,1,'Cisco-Generic'), - (3,15,'Juniper-Generic'), - (4,16,'Palo Alto-Generic'), - (5,17,'A10-Generic'), - (6,4,'Alcatel-Generic'), - (7,18,'Aruba-Generic'), - (8,19,'Mikrotik-Generic'); + (1,1,'7200'), + (2,1,'Cisco-Generic'), + (3,15,'Juniper-Generic'), + (4,16,'Palo Alto-Generic'), + (5,17,'A10-Generic'), + (6,4,'Alcatel-Generic'), + (7,18,'Aruba-Generic'), + (8,19,'Mikrotik-Generic'); INSERT INTO `tncm_template` VALUES - (1,'cisco-base','[\"1\"]','[\"1\"]'), - (2,'Cisco-Generic','[\"1\"]','[\"2\"]'), - (3,'Juniper-Generic','[\"15\"]','[\"3\"]'), - (4,'Palo Alto-Generic','[\"16\"]','[\"4\"]'), - (5,'A10-Generic','[\"17\"]','[\"5\"]'), - (6,'Alcatel-Generic','[\"4\"]','[\"6\"]'), - (7,'Aruba-Generic','[\"18\"]','[\"7\"]'), - (8,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); + (1,'cisco-base','[\"1\"]','[\"1\"]'), + (2,'Cisco-Generic','[\"1\"]','[\"2\"]'), + (3,'Juniper-Generic','[\"15\"]','[\"3\"]'), + (4,'Palo Alto-Generic','[\"16\"]','[\"4\"]'), + (5,'A10-Generic','[\"17\"]','[\"5\"]'), + (6,'Alcatel-Generic','[\"4\"]','[\"6\"]'), + (7,'Aruba-Generic','[\"18\"]','[\"7\"]'), + (8,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); INSERT INTO `tncm_script` VALUES (1,0,'enable expect:Password:\s* _enablepass_ exit'), (2,1,'enable expect:Password:\s* _enablepass_ term length 0 capture:show running-config exit '), - (3,2,'enable expect:Password:\s* _enablepass_ term length 0 config terminal _applyconfigbackup_ exit '), - (4,3,'enable expect:Password:\s* _enablepass_ term length 0 capture:show version | i IOS Software exit '), - (5,5,'enable expect:Password:\s* _enablepass_ term length 0 config term end end exit '), - (6,4,'copy tftp flash expect:\]\? _TFTP_SERVER_IP_ expect:\]\? _SOURCE_FILE_NAME_ expect:\]\? _DESTINATION_FILE_NAME_ show flash reload expect:confirm y config terminal boot system _DESTINATION_FILE_NAME_'), - (7,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), - (8,1,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show running-config\n exit\n'), - (9,2,'enable\n expect:Password:\s* _enablepass_\n term length 0\n config terminal\n _applyconfigbackup_\n exit\n'), - (10,3,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show version | i IOS Software\n exit\n'), - (11,4,'copy tftp flash\n expect:\]\? _TFTP_SERVER_IP_\n expect:\]\? _SOURCE_FILE_NAME_\n expect:\]\? _DESTINATION_FILE_NAME_\n show flash\n reload\n expect:confirm y\n config terminal\n boot system _DESTINATION_FILE_NAME_\n'), - (12,5,''), - (13,7,''), - (14,0,'expect:root@% cli\n exit\n'), - (15,1,'expect:root@% cli\n expect:root> capture:show configuration\n capture:\n quit\n expect:root@% exit\n'), - (16,2,'expect:root@% cli\n expect:root> configure\n load override terminal\n _applyconfigbackup_\n commit\n exit\n'), - (17,3,'expect:root@% cli\n expect:root> capture:show version|match Junos:\n capture: \n quit\n expect:root@% exit\n'), - (18,4,'expect:root@% cli\n expect:root> save software from tftp _TFTP_SERVER_IP_ _FIRMWARE_NAME_ to flash\n reset\n exit\n'), - (19,5,''), - (20,7,''), - (21,0,'sleep:1 exit\n'), - (22,1,'set cli pager off \n capture:show config running\n exit\n'), - (23,2,'set cli terminal width 500\n set cli scripting-mode on\n configure\n _applyconfigbackup_\n commit\n'), - (24,3,'set cli pager off \n capture:show system info | match app-version:\n sleep:1 expect:app-version:\s* exit \n'), - (25,4,'tftp import software from _TFTP_SERVER_IP_ file _FIRMWARE_NAME_\n request system software install version\n reboot\n exit\n'), - (26,5,''), - (27,7,''), - (28,0,'sleep:1 enable\n expect:Password:\s* _enablepass_\n'), - (29,1,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), - (30,2,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n _applyconfigbackup_\n exit\n'), - (31,3,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), - (32,4,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n expect:(config) restore _TFTP_SERVER_IP_/_FIRMWARE_NAME_\n expect:Password:\s* _enablepass_\n expect:skip port map yes\n expect: see the diff yes\n sleep:1 expect:Proceed with reboot yes\n expect:eof'), - (33,5,''), - (34,7,''), - (35,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), - (36,1,'enable\n expect:Password:\s* _enablepass_\n capture:admin display-config\n logout\n'), - (37,2,''), - (38,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n logout\n'), - (39,4,''), - (40,5,''), - (41,7,''), - (42,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), - (43,1,'enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), - (44,2,'configure terminal\n load replace /var/tmp/file.conf\n end\n write memory\n exit\n'), - (45,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), - (46,4,'copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_.swi secondary\n boot system flash secondary\n copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_ primary\n boot system flash primary\n'), - (47,5,''), - (48,7,''), - (49,0,'sleep:1 exit\n\r'), - (50,1,'sleep:1 capture:system resource print\n\r exit\n\r'), - (51,2,'sleep:1 system backup load name=_nameBackup_ password=_passwordBackup_\n\r expect:Restore yes\n\r exit\n\r'), - (52,3,'sleep:1 capture:/system package print\n\r exit\n\r'), - (53,4,'sleep:1 /system routerboard upgrade\n\r expect:Do yes\n\r exit\n\r'), - (54,5,''), - (55,7,''); + (3,2,'enable expect:Password:\s* _enablepass_ term length 0 config terminal _applyconfigbackup_ exit '), + (4,3,'enable expect:Password:\s* _enablepass_ term length 0 capture:show version | i IOS Software exit '), + (5,5,'enable expect:Password:\s* _enablepass_ term length 0 config term end end exit '), + (6,4,'copy tftp flash expect:\]\? _TFTP_SERVER_IP_ expect:\]\? _SOURCE_FILE_NAME_ expect:\]\? _DESTINATION_FILE_NAME_ show flash reload expect:confirm y config terminal boot system _DESTINATION_FILE_NAME_'), + (7,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), + (8,1,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show running-config\n exit\n'), + (9,2,'enable\n expect:Password:\s* _enablepass_\n term length 0\n config terminal\n _applyconfigbackup_\n exit\n'), + (10,3,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show version | i IOS Software\n exit\n'), + (11,4,'copy tftp flash\n expect:\]\? _TFTP_SERVER_IP_\n expect:\]\? _SOURCE_FILE_NAME_\n expect:\]\? _DESTINATION_FILE_NAME_\n show flash\n reload\n expect:confirm y\n config terminal\n boot system _DESTINATION_FILE_NAME_\n'), + (12,5,''), + (13,7,''), + (14,0,'expect:root@% cli\n exit\n'), + (15,1,'expect:root@% cli\n expect:root> capture:show configuration\n capture:\n quit\n expect:root@% exit\n'), + (16,2,'expect:root@% cli\n expect:root> configure\n load override terminal\n _applyconfigbackup_\n commit\n exit\n'), + (17,3,'expect:root@% cli\n expect:root> capture:show version|match Junos:\n capture: \n quit\n expect:root@% exit\n'), + (18,4,'expect:root@% cli\n expect:root> save software from tftp _TFTP_SERVER_IP_ _FIRMWARE_NAME_ to flash\n reset\n exit\n'), + (19,5,''), + (20,7,''), + (21,0,'sleep:1 exit\n'), + (22,1,'set cli pager off \n capture:show config running\n exit\n'), + (23,2,'set cli terminal width 500\n set cli scripting-mode on\n configure\n _applyconfigbackup_\n commit\n'), + (24,3,'set cli pager off \n capture:show system info | match app-version:\n sleep:1 expect:app-version:\s* exit \n'), + (25,4,'tftp import software from _TFTP_SERVER_IP_ file _FIRMWARE_NAME_\n request system software install version\n reboot\n exit\n'), + (26,5,''), + (27,7,''), + (28,0,'sleep:1 enable\n expect:Password:\s* _enablepass_\n'), + (29,1,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), + (30,2,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n _applyconfigbackup_\n exit\n'), + (31,3,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), + (32,4,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n expect:(config) restore _TFTP_SERVER_IP_/_FIRMWARE_NAME_\n expect:Password:\s* _enablepass_\n expect:skip port map yes\n expect: see the diff yes\n sleep:1 expect:Proceed with reboot yes\n expect:eof'), + (33,5,''), + (34,7,''), + (35,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), + (36,1,'enable\n expect:Password:\s* _enablepass_\n capture:admin display-config\n logout\n'), + (37,2,''), + (38,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n logout\n'), + (39,4,''), + (40,5,''), + (41,7,''), + (42,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), + (43,1,'enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), + (44,2,'configure terminal\n load replace /var/tmp/file.conf\n end\n write memory\n exit\n'), + (45,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), + (46,4,'copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_.swi secondary\n boot system flash secondary\n copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_ primary\n boot system flash primary\n'), + (47,5,''), + (48,7,''), + (49,0,'sleep:1 exit\n\r'), + (50,1,'sleep:1 capture:system resource print\n\r exit\n\r'), + (51,2,'sleep:1 system backup load name=_nameBackup_ password=_passwordBackup_\n\r expect:Restore yes\n\r exit\n\r'), + (52,3,'sleep:1 capture:/system package print\n\r exit\n\r'), + (53,4,'sleep:1 /system routerboard upgrade\n\r expect:Do yes\n\r exit\n\r'), + (54,5,''), + (55,7,''); INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES - (1,1), - (1,2), - (1,3), - (1,4), - (1,5), - (1,6), - (2,7), - (2,8), - (2,9), - (2,10), - (2,11), - (2,12), - (3,14), - (3,15), - (3,16), - (3,17), - (3,18), - (3,19), - (4,21), - (4,22), - (4,23), - (4,24), - (4,25), - (4,26), - (5,28), - (5,29), - (5,30), - (5,31), - (5,32), - (5,33), - (6,35), - (6,36), - (6,37), - (6,38), - (6,39), - (6,40), - (7,42), - (7,43), - (7,44), - (7,45), - (7,46), - (7,47), - (8,49), - (8,50), - (8,51), - (8,52), - (8,53), - (8,54); + (1,1), + (1,2), + (1,3), + (1,4), + (1,5), + (1,6), + (2,7), + (2,8), + (2,9), + (2,10), + (2,11), + (2,12), + (3,14), + (3,15), + (3,16), + (3,17), + (3,18), + (3,19), + (4,21), + (4,22), + (4,23), + (4,24), + (4,25), + (4,26), + (5,28), + (5,29), + (5,30), + (5,31), + (5,32), + (5,33), + (6,35), + (6,36), + (6,37), + (6,38), + (6,39), + (6,40), + (7,42), + (7,43), + (7,44), + (7,45), + (7,46), + (7,47), + (8,49), + (8,50), + (8,51), + (8,52), + (8,53), + (8,54); INSERT INTO `tncm_agent_data_template` VALUES - (1,'Cisco-Generic','[\"1\"]','[\"2\"]'), - (2,'Juniper-Generic','[\"15\"]','[\"3\"]'), - (3,'Palo Alto-Generic','[\"16\"]','[\"4\"]'), - (4,'A10-Generic','[\"17\"]','[\"5\"]'), - (5,'Alcatel-Generic','[\"4\"]','[\"6\"]'), - (6,'Aruba-Generic','[\"18\"]','[\"7\"]'), - (7,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); + (1,'Cisco-Generic','[\"1\"]','[\"2\"]'), + (2,'Juniper-Generic','[\"15\"]','[\"3\"]'), + (3,'Palo Alto-Generic','[\"16\"]','[\"4\"]'), + (4,'A10-Generic','[\"17\"]','[\"5\"]'), + (5,'Alcatel-Generic','[\"4\"]','[\"6\"]'), + (6,'Aruba-Generic','[\"18\"]','[\"7\"]'), + (7,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); INSERT INTO `tncm_agent_data_template_scripts`(`id_agent_data_template`, `id_script`) VALUES - (1,13), - (2,20), - (3,27), - (4,34), - (5,41), - (6,48), - (7,55); + (1,13), + (2,20), + (3,27), + (4,34), + (5,41), + (6,48), + (7,55); INSERT INTO `talert_calendar` VALUES (1, 'Default', 0, 'Default calendar'); From 86804398fe8b619aab7a488b6728be41993082f2 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Mon, 6 Nov 2023 16:50:54 +0100 Subject: [PATCH 063/397] Fixed SQL issue --- pandora_console/pandoradb_data.sql | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index 7e4bee1954..e7327e578b 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -2516,8 +2516,7 @@ INSERT INTO `tncm_vendor` (`id`, `name`) VALUES (15, 'Juniper'), (16, 'Palo Alto'), (17, 'A10'), - (18, 'Aruba'), - (19, 'Mikrotik'); + (18, 'Aruba'); INSERT INTO `tncm_model` VALUES (1,1,'7200'), @@ -2527,7 +2526,7 @@ INSERT INTO `tncm_model` VALUES (5,17,'A10-Generic'), (6,4,'Alcatel-Generic'), (7,18,'Aruba-Generic'), - (8,19,'Mikrotik-Generic'); + (8,3,'Mikrotik-Generic'); INSERT INTO `tncm_template` VALUES (1,'cisco-base','[\"1\"]','[\"1\"]'), @@ -2537,7 +2536,7 @@ INSERT INTO `tncm_template` VALUES (5,'A10-Generic','[\"17\"]','[\"5\"]'), (6,'Alcatel-Generic','[\"4\"]','[\"6\"]'), (7,'Aruba-Generic','[\"18\"]','[\"7\"]'), - (8,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); + (8,'Mikrotik-Generic','[\"3\"]','[\"8\"]'); INSERT INTO `tncm_script` VALUES (1,0,'enable expect:Password:\s* _enablepass_ exit'), @@ -2653,7 +2652,7 @@ INSERT INTO `tncm_agent_data_template` VALUES (4,'A10-Generic','[\"17\"]','[\"5\"]'), (5,'Alcatel-Generic','[\"4\"]','[\"6\"]'), (6,'Aruba-Generic','[\"18\"]','[\"7\"]'), - (7,'Mikrotik-Generic','[\"19\"]','[\"8\"]'); + (7,'Mikrotik-Generic','[\"3\"]','[\"8\"]'); INSERT INTO `tncm_agent_data_template_scripts`(`id_agent_data_template`, `id_script`) VALUES (1,13), From 194a3ca8c4668d73dceb3f2d472b8d6a56c3fb8e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 7 Nov 2023 12:36:05 +0100 Subject: [PATCH 064/397] #12381 fix dropdown select2 modal position --- .../godmode/agentes/module_manager_editor_common.php | 2 +- pandora_console/include/styles/pandora.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor_common.php b/pandora_console/godmode/agentes/module_manager_editor_common.php index ca74b7d171..de08a299de 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_common.php +++ b/pandora_console/godmode/agentes/module_manager_editor_common.php @@ -1387,7 +1387,7 @@ $table_advanced->data['made_enabled'][0] = html_print_checkbox_switch( 'made_enabled', 1, (bool) $made_enabled, - false, + true, false, '', false, diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 63179618b1..dd6723dfb2 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -12798,3 +12798,7 @@ tr.shown td.details-control { position: relative; top: -92px; } + +.tags_selected_container > span.select2 { + background-color: white !important; +} From 8700d1146117c2b303bd9ea3eb238ff6355bea6c Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Tue, 7 Nov 2023 13:13:45 +0100 Subject: [PATCH 065/397] Fixed agent data scripts on pandoradb_data.sql --- pandora_console/pandoradb_data.sql | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index e7327e578b..123940c22e 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -2551,49 +2551,49 @@ INSERT INTO `tncm_script` VALUES (10,3,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show version | i IOS Software\n exit\n'), (11,4,'copy tftp flash\n expect:\]\? _TFTP_SERVER_IP_\n expect:\]\? _SOURCE_FILE_NAME_\n expect:\]\? _DESTINATION_FILE_NAME_\n show flash\n reload\n expect:confirm y\n config terminal\n boot system _DESTINATION_FILE_NAME_\n'), (12,5,''), - (13,7,''), + (13,7,'enable\n expect:Password:\s* _enablepass_\n term length 0\n capture:show version | i IOS Software\n exit\n'), (14,0,'expect:root@% cli\n exit\n'), (15,1,'expect:root@% cli\n expect:root> capture:show configuration\n capture:\n quit\n expect:root@% exit\n'), (16,2,'expect:root@% cli\n expect:root> configure\n load override terminal\n _applyconfigbackup_\n commit\n exit\n'), (17,3,'expect:root@% cli\n expect:root> capture:show version|match Junos:\n capture: \n quit\n expect:root@% exit\n'), (18,4,'expect:root@% cli\n expect:root> save software from tftp _TFTP_SERVER_IP_ _FIRMWARE_NAME_ to flash\n reset\n exit\n'), (19,5,''), - (20,7,''), + (20,7,'expect:root@% cli\n expect:root> capture:show version|match Junos:\n capture: \n quit\n expect:root@% exit\n'), (21,0,'sleep:1 exit\n'), (22,1,'set cli pager off \n capture:show config running\n exit\n'), (23,2,'set cli terminal width 500\n set cli scripting-mode on\n configure\n _applyconfigbackup_\n commit\n'), (24,3,'set cli pager off \n capture:show system info | match app-version:\n sleep:1 expect:app-version:\s* exit \n'), (25,4,'tftp import software from _TFTP_SERVER_IP_ file _FIRMWARE_NAME_\n request system software install version\n reboot\n exit\n'), (26,5,''), - (27,7,''), + (27,7,'set cli pager off \n capture:show system info | match app-version:\n sleep:1 expect:app-version:\s* exit \n'), (28,0,'sleep:1 enable\n expect:Password:\s* _enablepass_\n'), (29,1,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), (30,2,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n _applyconfigbackup_\n exit\n'), (31,3,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), (32,4,'sleep:1 enable\n expect:Password:\s* _enablepass_\n configure\n expect:(config) restore _TFTP_SERVER_IP_/_FIRMWARE_NAME_\n expect:Password:\s* _enablepass_\n expect:skip port map yes\n expect: see the diff yes\n sleep:1 expect:Proceed with reboot yes\n expect:eof'), (33,5,''), - (34,7,''), + (34,7,'sleep:1 enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), (35,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), (36,1,'enable\n expect:Password:\s* _enablepass_\n capture:admin display-config\n logout\n'), (37,2,''), (38,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n logout\n'), (39,4,''), (40,5,''), - (41,7,''), + (41,7,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n logout\n'), (42,0,'enable\n expect:Password:\s* _enablepass_\n exit\n'), (43,1,'enable\n expect:Password:\s* _enablepass_\n capture:show running-config\n exit\n'), (44,2,'configure terminal\n load replace /var/tmp/file.conf\n end\n write memory\n exit\n'), (45,3,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), (46,4,'copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_.swi secondary\n boot system flash secondary\n copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_ primary\n boot system flash primary\n'), (47,5,''), - (48,7,''), + (48,7,'enable\n expect:Password:\s* _enablepass_\n capture:show version\n exit\n'), (49,0,'sleep:1 exit\n\r'), (50,1,'sleep:1 capture:system resource print\n\r exit\n\r'), (51,2,'sleep:1 system backup load name=_nameBackup_ password=_passwordBackup_\n\r expect:Restore yes\n\r exit\n\r'), (52,3,'sleep:1 capture:/system package print\n\r exit\n\r'), (53,4,'sleep:1 /system routerboard upgrade\n\r expect:Do yes\n\r exit\n\r'), (54,5,''), - (55,7,''); + (55,7,'sleep:1 capture:/system package print\n\r exit\n\r'); INSERT INTO `tncm_template_scripts`(`id_template`, `id_script`) VALUES (1,1), From 46a74c2e220efaad8e520bef24cf61bdb33c1378 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 7 Nov 2023 13:35:08 +0100 Subject: [PATCH 066/397] #12345 Fixed enable/disable --- .../godmode/agentes/configurar_agente.php | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/agentes/configurar_agente.php b/pandora_console/godmode/agentes/configurar_agente.php index 88d4b0e4ed..baf0a24524 100644 --- a/pandora_console/godmode/agentes/configurar_agente.php +++ b/pandora_console/godmode/agentes/configurar_agente.php @@ -2149,6 +2149,28 @@ if ($update_module || $create_module || ($module_in_policy && !$module_linked) ) { if ($success_action > 0) { + if (empty($old_configuration_data) === true + && empty($configuration_data) === true && $disabled === '0' + && ($enable_module || $disable_module) + ) { + $modulo_nombre = io_safe_output( + db_get_value( + 'nombre', + 'tagente_modulo', + 'id_agente_modulo', + (empty($disable_module) === false) ? $disable_module : $enable_module + ) + ); + + $old_configuration_data = config_agents_get_module_from_conf( + $id_agente, + $modulo_nombre + ); + $configuration_data = $old_configuration_data; + + $disabled = (empty($disable_module) === false) ? true : false; + } + enterprise_hook( 'config_agents_write_module_in_conf', [ @@ -2297,7 +2319,6 @@ if ($disable_module) { $modulo_nombre = io_safe_output($modulo_nombre['nombre']); if ($result === NOERR) { - enterprise_hook('config_agents_disable_module_conf', [$id_agente, $disable_module]); db_pandora_audit( AUDIT_LOG_MODULE_MANAGEMENT, 'Disable #'.$disable_module.' | '.$modulo_nombre.' | '.$agent['alias'] From 2d7895b39b7a4a258da9698bd133185b39220247 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Tue, 7 Nov 2023 15:22:22 +0100 Subject: [PATCH 067/397] #8365 Fixed ncm reports of html type --- .../godmode/reporting/reporting_builder.item_editor.php | 7 +++++++ pandora_console/include/functions_reporting_html.php | 7 ++++++- pandora_console/include/styles/pandora.css | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index f50b451683..c16cbd4a05 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -8146,10 +8146,17 @@ function filterNcmAgentChange() { }, success: function(data) { $("#agent_ncm").empty(); + var optionAny = $("") + .attr("value",0) + .html("Any"); + // Add any option. + $("#agent_ncm").append(optionAny); + data.map(item => { var option = $("") .attr("value", item.id_agent) .html(item.alias); + // Add agents options. $("#agent_ncm").append(option); }); }, diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index a74fcb4a47..d2d4f5850f 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -7437,6 +7437,7 @@ function reporting_html_ncm_backups($table, $item, $pdf=0) ui_require_javascript_file('highlight.min'); ui_require_javascript_file('highlightjs-line-numbers.min'); ui_require_javascript_file('languages/plaintext.min'); + ui_require_javascript_file('jquery', ENTERPRISE_DIR.'/include/javascript/'); ui_require_javascript_file('functions_ncm', ENTERPRISE_DIR.'/include/javascript/'); // Create table diff. @@ -7448,6 +7449,8 @@ function reporting_html_ncm_backups($table, $item, $pdf=0) $table_ncm->head = []; $table_ncm->head[0] = __('Date'); $table_ncm->head[1] = __('Diff'); + $table_ncm->caption = $item['caption']; + $table_ncm->id = 'ncm_backups'; $table_ncm->data = []; @@ -7459,7 +7462,9 @@ function reporting_html_ncm_backups($table, $item, $pdf=0) ]; } - return $table->data[] = html_print_table( + $table->colspan['ncm_backups']['cell'] = 3; + $table->cellstyle['ncm_backups']['cell'] = 'text-align: left;'; + $table->data['ncm_backups']['cell'] = html_print_table( $table_ncm, true ); diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 63179618b1..7e9669bc21 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -12798,3 +12798,7 @@ tr.shown td.details-control { position: relative; top: -92px; } + +#ncm_backups > caption > h4 { + color: black; +} From 98bc73a83ab0b6308703b90132187392a9a8e2ae Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Wed, 8 Nov 2023 14:40:47 +0100 Subject: [PATCH 068/397] #8365 Fix ncm report for multiple agents --- pandora_console/extras/mr/67.sql | 3 + .../reporting_builder.item_editor.php | 6 +- .../godmode/reporting/reporting_builder.php | 11 ++- .../include/functions_reporting_html.php | 71 ++++++++++--------- pandora_console/pandoradb.sql | 1 + 5 files changed, 54 insertions(+), 38 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 2a604941e0..2913cd8248 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -29,6 +29,9 @@ ADD COLUMN `agent_data_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_i ALTER TABLE `tncm_agent` ADD COLUMN `agent_data_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`; +ALTER TABLE `treport_content` +ADD COLUMN `ncm_agents` MEDIUMTEXT NULL AFTER `status_of_check`; + -- Add new vendor and model SET @vendor_name = 'Cisco'; SET @model_name = 'Cisco-Generic'; diff --git a/pandora_console/godmode/reporting/reporting_builder.item_editor.php b/pandora_console/godmode/reporting/reporting_builder.item_editor.php index c16cbd4a05..49c7ac7f80 100755 --- a/pandora_console/godmode/reporting/reporting_builder.item_editor.php +++ b/pandora_console/godmode/reporting/reporting_builder.item_editor.php @@ -1036,12 +1036,12 @@ switch ($action) { break; case 'ncm': - $id_agent_ncm = $item['id_agent']; + $id_agent_ncm = json_decode($item['ncm_agents']); $ncm_group = $item['id_group']; break; case 'ncm_backups': - $id_agent_ncm = $item['id_agent']; + $id_agent_ncm = json_decode($item['ncm_agents']); $ncm_group = $item['id_group']; break; @@ -1973,7 +1973,7 @@ if (is_metaconsole() === true) { $all_agents = agents_get_agents_selected($ncm_group); html_print_select( $all_agents, - 'agent_ncm', + 'agent_ncm[]', $id_agent_ncm, '', __('Any'), diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index f155a89831..e449b766ff 100755 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -2046,13 +2046,15 @@ switch ($action) { break; case 'ncm_backups': - $values['id_agent'] = get_parameter('agent_ncm'); + $agents_ncm = get_parameter('agent_ncm'); + $values['ncm_agents'] = json_encode($agents_ncm); $values['id_group'] = get_parameter('ncm_group'); $good_format = true; break; case 'ncm': - $values['id_agent'] = get_parameter('agent_ncm'); + $agents_ncm = get_parameter('agent_ncm'); + $values['ncm_agents'] = json_encode($agents_ncm); $values['id_group'] = get_parameter('ncm_group'); $good_format = true; break; @@ -2996,12 +2998,15 @@ switch ($action) { break; case 'ncm_backups': - $values['id_agent'] = get_parameter('agent_ncm'); + $agents_ncm = get_parameter('agent_ncm'); + $values['ncm_agents'] = json_encode($agents_ncm); $values['id_group'] = get_parameter('ncm_group'); $good_format = true; break; case 'ncm': + $agents_ncm = get_parameter('agent_ncm'); + $values['ncm_agents'] = json_encode($agents_ncm); $values['id_agent'] = get_parameter('agent_ncm'); $values['id_group'] = get_parameter('ncm_group'); $good_format = true; diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index d2d4f5850f..0fbae441ec 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -7441,45 +7441,52 @@ function reporting_html_ncm_backups($table, $item, $pdf=0) ui_require_javascript_file('functions_ncm', ENTERPRISE_DIR.'/include/javascript/'); // Create table diff. - $table_ncm = new stdClass(); - $table_ncm->width = '100%'; - $table_ncm->class = 'info_table'; - $table_ncm->styleTable = 'table-layout: fixed;'; - $table_ncm->headstyle[0] = 'width: 250px'; - $table_ncm->head = []; - $table_ncm->head[0] = __('Date'); - $table_ncm->head[1] = __('Diff'); - $table_ncm->caption = $item['caption']; - $table_ncm->id = 'ncm_backups'; - - $table_ncm->data = []; - - if ($pdf === 0) { - foreach ($item['data'] as $key => $row) { - $table_ncm->data[] = [ - $row['updated_at'], - $row['diff'], - ]; + foreach ($item['data'] as $ncm_agent_key => $ncm_agent) { + $table_ncm = new stdClass(); + if ($pdf === 1) { + $table_ncm->width = '100%'; } - $table->colspan['ncm_backups']['cell'] = 3; - $table->cellstyle['ncm_backups']['cell'] = 'text-align: left;'; - $table->data['ncm_backups']['cell'] = html_print_table( - $table_ncm, - true - ); - } else { - foreach ($item['data'] as $key => $row) { - $table_ncm->data[] = [ - $row['updated_at'], - ($row['diffstr'] === '') ? $row['diff'] : str_replace("\n", '
    ', $row['diffstr']), - ]; + $table_ncm->class = 'info_table'; + $table_ncm->styleTable = 'table-layout: fixed;'; + $table_ncm->headstyle[0] = 'width: 250px'; + $table_ncm->head = []; + $table_ncm->head[0] = __('Date'); + $table_ncm->head[1] = __('Diff'); + $table_ncm->id = 'ncm_backups'; + $table_ncm->name = 'ncm_backups'; + $table_ncm->title = $ncm_agent['caption']; + $row = []; + foreach ($ncm_agent['data'] as $ncm_agent_data) { + if ($pdf === 1) { + $row[] = [ + $ncm_agent_data['updated_at'], + ($ncm_agent_data['diffstr'] === '') ? $ncm_agent_data['diff'] : str_replace("\n", '
    ', $ncm_agent_data['diffstr']), + ]; + } else { + $row[] = [ + $ncm_agent_data['updated_at'], + $ncm_agent_data['diff'], + ]; + } + + $table_ncm->data = $row; } - return html_print_table( + $table->colspan[$ncm_agent_key]['cell'] = 3; + $table->cellstyle[$ncm_agent_key]['cell'] = 'text-align: left;'; + $table->data[$ncm_agent_key]['cell'] = html_print_table( $table_ncm, true ); } + if ($pdf === 1) { + $table->width = '100%'; + return html_print_table( + $table, + true + ); + } + } diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 8b83b26011..334afe02b2 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -1645,6 +1645,7 @@ CREATE TABLE IF NOT EXISTS `treport_content` ( `cat_security_hardening` INT NOT NULL DEFAULT 0, `ignore_skipped` INT NOT NULL DEFAULT 0, `status_of_check` TINYTEXT, + `ncm_agents` MEDIUMTEXT, PRIMARY KEY(`id_rc`), FOREIGN KEY (`id_report`) REFERENCES treport(`id_report`) ON UPDATE CASCADE ON DELETE CASCADE From f773230ebf3851f65c85f339017650d817c5f8fc Mon Sep 17 00:00:00 2001 From: "felix.suarez" Date: Thu, 9 Nov 2023 16:18:06 -0500 Subject: [PATCH 069/397] Modify pandora_cps_enabled function --- pandora_server/lib/PandoraFMS/Core.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index afd3e8e865..797268f032 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -5778,9 +5778,9 @@ sub pandora_inhibit_alerts { sub pandora_cps_enabled($$) { my ($agent, $module) = @_; - return 1 if ($agent->{'cps'} > 0); + return 1 if ($agent->{'cps'} >= 0); - return 1 if ($module->{'cps'} > 0); + return 1 if ($module->{'cps'} >= 0); return 0; } From 1fcc263046aa69d254b81f3707c91d95f866734c Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 10 Nov 2023 11:24:34 +0100 Subject: [PATCH 070/397] implemented demo data load --- pandora_console/godmode/setup/demo.php | 221 +++++++++++++++--- .../include/ajax/demo_data.ajax.php | 158 ++++++++++--- 2 files changed, 315 insertions(+), 64 deletions(-) diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index 9af7e2721e..d0d65c748f 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -34,6 +34,14 @@ if (! check_acl($config['id_user'], 0, 'PM') && ! is_user_admin($config['id_user return; } +config_update_value('demo_data_load_progress', 0); + +html_print_input_hidden('demo_items_count', 0); + +$submit_value = (string) get_parameter('update_button', ''); +$demo_items_count = db_get_value('count(*)', 'tdemo_data'); +$demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + // Basic/Advanced mode. $mode = (string) get_parameter('mode', 'basic'); @@ -85,7 +93,7 @@ ui_print_standard_header( ); $table_aux = new stdClass(); -$table_aux->id = 'table-password-policy'; +$table_aux->id = 'table-demo'; $table_aux->class = 'filter-table-adv'; $table_aux->width = '100%'; $table_aux->data = []; @@ -124,20 +132,34 @@ $table_aux->data['row1'][] = html_print_label_input_block( 'agents_num', $config['gis_default_icon'], '', - '', - '', + '30', + 30, true, false, true, 'w80px' - ).'  '.__('(%d demo agents currently in the system)').'', + ).'  '.__('(%d demo agents currently in the system)', $demo_agents_count).'', ], true ) ); +$table_aux->data['row2'][] = progress_bar( + 0, + 100, + 20, + '', + 0, + false, + ((int) 0 !== -1) ? false : '#f3b200', + [ + 'class' => 'progress_bar', + 'id' => 'progress_bar', + ] +).html_print_input_hidden('js_timer_'.$operation['id'], 0, true); + if ($mode === 'advanced') { - $table_aux->data['row2'][] = html_print_label_input_block( + $table_aux->data['row3'][] = html_print_label_input_block( __('Generate historical data for all agents (15 days by default)'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -147,7 +169,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row3'][] = html_print_label_input_block( + $table_aux->data['row4'][] = html_print_label_input_block( __('Create services, visual console, dashboard, reports, clusters and network maps'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -157,7 +179,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row4'][] = html_print_label_input_block( + $table_aux->data['row5'][] = html_print_label_input_block( __('Generate custom/combined graphs'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -167,7 +189,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row5'][] = html_print_label_input_block( + $table_aux->data['row6'][] = html_print_label_input_block( __('Generate netflow demo data'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -177,7 +199,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row6'][] = html_print_label_input_block( + $table_aux->data['row7'][] = html_print_label_input_block( __('Generate logs for each agent'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -187,7 +209,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row7'][] = html_print_label_input_block( + $table_aux->data['row8'][] = html_print_label_input_block( __('Generate inventory data for each agent'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -197,7 +219,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row8'][] = html_print_label_input_block( + $table_aux->data['row9'][] = html_print_label_input_block( __('Generate SNMP traps for each agent'), html_print_checkbox_switch( 'enable_pass_policy_admin', @@ -207,7 +229,7 @@ if ($mode === 'advanced') { ) ); - $table_aux->data['row9'][] = html_print_label_input_block( + $table_aux->data['row10'][] = html_print_label_input_block( __('Days of historical data to insert in the agent data'), html_print_input_text( 'days_hist_data', @@ -250,18 +272,21 @@ $actionButtons[] = html_print_submit_button( __('Create demo data'), 'update_button', false, - [ 'icon' => 'update' ], + [ + 'icon' => 'update', + 'fixed_id' => 'btn-create-demo-data', + ], true ); -$actionButtons[] = html_print_button( +$actionButtons[] = html_print_submit_button( __('Delete demo data'), - 'delete_session_users', + 'update_button', false, - '', [ - 'icon' => 'delete', - 'mode' => 'secondary', + 'icon' => 'delete', + 'mode' => 'secondary', + 'fixed_id' => 'btn-delete-demo-data', ], true ); @@ -271,29 +296,161 @@ html_print_action_buttons( ); echo ''; - ?> \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 1016903e57..c2d163054a 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -20,17 +20,23 @@ * ============================================================================ */ +global $config; + +// Login check. +check_login(); + include $config['homedir'].'/include/functions_inventory.php'; $action = (string) get_parameter('action', null); if ($action === 'create_demo_data') { + config_update_value('demo_data_load_progress', 0); $agents_num = (int) get_parameter('agents_num', 0); - hd("qqqq ".$agents_num, true); + if ($agents_num > 0) { // Read all ini files. $parsed_ini[] = parse_ini_file($config['homedir'].'/extras/demodata/agents/linux.ini', true, INI_SCANNER_TYPED); -hd($parsed_ini, true); + $ag_groups_num = ($agents_num / 10); // Create new group per group of ten agents that are to be created. @@ -88,6 +94,7 @@ hd($parsed_ini, true); $agent_last_id = (int) explode(' ', $agent_alias)[1]; } + // Traverse ini files and create items. foreach ($parsed_ini as $ini_so_data) { $agent_data = $ini_so_data['agent_data']; $modules_data = $ini_so_data['modules']; @@ -109,6 +116,21 @@ hd($parsed_ini, true); if ($id_os === false) { continue; } + + if ($id_os > 0) { + // Register created OS in tdemo_data. + $values = [ + 'item_id' => $id_os, + 'table_name' => 'tconfig_os', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback OS creation if could not be registered in tdemo_data. + db_process_sql_delete('tconfig_os', ['id_os' => $id_os]); + continue; + } + } } // Define agents to be created per group of 10. @@ -122,7 +144,7 @@ hd($parsed_ini, true); $agents_to_create = ($ag_groups_num * $agents_per_os[$os_name]); - for ($i=0; $i < $agents_to_create; $i++) { + for ($i = 0; $i < $agents_to_create; $i++) { $next_ip_address = calculateNextHostAddress($address_network); $os_version = current($os_versions); @@ -163,6 +185,15 @@ hd($parsed_ini, true); $agents_created_count++; + $percentage_inc = ((($agents_created_count * 100) / $agents_to_create) / count($parsed_ini)); + $current_progress_val = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_progress']); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + if (($agents_created_count % 10) === 0) { $group_idx++; } @@ -249,6 +280,7 @@ hd($parsed_ini, true); $current_date_time = $date_time->format('Y-m-d H:i:s'); while (1) { + // Insert in tmodule_inventory. $modules_array = []; foreach ($inventory as $key => $value) { $modules_array[$key] = ($value[$module_access_idx] ?? null); @@ -266,7 +298,6 @@ hd($parsed_ini, true); 'id_os' => 1, ]; - // STEP 1: tmodule_inventory. $created_inventory_mod_id = inventory_create_inventory_module($values); if ($created_inventory_mod_id > 0) { @@ -286,18 +317,7 @@ hd($parsed_ini, true); $module_access_idx++; - // STEP 2: tagent_module_inventory. - $values = [ - 'id_agente' => $created_agent_id, - 'id_module_inventory' => $created_inventory_mod_id, - 'interval' => 300, - 'utimestamp' => time(), - 'timestamp' => $current_date_time, - ]; - - - - // STEP 3: Create inventory values (tagente_datos_inventory). + // Insert in tagent_module_inventory and tagente_datos_inventory. $field_idx = 1; $values_array = explode(';', $modules_array['values']); @@ -309,9 +329,6 @@ hd($parsed_ini, true); ARRAY_FILTER_USE_KEY ); - hd("INV VALUES", true); - hd($selected_inventory_values, true); - $data_lines = []; while (1) { $line_values = array_column($selected_inventory_values, $field_idx); @@ -326,19 +343,40 @@ hd($parsed_ini, true); $data_str = implode('\n', $data_lines); - hd("DATA STR",true); - hd($data_str, true); + $values = [ + 'id_agente' => $created_agent_id, + 'id_module_inventory' => $created_inventory_mod_id, + 'interval' => 300, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, + 'data' => $data_str, + ]; + + $created_module_inventory_id = db_process_sql_insert('tagent_module_inventory', $values); + + if ($created_module_inventory_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_module_inventory_id, + 'table_name' => 'tagent_module_inventory', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback inventory module if could not be registered in tdemo_data. + db_process_sql_delete('tagent_module_inventory', ['id_agent_module_inventory' => $created_module_inventory_id]); + continue; + } + } $inventory_data_values = [ - 'data' => $data_str, - 'utimestamp' => time(), - 'timestamp' => $current_date_time, + 'id_agent_module_inventory' => $created_module_inventory_id, + 'data' => $data_str, + 'utimestamp' => time(), + 'timestamp' => $current_date_time, ]; $created_inventory_data = db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); - hd("CID",true); - hd($inventory_data_values, true); - hd($created_inventory_data, true); if ($created_inventory_data > 0) { // Register created inventory data element in tdemo_data. @@ -363,9 +401,65 @@ hd($parsed_ini, true); } } + $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + echo json_encode(['agents_count' => $demo_agents_count]); + return; } +if ($action === 'cleanup_demo_data') { + config_update_value('demo_data_load_progress', 0); + + $demo_items = db_get_all_rows_in_table('tdemo_data'); + + foreach ($demo_items as $item) { + $table_id_field_dict = [ + 'tconfig_os' => 'id_os', + 'tagente' => 'id_agente', + 'tgrupo' => 'id_grupo', + 'tagente_modulo' => 'id_agente_modulo', + 'tmodule_inventory' => 'id_module_inventory', + 'tagent_module_inventory' => 'id_agent_module_inventory', + 'tagente_datos_inventory' => 'id_agent_module_inventory', + ]; + + $table_id_field = $table_id_field_dict[$item['table_name']]; + + $result = db_process_sql_delete( + $item['table_name'], + [$table_id_field => $item['item_id']] + ); + + if ($result !== false) { + db_process_sql_delete( + 'tdemo_data', + ['item_id' => $item['item_id']] + ); + } + } + + echo 1; +} + +if ($action === 'get_progress_bar') { + $operation = (string) get_parameter('operation'); + + if ($operation === 'create') { + $current_progress_val = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_progress']); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + } else if ($operation === 'cleanup') { + $demo_items_to_cleanup = (int) get_parameter('demo_items_to_cleanup'); + $count_current_demo_items = db_get_value('count(*)', 'tdemo_data'); + $current_progress_val = ((($demo_items_to_cleanup - $count_current_demo_items) * 100) / $demo_items_to_cleanup); + } + + echo $current_progress_val; + + return; +} function calculateNextHostAddress($ip) { list($network, $subnet) = explode('/', $ip); @@ -374,13 +468,13 @@ function calculateNextHostAddress($ip) { $octets = explode('.', $network); // Convert the last octet to an integer. - $lastOctet = (int)$octets[3]; + $lastOctet = (int) $octets[3]; // Increment the last octet, and wrap around if it exceeds 255. - $lastOctet = ($lastOctet + 1) % 256; + $lastOctet = (($lastOctet + 1) % 256); // Assemble the next host address. - $nextHost = implode('.', array($octets[0], $octets[1], $octets[2], $lastOctet)); + $nextHost = implode('.', [$octets[0], $octets[1], $octets[2], $lastOctet]); - return $nextHost . '/' . $subnet; -} \ No newline at end of file + return $nextHost.'/'.$subnet; +} From 06f9b2e0935413d72861ab74aafdbf4cb1342fd7 Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 10 Nov 2023 16:20:04 +0100 Subject: [PATCH 071/397] Policy capacity planning modules. JS errors --- .../godmode/agentes/module_manager_editor.php | 13 +++++++++++++ .../agentes/module_manager_editor_common.php | 2 +- .../agentes/module_manager_editor_prediction.php | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/agentes/module_manager_editor.php b/pandora_console/godmode/agentes/module_manager_editor.php index a52813fbf3..29d5cb43e1 100644 --- a/pandora_console/godmode/agentes/module_manager_editor.php +++ b/pandora_console/godmode/agentes/module_manager_editor.php @@ -680,6 +680,8 @@ switch ($moduletype) { 1, ]; include 'module_manager_editor_common.php'; + ui_require_jquery_file('validate'); + ui_require_javascript_file_enterprise('pandora_synthetic'); include 'module_manager_editor_prediction.php'; break; @@ -862,6 +864,17 @@ ui_require_javascript_file('pandora_modules'); ?> From 863561781567df6bb90a1ec18fe476a1ceba42d9 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Thu, 16 Nov 2023 10:24:03 +0100 Subject: [PATCH 079/397] #12200 The Christmas effect is added after 25 clicks on the about image --- pandora_console/include/functions_menu.php | 3 ++- .../include/javascript/pandora_events.js | 12 ++++++++++++ pandora_console/index.php | 15 +++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 346dee04b5..ac76541162 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -1328,8 +1328,9 @@ if (is_ajax()) { -
    + logo + diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 86b84376c5..4c1364c54c 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1483,6 +1483,18 @@ function show_dialog(dialog) { }, 50); } +function christmas_click() { + let counter = $("#count_click").val(); + counter++; + $("#count_click").val(counter); + if (counter == 25) { + $("#container-snow").removeClass("invisible"); + setTimeout(() => { + $("#container-snow").addClass("invisible"); + }, 30000); + } +} + /* ############################################################################# ## diff --git a/pandora_console/index.php b/pandora_console/index.php index ff6f27b152..63f063c02d 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1199,7 +1199,7 @@ if ($config['pure'] == 0) { $menuCollapsed = (isset($_SESSION['menu_type']) === true && $_SESSION['menu_type'] !== 'classic'); $menuTypeClass = ($menuCollapsed === true) ? 'collapsed' : 'classic'; // Snow. - $string = '
    + $string = ''; echo "
    "; - echo ""; + echo "
    "; echo ''; echo ''; echo ''; @@ -755,6 +741,7 @@ if (isset($id_custom_fields_data) && is_array($id_custom_fields_data)) { echo ''; ui_require_css_file('datatables.min', 'include/styles/js/'); +ui_require_css_file('custom_field', 'include/styles/'); ui_require_javascript_file_enterprise('functions_csv'); ui_require_javascript_file('datatables.min'); ui_require_javascript_file('buttons.dataTables.min'); @@ -904,7 +891,6 @@ function dialog_filter_cf(title, type_form){ } function table_datatables(filters, indexed_descriptions, processing){ - console.log(indexed_descriptions); array_data = JSON.parse(filters); table = $('#datatables').DataTable({ processing: true, @@ -913,7 +899,6 @@ function table_datatables(filters, indexed_descriptions, processing){ searching: true, pageLength: Number(array_data.block_size), lengthMenu: [ 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 75, 100], - //buttons: [{ extend: 'csvHtml5', text: 'Save as csvHtml5' }], responsive: false, ajax: { type: "POST", @@ -933,21 +918,16 @@ function table_datatables(filters, indexed_descriptions, processing){ 'paging': true, 'ordering': true, 'scrollX': true, - 'scroller': true + 'scroller': true, }, }, language: { processing: processing, lengthMenu: "Show _MENU_ items per page", zeroRecords: "Nothing found. Please change your search term", - //info: "Page _PAGE_ of _PAGES_", infoEmpty: "No results", infoFiltered: "", search: "Search:", - /*paginate:{ - next: "Next", - previous: "Next" - }*/ }, sDom: '<"top"lfp>rt<"bottom"ip><"clear">', columns: [ From 38d23001cf85938ac69188acd6338fede0f74b6b Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Wed, 22 Nov 2023 09:28:56 +0100 Subject: [PATCH 090/397] #12198 fixed timezone of user or server --- .../include/lib/TacticalView/GeneralTacticalView.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/lib/TacticalView/GeneralTacticalView.php b/pandora_console/include/lib/TacticalView/GeneralTacticalView.php index d25191f2c7..d0f8ecaad6 100644 --- a/pandora_console/include/lib/TacticalView/GeneralTacticalView.php +++ b/pandora_console/include/lib/TacticalView/GeneralTacticalView.php @@ -193,8 +193,14 @@ class GeneralTacticalView } // Config user time zone. - date_default_timezone_set($user['timezone']); - $date_zone = new DateTimeZone($user['timezone']); + if (!empty($user['timezone'])) { + $timezone = $user['timezone']; + } else { + $timezone = date_default_timezone_get(); + } + + date_default_timezone_set($timezone); + $date_zone = new DateTimeZone($timezone); $zone_location = $date_zone->getLocation(); $latitude = $zone_location['latitude']; @@ -213,7 +219,7 @@ class GeneralTacticalView // Welcome back. $user_last_connect = $user['last_connect']; - $user_last_day = date('d', strtotime($user_last_connect)); + $user_last_day = date('d', $user_last_connect); $day = date('d', strtotime('now')); if ($user_last_day === $day) { if (empty($name) === true) { From b6582b7f7ea10588862856e007b63d81d5373cf2 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Wed, 22 Nov 2023 13:30:44 +0100 Subject: [PATCH 091/397] #12202 added Asteroids game --- pandora_console/include/ajax/events.php | 13 + pandora_console/include/asteroids/LICENSE.txt | 25 + pandora_console/include/asteroids/README.rst | 46 + .../include/asteroids/asteroids.js | 840 ++++++++++++++++++ pandora_console/include/asteroids/index.html | 14 + pandora_console/include/asteroids/style.css | 46 + .../include/javascript/pandora_events.js | 45 + pandora_console/include/styles/asteroids.css | 65 ++ pandora_console/operation/menu.php | 1 + 9 files changed, 1095 insertions(+) create mode 100644 pandora_console/include/asteroids/LICENSE.txt create mode 100644 pandora_console/include/asteroids/README.rst create mode 100644 pandora_console/include/asteroids/asteroids.js create mode 100644 pandora_console/include/asteroids/index.html create mode 100644 pandora_console/include/asteroids/style.css create mode 100644 pandora_console/include/styles/asteroids.css diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index 7e8341c4a1..88e063b581 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -95,6 +95,8 @@ $parameters_modal = get_parameter('parameters', 0); // User private filter. $current_filter = get_parameter('current_filter', 0); $private_filter_event = get_parameter('private_filter_event', 0); +// Asteroids. +$playAsteroids = (bool) get_parameter('playAsteroids', false); if ($get_comments === true) { global $config; @@ -2751,3 +2753,14 @@ if ($draw_row_response_info === true) { echo $output; return; } + +// Asteroids. +if ($playAsteroids === true) { + echo ui_require_css_file('asteroids', 'include/styles/', true); + echo ui_require_javascript_file('asteroids', 'include/asteroids/', true); + + $output = '
    Asteroids game goes here!
    '; + + echo $output; + return; +} diff --git a/pandora_console/include/asteroids/LICENSE.txt b/pandora_console/include/asteroids/LICENSE.txt new file mode 100644 index 0000000000..0dc661d166 --- /dev/null +++ b/pandora_console/include/asteroids/LICENSE.txt @@ -0,0 +1,25 @@ +Copyright (c) 2023, James Socol +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + diff --git a/pandora_console/include/asteroids/README.rst b/pandora_console/include/asteroids/README.rst new file mode 100644 index 0000000000..c7465358c2 --- /dev/null +++ b/pandora_console/include/asteroids/README.rst @@ -0,0 +1,46 @@ +========= +ASTEROIDS +========= + +Last week, at work, we joked about creating an Asteroids clone where every +asteroid had a bug number in it, as a bit of a joke. (Ha ha, every bug you +kill spawns two more!) + +I was bored this afternoon, so here's a port of Asteroids to JS/Canvas. + +Now all I need to do is hook in the bug numbers. + + +Gameplay +======== + +You're the triangle in the middle. You want to destroy the circles. You have +a gun (spacebar), some thrusters to turn (left and right arrow keys) and an +engine (up arrow key). + +Remember, it's kill or be killed out there. + + +Rights +====== + +The name *Asteroids* is, as far as I know, still property of Atari. I mean no +ill-will towards Atari by releasing this code. Frankly, it's a poor +substitute for anything resembling a real game. I just wanted to see if I +could do it. + +If anyone from Atari asks, I will gladly rename and/or remove this code. But +since there are so many *Asteroids* clones as it is, and the original was +released in 1979, and it was kind of a copy of *Spacewar!*, I doubt they'll +mind too much. + + +Strikes me as funny... +====================== + +The original *Spacewar!*, one of the earliest (if not the original) computer +games, took `200 hours to code `_. + +This probably took me 6. + +I am so glad we've moved past the PDP-1. diff --git a/pandora_console/include/asteroids/asteroids.js b/pandora_console/include/asteroids/asteroids.js new file mode 100644 index 0000000000..d6e9a460f4 --- /dev/null +++ b/pandora_console/include/asteroids/asteroids.js @@ -0,0 +1,840 @@ +// Asteroids.js +// Copyright (c) 2010–2023 James Socol +// See LICENSE.txt for license terms. + +// Game settings +GAME_HEIGHT = 480; +GAME_WIDTH = 640; +FRAME_PERIOD = 60; // 1 frame / x frames/sec +LEVEL_TIMEOUT = 2000; // How long to wait after clearing a level. + +// Player settings +ROTATE_SPEED = Math.PI / 10; // How fast do players turn? (radians) +MAX_SPEED = 15; // Maximum player speed +THRUST_ACCEL = 1; +DEATH_TIMEOUT = 2000; // milliseconds +INVINCIBLE_TIMEOUT = 1500; // How long to stay invincible after resurrecting? +PLAYER_LIVES = 3; +POINTS_PER_SHOT = 1; // How many points does a shot cost? (Should be >= 0.) +POINTS_TO_EXTRA_LIFE = 1000; // How many points to get a 1-up? + +// Bullet settings +BULLET_SPEED = 20; +MAX_BULLETS = 3; +MAX_BULLET_AGE = 25; + +// Asteroid settings +ASTEROID_COUNT = 2; // This + current level = number of asteroids. +ASTEROID_GENERATIONS = 3; // How many times to they split before dying? +ASTEROID_CHILDREN = 2; // How many does each death create? +ASTEROID_SPEED = 3; +ASTEROID_SCORE = 10; // How many points is each one worth? + +var Asteroids = function(home) { + // Constructor + // Order matters. + + // Set up logging. + this.log_level = Asteroids.LOG_DEBUG; + this.log = Asteroids.logger(this); + + // Create the info pane, player, and playfield. + home.innerHTML = ""; + this.info = Asteroids.infoPane(this, home); + this.playfield = Asteroids.playfield(this, home); + this.player = Asteroids.player(this); + + // Set up the event listeners. + this.keyState = Asteroids.keyState(this); + this.listen = Asteroids.listen(this); + + // Useful functions. + this.asteroids = Asteroids.asteroids(this); + this.overlays = Asteroids.overlays(this); + this.highScores = Asteroids.highScores(this); + this.level = Asteroids.level(this); + this.gameOver = Asteroids.gameOver(this); + + // Play the game. + Asteroids.play(this); + return this; +}; + +Asteroids.infoPane = function(game, home) { + var pane = document.createElement("div"); + pane.innerHTML = "ASTEROIDS"; + + var lives = document.createElement("span"); + lives.className = "lives"; + lives.innerHTML = "LIVES: " + PLAYER_LIVES; + + var score = document.createElement("span"); + score.className = "score"; + score.innerHTML = "SCORE: 0"; + + var level = document.createElement("span"); + level.className = "level"; + level.innerHTML = "LEVEL: 1"; + + pane.appendChild(lives); + pane.appendChild(score); + pane.appendChild(level); + home.appendChild(pane); + + return { + setLives: function(game, l) { + lives.innerHTML = "LIVES: " + l; + }, + setScore: function(game, s) { + score.innerHTML = "SCORE: " + s; + }, + setLevel: function(game, _level) { + level.innerHTML = "LEVEL: " + _level; + }, + getPane: function() { + return pane; + } + }; +}; + +Asteroids.playfield = function(game, home) { + var canvas = document.createElement("canvas"); + canvas.width = GAME_WIDTH; + canvas.height = GAME_HEIGHT; + home.appendChild(canvas); + return canvas; +}; + +Asteroids.logger = function(game) { + if (typeof console != "undefined" && typeof console.log != "undefined") { + return { + info: function(msg) { + if (game.log_level <= Asteroids.LOG_INFO) console.log(msg); + }, + debug: function(msg) { + if (game.log_level <= Asteroids.LOG_DEBUG) console.log(msg); + }, + warning: function(msg) { + if (game.log_level <= Asteroids.LOG_WARNING) console.log(msg); + }, + error: function(msg) { + if (game.log_level <= Asteroids.LOG_ERROR) console.log(msg); + }, + critical: function(msg) { + if (game.log_level <= Asteroids.LOG_CRITICAL) console.log(msg); + } + }; + } else { + return { + info: function(msg) {}, + debug: function(msg) {}, + warning: function(msg) {}, + error: function(msg) {}, + critical: function(msg) {} + }; + } +}; + +Asteroids.asteroids = function(game) { + var asteroids = []; + + return { + push: function(obj) { + return asteroids.push(obj); + }, + pop: function() { + return asteroids.pop(); + }, + splice: function(i, j) { + return asteroids.splice(i, j); + }, + get length() { + return asteroids.length; + }, + getIterator: function() { + return asteroids; + }, + generationCount: function(_gen) { + var total = 0; + for (var i = 0; i < asteroids.length; i++) { + if (asteroids[i].getGeneration() == _gen) total++; + } + game.log.debug("Found " + total + " asteroids in generation " + _gen); + return total; + } + }; +}; + +/** + * Creates an overlays controller. + */ +Asteroids.overlays = function(game) { + var overlays = []; + + return { + draw: function(ctx) { + for (var i = 0; i < overlays.length; i++) { + overlays[i].draw(ctx); + } + }, + add: function(obj) { + if (-1 == overlays.indexOf(obj) && typeof obj.draw != "undefined") { + overlays.push(obj); + return true; + } + return false; + }, + remove: function(obj) { + var i = overlays.indexOf(obj); + if (-1 != i) { + overlays.splice(i, 1); + return true; + } + return false; + } + }; +}; + +/** + * Creates a player object. + */ +Asteroids.player = function(game) { + // implements IScreenObject + var position = [GAME_WIDTH / 2, GAME_HEIGHT / 2], + velocity = [0, 0], + direction = -Math.PI / 2, + dead = false, + invincible = false, + lastRez = null, + lives = PLAYER_LIVES, + score = 0, + radius = 3, + path = [ + [10, 0], + [-5, 5], + [-5, -5], + [10, 0] + ]; + + return { + getPosition: function() { + return position; + }, + getVelocity: function() { + return velocity; + }, + getSpeed: function() { + return Math.sqrt(Math.pow(velocity[0], 2) + Math.pow(velocity[1], 2)); + }, + getDirection: function() { + return direction; + }, + getRadius: function() { + return radius; + }, + getScore: function() { + return score; + }, + addScore: function(pts) { + score += pts; + }, + lowerScore: function(pts) { + score -= pts; + if (score < 0) { + score = 0; + } + }, + getLives: function() { + return lives; + }, + rotate: function(rad) { + if (!dead) { + direction += rad; + game.log.info(direction); + } + }, + thrust: function(force) { + if (!dead) { + velocity[0] += force * Math.cos(direction); + velocity[1] += force * Math.sin(direction); + + if (this.getSpeed() > MAX_SPEED) { + velocity[0] = MAX_SPEED * Math.cos(direction); + velocity[1] = MAX_SPEED * Math.sin(direction); + } + + game.log.info(velocity); + } + }, + move: function() { + Asteroids.move(position, velocity); + }, + draw: function(ctx) { + let color = "#fff"; + if (invincible) { + const dt = (new Date() - lastRez) / 200; + const c = Math.floor(Math.cos(dt) * 16).toString(16); + color = `#${c}${c}${c}`; + } + Asteroids.drawPath(ctx, position, direction, 1, path, color); + }, + isDead: function() { + return dead; + }, + isInvincible: function() { + return invincible; + }, + extraLife: function(game) { + game.log.debug("Woo, extra life!"); + lives++; + }, + die: function(game) { + if (!dead) { + game.log.info("You died!"); + dead = true; + invincible = true; + lives--; + position = [GAME_WIDTH / 2, GAME_HEIGHT / 2]; + velocity = [0, 0]; + direction = -Math.PI / 2; + if (lives > 0) { + setTimeout( + (function(player, _game) { + return function() { + player.resurrect(_game); + }; + })(this, game), + DEATH_TIMEOUT + ); + } else { + game.gameOver(); + } + } + }, + resurrect: function(game) { + if (dead) { + dead = false; + invincible = true; + lastRez = new Date(); + setTimeout(function() { + invincible = false; + game.log.debug("No longer invincible!"); + }, INVINCIBLE_TIMEOUT); + game.log.debug("You ressurrected!"); + } + }, + fire: function(game) { + if (!dead) { + game.log.debug("You fired!"); + var _pos = [position[0], position[1]], + _dir = direction; + + this.lowerScore(POINTS_PER_SHOT); + + return Asteroids.bullet(game, _pos, _dir); + } + } + }; +}; + +Asteroids.bullet = function(game, _pos, _dir) { + // implements IScreenObject + var position = [_pos[0], _pos[1]], + velocity = [0, 0], + direction = _dir, + age = 0, + radius = 1, + path = [ + [0, 0], + [-4, 0] + ]; + + velocity[0] = BULLET_SPEED * Math.cos(_dir); + velocity[1] = BULLET_SPEED * Math.sin(_dir); + + return { + getPosition: function() { + return position; + }, + getVelocity: function() { + return velocity; + }, + getSpeed: function() { + return Math.sqrt(Math.pow(velocity[0], 2) + Math.pow(velocity[1], 2)); + }, + getRadius: function() { + return radius; + }, + getAge: function() { + return age; + }, + birthday: function() { + age++; + }, + move: function() { + Asteroids.move(position, velocity); + }, + draw: function(ctx) { + Asteroids.drawPath(ctx, position, direction, 1, path); + } + }; +}; + +Asteroids.keyState = function(_) { + var state = { + [Asteroids.LEFT]: false, + [Asteroids.UP]: false, + [Asteroids.RIGHT]: false, + [Asteroids.DOWN]: false, + [Asteroids.FIRE]: false + }; + + return { + on: function(key) { + state[key] = true; + }, + off: function(key) { + state[key] = false; + }, + getState: function(key) { + if (typeof state[key] != "undefined") return state[key]; + return false; + } + }; +}; + +Asteroids.listen = function(game) { + const keyMap = { + ArrowLeft: Asteroids.LEFT, + KeyA: Asteroids.LEFT, + ArrowRight: Asteroids.RIGHT, + KeyD: Asteroids.RIGHT, + ArrowUp: Asteroids.UP, + KeyW: Asteroids.UP, + Space: Asteroids.FIRE + }; + + window.addEventListener( + "keydown", + function(e) { + const state = keyMap[e.code]; + if (state) { + e.preventDefault(); + e.stopPropagation(); + game.keyState.on(state); + return false; + } + return true; + }, + true + ); + + window.addEventListener( + "keyup", + function(e) { + const state = keyMap[e.code]; + if (state) { + e.preventDefault(); + e.stopPropagation(); + game.keyState.off(state); + return false; + } + return true; + }, + true + ); +}; + +Asteroids.asteroid = function(game, _gen) { + // implements IScreenObject + var position = [0, 0], + velocity = [0, 0], + direction = 0, + generation = _gen, + radius = 7, + path = [ + [1, 7], + [5, 5], + [7, 1], + [5, -3], + [7, -7], + [3, -9], + [-1, -5], + [-4, -2], + [-8, -1], + [-9, 3], + [-5, 5], + [-1, 3], + [1, 7] + ]; + + return { + getPosition: function() { + return position; + }, + setPosition: function(pos) { + position = pos; + }, + getVelocity: function() { + return velocity; + }, + setVelocity: function(vel) { + velocity = vel; + direction = Math.atan2(vel[1], vel[0]); + }, + getSpeed: function() { + return Math.sqrt(Math.pow(velocity[0], 2) + Math.pow(velocity[1], 2)); + }, + getRadius: function() { + return radius * generation; + }, + getGeneration: function() { + return generation; + }, + move: function() { + Asteroids.move(position, velocity); + }, + draw: function(ctx) { + Asteroids.drawPath(ctx, position, direction, generation, path); + // ctx.setTransform(1, 0, 0, 1, position[0], position[1]); + // ctx.beginPath(); + // ctx.arc(0, 0, radius*generation, 0, Math.PI*2, false); + // ctx.stroke(); + // ctx.closePath(); + } + }; +}; + +Asteroids.collision = function(a, b) { + // if a.getPosition() inside b.getBounds? + var a_pos = a.getPosition(), + b_pos = b.getPosition(); + + function sq(x) { + return Math.pow(x, 2); + } + + var distance = Math.sqrt(sq(a_pos[0] - b_pos[0]) + sq(a_pos[1] - b_pos[1])); + + if (distance <= a.getRadius() + b.getRadius()) return true; + return false; +}; + +Asteroids.level = function(game) { + var level = 0, + speed = ASTEROID_SPEED, + hspeed = ASTEROID_SPEED / 2; + + return { + getLevel: function() { + return level; + }, + levelUp: function(game) { + level++; + game.log.debug("Congrats! On to level " + level); + while ( + game.asteroids.generationCount(ASTEROID_GENERATIONS) < + level + ASTEROID_COUNT + ) { + var a = Asteroids.asteroid(game, ASTEROID_GENERATIONS); + a.setPosition([ + Math.random() * GAME_WIDTH, + Math.random() * GAME_HEIGHT + ]); + a.setVelocity([ + Math.random() * speed - hspeed, + Math.random() * speed - hspeed + ]); + game.asteroids.push(a); + } + } + }; +}; + +Asteroids.gameOver = function(game) { + return function() { + game.log.debug("Game over!"); + + if (game.player.getScore() > 0) { + game.highScores.addScore("Player", game.player.getScore()); + } + + game.overlays.add({ + // implements IOverlay + draw: function(ctx) { + ctx.font = "30px System, monospace"; + ctx.textAlign = "center"; + ctx.textBaseline = "middle"; + ctx.setTransform(1, 0, 0, 1, 0, 0); + ctx.fillText("GAME OVER", GAME_WIDTH / 2, GAME_HEIGHT / 2); + + var scores = game.highScores.getScores(); + ctx.font = "12px System, monospace"; + for (var i = 0; i < scores.length; i++) { + ctx.fillText( + scores[i].name + " " + scores[i].score, + GAME_WIDTH / 2, + GAME_HEIGHT / 2 + 20 + 14 * i + ); + } + } + }); + }; +}; + +Asteroids.highScores = function(game) { + var scores = []; + + if ((t = localStorage.getItem("high-scores"))) { + scores = JSON.parse(t); + } + + return { + getScores: function() { + return scores; + }, + addScore: function(_name, _score) { + scores.push({ name: _name, score: _score }); + scores.sort(function(a, b) { + return b.score - a.score; + }); + if (scores.length > 10) { + scores.length = 10; + } + game.log.debug("Saving high scores."); + var str = JSON.stringify(scores); + localStorage.setItem("high-scores", str); + } + }; +}; + +Asteroids.drawPath = function(ctx, position, direction, scale, path, color) { + if (!color) { + color = "#fff"; + } + ctx.strokeStyle = color; + ctx.setTransform( + Math.cos(direction) * scale, + Math.sin(direction) * scale, + -Math.sin(direction) * scale, + Math.cos(direction) * scale, + position[0], + position[1] + ); + + ctx.beginPath(); + ctx.moveTo(path[0][0], path[0][1]); + for (i = 1; i < path.length; i++) { + ctx.lineTo(path[i][0], path[i][1]); + } + ctx.stroke(); + ctx.closePath(); + ctx.strokeStyle = "#fff"; +}; + +Asteroids.move = function(position, velocity) { + position[0] += velocity[0]; + if (position[0] < 0) position[0] = GAME_WIDTH + position[0]; + else if (position[0] > GAME_WIDTH) position[0] -= GAME_WIDTH; + + position[1] += velocity[1]; + if (position[1] < 0) position[1] = GAME_HEIGHT + position[1]; + else if (position[1] > GAME_HEIGHT) position[1] -= GAME_HEIGHT; +}; + +Asteroids.stars = function() { + var stars = []; + for (var i = 0; i < 50; i++) { + stars.push([Math.random() * GAME_WIDTH, Math.random() * GAME_HEIGHT]); + } + + return { + draw: function(ctx) { + var ii = stars.length; + for (var i = 0; i < ii; i++) { + ctx.fillRect(stars[i][0], stars[i][1], 1, 1); + } + } + }; +}; + +Asteroids.play = function(game) { + var ctx = game.playfield.getContext("2d"); + ctx.fillStyle = "white"; + ctx.strokeStyle = "white"; + + var speed = ASTEROID_SPEED, + hspeed = ASTEROID_SPEED / 2; + + game.level.levelUp(game); + + var bullets = [], + last_fire_state = false, + last_asteroid_count = 0; + + var extra_lives = 0; + + // Add a star field. + game.overlays.add(Asteroids.stars()); + + game.pulse = setInterval(function() { + var kill_asteroids = [], + new_asteroids = [], + kill_bullets = []; + + ctx.save(); + ctx.clearRect(0, 0, GAME_WIDTH, GAME_HEIGHT); + + // Be nice and award extra lives first. + var t_extra_lives = game.player.getScore() / POINTS_TO_EXTRA_LIFE; + t_extra_lives = Math.floor(t_extra_lives); + if (t_extra_lives > extra_lives) { + game.player.extraLife(game); + } + extra_lives = t_extra_lives; + + if (game.keyState.getState(Asteroids.UP)) { + game.player.thrust(THRUST_ACCEL); + } + + if (game.keyState.getState(Asteroids.LEFT)) { + game.player.rotate(-ROTATE_SPEED); + } + + if (game.keyState.getState(Asteroids.RIGHT)) { + game.player.rotate(ROTATE_SPEED); + } + + var fire_state = game.keyState.getState(Asteroids.FIRE); + if ( + fire_state && + fire_state != last_fire_state && + bullets.length < MAX_BULLETS + ) { + var b = game.player.fire(game); + bullets.push(b); + } + last_fire_state = fire_state; + + if (!game.player.isDead()) { + game.player.move(); + game.player.draw(ctx); + } + + for (var k = 0; k < bullets.length; k++) { + if (!bullets[k]) continue; + + if (bullets[k].getAge() > MAX_BULLET_AGE) { + kill_bullets.push(k); + continue; + } + bullets[k].birthday(); + bullets[k].move(); + bullets[k].draw(ctx); + } + + for (var r = kill_bullets.length - 1; r >= 0; r--) { + bullets.splice(r, 1); + } + + var asteroids = game.asteroids.getIterator(); + for (var i = 0; i < game.asteroids.length; i++) { + var killit = false; + asteroids[i].move(); + asteroids[i].draw(ctx); + + // Destroy the asteroid + for (var j = 0; j < bullets.length; j++) { + if (!bullets[j]) continue; + if (Asteroids.collision(bullets[j], asteroids[i])) { + game.log.debug("You shot an asteroid!"); + // Destroy the bullet. + bullets.splice(j, 1); + killit = true; // JS doesn't have "continue 2;" + continue; + } + } + + // Kill the asteroid? + if (killit) { + var _gen = asteroids[i].getGeneration() - 1; + if (_gen > 0) { + // Create children ;) + for (var n = 0; n < ASTEROID_CHILDREN; n++) { + var a = Asteroids.asteroid(game, _gen); + var _pos = [ + asteroids[i].getPosition()[0], + asteroids[i].getPosition()[1] + ]; + a.setPosition(_pos); + a.setVelocity([ + Math.random() * speed - hspeed, + Math.random() * speed - hspeed + ]); + new_asteroids.push(a); + } + } + game.player.addScore(ASTEROID_SCORE); + kill_asteroids.push(i); + continue; + } + + // Kill the player? + if ( + !game.player.isDead() && + !game.player.isInvincible() && + Asteroids.collision(game.player, asteroids[i]) + ) { + game.player.die(game); + } + } + + kill_asteroids.sort(function(a, b) { + return a - b; + }); + for (var m = kill_asteroids.length - 1; m >= 0; m--) { + game.asteroids.splice(kill_asteroids[m], 1); + } + + for (var o = 0; o < new_asteroids.length; o++) { + game.asteroids.push(new_asteroids[o]); + } + + ctx.restore(); + + // Do we need to level up? + if (0 == game.asteroids.length && last_asteroid_count != 0) { + setTimeout(function() { + game.level.levelUp(game); + }, LEVEL_TIMEOUT); + } + + last_asteroid_count = game.asteroids.length; + + // Draw overlays. + game.overlays.draw(ctx); + + // Update the info pane. + game.info.setLives(game, game.player.getLives()); + game.info.setScore(game, game.player.getScore()); + game.info.setLevel(game, game.level.getLevel()); + }, FRAME_PERIOD); +}; + +// Some boring constants. +Asteroids.LOG_ALL = 0; +Asteroids.LOG_INFO = 1; +Asteroids.LOG_DEBUG = 2; +Asteroids.LOG_WARNING = 3; +Asteroids.LOG_ERROR = 4; +Asteroids.LOG_CRITICAL = 5; +Asteroids.LOG_NONE = 6; + +Asteroids.LEFT = 37; +Asteroids.UP = 38; +Asteroids.RIGHT = 39; +Asteroids.DOWN = 40; +Asteroids.FIRE = 32; + +// Load it up! +window.onload = Asteroids(document.getElementById("asteroids")); diff --git a/pandora_console/include/asteroids/index.html b/pandora_console/include/asteroids/index.html new file mode 100644 index 0000000000..3c1dfbd690 --- /dev/null +++ b/pandora_console/include/asteroids/index.html @@ -0,0 +1,14 @@ + + + + + Asteroids + + + + +
    Asteroids game goes here!
    + + + + diff --git a/pandora_console/include/asteroids/style.css b/pandora_console/include/asteroids/style.css new file mode 100644 index 0000000000..ab877caa06 --- /dev/null +++ b/pandora_console/include/asteroids/style.css @@ -0,0 +1,46 @@ +/* Style for Asteroids.js + * Copyright (c) 2010 James Socol + * See LICENSE.txt for license. + */ + +body { + background-color: #000; + color: #fff; + font-family: "Calibri", "System", monospace; + font-size: 14px; +} + +div#asteroids { + margin: 50px auto; + width: 640px; + border: 1px solid #fff; + padding: 5px; +} + +div#asteroids > * { + color: #fff; +} + +div#asteroids > div { + font-family: "System", monospace; + font-size: 11px; + padding-bottom: 5px; +} + +div#asteroids > div > span { + float: right; + padding-left: 20px; +} + +div#instructions { + width: 640px; + margin: 20px auto; +} + +h1 { + font-size: 18px; +} + +h2 { + font-size: 16px; +} diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index 86b84376c5..f1453ce493 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1739,3 +1739,48 @@ function loadModal() { } } window.onload = loadModal; + +// Load Asteroids game. +$(window).on("load", function() { + let counter = 0; + $("#button-sound_events_button") + .off("click") + .on("click", function(e) { + counter++; + if (counter == 12) { + $("#modal-asteroids") + .dialog({ + title: "Asteroids", + resizable: true, + modal: true, + width: 900, + height: 700, + open: function() { + $.ajax({ + method: "post", + url: getUrlAjax(), + data: { + page: "include/ajax/events", + playAsteroids: 1 + }, + dataType: "html", + success: function(data) { + $("#modal-asteroids").html(data); + $(".ui-widget-content").css("background", "#222"); + $(".ui-dialog-title").css("color", "#fff"); + }, + error: function(error) { + console.error(error); + } + }); + }, + close: function() { + counter = 0; + $(".ui-widget-content").css("background", "#fff"); + $(".ui-dialog-title").css("color", "rgb(51, 51, 51)"); + } + }) + .show(); + } + }); +}); diff --git a/pandora_console/include/styles/asteroids.css b/pandora_console/include/styles/asteroids.css new file mode 100644 index 0000000000..8b434b59ba --- /dev/null +++ b/pandora_console/include/styles/asteroids.css @@ -0,0 +1,65 @@ +/** + * + * Name: Default theme + * Pandora Stylesheet + * + * @category Stylesheet + * @package Pandora FMS + * @subpackage Community + * @version 1.0.0 + * @license See below + * + * ______ ___ _______ _______ ________ + * | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __| + * | __/| _ | | _ || _ | _| _ | | ___| |__ | + * |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______| + * + * ============================================================================ + * Copyright (c) 2005-2023 Pandora FMS + * Please see https://pandorafms.com 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 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 + * GNU General Public License for more details. + * ============================================================================ + */ + +div#asteroids { + background-color: #000; + color: #fff; + margin: 50px auto; + width: 640px; + border: 1px solid #fff; + padding: 5px; +} + +div#asteroids > * { + color: #fff; +} + +div#asteroids > div { + font-family: "System", monospace; + font-size: 11px; + padding-bottom: 5px; +} + +div#asteroids > div > span { + float: right; + padding-left: 20px; +} + +div#instructions { + width: 640px; + margin: 20px auto; +} + +h1 { + font-size: 18px; +} + +h2 { + font-size: 16px; +} diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 3794a30ae3..2ec659f51a 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -603,6 +603,7 @@ if ($access_console_node === true) { $sub[$javascript]['type'] = 'direct'; echo ''; + echo ''; ui_require_javascript_file('pandora_events'); From 0a9e1275765d39dc09094651754a6bbe4b230437 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 22 Nov 2023 16:12:37 +0100 Subject: [PATCH 092/397] #8365 NCM v3 snipets --- pandora_console/extras/mr/67.sql | 3 +++ pandora_console/pandoradb.sql | 1 + 2 files changed, 4 insertions(+) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 76a2619e00..565882214a 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -3,6 +3,9 @@ START TRANSACTION; ALTER TABLE `tncm_queue` ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`; +ALTER TABLE `tncm_queue` +ADD COLUMN `snipet` TEXT NULL AFTER `scheduled`; + CREATE TABLE IF NOT EXISTS `tncm_agent_data_template` ( `id` SERIAL, `name` TEXT, diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 334afe02b2..aeb33e9a10 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4270,6 +4270,7 @@ CREATE TABLE IF NOT EXISTS `tncm_queue` ( `id_agent_data` bigint unsigned, `utimestamp` INT UNSIGNED NOT NULL, `scheduled` INT UNSIGNED DEFAULT NULL, + `snipet` TEXT NULL, FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; From a277e56672b1875ddc8fefac9b2f9bb2d7f61af8 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 22 Nov 2023 16:47:13 +0100 Subject: [PATCH 093/397] #8365 NCM v3 rename snipet to snippet --- pandora_console/extras/mr/67.sql | 2 +- pandora_console/pandoradb.sql | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 565882214a..00a357d18a 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -4,7 +4,7 @@ ALTER TABLE `tncm_queue` ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`; ALTER TABLE `tncm_queue` -ADD COLUMN `snipet` TEXT NULL AFTER `scheduled`; +ADD COLUMN `snippet` TEXT NULL AFTER `scheduled`; CREATE TABLE IF NOT EXISTS `tncm_agent_data_template` ( `id` SERIAL, diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index aeb33e9a10..d009554cc6 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4270,7 +4270,7 @@ CREATE TABLE IF NOT EXISTS `tncm_queue` ( `id_agent_data` bigint unsigned, `utimestamp` INT UNSIGNED NOT NULL, `scheduled` INT UNSIGNED DEFAULT NULL, - `snipet` TEXT NULL, + `snippet` TEXT NULL, FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE, FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; From 51e07930ed16d37bdb246c6a42266dccae54f00a Mon Sep 17 00:00:00 2001 From: miguel angel rasteu Date: Thu, 23 Nov 2023 09:51:12 +0100 Subject: [PATCH 094/397] #11495 Align text left --- pandora_console/include/functions_reporting_html.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 71bf7afbc3..e67bd2b173 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -2797,13 +2797,16 @@ function reporting_html_service_level($table, $item, $pdf=0) $table_info->head[5] = __('Warn. Events'); $table_info->head[6] = __('Last change'); $table_info->data = []; + $table_info->cellstyle = []; $row = 0; foreach ($item['data'] as $agentmodule_id => $module_data) { if ($show_agents === 'on') { $table_info->data[$row][0] = $module_data['agent_alias'].' / '.$module_data['module_name']; + $table_info->cellstyle[$row][0] = 'text-align:left; padding-left: 30px;'; } else { $table_info->data[$row][0] = $module_data['module_name']; + $table_info->cellstyle[$row][0] = 'text-align:left; padding-left: 30px;'; } $table_info->data[$row][1] = $module_data['availability'].'%'; From b4e07c8ce72e7b54d113bbc424a086fc8da37e01 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Thu, 23 Nov 2023 17:31:11 +0100 Subject: [PATCH 095/397] #12067 Added easter egg, think green --- pandora_console/index.php | 142 ++++++++++++++++++ .../operation/agentes/group_view.php | 4 +- 2 files changed, 144 insertions(+), 2 deletions(-) diff --git a/pandora_console/index.php b/pandora_console/index.php index 4ca8f80a82..95641b313f 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1667,5 +1667,147 @@ require 'include/php_to_js_values.php'; $(".submitButton").click(function(){ $("#"+this.id+" > .subIcon.cog").addClass("rotation"); }); + + // Easter egg think green. + let counter = 0; + $("#keywords").on("click", function(e) { + counter++; + let falEasternEgg = true; + if (counter == 5 && falEasternEgg == true) { + easterEggThinkGreen(); + } + }); }); + + function easterEggThinkGreen() { + // Agent detail. + $('#agent_list > tbody > tr').each(function(index, fila) { + var divId = $(fila).find('td:eq(5)').attr('id'); + var hasClassRed = $("#"+divId).children('b').children().next().hasClass('red'); + var hasClassGrey = $("#"+divId).children('b').children().next().hasClass('grey'); + if (hasClassRed === true || hasClassGrey === true) { + $("#"+divId).children('b').children().next().addClass('green'); + } + + var divStatus = $(fila).find('td:eq(6)').attr('id'); + $("#"+divStatus).find('div').attr('style', 'background: #82b92e;'); + }); + + // Agent main view. + const agentDetailsHeaderIcono = $('.agent_details_header > .icono_right').children('img'); + const statusImg = $(agentDetailsHeaderIcono).attr('src'); + if (statusImg !== undefined) { + if (statusImg.indexOf('critical') >= 0 || statusImg.indexOf('unknown') >= 0) { + $(agentDetailsHeaderIcono).attr('src', 'images/agent_ok.png'); + } + } + // Agent details bullets. + const agentDetailsBullets = $('.agent_details_bullets > #bullets_modules').children('div').children('div').attr('id'); + var hasClassRed = $("#"+agentDetailsBullets).hasClass('red_background'); + var hasClassGrey = $("#"+agentDetailsBullets).hasClass('grey_background'); + const elementChange = { + 'hasClassRed': hasClassRed, + 'hasClassGrey': hasClassGrey, + 'elementID' : agentDetailsBullets, + 'class' : true + } + setClassGreen(elementChange); + // Header list of modules + const headerList = $('.white_table_graph_header').children('span').children('div'); + var hasClassRed = $(headerList[5]).children('div').children('div').hasClass('red_background'); + var hasClassGrey = $(headerList[5]).children('div').children('div').hasClass('grey_background'); + elementChange.hasClassRed = hasClassRed; + elementChange.hasClassGrey = hasClassGrey; + elementChange.elementID = $(headerList[5]).children('div').children('div').attr('id'); + elementChange.class = true; + setClassGreen(elementChange); + + // List of modules table. + $('#table1 > tbody > tr').each(function(index, fila) { + var divId = $(fila).find('td:eq(4)').attr('id'); + var divStyle = $("#"+divId).children('div').attr('style'); + if (divStyle !== undefined) { + let findedRed = divStyle.indexOf('background: #e63c52;') + let findedGrey = divStyle.indexOf('background: #B2B2B2;') + if (findedRed >= 0 || findedGrey >= 0) { + elementChange.hasClassRed = true; + elementChange.hasClassGrey = true; + elementChange.elementID = $("#"+divId).children('div'); + elementChange.class = false; + setClassGreen(elementChange); + } + } + }); + + // latest events table. + $('#latest_events_table > tbody > tr').each(function(index, fila) { + // Change status. + var divId = $(fila).find('td:eq(3)').attr('id'); + var divStyle = $("#"+divId).children('div').attr('style'); + if (divStyle !== undefined) { + let findedRed = divStyle.indexOf('background: #e63c52'); + let findedGrey = divStyle.indexOf('background: #B2B2B2'); + if (findedRed >= 0 || findedGrey >= 0) { + elementChange.hasClassRed = true; + elementChange.hasClassGrey = true; + elementChange.elementID = $("#"+divId).children('div'); + elementChange.class = false; + setClassGreen(elementChange); + // Change Image + const tdId = $(fila).find('td:eq(0)').attr('id'); + var img = $("#"+tdId).children('img'); + $(img).attr('src', 'images/module_ok.png'); + } + } + }); + + // Group view. + //Summary status groups + $('#summary_status_groups > tbody > tr > td > span').each(function(index, fila) { + var hasClassRed = $(fila).hasClass('red_background'); + if (hasClassRed) { + $(fila).removeClass('red_background').addClass('green_background'); + } + }); + + $('#summary_status_groups_detail > tbody > tr > td').each(function(index, fila) { + var hasClassRed = $(fila).hasClass('group_view_crit'); + console.log(hasClassRed); + if (hasClassRed) { + $(fila).removeClass('group_view_crit').addClass('group_view_ok'); + $(fila).children('a').removeClass('group_view_crit').addClass('group_view_ok'); + } + }); + + // Monitor detail. + // Monitors view table + $('#monitors_view > tbody > tr').each(function(index, fila) { + // Change status. + var divId = $(fila).find('td:eq(6)').attr('id'); + var divStyle = $("#"+divId).children('div').children('div').attr('style'); + if (divStyle !== undefined) { + let findedRed = divStyle.indexOf('background: #e63c52'); + let findedGrey = divStyle.indexOf('background: #B2B2B2'); + if (findedRed >= 0 || findedGrey >= 0) { + elementChange.hasClassRed = true; + elementChange.hasClassGrey = true; + elementChange.elementID = $("#"+divId).children('div').children('div'); + elementChange.class = false; + setClassGreen(elementChange); + } + } + }); + + } + + function setClassGreen(element) { + // Class. + if ((element.hasClassRed === true || element.hasClassGrey === true) && element.class == true) { + $("#"+element.elementID).addClass('green_background'); + } + // Element style. + if ((element.hasClassRed === true || element.hasClassGrey === true) && element.class == false) { + element.elementID.css('background', '#82b92e'); + } + } diff --git a/pandora_console/operation/agentes/group_view.php b/pandora_console/operation/agentes/group_view.php index 08066014e0..c7bca5635a 100644 --- a/pandora_console/operation/agentes/group_view.php +++ b/pandora_console/operation/agentes/group_view.php @@ -175,7 +175,7 @@ if ($total_agentes > 0) { $total_not_init = format_numeric((($agents_notinit * 100) / $total_agentes), 2); } -echo '
    '; +echo '
    '; echo ''; echo ''; echo "'; @@ -227,7 +227,7 @@ if (empty($result_groups) === false) { [ 'right_content' => $pagination ] ); - echo '
    ".__('Summary of the status groups').'
    '; + echo '
    '; echo ''; echo ''; echo ''; From c7770ec4f1e05794d0fb426fc36e9a139cc22f3d Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Thu, 23 Nov 2023 17:59:22 +0100 Subject: [PATCH 096/397] implement demo data load --- pandora_console/godmode/setup/demo.php | 794 ++++--- .../include/ajax/demo_data.ajax.php | 2083 +++++++++++------ pandora_console/include/constants.php | 9 + 3 files changed, 1821 insertions(+), 1065 deletions(-) diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index daf400003d..b1caf6f9cc 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -34,320 +34,496 @@ if (users_is_admin() === false) { return; } -config_update_value('demo_data_load_progress', 0); - html_print_input_hidden('demo_items_count', 0); +$display_loading = (bool) get_parameter('display_loading', 0); + $agents_num = (int) get_parameter('agents_num', 30); -$submit_value = (string) get_parameter('update_button', ''); +$create_data = (bool) get_parameter('create_data', false); +$delete_data = (bool) get_parameter('delete_data', false); $def_value = 0; -if ($submit_value === '') { +if ($create_data === false) { $def_value = 1; } +$adv_options_is_enabled = get_parameter('toggle_adv_opts', 0); +$days_hist_data = (int) get_parameter('days_hist_data', 15); +$interval = get_parameter('interval', 0); + +// Map directory and demo item ID. +$dir_item_id_map = [ + DEMO_CUSTOM_GRAPH => 'graphs', + DEMO_NETWORK_MAP => 'network_maps', + DEMO_SERVICE => 'services', + DEMO_REPORT => 'reports', + DEMO_DASHBOARD => 'dashboards', + DEMO_VISUAL_CONSOLE => 'visual_consoles', +]; + $enabled_items = [ - 'enable_cg' => (int) get_parameter('enable_cg', $def_value), - 'enable_nm' => (int) get_parameter('enable_nm', $def_value), - 'enable_services' => (int) get_parameter('enable_services', $def_value), - 'enable_rep' => (int) get_parameter('enable_rep', $def_value), - 'enable_dashboards' => (int) get_parameter('enable_dashboards', $def_value), - 'enable_vc' => (int) get_parameter('enable_vc', $def_value), + 'graphs' => (int) get_parameter('enable_cg', $def_value), + 'network_maps' => (int) get_parameter('enable_nm', $def_value), + 'services' => (int) get_parameter('enable_services', $def_value), + 'reports' => (int) get_parameter('enable_rep', $def_value), + 'dashboards' => (int) get_parameter('enable_dashboards', $def_value), + 'visual_consoles' => (int) get_parameter('enable_vc', $def_value), + 'enable_history' => (int) get_parameter('enable_history', 0), ]; -$demo_items_count = db_get_value('count(*)', 'tdemo_data'); -$demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); +$demo_items_count = (int) db_get_value('count(*)', 'tdemo_data'); -// Basic/Advanced mode. -$mode = (string) get_parameter('mode', 'basic'); - -$buttons = []; - -// Draws header. -$buttons['basic'] = [ - 'active' => false, - 'text' => ''.html_print_image( - 'images/setup.png', - true, - [ - 'title' => __('General'), - 'class' => 'invert_filter', - ] - ).'', -]; - -$buttons['advanced'] = [ - 'active' => false, - 'text' => ''.html_print_image( - 'images/key.png', - true, - [ - 'title' => __('Advanced'), - 'class' => 'invert_filter', - ] - ).'', -]; - -// Header. -ui_print_standard_header( - __('Demo data'), - 'images/custom_field.png', +$current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', false, - '', - true, - $buttons, - [ - [ - 'link' => '', - 'label' => __('Setup'), - ], - [ - 'link' => '', - 'label' => __('Demo data'), - ], - ] + false ); -$table_aux = new stdClass(); -$table_aux->id = 'table-demo'; -$table_aux->class = 'filter-table-adv'; -$table_aux->width = '100%'; -$table_aux->data = []; -$table_aux->size = []; -$table_aux->size[0] = '50%'; -$table_aux->size[1] = '50%'; +$current_progress_val_delete = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_delete_progress'], + 'AND', + false, + false +); -if ($mode === 'advanced') { - $arraySelectIcon = [ - 10 => '10', - 30 => '30', - 50 => '50', - 500 => '500', - 1000 => '1000', - 2000 => '2000', - ]; -} else { - $arraySelectIcon = [ - 10 => '10', - 30 => '30', - 50 => '50', - ]; -} +$running_create = ($current_progress_val > 0 && $current_progress_val < 100); +$running_delete = ($current_progress_val_delete > 0 && $current_progress_val_delete < 100); -$agent_num = (int) get_parameter('agents_num'); +// Real time loading. +if ($display_loading === true || $running_create === true || $running_delete) { + $table_load = new stdClass(); + $table_load->id = 'table-demo'; + $table_load->class = 'filter-table-adv'; + $table_load->width = '100%'; + $table_load->data = []; + $table_load->size = []; + $table_load->size[0] = '50%'; + $table_load->size[1] = '50%'; -$otherData = []; -$table_aux->data['row1'][] = html_print_label_input_block( - __('Agents'), + $table_load->data['row0'][] = progress_bar( + 0, + 100, + 20, + '', + 0, + false, + ((int) 0 !== -1) ? false : '#f3b200', + [ + 'class' => 'progress_bar', + 'id' => 'progress_bar', + ] + ).html_print_input_hidden('js_timer_'.$operation['id'], 0, true); + + if ($create_data === true || $running_create === true) { + // Map demo item ID to display name in page. + $items_ids_text_map = [ + DEMO_AGENT => 'agents', + DEMO_SERVICE => 'services', + DEMO_NETWORK_MAP => 'network maps', + DEMO_CUSTOM_GRAPH => 'custom graphs', + DEMO_REPORT => 'custom reports', + DEMO_VISUAL_CONSOLE => 'visual consoles', + DEMO_DASHBOARD => 'dashboards', + ]; + + if ($adv_options_is_enabled === true) { + $enabled_keys = array_keys(array_filter($enabled_items)); + + $items_ids_text_map = array_filter( + $items_ids_text_map, + function ($k) use ($dir_item_id_map, $enabled_keys) { + return in_array($dir_item_id_map[$k], $enabled_keys); + }, + ARRAY_FILTER_USE_KEY + ); + + array_merge([DEMO_AGENT => 'agents'], $items_ids_text_map); + } + + $list_mkup = '
      '; + foreach ($items_ids_text_map as $item_id => $item_text) { + $list_mkup .= '
    • '; + $list_mkup .= '
      '.html_print_image( + 'images/icono-unknown.png', + true, + [ + 'title' => __('View'), + 'class' => 'icon w100p h100p', + ] + ).'
      '; + $list_mkup .= 'Create demo '.$item_text.''; + $list_mkup .= '
        '; + $list_mkup .= '
      '; + $list_mkup .= '
    • '; + } + + $list_mkup .= '
    '; + } + + echo '
    '; + echo '
    '; + echo ''.__('Progress').''; + html_print_table($table_load); + echo $list_mkup; + + echo '
    '; + + if ($create_data === true || $running_create === true) { + $btn_span = __('View summary'); + $icon = 'next'; + } else { + $btn_span = __('Back'); + $icon = 'back'; + } + + + $action_btns = html_print_action_buttons( + html_print_submit_button( + $btn_span, + 'redirect_button', + false, + [ + 'icon' => $icon, + ], + true + ), + [], + true + ); + + // Only rendered when data creation has been completed. html_print_div( [ - 'class' => '', - 'content' => html_print_select( - $arraySelectIcon, - 'agents_num', - $agents_num, + 'id' => 'action-btns-loading-done', + 'class' => 'invisible', + 'content' => $action_btns, + ] + ); + + echo ''; +} else { + // Configuration. + if ($demo_items_count === 0) { + $table_aux = new stdClass(); + $table_aux->id = 'table-demo'; + $table_aux->class = 'filter-table-adv'; + $table_aux->width = '100%'; + $table_aux->data = []; + $table_aux->size = []; + $table_aux->size[0] = '50%'; + $table_aux->size[1] = '50%'; + + $agent_sel_values = [ + 10 => '10', + 30 => '30', + 50 => '50', + 500 => '500', + 1000 => '1000', + 2000 => '2000', + ]; + + $agent_num = (int) get_parameter('agents_num'); + + $otherData = []; + $table_aux->data['row1'][] = html_print_label_input_block( + __('Agents'), + html_print_div( + [ + 'class' => '', + 'content' => html_print_select( + $agent_sel_values, + 'agents_num', + $agents_num, + '', + '30', + 30, + true, + false, + true, + 'w80px' + ), + ], + true + ) + ); + + $table_aux->data['row2'][] = html_print_label_input_block( + __('Advanced options'), + html_print_checkbox_switch( + 'toggle_adv_opts', + 1, + false, + true + ) + ); + + $table_adv = new stdClass(); + $table_adv->id = 'table-adv'; + $table_adv->class = 'filter-table-adv'; + $table_adv->width = '100%'; + $table_adv->data = []; + $table_adv->size = []; + $table_adv->size[0] = '50%'; + $table_adv->size[1] = '50%'; + + $table_adv->data['row0'][] = html_print_label_input_block( + __('Generate historical data for all agents (15 days by default)'), + html_print_checkbox_switch( + 'enable_history', + 1, + false, + true + ) + ); + + $table_adv->data['row1'][] = html_print_label_input_block( + __('Days of historical data to insert in the agent data'), + html_print_input_text( + 'days_hist_data', + $days_hist_data, '', - '30', - 30, + 10, + 20, true, false, - true, + false, + '', 'w80px' - ).'  '.__('(%d demo agents currently in the system)', $demo_agents_count).'', - ], - true - ) -); + ) + ); -$table_aux->data['row2'][] = progress_bar( - 0, - 100, - 20, - '', - 0, - false, - ((int) 0 !== -1) ? false : '#f3b200', - [ - 'class' => 'progress_bar', - 'id' => 'progress_bar', - ] -).html_print_input_hidden('js_timer_'.$operation['id'], 0, true); + $table_adv->data['row2'][] = html_print_label_input_block( + __('Create custom graphs'), + html_print_checkbox_switch( + 'enable_cg', + 1, + $enabled_items['graphs'], + true + ) + ); -if ($mode === 'advanced') { - $table_aux->data['row3'][] = html_print_label_input_block( - __('Generate historical data for all agents (15 days by default)'), - html_print_checkbox_switch( - 'enable_historical', - 1, - true, - true - ) - ); - - $table_aux->data['row4'][] = html_print_label_input_block( - __('Create custom graphs'), - html_print_checkbox_switch( - 'enable_cg', - 1, - $enabled_items['enable_cg'], - true - ) - ); - - $table_aux->data['row5'][] = html_print_label_input_block( - __('Create network maps'), - html_print_checkbox_switch( - 'enable_nm', - 1, - $enabled_items['enable_nm'], - true - ) - ); - - $table_aux->data['row6'][] = html_print_label_input_block( - __('Create services'), - html_print_checkbox_switch( - 'enable_services', - 1, - $enabled_items['enable_services'], - true - ) - ); - - $table_aux->data['row7'][] = html_print_label_input_block( - __('Create reports'), - html_print_checkbox_switch( - 'enable_rep', - 1, - $enabled_items['enable_rep'], - true - ) - ); - - $table_aux->data['row8'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['enable_dashboards'], - true - ) - ); - - - $table_aux->data['row9'][] = html_print_label_input_block( - __('Create visual consoles'), - html_print_checkbox_switch( - 'enable_vc', - 1, - $enabled_items['enable_vc'], - true - ) - ); - - $table_aux->data['row10'][] = html_print_label_input_block( - __('Days of historical data to insert in the agent data'), - html_print_input_text( - 'days_hist_data', - 15, + $interval_select = html_print_extended_select_for_time( + 'interval', + $interval, '', + '', + '0', 10, - 20, true, false, - false, - '', - 'w80px' - ) - ); - ?> + true, + 'w20p' + ); - data['row3'][] = html_print_label_input_block( + __('Interval'), + $interval_select + ); + + $table_adv->data['row4'][] = html_print_label_input_block( + __('Create network maps'), + html_print_checkbox_switch( + 'enable_nm', + 1, + $enabled_items['network_maps'], + true + ) + ); + + $table_adv->data['row5'][] = html_print_label_input_block( + __('Create services'), + html_print_checkbox_switch( + 'enable_services', + 1, + $enabled_items['services'], + true + ) + ); + + $table_adv->data['row6'][] = html_print_label_input_block( + __('Create reports'), + html_print_checkbox_switch( + 'enable_rep', + 1, + $enabled_items['reports'], + true + ) + ); + + $table_adv->data['row7'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); + + + $table_adv->data['row8'][] = html_print_label_input_block( + __('Create visual consoles'), + html_print_checkbox_switch( + 'enable_vc', + 1, + $enabled_items['visual_consoles'], + true + ) + ); + + echo '
    '; + echo '
    '; + echo ''.__('Configure demo data').''; + html_print_input_hidden('create_data', 1); + html_print_input_hidden('display_loading', 1); + html_print_table($table_aux); + html_print_div( + [ + 'class' => 'invisible', + 'content' => html_print_table($table_adv), + ], + true + ); + echo '
    '; + + $actionButtons = []; + + $actionButtons[] = html_print_submit_button( + __('Create demo data'), + 'create_button', + false, + [ + 'icon' => 'update', + 'fixed_id' => 'btn-create-demo-data', + ], + true + ); + + // echo ''; + + echo ''; + } else { + // Summary data. + $demo_agents_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); + $demo_services_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tservice'); + $demo_nm_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tmap'); + $demo_cg_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tgraph'); + $demo_rep_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'treport'); + $demo_vc_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tlayout'); + $demo_dashboards_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tdashboard'); + + $table_summary = new stdClass(); + $table_summary->id = 'table-summary'; + $table_summary->class = 'filter-table-adv'; + $table_summary->width = '100%'; + $table_summary->data = []; + $table_summary->size = []; + $table_summary->size[0] = '50%'; + $table_summary->size[1] = '50%'; + + $table_summary->data['row0'][0] = __('Agents'); + $table_summary->data['row0'][1] = ($demo_agents_count > 0) ? $demo_agents_count : '-'; + $table_summary->data['row1'][0] = __('Services'); + $table_summary->data['row1'][1] = ($demo_services_count > 0) ? $demo_services_count : '-'; + $table_summary->data['row2'][0] = __('Network maps'); + $table_summary->data['row2'][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-'; + $table_summary->data['row3'][0] = __('Custom graphs'); + $table_summary->data['row3'][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-'; + $table_summary->data['row4'][0] = __('Custom reports'); + $table_summary->data['row4'][1] = ($demo_rep_count > 0) ? $demo_rep_count : '-'; + $table_summary->data['row5'][0] = __('Visual consoles'); + $table_summary->data['row5'][1] = ($demo_vc_count > 0) ? $demo_vc_count : '-'; + $table_summary->data['row6'][0] = __('Dashboards'); + $table_summary->data['row6'][1] = ($demo_dashboards_count > 0) ? $demo_dashboards_count : '-'; + + echo '
    '; + echo '
    '; + echo ''.__('Active demo data summary').''; + html_print_table($table_summary); + echo '
    '; + + html_print_input_hidden('delete_data', 1); + html_print_input_hidden('display_loading', 1); + + html_print_action_buttons( + html_print_submit_button( + __('Delete all demo data'), + 'delete_button', + false, + [ + 'icon' => 'delete', + 'mode' => 'secondary', + 'fixed_id' => 'btn-delete-demo-data', + ], + true + ) + ); + echo ''; + } } -echo '
    '; -echo '
    '; -echo ''.__('Configure demo data').''; -html_print_input_hidden('update_config', 1); -html_print_table($table_aux); -echo '
    '; - -$actionButtons = []; - -$actionButtons[] = html_print_submit_button( - __('Create demo data'), - 'update_button', - false, - [ - 'icon' => 'update', - 'fixed_id' => 'btn-create-demo-data', - ], - true -); - -$actionButtons[] = html_print_submit_button( - __('Delete demo data'), - 'update_button', - false, - [ - 'icon' => 'delete', - 'mode' => 'secondary', - 'fixed_id' => 'btn-delete-demo-data', - ], - true -); - -echo ''; - -echo ''; ?> \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 5353a49557..d355abe41a 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -38,10 +38,16 @@ require $config['homedir'].'/include/functions_inventory.php'; require $config['homedir'].'/include/functions_custom_graphs.php'; require $config['homedir'].'/include/functions_reports.php'; +// Ensure script keeps running even if client-side of the AJAX request disconnected. +ignore_user_abort(true); + +set_time_limit(500); + $action = (string) get_parameter('action', null); if ($action === 'create_demo_data') { config_update_value('demo_data_load_progress', 0); + config_update_value('demo_data_load_status', '{}'); // Read agent ini files. $directories = [ @@ -56,22 +62,36 @@ if ($action === 'create_demo_data') { $demodata_directory = $config['homedir'].'/extras/demodata/'; - foreach ($directories as $directory) { + $adv_options_is_enabled = (bool) get_parameter('adv_options_is_enabled', false); + if ($adv_options_is_enabled === true) { + $enabled_items = get_parameter('enabled_items'); + $history_is_enabled = (bool) $enabled_items['enable_history']; + $days_hist_data = (int) get_parameter('days_hist_data', 15); + $interval = (int) get_parameter('interval', 300); + + $enabled_directories = array_intersect($directories, array_keys(array_filter($enabled_items))); + $enabled_directories[] = 'agents'; + } else { + $enabled_directories = $directories; + } + + foreach ($enabled_directories as $directory) { $directory_path = $demodata_directory.$directory; if (is_dir($directory_path)) { $files = scandir($directory_path); $files = array_diff($files, ['.', '..']); } + sort($files, (SORT_NATURAL | SORT_FLAG_CASE)); + foreach ($files as $file) { - $parsed_ini[$directory][] = parse_ini_file($directory_path.'/'.$file, true, INI_SCANNER_TYPED); + $parsed_ini[$directory][] = array_merge(['filename' => $file], parse_ini_file($directory_path.'/'.$file, true, INI_SCANNER_TYPED)); } } $total_agents_to_create = (int) get_parameter('agents_num', 0); - $enabled_items = get_parameter('enabled_items'); - $excluded_items = (int) array_count_values($enabled_items)[0]; - $total_items_count = (count($parsed_ini) - $excluded_items); + + $total_items_count = count($parsed_ini); if ($total_agents_to_create > 0) { $agents_to_create = 0; @@ -90,10 +110,20 @@ if ($action === 'create_demo_data') { $agent_created_total = 0; if ($total_agents_to_create > 0 && $agents_to_create > 0) { - while ($agent_created_total < $total_agents_to_create) { + while ($agent_created_total < ($total_agents_to_create - 1)) { + if (count($parsed_ini['agents']) === 0) { + register_error(DEMO_AGENT, __('No configuration files found or failed to parse files')); + break; + } + + ///$iter_agents_created = 0; + + // Get first server: general value for all created modules. . + $server_name = db_get_value('name' ,'tserver', 'id_server', 1); + // Traverse agent ini files and create agents. foreach ($parsed_ini['agents'] as $ini_agent_data) { - // Read blocks: agent data, modules, inventory, inventory values. + $filename = $ini_agent_data['filename']; $agent_data = $ini_agent_data['agent_data']; if (isset($agent_data['agents_number']) === true @@ -103,14 +133,28 @@ if ($action === 'create_demo_data') { continue; } + if (isset($agent_data['agent_name']) === false + || is_string($agent_data['agent_name']) === false + || isset($agent_data['agent_alias']) === false + || is_string($agent_data['agent_alias']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: name and/or alias is not specified or does not have a valid format. Skipping agent creation', $filename), + true + ); + continue; + } + $iter_agents_to_create = $agent_data['agents_number']; - if (($agent_created_total + $iter_agents_to_create) >= $total_agents_to_create) { + if (($agent_created_total + $iter_agents_to_create/* + $iter_agents_created*/) >= $total_agents_to_create) { // Total agents limit specified by user has been reached. break; } else { + ///hd($total_agents_to_create." - (".$agent_created_total." + ".$iter_agents_to_create." + ".$iter_agents_created.")", true); // Calculate max number of agents that can be created in this iteration until max number specified by user is reached. - $max_agents_to_limit = ($total_agents_to_create - ($agent_created_total + $iter_agents_to_create)); + $max_agents_to_limit = ($total_agents_to_create - ($agent_created_total + $iter_agents_to_create/* + $iter_agents_created*/)); } $modules_data = $ini_agent_data['modules']; @@ -129,6 +173,11 @@ if ($action === 'create_demo_data') { if (isset($address_network) === false || is_string($address_network) === false) { // Agent address is not specified or not valid. + register_error( + DEMO_AGENT, + __('Error in %s: address is not specified or does not have a valid format. Skipping agent creation', $filename), + true + ); continue; } @@ -142,10 +191,15 @@ if ($action === 'create_demo_data') { if ($id_os === false) { // Create OS if does not exist. $values = ['name' => $os_name]; - $id_os = (bool) db_process_sql_insert('tconfig_os', $values); + $id_os = db_process_sql_insert('tconfig_os', $values); if ($id_os === false) { // Could not create OS. Skip agent creation. + register_error( + DEMO_AGENT, + __('Error in %s: failed to create the specified operating system. Skipping agent creation', $filename), + true + ); continue; } @@ -166,6 +220,9 @@ if ($action === 'create_demo_data') { } $group_id = get_group_or_create_demo_group($group_name); + $agent_interval = ($adv_options_is_enabled === true) ? $interval : 300; + + $iter_agents_created = 0; // Create agents (remaining number of agents to reach number specified by user). for ($i = 0; $i < min($iter_agents_to_create, $max_agents_to_limit); $i++) { @@ -178,13 +235,18 @@ if ($action === 'create_demo_data') { reset($os_versions); } + $values = [ + 'server_name' => $server_name + ]; + + $create_alias = $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_name']] + 1); $created_agent_id = agents_create_agent( - $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_name']] + 1), + $create_alias, $group_id, // Default interval. - 300, + $agent_interval, $next_ip_address, - false, + $values, true, $id_os, $os_version @@ -201,31 +263,27 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback agent creation if could not be registered in tdemo_data. db_process_sql_delete('tagente', ['id_agente' => $created_agent_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create agent %s', $filename, $create_alias), + true + ); + continue; } } else { // Could not create agent. Skip. + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create agent %s', $filename, $create_alias), + true + ); continue; } $agents_created_count[$agent_data['agent_name']]++; - - // Calculate progress. - $percentage_inc = (100 / ($agents_to_create * $total_items_count)); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); + $iter_agents_created++; // Create agent modules. $module_access_idx = 1; @@ -244,12 +302,37 @@ if ($action === 'create_demo_data') { break; } - $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + if (isset($modules_array['name']) === false + || is_string($modules_array['name']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: all modules must have a name. Skipping creation of item with index %d', $filename, ($module_access_idx - 1)), + true + ); + continue; + } if (isset($modules_array['type']) === false || is_string($modules_array['type']) === false ) { // Module type not defined. + register_error( + DEMO_AGENT, + __('Error in %s: module type is not specified or does not have a valid format (%s). Skipping creation of item with index %d', $filename, ($module_access_idx - 1)), + true + ); + continue; + } + + $id_tipo = db_get_value_filter('id_tipo', 'ttipo_modulo', ['nombre' => $modules_array['type']]); + + if (!($id_tipo > 0)) { + register_error( + DEMO_AGENT, + __('Error in %s: the specified module type is not defined in the system (%s). Skipping creation of item with index %d', $filename, $modules_array['name'], ($module_access_idx - 1)), + true + ); continue; } @@ -264,6 +347,7 @@ if ($action === 'create_demo_data') { 'descripcion' => $module_description, 'id_tipo_modulo' => $id_tipo, 'id_module_group' => ($modules_array['group'] ?? 0), + 'id_modulo' => 1, ]; $created_mod_id = modules_create_agent_module( @@ -284,6 +368,13 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback agent module creation if could not be registered in tdemo_data. db_process_sql_delete('tagente_modulo', ['id_agente_modulo' => $created_mod_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create module with index %d', $filename, ($module_access_idx - 1)), + true + ); + continue; } @@ -292,8 +383,11 @@ if ($action === 'create_demo_data') { $date_time = new DateTime(); $current_date_time = $date_time->format('Y-m-d H:i:s'); - $back_periods = 10; - $period_mins = 5; + $back_periods = 1; + + if ($adv_options_is_enabled === true && $history_is_enabled === true) { + $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); + } $utimestamp = time(); @@ -336,14 +430,64 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback demo item creation if could not be registered in tdemo_data. db_process_sql_delete('tagente_datos', ['id_agente_modulo' => $created_data_id]); - continue; } } - $utimestamp -= 300; + if ($p === 0) { + $status_values = [ + 'datos' => $data, + 'estado' => 0, + 'known_status' => 0, + 'timestamp' => $current_date_time, + 'utimestamp' => $utimestamp, + 'last_status' => 0, + 'last_known_status' => 0, + ]; + + $status_id = db_get_value( + 'id_agente_estado', + 'tagente_estado', + 'id_agente_modulo', + $created_mod_id + ); + + $update_status_res = db_process_sql_update( + 'tagente_estado', + $status_values, + ['id_agente_estado' => $status_id] + ); + + if ($update_status_res !== false) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $status_id, + 'table_name' => 'tagente_estado', + ]; + + $result = db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tagente_estado', ['id_agente_estado' => $status_id]); + } + } + } + + if ($adv_options_is_enabled === true && $history_is_enabled === true) { + $utimestamp -= $interval; + } } + } else { + // Could not create module. + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create module with index %d', $filename, ($module_access_idx - 1)), + true + ); + + continue; } - }; + } // Create inventory modules. $module_access_idx = 1; @@ -365,6 +509,29 @@ if ($action === 'create_demo_data') { break; } + if (isset($modules_array['name']) === false + || is_string($modules_array['name']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: all inventory modules must have a name. Skipping creation of item with index %d', $filename, ($module_access_idx - 1)), + true + ); + } + + if (isset($modules_array['format']) === false + || is_string($modules_array['format']) === false + || isset($modules_array['values']) === false + || is_string($modules_array['values']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: one or more required fields (format, values) were not found for inventory module %s. Skipping creation of item with index %d', $filename, $modules_array['name'], ($module_access_idx - 1)), + true + ); + continue; + } + $values = [ 'name' => $modules_array['name'], 'data_format' => $modules_array['format'], @@ -384,8 +551,23 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback inventory module if could not be registered in tdemo_data. db_process_sql_delete('tmodule_inventory', ['id_module_inventory' => $created_inventory_mod_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create inventory module with index %d', $filename, ($module_access_idx - 1)), + true + ); + continue; } + } else { + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create inventory module with index %d', $filename, ($module_access_idx - 1)), + true + ); + + continue; } // Insert in tagent_module_inventory and tagente_datos_inventory. @@ -472,8 +654,12 @@ if ($action === 'create_demo_data') { // Create traps. $date_time = new DateTime(); $current_date_time = $date_time->format('Y-m-d H:i:s'); - $back_periods = 10; - $period_mins = 5; + $back_periods = 1; + + if ($adv_options_is_enabled === true && $history_is_enabled === true) { + $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); + } + $utimestamp = time(); for ($p = 0; $p < $back_periods; $p++) { @@ -492,18 +678,27 @@ if ($action === 'create_demo_data') { break; } - $create_trap = false; - if (isset($traps_array['chance_percent']) === false) { - // Chance percent must be specified. + if (isset($traps_array['oid']) === false || is_string($traps_array['oid']) === false + || isset($traps_array['value']) === false || is_string($traps_array['value']) === false + || isset($traps_array['snmp_type']) === false || is_string($traps_array['snmp_type']) === false + || isset($traps_array['chance_percent']) === false || is_string($traps_array['chance_percent']) === false + ) { + register_error( + DEMO_AGENT, + __('Error in %s: all traps must have the following required fields: oid, value, snmp_type, chance_percent. Skipping creation of item with index %d', $filename, ($trap_access_idx - 1)), + true + ); continue; - } else { - $trap_creation_prob = (int) $traps_array['chance_percent']; + } - if ($trap_creation_prob > 0) { - $randomNumber = rand(1, 100); - if ($randomNumber <= $trap_creation_prob) { - $create_trap = true; - } + $create_trap = false; + + $trap_creation_prob = (int) $traps_array['chance_percent']; + + if ($trap_creation_prob > 0) { + $randomNumber = rand(1, 100); + if ($randomNumber <= $trap_creation_prob) { + $create_trap = true; } } @@ -511,16 +706,11 @@ if ($action === 'create_demo_data') { continue; } - if (isset($traps_array['value']) === false || is_string($traps_array['value']) === false) { - // Trap value must be specified. - continue; - } else { - $parsed = explode(';', $traps_array['values']); + $parsed = explode(';', $traps_array['values']); - $data = ''; - if ((string) $parsed[0] === 'RANDOM') { - $data = rand($parsed[1], $parsed[2]); - } + $data = ''; + if ((string) $parsed[0] === 'RANDOM') { + $data = rand($parsed[1], $parsed[2]); } $values = [ @@ -544,16 +734,33 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback inventory module if could not be registered in tdemo_data. db_process_sql_delete('ttrap', ['id_module_inventory' => $created_trap_id]); + + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create trap with index %d', $filename, ($trap_access_idx - 1)), + true + ); + continue; } + } else { + register_error( + DEMO_AGENT, + __('Uncaught error (source %s): could not create trap with index %d', $filename, ($trap_access_idx - 1)), + true + ); } } - $date_time->sub(new DateInterval("PT{$period_mins}M")); - $current_date_time = $date_time->format('Y-m-d H:i:s'); - $utimestamp -= 300; + if ($adv_options_is_enabled === true && $history_is_enabled === true) { + $date_time->sub(new DateInterval("PT{$interval}S")); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $utimestamp -= $interval; + } } } + + update_progress($total_items_count, $total_agents_to_create, $iter_agents_created); } $agent_created_total = array_sum($agents_created_count); @@ -563,459 +770,40 @@ if ($action === 'create_demo_data') { break; } } + + update_item_checked(DEMO_AGENT); } } - if ((bool) $enabled_items['enable_nm'] === true) { - // Create network maps. - foreach ($parsed_ini['network_maps'] as $ini_nm_data) { - $map_data = $ini_nm_data['map_data']; - $map_items = $ini_nm_data['map_items']; - - $nm_name = $map_data['name']; - $nm_group = $map_data['group']; - $nm_description = $map_data['description']; - $nm_node_radius = $map_data['node_radius']; - - $nm_id_group = get_group_or_create_demo_group($nm_group); - - if ($nm_id_group === false) { - // Network map could not be created. Skip network map creation. - continue; - } - - $values = []; - $new_map_filter = []; - $new_map_filter['dont_show_subgroups'] = 0; - $new_map_filter['node_radius'] = $nm_node_radius; - $new_map_filter['x_offs'] = 0; - $new_map_filter['y_offs'] = 0; - $new_map_filter['z_dash'] = '0.5'; - $new_map_filter['node_sep'] = '0.25'; - $new_map_filter['rank_sep'] = '0.25'; - $new_map_filter['mindist'] = 1; - $new_map_filter['kval'] = '0.3'; - $values['filter'] = json_encode($new_map_filter); - $values['description'] = $nm_description; - $values['id_group'] = $nm_id_group; - $values['name'] = $nm_name; - - $id_map = db_process_sql_insert('tmap', $values); - - if ($id_map > 0) { - // Register created map in tdemo_data. - $values = [ - 'item_id' => $id_map, - 'table_name' => 'tmap', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback demo item creation if could not be registered in tdemo_data. - db_process_sql_delete('tmap', ['id' => $id_map]); - continue; - } - } else { - // Network map group could not be created. Skip creation of map. - continue; - } - - if (count($map_items) > 0) { - $item_access_idx = 1; - - while (1) { - $items_array = []; - foreach ($map_items as $key => $value) { - $items_array[$key] = ($value[$item_access_idx] ?? null); - } - - $item_access_idx++; - - $test_empty_array = array_filter($items_array); - - if (empty($test_empty_array) === true) { - break; - } - - $item_values = []; - - $item_values['id_map'] = $id_map; - - if (isset($items_array['agent_name']) === true || is_string($items_array['agent_name']) === false) { - $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente', 'id_os', 'alias']); - - $matched_agent = $matched_agents[0]['id_agente']; - $alias = $matched_agents[0]['alias']; - if (isset($matched_agent) === true && $matched_agent > 0) { - $item_values['source_data'] = $matched_agent; - if (isset($matched_agents[0]['id_agente']) === true && $matched_agents[0]['id_os']) { - $agent_os_id = $matched_agents[0]['id_os']; - $icon_name = db_get_value('icon_name', 'tconfig_os', 'id_os', $agent_os_id); - } - } else { - // Skip report item creation if agent does not exist. - continue; - } - } else { - continue; - } - - $style_values = [ - 'shape' => 'circle', - 'image' => 'images/networkmap/'.$icon_name, - 'width' => null, - 'height' => null, - 'label' => $alias, - ]; - - $item_values['style'] = json_encode($style_values); - $item_values['x'] = (isset($items_array['x']) === true) ? $items_array['x'] : '0'; - $item_values['y'] = (isset($items_array['y']) === true) ? $items_array['y'] : '0'; - - $created_nm_item_id = db_process_sql_insert('titem', $item_values); - - if ($created_nm_item_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_nm_item_id, - 'table_name' => 'titem', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback demo item if could not be registered in tdemo_data. - db_process_sql_delete('titem', ['id' => $created_nm_item_id]); - continue; - } - } - } - } - - // Calculate progress. - $percentage_inc = (100 / $total_items_count); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); - } - } - - if ((bool) $enabled_items['enable_cg'] === true) { - // Create graphs. - foreach ($parsed_ini['graphs'] as $ini_graph_data) { - // Constant graph types. - $graph_types = [ - 'line' => 2, - 'area' => 0, - 's_line' => 3, - 's_area' => 1, - 'h_bars' => 6, - 'v_bars' => 7, - 'gauge' => 5, - 'pie' => 8, - ]; - - $graph_data = $ini_graph_data['graph_data']; - $graph_items = $ini_graph_data['graph_items']; - - $graph_name = $graph_data['name']; - $graph_group = $graph_data['group']; - $graph_description = $graph_data['description']; - $graph_type = (isset($graph_types[$graph_data['type']]) === true) ? $graph_types[$graph_data['type']] : 0; - $graph_periodicity = $graph_data['periodicity']; - - $graph_id_group = get_group_or_create_demo_group($graph_group); - - if ($graph_id_group === false) { - // Group could not be created. Skip graph creation. - continue; - } - - $values = []; - $values['description'] = $graph_description; - $values['id_group'] = $graph_id_group; - $values['name'] = $graph_name; - $values['period'] = $graph_periodicity; - $values['stacked'] = $graph_type; - - $id_graph = db_process_sql_insert('tgraph', $values); - - if ($id_graph > 0) { - // Register created graph in tdemo_data. - $values = [ - 'item_id' => $id_graph, - 'table_name' => 'tgraph', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback graph creation if could not be registered in tdemo_data. - db_process_sql_delete('tgraph', ['id_graph' => $id_graph]); - continue; - } - } else { - // Graph could not be created. Skip creation of graph. - continue; - } - - if (count($graph_items) > 0) { - $item_access_idx = 1; - - while (1) { - $items_array = []; - foreach ($graph_items as $key => $value) { - $items_array[$key] = ($value[$item_access_idx] ?? null); - } - - $item_access_idx++; - - $test_empty_array = array_filter($items_array); - - if (empty($test_empty_array) === true) { - break; - } - - $item_values = []; - - if (isset($items_array['agent_name']) === false || is_string($items_array['agent_name']) === false) { - // Agent must be defined. Skip graph item creation. - continue; - } - - if (isset($items_array['module']) === false || is_string($items_array['module']) === false) { - // Module must be defined. Skip graph item creation. - continue; - } - - $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); - $agent_id = $matched_agents[0]['id_agente']; - - if (!($agent_id > 0)) { - continue; - } - - $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); - - $module_id = $module_row['id_agente_modulo']; - - if (!($module_id > 0)) { - continue; - } - - $item_values = [ - 'id_graph' => $id_graph, - 'id_agent_module' => $module_id, - ]; - - $created_graph_item_id = db_process_sql_insert('tgraph_source', $item_values); - - if ($created_graph_item_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_graph_item_id, - 'table_name' => 'tgraph_source', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback demo item if could not be registered in tdemo_data. - db_process_sql_delete('tgraph_source', ['id_gs' => $created_graph_item_id]); - continue; - } - } - } - } - - // Calculate progress. - $percentage_inc = (100 / $total_items_count); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); - } - } - - if ((bool) $enabled_items['enable_rep'] === true) { - // Create reports. - foreach ($parsed_ini['reports'] as $ini_report_data) { - $report_data = $ini_report_data['report_data']; - $report_items = $ini_report_data['report_items']; - - $group_id = get_group_or_create_demo_group($report_data['group']); - - if ($group_id === false) { - // Could not create group. Skip report creation. - continue; - } - - $report_values = []; - $report_values['id_group'] = $group_id; - $report_values['name'] = $report_data['name']; - $report_values['description'] = $report_data['description']; - - $created_report_id = db_process_sql_insert('treport', $report_values); - - if ($created_report_id > 0) { - // Register created graph in tdemo_data. - $values = [ - 'item_id' => $created_report_id, - 'table_name' => 'treport', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback report creation if could not be registered in tdemo_data. - db_process_sql_delete('treport', ['id_report' => $created_report_id]); - continue; - } - } else { - // Report could not be created. Skip creation of map. - continue; - } - - if (count($report_items) > 0) { - $item_access_idx = 1; - - while (1) { - $items_array = []; - foreach ($report_items as $key => $value) { - $items_array[$key] = ($value[$item_access_idx] ?? null); - } - - $item_access_idx++; - - $test_empty_array = array_filter($items_array); - - if (empty($test_empty_array) === true) { - break; - } - - $item_values = []; - - $item_values['id_report'] = $created_report_id; - - if (isset($items_array['agent_name']) === true) { - if (is_string($items_array['module']) === false) { - continue; - } - - $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); - - $matched_agent = $matched_agents[0]['id_agente']; - if (isset($matched_agent) === true && $matched_agent > 0) { - $item_values['id_agent'] = $matched_agent; - } else { - // Skip report item creation if agent does not exist. - continue; - } - } - - if (isset($items_array['module']) === true) { - if (is_string($items_array['module']) === false) { - // Module wrong data type read. Skip. - continue; - } - - if ($item_values['id_agent'] > 0) { - $module_id = db_get_value_sql('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "'.io_safe_input($items_array['module']).'" AND id_agente = '.$item_values['id_agent']); - - if ($module_id > 0) { - $item_values['id_agent_module'] = $module_id; - } else { - // Skip report item creation if agent module does not exist. - continue; - } - } else { - continue; - } - } - - if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true) { - $id_custom_graph = reset(custom_graphs_search('', $items_array['graph_name']))['id_graph']; - - if ($id_custom_graph > 0) { - $item_values['id_gs'] = $id_custom_graph; - } else { - // Skip report item creation if specified custom graph does not exist. - continue; - } - } - - $created_report_item_id = db_process_sql_insert('treport_content', $item_values); - - if ($created_report_item_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_report_item_id, - 'table_name' => 'treport_content', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback report item if could not be registered in tdemo_data. - db_process_sql_delete('treport_content', ['id_rc' => $created_report_item_id]); - continue; - } - } - } - } - - // Calculate progress. - $percentage_inc = (100 / $total_items_count); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); - } - } - - if ((bool) $enabled_items['enable_services'] === true) { + $services_count = count($parsed_ini['services']); + if ($services_count > 0) { // Create services. foreach ($parsed_ini['services'] as $ini_service_data) { + $filename = $ini_service_data['filename']; $service_data = $ini_service_data['service_data']; $service_items = $ini_service_data['service_items']; // Check for mandatory fields. if (isset($service_data['name']) === false + || is_string($service_data['name']) === false || isset($service_data['group']) === false + || is_string($service_data['group']) === false ) { + register_error( + DEMO_SERVICE, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping service creation', $filename) + ); continue; } $id_group = get_group_or_create_demo_group($service_data['group']); if ($id_group === false) { - // Group could not be created. Skip graph creation. + // Group could not be created. Skip service creation. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); continue; } @@ -1041,10 +829,21 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback service creation if could not be registered in tdemo_data. db_process_sql_delete('tservice', ['id' => $created_service_id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service %s', $filename, $service_values['name']) + ); + continue; } } else { // Service could not be created. Skip creation of map. + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service %s', $filename, $service_values['name']) + ); + continue; } @@ -1066,6 +865,10 @@ if ($action === 'create_demo_data') { if (isset($items_array['type']) === false) { // Service element type must be specified. + register_error( + DEMO_SERVICE, + __('Error in %s: all service items must have the following required fields: type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); continue; } @@ -1077,6 +880,10 @@ if ($action === 'create_demo_data') { if (in_array($element_type, ['agent', 'module', 'dynamic', 'service']) === false) { // Skip element creation if type not valid. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified type of service item is not valid. All service items must have one of the following types: agent, module, dynamic, service. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); continue; } @@ -1089,6 +896,10 @@ if ($action === 'create_demo_data') { $element_values['id_agent'] = $matched_agent; } else { // Skip element creation if agent does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); continue; } } @@ -1101,6 +912,10 @@ if ($action === 'create_demo_data') { $element_values['id_agente_modulo'] = $module_id; } else { // Skip element creation if agent module does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified agent module does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['module'], ($item_access_idx - 1)) + ); continue; } } else { @@ -1157,6 +972,10 @@ if ($action === 'create_demo_data') { $element_values['id_service_child'] = $service_id; } else { // Skip element creation if specified service does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified service does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['service_name'], ($item_access_idx - 1)) + ); continue; } } else { @@ -1178,83 +997,118 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback service element if could not be registered in tdemo_data. db_process_sql_delete('tservice_element', ['id' => $id]); + + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; } + } else { + register_error( + DEMO_SERVICE, + __('Uncaught error (source %s): could not create service item with index %d', $filename, ($item_access_idx - 1)) + ); } } } - - // Calculate progress. - $percentage_inc = (100 / $total_items_count); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); } + + update_progress($total_items_count, $services_count); + update_item_checked(DEMO_SERVICE); + } else { + register_error(DEMO_SERVICE, __('No configuration files found or failed to parse files')); } - if ((bool) $enabled_items['enable_dashboards'] === true) { - // Create dashboards. - foreach ($parsed_ini['dashboards'] as $ini_data) { - $data = $ini_data['dashboard_data']; - $items = $ini_data['dashboard_items']; + $nm_count = count($parsed_ini['network_maps']); + if ($nm_count > 0) { + // Create network maps. + foreach ($parsed_ini['network_maps'] as $ini_nm_data) { + $filename = $ini_nm_data['filename']; + $map_data = $ini_nm_data['map_data']; + $map_items = $ini_nm_data['map_items']; - // Check for mandatory fields. - if (isset($data['name']) === false - || isset($data['group']) === false + if (isset($map_data['name']) === false + || is_string($map_data['name']) === false + || isset($map_data['group']) === false + || is_string($map_data['group']) === false ) { - // Name and group fields must be specified for dashbaord. + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping network map creation', $filename) + ); continue; } - $id_group = get_group_or_create_demo_group($data['group']); + $nm_name = $map_data['name']; + $nm_group = $map_data['group']; + $nm_description = (isset($map_data['description']) === true) ? $map_data['description'] : ''; + $nm_node_radius = (isset($map_data['node_radius']) === true) ? $map_data['node_radius'] : '40'; - if ($id_group === false) { - // Group could not be created. Skip dashboard creation. + $nm_id_group = get_group_or_create_demo_group($nm_group); + + if ($nm_id_group === false) { + // Group could not be created. Skip network map creation. + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); continue; } - $insert_values = []; + $values = []; + $new_map_filter = []; + $new_map_filter['dont_show_subgroups'] = 0; + $new_map_filter['node_radius'] = $nm_node_radius; + $new_map_filter['x_offs'] = 0; + $new_map_filter['y_offs'] = 0; + $new_map_filter['z_dash'] = '0.5'; + $new_map_filter['node_sep'] = '0.25'; + $new_map_filter['rank_sep'] = '0.25'; + $new_map_filter['mindist'] = 1; + $new_map_filter['kval'] = '0.3'; + $values['filter'] = json_encode($new_map_filter); + $values['description'] = $nm_description; + $values['id_group'] = $nm_id_group; + $values['name'] = $nm_name; - $insert_values['name'] = io_safe_input($data['name']); - $insert_values['id_group'] = $id_group; + $id_map = db_process_sql_insert('tmap', $values); - $created_id = db_process_sql_insert('tdashboard', $insert_values); - - if ($created_id > 0) { - // Register created item in tdemo_data. + if ($id_map > 0) { + // Register created map in tdemo_data. $values = [ - 'item_id' => $created_id, - 'table_name' => 'tdashboard', + 'item_id' => $id_map, + 'table_name' => 'tmap', ]; $result = (bool) db_process_sql_insert('tdemo_data', $values); if ($result === false) { // Rollback demo item creation if could not be registered in tdemo_data. - db_process_sql_delete('tdashboard', ['id' => $created_id]); + db_process_sql_delete('tmap', ['id' => $id_map]); + + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map %s', $filename, $nm_name) + ); + continue; } } else { - // Dashboard could not be created. Skip creation of item. + // Network map group could not be created. Skip creation of map. + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map %s', $filename, $nm_name) + ); continue; } - if (count($items) > 0) { + if (count($map_items) > 0) { $item_access_idx = 1; - $order = -1; + while (1) { $items_array = []; - foreach ($items as $key => $value) { + foreach ($map_items as $key => $value) { $items_array[$key] = ($value[$item_access_idx] ?? null); } @@ -1266,245 +1120,461 @@ if ($action === 'create_demo_data') { break; } - if (isset($items_array['type']) === false || isset($items_array['title']) === false) { - // All dashboard widgets must have a type and a title. - continue; - } + $item_values = []; - // Get ID of widget type. Skip if it does not exist. - $type_id = db_get_value('id', 'twidget', 'unique_name', $items_array['type']); + $item_values['id_map'] = $id_map; - if (!($type_id > 0)) { - continue; - } + if (isset($items_array['agent_name']) === true || is_string($items_array['agent_name']) === false) { + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente', 'id_os', 'alias']); - $title = io_safe_input($items_array['title']); - - if ($items_array['type'] === 'single_graph') { - if (isset($items_array['agent_name']) === false - || isset($items_array['module']) === false - ) { - // The above fields are required for this item. - continue; - } - - $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); - $agent_id = $matched_agents[0]['id_agente']; - - if (!($agent_id > 0)) { - continue; - } - - $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); - - $module_id = $module_row['id_agente_modulo']; - - if (!($module_id > 0)) { - continue; - } - - $element_values = []; - - $options_data = [ - 'title' => $title, - 'background' => '#ffffff', - 'agentId' => "$agent_id", - 'metaconsoleId' => 0, - 'moduleId' => "$module_id", - 'period' => (isset($items_array['interval']) === false) ? $items_array['interval'] : '86400', - 'showLegend' => 1, - 'projection_switch' => false, - 'period_projection' => '300', - ]; - - $order++; - } - - if ($items_array['type'] === 'custom_graph') { - if (isset($items_array['graph_name']) === false - || isset($items_array['graph_type']) === false - ) { - // The above fields are required for this item. - continue; - } - - // Try to get graph and skip if not exists. - $id_graph = db_get_value('id_graph', 'tgraph', 'name', $items_array['graph_name']); - - if (!($id_graph > 0)) { - continue; - } - - $graph_types = [ - 'line' => 2, - 'area' => 0, - 's_line' => 3, - 's_area' => 1, - 'h_bars' => 6, - 'v_bars' => 7, - 'gauge' => 5, - 'pie' => 8, - ]; - - if (isset($graph_types[$items_array['graph_type']]) === true) { - $graph_type_id = $items_array['graph_type']; + $matched_agent = $matched_agents[0]['id_agente']; + $alias = $matched_agents[0]['alias']; + if (isset($matched_agent) === true && $matched_agent > 0) { + $item_values['source_data'] = $matched_agent; + if (isset($matched_agents[0]['id_agente']) === true && $matched_agents[0]['id_os']) { + $agent_os_id = $matched_agents[0]['id_os']; + $icon_name = db_get_value('icon_name', 'tconfig_os', 'id_os', $agent_os_id); + } } else { - // Specified graph type is not a valid one. + // Skip report item creation if agent does not exist. + + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + continue; } + } else { + register_error( + DEMO_NETWORK_MAP, + __('Error in %s: all network map items must have the following required fields: agent_name. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); - $element_values = []; - - $options_data = [ - 'title' => $title, - 'background' => '#ffffff', - 'id_graph' => $id_graph, - 'type' => $graph_type_id, - 'period' => (isset($items_array['interval']) === false) ? $items_array['interval'] : 86400, - 'showLegend' => 1, - ]; - - $order++; + continue; } - if ($items_array['type'] === 'reports') { - if (isset($items_array['report_name']) === false) { - // The above fields are required for this item. - continue; - } - - $id_report = reports_get_reports(['name' => $items_array['report_name']], ['id_report'])[0]['id_report']; - - if (!($id_report > 0)) { - continue; - } - - $element_values = []; - - $options_data = [ - 'title' => $title, - 'background' => '#ffffff', - 'reportId' => $id_report, - ]; - - $order++; - } - - if ($items_array['type'] === 'network_map') { - if (isset($items_array['map_name']) === false) { - // The above fields are required for this item. - continue; - } - - $id_map = db_get_value('id', 'tmap', 'name', $items_array['map_name']); - - if (!($id_map > 0)) { - continue; - } - - $element_values = []; - - $options_data = [ - 'title' => $title, - 'background' => '#ffffff', - 'networkmapId' => "$id_map", - 'xOffset' => '0', - 'yOffset' => '0', - 'zoomLevel' => 0.5, - ]; - - $order++; - } - - if ($items_array['type'] === 'service_map') { - if (isset($items_array['service_name']) === false) { - // The above fields are required for this item. - continue; - } - - $services = services_get_services(['name' => $items_array['service_name']]); - - $service_id = $services[0]['id']; - - if (!($service_id > 0)) { - continue; - } - - $element_values = []; - - $options_data = [ - 'title' => $title, - 'background' => '#ffffff', - 'serviceId' => "$service_id", - 'sunburst' => 0, - ]; - - $order++; - } - - $item_x = $items_array['x']; - $item_y = $items_array['y']; - $item_width = $items_array['width']; - $item_height = $items_array['height']; - - $position_data = [ - 'x' => (isset($items_array['x']) === false) ? "$item_x" : "0", - 'y' => (isset($items_array['y']) === false) ? "$item_y" : "0", - 'width' => (isset($items_array['width']) === false) ? "$item_width" : "4", - 'height' => (isset($items_array['height']) === false) ? "$item_height" : "4", + $style_values = [ + 'shape' => 'circle', + 'image' => 'images/networkmap/'.$icon_name, + 'width' => null, + 'height' => null, + 'label' => $alias, ]; - $element_values = [ - 'position' => json_encode($position_data), - 'options' => json_encode($options_data), - 'order' => $order, - 'id_dashboard' => $created_id, - 'id_widget' => $type_id, - 'prop_width' => 0.32, - 'prop_height' => 0.32, - ]; + $item_values['style'] = json_encode($style_values); + $item_values['x'] = (isset($items_array['x']) === true) ? $items_array['x'] : '0'; + $item_values['y'] = (isset($items_array['y']) === true) ? $items_array['y'] : '0'; - $id = db_process_sql_insert('twidget_dashboard', $element_values); + $created_nm_item_id = db_process_sql_insert('titem', $item_values); - if ($id > 0) { + if ($created_nm_item_id > 0) { // Register created demo item in tdemo_data. $values = [ - 'item_id' => $id, - 'table_name' => 'twidget_dashboard', + 'item_id' => $created_nm_item_id, + 'table_name' => 'titem', ]; $result = (bool) db_process_sql_insert('tdemo_data', $values); if ($result === false) { // Rollback demo item if could not be registered in tdemo_data. - db_process_sql_delete('twidget_dashboard', ['id' => $id]); + db_process_sql_delete('titem', ['id' => $created_nm_item_id]); + + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; } + } else { + register_error( + DEMO_NETWORK_MAP, + __('Uncaught error (source %s): could not create network map item with index %d', $filename, ($item_access_idx - 1)) + ); } } } - - // Calculate progress. - $percentage_inc = (100 / $total_items_count); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); } + + update_progress($total_items_count, $nm_count); + update_item_checked(DEMO_NETWORK_MAP); + } else { + register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files')); } - if ((bool) $enabled_items['enable_vc'] === true) { + $cg_count = count($parsed_ini['graphs']); + if ($cg_count > 0) { + // Create graphs. + foreach ($parsed_ini['graphs'] as $ini_graph_data) { + // Constant graph types. + $graph_types = [ + 'line' => 2, + 'area' => 0, + 's_line' => 3, + 's_area' => 1, + 'h_bars' => 6, + 'v_bars' => 7, + 'gauge' => 5, + 'pie' => 8, + ]; + + $filename = $ini_graph_data['filename']; + $graph_data = $ini_graph_data['graph_data']; + $graph_items = $ini_graph_data['graph_items']; + + $graph_name = $graph_data['name']; + $graph_group = $graph_data['group']; + $graph_description = $graph_data['description']; + $graph_type = (isset($graph_types[$graph_data['type']]) === true) ? $graph_types[$graph_data['type']] : 0; + $graph_periodicity = $graph_data['periodicity']; + + $graph_id_group = get_group_or_create_demo_group($graph_group); + + if ($graph_id_group === false) { + // Group could not be created. Skip graph creation. + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); + continue; + } + + $values = []; + $values['description'] = $graph_description; + $values['id_group'] = $graph_id_group; + $values['name'] = $graph_name; + $values['period'] = $graph_periodicity; + $values['stacked'] = $graph_type; + + $id_graph = db_process_sql_insert('tgraph', $values); + + if ($id_graph > 0) { + // Register created graph in tdemo_data. + $values = [ + 'item_id' => $id_graph, + 'table_name' => 'tgraph', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback graph creation if could not be registered in tdemo_data. + db_process_sql_delete('tgraph', ['id_graph' => $id_graph]); + + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph %s', $filename, $graph_name) + ); + + continue; + } + } else { + // Graph could not be created. Skip creation of graph. + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph %s', $filename, $graph_name) + ); + continue; + } + + if (count($graph_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($graph_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + if (isset($items_array['agent_name']) === false + || is_string($items_array['agent_name']) === false + || isset($items_array['module']) === false + || is_string($items_array['module']) === false + ) { + // Agent and module must be defined. Skip graph item creation. + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: one or more required fields (agent_name, module) were not found for custom graph item with index %d. Skipping creation of item with index %d', $filename, $item_access_idx, ($item_access_idx - 1)) + ); + continue; + } + + + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + continue; + } + + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + register_error( + DEMO_CUSTOM_GRAPH, + __('Error in %s: the specified agent module does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['module'], ($item_access_idx - 1)) + ); + continue; + } + + $item_values = [ + 'id_graph' => $id_graph, + 'id_agent_module' => $module_id, + ]; + + $created_graph_item_id = db_process_sql_insert('tgraph_source', $item_values); + + if ($created_graph_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_graph_item_id, + 'table_name' => 'tgraph_source', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('tgraph_source', ['id_gs' => $created_graph_item_id]); + + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_CUSTOM_GRAPH, + __('Uncaught error (source %s): could not create custom graph item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $cg_count); + update_item_checked(DEMO_CUSTOM_GRAPH); + } else { + register_error(DEMO_CUSTOM_GRAPH, __('No configuration files found or failed to parse files')); + } + + $rep_count = count($parsed_ini['reports']); + if ($rep_count > 0) { + // Create reports. + foreach ($parsed_ini['reports'] as $ini_report_data) { + $filename = $ini_report_data['filename']; + $report_data = $ini_report_data['report_data']; + $report_items = $ini_report_data['report_items']; + + // Check for mandatory fields. + if (isset($report_data['name']) === false + || is_string($report_data['name']) === false + || isset($report_data['group']) === false + || is_string($report_data['group']) === false + ) { + register_error( + DEMO_REPORT, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping custom report creation', $filename) + ); + } + + $group_id = get_group_or_create_demo_group($report_data['group']); + + if ($group_id === false) { + // Could not create group. Skip report creation. + register_error( + DEMO_REPORT, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping service creation', $filename) + ); + continue; + } + + $report_values = []; + $report_values['id_group'] = $group_id; + $report_values['name'] = $report_data['name']; + $report_values['description'] = $report_data['description']; + + $created_report_id = db_process_sql_insert('treport', $report_values); + + if ($created_report_id > 0) { + // Register created graph in tdemo_data. + $values = [ + 'item_id' => $created_report_id, + 'table_name' => 'treport', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report creation if could not be registered in tdemo_data. + db_process_sql_delete('treport', ['id_report' => $created_report_id]); + + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report %s', $filename, $report_data['name']) + ); + + continue; + } + } else { + // Report could not be created. Skip creation of map. + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report %s', $filename, $report_data['name']) + ); + continue; + } + + if (count($report_items) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($report_items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($items_array['type']) === false + || is_string($items_array['type']) === false) { + // All report items must have a type. + register_error( + DEMO_REPORT, + __('Error in %s: all custom report items must have the following required fields: type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + + $item_values = []; + + $item_values['id_report'] = $created_report_id; + + if (isset($items_array['agent_name']) === true) { + if (isset($items_array['module']) === false + || is_string($items_array['module']) === false + ) { + continue; + } + + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); + + $matched_agent = $matched_agents[0]['id_agente']; + if (isset($matched_agent) === true && $matched_agent > 0) { + $item_values['id_agent'] = $matched_agent; + } else { + // Skip report item creation if agent does not exist. + register_error( + DEMO_REPORT, + __('Error in %s: the specified agent does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['agent_name'], ($item_access_idx - 1)) + ); + continue; + } + } + + if (isset($items_array['module']) === true) { + if (is_string($items_array['module']) === false) { + // Module wrong data type read. Skip. + continue; + } + + if ($item_values['id_agent'] > 0) { + $module_id = db_get_value_sql('SELECT id_agente_modulo FROM tagente_modulo WHERE nombre = "'.io_safe_input($items_array['module']).'" AND id_agente = '.$item_values['id_agent']); + + if ($module_id > 0) { + $item_values['id_agent_module'] = $module_id; + } else { + // Skip report item creation if agent module does not exist. + register_error( + DEMO_REPORT, + __('Error in %s: the specified agent module does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['module'], ($item_access_idx - 1)) + ); + continue; + } + } else { + continue; + } + } + + if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true) { + $id_custom_graph = reset(custom_graphs_search('', $items_array['graph_name']))['id_graph']; + + if ($id_custom_graph > 0) { + $item_values['id_gs'] = $id_custom_graph; + } else { + // Skip report item creation if specified custom graph does not exist. + register_error( + DEMO_REPORT, + __('Error in %s: the specified custom graph does not exist in the system: %s. Skipping creation of item with index %d', $filename, $items_array['graph_name'], ($item_access_idx - 1)) + ); + continue; + } + } + + $created_report_item_id = db_process_sql_insert('treport_content', $item_values); + + if ($created_report_item_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_report_item_id, + 'table_name' => 'treport_content', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report item if could not be registered in tdemo_data. + db_process_sql_delete('treport_content', ['id_rc' => $created_report_item_id]); + + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $rep_count); + update_item_checked(DEMO_REPORT); + } else { + register_error(DEMO_REPORT, __('No configuration files found or failed to parse files')); + } + + $vc_count = count($parsed_ini['visual_consoles']); + if ($vc_count > 0) { // Create visual consoles. foreach ($parsed_ini['visual_consoles'] as $ini_data) { + $filename = $ini_data['filename']; $data = $ini_data['visual_console_data']; $items = $ini_data['visual_console_items']; @@ -1513,6 +1583,10 @@ if ($action === 'create_demo_data') { || isset($data['group']) === false ) { // Name and group fields must be specified for vc. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping visual console creation', $filename) + ); continue; } @@ -1520,6 +1594,10 @@ if ($action === 'create_demo_data') { if ($id_group === false) { // Group could not be created. Skip dashboard creation. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping visual console creation', $filename) + ); continue; } @@ -1545,10 +1623,20 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback demo item creation if could not be registered in tdemo_data. db_process_sql_delete('tlayout', ['id' => $created_id]); + + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console %s', $filename, $insert_values['name']) + ); + continue; } } else { - // Dashboard could not be created. Skip creation of item. + // VC could not be created. Skip creation of item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console %s', $filename, $insert_values['name']) + ); continue; } @@ -1570,6 +1658,10 @@ if ($action === 'create_demo_data') { if (isset($items_array['type']) === false) { // All visual console items must have a type. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: all visual console items must have the following required fields: type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); continue; } @@ -1585,6 +1677,10 @@ if ($action === 'create_demo_data') { // Get ID of item type. Skip if it does not exist. if (isset($types[$items_array['type']]) === false) { + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: the specified type is not a valid one. It must be one of the following values: static_image, module_graph, custom_graph, value, label, icon. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); continue; } @@ -1598,6 +1694,10 @@ if ($action === 'create_demo_data') { || is_string($items_array['image']) === false ) { // The above fields are required for this item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: image field must be specified for static image item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); continue; } @@ -1693,6 +1793,10 @@ if ($action === 'create_demo_data') { || is_string($items_array['image']) === false ) { // The above fields are required for this item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: image field must be specified for icon item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); continue; } @@ -1735,7 +1839,7 @@ if ($action === 'create_demo_data') { } if (isset($items_array['label']) === true) { - $element_values['label'] = io_safe_input($items_array['label']); + $element_values['label'] = io_safe_input($items_array['label']); } if (isset($items_array['label_position']) === true) { @@ -1771,29 +1875,307 @@ if ($action === 'create_demo_data') { if ($result === false) { // Rollback demo item if could not be registered in tdemo_data. db_process_sql_delete('tlayout_data', ['id' => $id]); + + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_VISUAL_CONSOLE, + __('Uncaught error (source %s): could not create visual console item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $vc_count); + update_item_checked(DEMO_VISUAL_CONSOLE); + } else { + register_error(DEMO_VISUAL_CONSOLE, __('No configuration files found or failed to parse files')); + } + + $dashboards_count = count($parsed_ini['dashboards']); + if ($dashboards_count > 0) { + // Create dashboards. + foreach ($parsed_ini['dashboards'] as $ini_data) { + $data = $ini_data['dashboard_data']; + $items = $ini_data['dashboard_items']; + + // Check for mandatory fields. + if (isset($data['name']) === false + || isset($data['group']) === false + ) { + // Name and group fields must be specified for dashbaord. + continue; + } + + $id_group = get_group_or_create_demo_group($data['group']); + + if ($id_group === false) { + // Group could not be created. Skip dashboard creation. + continue; + } + + $insert_values = []; + + $insert_values['name'] = io_safe_input($data['name']); + $insert_values['id_group'] = $id_group; + + $created_id = db_process_sql_insert('tdashboard', $insert_values); + + if ($created_id > 0) { + // Register created item in tdemo_data. + $values = [ + 'item_id' => $created_id, + 'table_name' => 'tdashboard', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tdashboard', ['id' => $created_id]); + continue; + } + } else { + // Dashboard could not be created. Skip creation of item. + continue; + } + + if (count($items) > 0) { + $item_access_idx = 1; + $order = -1; + while (1) { + $items_array = []; + foreach ($items as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + if (isset($items_array['type']) === false || isset($items_array['title']) === false) { + // All dashboard widgets must have a type and a title. + continue; + } + + // Get ID of widget type. Skip if it does not exist. + $type_id = db_get_value('id', 'twidget', 'unique_name', $items_array['type']); + + if (!($type_id > 0)) { + continue; + } + + $title = io_safe_input($items_array['title']); + $element_values = []; + + if ($items_array['type'] === 'single_graph') { + if (isset($items_array['agent_name']) === false + || isset($items_array['module']) === false + ) { + // The above fields are required for this item. + continue; + } + + $matched_agents = agents_get_agents(['nombre' => $items_array['agent_name']], ['id_agente']); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'agentId' => "$agent_id", + 'metaconsoleId' => 0, + 'moduleId' => "$module_id", + 'period' => (isset($items_array['interval']) === false) ? $items_array['interval'] : '86400', + 'showLegend' => 1, + 'projection_switch' => false, + 'period_projection' => '300', + ]; + + $order++; + } + + if ($items_array['type'] === 'custom_graph') { + if (isset($items_array['graph_name']) === false + || isset($items_array['graph_type']) === false + ) { + // The above fields are required for this item. + continue; + } + + // Try to get graph and skip if not exists. + $id_graph = db_get_value('id_graph', 'tgraph', 'name', $items_array['graph_name']); + + if (!($id_graph > 0)) { + continue; + } + + $graph_types = [ + 'line' => 2, + 'area' => 0, + 's_line' => 3, + 's_area' => 1, + 'h_bars' => 6, + 'v_bars' => 7, + 'gauge' => 5, + 'pie' => 8, + ]; + + if (isset($graph_types[$items_array['graph_type']]) === true) { + $graph_type_id = $items_array['graph_type']; + } else { + // Specified graph type is not a valid one. + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'id_graph' => $id_graph, + 'type' => $graph_type_id, + 'period' => (isset($items_array['interval']) === false) ? $items_array['interval'] : 86400, + 'showLegend' => 1, + ]; + + $order++; + } + + if ($items_array['type'] === 'reports') { + if (isset($items_array['report_name']) === false) { + // The above fields are required for this item. + continue; + } + + $id_report = reports_get_reports(['name' => $items_array['report_name']], ['id_report'])[0]['id_report']; + + if (!($id_report > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'reportId' => $id_report, + ]; + + $order++; + } + + if ($items_array['type'] === 'network_map') { + if (isset($items_array['map_name']) === false) { + // The above fields are required for this item. + continue; + } + + $id_map = db_get_value('id', 'tmap', 'name', $items_array['map_name']); + + if (!($id_map > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'networkmapId' => "$id_map", + 'xOffset' => '0', + 'yOffset' => '0', + 'zoomLevel' => 0.5, + ]; + + $order++; + } + + if ($items_array['type'] === 'service_map') { + if (isset($items_array['service_name']) === false) { + // The above fields are required for this item. + continue; + } + + $services = services_get_services(['name' => $items_array['service_name']]); + + $service_id = $services[0]['id']; + + if (!($service_id > 0)) { + continue; + } + + $options_data = [ + 'title' => $title, + 'background' => '#ffffff', + 'serviceId' => "$service_id", + 'sunburst' => 0, + ]; + + $order++; + } + + $item_x = $items_array['x']; + $item_y = $items_array['y']; + $item_width = $items_array['width']; + $item_height = $items_array['height']; + + $position_data = [ + 'x' => (isset($items_array['x']) === false) ? "$item_x" : "0", + 'y' => (isset($items_array['y']) === false) ? "$item_y" : "0", + 'width' => (isset($items_array['width']) === false) ? "$item_width" : "4", + 'height' => (isset($items_array['height']) === false) ? "$item_height" : "4", + ]; + + $element_values = [ + 'position' => json_encode($position_data), + 'options' => json_encode($options_data), + 'order' => $order, + 'id_dashboard' => $created_id, + 'id_widget' => $type_id, + 'prop_width' => 0.32, + 'prop_height' => 0.32, + ]; + + $id = db_process_sql_insert('twidget_dashboard', $element_values); + + if ($id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $id, + 'table_name' => 'twidget_dashboard', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('twidget_dashboard', ['id' => $id]); continue; } } } } - - // Calculate progress. - $percentage_inc = (100 / $total_items_count); - $current_progress_val = db_get_value_filter( - 'value', - 'tconfig', - ['token' => 'demo_data_load_progress'], - 'AND', - false, - false - ); - - if ($current_progress_val === false) { - $current_progress_val = 0; - } - - config_update_value('demo_data_load_progress', ($current_progress_val + $percentage_inc)); } + + update_progress($total_items_count, $dashboards_count); + update_item_checked(DEMO_DASHBOARD); + } else { + register_error(DEMO_DASHBOARD, __('No configuration files found or failed to parse files')); } $demo_agents_count = db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); @@ -1831,24 +2213,30 @@ if ($action === 'cleanup_demo_data') { 'tdashboard' => 'id', 'tlayout' => 'id', 'tlayout_data' => 'id', + 'tagente_estado' => 'id_agente_estado', ]; $table_id_field = $table_id_field_dict[$item['table_name']]; - $result = db_process_sql_delete( + $result1 = db_process_sql_delete( $item['table_name'], [$table_id_field => $item['item_id']] ); - if ($result !== false) { - db_process_sql_delete( + if ($result1 !== false) { + $result2 = db_process_sql_delete( 'tdemo_data', ['item_id' => $item['item_id']] ); } } - echo 1; + if ($result1 !== false && $result1 !== false) { + echo 1; + return; + } + + echo 0; } if ($action === 'get_progress_bar') { @@ -1856,22 +2244,47 @@ if ($action === 'get_progress_bar') { if ($operation === 'create') { $current_progress_val = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_progress']); + $demo_data_load_status = db_get_value_filter('value', 'tconfig', ['token' => 'demo_data_load_status']); if ($current_progress_val === false) { $current_progress_val = 0; } + + // Clean up checked items status and errors associated to them every time check items are obtained. + /*$demo_data_load_status_decoded = json_decode(io_safe_output($demo_data_load_status), true); + foreach ($demo_data_load_status_decoded['checked_items'] as $item_id) { + $demo_data_load_status_decoded['errors'][$item_id] = []; + } + + $demo_data_load_status_decoded['checked_items'] = []; + + config_update_value('demo_data_load_status', json_encode($demo_data_load_status_decoded));*/ + + $ret = [ + 'current_progress_val' => $current_progress_val, + 'demo_data_load_status' => json_decode(io_safe_output($demo_data_load_status), true), + ]; } else if ($operation === 'cleanup') { $demo_items_to_cleanup = (int) get_parameter('demo_items_to_cleanup'); $count_current_demo_items = db_get_value('count(*)', 'tdemo_data'); $current_progress_val = ((($demo_items_to_cleanup - $count_current_demo_items) * 100) / $demo_items_to_cleanup); + config_update_value('demo_data_delete_progress', $current_progress_val); + $ret = ['current_progress_val' => $current_progress_val]; } - echo $current_progress_val; + echo json_encode($ret); return; } +/** + * AUXILIARY FUNCTION: Calculate and return next host address within subnet given a CIDR-formatted address. + * + * @param string $ip CIDR IP address. + * + * @return string Next host address. + */ function calculateNextHostAddress($ip) { list($network, $subnet) = explode('/', $ip); @@ -1892,6 +2305,14 @@ function calculateNextHostAddress($ip) } +/** + * AUXILIARY FUNCTION: Try to return the group ID of a group given its name or create + * and return its ID if it does not exist. + * + * @param string $name Group name. + * + * @return mixed group ID or false if group not found and could not be created. + */ function get_group_or_create_demo_group($name) { if (is_string($name) === false) { @@ -1928,6 +2349,11 @@ function get_group_or_create_demo_group($name) } +/** + * AUXILIARY FUNCTION: Generate and return a randomly generated MAC address. + * + * @return string Random MAC address string. + */ function generateRandomMacAddress() { $macAddress = []; @@ -1942,3 +2368,118 @@ function generateRandomMacAddress() return $randomMacAddress; } + + +function update_progress($total_items_count, $total_type_items_count, $created_num=1) { + // Calculate progress. + $percentage_inc = (($created_num * 100) / ($total_type_items_count * $total_items_count)); + $current_progress_val = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_progress'], + 'AND', + false, + false + ); + + if ($current_progress_val === false) { + $current_progress_val = 0; + } + + $new_val = ($current_progress_val + $percentage_inc); + + if ((int) round($new_val) === 100) { + $new_val = 100; + } + + config_update_value('demo_data_load_progress', $new_val); +} + + +function update_item_checked($item_id) { + $current_load_status_data = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_status'], + 'AND', + false, + false + ); + + if ($current_load_status_data === false || $current_load_status_data === '{}') { + $current_load_data_arr = []; + } else { + $current_load_data_arr = json_decode(io_safe_output($current_load_status_data), true); + } + + $current_load_data_arr['checked_items'][] = $item_id; + + config_update_value('demo_data_load_status', json_encode($current_load_data_arr)); +} + + +function register_error( + $item_id, + $error_msg, + $search_for_repeated_msgs=false +) { + $current_load_status_data = db_get_value_filter( + 'value', + 'tconfig', + ['token' => 'demo_data_load_status'], + 'AND', + false, + false + ); + + if ($current_load_status_data === false || $current_load_status_data === '{}') { + $current_load_data_arr = []; + } else { + $current_load_data_arr = json_decode(io_safe_output($current_load_status_data), true); + } + + if ($search_for_repeated_msgs === true && isset($current_load_data_arr['errors'][$item_id]) === true) { + $matching_string = null; + $msg_key = array_search($error_msg, $current_load_data_arr['errors'][$item_id]); + + if ($msg_key === false) { + foreach ($current_load_data_arr['errors'][$item_id] as $key => $string) { + // Use regular expression to check if the part after "(...) " matches the error string. + if (preg_match('/\s*\((.*?)\)\s*(.*)/', $string, $matches)) { + $rest_of_string = $matches[2]; + + if ($rest_of_string === $error_msg) { + $matching_string = $string; + $msg_key = $key; + break; + } + } + } + + if ($matching_string === null) { + // String not found. + $current_load_data_arr['errors'][$item_id][] = $error_msg; + } else { + // Count parentheses string was found, then replace number. + $new_error_msg = preg_replace_callback( + '/\((\d+)\)/', + function ($matches) { + $currentNumber = $matches[1]; + $newNumber = ($currentNumber + 1); + return "($newNumber)"; + }, + $matching_string + ); + $current_load_data_arr['errors'][$item_id][$msg_key] = $new_error_msg; + } + } else { + // String without count found. + $new_error_msg = '(2) '.$error_msg; + $current_load_data_arr['errors'][$item_id][$msg_key] = $new_error_msg; + } + } else { + $current_load_data_arr['errors'][$item_id][] = $error_msg; + } + + config_update_value('demo_data_load_status', json_encode($current_load_data_arr)); +} diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 2dba4790e3..e6919f21f0 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -893,3 +893,12 @@ define('HOME_SCREEN_DASHBOARD', 'dashboard'); // Alert correlation. define('EVENT_ALERTS', 1); define('LOG_ALERTS', 2); + +// Demo items IDs. +define('DEMO_AGENT', 1); +define('DEMO_NETWORK_MAP', 2); +define('DEMO_CUSTOM_GRAPH', 3); +define('DEMO_REPORT', 4); +define('DEMO_SERVICE', 5); +define('DEMO_DASHBOARD', 6); +define('DEMO_VISUAL_CONSOLE', 7); From cdc77b5f7047fe75aaab92b853e7e7f72b35e1b9 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Fri, 24 Nov 2023 10:24:46 +0100 Subject: [PATCH 097/397] Added demo agents plugin --- .../util/plugin/pandora_demo_agents.pl | 666 ++++++++++++++++++ 1 file changed, 666 insertions(+) create mode 100644 pandora_server/util/plugin/pandora_demo_agents.pl diff --git a/pandora_server/util/plugin/pandora_demo_agents.pl b/pandora_server/util/plugin/pandora_demo_agents.pl new file mode 100644 index 0000000000..8469a84a93 --- /dev/null +++ b/pandora_server/util/plugin/pandora_demo_agents.pl @@ -0,0 +1,666 @@ +#!/usr/bin/perl +################################################################################ +# Author: Enrique Martin Garcia +# Copyright: 2023, PandoraFMS +# Maintainer: Operations department +# Version: 1.0 +################################################################################ + +use strict; +use warnings; + +use lib '/usr/lib/perl5'; + +use POSIX qw(strftime); +use Scalar::Util qw(looks_like_number); +use Digest::MD5 qw(md5_hex); +use PandoraFMS::PluginTools qw(empty trim print_agent); + +## +# GLOBALS +################## + +my $timestamp = strftime '%Y-%m-%d %H:%M:%S', localtime; +my ($sec,$min,$hour,$mday,$mon,$year)=localtime(time); +$year += 1900; +$mon += 1; + +my @sorted_ini; +my @agents_indexes; +my @block_agents_created_count; +my $current_ini = 0; + +my $result = 1; + +my $errors = ''; + +## +# FUNCTIONS +################## + +sub help() { + print STDERR "$0 [agents_seconds_interval] [traps_ip] [traps_community] [tentacle_ip] [tentacle_port] [tentacle_extra_opts]\n"; +} + +sub result($) { + my ($res) = @_; + + if($errors ne '') { + print STDERR $errors; + } + + print $res . "\n"; +} + +sub add_error($) { + my ($err) = @_; + + $errors .= '[ERROR] ' . $err . "\n"; +} + +sub error($) { + my ($msg) = @_; + + print STDERR '[ERROR] ' . $msg . "\n"; + result(0); + exit; +} + +sub alphanumerically { + my ($num_a, $num_b) = map { /(\d+)[^\d]*$/ ? $1 : 0 } ($a, $b); + $num_a <=> $num_b; +} + +sub parse_ini_file { + my ($file_path) = @_; + + open my $fh, '<', $file_path or return undef; + + my %ini_data; + my %ini_indexes; + my $current_section = ''; + + while (my $line = <$fh>) { + chomp $line; + + # Skip comments and empty lines + next if $line =~ /^\s*#/ || $line =~ /^\s*$/; + + # Match section headers + if ($line =~ /^\s*\[(\w+)\]\s*$/) { + $current_section = $1; + next; + } + + my $key; + my $index; + my $value; + + # Match key-value pairs + # key=value + if ($line =~ /^\s*(\w+)\s*=\s*[\"\']?\s*(.+?)\s*[\"\']?\s*$/) { + $key = $1; + $value = $2; + + # Store in the hash + $ini_data{$current_section}{$key} = $value; + + # Match key-array values pairs + # key[]=value + } elsif ($line =~ /^\s*(\w+)\[\]\s*=\s*[\"\']?\s*(.+?)\s*[\"\']?\s*$/) { + $key = $1; + $value = $2; + + # Create HASH if not defined or key is not HASH + if (!defined($ini_data{$current_section}{$key}) || ref($ini_data{$current_section}{$key}) ne "HASH") { + $ini_data{$current_section}{$key} = {}; + $ini_indexes{$current_section}{$key} = 0; + } + + # Get dynamic index + $index = $ini_indexes{$current_section}{$key}; + + # Store in the hash + $ini_data{$current_section}{$key}{$index} = $value; + + # Set new dynamic index + while(defined($ini_data{$current_section}{$key}{$ini_indexes{$current_section}{$key}})) { + $ini_indexes{$current_section}{$key}++; + } + + # Match indexed key-array values pairs + # key[index]=value + } elsif ($line =~ /^\s*(\w+)\[([\w\d]+)\]\s*=\s*[\"\']?\s*(.+?)\s*[\"\']?\s*$/) { + $key = $1; + $index = $2; + $value = $3; + + # Create HASH if not defined or key is not HASH + if (!defined($ini_data{$current_section}{$key}) || ref($ini_data{$current_section}{$key}) ne "HASH") { + $ini_data{$current_section}{$key} = {}; + $ini_indexes{$current_section}{$key} = 0; + } + + # Store in the hash + $ini_data{$current_section}{$key}{$index} = $value; + + # Set new dynamic index + if(looks_like_number($index) && $index == $ini_indexes{$current_section}{$key}) { + $ini_indexes{$current_section}{$key}++; + } + + # Not a valid line, INI bad format + } else { + return undef; + } + } + + close $fh; + + # Verify ini content + if(!defined($ini_data{'agent_data'})) { + return undef; + } + + if(!defined($ini_data{'agent_data'}{'agent_name'})) { + return undef; + } + + # Initialize agent_data keys + if(!defined($ini_data{'agent_data'}{'agents_number'}) || !looks_like_number($ini_data{'agent_data'}{'agents_number'})) { + $ini_data{'agent_data'}{'agents_number'} = 1; + } + + if(!defined($ini_data{'agent_data'}{'agent_alias'})) { + $ini_data{'agent_data'}{'agent_alias'} = $ini_data{'agent_data'}{'agent_name'}; + } + + if(!defined($ini_data{'agent_data'}{'group'})) { + $ini_data{'agent_data'}{'group'} = ''; + } + + # Initialize modules keys + if(!defined($ini_data{'modules'})) { + $ini_data{'modules'} = {}; + } + + if(!defined($ini_data{'modules'}{'name'})) { + $ini_data{'modules'}{'name'} = {}; + } + + # Initialize inventory keys + if(!defined($ini_data{'inventory'})) { + $ini_data{'inventory'} = {}; + } + + if(!defined($ini_data{'inventory'}{'name'})) { + $ini_data{'inventory'}{'name'} = {}; + } + + if(!defined($ini_data{'inventory_values'})) { + $ini_data{'inventory_values'} = {}; + } + + # Initialize traps keys + if(!defined($ini_data{'traps'})) { + $ini_data{'traps'} = {}; + } + + if(!defined($ini_data{'traps'}{'oid'})) { + $ini_data{'traps'}{'oid'} = {}; + } + + return %ini_data; +} + +sub get_bool($) { + my ($false_chance) = @_; + + $false_chance = 0 if $false_chance < 0; + $false_chance = 100 if $false_chance > 100; + + return int(rand(100)) + 1 <= $false_chance ? 0 : 1; +} + +sub get_value($) { + my ($value_rule) = @_; + + my $value = 1; + + my @rule_parts = split(/;/, $value_rule); + + if($rule_parts[0] eq 'RANDOM') { + my $min = 0; + if(defined($rule_parts[1])) { + $min = $rule_parts[1]; + } + my $max = 100; + if(defined($rule_parts[2])) { + $max = $rule_parts[2]; + } + + $value = $min + rand($max - $min); + + } elsif($rule_parts[0] eq 'PROC') { + my $error_percent = 0; + if(defined($rule_parts[1])) { + $error_percent = $rule_parts[1]; + } + + $value = get_bool($error_percent); + } + + return int($value); +} + +sub daily_match($$$) { + my ($conf, $m_hour, $m_min) = @_; + my $match = 0; + + if($hour == $m_hour && $min - ($conf->{'agents_interval'} / 60) < $m_min) { + $match = 1; + } + + return $match; +} + +sub ip_to_long { + my $ip = shift; + my @ip_parts = split(/\./, $ip); + return ($ip_parts[0] << 24) + ($ip_parts[1] << 16) + ($ip_parts[2] << 8) + $ip_parts[3]; +} + +sub long_to_ip { + my $long = shift; + return join('.', ($long >> 24) & 255, ($long >> 16) & 255, ($long >> 8) & 255, $long & 255); +} + +sub get_broadcast_ip_long { + my ($base_ip, $subnet_mask) = @_; + my $ip_long = ip_to_long($base_ip); + my $broadcast_ip_long = ($ip_long | (2**(32 - $subnet_mask) - 1)); + return $broadcast_ip_long; +} + +sub get_network_ip_long { + my ($base_ip, $subnet_mask) = @_; + return ip_to_long($base_ip); +} + +sub next_ip($$) { + my ($network , $counter) = @_; + + # Get base IP and subnet mask + my ($base_ip, $subnet_mask) = split('/', $network); + + # If subnet mask is 32 there is only 1 IP + if($subnet_mask == 32){ + return $base_ip; + } + + # Get broadcast and network IPs long + my $broadcast_ip = get_broadcast_ip_long($base_ip, $subnet_mask); + my $network_ip = get_network_ip_long($base_ip, $subnet_mask); + + # Get next IP + my $next_ip = $network_ip + $counter; + + # Keep rotating until next IP is below broadcast + while ($next_ip >= $broadcast_ip) { + $counter = $next_ip - $broadcast_ip + 1; + $next_ip = $network_ip + $counter; + } + + return long_to_ip($next_ip); +} + +sub transfer_xml($$$) { + my ($conf, $xml, $name) = @_; + my $file_name; + my $short_filename; + my $file_path; + + if ($xml =~ /\n/ || ! -f $xml) { + # Not a file, it's content. + if (! (empty ($name))) { + $file_name = $name . "." . sprintf("%d",time()) . ".data"; + } + else { + # Inherit file name + ($file_name) = $xml =~ /\s+agent_name='(.*?)'\s+.*$/m; + if (empty($file_name)){ + ($file_name) = $xml =~ /\s+agent_name="(.*?)"\s+.*$/m; + } + if (empty($file_name)){ + $file_name = trim(`hostname`); + } + + # Tentacle server does not allow files with symbols in theirs name. + $file_name =~ s/[^a-zA-Z0-9_-]//g; + $short_filename = $file_name; + $file_name .= "." . sprintf("%d",time()) . ".data"; + } + + if (empty($file_name)) { + return (0, "Failed to generate file name"); + } + + $conf->{temp} = $conf->{tmp} if (empty($conf->{temp}) && defined($conf->{tmp})); + $conf->{temp} = $conf->{temporal} if (empty($conf->{temp}) && defined($conf->{temporal})); + $conf->{temp} = $conf->{__system}->{tmp} if (empty($conf->{temp}) && defined($conf->{__system})) && (ref($conf->{__system}) eq "HASH"); + $conf->{temp} = '/tmp' if empty($conf->{temp}); + + $file_path = $conf->{temp} . "/" . $file_name; + + #Creating XML file in temp directory + + while ( -e $file_path ) { + sleep (1); + $file_name = $short_filename . "." . sprintf("%d",time()) . ".data"; + $file_path = $conf->{temp} . "/" . $file_name; + } + + my $r = open (my $FD, ">>", $file_path); + + if (empty($r)) { + return (0, "Cannot write XML [" . $file_path . "]"); + } + + my $bin_opts = ':raw:encoding(UTF8)'; + + if ($^O eq "Windows") { + $bin_opts .= ':crlf'; + } + + binmode($FD, $bin_opts); + + print $FD $xml; + + close ($FD); + + } else { + $file_path = $xml; + } + + # Reassign default values if not present + $conf->{tentacle_port} = "41121" if empty($conf->{tentacle_port}); + $conf->{tentacle_opts} = "" if empty($conf->{tentacle_opts}); + + #Send using tentacle + my $msg = `tentacle_client -v -a $conf->{tentacle_ip} -p $conf->{tentacle_port} $conf->{tentacle_opts} "$file_path" 2>&1`; + my $r = $?; + + unlink ($file_path); + + if ($r != 0) { + return (0, trim($msg)); + } + + return (1, ""); +} + +sub send_snmp_trap($$) { + my ($conf, $trap) = @_; + + # Check trap chance + if (get_bool($trap->{'chance_percent'}) == 1) { + my $value = get_value($trap->{'value'}); + my $msg = `snmptrap -v 1 -c $conf->{'traps_community'} $conf->{'traps_ip'} $trap->{'oid'} $trap->{'address'} $trap->{'snmp_type'} 1 0 $trap->{'oid'} s "$value" 2>&1`; + my $r = $?; + + if ($r != 0) { + return (0, trim($msg)); + } + } + + return (1, ""); +} + +sub generate_agent($) { + my ($cfg) = @_; + + # Set current ini + if($block_agents_created_count[$current_ini] >= $sorted_ini[$current_ini]->{'agent_data'}->{'agents_number'}) { + $block_agents_created_count[$current_ini] = 0; + $current_ini++; + } + + if($current_ini >= @sorted_ini) { + $current_ini = 0; + } + + # Get agent info + my $agent; + $agent->{'agent_name'} = $sorted_ini[$current_ini]->{'agent_data'}->{'agent_name'}.'-'.$agents_indexes[$current_ini]; + $agent->{'agent_alias'} = $sorted_ini[$current_ini]->{'agent_data'}->{'agent_alias'}.'-'.$agents_indexes[$current_ini]; + $agent->{'group'} = $sorted_ini[$current_ini]->{'agent_data'}->{'group'}; + $agent->{'interval'} = $cfg->{'agents_interval'}; + $agent->{'timestamp'} = $timestamp; + + # Get modules info + my @modules; + foreach my $k (sort keys %{$sorted_ini[$current_ini]->{'modules'}->{'name'}}) { + # Set default type if not defined + if(!defined($sorted_ini[$current_ini]->{'modules'}->{'type'}->{$k})) { + $sorted_ini[$current_ini]->{'modules'}->{'type'}->{$k} = 'generic_data_string'; + } + + # Set default value if not defined + if(!defined($sorted_ini[$current_ini]->{'modules'}->{'values'}->{$k})) { + $sorted_ini[$current_ini]->{'modules'}->{'values'}->{$k} = 'RANDOM;0;100'; + } + + push (@modules, { + 'name' => $sorted_ini[$current_ini]->{'modules'}->{'name'}->{$k}, + 'type' => $sorted_ini[$current_ini]->{'modules'}->{'type'}->{$k}, + 'value' => get_value($sorted_ini[$current_ini]->{'modules'}->{'values'}->{$k}) + }); + } + + # Create XML + my $xml = print_agent({},$agent,\@modules); + + # Append inventory data to XML (only once a day at 00:00) + if (!empty($sorted_ini[$current_ini]->{'inventory'}->{'name'}) && daily_match($cfg, 0, 0)) { + + # Remove agent_data closing tag + $xml =~ s/<\/agent_data>//i; + + $xml .= "\n"; + + # Add inventory for each module + foreach my $k (sort keys %{$sorted_ini[$current_ini]->{'inventory'}->{'name'}}) { + # Only if values are defined + if(defined($sorted_ini[$current_ini]->{'inventory'}->{'values'}->{$k})) { + # Get inventory module name + my $inventory_name = $sorted_ini[$current_ini]->{'inventory'}->{'name'}->{$k}; + + $xml .= "\t\n"; + $xml .= "\t\t\n"; + + # Get inventory values keys + my @values_keys = split(/;/, $sorted_ini[$current_ini]->{'inventory'}->{'values'}->{$k}); + + my %inventory_values; + + # Parse each inventory values key for indexes + foreach my $key (@values_keys) { + # Get indexes from each key + foreach my $i (sort keys %{$sorted_ini[$current_ini]->{'inventory_values'}->{$key}}) { + $inventory_values{$i} = (); + } + } + + # Parse each inventory values key for values + foreach my $key (@values_keys) { + # Get values from each key + foreach my $v (sort keys %inventory_values) { + if (defined($sorted_ini[$current_ini]->{'inventory_values'}->{$key}->{$v})) { + push(@{$inventory_values{$v}}, $sorted_ini[$current_ini]->{'inventory_values'}->{$key}->{$v}); + } else { + push(@{$inventory_values{$v}}, ''); + } + } + } + + $xml .= "\t\t\n"; + + # Get each value string + foreach my $r (sort keys %inventory_values) { + my $inv_value = join(';', @{$inventory_values{$r}}); + $xml .= "\t\t\t\n"; + } + + $xml .= "\t\t\n"; + $xml .= "\t\n\n"; + } + } + + $xml .= "\n"; + + # Close agent_data tag again + $xml .= "\n"; + } + + # Get file name MD5 + my $file_md5 = md5_hex($agent->{'agent_name'}); + + # Send XML + my ($transfer_res, $transfer_err) = transfer_xml($cfg, $xml, $file_md5); + if ($transfer_res == 0) { + add_error("Failed to transfer XML for agent: " . $agent->{'agent_name'} . "\n\t" . $transfer_err); + $result = 0; + } + + # Get traps source address + my $traps_addr = '127.0.0.1'; + if(defined($sorted_ini[$current_ini]->{'agent_data'}->{'address_network'})) { + $traps_addr = next_ip($sorted_ini[$current_ini]->{'agent_data'}->{'address_network'}, $agents_indexes[$current_ini]); + } + + # Generate SNMP traps + foreach my $k (sort keys %{$sorted_ini[$current_ini]->{'traps'}->{'oid'}}) { + # Set default type if not defined + if(!defined($sorted_ini[$current_ini]->{'traps'}->{'snmp_type'}->{$k})) { + $sorted_ini[$current_ini]->{'traps'}->{'snmp_type'}->{$k} = '6'; + } + + # Set default value if not defined + if(!defined($sorted_ini[$current_ini]->{'traps'}->{'value'}->{$k})) { + $sorted_ini[$current_ini]->{'traps'}->{'value'}->{$k} = 'RANDOM;0;100'; + } + + # Set default chance if not defined + if(!defined($sorted_ini[$current_ini]->{'traps'}->{'chance_percent'}->{$k})) { + $sorted_ini[$current_ini]->{'traps'}->{'chance_percent'}->{$k} = '5'; + } + + my $trap; + $trap->{'oid'} = $sorted_ini[$current_ini]->{'traps'}->{'oid'}->{$k}; + $trap->{'snmp_type'} = $sorted_ini[$current_ini]->{'traps'}->{'snmp_type'}->{$k}; + $trap->{'value'} = $sorted_ini[$current_ini]->{'traps'}->{'value'}->{$k}; + $trap->{'chance_percent'} = $sorted_ini[$current_ini]->{'traps'}->{'chance_percent'}->{$k}; + $trap->{'address'} = $traps_addr; + + my ($trap_res, $trap_err) = send_snmp_trap($cfg, $trap); + if ($trap_res == 0) { + add_error("Failed to send SNMP trap for agent: " . $agent->{'agent_name'} . "\n\t" . $trap_err); + $result = 0; + } + + undef($trap); + } + + # Increase agents indexes + $agents_indexes[$current_ini]++; +} + +## +# ARGUMENTS +################## + +my $agents_files_path = $ARGV[0]; +my $total_agents = $ARGV[1]; +my $agents_interval = (defined($ARGV[2]) ? $ARGV[2] : 300); + +my $traps_ip = (defined($ARGV[3]) ? $ARGV[3] : '127.0.0.1'); +my $traps_community = (defined($ARGV[4]) ? $ARGV[4] : 'public'); + +my $tentacle_ip = (defined($ARGV[5]) ? $ARGV[5] : '127.0.0.1'); +my $tentacle_port = (defined($ARGV[6]) ? $ARGV[6] : 41121); + +my $tentacle_opts = join(' ', @ARGV[7..$#ARGV]); + +# Verify parameters + +if(!defined($agents_files_path)) { + help(); + error("Agents definition folder must be defined"); +} + +if(!defined($total_agents) || !looks_like_number($total_agents) || $total_agents <= 0) { + help(); + error("Total number of agents must be defined and a number greater than 0"); +} + +if(!-d $agents_files_path || !-r $agents_files_path) { + error("Can't access agents definition folder: " . $agents_files_path); +} + +if(!looks_like_number($agents_interval) || $agents_interval <= 0) { + $agents_interval = 300; +} + +if(!looks_like_number($tentacle_port) || $tentacle_port <= 0) { + $tentacle_port = 41121; +} + +## +# MAIN +################## + +# Set config +my $config; +$config->{'tentacle_ip'} = $tentacle_ip; +$config->{'tentacle_port'} = $tentacle_port; +$config->{'tentacle_opts'} = $tentacle_opts; +$config->{'agents_interval'} = $agents_interval; +$config->{'traps_ip'} = $traps_ip; +$config->{'traps_community'} = $traps_community; + +# Open the directory +opendir(my $dh, $agents_files_path) or error("Could not open directory '$agents_files_path': $!"); + +# Read the directory and sort the filenames numerically +my @files = sort alphanumerically map { "$agents_files_path/$_" } grep { -f "$agents_files_path/$_" } readdir($dh); + +# Close the directory +closedir($dh); + +# Parse each ini file and sort them +foreach my $file (@files) { + if (-f $file && -r $file) { + my %ini_data = parse_ini_file($file); + if (defined(\%ini_data)) { + push(@sorted_ini, \%ini_data); + push(@agents_indexes, 1); + push(@block_agents_created_count, 0); + } + } +} + +# Error if not agents definitions loaded +if (empty(@sorted_ini)) { + error("Unable to load agents definitions from folder '$agents_files_path'"); +} + +# Generate all requested agents +my $generated_agents = 0; +while ($generated_agents < $total_agents) { + generate_agent($config); + $block_agents_created_count[$current_ini]++; + $generated_agents++; +} + +# Print result +result($result); \ No newline at end of file From 26e4b46b1fa0e3661e3a0337e7e643ed9662a8c7 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Fri, 24 Nov 2023 12:26:59 +0100 Subject: [PATCH 098/397] Removed agent_alias from agent_data --- pandora_server/util/plugin/pandora_demo_agents.pl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pandora_server/util/plugin/pandora_demo_agents.pl b/pandora_server/util/plugin/pandora_demo_agents.pl index 8469a84a93..d58472aa66 100644 --- a/pandora_server/util/plugin/pandora_demo_agents.pl +++ b/pandora_server/util/plugin/pandora_demo_agents.pl @@ -171,10 +171,6 @@ sub parse_ini_file { $ini_data{'agent_data'}{'agents_number'} = 1; } - if(!defined($ini_data{'agent_data'}{'agent_alias'})) { - $ini_data{'agent_data'}{'agent_alias'} = $ini_data{'agent_data'}{'agent_name'}; - } - if(!defined($ini_data{'agent_data'}{'group'})) { $ini_data{'agent_data'}{'group'} = ''; } @@ -432,7 +428,7 @@ sub generate_agent($) { # Get agent info my $agent; $agent->{'agent_name'} = $sorted_ini[$current_ini]->{'agent_data'}->{'agent_name'}.'-'.$agents_indexes[$current_ini]; - $agent->{'agent_alias'} = $sorted_ini[$current_ini]->{'agent_data'}->{'agent_alias'}.'-'.$agents_indexes[$current_ini]; + $agent->{'agent_alias'} = $sorted_ini[$current_ini]->{'agent_data'}->{'agent_name'}.'-'.$agents_indexes[$current_ini]; $agent->{'group'} = $sorted_ini[$current_ini]->{'agent_data'}->{'group'}; $agent->{'interval'} = $cfg->{'agents_interval'}; $agent->{'timestamp'} = $timestamp; From 52134623347ae0693bc2f889ab4038c36ffb40ab Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 24 Nov 2023 12:54:19 +0100 Subject: [PATCH 099/397] #12067 Aggregated Agents Modules and module group --- pandora_console/extensions/agents_modules.php | 2 +- pandora_console/extensions/module_groups.php | 1 + pandora_console/index.php | 72 ++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/pandora_console/extensions/agents_modules.php b/pandora_console/extensions/agents_modules.php index d6c4f3bb32..588d64f3d7 100644 --- a/pandora_console/extensions/agents_modules.php +++ b/pandora_console/extensions/agents_modules.php @@ -880,7 +880,7 @@ function mainAgentsModules() return; } - echo '
    '.__('Total items').': '.$count.'
    '; + echo '
    '; echo ''; diff --git a/pandora_console/extensions/module_groups.php b/pandora_console/extensions/module_groups.php index f1cb6b91c5..957d3a17a1 100644 --- a/pandora_console/extensions/module_groups.php +++ b/pandora_console/extensions/module_groups.php @@ -345,6 +345,7 @@ function mainModuleGroups() $table = new StdClass(); $table->class = 'info_table'; $table->style[0] = 'font-weight: bolder; min-width: 230px;'; + $table->id = 'agent_group_module_group'; $table->width = '100%'; $head[0] = __('Groups'); diff --git a/pandora_console/index.php b/pandora_console/index.php index 95641b313f..35b907cbec 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1672,8 +1672,8 @@ require 'include/php_to_js_values.php'; let counter = 0; $("#keywords").on("click", function(e) { counter++; - let falEasternEgg = true; - if (counter == 5 && falEasternEgg == true) { + let flagEasternEgg = $("#flagEasternEgg").val(); + if (counter == 5 && flagEasternEgg == true) { easterEggThinkGreen(); } }); @@ -1772,7 +1772,6 @@ require 'include/php_to_js_values.php'; $('#summary_status_groups_detail > tbody > tr > td').each(function(index, fila) { var hasClassRed = $(fila).hasClass('group_view_crit'); - console.log(hasClassRed); if (hasClassRed) { $(fila).removeClass('group_view_crit').addClass('group_view_ok'); $(fila).children('a').removeClass('group_view_crit').addClass('group_view_ok'); @@ -1798,6 +1797,73 @@ require 'include/php_to_js_values.php'; } }); + // Agents Modules. + $('#agents_modules_table > tbody > tr > td').each(function(index, fila) { + // Change status. + var hasClassRed = $(fila).hasClass('group_view_crit'); + var hasClassGrey = $(fila).hasClass('group_view_unk'); + if (hasClassRed == true) { + $(fila).removeClass('group_view_crit').addClass('group_view_ok'); + $(fila).children('a').removeClass('group_view_crit').addClass('group_view_ok'); + } else if (hasClassRed == false) { + var hasClassGroupRed = $(fila).children('a').children('div').attr('style'); + if (hasClassGroupRed !== undefined) { + let findedRed = hasClassGroupRed.indexOf('background: #e63c52'); + if (findedRed >= 0) { + elementChange.hasClassRed = true; + elementChange.hasClassGrey = false; + elementChange.elementID = $(fila).children('a').children('div'); + elementChange.class = false; + setClassGreen(elementChange); + } + } + } + + if (hasClassGrey == true) { + $(fila).removeClass('group_view_unk').addClass('group_view_ok'); + $(fila).children('a').removeClass('group_view_unk').addClass('group_view_ok'); + } else if (hasClassGrey == false) { + var hasClassGroupGrey = $(fila).children('a').children('div').attr('style'); + if (hasClassGroupGrey !== undefined) { + let findedGrey = hasClassGroupGrey.indexOf('background: #B2B2B2'); + if (findedGrey >= 0) { + elementChange.hasClassRed = false; + elementChange.hasClassGrey = true; + elementChange.elementID = $(fila).children('a').children('div'); + elementChange.class = false; + setClassGreen(elementChange); + } + } + } + }); + + // Combined table of agent group and module group. + $('#agent_group_module_group > tbody > tr > td').each(function(index, fila) { + var hasClassGroupRed = $(fila).children('div').attr('style'); + if (hasClassGroupRed !== undefined) { + let findedRed = hasClassGroupRed.indexOf(' background:#e63c52;'); + if (findedRed >= 0) { + elementChange.hasClassRed = true; + elementChange.hasClassGrey = false; + elementChange.elementID = $(fila).children('div'); + elementChange.class = false; + setClassGreen(elementChange); + } + } + + var hasClassGroupGrey = $(fila).children('div').attr('style'); + if (hasClassGroupGrey !== undefined) { + let findedGrey = hasClassGroupGrey.indexOf(' background:#B2B2B2;'); + if (findedGrey >= 0) { + elementChange.hasClassRed = false; + elementChange.hasClassGrey = true; + elementChange.elementID = $(fila).children('div'); + elementChange.class = false; + setClassGreen(elementChange); + } + } + }); + } function setClassGreen(element) { From a1916dc4b948cdbebf2509a53ab52fce8ee700a4 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 24 Nov 2023 12:56:21 +0100 Subject: [PATCH 100/397] implement demo data load --- pandora_console/godmode/menu.php | 8 +- pandora_console/godmode/setup/demo.php | 147 ++++++++++-------- pandora_console/godmode/setup/setup.php | 15 ++ pandora_console/images/demo_data.png | Bin 0 -> 655 bytes .../include/ajax/demo_data.ajax.php | 29 ++-- pandora_console/include/functions_agents.php | 4 +- 6 files changed, 118 insertions(+), 85 deletions(-) create mode 100644 pandora_console/images/demo_data.png diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 0e41b1925b..e779ad11eb 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -496,6 +496,9 @@ if ($access_console_node === true) { $sub2['godmode/setup/setup§ion=welcome_tips']['text'] = __('Welcome Tips'); $sub2['godmode/setup/setup§ion=welcome_tips']['refr'] = 0; + $sub2['godmode/setup/setup§ion=demo_data']['text'] = __('Demo data'); + $sub2['godmode/setup/setup§ion=demo_data']['refr'] = 0; + if ((bool) $config['activate_gis'] === true) { $sub2['godmode/setup/setup§ion=gis']['text'] = __('Map conections GIS'); } @@ -506,12 +509,7 @@ if ($access_console_node === true) { enterprise_hook('skins_submenu'); - - $sub['godmode/setup/demo']['text'] = __('Demo data'); - $sub['godmode/setup/demo']['id'] = 'demo'; - $menu_godmode['gsetup']['sub'] = $sub; - } } diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index b1caf6f9cc..800701a2b9 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -131,9 +131,8 @@ if ($display_loading === true || $running_create === true || $running_delete) { DEMO_DASHBOARD => 'dashboards', ]; - if ($adv_options_is_enabled === true) { + if ((bool) $adv_options_is_enabled === true) { $enabled_keys = array_keys(array_filter($enabled_items)); - $items_ids_text_map = array_filter( $items_ids_text_map, function ($k) use ($dir_item_id_map, $enabled_keys) { @@ -141,10 +140,13 @@ if ($display_loading === true || $running_create === true || $running_delete) { }, ARRAY_FILTER_USE_KEY ); - - array_merge([DEMO_AGENT => 'agents'], $items_ids_text_map); } + if (enterprise_installed() === false) { + unset($items_ids_text_map[DEMO_SERVICE]); + } + + $items_ids_text_map = ([DEMO_AGENT => 'agents'] + $items_ids_text_map); $list_mkup = '
      '; foreach ($items_ids_text_map as $item_id => $item_text) { $list_mkup .= '
    • '; @@ -240,7 +242,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { 'agents_num', $agents_num, '', - '30', + '', 30, true, false, @@ -271,8 +273,26 @@ if ($display_loading === true || $running_create === true || $running_delete) { $table_adv->size[0] = '50%'; $table_adv->size[1] = '50%'; + $interval_select = html_print_extended_select_for_time( + 'interval', + $interval, + '', + '', + '0', + 10, + true, + false, + true, + 'w20p' + ); + $table_adv->data['row0'][] = html_print_label_input_block( - __('Generate historical data for all agents (15 days by default)'), + __('Agents interval'), + $interval_select + ); + + $table_adv->data['row1'][] = html_print_label_input_block( + __('Generate historical data for all agents'), html_print_checkbox_switch( 'enable_history', 1, @@ -281,7 +301,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row1'][] = html_print_label_input_block( + $table_adv->data['row2'][] = html_print_label_input_block( __('Days of historical data to insert in the agent data'), html_print_input_text( 'days_hist_data', @@ -297,33 +317,17 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row2'][] = html_print_label_input_block( - __('Create custom graphs'), - html_print_checkbox_switch( - 'enable_cg', - 1, - $enabled_items['graphs'], - true - ) - ); - - $interval_select = html_print_extended_select_for_time( - 'interval', - $interval, - '', - '', - '0', - 10, - true, - false, - true, - 'w20p' - ); - - $table_adv->data['row3'][] = html_print_label_input_block( - __('Interval'), - $interval_select - ); + if (enterprise_installed() === true) { + $table_adv->data['row3'][] = html_print_label_input_block( + __('Create services'), + html_print_checkbox_switch( + 'enable_services', + 1, + $enabled_items['services'], + true + ) + ); + } $table_adv->data['row4'][] = html_print_label_input_block( __('Create network maps'), @@ -336,11 +340,11 @@ if ($display_loading === true || $running_create === true || $running_delete) { ); $table_adv->data['row5'][] = html_print_label_input_block( - __('Create services'), + __('Create custom graphs'), html_print_checkbox_switch( - 'enable_services', + 'enable_cg', 1, - $enabled_items['services'], + $enabled_items['graphs'], true ) ); @@ -356,17 +360,6 @@ if ($display_loading === true || $running_create === true || $running_delete) { ); $table_adv->data['row7'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['dashboards'], - true - ) - ); - - - $table_adv->data['row8'][] = html_print_label_input_block( __('Create visual consoles'), html_print_checkbox_switch( 'enable_vc', @@ -376,6 +369,16 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); + $table_adv->data['row8'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); + echo '
      '; echo '
      '; echo ''.__('Configure demo data').''; @@ -432,20 +435,32 @@ if ($display_loading === true || $running_create === true || $running_delete) { $table_summary->size[0] = '50%'; $table_summary->size[1] = '50%'; - $table_summary->data['row0'][0] = __('Agents'); - $table_summary->data['row0'][1] = ($demo_agents_count > 0) ? $demo_agents_count : '-'; - $table_summary->data['row1'][0] = __('Services'); - $table_summary->data['row1'][1] = ($demo_services_count > 0) ? $demo_services_count : '-'; - $table_summary->data['row2'][0] = __('Network maps'); - $table_summary->data['row2'][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-'; - $table_summary->data['row3'][0] = __('Custom graphs'); - $table_summary->data['row3'][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-'; - $table_summary->data['row4'][0] = __('Custom reports'); - $table_summary->data['row4'][1] = ($demo_rep_count > 0) ? $demo_rep_count : '-'; - $table_summary->data['row5'][0] = __('Visual consoles'); - $table_summary->data['row5'][1] = ($demo_vc_count > 0) ? $demo_vc_count : '-'; - $table_summary->data['row6'][0] = __('Dashboards'); - $table_summary->data['row6'][1] = ($demo_dashboards_count > 0) ? $demo_dashboards_count : '-'; + $i = 0; + $table_summary->data[$i][0] = __('Agents'); + $table_summary->data[$i][1] = ($demo_agents_count > 0) ? $demo_agents_count : '-'; + $i++; + + if (enterprise_installed() === true) { + $table_summary->data[$i][0] = __('Services'); + $table_summary->data[$i][1] = ($demo_services_count > 0) ? $demo_services_count : '-'; + $i++; + } + + $i++; + $table_summary->data[$i][0] = __('Network maps'); + $table_summary->data[$i][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Custom graphs'); + $table_summary->data[$i][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Custom reports'); + $table_summary->data[$i][1] = ($demo_rep_count > 0) ? $demo_rep_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Visual consoles'); + $table_summary->data[$i][1] = ($demo_vc_count > 0) ? $demo_vc_count : '-'; + $i++; + $table_summary->data[$i][0] = __('Dashboards'); + $table_summary->data[$i][1] = ($demo_dashboards_count > 0) ? $demo_dashboards_count : '-'; echo ''; echo '
      '; @@ -504,16 +519,16 @@ if ($display_loading === true || $running_create === true || $running_delete) { } }); - $('#table-adv-row1').hide(); + $('#table-adv-row2').hide(); if ($('#checkbox-enable_history').is(':checked') === true) { - $('#table-adv-row1').show(); + $('#table-adv-row2').show(); } $('#checkbox-enable_history').change(function() { if ($(this).is(':checked') === true) { - $('#table-adv-row1').show(); + $('#table-adv-row2').show(); } else { - $('#table-adv-row1').hide(); + $('#table-adv-row2').hide(); } }); diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 0fd6bebff8..b8f41b790f 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -243,6 +243,11 @@ $buttons['welcome_tips'] = [ 'text' => ''.html_print_image('images/inventory.png', true, ['title' => __('Welcome tips'), 'class' => 'invert_filter']).'', ]; +$buttons['demo_data'] = [ + 'active' => false, + 'text' => ''.html_print_image('images/demo_data.png', true, ['title' => __('Demo data'), 'class' => 'invert_filter']).'', +]; + if ($config['activate_gis']) { $buttons['gis'] = [ 'active' => false, @@ -351,6 +356,12 @@ switch ($section) { $help_header = ''; break; + case 'demo_data': + $buttons['demo_data']['active'] = true; + $subpage = __('Demo data'); + $help_header = ''; + break; + case 'enterprise': $buttons['enterprise']['active'] = true; $subpage = __('Enterprise'); @@ -466,6 +477,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/welcome_tips.php'; break; + case 'demo_data': + include_once $config['homedir'].'/godmode/setup/demo.php'; + break; + default: enterprise_hook('setup_enterprise_select_tab', [$section]); break; diff --git a/pandora_console/images/demo_data.png b/pandora_console/images/demo_data.png new file mode 100644 index 0000000000000000000000000000000000000000..edc30ceaf68b42f70d5e8ae4f3043bd9c7137950 GIT binary patch literal 655 zcmeAS@N?(olHy`uVBq!ia0vp^q9Dw{#=yXMPhcvL&A^iG==e(WdjqS5++X<#}Es_xgplx z%#H%*o^BIZBv!_?O^`d7BZ_0v^xlr%2~Hl9-Tp9!HA%1>lvn6rJm{u4HI!v`Opqs+ zr?5-Tnk$#??fH{-bLX3Thv(=$dG@!~xVXA=>E)MEK65Reu)Qqc(_I?l^lqY^RjboM zHSc8?o1Len@yt5AZ0#F=&ShRa4vVH(@I3UI@@`jKkjC$@#}lSLsbQXZIx(cs%+rzo z^rmg?&fA~PcymCbaUs7@_wmQkeUI-{Prf0xW`Yb4Te^Uo(RYW!_~}1u>h@lLJ$Lc? z_il?fE>ibSvFKZ2H2dtlMZHQ_rr0qYeNiB-p2D!w*XRqw*PStX?0)OT0}m->{MM+r z#2j}wLXy?+g3zrO6Z-CnZ18>+%VUU%!3i7R+;@VUl};e3D{s!;F%|!qYd7+8qDbbo;Tx%T-&1 zI*+8S4g3AbX_}-=UHu#7lh $server_name + 'server_name' => $server_name, + 'id_os' => $id_os, + 'os_version' => $os_version, ]; $create_alias = $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_name']] + 1); @@ -247,9 +256,7 @@ if ($action === 'create_demo_data') { $agent_interval, $next_ip_address, $values, - true, - $id_os, - $os_version + true ); if ($created_agent_id > 0) { @@ -775,7 +782,7 @@ if ($action === 'create_demo_data') { } } - $services_count = count($parsed_ini['services']); + $services_count = count($parsed_ini['services'] ?? []); if ($services_count > 0) { // Create services. foreach ($parsed_ini['services'] as $ini_service_data) { @@ -1021,7 +1028,7 @@ if ($action === 'create_demo_data') { register_error(DEMO_SERVICE, __('No configuration files found or failed to parse files')); } - $nm_count = count($parsed_ini['network_maps']); + $nm_count = count($parsed_ini['network_maps'] ?? []); if ($nm_count > 0) { // Create network maps. foreach ($parsed_ini['network_maps'] as $ini_nm_data) { @@ -1203,7 +1210,7 @@ if ($action === 'create_demo_data') { register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files')); } - $cg_count = count($parsed_ini['graphs']); + $cg_count = count($parsed_ini['graphs'] ?? []); if ($cg_count > 0) { // Create graphs. foreach ($parsed_ini['graphs'] as $ini_graph_data) { @@ -1375,7 +1382,7 @@ if ($action === 'create_demo_data') { register_error(DEMO_CUSTOM_GRAPH, __('No configuration files found or failed to parse files')); } - $rep_count = count($parsed_ini['reports']); + $rep_count = count($parsed_ini['reports'] ?? []); if ($rep_count > 0) { // Create reports. foreach ($parsed_ini['reports'] as $ini_report_data) { @@ -1570,7 +1577,7 @@ if ($action === 'create_demo_data') { register_error(DEMO_REPORT, __('No configuration files found or failed to parse files')); } - $vc_count = count($parsed_ini['visual_consoles']); + $vc_count = count($parsed_ini['visual_consoles'] ?? []); if ($vc_count > 0) { // Create visual consoles. foreach ($parsed_ini['visual_consoles'] as $ini_data) { @@ -1899,7 +1906,7 @@ if ($action === 'create_demo_data') { register_error(DEMO_VISUAL_CONSOLE, __('No configuration files found or failed to parse files')); } - $dashboards_count = count($parsed_ini['dashboards']); + $dashboards_count = count($parsed_ini['dashboards'] ?? []); if ($dashboards_count > 0) { // Create dashboards. foreach ($parsed_ini['dashboards'] as $ini_data) { diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 04174569a1..a7115496ed 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -218,9 +218,7 @@ function agents_create_agent( $interval, $ip_address, $values=false, - $alias_as_name=false, - $os=false, - $os_version=false + $alias_as_name=false ) { global $config; From 1f51b0475e3c29f1bea806c2c8ef45f7f3d7946c Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 24 Nov 2023 13:12:12 +0100 Subject: [PATCH 101/397] #12201 Added configuration in the setup for easter egg --- pandora_console/godmode/setup/setup_general.php | 10 ++++++++++ pandora_console/include/functions_config.php | 8 ++++++++ pandora_console/index.php | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index 2732568208..b7bcbcabf2 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -767,6 +767,16 @@ $table->data[$i][] = html_print_label_input_block( ) ); +$table->data[$i][] = html_print_label_input_block( + __('Eastern eggs disabled'), + html_print_checkbox_switch( + 'eastern_eggs_disabled', + 1, + $config['eastern_eggs_disabled'], + true + ) +); + echo ''; diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index c9e4aa2226..0c7d6039cd 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -371,6 +371,10 @@ function config_update_config() $error_update[] = __('show_experimental_features'); } + if (config_update_value('eastern_eggs_disabled', get_parameter('eastern_eggs_disabled'), true) === false) { + $error_update[] = __('eastern_eggs_disabled'); + } + if (config_update_value('console_log_enabled', get_parameter('console_log_enabled'), true) === false) { $error_update[] = __('Console log enabled'); } @@ -2449,6 +2453,10 @@ function config_process_config() config_update_value('show_experimental_features', 0); } + if (!isset($config['eastern_eggs_disabled'])) { + config_update_value('eastern_eggs_disabled', 1); + } + if (!isset($config['agent_vulnerabilities'])) { config_update_value('agent_vulnerabilities', 1); } diff --git a/pandora_console/index.php b/pandora_console/index.php index 4ca8f80a82..49bccd1b14 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1515,6 +1515,15 @@ echo html_print_div( true ); +echo html_print_input_hidden( + 'flagEasternEgg', + $config['eastern_eggs_disabled'], + false, + '', + '', + 'flagEasternEgg' +); + // Connection lost alert. set_js_value('check_conexion_interval', $config['check_conexion_interval']); set_js_value('title_conexion_interval', __('Connection with console has been lost')); From 51a152d86d50886b090d1908cf7a41cb1bbc32f6 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 24 Nov 2023 13:25:42 +0100 Subject: [PATCH 102/397] #12202 Added setup flag for easter egg --- pandora_console/include/javascript/pandora_events.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index f1453ce493..a95ce68899 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -1747,7 +1747,8 @@ $(window).on("load", function() { .off("click") .on("click", function(e) { counter++; - if (counter == 12) { + let flagEasternEgg = $("#flagEasternEgg").val(); + if (counter == 12 && flagEasternEgg == true) { $("#modal-asteroids") .dialog({ title: "Asteroids", From 9f08b9907c9eeb5c141617385bbcef77cd483508 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 24 Nov 2023 13:37:00 +0100 Subject: [PATCH 103/397] #12198 Added setup flag for easter egg --- .../lib/TacticalView/GeneralTacticalView.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/lib/TacticalView/GeneralTacticalView.php b/pandora_console/include/lib/TacticalView/GeneralTacticalView.php index d0f8ecaad6..4d06d5c5e2 100644 --- a/pandora_console/include/lib/TacticalView/GeneralTacticalView.php +++ b/pandora_console/include/lib/TacticalView/GeneralTacticalView.php @@ -163,7 +163,27 @@ class GeneralTacticalView */ private function getWelcomeMessage():string { - $message = $this->randomWelcomeMessage(); + global $config; + + $flag_eastern_egg = $config['eastern_eggs_disabled']; + + if ((bool) $flag_eastern_egg === true) { + $message = $this->randomWelcomeMessage(); + } else { + $user = users_get_user_by_id($config['id_user']); + if (is_array($user) === true && count($user) > 0) { + $name = $user['fullname']; + } else { + $name = ''; + $name = $user['firstname']; + } + + if (empty($name) === true) { + $message = __('Welcome back! 👋'); + } else { + $message = __('Welcome back %s! 👋', $name); + } + } return html_print_div( [ From 9f72dd7d6e08505e0358c5aa506a14140e020d61 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 24 Nov 2023 14:01:17 +0100 Subject: [PATCH 104/397] #12200 Added setup flag for easter egg --- pandora_console/include/functions_menu.php | 2 +- pandora_console/include/javascript/pandora.js | 4 ++-- pandora_console/index.php | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index ac76541162..6679b890ea 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -1328,7 +1328,7 @@ if (is_ajax()) {
    - + logo diff --git a/pandora_console/include/javascript/pandora.js b/pandora_console/include/javascript/pandora.js index df9ee447dd..3ac30e5e83 100644 --- a/pandora_console/include/javascript/pandora.js +++ b/pandora_console/include/javascript/pandora.js @@ -2558,11 +2558,11 @@ function WarningPeriodicityModal(title, message) { }); } -function christmas_click() { +function christmas_click(flagEasternEgg) { let counter = $("#count_click").val(); counter++; $("#count_click").val(counter); - if (counter == 25) { + if (counter == 25 && flagEasternEgg == true) { $("#container-snow").removeClass("invisible"); setTimeout(() => { $("#container-snow").addClass("invisible"); diff --git a/pandora_console/index.php b/pandora_console/index.php index 63f063c02d..917448ee01 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1682,8 +1682,10 @@ require 'include/php_to_js_values.php'; $(document).ready(function() { const date = new Date(); const today = date.toLocaleDateString(); - const christmasDay = "25-12-2023"; - if (today == christmasDay) { + const year = date.getFullYear(); + const christmasDay = "25/12/"+year; + let flagEasternEgg = $("#flagEasternEgg").val(); + if (today === christmasDay && flagEasternEgg == true) { $("#container-snow").removeClass('invisible'); setTimeout(() => { $("#container-snow").addClass('invisible'); From 3d3cbd5e96a2b3404dacc1b439d2b63fcbfee290 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Mon, 27 Nov 2023 09:39:56 +0100 Subject: [PATCH 105/397] 9753 Fixed group list --- pandora_console/godmode/groups/modu_group_list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/godmode/groups/modu_group_list.php b/pandora_console/godmode/groups/modu_group_list.php index 560de898e9..a8f7930b26 100644 --- a/pandora_console/godmode/groups/modu_group_list.php +++ b/pandora_console/godmode/groups/modu_group_list.php @@ -154,7 +154,7 @@ if ($is_management_allowed === true && $update_group === true) { $subcheck = db_get_value('name', 'tmodule_group', 'id_mg', $id_group); if ($name) { - if (!$check || $subcheck == $name) { + if ($check === false || strcasecmp($subcheck, $name) === 0) { $result = db_process_sql_update( 'tmodule_group', ['name' => $name], From 3f3e8e42bcc160b4b67202db61971c2963deef14 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 28 Nov 2023 08:13:00 +0100 Subject: [PATCH 106/397] move extension translate_string and file_repo pandora_enterprise#12333 --- pandora_console/extensions/files_repo.php | 286 ------------------ .../files_repo/files_repo_get_file.php | 68 ----- .../extensions/files_repo/files_repo_list.php | 168 ---------- .../files_repo/sql/files_repo.oracle.sql | 16 - .../files_repo/sql/files_repo.postgreSQL.sql | 2 - .../extensions/files_repo/sql/files_repo.sql | 15 - .../extras/delete_files/delete_files.txt | 4 + pandora_console/extras/mr/67.sql | 29 ++ .../godmode/files_repo/files_repo.php | 167 ++++++++++ .../files_repo/files_repo_form.php | 41 ++- .../godmode/files_repo/files_repo_list.php | 153 ++++++++++ pandora_console/godmode/menu.php | 2 + .../include/functions_extensions.php | 18 +- .../functions_files_repository.php} | 167 +++++++--- pandora_console/include/functions_io.php | 32 +- pandora_console/include/get_file.php | 3 +- pandora_console/operation/menu.php | 5 + pandora_console/pandoradb.sql | 24 +- 18 files changed, 555 insertions(+), 645 deletions(-) delete mode 100644 pandora_console/extensions/files_repo.php delete mode 100644 pandora_console/extensions/files_repo/files_repo_get_file.php delete mode 100644 pandora_console/extensions/files_repo/files_repo_list.php delete mode 100644 pandora_console/extensions/files_repo/sql/files_repo.oracle.sql delete mode 100644 pandora_console/extensions/files_repo/sql/files_repo.postgreSQL.sql delete mode 100644 pandora_console/extensions/files_repo/sql/files_repo.sql create mode 100644 pandora_console/godmode/files_repo/files_repo.php rename pandora_console/{extensions => godmode}/files_repo/files_repo_form.php (76%) create mode 100644 pandora_console/godmode/files_repo/files_repo_list.php rename pandora_console/{extensions/files_repo/functions_files_repo.php => include/functions_files_repository.php} (69%) diff --git a/pandora_console/extensions/files_repo.php b/pandora_console/extensions/files_repo.php deleted file mode 100644 index a482a59669..0000000000 --- a/pandora_console/extensions/files_repo.php +++ /dev/null @@ -1,286 +0,0 @@ - 'files_repo_installed', - 'value' => 1, - ]; - db_process_sql_insert('tconfig', $values); - } - } -} - - -function pandora_files_repo_uninstall() -{ - global $config; - - switch ($config['dbtype']) { - case 'mysql': - db_process_sql('DROP TABLE `tfiles_repo_group`'); - db_process_sql('DROP TABLE `tfiles_repo`'); - db_process_sql( - 'DELETE FROM `tconfig` - WHERE `token` LIKE "files_repo_%"' - ); - break; - - case 'postgresql': - db_process_sql('DROP TABLE "tfiles_repo_group"'); - db_process_sql('DROP TABLE "tfiles_repo"'); - db_process_sql( - 'DELETE FROM "tconfig" - WHERE "token" LIKE \'files_repo_%\'' - ); - break; - - case 'oracle': - db_process_sql('DROP TRIGGER "tfiles_repo_group_inc"'); - db_process_sql('DROP SEQUENCE "tfiles_repo_group_s"'); - db_process_sql('DROP TABLE "tfiles_repo_group"'); - db_process_sql('DROP TRIGGER "tfiles_repo_inc"'); - db_process_sql('DROP SEQUENCE "tfiles_repo_s"'); - db_process_sql('DROP TABLE "tfiles_repo"'); - db_process_sql( - 'DELETE FROM tconfig - WHERE token LIKE \'files_repo_%\'' - ); - break; - } - - if (!empty($config['attachment_store'])) { - delete_dir($config['attachment_store'].'/files_repo'); - } -} - - -function pandora_files_repo_godmode() -{ - global $config; - - if (!isset($config['files_repo_installed']) || !$config['files_repo_installed']) { - ui_print_error_message(__('Extension not installed')); - } - - // ACL Check - check_login(); - if (! check_acl($config['id_user'], 0, 'PM')) { - db_pandora_audit( - AUDIT_LOG_ACL_VIOLATION, - 'Trying to access to Files repository' - ); - include 'general/noaccess.php'; - return; - } - - // Header tabs. - $godmode['text'] = ''.html_print_image('images/configuration@svg.svg', true, ['title' => __('Administration view'), 'class' => 'main_menu_icon invert_filter']).''; - $godmode['godmode'] = 1; - $godmode['active'] = 1; - - $operation['text'] = ''.html_print_image('images/see-details@svg.svg', true, ['title' => __('Operation view'), 'class' => 'main_menu_icon invert_filter']).''; - $operation['operation'] = 1; - - $onheader = [ - 'godmode' => $godmode, - 'operation' => $operation, - ]; - - // Header. - ui_print_standard_header( - __('Extensions'), - 'images/extensions.png', - false, - '', - true, - $onheader, - [ - [ - 'link' => '', - 'label' => __('Admin tools'), - ], - [ - 'link' => '', - 'label' => __('Extension manager'), - ], - [ - 'link' => '', - 'label' => __('Files repository manager'), - ], - ] - ); - - $full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/'; - include_once $full_extensions_dir.'files_repo/functions_files_repo.php'; - - // Directory files_repo check. - if (!files_repo_check_directory(true)) { - return; - } - - $server_content_length = 0; - if (isset($_SERVER['CONTENT_LENGTH'])) { - $server_content_length = $_SERVER['CONTENT_LENGTH']; - } - - // Check for an anoying error that causes the $_POST and $_FILES arrays. - // were empty if the file is larger than the post_max_size. - if (intval($server_content_length) > 0 && empty($_POST)) { - ui_print_error_message(__('Problem uploading. Please check this PHP runtime variable values:
      post_max_size (currently '.ini_get('post_max_size').')
    ')); - } - - // GET and POST parameters. - $file_id = (int) get_parameter('file_id'); - $add_file = (bool) get_parameter('add_file'); - $update_file = (bool) get_parameter('update_file'); - $delete_file = (bool) get_parameter('delete'); - - // File add or update. - if ($add_file || ($update_file && $file_id > 0)) { - $groups = get_parameter('groups', []); - $public = (bool) get_parameter('public'); - $description = io_safe_output((string) get_parameter('description')); - if (mb_strlen($description, 'UTF-8') > 200) { - $description = mb_substr($description, 0, 200, 'UTF-8'); - } - - $description = io_safe_input($description); - - if ($add_file) { - $result = files_repo_add_file('upfile', $description, $groups, $public); - } else if ($update_file) { - $result = files_repo_update_file($file_id, $description, $groups, $public); - $file_id = 0; - } - - if ($result['status'] == false) { - ui_print_error_message($result['message']); - } - } - - // File delete. - if ($delete_file && $file_id > 0) { - $result = files_repo_delete_file($file_id); - if ($result !== -1) { - ui_print_result_message($result, __('Successfully deleted'), __('Could not be deleted')); - } - - $file_id = 0; - } - - // FORM. - include $full_extensions_dir.'files_repo/files_repo_form.php'; - if (!$file_id) { - // LIST. - $manage = true; - include $full_extensions_dir.'files_repo/files_repo_list.php'; - } -} - - -function pandora_files_repo_operation() -{ - global $config; - - // Header tabs. - $onheader = []; - if (check_acl($config['id_user'], 0, 'PM')) { - $godmode['text'] = ''.html_print_image('images/configuration@svg.svg', true, ['title' => __('Administration view'), 'class' => 'main_menu_icon invert_filter']).''; - $godmode['godmode'] = 1; - - $operation['text'] = ''.html_print_image('images/see-details@svg.svg', true, ['title' => __('Operation view'), 'class' => 'main_menu_icon invert_filter']).''; - $operation['operation'] = 1; - $operation['active'] = 1; - - $onheader = [ - 'godmode' => $godmode, - 'operation' => $operation, - ]; - } - - // Header. - ui_print_standard_header( - __('Files repository'), - 'images/extensions.png', - false, - '', - false, - $onheader, - [ - [ - 'link' => '', - 'label' => __('Admin tools'), - ], - [ - 'link' => '', - 'label' => __('Extension manager'), - ], - [ - 'link' => '', - 'label' => __('Files repository'), - ], - ] - ); - - $full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/'; - include_once $full_extensions_dir.'files_repo/functions_files_repo.php'; - - // Directory files_repo check. - if (!files_repo_check_directory(true)) { - return; - } - - // LIST. - $full_extensions_dir = $config['homedir'].'/'.EXTENSIONS_DIR.'/'; - - include $full_extensions_dir.'files_repo/files_repo_list.php'; -} - - -extensions_add_operation_menu_option(__('Files repository'), null, null, 'v1r1'); -extensions_add_main_function('pandora_files_repo_operation'); -extensions_add_godmode_menu_option(__('Files repository manager'), 'PM', null, null, 'v1r1'); -extensions_add_godmode_function('pandora_files_repo_godmode'); - -pandora_files_repo_install(); diff --git a/pandora_console/extensions/files_repo/files_repo_get_file.php b/pandora_console/extensions/files_repo/files_repo_get_file.php deleted file mode 100644 index 6d6595a01f..0000000000 --- a/pandora_console/extensions/files_repo/files_repo_get_file.php +++ /dev/null @@ -1,68 +0,0 @@ - $file_hash]); -if (!$file) { - throw_error(10); - // ERROR -} - -// Case sensitive check -$check_hash = ($file['hash'] == $file_hash) ? true : false; -if (!$check_hash) { - throw_error(10); - // ERROR -} - -// Get the location -$files_repo_path = io_safe_output($config['attachment_store']).'/files_repo'; -$location = $files_repo_path.'/'.$file['id'].'_'.$file['name']; -if (!file_exists($location) || !is_readable($location) || !is_file($location)) { - throw_error(5); - // ERROR -} - -// All checks are fine. Download the file! -header('Content-type: aplication/octet-stream;'); -header('Content-Length: '.filesize($location)); -header('Content-Disposition: attachment; filename="'.$file['name'].'"'); -readfile($location); - - -function throw_error($time=15) -{ - sleep($time); - - $styleError = 'background:url("../images/err.png") no-repeat scroll 0 0 transparent; padding:4px 1px 6px 30px; color:#CC0000;'; - echo "

    ".__('Unreliable petition').'. '.__('Please contact the administrator').'

    '; - exit; -} diff --git a/pandora_console/extensions/files_repo/files_repo_list.php b/pandora_console/extensions/files_repo/files_repo_list.php deleted file mode 100644 index 6c08b8f505..0000000000 --- a/pandora_console/extensions/files_repo/files_repo_list.php +++ /dev/null @@ -1,168 +0,0 @@ - 'id', - 'order' => 'DESC', -]; - -$files = files_repo_get_files($filter); - - -if (!empty($files)) { - if (!isset($manage)) { - $manage = false; - } - - // Pagination - if ($manage) { - $url = ui_get_full_url('index.php?sec=godmode/extensions&sec2=extensions/files_repo'); - } else { - $url = ui_get_full_url('index.php?sec=extensions&sec2=extensions/files_repo'); - } - - $total_files = files_repo_get_files(false, true); - ui_pagination($total_files, $url, $offset); - - $table = new stdClass(); - $table->width = '100%'; - $table->class = 'info_table'; - $table->style = []; - $table->style[1] = 'max-width: 200px;'; - $table->style[4] = 'text-align: center;'; - $table->head = []; - $table->head[0] = __('Name'); - $table->head[1] = __('Description'); - $table->head[2] = __('Size'); - $table->head[3] = __('Last modification'); - $table->head[4] = ''; - $table->data = []; - - foreach ($files as $file_id => $file) { - $data = []; - - // Prepare the filename for the get_file.php script - $document_root = str_replace( - '\\', - '/', - io_safe_output($_SERVER['DOCUMENT_ROOT']) - ); - $file['location'] = str_replace( - '\\', - '/', - io_safe_output($file['location']) - ); - $relative_path = str_replace($document_root, '', $file['location']); - $file_name = explode('/', $file['location']); - $file_decoded = $file_name[(count($file_name) - 1)]; - $file_path = base64_encode($file_decoded); - $hash = md5($file_path.$config['server_unique_identifier']); - $url = ui_get_full_url( - 'include/get_file.php?file='.urlencode($file_path).'&hash='.$hash - ); - $date_format = ($config['date_format']) ? io_safe_output($config['date_format']) : 'F j, Y - H:m'; - - $data[0] = "".$file['name'].''; - // Name - $data[1] = ui_print_truncate_text( - $file['description'], - 'description', - true, - true - ); - // Description - $data[2] = ui_format_filesize($file['size']); - // Size - $data[3] = date($date_format, $file['mtime']); - // Last modification - // Public URL - $data[4] = ''; - $table->cellclass[][4] = 'table_action_buttons'; - if (!empty($file['hash'])) { - $public_url = ui_get_full_url( - EXTENSIONS_DIR.'/files_repo/files_repo_get_file.php?file='.$file['hash'] - ); - $message = __('Copy to clipboard').': Ctrl+C -> Enter'; - $action = "window.prompt('$message', '$public_url');"; - $data[4] .= ""; - $data[4] .= html_print_image( - 'images/world.png', - true, - ['title' => __('Public link')] - ); - // Public link image - $data[4] .= ' '; - } - - $data[4] .= ""; - $data[4] .= html_print_image( - 'images/download.png', - true, - [ - 'title' => __('Download'), - 'style' => 'padding:3px', - ] - ); - // Download image - $data[4] .= ''; - - if ($manage) { - $config_url = ui_get_full_url( - 'index.php?sec=godmode/extensions&sec2=extensions/files_repo&file_id='.$file_id - ); - $data[4] .= ""; - $data[4] .= html_print_image( - 'images/edit.svg', - true, - [ - 'title' => __('Edit'), - 'class' => 'main_menu_icon invert_filter', - ] - ); - // Edit image - $data[4] .= ''; - - $delete_url = ui_get_full_url( - 'index.php?sec=godmode/extensions&sec2=extensions/files_repo&delete=1&file_id='.$file_id - ); - $data[4] .= " "; - $data[4] .= html_print_image( - 'images/delete.svg', - true, - [ - 'title' => __('Delete'), - 'class' => 'main_menu_icon invert_filter', - ] - ); - // Delete image - $data[4] .= ''; - } - - $table->data[] = $data; - } - - html_print_table($table); -} else { - ui_print_info_message(__('No items')); -} diff --git a/pandora_console/extensions/files_repo/sql/files_repo.oracle.sql b/pandora_console/extensions/files_repo/sql/files_repo.oracle.sql deleted file mode 100644 index d86b775920..0000000000 --- a/pandora_console/extensions/files_repo/sql/files_repo.oracle.sql +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE tfiles_repo ( - id NUMBER(5, 0) NOT NULL PRIMARY KEY, - name VARCHAR2(255) NOT NULL, - description VARCHAR2(500) NULL, - hash VARCHAR2(8) NULL -); -CREATE SEQUENCE tfiles_repo_s INCREMENT BY 1 START WITH 1; -CREATE OR REPLACE TRIGGER tfiles_repo_inc BEFORE INSERT ON tfiles_repo REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tfiles_repo_s.nextval INTO :NEW.ID FROM dual; END;; - -CREATE TABLE tfiles_repo_group ( - id NUMBER(10, 0) NOT NULL PRIMARY KEY, - id_file NUMBER(5, 0) NOT NULL REFERENCES tfiles_repo(id) ON DELETE CASCADE, - id_group NUMBER(4, 0) NOT NULL -); -CREATE SEQUENCE tfiles_repo_group_s INCREMENT BY 1 START WITH 1; -CREATE OR REPLACE TRIGGER tfiles_repo_group_inc BEFORE INSERT ON tfiles_repo_group REFERENCING NEW AS NEW FOR EACH ROW BEGIN SELECT tfiles_repo_group_s.nextval INTO :NEW.ID FROM dual; END;; \ No newline at end of file diff --git a/pandora_console/extensions/files_repo/sql/files_repo.postgreSQL.sql b/pandora_console/extensions/files_repo/sql/files_repo.postgreSQL.sql deleted file mode 100644 index 3f129e10cb..0000000000 --- a/pandora_console/extensions/files_repo/sql/files_repo.postgreSQL.sql +++ /dev/null @@ -1,2 +0,0 @@ -CREATE TABLE "tfiles_repo" ("id" SERIAL NOT NULL PRIMARY KEY, "name" VARCHAR(255) NOT NULL, "description" VARCHAR(500) NULL default '', "hash" VARCHAR(8) NULL default ''); -CREATE TABLE "tfiles_repo_group" ("id" SERIAL NOT NULL PRIMARY KEY, "id_file" INTEGER NOT NULL REFERENCES tfiles_repo("id") ON DELETE CASCADE, "id_group" INTEGER NOT NULL); diff --git a/pandora_console/extensions/files_repo/sql/files_repo.sql b/pandora_console/extensions/files_repo/sql/files_repo.sql deleted file mode 100644 index d6dce31339..0000000000 --- a/pandora_console/extensions/files_repo/sql/files_repo.sql +++ /dev/null @@ -1,15 +0,0 @@ -CREATE TABLE IF NOT EXISTS `tfiles_repo` ( - `id` int(5) unsigned NOT NULL auto_increment, - `name` varchar(255) NOT NULL, - `description` varchar(500) NULL default '', - `hash` varchar(8) NULL default '', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE IF NOT EXISTS `tfiles_repo_group` ( - `id` int(10) unsigned NOT NULL auto_increment, - `id_file` int(5) unsigned NOT NULL, - `id_group` int(4) unsigned NOT NULL, - PRIMARY KEY (`id`), - FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index 234ec4e997..6704356ae4 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -1720,3 +1720,7 @@ include/functions_integriaims.php include/ajax/integria_incidents.ajax.php enterprise/operation/log/log_source.php enterprise/include/class/LogSource.class.php +enterprise/extensions/translate_string +enterprise/extensions/translate_string.php +extensions/files_repo +extensions/files_repo.php diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index a31ea6e670..2e04ab23c2 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -5,4 +5,33 @@ DROP TABLE tagent_access; ALTER TABLE treport_content ADD check_unknowns_graph tinyint DEFAULT 0 NULL; +DELETE FROM `tconfig` WHERE `token` LIKE 'translate_string_extension_installed'; + +CREATE TABLE IF NOT EXISTS `textension_translate_string` ( + `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, + `lang` VARCHAR(10) NOT NULL , + `string` TEXT , + `translation` TEXT , + PRIMARY KEY (`id`), + KEY `lang_index` (`lang`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +DELETE FROM `tconfig` WHERE `token` LIKE 'files_repo_installed'; + +CREATE TABLE IF NOT EXISTS `tfiles_repo` ( + `id` int(5) unsigned NOT NULL auto_increment, + `name` varchar(255) NOT NULL, + `description` varchar(500) NULL default '', + `hash` varchar(8) NULL default '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `tfiles_repo_group` ( + `id` int(10) unsigned NOT NULL auto_increment, + `id_file` int(5) unsigned NOT NULL, + `id_group` int(4) unsigned NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + COMMIT; diff --git a/pandora_console/godmode/files_repo/files_repo.php b/pandora_console/godmode/files_repo/files_repo.php new file mode 100644 index 0000000000..cf22ee294c --- /dev/null +++ b/pandora_console/godmode/files_repo/files_repo.php @@ -0,0 +1,167 @@ +'; +$godmode['text'] .= html_print_image( + 'images/configuration@svg.svg', + true, + [ + 'title' => __('Administration view'), + 'class' => 'main_menu_icon invert_filter', + ] +); +$godmode['text'] .= ''; +$godmode['godmode'] = 1; + +$operation['text'] = ''; +$operation['text'] .= html_print_image( + 'images/see-details@svg.svg', + true, + [ + 'title' => __('Operation view'), + 'class' => 'main_menu_icon invert_filter', + ] +); +$operation['text'] .= ''; +$operation['operation'] = 1; + +$operation['active'] = 1; +$godmode['active'] = 0; +if ($tab === 'configuration') { + $godmode['active'] = 1; + $operation['active'] = 0; +} + +$onheader = [ + 'godmode' => $godmode, + 'operation' => $operation, +]; + +// Header. +ui_print_standard_header( + __('Extensions'), + 'images/extensions.png', + false, + '', + true, + $onheader, + [ + [ + 'link' => '', + 'label' => __('Tools'), + ], + [ + 'link' => '', + 'label' => __('Files repository'), + ], + ] +); + +require_once __DIR__.'/../../include/functions_files_repository.php'; + +// Directory files_repo check. +if (files_repo_check_directory() === false) { + return; +} + +$server_content_length = 0; +if (isset($_SERVER['CONTENT_LENGTH'])) { + $server_content_length = $_SERVER['CONTENT_LENGTH']; +} + +// Check for an anoying error that causes the $_POST and $_FILES arrays. +// were empty if the file is larger than the post_max_size. +if (intval($server_content_length) > 0 && empty($_POST)) { + ui_print_error_message( + __('Problem uploading. Please check this PHP runtime variable values:
      post_max_size (currently '.ini_get('post_max_size').')
    ') + ); +} + +// GET and POST parameters. +$file_id = (int) get_parameter('file_id'); +$add_file = (bool) get_parameter('add_file'); +$update_file = (bool) get_parameter('update_file'); +$delete_file = (bool) get_parameter('delete'); + +// File add or update. +if ($add_file === true || ($update_file === true && $file_id > 0)) { + $groups = get_parameter('groups', []); + $public = (bool) get_parameter('public'); + $description = io_safe_output((string) get_parameter('description')); + if (mb_strlen($description, 'UTF-8') > 200) { + $description = mb_substr($description, 0, 200, 'UTF-8'); + } + + $description = io_safe_input($description); + + if ($add_file === true) { + $result = files_repo_add_file('upfile', $description, $groups, $public); + } else if ($update_file === true) { + $result = files_repo_update_file($file_id, $description, $groups, $public); + $file_id = 0; + } + + if ($result['status'] == false) { + ui_print_error_message($result['message']); + } else { + if ($add_file === true) { + ui_print_success_message(__('Successfully created')); + } else if ($update_file === true) { + ui_print_success_message(__('Successfully updated')); + } + } +} + +// File delete. +if ($delete_file === true && $file_id > 0) { + $result = files_repo_delete_file($file_id); + if ($result !== -1) { + ui_print_result_message($result, __('Successfully deleted'), __('Could not be deleted')); + } + + $file_id = 0; +} + +$operation['active'] = 1; +if ($tab === 'configuration') { + include_once __DIR__.'/files_repo_form.php'; +} else { + include_once __DIR__.'/files_repo_list.php'; +} diff --git a/pandora_console/extensions/files_repo/files_repo_form.php b/pandora_console/godmode/files_repo/files_repo_form.php similarity index 76% rename from pandora_console/extensions/files_repo/files_repo_form.php rename to pandora_console/godmode/files_repo/files_repo_form.php index d8bf6c6836..bf1bc81ca7 100644 --- a/pandora_console/extensions/files_repo/files_repo_form.php +++ b/pandora_console/godmode/files_repo/files_repo_form.php @@ -1,20 +1,27 @@ 0) { 'file_id', $file_id, true + ).html_print_input_hidden( + 'update_file', + 1, + true ) ); } else { @@ -150,8 +161,8 @@ if ($file_id > 0) { $table->data[] = $row; -$url = ui_get_full_url('index.php?sec=godmode/extensions&sec2=extensions/files_repo'); -echo ""; +$url = ui_get_full_url('index.php?sec=extensions&sec2=godmode/files_repo/files_repo'); +echo ''; html_print_table($table); html_print_action_buttons($submit_button); echo ''; diff --git a/pandora_console/godmode/files_repo/files_repo_list.php b/pandora_console/godmode/files_repo/files_repo_list.php new file mode 100644 index 0000000000..f89b4b2d12 --- /dev/null +++ b/pandora_console/godmode/files_repo/files_repo_list.php @@ -0,0 +1,153 @@ + 'id', + 'order' => 'DESC', +]; + +$files = files_repo_get_files($filter); + +if (empty($files) === false) { + $url = ui_get_full_url('index.php?sec=extensions&sec2=godmode/files_repo/files_repo'); + + $total_files = files_repo_get_files(false, true); + ui_pagination($total_files, $url, $offset); + + $table = new stdClass(); + $table->width = '100%'; + $table->class = 'info_table'; + $table->style = []; + $table->style[1] = 'max-width: 200px;'; + $table->style[4] = 'text-align: center;'; + $table->head = []; + $table->head[0] = __('Name'); + $table->head[1] = __('Description'); + $table->head[2] = __('Size'); + $table->head[3] = __('Last modification'); + $table->head[4] = ''; + $table->data = []; + + foreach ($files as $file_id => $file) { + $data = []; + // Prepare the filename for the get_file.php script. + $document_root = str_replace( + '\\', + '/', + io_safe_output($_SERVER['DOCUMENT_ROOT']) + ); + $file['location'] = str_replace( + '\\', + '/', + io_safe_output($file['location']) + ); + $relative_path = str_replace($document_root, '', $file['location']); + $file_name = explode('/', $file['location']); + $file_decoded = $file_name[(count($file_name) - 1)]; + $file_path = base64_encode($file_decoded); + $hash = md5($file_path.$config['server_unique_identifier']); + $url_get_file = ui_get_full_url( + 'include/get_file.php?file='.urlencode($file_path).'&hash='.$hash + ); + + $date_format = (isset($config['date_format']) === true) ? io_safe_output($config['date_format']) : 'F j, Y - H:m'; + + $data[0] = ''.$file['name'].''; + // Name. + $data[1] = ui_print_truncate_text( + $file['description'], + 'description', + true, + true + ); + // Description. + $data[2] = ui_format_filesize($file['size']); + // Size. + $data[3] = date($date_format, $file['mtime']); + // Last modification. + // Public URL. + $data[4] = ''; + $table->cellclass[][4] = 'table_action_buttons'; + if (empty($file['hash']) === false) { + $message = __('Copy to clipboard').': Ctrl+C -> Enter'; + $action = 'window.prompt(\''.$message.'\', \''.$url_get_file.'\');'; + $data[4] .= ''; + $data[4] .= html_print_image( + 'images/world.png', + true, + ['title' => __('Public link')] + ); + // Public link image. + $data[4] .= ' '; + } + + $data[4] .= ''; + $data[4] .= html_print_image( + 'images/download.png', + true, + [ + 'title' => __('Download'), + 'style' => 'padding:3px', + ] + ); + // Download image. + $data[4] .= ''; + + $config_url = $url.'&tab=configuration&file_id='.$file_id; + $data[4] .= ''; + $data[4] .= html_print_image( + 'images/edit.svg', + true, + [ + 'title' => __('Edit'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + // Edit image. + $data[4] .= ''; + + $delete_url = $url.'&delete=1&file_id='.$file_id; + $data[4] .= ''; + $data[4] .= html_print_image( + 'images/delete.svg', + true, + [ + 'title' => __('Delete'), + 'class' => 'main_menu_icon invert_filter', + ] + ); + // Delete image. + $data[4] .= ''; + + $table->data[] = $data; + } + + html_print_table($table); +} else { + ui_print_info_message(__('No items')); +} diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index 171e16870b..bd041e098a 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -508,6 +508,8 @@ if ($access_console_node === true) { enterprise_hook('skins_submenu'); + enterprise_hook('translate_string_submenu'); + $menu_godmode['gsetup']['sub'] = $sub; } } diff --git a/pandora_console/include/functions_extensions.php b/pandora_console/include/functions_extensions.php index acecf194ec..f381484461 100755 --- a/pandora_console/include/functions_extensions.php +++ b/pandora_console/include/functions_extensions.php @@ -169,13 +169,21 @@ function extensions_get_extensions($enterprise=false, $rel_path='') $file = readdir($handle); } - // Load extensions in enterprise directory - if (! $enterprise && file_exists($master_dir)) { - return array_merge($extensions, extensions_get_extensions(true, $rel_path)); + if (isset($extensions['ipam.php']) === true) { + unset($extensions['ipam.php']); } - if (isset($extensions['ipam.php'])) { - unset($extensions['ipam.php']); + if (isset($extensions['translate_string.php']) === true) { + unset($extensions['translate_string.php']); + } + + if (isset($extensions['files_repo.php']) === true) { + unset($extensions['files_repo.php']); + } + + // Load extensions in enterprise directory. + if (! $enterprise && file_exists($master_dir)) { + return array_merge($extensions, extensions_get_extensions(true, $rel_path)); } return $extensions; diff --git a/pandora_console/extensions/files_repo/functions_files_repo.php b/pandora_console/include/functions_files_repository.php similarity index 69% rename from pandora_console/extensions/files_repo/functions_files_repo.php rename to pandora_console/include/functions_files_repository.php index 2989499350..18ac6ce8ad 100644 --- a/pandora_console/extensions/files_repo/functions_files_repo.php +++ b/pandora_console/include/functions_files_repository.php @@ -1,17 +1,34 @@

    '; + $msg_error .= sprintf( + __('Please check that the web server has write rights on the %s directory'), + $attachment_path + ); + + // Attachment/ check. + if (is_writable($attachment_path) === false) { $messages .= ui_print_error_message( [ - 'message' => __('Attachment directory is not writable by HTTP Server').''.'

    '.sprinf(__('Please check that the web server has write rights on the %s directory'), $attachment_path), + 'message' => $msg_error, 'no_close' => true, 'force_style' => 'color: #000000 !important', ], @@ -33,17 +57,17 @@ function files_repo_check_directory($print_messages=false) true ); } else { - // attachment/agent_packages/ check - if (!file_exists($files_repo_path) || !is_writable($files_repo_path)) { - // Create the directoty if not exist - if (!file_exists($files_repo_path)) { + // Attachment/agent_packages/ check. + if (file_exists($files_repo_path) === false || is_writable($files_repo_path) === false) { + // Create the directoty if not exist. + if (file_exists($files_repo_path) === false) { mkdir($files_repo_path); } - if (!is_writable($files_repo_path)) { + if (is_writable($files_repo_path) === false) { $messages .= ui_print_error_message( [ - 'message' => __('Attachment directory is not writable by HTTP Server').''.'

    '.sprintf(__('Please check that the web server has write rights on the %s directory'), $attachment_path), + 'message' => $msg_error, 'no_close' => true, 'force_style' => 'color: #000000 !important', ], @@ -58,48 +82,60 @@ function files_repo_check_directory($print_messages=false) } } - if ($print_messages) { - echo $messages; - } + echo $messages; return $result; } -function files_repo_check_file_acl($file_id, $user_id=false, $file_groups=false, $user_groups=false) -{ +/** + * Check acl file + * + * @param integer $file_id ID. + * @param boolean $user_id Users. + * @param boolean $file_groups File Groups. + * @param boolean $user_groups User Groups. + * + * @return boolean + */ +function files_repo_check_file_acl( + $file_id, + $user_id=false, + $file_groups=false, + $user_groups=false +) { global $config; $result = false; - if (!$user_id) { + if (empty($user_id) === true) { $user_id = $config['id_user']; } - if (is_user_admin($user_id)) { + if (is_user_admin($user_id) === true) { return true; } if (!$file_groups) { $file_groups = files_repo_get_file_groups($file_id); - if (empty($file_groups)) { + if (empty($file_groups) === true) { $file_groups = []; } } - if (in_array(0, $file_groups)) { + if (in_array(0, $file_groups) === true) { return true; } if (!$user_groups) { $user_groups = users_get_groups($user_id, false, true); - if (empty($user_groups)) { + if (empty($user_groups) === true) { $user_groups = []; } } foreach ($file_groups as $group_id) { - // $user_groups has the id in the array keys - if (in_array($group_id, $user_groups)) { + // $user_groups has the id in the array keys. + if (in_array($group_id, $user_groups) === true) { $result = true; break; } @@ -109,13 +145,19 @@ function files_repo_check_file_acl($file_id, $user_id=false, $file_groups=false, } +/** + * File groups. + * + * @param integer $file_id File. + * + * @return array + */ function files_repo_get_file_groups($file_id) { $groups = []; $filter = ['id_file' => $file_id]; $result = db_get_all_rows_filter('tfiles_repo_group', $filter, 'id_group'); - - if (!empty($result)) { + if (empty($result) === false) { foreach ($result as $key => $value) { $groups[] = $value['id_group']; } @@ -125,13 +167,19 @@ function files_repo_get_file_groups($file_id) } +/** + * File user groups. + * + * @param string $user_id User id. + * + * @return array + */ function files_repo_get_user_groups($user_id) { $groups = []; $filter = ['id_usuario' => $user_id]; $result = db_get_all_rows_filter('tusuario_perfil', $filter, 'id_grupo'); - - if (!empty($result)) { + if (empty($result) === false) { foreach ($result as $key => $value) { $groups[] = $value['id_grupo']; } @@ -141,7 +189,15 @@ function files_repo_get_user_groups($user_id) } -function files_repo_get_files($filter=false, $count=false) +/** + * Get files. + * + * @param array $filter Filters. + * @param boolean $count Count. + * + * @return array + */ +function files_repo_get_files($filter=[], $count=false) { global $config; @@ -171,9 +227,9 @@ function files_repo_get_files($filter=false, $count=false) $data['name'] = $file['name']; $data['description'] = $file['description']; $data['location'] = $files_repo_path.'/'.$file['id'].'_'.$data['name']; - // Size in bytes + // Size in bytes. $data['size'] = filesize($data['location']); - // Last modification time in unix timestamp + // Last modification time in unix timestamp. $data['mtime'] = filemtime($data['location']); $data['groups'] = $file_groups; $data['hash'] = $file['hash']; @@ -188,6 +244,16 @@ function files_repo_get_files($filter=false, $count=false) } +/** + * Add file. + * + * @param string $file_input_name Name. + * @param string $description Description. + * @param array $groups Groups. + * @param boolean $public Mode. + * + * @return array + */ function files_repo_add_file($file_input_name='upfile', $description='', $groups=[], $public=false) { global $config; @@ -210,10 +276,10 @@ function files_repo_add_file($file_input_name='upfile', $description='', $groups $invalid_extensions = '/^(php|php1|php2|php3|php4|php5|php7|php8|phar|phptml|phps)$/i'; if (preg_match($invalid_extensions, $extension) === 0) { - // Replace conflictive characters + // Replace conflictive characters. $filename = str_replace([' ', '=', '?', '&'], '_', $filename); $filename = filter_var($filename, FILTER_SANITIZE_URL); - // The filename should not be larger than 200 characters + // The filename should not be larger than 200 characters. if (mb_strlen($filename, 'UTF-8') > 200) { $filename = mb_substr($filename, 0, 200, 'UTF-8'); } @@ -267,6 +333,16 @@ function files_repo_add_file($file_input_name='upfile', $description='', $groups } +/** + * Update file. + * + * @param string $file_id File Name. + * @param string $description Description. + * @param array $groups Groups. + * @param boolean $public Mode. + * + * @return array + */ function files_repo_update_file($file_id, $description='', $groups=[], $public=false) { global $config; @@ -308,6 +384,13 @@ function files_repo_update_file($file_id, $description='', $groups=[], $public=f } +/** + * Delete File + * + * @param string $file_id File Name. + * + * @return mixed + */ function files_repo_delete_file($file_id) { global $config; diff --git a/pandora_console/include/functions_io.php b/pandora_console/include/functions_io.php index 6283fdbaed..5b93341a56 100755 --- a/pandora_console/include/functions_io.php +++ b/pandora_console/include/functions_io.php @@ -410,32 +410,14 @@ function __($string /*, variable arguments */) global $config; - if (defined('METACONSOLE')) { - enterprise_include_once('meta/include/functions_meta.php'); + enterprise_include_once('include/functions_setup.php'); + $tranlateString = call_user_func_array( + 'get_defined_translation', + array_values(func_get_args()) + ); - $tranlateString = call_user_func_array( - 'meta_get_defined_translation', - array_values(func_get_args()) - ); - - if ($tranlateString !== false) { - return $tranlateString; - } - } else if (enterprise_installed() - && isset($config['translate_string_extension_installed']) - && $config['translate_string_extension_installed'] == 1 - && array_key_exists('translate_string.php', $extensions) - ) { - enterprise_include_once('extensions/translate_string/functions.php'); - - $tranlateString = call_user_func_array( - 'get_defined_translation', - array_values(func_get_args()) - ); - - if ($tranlateString !== false) { - return $tranlateString; - } + if ($tranlateString !== false) { + return $tranlateString; } if ($string == '') { diff --git a/pandora_console/include/get_file.php b/pandora_console/include/get_file.php index 679fdad5ad..435ac8dded 100644 --- a/pandora_console/include/get_file.php +++ b/pandora_console/include/get_file.php @@ -82,10 +82,9 @@ if (empty($file) === true || empty($hash) === true || $hash !== md5($file_raw.$c $downloadable_file = $_SERVER['DOCUMENT_ROOT'].'/pandora_console/'.$file; break; - case 'extensions/files_repo': + case 'godmode/files_repo/files_repo': $attachment_path = io_safe_output($config['attachment_store']); $downloadable_file = $attachment_path.'/files_repo/'.$file; - // $downloadable_file = $_SERVER['DOCUMENT_ROOT'].'/pandora_console/attachment/files_repo/'.$file; break; case 'godmode/servers/plugin': diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index c800d9b372..011d0a6581 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -752,6 +752,11 @@ if ($access_console_node === true) { $sub['godmode/agentes/planned_downtime.list']['id'] = 'Scheduled_downtime'; } + if ((bool) check_acl($config['id_user'], 0, 'PM') === true) { + $sub['godmode/files_repo/files_repo']['text'] = __('File Repository'); + $sub['godmode/files_repo/files_repo']['id'] = 'File_repository'; + } + foreach ($config['extensions'] as $extension) { // If no operation_menu is a godmode extension. if ($extension['operation_menu'] == '') { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 4c527345c0..6887710bcb 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4532,4 +4532,26 @@ CREATE TABLE IF NOT EXISTS `tpandora_cve` ( `cvss_score` DOUBLE DEFAULT NULL, `cvss_vector` VARCHAR(255) DEFAULT NULL, PRIMARY KEY (`cve_id`) -) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- --------------------------------------------------------------------- +-- Table `tfiles_repo` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tfiles_repo` ( + `id` int(5) unsigned NOT NULL auto_increment, + `name` varchar(255) NOT NULL, + `description` varchar(500) NULL default '', + `hash` varchar(8) NULL default '', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- --------------------------------------------------------------------- +-- Table `tfiles_repo_group` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tfiles_repo_group` ( + `id` int(10) unsigned NOT NULL auto_increment, + `id_file` int(5) unsigned NOT NULL, + `id_group` int(4) unsigned NOT NULL, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file From 6eefd38f65d844a3c60ecfdef10f7eb4a60ceab0 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 28 Nov 2023 08:49:58 +0100 Subject: [PATCH 107/397] move extension translate_string and file_repo pandora_enterprise#12333 --- .../extras/delete_files/delete_files.txt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandora_console/extras/delete_files/delete_files.txt b/pandora_console/extras/delete_files/delete_files.txt index 6704356ae4..a57328e54f 100644 --- a/pandora_console/extras/delete_files/delete_files.txt +++ b/pandora_console/extras/delete_files/delete_files.txt @@ -1720,7 +1720,18 @@ include/functions_integriaims.php include/ajax/integria_incidents.ajax.php enterprise/operation/log/log_source.php enterprise/include/class/LogSource.class.php -enterprise/extensions/translate_string enterprise/extensions/translate_string.php -extensions/files_repo +enterprise/extensions/translate_string/functions.php +enterprise/extensions/translate_string/translate_string.oracle.sql +enterprise/extensions/translate_string/translate_string.postgresql.sql +enterprise/extensions/translate_string/translate_string.sql +enterprise/extensions/translate_string extensions/files_repo.php +extensions/files_repo/files_repo_form.php +extensions/files_repo/files_repo_get_file.php +extensions/files_repo/files_repo_list.php +extensions/files_repo/functions_files_repo.php +extensions/files_repo/sql/files_repo.oracle.sql +extensions/files_repo/sql/files_repo.postgreSQL.sql +extensions/files_repo/sql/files_repo.sql +extensions/files_repo \ No newline at end of file From e7ebbedabc2f6188def055435810ad5f020eb770 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Tue, 28 Nov 2023 09:34:10 +0100 Subject: [PATCH 108/397] #12176 formatted error --- .../wizards/DiscoveryTaskList.class.php | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index e831022c23..0872b52e88 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -1474,13 +1474,20 @@ class DiscoveryTaskList extends HTML } else if ((int) $task['type'] === DISCOVERY_EXTENSION) { // Content. $countSummary = 1; + $countErrors = 1; + $tableErrors = new StdClasS(); + $tableErrors->class = 'databox data'; + $tableErrors->width = '75%'; + $tableErrors->styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;background: white;'; + $tableErrors->rowid = []; + $tableErrors->data = []; if (is_array($task['stats']) === true && count(array_filter(array_keys($task['stats']), 'is_numeric')) === count($task['stats'])) { foreach ($task['stats'] as $key => $summary) { - $table->data[$i][0] = ''.__('Summary').' '.$countSummary.''; - $table->data[$i][1] = ''; - $countSummary++; - $i++; if (is_array($summary) === true) { + $table->data[$i][0] = ''.__('Summary').' '.$countSummary.''; + $table->data[$i][1] = ''; + $countSummary++; + $i++; if (empty($summary['summary']) === true && empty($summary['info']) === true) { $table->data[$i][0] = json_encode($summary, JSON_PRETTY_PRINT); $table->data[$i][1] = ''; @@ -1517,8 +1524,12 @@ class DiscoveryTaskList extends HTML $i++; } } else { - $table->data[$i][0] = $summary; - $table->data[$i][1] = ''; + $tableErrors->data[$i][0] = ''.__('Error %s', $countErrors).''; + $tableErrors->data[$i][1] = ''; + $i++; + $tableErrors->data[$i][0] = $summary; + $tableErrors->data[$i][1] = ''; + $countErrors++; $i++; } } @@ -1565,7 +1576,15 @@ class DiscoveryTaskList extends HTML } $output = '

    '.__('Summary').'
    '; - $output .= html_print_table($table, true).''; + if (is_array($table->data) === true && count($table->data) > 0) { + $output .= html_print_table($table, true); + } + + if (is_array($tableErrors->data) === true && count($tableErrors->data) > 0) { + $output .= html_print_table($tableErrors, true); + } + + $output .= ''; } return $output; From 4ce47cec8ebb2870c2ae8aa5c07d36edefc80eed Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Tue, 28 Nov 2023 09:56:51 +0100 Subject: [PATCH 109/397] #12176 control error legacy --- .../wizards/DiscoveryTaskList.class.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php index 0872b52e88..d088e8c84f 100644 --- a/pandora_console/godmode/wizards/DiscoveryTaskList.class.php +++ b/pandora_console/godmode/wizards/DiscoveryTaskList.class.php @@ -1422,6 +1422,14 @@ class DiscoveryTaskList extends HTML $table->rowid = []; $table->data = []; + $countErrors = 1; + $tableErrors = new StdClasS(); + $tableErrors->class = 'databox data'; + $tableErrors->width = '75%'; + $tableErrors->styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;background: white;'; + $tableErrors->rowid = []; + $tableErrors->data = []; + if ($task['review_mode'] == DISCOVERY_RESULTS) { $agents_review = db_get_all_rows_filter( 'tdiscovery_tmp_agents', @@ -1474,13 +1482,6 @@ class DiscoveryTaskList extends HTML } else if ((int) $task['type'] === DISCOVERY_EXTENSION) { // Content. $countSummary = 1; - $countErrors = 1; - $tableErrors = new StdClasS(); - $tableErrors->class = 'databox data'; - $tableErrors->width = '75%'; - $tableErrors->styleTable = 'margin: 2em auto 0;border: 1px solid #ddd;background: white;'; - $tableErrors->rowid = []; - $tableErrors->data = []; if (is_array($task['stats']) === true && count(array_filter(array_keys($task['stats']), 'is_numeric')) === count($task['stats'])) { foreach ($task['stats'] as $key => $summary) { if (is_array($summary) === true) { @@ -1571,7 +1572,13 @@ class DiscoveryTaskList extends HTML $table->data[$i++][1] .= ''; } } else { - $table->data[$i][0] = $task['stats']['summary']; + $tableErrors->data[$i][0] = ''.__('Error %s', $countErrors).''; + $tableErrors->data[$i][1] = ''; + $i++; + $tableErrors->data[$i][0] = $task['stats']['summary']; + $tableErrors->data[$i][1] = ''; + $countErrors++; + $i++; } } From 5bd689500c3c65fbb4e10f06df950cda0693b9c6 Mon Sep 17 00:00:00 2001 From: daniel Date: Tue, 28 Nov 2023 11:06:39 +0100 Subject: [PATCH 110/397] move extension translate_string and file_repo pandora_enterprise#12333 --- pandora_console/extras/mr/67.sql | 4 +- .../files_repo/files_repo_get_file.php | 81 +++++++++++++++++++ .../godmode/files_repo/files_repo_list.php | 6 +- pandora_console/godmode/menu.php | 20 +++-- pandora_console/operation/menu.php | 78 +++++------------- pandora_console/pandoradb_data.sql | 4 +- 6 files changed, 127 insertions(+), 66 deletions(-) create mode 100644 pandora_console/godmode/files_repo/files_repo_get_file.php diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 2e04ab23c2..ded4d9d9bb 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -24,7 +24,7 @@ CREATE TABLE IF NOT EXISTS `tfiles_repo` ( `description` varchar(500) NULL default '', `hash` varchar(8) NULL default '', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; CREATE TABLE IF NOT EXISTS `tfiles_repo_group` ( `id` int(10) unsigned NOT NULL auto_increment, @@ -32,6 +32,6 @@ CREATE TABLE IF NOT EXISTS `tfiles_repo_group` ( `id_group` int(4) unsigned NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`id_file`) REFERENCES tfiles_repo(`id`) ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; COMMIT; diff --git a/pandora_console/godmode/files_repo/files_repo_get_file.php b/pandora_console/godmode/files_repo/files_repo_get_file.php new file mode 100644 index 0000000000..b9a5b4c821 --- /dev/null +++ b/pandora_console/godmode/files_repo/files_repo_get_file.php @@ -0,0 +1,81 @@ + $file_hash]); +if (!$file) { + throw_error(10); +} + +// Case sensitive check. +$check_hash = ($file['hash'] == $file_hash) ? true : false; +if (!$check_hash) { + throw_error(10); +} + +// Get the location. +$files_repo_path = io_safe_output($config['attachment_store']).'/files_repo'; +$location = $files_repo_path.'/'.$file['id'].'_'.$file['name']; +if (!file_exists($location) || !is_readable($location) || !is_file($location)) { + throw_error(5); +} + +// All checks are fine. Download the file! +header('Content-type: aplication/octet-stream;'); +header('Content-Length: '.filesize($location)); +header('Content-Disposition: attachment; filename="'.$file['name'].'"'); +readfile($location); + + +/** + * Show errors + * + * @param integer $time Sleep. + * + * @return void + */ +function throw_error($time=15) +{ + sleep($time); + + $styleError = 'background:url("../images/err.png") no-repeat scroll 0 0 transparent; padding:4px 1px 6px 30px; color:#CC0000;'; + echo "

    ".__('Unreliable petition').'. '.__('Please contact the administrator').'

    '; + exit; +} diff --git a/pandora_console/godmode/files_repo/files_repo_list.php b/pandora_console/godmode/files_repo/files_repo_list.php index f89b4b2d12..bc2fb4e1bf 100644 --- a/pandora_console/godmode/files_repo/files_repo_list.php +++ b/pandora_console/godmode/files_repo/files_repo_list.php @@ -94,8 +94,12 @@ if (empty($files) === false) { $data[4] = ''; $table->cellclass[][4] = 'table_action_buttons'; if (empty($file['hash']) === false) { + $url_get_public_file = ui_get_full_url( + 'godmode/files_repo/files_repo_get_file.php?file='.$file['hash'] + ); + $message = __('Copy to clipboard').': Ctrl+C -> Enter'; - $action = 'window.prompt(\''.$message.'\', \''.$url_get_file.'\');'; + $action = 'window.prompt(\''.$message.'\', \''.$url_get_public_file.'\');'; $data[4] .= ''; $data[4] .= html_print_image( 'images/world.png', diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index bd041e098a..da029bc11e 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -712,15 +712,25 @@ if ($access_console_node === true) { } if ($access_console_node === true) { - // Tools + // Tools. $menu_godmode['tools']['text'] = __('Tools'); $menu_godmode['tools']['sec2'] = 'operation/extensions'; $menu_godmode['tools']['id'] = 'oper-extensions'; $sub = []; - $sub['operation/agentes/exportdata']['text'] = __('Export data'); - $sub['operation/agentes/exportdata']['id'] = 'export_data'; - $sub['extensions/files_repo']['text'] = __('File repository'); - $sub['extensions/files_repo']['id'] = 'file_repository'; + + if (check_acl($config['id_user'], 0, 'RR') + || check_acl($config['id_user'], 0, 'RW') + || check_acl($config['id_user'], 0, 'RM') + ) { + $sub['operation/agentes/exportdata']['text'] = __('Export data'); + $sub['operation/agentes/exportdata']['id'] = 'export_data'; + } + + if ((bool) check_acl($config['id_user'], 0, 'PM') === true) { + $sub['godmode/files_repo/files_repo']['text'] = __('File repository'); + $sub['godmode/files_repo/files_repo']['id'] = 'file_repository'; + } + $menu_godmode['tools']['sub'] = $sub; // About. diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 011d0a6581..f0777a61f1 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -734,29 +734,8 @@ if ($access_console_node === true) { } if ($access_console_node === true) { - // Rest of options, all with AR privilege (or should events be with incidents?) - // ~ if (check_acl ($config['id_user'], 0, "AR")) { // Extensions menu additions. if (is_array($config['extensions'])) { - $sub = []; - $sub2 = []; - - if (check_acl($config['id_user'], 0, 'RR') || check_acl($config['id_user'], 0, 'RW') || check_acl($config['id_user'], 0, 'RM')) { - $sub['operation/agentes/exportdata']['text'] = __('Export data'); - $sub['operation/agentes/exportdata']['id'] = 'Export_data'; - $sub['operation/agentes/exportdata']['subsecs'] = ['operation/agentes/exportdata']; - } - - if (check_acl($config['id_user'], 0, 'AR') || check_acl($config['id_user'], 0, 'AD') || check_acl($config['id_user'], 0, 'AW')) { - $sub['godmode/agentes/planned_downtime.list']['text'] = __('Scheduled downtime'); - $sub['godmode/agentes/planned_downtime.list']['id'] = 'Scheduled_downtime'; - } - - if ((bool) check_acl($config['id_user'], 0, 'PM') === true) { - $sub['godmode/files_repo/files_repo']['text'] = __('File Repository'); - $sub['godmode/files_repo/files_repo']['id'] = 'File_repository'; - } - foreach ($config['extensions'] as $extension) { // If no operation_menu is a godmode extension. if ($extension['operation_menu'] == '') { @@ -777,39 +756,19 @@ if ($access_console_node === true) { continue; } - // Check if was displayed inside other menu. - if ($extension['operation_menu']['fatherId'] == '') { - if ($extension_menu['name'] == 'Update manager') { - continue; - } - - $sub[$extension_menu['sec2']]['text'] = $extension_menu['name']; - $sub[$extension_menu['sec2']]['id'] = str_replace(' ', '_', $extension_menu['name']); - $sub[$extension_menu['sec2']]['refr'] = 0; - } else { - if (array_key_exists('fatherId', $extension_menu)) { - // Check that extension father ID exists previously on the menu. - if ((strlen($extension_menu['fatherId']) > 0)) { - if (array_key_exists('subfatherId', $extension_menu) && empty($extension_menu['subfatherId']) === false) { - if ((strlen($extension_menu['subfatherId']) > 0)) { - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['text'] = __($extension_menu['name']); - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['id'] = str_replace(' ', '_', $extension_menu['name']); - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['refr'] = 0; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['icon'] = $extension_menu['icon']; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['sec'] = 'extensions'; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['extension'] = true; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['enterprise'] = $extension['enterprise']; - $menu_operation[$extension_menu['fatherId']]['hasExtensions'] = true; - } else { - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['text'] = __($extension_menu['name']); - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['id'] = str_replace(' ', '_', $extension_menu['name']); - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['refr'] = 0; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['icon'] = $extension_menu['icon']; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['sec'] = 'extensions'; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['extension'] = true; - $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['enterprise'] = $extension['enterprise']; - $menu_operation[$extension_menu['fatherId']]['hasExtensions'] = true; - } + if (array_key_exists('fatherId', $extension_menu)) { + // Check that extension father ID exists previously on the menu. + if ((strlen($extension_menu['fatherId']) > 0)) { + if (array_key_exists('subfatherId', $extension_menu) && empty($extension_menu['subfatherId']) === false) { + if ((strlen($extension_menu['subfatherId']) > 0)) { + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['text'] = __($extension_menu['name']); + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['id'] = str_replace(' ', '_', $extension_menu['name']); + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['refr'] = 0; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['icon'] = $extension_menu['icon']; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['sec'] = 'extensions'; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['extension'] = true; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['subfatherId']]['sub2'][$extension_menu['sec2']]['enterprise'] = $extension['enterprise']; + $menu_operation[$extension_menu['fatherId']]['hasExtensions'] = true; } else { $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['text'] = __($extension_menu['name']); $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['id'] = str_replace(' ', '_', $extension_menu['name']); @@ -820,13 +779,20 @@ if ($access_console_node === true) { $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['enterprise'] = $extension['enterprise']; $menu_operation[$extension_menu['fatherId']]['hasExtensions'] = true; } + } else { + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['text'] = __($extension_menu['name']); + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['id'] = str_replace(' ', '_', $extension_menu['name']); + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['refr'] = 0; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['icon'] = $extension_menu['icon']; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['sec'] = 'extensions'; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['extension'] = true; + $menu_operation[$extension_menu['fatherId']]['sub'][$extension_menu['sec2']]['enterprise'] = $extension['enterprise']; + $menu_operation[$extension_menu['fatherId']]['hasExtensions'] = true; } } } } } - - // ~ } } $menu_operation['about_operation']['text'] = __('About'); diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index bfb1d0ee96..87ced3e421 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -125,10 +125,10 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('custom_report_front_logo', 'images/pandora_logo_white.jpg'), ('custom_report_front_header', ''), ('custom_report_front_footer', ''), -('MR', 66), +('MR', 67), ('identification_reminder', 1), ('identification_reminder_timestamp', 0), -('current_package', 774), +('current_package', 775), ('post_process_custom_values', '{"0.00000038580247":"Seconds to months","0.00000165343915":"Seconds to weeks","0.00001157407407":"Seconds to days","0.01666666666667":"Seconds to minutes","0.00000000093132":"Bytes to Gigabytes","0.00000095367432":"Bytes to Megabytes","0.00097656250000":"Bytes to Kilobytes","0.00000001653439":"Timeticks to weeks","0.00000011574074":"Timeticks to days"}'), ('custom_docs_logo', 'default_docs.png'), ('custom_support_logo', 'default_support.png'), From 8849e8040641d6f742fff2edf00a382153e44dc9 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Tue, 28 Nov 2023 12:59:11 +0100 Subject: [PATCH 111/397] Added demodata PRD files --- .../extras/demodata/agents/0-demo-agent.prd | 26 ++ .../extras/demodata/agents/1-linux.prd | 145 +++++++++ .../extras/demodata/agents/2-windows.prd | 114 +++++++ .../extras/demodata/agents/3-macosx.prd | 70 +++++ .../extras/demodata/agents/4-freebsd.prd | 69 +++++ .../extras/demodata/agents/5-cisco.prd | 293 ++++++++++++++++++ .../demodata/dashboards/1-dashboard.prd | 43 +++ .../extras/demodata/graphs/1-cpu-graph.prd | 21 ++ .../extras/demodata/graphs/2-disks-graph.prd | 21 ++ .../demodata/graphs/3-network-usage-graph.prd | 27 ++ .../demodata/network_maps/1-networkmap.prd | 97 ++++++ .../extras/demodata/reports/1-sla-report.prd | 47 +++ .../demodata/reports/2-graphs-report.prd | 50 +++ .../demodata/services/1-mysql-service.prd | 26 ++ .../demodata/services/2-http-service.prd | 26 ++ .../demodata/services/3-parent-service.prd | 16 + .../services/4-sunburst-linux-service.prd | 17 + .../services/5-sunburst-windows-service.prd | 17 + .../services/6-sunburst-macos-service.prd | 17 + .../services/7-sunburst-freebsd-service.prd | 17 + .../services/8-sunburst-cisco-service.prd | 17 + .../services/9-sunburst-parent-service.prd | 26 ++ .../1-linux-visual-console.prd | 150 +++++++++ 23 files changed, 1352 insertions(+) create mode 100644 pandora_console/extras/demodata/agents/0-demo-agent.prd create mode 100644 pandora_console/extras/demodata/agents/1-linux.prd create mode 100644 pandora_console/extras/demodata/agents/2-windows.prd create mode 100644 pandora_console/extras/demodata/agents/3-macosx.prd create mode 100644 pandora_console/extras/demodata/agents/4-freebsd.prd create mode 100644 pandora_console/extras/demodata/agents/5-cisco.prd create mode 100644 pandora_console/extras/demodata/dashboards/1-dashboard.prd create mode 100644 pandora_console/extras/demodata/graphs/1-cpu-graph.prd create mode 100644 pandora_console/extras/demodata/graphs/2-disks-graph.prd create mode 100644 pandora_console/extras/demodata/graphs/3-network-usage-graph.prd create mode 100644 pandora_console/extras/demodata/network_maps/1-networkmap.prd create mode 100644 pandora_console/extras/demodata/reports/1-sla-report.prd create mode 100644 pandora_console/extras/demodata/reports/2-graphs-report.prd create mode 100644 pandora_console/extras/demodata/services/1-mysql-service.prd create mode 100644 pandora_console/extras/demodata/services/2-http-service.prd create mode 100644 pandora_console/extras/demodata/services/3-parent-service.prd create mode 100644 pandora_console/extras/demodata/services/4-sunburst-linux-service.prd create mode 100644 pandora_console/extras/demodata/services/5-sunburst-windows-service.prd create mode 100644 pandora_console/extras/demodata/services/6-sunburst-macos-service.prd create mode 100644 pandora_console/extras/demodata/services/7-sunburst-freebsd-service.prd create mode 100644 pandora_console/extras/demodata/services/8-sunburst-cisco-service.prd create mode 100644 pandora_console/extras/demodata/services/9-sunburst-parent-service.prd create mode 100644 pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd diff --git a/pandora_console/extras/demodata/agents/0-demo-agent.prd b/pandora_console/extras/demodata/agents/0-demo-agent.prd new file mode 100644 index 0000000000..af1fa72a66 --- /dev/null +++ b/pandora_console/extras/demodata/agents/0-demo-agent.prd @@ -0,0 +1,26 @@ +[agent_data] + +agents_number="1" + +agent_name="demo-global-agent" +agent_alias="demo-global-agent" + +group="Demo servers" + +address_network="192.168.0.0/24" + +os_name="Linux" + +os_versions[]="Rocky Linux 9.2 (Blue Onyx)" +os_versions[]="CentOS Linux 7 (Core)" +os_versions[]="CentOS Linux 6 (Core)" +os_versions[]="RHEL 8.2" +os_versions[]="RHEL 8.1" +os_versions[]="Alma Linux 9.1" + +[modules] + +name[1]="Host Alive" +type[1]="generic_proc" +values[1]="PROC;5" +group[1]="Network" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/1-linux.prd b/pandora_console/extras/demodata/agents/1-linux.prd new file mode 100644 index 0000000000..5cd29b117e --- /dev/null +++ b/pandora_console/extras/demodata/agents/1-linux.prd @@ -0,0 +1,145 @@ +[agent_data] + +agents_number="4" + +agent_name="linux" +agent_alias="linux" + +group="Demo servers" + +address_network="192.168.1.0/24" + +os_name="Linux" + +os_versions[]="Rocky Linux 9.2 (Blue Onyx)" +os_versions[]="CentOS Linux 7 (Core)" +os_versions[]="CentOS Linux 6 (Core)" +os_versions[]="RHEL 8.2" +os_versions[]="RHEL 8.1" +os_versions[]="Alma Linux 9.1" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Antivirus Updated" +type[6]="generic_proc" +description[6]="Detect if A/V is enabled and updated" +values[6]="PROC;5" +group[6]="Security" + +name[7]="Insecure passwords status" +type[7]="generic_proc" +description[7]="No insecure passwords found" +values[7]="PROC;0" +group[7]="Security" + +name[8]="Files check status" +type[8]="generic_proc" +description[8]="No changed files found" +values[8]="PROC;0" +group[8]="Security" + +name[9]="Authorized ports status" +type[9]="generic_proc" +description[9]="No unauthorized ports found" +values[9]="PROC;0" +group[9]="Security" + +name[10]="Service httpd" +type[10]="generic_proc" +values[10]="PROC;5" +group[10]="Applications" + +name[11]="Service mysqld" +type[11]="generic_proc" +values[11]="PROC;5" +group[11]="Applications" + +name[12]="Service sshd" +type[12]="generic_proc" +values[12]="PROC;5" +group[12]="Applications" + +[inventory] + +name[1]="Software" +format[1]="Name;Version;Description" +values[1]="name;version;description" + +name[2]="Users" +format[2]="Username" +values[2]="username" + +name[3]="File System" +format[3]="Device;Free size;Total size;Mount point" +values[3]="device;free_size;total_size;mount_point" + +[inventory_values] + +name[1]="aajohan-comfortaa-fonts" +name[2]="aardvark-dns" +name[3]="abattis-cantarell-fonts" +name[4]="abrt" + +version[1]="3.101" +version[2]="1.0.3" +version[3]="0.301" +version[4]="2.14.6" + +description[1]="Modern style true type font" +description[2]="Authoritative DNS server for A/AAAA container records" +description[3]="Humanist sans serif font" +description[4]="Automatic bug detection and reporting tool" + +username[1]="root" +username[2]="pandora" + +device[1]="/dev/sda1" +device[2]="/dev/sda2" +device[3]="/dev/sdb1" + +free_size[1]="96G" +free_size[2]="136G" +free_size[3]="97M" + +total_size[1]="180G" +total_size[2]="1.6T" +total_size[3]="819M" + +mount_point[1]="/home" +mount_point[2]="/" +mount_point[3]="/tmp" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/2-windows.prd b/pandora_console/extras/demodata/agents/2-windows.prd new file mode 100644 index 0000000000..1d1d6c782c --- /dev/null +++ b/pandora_console/extras/demodata/agents/2-windows.prd @@ -0,0 +1,114 @@ +[agent_data] + +agents_number="2" + +agent_name="windows" +agent_alias="windows" + +group="Demo servers" + +address_network="192.168.2.0/24" + +os_name="Windows" + +os_versions[]="Microsoft Windows 11 Pro" +os_versions[]="Microsoft Windows 11" +os_versions[]="Home Microsoft Windows 10 Pro" +os_versions[]="Microsoft Windows 10 Home" +os_versions[]="Microsoft Windows 2018" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Service WMI" +type[6]="generic_proc" +values[6]="PROC;5" +group[6]="Applications" + +[inventory] + +name[1]="Software" +format[1]="Name;Version" +values[1]="name;version" + +name[2]="Users" +format[2]="Domain;User" +values[2]="domain;user" + +name[3]="File System" +format[3]="Device;Total size;Free size;Mount point" +values[3]="device;total_size;free_size;mount_point" + +name[4]="Windows Serial Number" +format[4]="Serial number" +values[4]="serial_number" + +[inventory_values] + +name[1]="Microsoft Update Health Tools" +name[2]="Java(TM) SE Development Kit 17.0.6 (64-bit)" +name[3]="DisplayLink Graphics" +name[4]="Microsoft Visual C++ 2019 X64 Additional Runtime - 14.28.29325" + +version[1]="5.71.0.0" +version[2]="17.0.6.0" +version[3]="10.2.7042.0" +version[4]="14.28.29325" + +domain[1]="DEMO" +domain[2]="DEMO" + +user[1]="Administrator" +user[2]="pandora" + +device[1]="C:" +device[2]="D:" +device[3]="T:" + +total_size[1]="1.6T" +total_size[2]="180G" +total_size[3]="819M" + +free_size[1]="136G" +free_size[2]="96G" +free_size[3]="97M" + +mount_point[1]="OS" +mount_point[2]="Data" +mount_point[3]="Temp" + +serial_number[1]="Demo-56 4d 7d 43 24 e4 c6 ac-67 57 52 60 e9 10 26 78" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/3-macosx.prd b/pandora_console/extras/demodata/agents/3-macosx.prd new file mode 100644 index 0000000000..ba8d75de87 --- /dev/null +++ b/pandora_console/extras/demodata/agents/3-macosx.prd @@ -0,0 +1,70 @@ +[agent_data] + +agents_number="1" + +agent_name="macos" +agent_alias="macos" + +group="Demo servers" + +address_network="192.168.3.0/24" + +os_name="MacOS" + +os_versions[]="12.1" +os_versions[]="13.1" +os_versions[]="11.2" +os_versions[]="11.3" +os_versions[]="10.3" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Service httpd" +type[6]="generic_proc" +values[6]="PROC;5" +group[6]="Applications" + +name[7]="Service mysqld" +type[7]="generic_proc" +values[7]="PROC;5" +group[7]="Applications" + +name[8]="Service sshd" +type[8]="generic_proc" +values[8]="PROC;5" +group[8]="Applications" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/4-freebsd.prd b/pandora_console/extras/demodata/agents/4-freebsd.prd new file mode 100644 index 0000000000..956a501660 --- /dev/null +++ b/pandora_console/extras/demodata/agents/4-freebsd.prd @@ -0,0 +1,69 @@ +[agent_data] + +agents_number="1" + +agent_name="freebsd" +agent_alias="freebsd" + +group="Demo servers" + +address_network="192.168.4.0/24" + +os_name="BSD" + +os_versions[]="14.0" +os_versions[]="13.1" +os_versions[]="13.2" +os_versions[]="13.3" + +[modules] + +name[1]="Network Usage" +type[1]="generic_data_inc" +description[1]="Network usage in the system" +values[1]="RANDOM;0;10000" +unit[1]="bytes/sec" +group[1]="Network" + +name[2]="Network latency" +type[2]="generic_data" +description[2]="Network latency to router" +values[2]="RANDOM;0;20" +unit[2]="msec" +group[2]="Network" + +name[3]="CPU Load" +type[3]="generic_data" +description[3]="CPU Usage" +values[3]="RANDOM;20;90" +unit[3]="%" +group[3]="System" + +name[4]="Disk Usage" +type[4]="generic_data" +description[4]="% used space" +values[4]="RANDOM;50;60" +unit[4]="%" +group[4]="System" + +name[5]="Memory Usage" +type[5]="generic_data" +description[5]="% Used memory" +values[5]="RANDOM;0;20" +unit[5]="%" +group[5]="System" + +name[6]="Service httpd" +type[6]="generic_proc" +values[6]="PROC;5" +group[6]="Applications" + +name[7]="Service mysqld" +type[7]="generic_proc" +values[7]="PROC;5" +group[7]="Applications" + +name[8]="Service sshd" +type[8]="generic_proc" +values[8]="PROC;5" +group[8]="Applications" \ No newline at end of file diff --git a/pandora_console/extras/demodata/agents/5-cisco.prd b/pandora_console/extras/demodata/agents/5-cisco.prd new file mode 100644 index 0000000000..58febab7fe --- /dev/null +++ b/pandora_console/extras/demodata/agents/5-cisco.prd @@ -0,0 +1,293 @@ +[agent_data] + +agents_number="1" + +agent_name="cisco" +agent_alias="cisco" + +group="Demo network" + +address_network="192.168.5.0/24" +mac="__randomMAC__" + +os_name="Cisco" + +os_versions[]="C9200L" +os_versions[]="C9300LM" +os_versions[]="C9600" + +[modules] + +name[1]="CPU Usage (5 min avg)" +type[1]="generic_data" +description[1]="CPU Usage" +values[1]="RANDOM;20;90" +unit[1]="%" +group[1]="General" + +name[2]="Big Buffer Misses" +type[2]="generic_data" +description[2]="Buffer misses" +values[2]="RANDOM;20;90" +unit[2]="%" +group[2]="General" + +name[3]="Temperature" +type[3]="generic_data" +description[3]="System temp" +values[3]="RANDOM;20;30" +unit[3]="ºC" +group[3]="General" + +name[4]="Host alive" +type[4]="generic_proc" +values[4]="PROC;5" +group[4]="Networking" + +name[5]="Gi0/0_ifOperStatus" +type[5]="generic_proc" +description[5]="(MAC: _mac_ - Gi0/0_ifOperStatus)" +values[5]="PROC;5" +group[5]="Networking" + +name[6]="Gi0/0_ifInOctets" +type[6]="generic_data_inc" +description[6]="(MAC: _mac_ - Gi0/0_ifInOctets)" +values[6]="RANDOM;0;1000" +unit[6]="bytes/s" +group[6]="Networking" + +name[7]="Gi0/0_ifOutOctets" +type[7]="generic_data_inc" +description[7]="(MAC: _mac_ - Gi0/0_ifOutOctets)" +values[7]="RANDOM;0;1000" +unit[7]="bytes/s" +group[7]="Networking" + +name[8]="Gi0/1_ifOperStatus" +type[8]="generic_proc" +description[8]="(MAC: _mac_ - Gi0/1_ifOperStatus)" +values[8]="PROC;5" +group[8]="Networking" + +name[9]="Gi0/1_ifInOctets" +type[9]="generic_data_inc" +description[9]="(MAC: _mac_ - Gi0/1_ifInOctets)" +values[9]="RANDOM;0;1000" +unit[9]="bytes/s" +group[9]="Networking" + +name[10]="Gi0/1_ifOutOctets" +type[10]="generic_data_inc" +description[10]="(MAC: _mac_ - Gi0/1_ifOutOctets)" +values[10]="RANDOM;0;1000" +unit[10]="bytes/s" +group[10]="Networking" + +name[11]="Gi0/2_ifOperStatus" +type[11]="generic_proc" +description[11]="(MAC: _mac_ - Gi0/2_ifOperStatus)" +values[11]="PROC;5" +group[11]="Networking" + +name[12]="Gi0/2_ifInOctets" +type[12]="generic_data_inc" +description[12]="(MAC: _mac_ - Gi0/2_ifInOctets)" +values[12]="RANDOM;0;1000" +unit[12]="bytes/s" +group[12]="Networking" + +name[13]="Gi0/2_ifOutOctets" +type[13]="generic_data_inc" +description[13]="(MAC: _mac_ - Gi0/2_ifOutOctets)" +values[13]="RANDOM;0;1000" +unit[13]="bytes/s" +group[13]="Networking" + +name[14]="Gi0/3_ifOperStatus" +type[14]="generic_proc" +description[14]="(MAC: _mac_ - Gi0/3_ifOperStatus)" +values[14]="PROC;5" +group[14]="Networking" + +name[15]="Gi0/3_ifInOctets" +type[15]="generic_data_inc" +description[15]="(MAC: _mac_ - Gi0/3_ifInOctets)" +values[15]="RANDOM;0;1000" +unit[15]="bytes/s" +group[15]="Networking" + +name[16]="Gi0/3_ifOutOctets" +type[16]="generic_data_inc" +description[16]="(MAC: _mac_ - Gi0/3_ifOutOctets)" +values[16]="RANDOM;0;1000" +unit[16]="bytes/s" +group[16]="Networking" + +name[17]="Gi0/4_ifOperStatus" +type[17]="generic_proc" +description[17]="(MAC: _mac_ - Gi0/4_ifOperStatus)" +values[17]="PROC;5" +group[17]="Networking" + +name[18]="Gi0/4_ifInOctets" +type[18]="generic_data_inc" +description[18]="(MAC: _mac_ - Gi0/4_ifInOctets)" +values[18]="RANDOM;0;1000" +unit[18]="bytes/s" +group[18]="Networking" + +name[19]="Gi0/4_ifOutOctets" +type[19]="generic_data_inc" +description[19]="(MAC: _mac_ - Gi0/4_ifOutOctets)" +values[19]="RANDOM;0;1000" +unit[19]="bytes/s" +group[19]="Networking" + +name[20]="Gi0/5_ifOperStatus" +type[20]="generic_proc" +description[20]="(MAC: _mac_ - Gi0/5_ifOperStatus)" +values[20]="PROC;5" +group[20]="Networking" + +name[21]="Gi0/5_ifInOctets" +type[21]="generic_data_inc" +description[21]="(MAC: _mac_ - Gi0/5_ifInOctets)" +values[21]="RANDOM;0;1000" +unit[21]="bytes/s" +group[21]="Networking" + +name[22]="Gi0/5_ifOutOctets" +type[22]="generic_data_inc" +description[22]="(MAC: _mac_ - Gi0/5_ifOutOctets)" +values[22]="RANDOM;0;1000" +unit[22]="bytes/s" +group[22]="Networking" + +name[23]="Gi0/6_ifOperStatus" +type[23]="generic_proc" +description[23]="(MAC: _mac_ - Gi0/6_ifOperStatus)" +values[23]="PROC;5" +group[23]="Networking" + +name[24]="Gi0/6_ifInOctets" +type[24]="generic_data_inc" +description[24]="(MAC: _mac_ - Gi0/6_ifInOctets)" +values[24]="RANDOM;0;1000" +unit[24]="bytes/s" +group[24]="Networking" + +name[25]="Gi0/6_ifOutOctets" +type[25]="generic_data_inc" +description[25]="(MAC: _mac_ - Gi0/6_ifOutOctets)" +values[25]="RANDOM;0;1000" +unit[25]="bytes/s" +group[25]="Networking" + +name[26]="Gi0/7_ifOperStatus" +type[26]="generic_proc" +description[26]="(MAC: _mac_ - Gi0/7_ifOperStatus)" +values[26]="PROC;5" +group[26]="Networking" + +name[27]="Gi0/7_ifInOctets" +type[27]="generic_data_inc" +description[27]="(MAC: _mac_ - Gi0/7_ifInOctets)" +values[27]="RANDOM;0;1000" +unit[27]="bytes/s" +group[27]="Networking" + +name[28]="Gi0/7_ifOutOctets" +type[28]="generic_data_inc" +description[28]="(MAC: _mac_ - Gi0/7_ifOutOctets)" +values[28]="RANDOM;0;1000" +unit[28]="bytes/s" +group[28]="Networking" + +name[29]="Gi0/8_ifOperStatus" +type[29]="generic_proc" +description[29]="(MAC: _mac_ - Gi0/8_ifOperStatus)" +values[29]="PROC;5" +group[29]="Networking" + +name[30]="Gi0/8_ifInOctets" +type[30]="generic_data_inc" +description[30]="(MAC: _mac_ - Gi0/8_ifInOctets)" +values[30]="RANDOM;0;1000" +unit[30]="bytes/s" +group[30]="Networking" + +name[31]="Gi0/8_ifOutOctets" +type[31]="generic_data_inc" +description[31]="(MAC: _mac_ - Gi0/8_ifOutOctets)" +values[31]="RANDOM;0;1000" +unit[31]="bytes/s" +group[31]="Networking" + +name[32]="Gi0/9_ifOperStatus" +type[32]="generic_proc" +description[32]="(MAC: _mac_ - Gi0/9_ifOperStatus)" +values[32]="PROC;5" +group[32]="Networking" + +name[33]="Gi0/9_ifInOctets" +type[33]="generic_data_inc" +description[33]="(MAC: _mac_ - Gi0/9_ifInOctets)" +values[33]="RANDOM;0;1000" +unit[33]="bytes/s" +group[33]="Networking" + +name[34]="Gi0/9_ifOutOctets" +type[34]="generic_data_inc" +description[34]="(MAC: _mac_ - Gi0/9_ifOutOctets)" +values[34]="RANDOM;0;1000" +unit[34]="bytes/s" +group[34]="Networking" + +name[35]="ipInReceives" +type[35]="generic_data" +description[35]="The total number of input datagrams received from interfaces" +values[35]="RANDOM;0;1000" +unit[35]="datagrams" +group[35]="Networking" + +name[36]="ipOutRequests" +type[36]="generic_data" +description[36]="The total number of output datagrams requested from interfaces" +values[36]="RANDOM;0;1000" +unit[36]="datagrams" +group[36]="Networking" + +name[37]="Latency" +type[37]="generic_data" +description[37]="Network latency" +values[37]="RANDOM;0;100" +unit[37]="msec" +group[37]="Networking" + +[traps] + +oid[1]=".1.3.6.1.4.1.9.9.41.1.2.3.1.2.0" +value[1]="RANDOM;0;100" +snmp_type[1]="6" +chance_percent[1]="5" + +oid[2]=".1.3.6.1.4.1.9.9.41.1.2.3.1.3.0" +value[2]="RANDOM;0;100" +snmp_type[2]="6" +chance_percent[2]="5" + +oid[3]=".1.3.6.1.4.1.9.9.41.1.2.3.1.4.0" +value[3]="RANDOM;0;100" +snmp_type[3]="6" +chance_percent[3]="5" + +oid[4]=".1.3.6.1.4.1.9.9.41.1.2.3.1.5.0" +value[4]="RANDOM;0;100" +snmp_type[4]="6" +chance_percent[4]="5" + +oid[5]=".1.3.6.1.4.1.9.9.41.1.2.3.1.6.0" +value[5]="RANDOM;0;100" +snmp_type[5]="6" +chance_percent[5]="5" \ No newline at end of file diff --git a/pandora_console/extras/demodata/dashboards/1-dashboard.prd b/pandora_console/extras/demodata/dashboards/1-dashboard.prd new file mode 100644 index 0000000000..8cfc89bc01 --- /dev/null +++ b/pandora_console/extras/demodata/dashboards/1-dashboard.prd @@ -0,0 +1,43 @@ +[dashboard_data] + +name="Demo dashboard" +group="Demo dashboard" + +[dashboard_items] + +title[1]="Agents sunburst" +type[1]="service_map" +service_name[1]="Sunburst service" +x[1]="0" +y[1]="0" +width[1]="6" +height[1]="10" +show_sunburst[1]=true + +title[2]="Linux CPU Load" +type[2]="custom_graph" +graph_name[2]="Linux CPU Load" +x[2]="6" +y[2]="0" +width[2]="6" +height[2]="5" +graph_type[2]="s_area" +interval[2]="86400" + +title[3]="Linux Disk Usage" +type[3]="custom_graph" +graph_name[3]="Linux Disk Usage" +x[3]="6" +y[3]="5" +width[3]="6" +height[3]="5" +graph_type[3]="line" +interval[3]="86400" + +title[4]="Network map" +type[4]="network_map" +map_name[4]="Demo network map" +x[4]="0" +y[4]="10" +width[4]="12" +height[4]="10" \ No newline at end of file diff --git a/pandora_console/extras/demodata/graphs/1-cpu-graph.prd b/pandora_console/extras/demodata/graphs/1-cpu-graph.prd new file mode 100644 index 0000000000..61b7ab456c --- /dev/null +++ b/pandora_console/extras/demodata/graphs/1-cpu-graph.prd @@ -0,0 +1,21 @@ +[graph_data] + +name="Linux CPU Load" +group="Demo servers" +description="This is a demo custom graph for linux agents CPU Load" +type="s_area" +periodicity="86400" + +[graph_items] + +agent_name[1]="linux-1" +module[1]="CPU Load" + +agent_name[2]="linux-2" +module[2]="CPU Load" + +agent_name[3]="linux-3" +module[3]="CPU Load" + +agent_name[4]="linux-4" +module[4]="CPU Load" \ No newline at end of file diff --git a/pandora_console/extras/demodata/graphs/2-disks-graph.prd b/pandora_console/extras/demodata/graphs/2-disks-graph.prd new file mode 100644 index 0000000000..cf3032c5f0 --- /dev/null +++ b/pandora_console/extras/demodata/graphs/2-disks-graph.prd @@ -0,0 +1,21 @@ +[graph_data] + +name="Linux Disk Usage" +group="Demo servers" +description="This is a demo custom graph for linux agents Disk Usage" +type="line" +periodicity="86400" + +[graph_items] + +agent_name[1]="linux-1" +module[1]="Disk Usage" + +agent_name[2]="linux-2" +module[2]="Disk Usage" + +agent_name[3]="linux-3" +module[3]="Disk Usage" + +agent_name[4]="linux-4" +module[4]="Disk Usage" \ No newline at end of file diff --git a/pandora_console/extras/demodata/graphs/3-network-usage-graph.prd b/pandora_console/extras/demodata/graphs/3-network-usage-graph.prd new file mode 100644 index 0000000000..3108b4cb7f --- /dev/null +++ b/pandora_console/extras/demodata/graphs/3-network-usage-graph.prd @@ -0,0 +1,27 @@ +[graph_data] + +name="Network Usage" +group="Demo servers" +description="This is a demo custom graph for linux and windows agents Network Usage" +type="s_area" +periodicity="86400" + +[graph_items] + +agent_name[1]="linux-1" +module[1]="Network Usage" + +agent_name[2]="linux-2" +module[2]="Network Usage" + +agent_name[3]="linux-3" +module[3]="Network Usage" + +agent_name[4]="linux-4" +module[4]="Network Usage" + +agent_name[5]="windows-1" +module[5]="Network Usage" + +agent_name[6]="windows-2" +module[6]="Network Usage" \ No newline at end of file diff --git a/pandora_console/extras/demodata/network_maps/1-networkmap.prd b/pandora_console/extras/demodata/network_maps/1-networkmap.prd new file mode 100644 index 0000000000..f780eb0977 --- /dev/null +++ b/pandora_console/extras/demodata/network_maps/1-networkmap.prd @@ -0,0 +1,97 @@ +[map_data] + +name="Demo network map" +group="Demo network" +description="This is a demo network map" +node_radius="40" + +[map_items] + +agent_name[1]="cisco-1" +x[1]="854" +y[1]="221" + +agent_name[2]="freebsd-1" +x[2]="1184" +y[2]="-25" +parent[2]="1" + +agent_name[3]="macos-1" +x[3]="1268" +y[3]="235" +parent[3]="1" + +agent_name[4]="windows-1" +x[4]="528" +y[4]="-37" +parent[4]="1" + +agent_name[5]="windows-2" +x[5]="514" +y[5]="389" +parent[5]="1" + +agent_name[6]="linux-1" +x[6]="342" +y[6]="-273" +parent[6]="4" + +agent_name[7]="linux-2" +x[7]="240" +y[7]="-7" +parent[7]="4" + +agent_name[8]="linux-3" +x[8]="214" +y[8]="275" +parent[8]="5" + +agent_name[9]="linux-4" +x[9]="226" +y[9]="595" +parent[9]="5" + +agent_name[10]="cisco-2" +x[10]="1036" +y[10]="711" +parent[10]="1" + +agent_name[11]="freebsd-2" +x[11]="892" +y[11]="-47" +parent[11]="1" + +agent_name[12]="macos-2" +x[12]="1150" +y[12]="409" +parent[12]="1" + +agent_name[13]="windows-3" +x[13]="686" +y[13]="875" +parent[13]="10" + +agent_name[14]="windows-4" +x[14]="1452" +y[14]="847" +parent[14]="10" + +agent_name[15]="linux-5" +x[15]="314" +y[15]="845" +parent[15]="13" + +agent_name[16]="linux-6" +x[16]="474" +y[16]="1043" +parent[16]="13" + +agent_name[17]="linux-7" +x[17]="1812" +y[17]="1011" +parent[17]="14" + +agent_name[18]="linux-8" +x[18]="1828" +y[18]="723" +parent[18]="14" \ No newline at end of file diff --git a/pandora_console/extras/demodata/reports/1-sla-report.prd b/pandora_console/extras/demodata/reports/1-sla-report.prd new file mode 100644 index 0000000000..e3d130b4a0 --- /dev/null +++ b/pandora_console/extras/demodata/reports/1-sla-report.prd @@ -0,0 +1,47 @@ +[report_data] + +name="SLA report" +group="Demo servers" +description="This is a demo report for SLA" + +[report_items] + +name[1]="linux-1 httpd" +type[1]="sla" +agent_name[1]="linux-1" +module[1]="Service httpd" + +name[2]="linux-2 httpd" +type[2]="sla" +agent_name[2]="linux-2" +module[2]="Service httpd" + +name[3]="linux-3 httpd" +type[3]="sla" +agent_name[3]="linux-3" +module[3]="Service httpd" + +name[4]="linux-4 httpd" +type[4]="sla" +agent_name[4]="linux-4" +module[4]="Service httpd" + +name[5]="linux-1 mysqld" +type[5]="sla" +agent_name[5]="linux-1" +module[5]="Service mysqld" + +name[6]="linux-2 mysqld" +type[6]="sla" +agent_name[6]="linux-2" +module[6]="Service mysqld" + +name[7]="linux-3 mysqld" +type[7]="sla" +agent_name[7]="linux-3" +module[7]="Service mysqld" + +name[8]="linux-4 mysqld" +type[8]="sla" +agent_name[8]="linux-4" +module[8]="Service mysqld" \ No newline at end of file diff --git a/pandora_console/extras/demodata/reports/2-graphs-report.prd b/pandora_console/extras/demodata/reports/2-graphs-report.prd new file mode 100644 index 0000000000..ecf3fe0502 --- /dev/null +++ b/pandora_console/extras/demodata/reports/2-graphs-report.prd @@ -0,0 +1,50 @@ +[report_data] + +name="CPU Load report" +group="Demo network" +description="This is a demo report for CPU Load" + +[report_items] + +type[1]="custom_graph" +graph_name[1]="Linux CPU Load" + +name[2]="linux-1 CPU Load graph" +type[2]="simple_graph" +agent_name[2]="linux-1" +module[2]="CPU Load" + +name[3]="linux-1 CPU Load data" +type[3]="historical" +agent_name[3]="linux-1" +module[3]="CPU Load" + +name[4]="linux-2 CPU Load graph" +type[4]="simple_graph" +agent_name[4]="linux-2" +module[4]="CPU Load" + +name[5]="linux-2 CPU Load data" +type[5]="historical" +agent_name[5]="linux-2" +module[5]="CPU Load" + +name[6]="linux-3 CPU Load graph" +type[6]="simple_graph" +agent_name[6]="linux-3" +module[6]="CPU Load" + +name[7]="linux-3 CPU Load data" +type[7]="historical" +agent_name[7]="linux-3" +module[7]="CPU Load" + +name[8]="linux-4 CPU Load graph" +type[8]="simple_graph" +agent_name[8]="linux-4" +module[8]="CPU Load" + +name[9]="linux-4 CPU Load data" +type[9]="historical" +agent_name[9]="linux-4" +module[9]="CPU Load" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/1-mysql-service.prd b/pandora_console/extras/demodata/services/1-mysql-service.prd new file mode 100644 index 0000000000..23e366e44a --- /dev/null +++ b/pandora_console/extras/demodata/services/1-mysql-service.prd @@ -0,0 +1,26 @@ +[service_data] + +name="MySQL service" +group="Demo services" +description="This is a demo service for MySQL" +mode="smart" +critical="50" +warning="30" + +[service_items] + +type[1]="module" +agent_name[1]="linux-1" +module[1]="Service mysqld" + +type[2]="module" +agent_name[2]="linux-2" +module[2]="Service mysqld" + +type[3]="module" +agent_name[3]="linux-3" +module[3]="Service mysqld" + +type[4]="module" +agent_name[4]="linux-4" +module[4]="Service mysqld" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/2-http-service.prd b/pandora_console/extras/demodata/services/2-http-service.prd new file mode 100644 index 0000000000..2257797134 --- /dev/null +++ b/pandora_console/extras/demodata/services/2-http-service.prd @@ -0,0 +1,26 @@ +[service_data] + +name="HTTP service" +group="Demo services" +description="This is a demo service for HTTP" +mode="smart" +critical="50" +warning="30" + +[service_items] + +type[1]="module" +agent_name[1]="linux-1" +module[1]="Service httpd" + +type[2]="module" +agent_name[2]="linux-2" +module[2]="Service httpd" + +type[3]="module" +agent_name[3]="linux-3" +module[3]="Service httpd" + +type[4]="module" +agent_name[4]="linux-4" +module[4]="Service httpd" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/3-parent-service.prd b/pandora_console/extras/demodata/services/3-parent-service.prd new file mode 100644 index 0000000000..a31f669735 --- /dev/null +++ b/pandora_console/extras/demodata/services/3-parent-service.prd @@ -0,0 +1,16 @@ +[service_data] + +name="Web cluster service" +group="Demo services" +description="This is a demo service for a clustered web" +mode="smart" +critical="50" +warning="50" + +[service_items] + +type[1]="service" +service_name[1]="MySQL service" + +type[2]="service" +service_name[2]="HTTP service" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/4-sunburst-linux-service.prd b/pandora_console/extras/demodata/services/4-sunburst-linux-service.prd new file mode 100644 index 0000000000..b85adcef56 --- /dev/null +++ b/pandora_console/extras/demodata/services/4-sunburst-linux-service.prd @@ -0,0 +1,17 @@ +[service_data] + +name="Linux service" +group="Demo services" +description="This is a demo sunburst service for linux agents" +mode="smart" +critical="50" +warning="30" +show_sunburst=true + +[service_items] + +type[1]="dynamic" +match[1]="agent" +group[1]="Demo servers" +regex[1]=true +agent_name[1]="linux" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/5-sunburst-windows-service.prd b/pandora_console/extras/demodata/services/5-sunburst-windows-service.prd new file mode 100644 index 0000000000..cada189ddf --- /dev/null +++ b/pandora_console/extras/demodata/services/5-sunburst-windows-service.prd @@ -0,0 +1,17 @@ +[service_data] + +name="Windows service" +group="Demo services" +description="This is a demo sunburst service for windows agents" +mode="smart" +critical="50" +warning="30" +show_sunburst=true + +[service_items] + +type[1]="dynamic" +match[1]="agent" +group[1]="Demo servers" +regex[1]=true +agent_name[1]="windows" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/6-sunburst-macos-service.prd b/pandora_console/extras/demodata/services/6-sunburst-macos-service.prd new file mode 100644 index 0000000000..7344761920 --- /dev/null +++ b/pandora_console/extras/demodata/services/6-sunburst-macos-service.prd @@ -0,0 +1,17 @@ +[service_data] + +name="MacOS service" +group="Demo services" +description="This is a demo sunburst service for macos agents" +mode="smart" +critical="50" +warning="30" +show_sunburst=true + +[service_items] + +type[1]="dynamic" +match[1]="agent" +group[1]="Demo servers" +regex[1]=true +agent_name[1]="macos" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/7-sunburst-freebsd-service.prd b/pandora_console/extras/demodata/services/7-sunburst-freebsd-service.prd new file mode 100644 index 0000000000..c97828123b --- /dev/null +++ b/pandora_console/extras/demodata/services/7-sunburst-freebsd-service.prd @@ -0,0 +1,17 @@ +[service_data] + +name="FreeBSD service" +group="Demo services" +description="This is a demo sunburst service for freebsd agents" +mode="smart" +critical="50" +warning="30" +show_sunburst=true + +[service_items] + +type[1]="dynamic" +match[1]="agent" +group[1]="Demo servers" +regex[1]=true +agent_name[1]="freebsd" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/8-sunburst-cisco-service.prd b/pandora_console/extras/demodata/services/8-sunburst-cisco-service.prd new file mode 100644 index 0000000000..079c5231c3 --- /dev/null +++ b/pandora_console/extras/demodata/services/8-sunburst-cisco-service.prd @@ -0,0 +1,17 @@ +[service_data] + +name="Cisco service" +group="Demo services" +description="This is a demo sunburst service for cisco agents" +mode="smart" +critical="50" +warning="30" +show_sunburst=true + +[service_items] + +type[1]="dynamic" +match[1]="agent" +group[1]="Demo servers" +regex[1]=true +agent_name[1]="cisco" \ No newline at end of file diff --git a/pandora_console/extras/demodata/services/9-sunburst-parent-service.prd b/pandora_console/extras/demodata/services/9-sunburst-parent-service.prd new file mode 100644 index 0000000000..2e13575e63 --- /dev/null +++ b/pandora_console/extras/demodata/services/9-sunburst-parent-service.prd @@ -0,0 +1,26 @@ +[service_data] + +name="Sunburst service" +group="Demo services" +description="This is a demo sunburst service for all agents" +mode="smart" +critical="50" +warning="30" +show_sunburst=true + +[service_items] + +type[1]="service" +service_name[1]="Linux service" + +type[2]="service" +service_name[2]="Windows service" + +type[3]="service" +service_name[3]="MacOS service" + +type[4]="service" +service_name[4]="FreeBSD service" + +type[5]="service" +service_name[5]="Cisco service" \ No newline at end of file diff --git a/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd b/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd new file mode 100644 index 0000000000..741cabb050 --- /dev/null +++ b/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd @@ -0,0 +1,150 @@ +[visual_console_data] + +name="Linux visual console" +group="Demo servers" +background="blackabstract.jpg" +background_color="#ffffff" +width="1285" +height="768" + +[visual_console_items] + +type[1]="label" +label[1]="

    Security

    " +label_position[1]="down" +x[1]="160" +y[1]="25" +width[1]="160" +height[1]="55" + +type[2]="label" +label[2]="

    Performance

    " +label_position[2]="down" +x[2]="840" +y[2]="25" +width[2]="160" +height[2]="55" + +type[3]="label" +label[3]="

    Services

    " +label_position[3]="down" +x[3]="170" +y[3]="400" +width[3]="160" +height[3]="55" + +type[4]="static_image" +image[4]="status" +agent_name[4]="linux-1" +module[4]="Antivirus Updated" +label[4]="

    _module_

    " +label_position[4]="right" +x[4]="80" +y[4]="105" +width[4]="50" +height[4]="50" + +type[5]="static_image" +image[5]="status" +agent_name[5]="linux-1" +module[5]="Insecure passwords status" +label[5]="

    _module_

    " +label_position[5]="right" +x[5]="80" +y[5]="165" +width[5]="50" +height[5]="50" + +type[6]="static_image" +image[6]="status" +agent_name[6]="linux-1" +module[6]="Files check status" +label[6]="

    _module_

    " +label_position[6]="right" +x[6]="80" +y[6]="225" +width[6]="50" +height[6]="50" + +type[7]="static_image" +image[7]="status" +agent_name[7]="linux-1" +module[7]="Authorized ports status" +label[7]="

    _module_

    " +label_position[7]="right" +x[7]="80" +y[7]="285" +width[7]="50" +height[7]="50" + +type[8]="static_image" +image[8]="status" +agent_name[8]="linux-1" +module[8]="Service httpd" +label[8]="

    _module_

    " +label_position[8]="right" +x[8]="80" +y[8]="490" +width[8]="50" +height[8]="50" + +type[9]="static_image" +image[9]="status" +agent_name[9]="linux-1" +module[9]="Service mysqld" +label[9]="

    _module_

    " +label_position[9]="right" +x[9]="80" +y[9]="550" +width[9]="50" +height[9]="50" + +type[10]="static_image" +image[10]="status" +agent_name[10]="linux-1" +module[10]="Service sshd" +label[10]="

    _module_

    " +label_position[10]="right" +x[10]="80" +y[10]="610" +width[10]="50" +height[10]="50" + +type[11]="module_graph" +image[11]="black" +agent_name[11]="linux-1" +module[11]="CPU Load" +interval[11]="86N00" +graph_type[11]="area" +label[11]="" +label_position[11]="down" +x[11]="625" +y[11]="100" +width[11]="600" +height[11]="180" + +type[12]="module_graph" +image[12]="black" +agent_name[12]="linux-1" +module[12]="Memory Usage" +interval[12]="86N00" +graph_type[12]="area" +label[12]="" +label_position[12]="down" +x[12]="625" +y[12]="300" +width[12]="600" +height[12]="180" + +type[13]="module_graph" +image[13]="black" +agent_name[13]="linux-1" +module[13]="Disk Usage" +interval[13]="86N00" +graph_type[13]="area" +label[13]="" +label_position[13]="down" +x[13]="625" +y[13]="500" +width[13]="600" +height[13]="180" \ No newline at end of file From 4cf2b3427ec6d6beb6f0f05445854925f454f330 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Tue, 28 Nov 2023 16:00:01 +0100 Subject: [PATCH 112/397] Added peridicity to reports prd format --- .../extras/demodata/reports/1-sla-report.prd | 10 +++++++++- .../extras/demodata/reports/2-graphs-report.prd | 11 ++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pandora_console/extras/demodata/reports/1-sla-report.prd b/pandora_console/extras/demodata/reports/1-sla-report.prd index e3d130b4a0..f40c9b896f 100644 --- a/pandora_console/extras/demodata/reports/1-sla-report.prd +++ b/pandora_console/extras/demodata/reports/1-sla-report.prd @@ -10,38 +10,46 @@ name[1]="linux-1 httpd" type[1]="sla" agent_name[1]="linux-1" module[1]="Service httpd" +periodicity[1]="86400" name[2]="linux-2 httpd" type[2]="sla" agent_name[2]="linux-2" module[2]="Service httpd" +periodicity[2]="86400" name[3]="linux-3 httpd" type[3]="sla" agent_name[3]="linux-3" module[3]="Service httpd" +periodicity[3]="86400" name[4]="linux-4 httpd" type[4]="sla" agent_name[4]="linux-4" module[4]="Service httpd" +periodicity[4]="86400" name[5]="linux-1 mysqld" type[5]="sla" agent_name[5]="linux-1" module[5]="Service mysqld" +periodicity[5]="86400" name[6]="linux-2 mysqld" type[6]="sla" agent_name[6]="linux-2" module[6]="Service mysqld" +periodicity[6]="86400" name[7]="linux-3 mysqld" type[7]="sla" agent_name[7]="linux-3" module[7]="Service mysqld" +periodicity[7]="86400" name[8]="linux-4 mysqld" type[8]="sla" agent_name[8]="linux-4" -module[8]="Service mysqld" \ No newline at end of file +module[8]="Service mysqld" +periodicity[8]="86400" \ No newline at end of file diff --git a/pandora_console/extras/demodata/reports/2-graphs-report.prd b/pandora_console/extras/demodata/reports/2-graphs-report.prd index ecf3fe0502..3e8e273e37 100644 --- a/pandora_console/extras/demodata/reports/2-graphs-report.prd +++ b/pandora_console/extras/demodata/reports/2-graphs-report.prd @@ -8,43 +8,52 @@ description="This is a demo report for CPU Load" type[1]="custom_graph" graph_name[1]="Linux CPU Load" +periodicity[1]="86400" name[2]="linux-1 CPU Load graph" type[2]="simple_graph" agent_name[2]="linux-1" module[2]="CPU Load" +periodicity[2]="86400" name[3]="linux-1 CPU Load data" type[3]="historical" agent_name[3]="linux-1" module[3]="CPU Load" +periodicity[3]="86400" name[4]="linux-2 CPU Load graph" type[4]="simple_graph" agent_name[4]="linux-2" module[4]="CPU Load" +periodicity[4]="86400" name[5]="linux-2 CPU Load data" type[5]="historical" agent_name[5]="linux-2" module[5]="CPU Load" +periodicity[5]="86400" name[6]="linux-3 CPU Load graph" type[6]="simple_graph" agent_name[6]="linux-3" module[6]="CPU Load" +periodicity[6]="86400" name[7]="linux-3 CPU Load data" type[7]="historical" agent_name[7]="linux-3" module[7]="CPU Load" +periodicity[7]="86400" name[8]="linux-4 CPU Load graph" type[8]="simple_graph" agent_name[8]="linux-4" module[8]="CPU Load" +periodicity[8]="86400" name[9]="linux-4 CPU Load data" type[9]="historical" agent_name[9]="linux-4" -module[9]="CPU Load" \ No newline at end of file +module[9]="CPU Load" +periodicity[9]="86400" \ No newline at end of file From e56b0ee37e0dd399395fb32aae1b809c17e03cc0 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Tue, 28 Nov 2023 16:46:42 +0100 Subject: [PATCH 113/397] Added all widgets by defult --- pandora_console/extras/mr/67.sql | 368 +++++++++++++++++++++++++++++++ 1 file changed, 368 insertions(+) diff --git a/pandora_console/extras/mr/67.sql b/pandora_console/extras/mr/67.sql index 0ae98fd735..3e48bf9e8b 100644 --- a/pandora_console/extras/mr/67.sql +++ b/pandora_console/extras/mr/67.sql @@ -7,4 +7,372 @@ CREATE TABLE IF NOT EXISTS `tdemo_data` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +SET @class_name = 'AgentHive'; +SET @unique_name = 'AgentHive'; +SET @description = 'Agents hive'; +SET @page = 'AgentHive.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'AvgSumMaxMinModule'; +SET @unique_name = 'AvgSumMaxMinModule'; +SET @description = 'Avg|Sum|Max|Min Module Data'; +SET @page = 'AvgSumMaxMinModule.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'BasicChart'; +SET @unique_name = 'BasicChart'; +SET @description = 'Basic chart'; +SET @page = 'BasicChart.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'BlockHistogram'; +SET @unique_name = 'BlockHistogram'; +SET @description = 'Block histogram'; +SET @page = 'BlockHistogram.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ColorModuleTabs'; +SET @unique_name = 'ColorModuleTabs'; +SET @description = 'Color tabs modules'; +SET @page = 'ColorModuleTabs.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'DataMatrix'; +SET @unique_name = 'DataMatrix'; +SET @description = 'Data Matrix'; +SET @page = 'DataMatrix.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'EventCardboard'; +SET @unique_name = 'EventCardboard'; +SET @description = 'Event cardboard'; +SET @page = 'EventCardboard.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GroupedMeterGraphs'; +SET @unique_name = 'GroupedMeterGraphs'; +SET @description = 'Grouped meter graphs'; +SET @page = 'GroupedMeterGraphs.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModulesByStatus'; +SET @unique_name = 'ModulesByStatus'; +SET @description = 'Modules by status'; +SET @page = 'ModulesByStatus.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'AgentModuleWidget'; +SET @unique_name = 'agent_module'; +SET @description = 'Agent/Module View'; +SET @page = 'agent_module.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'AlertsFiredWidget'; +SET @unique_name = 'alerts_fired'; +SET @description = 'Triggered alerts report'; +SET @page = 'alerts_fired.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ClockWidget'; +SET @unique_name = 'clock'; +SET @description = 'Clock'; +SET @page = 'clock.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'CustomGraphWidget'; +SET @unique_name = 'custom_graph'; +SET @description = 'Defined custom graph'; +SET @page = 'custom_graph.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'EventsListWidget'; +SET @unique_name = 'events_list'; +SET @description = 'List of latest events'; +SET @page = 'events_list.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'WelcomeWidget'; +SET @unique_name = 'example'; +SET @description = 'Welcome message to Pandora FMS'; +SET @page = 'example.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GraphModuleHistogramWidget'; +SET @unique_name = 'graph_module_histogram'; +SET @description = 'Module histogram'; +SET @page = 'graph_module_histogram.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GroupsStatusWidget'; +SET @unique_name = 'groups_status'; +SET @description = 'General group status'; +SET @page = 'groups_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'GroupsStatusMapWidget'; +SET @unique_name = 'groups_status_map'; +SET @description = 'Group status map'; +SET @page = 'groups_status_map.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'HeatmapWidget'; +SET @unique_name = 'heatmap'; +SET @description = 'Heatmap'; +SET @page = 'heatmap.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'InventoryWidget'; +SET @unique_name = 'inventory'; +SET @description = 'Inventory'; +SET @page = 'inventory.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'MapsMadeByUser'; +SET @unique_name = 'maps_made_by_user'; +SET @description = 'Visual Console'; +SET @page = 'maps_made_by_user.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'MapsStatusWidget'; +SET @unique_name = 'maps_status'; +SET @description = 'General visual maps report'; +SET @page = 'maps_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleIconWidget'; +SET @unique_name = 'module_icon'; +SET @description = 'Icon and module value'; +SET @page = 'module_icon.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleStatusWidget'; +SET @unique_name = 'module_status'; +SET @description = 'Module status'; +SET @page = 'module_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleTableValueWidget'; +SET @unique_name = 'module_table_value'; +SET @description = 'Module in a table'; +SET @page = 'module_table_value.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ModuleValueWidget'; +SET @unique_name = 'module_value'; +SET @description = 'Module value'; +SET @page = 'module_value.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'MonitorHealthWidget'; +SET @unique_name = 'monitor_health'; +SET @description = 'Global health info'; +SET @page = 'monitor_health.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'Netflow'; +SET @unique_name = 'netflow'; +SET @description = 'Netflow'; +SET @page = 'netflow.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'NetworkMapWidget'; +SET @unique_name = 'network_map'; +SET @description = 'Network map'; +SET @page = 'network_map.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'OsQuickReportWidget'; +SET @unique_name = 'os_quick_report'; +SET @description = 'OS quick report'; +SET @page = 'os_quick_report.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'PostWidget'; +SET @unique_name = 'post'; +SET @description = 'Panel with a message'; +SET @page = 'post.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ReportsWidget'; +SET @unique_name = 'reports'; +SET @description = 'Custom report'; +SET @page = 'reports.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ServiceMapWidget'; +SET @unique_name = 'service_map'; +SET @description = 'Service map'; +SET @page = 'service_map.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'ServiceViewWidget'; +SET @unique_name = 'service_view'; +SET @description = 'Services view'; +SET @page = 'service_view.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SingleGraphWidget'; +SET @unique_name = 'single_graph'; +SET @description = 'Agent module graph'; +SET @page = 'single_graph.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SLAPercentWidget'; +SET @unique_name = 'sla_percent'; +SET @description = 'SLA percentage'; +SET @page = 'sla_percent.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SystemGroupStatusWidget'; +SET @unique_name = 'system_group_status'; +SET @description = 'Groups status'; +SET @page = 'system_group_status.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TacticalWidget'; +SET @unique_name = 'tactical'; +SET @description = 'Tactical view'; +SET @page = 'tactical.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TopNWidget'; +SET @unique_name = 'top_n'; +SET @description = 'Top N of agent modules'; +SET @page = 'top_n.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TopNEventByGroupWidget'; +SET @unique_name = 'top_n_events_by_group'; +SET @description = 'Top N events by agent'; +SET @page = 'top_n_events_by_group.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TopNEventByModuleWidget'; +SET @unique_name = 'top_n_events_by_module'; +SET @description = 'Top N events by module'; +SET @page = 'top_n_events_by_module.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'TreeViewWidget'; +SET @unique_name = 'tree_view'; +SET @description = 'Tree view'; +SET @page = 'tree_view.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'UrlWidget'; +SET @unique_name = 'url'; +SET @description = 'URL content'; +SET @page = 'url.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'WuxWidget'; +SET @unique_name = 'wux_transaction'; +SET @description = 'Agent WUX transaction'; +SET @page = 'wux_transaction.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'WuxStatsWidget'; +SET @unique_name = 'wux_transaction_stats'; +SET @description = 'WUX transaction stats'; +SET @page = 'wux_transaction_stats.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + +SET @class_name = 'SecurityHardening'; +SET @unique_name = 'security_hardening'; +SET @description = 'Security Hardening'; +SET @page = 'security_hardening.php'; +SET @widget_id = NULL; +SELECT @widget_id := `id` FROM `twidget` WHERE `unique_name` = @unique_name; +INSERT IGNORE INTO `twidget` (`id`,`class_name`,`unique_name`,`description`,`options`,`page`) VALUES (@widget_id,@class_name,@unique_name,@description,'',@page); + COMMIT; From 7240bbf93446737cb4359868193d23625df05ccf Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 29 Nov 2023 09:00:45 +0100 Subject: [PATCH 114/397] implement demo data load --- pandora_console/godmode/setup/demo.php | 217 ++++++- .../include/ajax/demo_data.ajax.php | 550 ++++++++++++++++-- pandora_console/include/constants.php | 1 + pandora_console/include/functions_agents.php | 11 +- pandora_console/include/functions_users.php | 2 +- .../include/lib/Dashboard/Manager.php | 2 +- .../include/lib/Dashboard/Widget.php | 4 +- 7 files changed, 728 insertions(+), 59 deletions(-) diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index 800701a2b9..df3af0bc02 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -49,7 +49,8 @@ if ($create_data === false) { $adv_options_is_enabled = get_parameter('toggle_adv_opts', 0); $days_hist_data = (int) get_parameter('days_hist_data', 15); -$interval = get_parameter('interval', 0); +$interval = get_parameter('interval', 300); +$service_agent_id = (int) get_parameter('service_agent_id', 0); // Map directory and demo item ID. $dir_item_id_map = [ @@ -71,6 +72,15 @@ $enabled_items = [ 'enable_history' => (int) get_parameter('enable_history', 0), ]; +$generate_hist = (int) get_parameter('enable_history', $def_value); + +$plugin_agent = (int) get_parameter('plugin_agent', 0); +$traps_target_ip = get_parameter('traps_target_ip', '127.0.0.1'); +$traps_community = get_parameter('traps_community', 'public'); +$tentacle_target_ip = get_parameter('tentacle_target_ip', '127.0.0.1'); +$tentacle_port = get_parameter('tentacle_port', '41121'); +$tentacle_extra_options = get_parameter('tentacle_extra_options', ''); + $demo_items_count = (int) db_get_value('count(*)', 'tdemo_data'); $current_progress_val = db_get_value_filter( @@ -146,7 +156,9 @@ if ($display_loading === true || $running_create === true || $running_delete) { unset($items_ids_text_map[DEMO_SERVICE]); } + $items_ids_text_map[DEMO_PLUGIN] = 'plugin'; $items_ids_text_map = ([DEMO_AGENT => 'agents'] + $items_ids_text_map); + $list_mkup = '
      '; foreach ($items_ids_text_map as $item_id => $item_text) { $list_mkup .= '
    • '; @@ -233,7 +245,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { $otherData = []; $table_aux->data['row1'][] = html_print_label_input_block( - __('Agents'), + __('Agents').ui_print_help_tip(__('You may need to increase the value of the plugin_timeout parameter in your server configuration to get all your agents data updated'), true), html_print_div( [ 'class' => '', @@ -296,7 +308,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { html_print_checkbox_switch( 'enable_history', 1, - false, + (bool) $generate_hist, true ) ); @@ -327,9 +339,27 @@ if ($display_loading === true || $running_create === true || $running_delete) { true ) ); + + $params = []; + $params['return'] = true; + $params['show_helptip'] = true; + $params['print_hidden_input_idagent'] = true; + $params['hidden_input_idagent_id'] = 'hidden-service_agent_id'; + $params['hidden_input_idagent_name'] = 'service_agent_id'; + $params['input_name'] = 'agent_alias'; + $params['value'] = ''; + $params['javascript_function_action_after_select'] = 'active_button_add_agent'; + $params['javascript_is_function_select'] = true; + $params['disabled_javascript_on_blur_function'] = false; + + $table_adv->data['row4'][] = html_print_label_input_block( + __('Services agent name').ui_print_help_tip(__('If not set, %s will be used as the default agent', 'demo-global-agent-1'), true), + ui_print_agent_autocomplete_input($params), + ['div_class' => 'w300px'] + ); } - $table_adv->data['row4'][] = html_print_label_input_block( + $table_adv->data['row5'][] = html_print_label_input_block( __('Create network maps'), html_print_checkbox_switch( 'enable_nm', @@ -339,7 +369,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row5'][] = html_print_label_input_block( + $table_adv->data['row6'][] = html_print_label_input_block( __('Create custom graphs'), html_print_checkbox_switch( 'enable_cg', @@ -349,7 +379,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row6'][] = html_print_label_input_block( + $table_adv->data['row7'][] = html_print_label_input_block( __('Create reports'), html_print_checkbox_switch( 'enable_rep', @@ -359,7 +389,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row7'][] = html_print_label_input_block( + $table_adv->data['row8'][] = html_print_label_input_block( __('Create visual consoles'), html_print_checkbox_switch( 'enable_vc', @@ -369,6 +399,123 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); + $table_adv->data['row9'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); + + $params = []; + $params['return'] = true; + $params['show_helptip'] = true; + $params['print_hidden_input_idagent'] = true; + $params['hidden_input_idagent_id'] = 'hidden-plugin_agent'; + $params['hidden_input_idagent_name'] = 'plugin_agent'; + $params['input_name'] = 'plugin_agent_alias'; + $params['value'] = ''; + $params['javascript_function_action_after_select'] = 'active_button_add_agent'; + $params['javascript_is_function_select'] = true; + $params['disabled_javascript_on_blur_function'] = false; + + $table_adv->data['row10'][] = html_print_label_input_block( + __('Demo data plugin agent').ui_print_help_tip(__('If not set, %s will be used as the default agent', 'demo-global-agent-1'), true), + ui_print_agent_autocomplete_input($params), + ['div_class' => 'w300px'] + ); + + $table_adv->data['row11'][] = html_print_label_input_block( + __('Traps target IP').ui_print_help_tip(__('All demo traps are generated using version 1'), true), + html_print_input_text( + 'traps_target_ip', + $traps_target_ip, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row12'][] = html_print_label_input_block( + __('Traps community'), + html_print_input_text( + 'traps_community', + $traps_community, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row13'][] = html_print_label_input_block( + __('Tentacle target IP'), + html_print_input_text( + 'tentacle_target_ip', + $tentacle_target_ip, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row14'][] = html_print_label_input_block( + __('Tentacle port'), + html_print_input_text( + 'tentacle_port', + $tentacle_port, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + $table_adv->data['row15'][] = html_print_label_input_block( + __('Tentacle extra options'), + html_print_input_text( + 'tentacle_extra_options', + $tentacle_extra_options, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) + ); + + /* $table_adv->data['row8'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); $table_adv->data['row8'][] = html_print_label_input_block( __('Create dashboards'), html_print_checkbox_switch( @@ -378,6 +525,33 @@ if ($display_loading === true || $running_create === true || $running_delete) { true ) ); + $table_adv->data['row8'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); + $table_adv->data['row8'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + ); + $table_adv->data['row8'][] = html_print_label_input_block( + __('Create dashboards'), + html_print_checkbox_switch( + 'enable_dashboards', + 1, + $enabled_items['dashboards'], + true + ) + );*/ echo '
      '; echo '
      '; @@ -492,6 +666,10 @@ if ($display_loading === true || $running_create === true || $running_delete) { ?> \ No newline at end of file From db89c72be577bf4fcae03d7c717e6f337c9256cb Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 29 Nov 2023 16:00:46 +0100 Subject: [PATCH 124/397] fix error empty clusters pandora_enterprise#12511 --- .../godmode/agentes/agent_manager.php | 27 +++++++++++++++-- pandora_console/include/functions_agents.php | 29 +++++++++++++++++-- pandora_console/include/lib/Cluster.php | 4 +++ pandora_console/views/cluster/view.php | 6 +++- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 557b855e09..a7f979180a 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -1104,11 +1104,24 @@ if ($new_agent === false) { $actionButtons .= html_print_input_hidden('id_agente', $id_agente); if (is_management_allowed() === true) { + $clusters = agents_get_agent_belongs_cluster($id_agente); + $cluster_belongs = ''; + if (empty($clusters) === false) { + $clusters = array_reduce( + $clusters, + function ($carry, $item) { + $carry[] = $item['name']; + return $carry; + } + ); + $cluster_belongs = implode(', ', $clusters); + } + $actionButtons .= html_print_button( __('Delete agent'), 'deleteAgent', false, - 'deleteAgentDialog('.$id_agente.')', + 'deleteAgentDialog('.$id_agente.', "'.$cluster_belongs.'")', [ 'icon' => 'delete', 'mode' => 'secondary dialog_opener', @@ -1156,10 +1169,18 @@ ui_require_jquery_file('bgiframe'); } } - function deleteAgentDialog($idAgente) { + function deleteAgentDialog($idAgente, cluster) { + var msg_cluster = ''; + if(cluster) { + msg_cluster = ""; + msg_cluster += ': '; + msg_cluster += cluster; + msg_cluster += '. '; + } + confirmDialog({ title: "", - message: "", + message: msg_cluster + "", onAccept: function() { window.location.assign('index.php?sec=gagente&sec2=godmode/agentes/modificar_agente&borrar_agente='+$idAgente); } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 2d6803ccd4..32dc0a9312 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -4976,13 +4976,38 @@ function get_resume_agent_concat($id_agente, $all_groups, $agent) } +/** + * agent belongs to the clusters. + * + * @param integer $idAgent + * + * @return array Names clusters. + */ +function agents_get_agent_belongs_cluster(int $idAgent): array +{ + $sql = sprintf( + 'SELECT tcluster.name + FROM tcluster + INNER JOIN tcluster_agent + ON tcluster.id = tcluster_agent.id_cluster + WHERE tcluster_agent.id_agent = %d', + $idAgent + ); + + $result = db_get_all_rows_sql($sql); + if ($result === false) { + $result = []; + } + + return $result; +} + + /** * Return an array with a list of status agents * * @return array. */ - - function agents_status_list() { $status_list = []; diff --git a/pandora_console/include/lib/Cluster.php b/pandora_console/include/lib/Cluster.php index b7bd21d929..46e7ba4324 100644 --- a/pandora_console/include/lib/Cluster.php +++ b/pandora_console/include/lib/Cluster.php @@ -213,6 +213,10 @@ class Cluster extends Entity public function getCounters() :array { $id_agent_modules = $this->getIdsModulesInvolved(); + if (empty($id_agent_modules) === true) { + return []; + } + $sql = sprintf( 'SELECT SUM( IF(estado = 1, 1, 0) ) AS critical, SUM( IF(estado = 2, 1, 0) ) AS warning, diff --git a/pandora_console/views/cluster/view.php b/pandora_console/views/cluster/view.php index 32bcdb0736..93894ba7e5 100644 --- a/pandora_console/views/cluster/view.php +++ b/pandora_console/views/cluster/view.php @@ -151,7 +151,11 @@ $agentCountModules = html_print_div( true ); -$alive_animation = agents_get_starmap(0, 180, 30, $module_involved_ids); +$alive_animation = ''; +if (empty($module_involved_ids) === false) { + $alive_animation = agents_get_starmap(0, 180, 30, $module_involved_ids); +} + $output = '
      '; $output .= '
      '; From f1a8c4b31de5c05c0bd3f7603a920efcc74c2e29 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 29 Nov 2023 16:12:12 +0100 Subject: [PATCH 125/397] #12541 change message export graph --- .../include/javascript/graph_analytics.js | 4 +- .../operation/reporting/graph_analytics.php | 52 +++++++++++-------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/pandora_console/include/javascript/graph_analytics.js b/pandora_console/include/javascript/graph_analytics.js index 742e43201e..475a310ebc 100644 --- a/pandora_console/include/javascript/graph_analytics.js +++ b/pandora_console/include/javascript/graph_analytics.js @@ -800,10 +800,10 @@ function exportCustomGraph() { group }, success: function(data) { - if (data) { + if (data === "created") { confirmDialog({ title: titleExportConfirm, - message: data + " " + messageExportConfirm, + message: messageExportConfirm, hideCancelButton: true, onAccept: function() { $( diff --git a/pandora_console/operation/reporting/graph_analytics.php b/pandora_console/operation/reporting/graph_analytics.php index b85a0cb84d..ff6272bdd6 100644 --- a/pandora_console/operation/reporting/graph_analytics.php +++ b/pandora_console/operation/reporting/graph_analytics.php @@ -364,7 +364,11 @@ if (is_ajax()) { } } - echo $counter; + if ($id_graph > 0) { + echo 'created'; + } else { + echo ''; + } } if (empty($load_list_filters) === false) { @@ -827,30 +831,31 @@ $left_content .= '
      + '.__('Agents').'
      '.ui_toggle( - '', - __('Agents'), - 'agents-toggle', - 'agents-toggle', - true, - true, - '', - 'white-box-content', - 'box-flat white_table_graph', - 'images/arrow@svg.svg', - 'images/arrow@svg.svg', - false, - false, - false, - '', - '', - null, - null, - false, - false, - 'static' + '', + __('Agents'), + 'agents-toggle', + 'agents-toggle', + true, + true, + '', + 'white-box-content', + 'box-flat white_table_graph', + 'images/arrow@svg.svg', + 'images/arrow@svg.svg', + false, + false, + false, + '', + '', + null, + null, + false, + false, + 'static' ).ui_toggle( '', __('Groups'), @@ -898,6 +903,7 @@ $left_content .= ' ).'
      + '.__('Modules').' @@ -1000,7 +1006,7 @@ const messageLoadConfirm = ""; const titleExport = ""; const titleExportConfirm = ""; -const messageExportConfirm = ""; +const messageExportConfirm = ""; const titleExportError = ""; const messageExportError = ""; From 7a5201db4ff30baf0cd826319317127ff5bdd22a Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 29 Nov 2023 16:31:06 +0100 Subject: [PATCH 126/397] #8365 NCM V3 Minor fix --- pandora_console/include/javascript/pandora_ui.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/javascript/pandora_ui.js b/pandora_console/include/javascript/pandora_ui.js index 80ddfd06f5..00ece1a178 100644 --- a/pandora_console/include/javascript/pandora_ui.js +++ b/pandora_console/include/javascript/pandora_ui.js @@ -514,7 +514,7 @@ function load_modal(settings) { if (settings.cleanup != undefined) { settings.cleanup(); } - $("#modal_overlay").removeClass("ui-widget-overlay"); + $("#modal_overlay").remove(); }, beforeClose: settings.beforeClose() }); From a2902038476784273c809567db496e299b91bf9e Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 29 Nov 2023 16:57:38 +0100 Subject: [PATCH 127/397] implement demo data load --- pandora_console/godmode/setup/demo.php | 79 +++--- .../include/ajax/demo_data.ajax.php | 253 +++++++++--------- 2 files changed, 169 insertions(+), 163 deletions(-) diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index df3af0bc02..3707dbe8ca 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -50,7 +50,7 @@ if ($create_data === false) { $adv_options_is_enabled = get_parameter('toggle_adv_opts', 0); $days_hist_data = (int) get_parameter('days_hist_data', 15); $interval = get_parameter('interval', 300); -$service_agent_id = (int) get_parameter('service_agent_id', 0); +$service_agent_name = get_parameter('service_agent_name', 'demo-global-agent-1'); // Map directory and demo item ID. $dir_item_id_map = [ @@ -74,7 +74,7 @@ $enabled_items = [ $generate_hist = (int) get_parameter('enable_history', $def_value); -$plugin_agent = (int) get_parameter('plugin_agent', 0); +$plugin_agent = get_parameter('plugin_agent', 'demo-global-agent-1'); $traps_target_ip = get_parameter('traps_target_ip', '127.0.0.1'); $traps_community = get_parameter('traps_community', 'public'); $tentacle_target_ip = get_parameter('tentacle_target_ip', '127.0.0.1'); @@ -340,22 +340,22 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $params = []; - $params['return'] = true; - $params['show_helptip'] = true; - $params['print_hidden_input_idagent'] = true; - $params['hidden_input_idagent_id'] = 'hidden-service_agent_id'; - $params['hidden_input_idagent_name'] = 'service_agent_id'; - $params['input_name'] = 'agent_alias'; - $params['value'] = ''; - $params['javascript_function_action_after_select'] = 'active_button_add_agent'; - $params['javascript_is_function_select'] = true; - $params['disabled_javascript_on_blur_function'] = false; + $table_adv->data['row4'][] = html_print_label_input_block( __('Services agent name').ui_print_help_tip(__('If not set, %s will be used as the default agent', 'demo-global-agent-1'), true), - ui_print_agent_autocomplete_input($params), - ['div_class' => 'w300px'] + html_print_input_text( + 'service_agent_name', + $service_agent_name, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) ); } @@ -409,22 +409,20 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $params = []; - $params['return'] = true; - $params['show_helptip'] = true; - $params['print_hidden_input_idagent'] = true; - $params['hidden_input_idagent_id'] = 'hidden-plugin_agent'; - $params['hidden_input_idagent_name'] = 'plugin_agent'; - $params['input_name'] = 'plugin_agent_alias'; - $params['value'] = ''; - $params['javascript_function_action_after_select'] = 'active_button_add_agent'; - $params['javascript_is_function_select'] = true; - $params['disabled_javascript_on_blur_function'] = false; - $table_adv->data['row10'][] = html_print_label_input_block( - __('Demo data plugin agent').ui_print_help_tip(__('If not set, %s will be used as the default agent', 'demo-global-agent-1'), true), - ui_print_agent_autocomplete_input($params), - ['div_class' => 'w300px'] + __('Demo data plugin agent'), + html_print_input_text( + 'plugin_agent', + $plugin_agent, + '', + 50, + 255, + true, + false, + false, + '', + 'w300px' + ) ); $table_adv->data['row11'][] = html_print_label_input_block( @@ -676,13 +674,13 @@ if ($display_loading === true || $running_create === true || $running_delete) { var agents_str = ''; var display_progress_bar_cr = ; - console.log("dpb ",display_progress_bar_cr); + if (display_progress_bar_cr == 1) { init_progress_bar('create'); } var display_progress_bar_del = ; - console.log("dpbdel ",display_progress_bar_del); + if (display_progress_bar_del == 1) { init_progress_bar('cleanup'); } @@ -729,8 +727,6 @@ if ($display_loading === true || $running_create === true || $running_delete) { // Creation operation must be done via AJAX in order to be able to run the operations in background // and keep it running even if we quit the page. if (create_data == true) { - console.log("CREATE"); - init_progress_bar('create'); var params = {}; @@ -747,9 +743,8 @@ if ($display_loading === true || $running_create === true || $running_delete) { params["tentacle_target_ip"] = ""; params["tentacle_port"] = ; params["tentacle_extra_options"] = ""; - params["service_agent_id"] = ""; - console.log("params"); - console.log(params); + params["service_agent_name"] = ""; + jQuery.ajax({ data: params, type: "POST", @@ -761,7 +756,6 @@ if ($display_loading === true || $running_create === true || $running_delete) { // Delete operation must be done via AJAX in order to be able to run the operations in background // and keep it running even if we quit the page. if (delete_data == true) { - console.log("DELETE"); /// $("#table-demo-row2").show(); init_progress_bar('cleanup'); @@ -814,8 +808,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { } params["page"] = "include/ajax/demo_data.ajax"; params["id_queue"] = id_queue; -console.log("ANTES DE AJAX"); -console.log(params); + jQuery.ajax({ data: params, type: "POST", @@ -840,13 +833,14 @@ console.log(params); if (operation == 'create') { var status_data = data?.demo_data_load_status; - console.log("----> ",status_data.checked_items); status_data.checked_items?.forEach(function(item_id) { if (items_checked.includes(item_id)) { return; } - if (typeof status_data.errors[item_id] !== 'undefined' + if (typeof status_data !== 'undefined' + && typeof status_data.errors !== 'undefined' + && typeof status_data.errors[item_id] !== 'undefined' && status_data.errors[item_id].length > 0 ) { status_data.errors[item_id].forEach(function(error_msg) { @@ -905,7 +899,6 @@ console.log(params); }); // Append the new item to the corresponding error-list ul. - console.log("qewdfefdsfs"+error_msg); $('#load-info li[data-item-id="' + item_id + '"] .error-list').append(error_list_item); } \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 0eab652fe2..6b5f96c325 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -62,17 +62,16 @@ if ($action === 'create_demo_data') { $demodata_directory = $config['homedir'].'/extras/demodata/'; - $service_agent_id = (int) get_parameter('service_agent_id', 0); - $adv_options_is_enabled = (bool) get_parameter('adv_options_is_enabled', false); if ($adv_options_is_enabled === true) { + $service_agent_name = get_parameter('service_agent_name', 'demo-global-agent-1'); $enabled_items = get_parameter('enabled_items'); $history_is_enabled = (bool) $enabled_items['enable_history']; $days_hist_data = (int) get_parameter('days_hist_data', 15); $interval = (int) get_parameter('interval', 300); // Plugin values. - $plugin_agent_id = (int) get_parameter('plugin_agent', 0); + $plugin_agent_name = get_parameter('plugin_agent', 'demo-global-agent-1'); $traps_target_ip = (string) get_parameter('traps_target_ip', ''); $traps_community = (string) get_parameter('traps_community', ''); @@ -84,6 +83,9 @@ if ($action === 'create_demo_data') { $enabled_directories[] = 'agents'; } else { $enabled_directories = $directories; + + $service_agent_name = 'demo-global-agent-1'; + $plugin_agent_name = 'demo-global-agent-1'; } if (enterprise_installed() === false) { @@ -140,7 +142,7 @@ if ($action === 'create_demo_data') { ///$iter_agents_created = 0; // Get first server: general value for all created modules. . - $server_name = db_get_value('name' ,'tserver', 'id_server', 1); + $server_name = db_get_value('name', 'tserver', 'id_server', 1); // Traverse agent ini files and create agents. foreach ($parsed_ini['agents'] as $ini_agent_data) { @@ -247,9 +249,10 @@ if ($action === 'create_demo_data') { // Create agents (remaining number of agents to reach number specified by user). for ($i = 0; $i < min($iter_agents_to_create, $max_agents_to_limit); $i++) { - $agent_base_host_address = explode('/', $address_network)[0]; - $next_ip_address = ($agents_last_ip[$agent_data['agent_alias']] !== null) ? $agents_last_ip[$agent_data['agent_alias']] : $agent_base_host_address; + $curr_ip_address = ($agents_last_ip[$agent_data['agent_alias']] !== null) ? $agents_last_ip[$agent_data['agent_alias']] : $address_network; + $next_ip_address = calculateNextHostAddress($curr_ip_address); $host_address = explode('/', $next_ip_address)[0]; + $agents_last_ip[$agent_data['agent_alias']] = $next_ip_address; $os_version = current($os_versions); next($os_versions); @@ -305,7 +308,7 @@ if ($action === 'create_demo_data') { } $agents_created_count[$agent_data['agent_alias']]++; - $agents_last_ip[$agent_data['agent_alias']] = calculateNextHostAddress($next_ip_address); + $iter_agents_created++; // Create agent modules. @@ -409,9 +412,10 @@ if ($action === 'create_demo_data') { $back_periods = 1; if ($adv_options_is_enabled === true && $history_is_enabled === true) { - $back_periods = $days_hist_data; + $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); } + $utimestamp = time(); // Generate back_periods amounts of tagente_datos rows each period_mins minutes back in time. @@ -441,24 +445,9 @@ if ($action === 'create_demo_data') { 'utimestamp' => $utimestamp, ]; - $created_data_id = db_process_sql_insert('tagente_datos', $agent_data_values); + $created_data_res = db_process_sql_insert('tagente_datos', $agent_data_values); - if ($created_data_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_data_id, - 'table_name' => 'tagente_datos', - ]; - - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback demo item creation if could not be registered in tdemo_data. - db_process_sql_delete('tagente_datos', ['id_agente_modulo' => $created_data_id]); - } else { - continue; - } - } else { + if ($created_data_res === false) { continue; } @@ -503,8 +492,6 @@ if ($action === 'create_demo_data') { } if ($adv_options_is_enabled === true && $history_is_enabled === true) { - // Get 00:00 timestamp and substract 24 hours interval. - $utimestamp = strtotime(date('Y-m-d', $utimestamp)); $utimestamp -= $interval; } } @@ -660,26 +647,7 @@ if ($action === 'create_demo_data') { 'timestamp' => $current_date_time, ]; - $created_inventory_data = db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); - - if ($created_inventory_data > 0) { - // Register created inventory data element in tdemo_data. - $values = [ - 'item_id' => $created_inventory_data, - 'table_name' => 'tagente_datos_inventory', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback inventory module if could not be registered in tdemo_data. - db_process_sql_delete( - 'tagente_datos_inventory', - ['id_agent_module_inventory' => $created_inventory_data] - ); - - continue; - } - } + db_process_sql_insert('tagente_datos_inventory', $inventory_data_values); } // Create traps. @@ -688,9 +656,10 @@ if ($action === 'create_demo_data') { $back_periods = 1; if ($adv_options_is_enabled === true && $history_is_enabled === true) { - $back_periods = $days_hist_data; + $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); } + $utimestamp = time(); for ($p = 0; $p < $back_periods; $p++) { @@ -786,12 +755,8 @@ if ($action === 'create_demo_data') { } if ($adv_options_is_enabled === true && $history_is_enabled === true) { - $date_time->setTime(0, 0, 0); $date_time->sub(new DateInterval("PT{$interval}S")); $current_date_time = $date_time->format('Y-m-d H:i:s'); - - // Get 00:00 timestamp and substract 24 hours interval. - $utimestamp = strtotime(date('Y-m-d', $utimestamp)); $utimestamp -= $interval; } } @@ -833,35 +798,33 @@ if ($action === 'create_demo_data') { continue; } - if ($service_agent_id === 0) { - // Check whether services default agent exists in the system. Try to get default agent if not. - $matched_agents = agents_get_agents( - ['nombre' => 'demo-global-agent-1'], - ['id_agente'], - 'AR', - [ - 'field' => 'nombre', - 'order' => 'ASC', - ], - false, - 0, - false, - false, - false + // Check whether services default agent exists in the system. Try to get default agent if not. + $matched_agents = agents_get_agents( + ['nombre' => $service_agent_name], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + + $matched_agent = $matched_agents[0]['id_agente']; + + if (isset($matched_agent) === true && $matched_agent > 0) { + $service_agent_id = $matched_agent; + } else { + // Skip element creation if agent does not exist. + register_error( + DEMO_SERVICE, + __('Error in %s: the specified services agent does not exist in the system: %s. Skipping service creation', $filename, $service_agent_name) ); - - $matched_agent = $matched_agents[0]['id_agente']; - - if (isset($matched_agent) === true && $matched_agent > 0) { - $service_agent_id = $matched_agent; - } else { - // Skip element creation if agent does not exist. - register_error( - DEMO_SERVICE, - __('Error in %s: no agent was specified for the service and default services agent does not exist in the system: demo-global-agent-1. Skipping service creation', $filename) - ); - continue; - } + continue; } $id_group = get_group_or_create_demo_group($service_data['group']); @@ -1085,7 +1048,7 @@ if ($action === 'create_demo_data') { if (in_array($element_type, ['agent', 'module']) === true) { // Get agent ID and module ID. $matched_agents = agents_get_agents( - ['nombre' => $items_array['agent_name']], + ['nombre' => io_safe_input($items_array['agent_name'])], ['id_agente'], 'AR', [ @@ -1751,6 +1714,8 @@ if ($action === 'create_demo_data') { $item_values = []; $item_values['id_report'] = $created_report_id; + $item_values['name'] = $items_array['name']; + $item_values['type'] = $items_array['type']; if (isset($items_array['agent_name']) === true) { if (isset($items_array['module']) === false @@ -1812,7 +1777,7 @@ if ($action === 'create_demo_data') { } if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true) { - $id_custom_graph = reset(custom_graphs_search('', $items_array['graph_name']))['id_graph']; + $id_custom_graph = reset(custom_graphs_search('', io_safe_input($items_array['graph_name'])))['id_graph']; if ($id_custom_graph > 0) { $item_values['id_gs'] = $id_custom_graph; @@ -2046,6 +2011,17 @@ if ($action === 'create_demo_data') { } if ($items_array['type'] === 'module_graph') { + if (isset($items_array['image']) === false + || is_string($items_array['image']) === false + ) { + // The above fields are required for this item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: image field must be specified for module_graph item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + if (isset($items_array['agent_name']) === true) { $matched_agents = agents_get_agents( ['nombre' => $items_array['agent_name']], @@ -2092,6 +2068,17 @@ if ($action === 'create_demo_data') { } if ($items_array['type'] === 'custom_graph') { + if (isset($items_array['image']) === false + || is_string($items_array['image']) === false + ) { + // The above fields are required for this item. + register_error( + DEMO_VISUAL_CONSOLE, + __('Error in %s: image field must be specified for custom_graph item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) + ); + continue; + } + if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true ) { @@ -2372,7 +2359,7 @@ if ($action === 'create_demo_data') { } // Try to get graph and skip if not exists. - $id_graph = db_get_value('id_graph', 'tgraph', 'name', $items_array['graph_name']); + $id_graph = db_get_value('id_graph', 'tgraph', 'name', io_safe_input($items_array['graph_name'])); if (!($id_graph > 0)) { continue; @@ -2414,7 +2401,7 @@ if ($action === 'create_demo_data') { continue; } - $id_report = reports_get_reports(['name' => $items_array['report_name']], ['id_report'])[0]['id_report']; + $id_report = reports_get_reports(['name' => io_safe_input($items_array['report_name'])], ['id_report'])[0]['id_report']; if (!($id_report > 0)) { continue; @@ -2435,7 +2422,7 @@ if ($action === 'create_demo_data') { continue; } - $id_map = db_get_value('id', 'tmap', 'name', $items_array['map_name']); + $id_map = db_get_value('id', 'tmap', 'name', io_safe_input($items_array['map_name'])); if (!($id_map > 0)) { continue; @@ -2483,10 +2470,10 @@ if ($action === 'create_demo_data') { $item_height = $items_array['height']; $position_data = [ - 'x' => (isset($items_array['x']) === false) ? "$item_x" : "0", - 'y' => (isset($items_array['y']) === false) ? "$item_y" : "0", - 'width' => (isset($items_array['width']) === false) ? "$item_width" : "4", - 'height' => (isset($items_array['height']) === false) ? "$item_height" : "4", + 'x' => (isset($items_array['x']) === true) ? "$item_x" : "0", + 'y' => (isset($items_array['y']) === true) ? "$item_y" : "0", + 'width' => (isset($items_array['width']) === true) ? "$item_width" : "4", + 'height' => (isset($items_array['height']) === true) ? "$item_height" : "4", ]; $element_values = [ @@ -2495,8 +2482,8 @@ if ($action === 'create_demo_data') { 'order' => $order, 'id_dashboard' => $created_id, 'id_widget' => $type_id, - 'prop_width' => 0.32, - 'prop_height' => 0.32, + 'prop_width' => $items_array['width'], + 'prop_height' => $items_array['height'], ]; $id = db_process_sql_insert('twidget_dashboard', $element_values); @@ -2527,35 +2514,34 @@ if ($action === 'create_demo_data') { // Register plugin. $quit = false; - if (!($plugin_agent_id > 0)) { - // Check whether plugin agent exists in the system. Try to get default agent if not. - $matched_agents = agents_get_agents( - ['nombre' => 'demo-global-agent-1'], - ['id_agente'], - 'AR', - [ - 'field' => 'nombre', - 'order' => 'ASC', - ], - false, - 0, - false, - false, - false + + // Check whether plugin agent exists in the system. Try to get default agent if not. + $matched_agents = agents_get_agents( + ['nombre' => $plugin_agent_name], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $matched_agent = $matched_agents[0]['id_agente']; + + if (isset($matched_agent) === true && $matched_agent > 0) { + $plugin_agent_id = $matched_agent; + } else { + // Skip element creation if agent does not exist. + register_error( + DEMO_PLUGIN, + __('Error in plugin creation: the specified agent for the plugin does not exist in the system: %s. Skipping plugin creation', $filename, $plugin_agent_name) ); - $matched_agent = $matched_agents[0]['id_agente']; - if (isset($matched_agent) === true && $matched_agent > 0) { - $plugin_agent_id = $matched_agent; - } else { - // Skip element creation if agent does not exist. - register_error( - DEMO_PLUGIN, - __('Error in plugin creation: no agent was specified for the plugin and default agent does not exist in the system: demo-global-agent-1. Skipping plugin creation', $filename) - ); - - $quit = true; - } + $quit = true; } if ($quit === false) { @@ -2651,6 +2637,34 @@ if ($action === 'cleanup_demo_data') { $demo_items = db_get_all_rows_in_table('tdemo_data'); + $module_items = array_filter( + $demo_items, + function ($item) { + return ($item['table_name'] === 'tagente_modulo'); + } + ); + + $inventory_module_items = array_filter( + $demo_items, + function ($item) { + return ($item['table_name'] === 'tagent_module_inventory'); + } + ); + + foreach ($inventory_module_items as $item) { + db_process_sql_delete( + 'tagente_datos_inventory', + ['id_agent_module_inventory' => $item['item_id']] + ); + } + + foreach ($module_items as $item) { + db_process_sql_delete( + 'tagente_datos', + ['id_agente_modulo' => $item['item_id']] + ); + } + foreach ($demo_items as $item) { $table_id_field_dict = [ 'tconfig_os' => 'id_os', @@ -2659,7 +2673,6 @@ if ($action === 'cleanup_demo_data') { 'tagente_modulo' => 'id_agente_modulo', 'tmodule_inventory' => 'id_module_inventory', 'tagent_module_inventory' => 'id_agent_module_inventory', - 'tagente_datos_inventory' => 'id_agent_module_inventory', 'tgraph' => 'id_graph', 'tmap' => 'id', 'treport' => 'id_report', @@ -2667,7 +2680,6 @@ if ($action === 'cleanup_demo_data') { 'tservice' => 'id', 'tservice_element' => 'id', 'ttrap' => 'id_trap', - 'tagente_datos' => 'id_agente_modulo', 'titem' => 'id', 'tgraph_source' => 'id_gs', 'twidget_dashboard' => 'id', @@ -2676,6 +2688,7 @@ if ($action === 'cleanup_demo_data') { 'tlayout_data' => 'id', 'tagente_estado' => 'id_agente_estado', 'trel_item' => 'id', + 'tplugin' => 'id', ]; $table_id_field = $table_id_field_dict[$item['table_name']]; From 93e79b51ebaf99c70d898d26d05602f3bad0fd0a Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Wed, 29 Nov 2023 17:30:57 +0100 Subject: [PATCH 128/397] Changed traps chance --- pandora_console/extras/demodata/agents/5-cisco.prd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/extras/demodata/agents/5-cisco.prd b/pandora_console/extras/demodata/agents/5-cisco.prd index 58febab7fe..9acab7907b 100644 --- a/pandora_console/extras/demodata/agents/5-cisco.prd +++ b/pandora_console/extras/demodata/agents/5-cisco.prd @@ -270,24 +270,24 @@ group[37]="Networking" oid[1]=".1.3.6.1.4.1.9.9.41.1.2.3.1.2.0" value[1]="RANDOM;0;100" snmp_type[1]="6" -chance_percent[1]="5" +chance_percent[1]="30" oid[2]=".1.3.6.1.4.1.9.9.41.1.2.3.1.3.0" value[2]="RANDOM;0;100" snmp_type[2]="6" -chance_percent[2]="5" +chance_percent[2]="30" oid[3]=".1.3.6.1.4.1.9.9.41.1.2.3.1.4.0" value[3]="RANDOM;0;100" snmp_type[3]="6" -chance_percent[3]="5" +chance_percent[3]="30" oid[4]=".1.3.6.1.4.1.9.9.41.1.2.3.1.5.0" value[4]="RANDOM;0;100" snmp_type[4]="6" -chance_percent[4]="5" +chance_percent[4]="30" oid[5]=".1.3.6.1.4.1.9.9.41.1.2.3.1.6.0" value[5]="RANDOM;0;100" snmp_type[5]="6" -chance_percent[5]="5" \ No newline at end of file +chance_percent[5]="30" \ No newline at end of file From 50ab2841e708eca66edb9ec7e176a73acf77447b Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Wed, 29 Nov 2023 18:02:33 +0100 Subject: [PATCH 129/397] Removed some elements from network map PRD --- .../demodata/network_maps/1-networkmap.prd | 47 +------------------ 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/pandora_console/extras/demodata/network_maps/1-networkmap.prd b/pandora_console/extras/demodata/network_maps/1-networkmap.prd index f780eb0977..1bfe9bb207 100644 --- a/pandora_console/extras/demodata/network_maps/1-networkmap.prd +++ b/pandora_console/extras/demodata/network_maps/1-networkmap.prd @@ -49,49 +49,4 @@ parent[8]="5" agent_name[9]="linux-4" x[9]="226" y[9]="595" -parent[9]="5" - -agent_name[10]="cisco-2" -x[10]="1036" -y[10]="711" -parent[10]="1" - -agent_name[11]="freebsd-2" -x[11]="892" -y[11]="-47" -parent[11]="1" - -agent_name[12]="macos-2" -x[12]="1150" -y[12]="409" -parent[12]="1" - -agent_name[13]="windows-3" -x[13]="686" -y[13]="875" -parent[13]="10" - -agent_name[14]="windows-4" -x[14]="1452" -y[14]="847" -parent[14]="10" - -agent_name[15]="linux-5" -x[15]="314" -y[15]="845" -parent[15]="13" - -agent_name[16]="linux-6" -x[16]="474" -y[16]="1043" -parent[16]="13" - -agent_name[17]="linux-7" -x[17]="1812" -y[17]="1011" -parent[17]="14" - -agent_name[18]="linux-8" -x[18]="1828" -y[18]="723" -parent[18]="14" \ No newline at end of file +parent[9]="5" \ No newline at end of file From ca17eef68a62c63f8f984494e7dbc88aca151aa6 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 29 Nov 2023 18:09:32 +0100 Subject: [PATCH 130/397] implement load demo data --- .../include/ajax/demo_data.ajax.php | 102 +++++++++++++----- .../include/class/WelcomeWindow.class.php | 2 +- 2 files changed, 76 insertions(+), 28 deletions(-) diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 6b5f96c325..bbc8258f34 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -84,8 +84,10 @@ if ($action === 'create_demo_data') { } else { $enabled_directories = $directories; + // Set default values when advanced mode is disabled. $service_agent_name = 'demo-global-agent-1'; $plugin_agent_name = 'demo-global-agent-1'; + $days_hist_data = 15; } if (enterprise_installed() === false) { @@ -411,7 +413,9 @@ if ($action === 'create_demo_data') { $current_date_time = $date_time->format('Y-m-d H:i:s'); $back_periods = 1; - if ($adv_options_is_enabled === true && $history_is_enabled === true) { + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); } @@ -491,7 +495,9 @@ if ($action === 'create_demo_data') { } } - if ($adv_options_is_enabled === true && $history_is_enabled === true) { + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { $utimestamp -= $interval; } } @@ -655,7 +661,9 @@ if ($action === 'create_demo_data') { $current_date_time = $date_time->format('Y-m-d H:i:s'); $back_periods = 1; - if ($adv_options_is_enabled === true && $history_is_enabled === true) { + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { $back_periods = round(($days_hist_data * SECONDS_1DAY) / $interval); } @@ -754,7 +762,9 @@ if ($action === 'create_demo_data') { } } - if ($adv_options_is_enabled === true && $history_is_enabled === true) { + if ($adv_options_is_enabled === false + || ($adv_options_is_enabled === true && $history_is_enabled === true) + ) { $date_time->sub(new DateInterval("PT{$interval}S")); $current_date_time = $date_time->format('Y-m-d H:i:s'); $utimestamp -= $interval; @@ -1714,7 +1724,7 @@ if ($action === 'create_demo_data') { $item_values = []; $item_values['id_report'] = $created_report_id; - $item_values['name'] = $items_array['name']; + $item_values['name'] = io_safe_input($items_array['name']); $item_values['type'] = $items_array['type']; if (isset($items_array['agent_name']) === true) { @@ -1814,6 +1824,43 @@ if ($action === 'create_demo_data') { continue; } + + if ($items_array['type'] === 'SLA') { + $sla_values = [ + 'id_report_content' => $created_report_item_id, + 'id_agent_module' => $item_values['id_agent_module'], + ]; + + $created_report_content_sla_id = db_process_sql_insert('treport_content_sla_combined', $sla_values); + + if ($created_report_content_sla_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_report_content_sla_id, + 'table_name' => 'treport_content_sla_combined', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback report item if could not be registered in tdemo_data. + db_process_sql_delete('treport_content_sla_combined', ['id' => $created_report_content_sla_id]); + + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_REPORT, + __('Uncaught error (source %s): could not create custom report item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } } else { register_error( DEMO_REPORT, @@ -2667,28 +2714,29 @@ if ($action === 'cleanup_demo_data') { foreach ($demo_items as $item) { $table_id_field_dict = [ - 'tconfig_os' => 'id_os', - 'tagente' => 'id_agente', - 'tgrupo' => 'id_grupo', - 'tagente_modulo' => 'id_agente_modulo', - 'tmodule_inventory' => 'id_module_inventory', - 'tagent_module_inventory' => 'id_agent_module_inventory', - 'tgraph' => 'id_graph', - 'tmap' => 'id', - 'treport' => 'id_report', - 'treport_content' => 'id_rc', - 'tservice' => 'id', - 'tservice_element' => 'id', - 'ttrap' => 'id_trap', - 'titem' => 'id', - 'tgraph_source' => 'id_gs', - 'twidget_dashboard' => 'id', - 'tdashboard' => 'id', - 'tlayout' => 'id', - 'tlayout_data' => 'id', - 'tagente_estado' => 'id_agente_estado', - 'trel_item' => 'id', - 'tplugin' => 'id', + 'tconfig_os' => 'id_os', + 'tagente' => 'id_agente', + 'tgrupo' => 'id_grupo', + 'tagente_modulo' => 'id_agente_modulo', + 'tmodule_inventory' => 'id_module_inventory', + 'tagent_module_inventory' => 'id_agent_module_inventory', + 'tgraph' => 'id_graph', + 'tmap' => 'id', + 'treport' => 'id_report', + 'treport_content' => 'id_rc', + 'treport_content_sla_combined' => 'id', + 'tservice' => 'id', + 'tservice_element' => 'id', + 'ttrap' => 'id_trap', + 'titem' => 'id', + 'tgraph_source' => 'id_gs', + 'twidget_dashboard' => 'id', + 'tdashboard' => 'id', + 'tlayout' => 'id', + 'tlayout_data' => 'id', + 'tagente_estado' => 'id_agente_estado', + 'trel_item' => 'id', + 'tplugin' => 'id', ]; $table_id_field = $table_id_field_dict[$item['table_name']]; diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index c0800e8b4c..b51e753048 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -1158,7 +1158,7 @@ class WelcomeWindow extends Wizard // Task to do actions. function loadDemoDataPage() { - window.location = ''; + window.location = ''; } function openCreateModulesDialog() { From dc2ac2a1b355a01480f96fa933864449ab0c2d65 Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Wed, 29 Nov 2023 18:13:56 +0100 Subject: [PATCH 131/397] implement load demo data --- pandora_console/include/ajax/demo_data.ajax.php | 1 + 1 file changed, 1 insertion(+) diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index bbc8258f34..41e40e4604 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -87,6 +87,7 @@ if ($action === 'create_demo_data') { // Set default values when advanced mode is disabled. $service_agent_name = 'demo-global-agent-1'; $plugin_agent_name = 'demo-global-agent-1'; + $interval = 300; $days_hist_data = 15; } From 76327c6d737be80d2c7411b66d61ca2e5fc7cf9a Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 30 Nov 2023 08:54:21 +0100 Subject: [PATCH 132/397] Fixed demo graphs generation --- .../visual_consoles/1-linux-visual-console.prd | 6 +++--- .../include/ajax/demo_data.ajax.php | 18 ++++++++---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd b/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd index e56a93d350..299d2296ed 100644 --- a/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd +++ b/pandora_console/extras/demodata/visual_consoles/1-linux-visual-console.prd @@ -114,7 +114,7 @@ type[11]="module_graph" image[11]="black" agent_name[11]="linux-1" module[11]="CPU Load" -interval[11]="86N00" +interval[11]="86400" graph_type[11]="area" label[11]="" label_position[11]="down" @@ -127,7 +127,7 @@ type[12]="module_graph" image[12]="black" agent_name[12]="linux-1" module[12]="Memory Usage" -interval[12]="86N00" +interval[12]="86400" graph_type[12]="area" label[12]="" label_position[12]="down" @@ -140,7 +140,7 @@ type[13]="module_graph" image[13]="black" agent_name[13]="linux-1" module[13]="Disk Usage" -interval[13]="86N00" +interval[13]="86400" graph_type[13]="area" label[13]="" label_position[13]="down" diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 41e40e4604..2cbac20e99 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -2113,19 +2113,13 @@ if ($action === 'create_demo_data') { if (isset($items_array['graph_type']) === true) { $element_values['type_graph'] = $items_array['graph_type']; } + + if (isset($items_array['image']) === true) { + $element_values['image'] = $items_array['image']; + } } if ($items_array['type'] === 'custom_graph') { - if (isset($items_array['image']) === false - || is_string($items_array['image']) === false - ) { - // The above fields are required for this item. - register_error( - DEMO_VISUAL_CONSOLE, - __('Error in %s: image field must be specified for custom_graph item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) - ); - continue; - } if (isset($items_array['graph_name']) === true && is_string($items_array['graph_name']) === true @@ -2142,6 +2136,10 @@ if ($action === 'create_demo_data') { if (isset($items_array['interval']) === true) { $element_values['period'] = $items_array['interval']; } + + if (isset($items_array['image']) === true) { + $element_values['image'] = $items_array['image']; + } } if ($items_array['type'] === 'icon') { From 817811ffac2ce997e93fdfc16f225bec7c7b2d1c Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 30 Nov 2023 10:13:18 +0100 Subject: [PATCH 133/397] fix error update manager pandora_enterprise#12447 --- pandora_console/include/functions_menu.php | 3 ++- .../update_manager_client/lib/UpdateManager/Client.php | 7 ------- .../resources/javascript/umc_offline.js | 1 - 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/functions_menu.php b/pandora_console/include/functions_menu.php index 1df84f6025..3b4c092680 100644 --- a/pandora_console/include/functions_menu.php +++ b/pandora_console/include/functions_menu.php @@ -983,7 +983,8 @@ if (is_ajax()) {

    '.$product_name.'

    '.__('Version').' '.$pandora_version.$lts_name.' - '.(enterprise_installed() ? 'Enterprise' : 'Community').'

    -

    '.__('MR version').' MR'.$config['MR'].'

    +

    '.__('Current package').' '.$config['current_package'].'

    +

    '.__('MR version').' MR'.$config['MR'].'

    Build'.$build_version.'

    '; if (enterprise_installed() === true) { $dialog .= '

    '.__('Support expires').''.$license_expiry_date.'

    '; diff --git a/pandora_console/update_manager_client/lib/UpdateManager/Client.php b/pandora_console/update_manager_client/lib/UpdateManager/Client.php index a0ca625009..8abe5f2f83 100644 --- a/pandora_console/update_manager_client/lib/UpdateManager/Client.php +++ b/pandora_console/update_manager_client/lib/UpdateManager/Client.php @@ -1829,13 +1829,6 @@ class Client } } else { // Manually uploaded package. - if (is_numeric($package['version']) !== true) { - $this->lastError = 'Version does not match required format (numeric)'; - $this->notify(10, $this->lastError, false); - $this->unlock(); - return false; - } - $classic_open_packages = false; $nextUpdate = [ 'version' => $package['version'] ]; $file_path = $package['file_path']; diff --git a/pandora_console/update_manager_client/resources/javascript/umc_offline.js b/pandora_console/update_manager_client/resources/javascript/umc_offline.js index a32dfc1e5c..ad2432a306 100644 --- a/pandora_console/update_manager_client/resources/javascript/umc_offline.js +++ b/pandora_console/update_manager_client/resources/javascript/umc_offline.js @@ -487,7 +487,6 @@ function updateOfflineProgress(url, auth) { * Cancel update. */ function cancelUpdate(reason = "") { - console.error(reason); var taskStatusLogContainer = $("#result li"); taskStatusLogContainer.addClass("error"); taskStatusLogContainer.find("p").text(texts.rejectedUpdate + " " + reason); From d5c24609d61f7cc38f2b5a8b28db8580a918e4c6 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 30 Nov 2023 11:21:54 +0100 Subject: [PATCH 134/397] add tables merge process pandora_enterprise#12352 --- pandora_console/extras/mr/68.sql | 40 +++++++++++++++++++++++++++++ pandora_console/pandoradb.sql | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 pandora_console/extras/mr/68.sql diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql new file mode 100644 index 0000000000..999d8e6c3c --- /dev/null +++ b/pandora_console/extras/mr/68.sql @@ -0,0 +1,40 @@ +START TRANSACTION; + +DROP TABLE IF EXISTS `tmerge_error`; +CREATE TABLE IF NOT EXISTS `tmerge_error` ( + `id` int(10) NOT NULL auto_increment, + `id_node` int(10) default 0, + `phase` int(10) default 0, + `step` int(10) default 0, + `msg` LONGTEXT default "", + `action` text default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +DROP TABLE IF EXISTS `tmerge_steps`; +CREATE TABLE IF NOT EXISTS `tmerge_steps` ( + `id` int(10) NOT NULL auto_increment, + `id_node` int(10) default 0, + `phase` int(10) default 0, + `total` int(10) default 0, + `step` int(10) default 0, + `debug` varchar(1024) default "", + `action` varchar(100) default "", + `affected` varchar(100) default "", + `query` mediumtext default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +DROP TABLE IF EXISTS `tmerge_queries`; +CREATE TABLE IF NOT EXISTS `tmerge_queries` ( + `steps` int(10) NOT NULL auto_increment, + `action` varchar(100) default "", + `affected` varchar(100) default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + `query` LONGTEXT NOT NULL default "", + PRIMARY KEY (`steps`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +COMMIT; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index b98f706667..78a7833861 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -4534,4 +4534,47 @@ CREATE TABLE IF NOT EXISTS `tpandora_cve` ( `cvss_score` DOUBLE DEFAULT NULL, `cvss_vector` VARCHAR(255) DEFAULT NULL, PRIMARY KEY (`cve_id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- --------------------------------------------------------------------- +-- Table `tmerge_error` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tmerge_error` ( + `id` int(10) NOT NULL auto_increment, + `id_node` int(10) default 0, + `phase` int(10) default 0, + `step` int(10) default 0, + `msg` LONGTEXT default "", + `action` text default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- --------------------------------------------------------------------- +-- Table `tmerge_steps` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tmerge_steps` ( + `id` int(10) NOT NULL auto_increment, + `id_node` int(10) default 0, + `phase` int(10) default 0, + `total` int(10) default 0, + `step` int(10) default 0, + `debug` varchar(1024) default "", + `action` varchar(100) default "", + `affected` varchar(100) default "", + `query` mediumtext default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; + +-- --------------------------------------------------------------------- +-- Table `tmerge_queries` +-- --------------------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `tmerge_queries` ( + `steps` int(10) NOT NULL auto_increment, + `action` varchar(100) default "", + `affected` varchar(100) default "", + `utimestamp` int(20) unsigned NOT NULL default 0, + `query` LONGTEXT NOT NULL default "", + PRIMARY KEY (`steps`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; \ No newline at end of file From 6154ce725bbe25a4487a8182183b944c0ed357cd Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Thu, 30 Nov 2023 13:18:44 +0100 Subject: [PATCH 135/397] #12501 Fixed password field --- pandora_console/godmode/agentes/agent_manager.php | 11 +++-------- pandora_console/godmode/agentes/configure_field.php | 6 ++++++ pandora_console/include/styles/pandora.css | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pandora_console/godmode/agentes/agent_manager.php b/pandora_console/godmode/agentes/agent_manager.php index 557b855e09..e469c3f155 100644 --- a/pandora_console/godmode/agentes/agent_manager.php +++ b/pandora_console/godmode/agentes/agent_manager.php @@ -986,17 +986,12 @@ foreach ($fields as $field) { } if ((bool) $field['is_password_type'] === true) { - $customContent = html_print_input_text_extended( + $customContent = html_print_input_password( 'customvalue_'.$field['id_field'], $custom_value, - 'customvalue_'.$field['id_field'], '', - 30, - 100, - $view_mode, - '', - '', - true, + 45, + 255, true ); } else if ($field['is_link_enabled']) { diff --git a/pandora_console/godmode/agentes/configure_field.php b/pandora_console/godmode/agentes/configure_field.php index 839040cb00..904b807bbd 100755 --- a/pandora_console/godmode/agentes/configure_field.php +++ b/pandora_console/godmode/agentes/configure_field.php @@ -275,21 +275,27 @@ $(document).ready (function () { $('#configure_field-3').show(); dialog_message("#message_no_set_password"); $('#configure_field-1').hide(); + $('#configure_field-2-0').hide(); } else{ $('#configure_field-3').hide(); $('#configure_field-1').show(); + $('#configure_field-2-0').show(); } }); $('input[type=checkbox][name=is_password_type]').change(function () { if( $('input[type=checkbox][name=is_password_type]').prop('checked')){ + $('#configure_field-1').hide(); dialog_message("#message_no_set_combo"); $('#configure_field-3').hide(); + $('#configure_field-2-1').hide(); } else{ if($('input[type=checkbox][name=is_combo_enable]').prop('checked') === true) { $('#configure_field-3').show(); } + $('#configure_field-1').show(); + $('#configure_field-2-1').show(); } }); }); diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 384048fa00..75dbb9a6ae 100644 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -11810,7 +11810,7 @@ p.trademark-copyright { } .show-hide-pass { - position: fixed; + position: absolute; border: 0; outline: none; margin-left: -50px; From 1e4c5563d3dfa37369c65a363e780ac2eda92d7a Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 30 Nov 2023 14:44:27 +0100 Subject: [PATCH 136/397] #12416 fixed encryption_passphrase in metaconsole --- pandora_console/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/index.php b/pandora_console/index.php index 4ca8f80a82..27f84d53fb 100755 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -1234,7 +1234,7 @@ if (has_metaconsole() === true [ 'dbhost' => $config['replication_dbhost'], 'dbuser' => $config['replication_dbuser'], - 'dbpass' => io_output_password($config['replication_dbpass']), + 'dbpass' => $config['replication_dbpass'], 'dbname' => $config['replication_dbname'], ] ); From 741c8d40b30a7e952c2c640be383f4c3b99b6b86 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Thu, 30 Nov 2023 15:24:34 +0100 Subject: [PATCH 137/397] #12530 Validation is added to the SLA report, the data of the SLA report item is not painted if the agent is not informed --- pandora_console/include/functions_reporting_html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/include/functions_reporting_html.php b/pandora_console/include/functions_reporting_html.php index 6699d2c74d..0f9ae0f68c 100644 --- a/pandora_console/include/functions_reporting_html.php +++ b/pandora_console/include/functions_reporting_html.php @@ -1275,7 +1275,7 @@ function reporting_html_SLA($table, $item, $mini, $pdf=0) $table3->headstyle[5] = 'text-align: right'; foreach ($item['data'] as $sla) { - if (isset($sla) === true) { + if (isset($sla) === true && empty($sla['agent']) === false) { // First_table. $row = []; $row[] = $sla['agent']; From 24c8e606f48751d24ff8832d7ec16eb9bd232cbd Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Thu, 30 Nov 2023 16:29:18 +0100 Subject: [PATCH 138/397] #12569 fixed button credential boxes --- pandora_console/godmode/servers/modificar_server.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/godmode/servers/modificar_server.php b/pandora_console/godmode/servers/modificar_server.php index c51c0476d3..03863fb4f5 100644 --- a/pandora_console/godmode/servers/modificar_server.php +++ b/pandora_console/godmode/servers/modificar_server.php @@ -521,7 +521,7 @@ $(document).ready (function () { function (data) { $(".white-box-content").html(data); - $("#submit-add").click(function (e) { + $("#button-add").click(function (e) { add_credential_boxes(); }); @@ -550,7 +550,7 @@ $(document).ready (function () { $(".white-box-content").html(data2); // Insert credential - $("#submit-add").click(function (e) { + $("#button-add").click(function (e) { save_credential_boxes(); }) }, From 3807baa8ef46ac4ea4a8a146e3a0419360ffd87f Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 30 Nov 2023 17:41:01 +0100 Subject: [PATCH 139/397] Added GIS random data to agents --- .../extras/demodata/agents/0-demo-agent.prd | 4 + .../extras/demodata/agents/1-linux.prd | 4 + .../extras/demodata/agents/2-windows.prd | 4 + .../extras/demodata/agents/3-macosx.prd | 4 + .../extras/demodata/agents/4-freebsd.prd | 4 + .../extras/demodata/agents/5-cisco.prd | 4 + .../demodata/network_maps/1-networkmap.prd | 92 ++++++++++++++++++- .../include/ajax/demo_data.ajax.php | 59 ++++++++++++ 8 files changed, 174 insertions(+), 1 deletion(-) diff --git a/pandora_console/extras/demodata/agents/0-demo-agent.prd b/pandora_console/extras/demodata/agents/0-demo-agent.prd index af1fa72a66..1a45fb939c 100644 --- a/pandora_console/extras/demodata/agents/0-demo-agent.prd +++ b/pandora_console/extras/demodata/agents/0-demo-agent.prd @@ -18,6 +18,10 @@ os_versions[]="RHEL 8.2" os_versions[]="RHEL 8.1" os_versions[]="Alma Linux 9.1" +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + [modules] name[1]="Host Alive" diff --git a/pandora_console/extras/demodata/agents/1-linux.prd b/pandora_console/extras/demodata/agents/1-linux.prd index 5cd29b117e..35d76f3f79 100644 --- a/pandora_console/extras/demodata/agents/1-linux.prd +++ b/pandora_console/extras/demodata/agents/1-linux.prd @@ -18,6 +18,10 @@ os_versions[]="RHEL 8.2" os_versions[]="RHEL 8.1" os_versions[]="Alma Linux 9.1" +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + [modules] name[1]="Network Usage" diff --git a/pandora_console/extras/demodata/agents/2-windows.prd b/pandora_console/extras/demodata/agents/2-windows.prd index 1d1d6c782c..921abeb7dc 100644 --- a/pandora_console/extras/demodata/agents/2-windows.prd +++ b/pandora_console/extras/demodata/agents/2-windows.prd @@ -17,6 +17,10 @@ os_versions[]="Home Microsoft Windows 10 Pro" os_versions[]="Microsoft Windows 10 Home" os_versions[]="Microsoft Windows 2018" +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + [modules] name[1]="Network Usage" diff --git a/pandora_console/extras/demodata/agents/3-macosx.prd b/pandora_console/extras/demodata/agents/3-macosx.prd index ba8d75de87..0bbf20edbb 100644 --- a/pandora_console/extras/demodata/agents/3-macosx.prd +++ b/pandora_console/extras/demodata/agents/3-macosx.prd @@ -17,6 +17,10 @@ os_versions[]="11.2" os_versions[]="11.3" os_versions[]="10.3" +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + [modules] name[1]="Network Usage" diff --git a/pandora_console/extras/demodata/agents/4-freebsd.prd b/pandora_console/extras/demodata/agents/4-freebsd.prd index 956a501660..c3d9d3eba2 100644 --- a/pandora_console/extras/demodata/agents/4-freebsd.prd +++ b/pandora_console/extras/demodata/agents/4-freebsd.prd @@ -16,6 +16,10 @@ os_versions[]="13.1" os_versions[]="13.2" os_versions[]="13.3" +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + [modules] name[1]="Network Usage" diff --git a/pandora_console/extras/demodata/agents/5-cisco.prd b/pandora_console/extras/demodata/agents/5-cisco.prd index 9acab7907b..1c8e3ff0a1 100644 --- a/pandora_console/extras/demodata/agents/5-cisco.prd +++ b/pandora_console/extras/demodata/agents/5-cisco.prd @@ -16,6 +16,10 @@ os_versions[]="C9200L" os_versions[]="C9300LM" os_versions[]="C9600" +latitude="RANDOM;37;42" +longitude="RANDOM;-8;-1" +altitude="0" + [modules] name[1]="CPU Usage (5 min avg)" diff --git a/pandora_console/extras/demodata/network_maps/1-networkmap.prd b/pandora_console/extras/demodata/network_maps/1-networkmap.prd index 1bfe9bb207..7ef0db5db8 100644 --- a/pandora_console/extras/demodata/network_maps/1-networkmap.prd +++ b/pandora_console/extras/demodata/network_maps/1-networkmap.prd @@ -49,4 +49,94 @@ parent[8]="5" agent_name[9]="linux-4" x[9]="226" y[9]="595" -parent[9]="5" \ No newline at end of file +parent[9]="5" + +agent_name[10]="cisco-2" +x[10]="1036" +y[10]="711" +parent[10]="1" + +agent_name[11]="freebsd-2" +x[11]="892" +y[11]="-47" +parent[11]="1" + +agent_name[12]="macos-2" +x[12]="1150" +y[12]="409" +parent[12]="1" + +agent_name[13]="windows-3" +x[13]="686" +y[13]="875" +parent[13]="10" + +agent_name[14]="windows-4" +x[14]="1452" +y[14]="847" +parent[14]="10" + +agent_name[15]="linux-5" +x[15]="314" +y[15]="845" +parent[15]="13" + +agent_name[16]="linux-6" +x[16]="474" +y[16]="1043" +parent[16]="13" + +agent_name[17]="linux-7" +x[17]="1812" +y[17]="1011" +parent[17]="14" + +agent_name[18]="linux-8" +x[18]="1828" +y[18]="723" +parent[18]="14" + +agent_name[19]="cisco-3" +x[19]="1824" +y[19]="285" +parent[19]="3" + +agent_name[20]="freebsd-3" +x[20]="-82" +y[20]="583" +parent[20]="9" + +agent_name[21]="macos-3" +x[21]="-140" +y[21]="299" +parent[21]="20" + +agent_name[22]="windows-5" +x[22]="-390" +y[22]="385" +parent[22]="20" + +agent_name[23]="windows-6" +x[23]="-470" +y[23]="671" +parent[23]="20" + +agent_name[24]="linux-9" +x[24]="-296" +y[24]="899" +parent[24]="20" + +agent_name[25]="linux-10" +x[25]="-25" +y[25]="961" +parent[25]="20" + +agent_name[26]="linux-11" +x[26]="1683" +y[26]="13" +parent[26]="19" + +agent_name[27]="linux-12" +x[27]="2135" +y[27]="51" +parent[27]="19" \ No newline at end of file diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 2cbac20e99..77b1fedef1 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -264,6 +264,37 @@ if ($action === 'create_demo_data') { reset($os_versions); } + $latitude = 0; + $longitude = 0; + $altitude = 0; + + if (isset($agent_data['latitude']) === true) { + $gis_parsed = explode(';', $agent_data['latitude']); + if ((string) $gis_parsed[0] === 'RANDOM') { + $latitude = rand($gis_parsed[1], $gis_parsed[2]); + } else { + $latitude = $agent_data['latitude']; + } + } + + if (isset($agent_data['longitude']) === true) { + $gis_parsed = explode(';', $agent_data['longitude']); + if ((string) $gis_parsed[0] === 'RANDOM') { + $longitude = rand($gis_parsed[1], $gis_parsed[2]); + } else { + $longitude = $agent_data['longitude']; + } + } + + if (isset($agent_data['altitude']) === true) { + $gis_parsed = explode(';', $agent_data['altitude']); + if ((string) $gis_parsed[0] === 'RANDOM') { + $altitude = rand($gis_parsed[1], $gis_parsed[2]); + } else { + $altitude = $agent_data['altitude']; + } + } + $values = [ 'server_name' => $server_name, 'id_os' => $id_os, @@ -310,6 +341,34 @@ if ($action === 'create_demo_data') { continue; } + // Register GIS data + $values = [ + 'tagente_id_agente' => $created_agent_id, + 'current_longitude' => $longitude, + 'current_latitude' => $latitude, + 'current_altitude' => $altitude, + 'stored_longitude' => $longitude, + 'stored_latitude' => $latitude, + 'stored_altitude' => $altitude, + 'number_of_packages' => 1, + 'manual_placement' => 1, + ]; + $result = db_process_sql_insert('tgis_data_status', $values); + + if ($result !== false) { + $values = [ + 'item_id' => $created_agent_id, + 'table_name' => 'tgis_data_status', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback GIS data creation if could not be registered in tdemo_data. + db_process_sql_delete('tgis_data_status', ['tagente_id_agente' => $created_agent_id]); + } + } + + $agents_created_count[$agent_data['agent_alias']]++; $iter_agents_created++; From 9da2ad8682b69f929e97dfdb27ce2017d79ff25c Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 1 Dec 2023 09:26:48 +0100 Subject: [PATCH 140/397] add tables merge process pandora_enterprise#12352 --- pandora_console/extras/mr/68.sql | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora_console/extras/mr/68.sql b/pandora_console/extras/mr/68.sql index 999d8e6c3c..c0e5788091 100644 --- a/pandora_console/extras/mr/68.sql +++ b/pandora_console/extras/mr/68.sql @@ -1,6 +1,5 @@ START TRANSACTION; -DROP TABLE IF EXISTS `tmerge_error`; CREATE TABLE IF NOT EXISTS `tmerge_error` ( `id` int(10) NOT NULL auto_increment, `id_node` int(10) default 0, @@ -12,7 +11,8 @@ CREATE TABLE IF NOT EXISTS `tmerge_error` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -DROP TABLE IF EXISTS `tmerge_steps`; +ALTER TABLE `tmerge_error` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; + CREATE TABLE IF NOT EXISTS `tmerge_steps` ( `id` int(10) NOT NULL auto_increment, `id_node` int(10) default 0, @@ -27,7 +27,8 @@ CREATE TABLE IF NOT EXISTS `tmerge_steps` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; -DROP TABLE IF EXISTS `tmerge_queries`; +ALTER TABLE `tmerge_steps` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; + CREATE TABLE IF NOT EXISTS `tmerge_queries` ( `steps` int(10) NOT NULL auto_increment, `action` varchar(100) default "", @@ -37,4 +38,6 @@ CREATE TABLE IF NOT EXISTS `tmerge_queries` ( PRIMARY KEY (`steps`) ) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4; +ALTER TABLE `tmerge_queries` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci; + COMMIT; From d6e107ea95303eff08173d25a0b1321b7c8965ff Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Fri, 1 Dec 2023 09:48:45 +0100 Subject: [PATCH 141/397] performance improvement --- .../include/ajax/demo_data.ajax.php | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 41e40e4604..f8582a0075 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -114,7 +114,6 @@ if ($action === 'create_demo_data') { } $total_agents_to_create = (int) get_parameter('agents_num', 0); - $total_items_count = count($parsed_ini); if ($total_agents_to_create > 0) { @@ -134,6 +133,7 @@ if ($action === 'create_demo_data') { } $agent_created_total = 0; + $agent_data_values_buffer = []; if ($total_agents_to_create > 0 && $agents_to_create > 0) { while ($agent_created_total < ($total_agents_to_create - 1)) { @@ -311,7 +311,7 @@ if ($action === 'create_demo_data') { } $agents_created_count[$agent_data['agent_alias']]++; - + $iter_agents_created++; // Create agent modules. @@ -439,6 +439,8 @@ if ($action === 'create_demo_data') { if ($randomNumber <= $probability) { // Set to 0 with a certain probability. $data = 0; + + // Set to critical status if 0. $new_status = 1; } } @@ -450,13 +452,15 @@ if ($action === 'create_demo_data') { 'utimestamp' => $utimestamp, ]; - $created_data_res = db_process_sql_insert('tagente_datos', $agent_data_values); - - if ($created_data_res === false) { - continue; - } - if ($p === 0) { + // Insert current module data right away so module status is initialized with such value. + $created_data_res = db_process_sql_insert('tagente_datos', $agent_data_values); + + if ($created_data_res === false) { + continue; + } + + // Proceed to update module status. $status_values = [ 'datos' => $data, 'estado' => $new_status, @@ -494,6 +498,9 @@ if ($action === 'create_demo_data') { db_process_sql_delete('tagente_estado', ['id_agente_estado' => $status_id]); } } + } else { + // Buffer history data for later bulk insertion (performance reasons). + $agent_data_values_buffer[] = $agent_data_values; } if ($adv_options_is_enabled === false @@ -784,6 +791,17 @@ if ($action === 'create_demo_data') { } } + $agent_data_values_buffer_chunks = array_chunk($agent_data_values_buffer, 1000); + + foreach ($agent_data_values_buffer_chunks as $chunk) { + // Bulk inserts. + mysql_db_process_sql_insert_multiple( + 'tagente_datos', + $chunk, + false + ); + } + update_item_checked(DEMO_AGENT); } } From 87f4a6e15fc66c6840afc1d1867f27df6e1158e7 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Fri, 1 Dec 2023 10:08:25 +0100 Subject: [PATCH 142/397] #12384 Fixed acl --- .../javascript/functions_pandora_networkmap.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandora_console/include/javascript/functions_pandora_networkmap.js b/pandora_console/include/javascript/functions_pandora_networkmap.js index c31216a2fc..44e3ba196c 100644 --- a/pandora_console/include/javascript/functions_pandora_networkmap.js +++ b/pandora_console/include/javascript/functions_pandora_networkmap.js @@ -806,6 +806,10 @@ function edit_node(data_node, dblClick) { var flag_edit_node = true; var edit_node = null; + if (networkmap_write === 0) { + return false; + } + //Only select one node var selection = d3_nm.selectAll(".node_selected"); var id; @@ -1950,6 +1954,10 @@ function init_minimap() { // Context menu //////////////////////////////////////////////////////////////////////// function show_menu(item, data) { + if (networkmap_write === 0) { + return false; + } + mouse = []; mouse[0] = d3_nm.event.pageX; mouse[1] = d3_nm.event.pageY; @@ -2819,6 +2827,10 @@ function cancel_set_parent() { // OWN CODE FOR TO DRAG //////////////////////////////////////////////////////////////////////// function init_drag_and_drop() { + if (networkmap_write === 0) { + return false; + } + window.dragables = svg.selectAll(".dragable_node"); window.drag_start = [0, 0]; From 5191739658e4dd3849d8090524a10697263f798a Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Fri, 1 Dec 2023 12:05:42 +0100 Subject: [PATCH 143/397] #12542 fixed local component module group --- pandora_console/include/javascript/pandora_modules.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/javascript/pandora_modules.js b/pandora_console/include/javascript/pandora_modules.js index 4e2f73db28..a126bc36f5 100644 --- a/pandora_console/include/javascript/pandora_modules.js +++ b/pandora_console/include/javascript/pandora_modules.js @@ -159,7 +159,9 @@ function configure_modules_form() { period_select_update("module_interval", data["module_interval"]); } - $("#id_module_group").val(data["id_module_group"]); + $("#id_module_group") + .val(data["id_module_group"]) + .trigger("change"); if (data["history_data"]) $("#checkbox-history_data").check(); else $("#checkbox-history_data").uncheck(); From 5609bc2313523fde08ced806a18b1746cbc637a1 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Fri, 1 Dec 2023 13:45:17 +0100 Subject: [PATCH 144/397] #12581 fixed strong size in visual console --- pandora_console/include/visual-console-client/vc.main.css | 3 +++ pandora_console/include/visual-console-client/vc.main.css.map | 2 +- visual_console_client/src/main.css | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/visual-console-client/vc.main.css b/pandora_console/include/visual-console-client/vc.main.css index 98d39f6cad..f146c0fc94 100644 --- a/pandora_console/include/visual-console-client/vc.main.css +++ b/pandora_console/include/visual-console-client/vc.main.css @@ -743,6 +743,9 @@ p { margin-block-end: 1em; } +strong { + font-size: inherit; +} /* Styles for the solid icons */ .fa { diff --git a/pandora_console/include/visual-console-client/vc.main.css.map b/pandora_console/include/visual-console-client/vc.main.css.map index b801994300..fcf332155e 100644 --- a/pandora_console/include/visual-console-client/vc.main.css.map +++ b/pandora_console/include/visual-console-client/vc.main.css.map @@ -1 +1 @@ -{"version":3,"file":"vc.main.css","mappings":"AAAA;EACE,gBAAgB;EAChB,kBAAkB;EAClB,4BAA4B;EAC5B,0BAA0B;EAC1B,2BAA2B;EAC3B,eAAe;AACjB;;AAEA;EACE,oEAA2D;AAC7D;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,kBAAkB;EAClB,aAAa;EACb,uBAAuB;EACvB,qBAAqB;EACrB,mBAAmB;EACnB,iBAAiB;EACjB,UAAU;AACZ;;AAEA;EACE,UAAU;AACZ;;AAEA;EACE,iBAAiB;EACjB,oBAAoB;EACpB,oBAAoB;EACpB,mCAAmC;EACnC,kCAAkC;EAClC,kCAAkC;AACpC;;AAEA;EACE,0BAA0B;EAC1B,4CAA4C;EAC5C,iBAAiB;AACnB;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,0BAA0B;EAC1B,YAAY;EACZ,WAAW;AACb;AACA;EACE,YAAY;EACZ,kBAAkB;EAClB,QAAQ;EACR,SAAS;EACT,WAAW;EACX,YAAY;EACZ,mDAAoC;EACpC,iBAAiB;EACjB,WAAW;AACb;;AAEA;EACE,oBAAoB;AACtB;;AAEA;EACE;IACE,uBAAuB;EACzB;EACA;IACE,wBAAwB;EAC1B;AACF;;AAEA;EACE,yBAAyB;AAC3B;;AAEA;EACE,6BAA6B;EAC7B,gBAAgB;EAChB,qCAAqC;EACrC,uCAAuC;EACvC,wCAAwC;EACxC,4CAA4C;;EAE5C,+BAA+B;EAC/B,wBAAwB;EACxB,mCAAmC;EACnC,iCAAiC;AACnC;;AAEA;;EAEE,cAAc;EACd,WAAW;EACX,YAAY;EACZ,kBAAkB;AACpB;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,YAAY;EACZ,8BAA8B;EAC9B,WAAW;AACb;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,aAAa;AACf;;AAEA,QAAQ;AACR;EACE,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,cAAc;EACd,kBAAkB;AACpB;AACA;EACE,gBAAgB;AAClB;;AAEA;;EAEE,YAAY;EACZ,eAAe;EACf,6BAA6B;EAC7B,YAAY;EACZ,gBAAgB;EAChB,6BAA6B;EAC7B,oBAAoB;EACpB,wBAAwB;EACxB,sBAAsB;EACtB,kBAAkB;EAClB,iBAAiB;AACnB;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,YAAY;AACd;;AAEA;EACE,oBAAoB;EACpB,eAAe;AACjB;;AAEA;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;AACjB;;AAEA;EACE,WAAW;EACX,mBAAmB;EACnB,kBAAkB;AACpB;;AAEA;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;EACf,uBAAuB;AACzB;;AAEA;EACE,kBAAkB;EAClB,gBAAgB;AAClB;;AAEA;;EAEE,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,mBAAmB;AACrB;;AAEA;EACE,uBAAuB;EACvB,kBAAkB;EAClB,kBAAkB;EAClB,0BAA0B;EAC1B,cAAc;AAChB;;AAEA;EACE,iBAAiB;AACnB;;AAEA;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;EACf,uBAAuB;EACvB,8BAA8B;EAC9B,YAAY;AACd;;AAEA;EACE,kBAAkB;AACpB;;AAEA;EACE,YAAY;AACd;;AAEA;EACE,iBAAiB;AACnB;;AAEA;EACE,iBAAiB;AACnB;;AAEA;;;EAGE,sBAAsB;AACxB;;AAEA;EACE,mBAAmB;AACrB;;AAEA;EACE,WAAW;EACX,WAAW;AACb;;AAEA;EACE,yBAAyB;AAC3B;;AAEA,+BAA+B;;AAE/B;EACE,qBAAqB;EACrB,SAAS;AACX;;AAEA;;;;EAIE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;EACE,qCAAqC;AACvC;;AAEA;EACE,uCAAuC;AACzC;;AAEA;EACE;IACE,uBAAuB;EACzB;EACA;IACE,yBAAyB;EAC3B;AACF;;AAEA;EACE,6CAA6C;EAC7C,kBAAkB;EAClB,qBAAqB;AACvB;AACA;EACE,oBAAoB;AACtB;AACA;EACE,yBAAyB;EACzB,mBAAmB;EACnB,gBAAgB;EAChB,yEAAyE;EACzE,kBAAkB;EAClB,UAAU;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;AAClB;AACA;EACE,WAAW;EACX,aAAa;EACb,eAAe;EACf,sBAAsB;EACtB,gCAAgC;EAChC,6BAA6B;AAC/B;AACA;EACE,WAAW;EACX,yBAAyB;AAC3B;AACA;EACE,0DAA0D;EAC1D,uCAAuC;EACvC,cAAc;AAChB;;AAEA,kBAAkB;;AAElB;EACE,oBAAoB;EACpB,oBAAoB;EACpB,aAAa;EACb,sBAAsB;EACtB,uBAAuB;EACvB,qBAAqB;EACrB,qBAAqB;EACrB,mBAAmB;AACrB;;AAEA;EACE,0BAA0B;EAC1B,kCAAkC;EAClC,wCAAwC;AAC1C;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA,iBAAiB;;AAEjB;EACE,kBAAkB;AACpB;;AAEA;EACE,6CAA6C;AAC/C;;AAEA;EACE,8CAA8C;AAChD;;AAEA;EACE,4CAA4C;AAC9C;;AAEA;EACE,yBAAyB;EACzB,WAAW;AACb;;AAEA;EACE,WAAW;EACX,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,8BAA8B;AAChC;;AAEA;EACE,kBAAkB;AACpB;;AAEA;EACE,8BAA8B;AAChC;;AAEA;;EAEE,kBAAkB;AACpB;;AAEA;;EAEE,WAAW;AACb;;AAEA;;;;EAIE,cAAc;EACd,iBAAiB;AACnB;;AAEA;EACE,aAAa;EACb,mBAAmB;EACnB,yBAAyB;AAC3B;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,mBAAmB;EACnB,cAAc;AAChB;;AAEA;EACE,YAAY;AACd;;AAEA;;;;;;EAME,6BAA6B;AAC/B;AACA;;EAEE,gBAAgB;EAChB,cAAc;AAChB;;AAEA;;EAEE,aAAa;AACf;;AAEA;EACE,iBAAiB;AACnB;;AAEA;EACE,yBAAyB;AAC3B;;AAEA,kCAAkC;AAClC;EACE,aAAa;EACb,sBAAsB;EACtB,WAAW;EACX,YAAY;AACd;AACA;EACE,WAAW;EACX,WAAW;EACX,yBAAyB;EACzB,YAAY;EACZ,iBAAiB;EACjB,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,uBAAuB;AACzB;AACA;EACE,WAAW;EACX,WAAW;EACX,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,WAAW;EACX,mBAAmB;AACrB;;AAEA;EACE,aAAa;EACb,aAAa;EACb,mBAAmB;EACnB,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,UAAU;AACZ;;AAEA;EACE,OAAO;EACP,WAAW;EACX,eAAe;EACf,WAAW;EACX,WAAW;EACX,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,uBAAuB;AACzB;;AAEA;EACE,OAAO;EACP,uBAAuB;EACvB,YAAY;EACZ,eAAe;EACf,WAAW;EACX,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,uBAAuB;AACzB;;AAEA;;EAEE,sBAAsB;EACtB,uBAAuB;EACvB,aAAa;EACb,sBAAsB;EACtB,uBAAuB;AACzB;;AAEA;EACE,kCAAkC;AACpC;;AAEA;EACE,YAAY;AACd;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,mBAAmB;EACnB,uBAAuB;AACzB;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,qBAAqB;EACrB,uBAAuB;AACzB;;AAEA;EACE,WAAW;EACX,WAAW;EACX,aAAa;AACf;;AAEA;EACE,SAAS;EACT,UAAU;EACV,YAAY;EACZ,UAAU;EACV,aAAa;EACb,mBAAmB;EACnB,kBAAkB;EAClB,eAAe;AACjB;;AAEA;EACE,SAAS;EACT,UAAU;EACV,YAAY;EACZ,UAAU;EACV,aAAa;EACb,mBAAmB;EACnB,uBAAuB;EACvB,kBAAkB;AACpB;;AAEA;EACE,eAAe;EACf,sBAAsB;EACtB,4BAA4B;EAC5B,kBAAkB;AACpB;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,kBAAkB;EAClB,sBAAsB;EACtB,YAAY;EACZ,iBAAiB;EACjB,eAAe;AACjB;;AAEA;EACE,2BAA2B;AAC7B;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,gBAAgB;EAChB,kBAAkB;EAClB,aAAa;EACb,qBAAqB;AACvB;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,iBAAiB;EACjB,oCAAoC;EACpC,aAAa;EACb,mBAAmB;EACnB,yBAAyB;EACzB,sBAAsB;EACtB,gBAAgB;AAClB;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,oCAAoC;EACpC,4BAA4B;EAC5B,gCAAgC;EAChC,cAAc;EACd,gBAAgB;AAClB;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,cAAc;EACd,yBAAyB;EACzB,iBAAiB;EACjB,kBAAkB;EAClB,oCAAoC;EACpC,4BAA4B;EAC5B,gCAAgC;AAClC;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,yBAAyB;EACzB,iBAAiB;EACjB,kBAAkB;EAClB,oCAAoC;EACpC,4BAA4B;EAC5B,gCAAgC;AAClC;;AAEA;EACE,UAAU;EACV,WAAW;EACX,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,2BAA2B;EAC3B,kBAAkB;EAClB,aAAa;EACb,uBAAuB;EACvB,qBAAqB;AACvB;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,WAAW;AACb;;AAEA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;;AAEA;EACE,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,yBAAyB;AAC3B;;AAEA;EACE,uBAAuB;EACvB,qBAAqB;AACvB;;ACvuBA,+BAA+B;;AAE/B;EACE,qBAAqB;EACrB,SAAS;AACX;;AAEA;;;;EAIE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;EACE,qCAAqC;AACvC;;AAEA;EACE,uCAAuC;AACzC;;AAEA;EACE;IACE,uBAAuB;EACzB;EACA;IACE,yBAAyB;EAC3B;AACF;;AC1CA;EACE,6CAA6C;EAC7C,kBAAkB;EAClB,qBAAqB;AACvB;AACA;EACE,oBAAoB;AACtB;AACA;EACE,yBAAyB;EACzB,mBAAmB;EACnB,gBAAgB;EAChB,yEAAyE;EACzE,kBAAkB;EAClB,UAAU;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;AAClB;AACA;EACE,WAAW;EACX,aAAa;EACb,eAAe;EACf,sBAAsB;EACtB,gCAAgC;EAChC,6BAA6B;AAC/B;AACA;EACE,WAAW;EACX,yBAAyB;AAC3B;AACA;EACE,0DAA0D;EAC1D,uCAAuC;EACvC,cAAc;AAChB;;ACnCA,kBAAkB;;AAElB;EACE,aAAa;EACb,sBAAsB;EACtB,6BAA6B;EAC7B,qBAAqB;EACrB,qBAAqB;EACrB,mBAAmB;AACrB;;AAEA;EACE,0BAA0B;EAC1B,mCAAmC;EACnC,kCAAkC;EAClC,kCAAkC;EAClC,wCAAwC;AAC1C;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA,iBAAiB;;AAEjB;EACE,kBAAkB;AACpB;;AAEA;EACE,6CAA6C;AAC/C;;AAEA;EACE,8CAA8C;AAChD;;AAEA;EACE,4CAA4C;AAC9C","sources":["webpack://pandora-fms-visual-console/./src/main.css","webpack://pandora-fms-visual-console/./src/lib/FontAwesomeIcon.styles.css","webpack://pandora-fms-visual-console/./src/lib/autocomplete.css","webpack://pandora-fms-visual-console/./src/items/Clock/styles.css"],"sourcesContent":["#visual-console-container {\n margin: 0px auto;\n position: relative;\n background-repeat: no-repeat;\n background-size: 100% 100%;\n background-position: center;\n margin-top: 5px;\n}\n\n.is-maintenance {\n background-image: url(./lib/maintenanceMode.png) !important;\n}\n\n.is-maintenance :nth-child(1) {\n display: none;\n}\n\n.visual-console-item {\n position: absolute;\n display: flex;\n flex-direction: initial;\n justify-items: center;\n align-items: center;\n user-select: text;\n z-index: 1;\n}\n\n.visual-console-item.is-on-top {\n z-index: 2;\n}\n\n.visual-console-item * {\n overflow: visible;\n font-family: inherit;\n line-height: inherit;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n}\n\n.visual-console-item.is-editing {\n border: 2px dashed #b2b2b2;\n transform: translateX(-2px) translateY(-2px);\n user-select: none;\n}\n\n.visual-console-item.is-editing:hover {\n border-color: #2b2b2b;\n}\n\n.visual-console-item.is-editing.is-selected {\n border: 2px dashed #82b92e;\n cursor: move;\n z-index: 10;\n}\n.visual-console-item.is-editing > .resize-draggable {\n float: right;\n position: absolute;\n right: 0;\n bottom: 0;\n width: 15px;\n height: 15px;\n background: url(./resize-handle.svg);\n cursor: se-resize;\n z-index: 10;\n}\n\n.visual-console-item.is-editing :first-child {\n pointer-events: none;\n}\n\n@keyframes spinner-loading {\n 0% {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(1turn);\n }\n}\n\n.visual-console-item.is-alert-triggered {\n border: 3px solid #f36201;\n}\n\n.visual-console-spinner {\n background-color: transparent;\n margin: 0px auto;\n border-top: 5px solid rgb(82, 85, 87);\n border-right: 5px solid rgb(82, 85, 87);\n border-bottom: 5px solid rgb(82, 85, 87);\n border-left: 5px solid rgba(82, 85, 87, 0.2);\n\n animation-name: spinner-loading;\n animation-duration: 0.8s;\n animation-iteration-count: infinite;\n animation-timing-function: linear;\n}\n\n.visual-console-spinner,\n.visual-console-spinner :after {\n display: block;\n width: 32px;\n height: 32px;\n border-radius: 50%;\n}\n\n.visual-console-spinner.small,\n.visual-console-spinner.small :after {\n width: 12px;\n height: 12px;\n}\n\n.div-visual-console-spinner {\n position: absolute;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n opacity: 0.7;\n background: rgb(212, 215, 218);\n z-index: 10;\n}\n\n.show-elements {\n display: inline-block;\n}\n\n.hide-elements {\n display: none;\n}\n\n/*Forms*/\n.div-input-group label {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n font-size: 12pt;\n font-weight: 600;\n color: #343434;\n margin-right: 10px;\n}\n.div-input-group label img {\n margin-left: 4px;\n}\n\n.div-input-group input[type=\"text\"],\n.div-input-group input[type=\"number\"] {\n height: 25px;\n font-size: 10pt;\n background-color: transparent;\n border: none;\n border-radius: 0;\n border-bottom: 1px solid #ccc;\n font-weight: lighter;\n padding: 0px 0px 2px 0px;\n box-sizing: border-box;\n margin-right: 10px;\n padding-left: 2px;\n}\n\n.div-input-group input[type=\"radio\"] {\n margin-right: 10px;\n width: 17px;\n height: 17px;\n}\n\n.div-input-group select {\n font-weight: lighter;\n font-size: 10pt;\n}\n\n.input-groups {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n}\n\n.input-group {\n width: 100%;\n margin-bottom: 25px;\n padding-left: 20px;\n}\n\n.div-ranges-input-group {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n align-items: flex-start;\n}\n\n.div-ranges-input-group > div {\n padding-left: 20px;\n margin-top: 10px;\n}\n\n.div-input-group,\n.div-input-group div div {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n}\n\n.div-input-group h3 {\n text-transform: initial;\n text-align: center;\n font-style: italic;\n text-decoration: underline;\n margin: 0 auto;\n}\n\n.div-input-group div div a {\n margin-left: 10px;\n}\n\n.div-input-group-autocomplete-agent {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n align-items: flex-start;\n justify-content: space-between;\n height: 70px;\n}\n\n.div-input-group-inside {\n padding-left: 20px;\n}\n\n.input-group-link-console {\n height: 70px;\n}\n\n.show-elements > div.div-input-group-autocomplete-agent {\n margin-left: 20px;\n}\n\n.img-vc-elements {\n margin-left: 10px;\n}\n\ninput.error-input-validate[type=\"number\"],\ninput.error-input-validate[type=\"text\"],\nselect.error-input-validate {\n border: 1px solid #c00;\n}\n\nselect.error-input-validate:focus {\n outline-color: #c00;\n}\n\np.error-p-validate {\n width: 100%;\n color: #c00;\n}\n\n#modalVCItemForm #textarea_label_ifr {\n background-color: #c9cfcd;\n}\n\n/* Styles for the solid icons */\n\n.fa {\n display: inline-block;\n margin: 0;\n}\n\n.fa,\n.fa > svg,\n.fa.medium,\n.fa.medium > svg {\n width: 28px;\n height: 28px;\n}\n\n.fa.fa-small,\n.fa.fa-small > svg {\n width: 14px;\n height: 14px;\n}\n\n.fa.fa-large,\n.fa.fa-large > svg {\n width: 44px;\n height: 44px;\n}\n\n.fa-spin {\n animation: fa-spin 2s infinite linear;\n}\n\n.fa-pulse {\n animation: fa-spin 1s infinite steps(8);\n}\n\n@keyframes fa-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n.autocomplete {\n /*the container must be positioned relative:*/\n position: relative;\n display: inline-block;\n}\n.autocomplete input {\n /*background: pink;*/\n}\n.autocomplete-items {\n border: 1px solid #d4d4d4;\n border-bottom: none;\n border-top: none;\n /*position the autocomplete items to be the same width as the container:*/\n position: absolute;\n z-index: 1;\n overflow: auto;\n max-height: 150px;\n max-width: 250px;\n}\n.autocomplete-items div {\n width: 100%;\n padding: 10px;\n cursor: pointer;\n background-color: #fff;\n border-bottom: 1px solid #d4d4d4;\n border-top: 1px solid #d4d4d4;\n}\n.autocomplete-items div:hover {\n width: 100%;\n background-color: #e9e9e9;\n}\n.autocomplete-active {\n /*when navigating through the items using the arrow keys:*/\n background-color: DodgerBlue !important;\n color: #ffffff;\n}\n\n/* Digital clock */\n\n.visual-console-item .digital-clock {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n flex-direction: column;\n justify-content: center;\n justify-items: center;\n align-content: center;\n align-items: center;\n}\n\n.visual-console-item .digital-clock > span {\n /* To improve legibility */\n text-rendering: optimizeLegibility;\n text-shadow: rgba(0, 0, 0, 0.01) 0 0 1px;\n}\n\n.visual-console-item .digital-clock > span.time {\n font-size: 50px;\n}\n\n.visual-console-item .digital-clock > span.date {\n font-size: 25px;\n}\n\n.visual-console-item .digital-clock > span.timezone {\n font-size: 25px;\n}\n\n/* Analog clock */\n\n.visual-console-item .analogic-clock {\n text-align: center;\n}\n\n.visual-console-item .analogic-clock .hour-hand {\n animation: rotate-hour 43200s infinite linear;\n}\n\n.visual-console-item .analogic-clock .minute-hand {\n animation: rotate-minute 3600s infinite linear;\n}\n\n.visual-console-item .analogic-clock .second-hand {\n animation: rotate-second 60s infinite linear;\n}\n\n#html-tabs .ui-widget-header {\n background-color: #ffffff;\n border: 0px;\n}\n\n#html-tabs .ui-tabs-anchor {\n float: none;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n}\n\n#html-tabs .ui-tabs-anchor img {\n margin-right: 10px;\n}\n\n#html-tabs .ui-tabs-nav li {\n border-radius: 5px 5px 0px 0px;\n}\n\nli.interval-color-ranges > label,\nli#li-default-ranges > label {\n margin-right: 15px;\n}\n\nli.interval-color-ranges > input[type=\"number\"],\nli#li-default-ranges > input[type=\"number\"] {\n width: 80px;\n}\n\nli.interval-color-ranges > label:not(:first-child),\nli#li-default-ranges > label:not(:first-child),\nli#li-size-item > label:not(:first-child),\nli#li-position-item > label:not(:first-child) {\n width: initial;\n margin-left: 15px;\n}\n\nli#li-image-item label {\n display: flex;\n flex-direction: row;\n justify-content: flex-end;\n}\n\nli#li-image-item label img {\n flex: initial;\n}\n\n.discovery.modal * {\n font-weight: normal;\n color: #343434;\n}\n\n.discovery.modal select {\n width: 100px;\n}\n\n.discovery.modal div#period_manual select,\n.discovery.modal div#period_manual input,\n.discovery.modal div#period_default select,\n.discovery.modal div#cacheExpiration_manual select,\n.discovery.modal div#cacheExpiration_manual input,\n.discovery.modal div#cacheExpiration_default select {\n font-size: inherit !important;\n}\n.discovery.modal div#period_default select#period_select,\n.discovery.modal div#cacheExpiration_default select#cacheExpiration_select {\n max-width: 230px;\n width: inherit;\n}\n\nli#li-timeZone-item > label:not(:first-child),\n.discovery.modal li#div-textarea-label > label {\n flex: inherit;\n}\n\nli#li-timeZone-item > select:not(:first-child) {\n margin-left: 10px;\n}\n\n.discovery.modal li#div-textarea-label table tbody td.mceIframeContainer {\n background-color: #ededed;\n}\n\n/*style item group show statistic*/\n.group-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n}\n.group-container .group-item-title {\n width: 100%;\n height: 30%;\n background-color: #9d9ea0;\n color: black;\n font-weight: bold;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n}\n.group-container .group-item-info {\n width: 100%;\n height: 70%;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n padding: 2%;\n align-items: center;\n}\n\n.group-container .group-item-info .group-item-info-container {\n flex: 1 1 20%;\n display: flex;\n flex-direction: row;\n border-radius: 2px;\n max-height: 50px;\n min-height: 35px;\n margin: 1%;\n}\n\n.group-container .group-item-info .group-item-info-container .value-style {\n flex: 1;\n color: #fff;\n font-size: 100%;\n padding: 0%;\n width: 100%;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n}\n\n.group-container .group-item-info .group-item-info-container .name-style {\n flex: 1;\n background-color: white;\n color: black;\n font-size: 100%;\n padding: 0%;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n}\n\ndiv.label,\ndiv.simple-value {\n min-width: fit-content;\n min-height: fit-content;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n\ndiv.simple-value > div {\n max-height: -webkit-fill-available;\n}\n\ndiv.module-graph .parent_graph p table tr {\n height: 25px;\n}\n\ndiv.module-graph {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n justify-content: center;\n}\n\ndiv.basic-chart {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: flex-end;\n justify-content: center;\n}\n\n.basic-chart-header {\n height: 40%;\n width: 100%;\n display: flex;\n}\n\n.basic-chart-header-name {\n margin: 0;\n padding: 0;\n height: 100%;\n width: 80%;\n display: flex;\n align-items: center;\n font-size: 2.5vmin;\n margin-left: 3%;\n}\n\n.basic-chart-header-value {\n margin: 0;\n padding: 0;\n height: 100%;\n width: 20%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 2.5vmin;\n}\n\ndiv.module-graph .gauge_d3_class {\n flex: 1 1 100px;\n float: none !important;\n overflow: inherit !important;\n text-align: center;\n}\n\n.textDecorationNone:hover {\n text-decoration: none;\n}\n\n.vc-item-nl-label {\n border-radius: 5px;\n background-color: #fff;\n padding: 5px;\n padding-left: 1em;\n font-size: 14px;\n}\n\n.odometer {\n overflow: hidden !important;\n}\n\n.odometer-container {\n width: 100%;\n height: 100%;\n overflow: hidden;\n text-align: center;\n display: flex;\n align-items: flex-end;\n}\n\n.odometer-a {\n z-index: 5;\n position: absolute;\n width: 65%;\n height: 65%;\n left: calc(17.5%);\n border-radius: 1000px 1000px 0px 0px;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n flex-direction: column;\n line-height: 0px;\n}\n\n.odometer-b {\n z-index: 4;\n position: relative;\n width: 95%;\n height: 95%;\n border-radius: 0px 0px 1000px 1000px;\n transform-origin: center top;\n transition: all 1.3s ease-in-out;\n top: calc(95%);\n left: calc(2.5%);\n}\n\n.odometer-c {\n z-index: 3;\n position: absolute;\n width: 96%;\n height: 96%;\n left: calc(2%);\n background-color: #202226;\n margin-left: auto;\n margin-right: auto;\n border-radius: 1000px 1000px 0px 0px;\n transform-origin: center top;\n transition: all 1.3s ease-in-out;\n}\n\n.odometer-d {\n z-index: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n background-color: #82b92e;\n margin-left: auto;\n margin-right: auto;\n border-radius: 1000px 1000px 0px 0px;\n transform-origin: center top;\n transition: all 1.3s ease-in-out;\n}\n\n.gauge-data {\n z-index: 4;\n color: #fff;\n font-size: 1.5em;\n width: 100%;\n height: 100%;\n transition: all 1s ease-out;\n position: absolute;\n display: flex;\n justify-content: center;\n align-items: flex-end;\n}\n\n.svg_warning {\n fill: #f3b200;\n}\n\n.svg_warning_hide {\n fill: #fff !important;\n}\n\n.gauge-data #percent {\n color: #000;\n}\n\n.orange_background {\n background: #ffa631;\n}\n.red_background {\n background: #e63c52;\n}\n.yellow_background {\n background: #f3b200;\n}\n.grey_background {\n background: #b2b2b2;\n}\n.blue_background {\n background: #4a83f3;\n}\n.green_background {\n background: #82b92e;\n}\n\n#box-rectangle-selection {\n position: absolute;\n width: 0px;\n height: 0px;\n border: 2px solid #002f33;\n}\n\np {\n margin-block-start: 1em;\n margin-block-end: 1em;\n}\n","/* Styles for the solid icons */\n\n.fa {\n display: inline-block;\n margin: 0;\n}\n\n.fa,\n.fa > svg,\n.fa.medium,\n.fa.medium > svg {\n width: 28px;\n height: 28px;\n}\n\n.fa.fa-small,\n.fa.fa-small > svg {\n width: 14px;\n height: 14px;\n}\n\n.fa.fa-large,\n.fa.fa-large > svg {\n width: 44px;\n height: 44px;\n}\n\n.fa-spin {\n animation: fa-spin 2s infinite linear;\n}\n\n.fa-pulse {\n animation: fa-spin 1s infinite steps(8);\n}\n\n@keyframes fa-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n",".autocomplete {\n /*the container must be positioned relative:*/\n position: relative;\n display: inline-block;\n}\n.autocomplete input {\n /*background: pink;*/\n}\n.autocomplete-items {\n border: 1px solid #d4d4d4;\n border-bottom: none;\n border-top: none;\n /*position the autocomplete items to be the same width as the container:*/\n position: absolute;\n z-index: 1;\n overflow: auto;\n max-height: 150px;\n max-width: 250px;\n}\n.autocomplete-items div {\n width: 100%;\n padding: 10px;\n cursor: pointer;\n background-color: #fff;\n border-bottom: 1px solid #d4d4d4;\n border-top: 1px solid #d4d4d4;\n}\n.autocomplete-items div:hover {\n width: 100%;\n background-color: #e9e9e9;\n}\n.autocomplete-active {\n /*when navigating through the items using the arrow keys:*/\n background-color: DodgerBlue !important;\n color: #ffffff;\n}\n","/* Digital clock */\n\n.visual-console-item .digital-clock {\n display: flex;\n flex-direction: column;\n justify-content: space-evenly;\n justify-items: center;\n align-content: center;\n align-items: center;\n}\n\n.visual-console-item .digital-clock > span {\n /* To improve legibility */\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n text-shadow: rgba(0, 0, 0, 0.01) 0 0 1px;\n}\n\n.visual-console-item .digital-clock > span.time {\n font-size: 50px;\n}\n\n.visual-console-item .digital-clock > span.date {\n font-size: 25px;\n}\n\n.visual-console-item .digital-clock > span.timezone {\n font-size: 25px;\n}\n\n/* Analog clock */\n\n.visual-console-item .analogic-clock {\n text-align: center;\n}\n\n.visual-console-item .analogic-clock .hour-hand {\n animation: rotate-hour 43200s infinite linear;\n}\n\n.visual-console-item .analogic-clock .minute-hand {\n animation: rotate-minute 3600s infinite linear;\n}\n\n.visual-console-item .analogic-clock .second-hand {\n animation: rotate-second 60s infinite linear;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"vc.main.css","mappings":"AAAA;EACE,gBAAgB;EAChB,kBAAkB;EAClB,4BAA4B;EAC5B,0BAA0B;EAC1B,2BAA2B;EAC3B,eAAe;AACjB;;AAEA;EACE,oEAA2D;AAC7D;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,kBAAkB;EAClB,aAAa;EACb,uBAAuB;EACvB,qBAAqB;EACrB,mBAAmB;EACnB,iBAAiB;EACjB,UAAU;AACZ;;AAEA;EACE,UAAU;AACZ;;AAEA;EACE,iBAAiB;EACjB,oBAAoB;EACpB,oBAAoB;EACpB,mCAAmC;EACnC,kCAAkC;EAClC,kCAAkC;AACpC;;AAEA;EACE,0BAA0B;EAC1B,4CAA4C;EAC5C,iBAAiB;AACnB;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,0BAA0B;EAC1B,YAAY;EACZ,WAAW;AACb;AACA;EACE,YAAY;EACZ,kBAAkB;EAClB,QAAQ;EACR,SAAS;EACT,WAAW;EACX,YAAY;EACZ,mDAAoC;EACpC,iBAAiB;EACjB,WAAW;AACb;;AAEA;EACE,oBAAoB;AACtB;;AAEA;EACE;IACE,uBAAuB;EACzB;EACA;IACE,wBAAwB;EAC1B;AACF;;AAEA;EACE,yBAAyB;AAC3B;;AAEA;EACE,6BAA6B;EAC7B,gBAAgB;EAChB,qCAAqC;EACrC,uCAAuC;EACvC,wCAAwC;EACxC,4CAA4C;;EAE5C,+BAA+B;EAC/B,wBAAwB;EACxB,mCAAmC;EACnC,iCAAiC;AACnC;;AAEA;;EAEE,cAAc;EACd,WAAW;EACX,YAAY;EACZ,kBAAkB;AACpB;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,YAAY;EACZ,8BAA8B;EAC9B,WAAW;AACb;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,aAAa;AACf;;AAEA,QAAQ;AACR;EACE,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,mBAAmB;EACnB,eAAe;EACf,gBAAgB;EAChB,cAAc;EACd,kBAAkB;AACpB;AACA;EACE,gBAAgB;AAClB;;AAEA;;EAEE,YAAY;EACZ,eAAe;EACf,6BAA6B;EAC7B,YAAY;EACZ,gBAAgB;EAChB,6BAA6B;EAC7B,oBAAoB;EACpB,wBAAwB;EACxB,sBAAsB;EACtB,kBAAkB;EAClB,iBAAiB;AACnB;;AAEA;EACE,kBAAkB;EAClB,WAAW;EACX,YAAY;AACd;;AAEA;EACE,oBAAoB;EACpB,eAAe;AACjB;;AAEA;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;AACjB;;AAEA;EACE,WAAW;EACX,mBAAmB;EACnB,kBAAkB;AACpB;;AAEA;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;EACf,uBAAuB;AACzB;;AAEA;EACE,kBAAkB;EAClB,gBAAgB;AAClB;;AAEA;;EAEE,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,mBAAmB;AACrB;;AAEA;EACE,uBAAuB;EACvB,kBAAkB;EAClB,kBAAkB;EAClB,0BAA0B;EAC1B,cAAc;AAChB;;AAEA;EACE,iBAAiB;AACnB;;AAEA;EACE,aAAa;EACb,sBAAsB;EACtB,eAAe;EACf,uBAAuB;EACvB,8BAA8B;EAC9B,YAAY;AACd;;AAEA;EACE,kBAAkB;AACpB;;AAEA;EACE,YAAY;AACd;;AAEA;EACE,iBAAiB;AACnB;;AAEA;EACE,iBAAiB;AACnB;;AAEA;;;EAGE,sBAAsB;AACxB;;AAEA;EACE,mBAAmB;AACrB;;AAEA;EACE,WAAW;EACX,WAAW;AACb;;AAEA;EACE,yBAAyB;AAC3B;;AAEA,+BAA+B;;AAE/B;EACE,qBAAqB;EACrB,SAAS;AACX;;AAEA;;;;EAIE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;EACE,qCAAqC;AACvC;;AAEA;EACE,uCAAuC;AACzC;;AAEA;EACE;IACE,uBAAuB;EACzB;EACA;IACE,yBAAyB;EAC3B;AACF;;AAEA;EACE,6CAA6C;EAC7C,kBAAkB;EAClB,qBAAqB;AACvB;AACA;EACE,oBAAoB;AACtB;AACA;EACE,yBAAyB;EACzB,mBAAmB;EACnB,gBAAgB;EAChB,yEAAyE;EACzE,kBAAkB;EAClB,UAAU;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;AAClB;AACA;EACE,WAAW;EACX,aAAa;EACb,eAAe;EACf,sBAAsB;EACtB,gCAAgC;EAChC,6BAA6B;AAC/B;AACA;EACE,WAAW;EACX,yBAAyB;AAC3B;AACA;EACE,0DAA0D;EAC1D,uCAAuC;EACvC,cAAc;AAChB;;AAEA,kBAAkB;;AAElB;EACE,oBAAoB;EACpB,oBAAoB;EACpB,aAAa;EACb,sBAAsB;EACtB,uBAAuB;EACvB,qBAAqB;EACrB,qBAAqB;EACrB,mBAAmB;AACrB;;AAEA;EACE,0BAA0B;EAC1B,kCAAkC;EAClC,wCAAwC;AAC1C;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA,iBAAiB;;AAEjB;EACE,kBAAkB;AACpB;;AAEA;EACE,6CAA6C;AAC/C;;AAEA;EACE,8CAA8C;AAChD;;AAEA;EACE,4CAA4C;AAC9C;;AAEA;EACE,yBAAyB;EACzB,WAAW;AACb;;AAEA;EACE,WAAW;EACX,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,8BAA8B;AAChC;;AAEA;EACE,kBAAkB;AACpB;;AAEA;EACE,8BAA8B;AAChC;;AAEA;;EAEE,kBAAkB;AACpB;;AAEA;;EAEE,WAAW;AACb;;AAEA;;;;EAIE,cAAc;EACd,iBAAiB;AACnB;;AAEA;EACE,aAAa;EACb,mBAAmB;EACnB,yBAAyB;AAC3B;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,mBAAmB;EACnB,cAAc;AAChB;;AAEA;EACE,YAAY;AACd;;AAEA;;;;;;EAME,6BAA6B;AAC/B;AACA;;EAEE,gBAAgB;EAChB,cAAc;AAChB;;AAEA;;EAEE,aAAa;AACf;;AAEA;EACE,iBAAiB;AACnB;;AAEA;EACE,yBAAyB;AAC3B;;AAEA,kCAAkC;AAClC;EACE,aAAa;EACb,sBAAsB;EACtB,WAAW;EACX,YAAY;AACd;AACA;EACE,WAAW;EACX,WAAW;EACX,yBAAyB;EACzB,YAAY;EACZ,iBAAiB;EACjB,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,uBAAuB;AACzB;AACA;EACE,WAAW;EACX,WAAW;EACX,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,WAAW;EACX,mBAAmB;AACrB;;AAEA;EACE,aAAa;EACb,aAAa;EACb,mBAAmB;EACnB,kBAAkB;EAClB,gBAAgB;EAChB,gBAAgB;EAChB,UAAU;AACZ;;AAEA;EACE,OAAO;EACP,WAAW;EACX,eAAe;EACf,WAAW;EACX,WAAW;EACX,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,uBAAuB;AACzB;;AAEA;EACE,OAAO;EACP,uBAAuB;EACvB,YAAY;EACZ,eAAe;EACf,WAAW;EACX,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,uBAAuB;AACzB;;AAEA;;EAEE,sBAAsB;EACtB,uBAAuB;EACvB,aAAa;EACb,sBAAsB;EACtB,uBAAuB;AACzB;;AAEA;EACE,kCAAkC;AACpC;;AAEA;EACE,YAAY;AACd;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,mBAAmB;EACnB,uBAAuB;AACzB;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,aAAa;EACb,mBAAmB;EACnB,eAAe;EACf,qBAAqB;EACrB,uBAAuB;AACzB;;AAEA;EACE,WAAW;EACX,WAAW;EACX,aAAa;AACf;;AAEA;EACE,SAAS;EACT,UAAU;EACV,YAAY;EACZ,UAAU;EACV,aAAa;EACb,mBAAmB;EACnB,kBAAkB;EAClB,eAAe;AACjB;;AAEA;EACE,SAAS;EACT,UAAU;EACV,YAAY;EACZ,UAAU;EACV,aAAa;EACb,mBAAmB;EACnB,uBAAuB;EACvB,kBAAkB;AACpB;;AAEA;EACE,eAAe;EACf,sBAAsB;EACtB,4BAA4B;EAC5B,kBAAkB;AACpB;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,kBAAkB;EAClB,sBAAsB;EACtB,YAAY;EACZ,iBAAiB;EACjB,eAAe;AACjB;;AAEA;EACE,2BAA2B;AAC7B;;AAEA;EACE,WAAW;EACX,YAAY;EACZ,gBAAgB;EAChB,kBAAkB;EAClB,aAAa;EACb,qBAAqB;AACvB;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,iBAAiB;EACjB,oCAAoC;EACpC,aAAa;EACb,mBAAmB;EACnB,yBAAyB;EACzB,sBAAsB;EACtB,gBAAgB;AAClB;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,oCAAoC;EACpC,4BAA4B;EAC5B,gCAAgC;EAChC,cAAc;EACd,gBAAgB;AAClB;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,cAAc;EACd,yBAAyB;EACzB,iBAAiB;EACjB,kBAAkB;EAClB,oCAAoC;EACpC,4BAA4B;EAC5B,gCAAgC;AAClC;;AAEA;EACE,UAAU;EACV,kBAAkB;EAClB,WAAW;EACX,YAAY;EACZ,yBAAyB;EACzB,iBAAiB;EACjB,kBAAkB;EAClB,oCAAoC;EACpC,4BAA4B;EAC5B,gCAAgC;AAClC;;AAEA;EACE,UAAU;EACV,WAAW;EACX,gBAAgB;EAChB,WAAW;EACX,YAAY;EACZ,2BAA2B;EAC3B,kBAAkB;EAClB,aAAa;EACb,uBAAuB;EACvB,qBAAqB;AACvB;;AAEA;EACE,aAAa;AACf;;AAEA;EACE,qBAAqB;AACvB;;AAEA;EACE,WAAW;AACb;;AAEA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;AACA;EACE,mBAAmB;AACrB;;AAEA;EACE,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,yBAAyB;AAC3B;;AAEA;EACE,uBAAuB;EACvB,qBAAqB;AACvB;;AAEA;EACE,kBAAkB;AACpB,C;AC3uBA,+BAA+B;;AAE/B;EACE,qBAAqB;EACrB,SAAS;AACX;;AAEA;;;;EAIE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;;EAEE,WAAW;EACX,YAAY;AACd;;AAEA;EACE,qCAAqC;AACvC;;AAEA;EACE,uCAAuC;AACzC;;AAEA;EACE;IACE,uBAAuB;EACzB;EACA;IACE,yBAAyB;EAC3B;AACF;;AC1CA;EACE,6CAA6C;EAC7C,kBAAkB;EAClB,qBAAqB;AACvB;AACA;EACE,oBAAoB;AACtB;AACA;EACE,yBAAyB;EACzB,mBAAmB;EACnB,gBAAgB;EAChB,yEAAyE;EACzE,kBAAkB;EAClB,UAAU;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;AAClB;AACA;EACE,WAAW;EACX,aAAa;EACb,eAAe;EACf,sBAAsB;EACtB,gCAAgC;EAChC,6BAA6B;AAC/B;AACA;EACE,WAAW;EACX,yBAAyB;AAC3B;AACA;EACE,0DAA0D;EAC1D,uCAAuC;EACvC,cAAc;AAChB;;ACnCA,kBAAkB;;AAElB;EACE,aAAa;EACb,sBAAsB;EACtB,6BAA6B;EAC7B,qBAAqB;EACrB,qBAAqB;EACrB,mBAAmB;AACrB;;AAEA;EACE,0BAA0B;EAC1B,mCAAmC;EACnC,kCAAkC;EAClC,kCAAkC;EAClC,wCAAwC;AAC1C;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA;EACE,eAAe;AACjB;;AAEA,iBAAiB;;AAEjB;EACE,kBAAkB;AACpB;;AAEA;EACE,6CAA6C;AAC/C;;AAEA;EACE,8CAA8C;AAChD;;AAEA;EACE,4CAA4C;AAC9C","sources":["webpack://pandora-fms-visual-console/./src/main.css","webpack://pandora-fms-visual-console/./src/lib/FontAwesomeIcon.styles.css","webpack://pandora-fms-visual-console/./src/lib/autocomplete.css","webpack://pandora-fms-visual-console/./src/items/Clock/styles.css"],"sourcesContent":["#visual-console-container {\n margin: 0px auto;\n position: relative;\n background-repeat: no-repeat;\n background-size: 100% 100%;\n background-position: center;\n margin-top: 5px;\n}\n\n.is-maintenance {\n background-image: url(./lib/maintenanceMode.png) !important;\n}\n\n.is-maintenance :nth-child(1) {\n display: none;\n}\n\n.visual-console-item {\n position: absolute;\n display: flex;\n flex-direction: initial;\n justify-items: center;\n align-items: center;\n user-select: text;\n z-index: 1;\n}\n\n.visual-console-item.is-on-top {\n z-index: 2;\n}\n\n.visual-console-item * {\n overflow: visible;\n font-family: inherit;\n line-height: inherit;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n}\n\n.visual-console-item.is-editing {\n border: 2px dashed #b2b2b2;\n transform: translateX(-2px) translateY(-2px);\n user-select: none;\n}\n\n.visual-console-item.is-editing:hover {\n border-color: #2b2b2b;\n}\n\n.visual-console-item.is-editing.is-selected {\n border: 2px dashed #82b92e;\n cursor: move;\n z-index: 10;\n}\n.visual-console-item.is-editing > .resize-draggable {\n float: right;\n position: absolute;\n right: 0;\n bottom: 0;\n width: 15px;\n height: 15px;\n background: url(./resize-handle.svg);\n cursor: se-resize;\n z-index: 10;\n}\n\n.visual-console-item.is-editing :first-child {\n pointer-events: none;\n}\n\n@keyframes spinner-loading {\n 0% {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(1turn);\n }\n}\n\n.visual-console-item.is-alert-triggered {\n border: 3px solid #f36201;\n}\n\n.visual-console-spinner {\n background-color: transparent;\n margin: 0px auto;\n border-top: 5px solid rgb(82, 85, 87);\n border-right: 5px solid rgb(82, 85, 87);\n border-bottom: 5px solid rgb(82, 85, 87);\n border-left: 5px solid rgba(82, 85, 87, 0.2);\n\n animation-name: spinner-loading;\n animation-duration: 0.8s;\n animation-iteration-count: infinite;\n animation-timing-function: linear;\n}\n\n.visual-console-spinner,\n.visual-console-spinner :after {\n display: block;\n width: 32px;\n height: 32px;\n border-radius: 50%;\n}\n\n.visual-console-spinner.small,\n.visual-console-spinner.small :after {\n width: 12px;\n height: 12px;\n}\n\n.div-visual-console-spinner {\n position: absolute;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n opacity: 0.7;\n background: rgb(212, 215, 218);\n z-index: 10;\n}\n\n.show-elements {\n display: inline-block;\n}\n\n.hide-elements {\n display: none;\n}\n\n/*Forms*/\n.div-input-group label {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n font-size: 12pt;\n font-weight: 600;\n color: #343434;\n margin-right: 10px;\n}\n.div-input-group label img {\n margin-left: 4px;\n}\n\n.div-input-group input[type=\"text\"],\n.div-input-group input[type=\"number\"] {\n height: 25px;\n font-size: 10pt;\n background-color: transparent;\n border: none;\n border-radius: 0;\n border-bottom: 1px solid #ccc;\n font-weight: lighter;\n padding: 0px 0px 2px 0px;\n box-sizing: border-box;\n margin-right: 10px;\n padding-left: 2px;\n}\n\n.div-input-group input[type=\"radio\"] {\n margin-right: 10px;\n width: 17px;\n height: 17px;\n}\n\n.div-input-group select {\n font-weight: lighter;\n font-size: 10pt;\n}\n\n.input-groups {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n}\n\n.input-group {\n width: 100%;\n margin-bottom: 25px;\n padding-left: 20px;\n}\n\n.div-ranges-input-group {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n align-items: flex-start;\n}\n\n.div-ranges-input-group > div {\n padding-left: 20px;\n margin-top: 10px;\n}\n\n.div-input-group,\n.div-input-group div div {\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n}\n\n.div-input-group h3 {\n text-transform: initial;\n text-align: center;\n font-style: italic;\n text-decoration: underline;\n margin: 0 auto;\n}\n\n.div-input-group div div a {\n margin-left: 10px;\n}\n\n.div-input-group-autocomplete-agent {\n display: flex;\n flex-direction: column;\n flex-wrap: wrap;\n align-items: flex-start;\n justify-content: space-between;\n height: 70px;\n}\n\n.div-input-group-inside {\n padding-left: 20px;\n}\n\n.input-group-link-console {\n height: 70px;\n}\n\n.show-elements > div.div-input-group-autocomplete-agent {\n margin-left: 20px;\n}\n\n.img-vc-elements {\n margin-left: 10px;\n}\n\ninput.error-input-validate[type=\"number\"],\ninput.error-input-validate[type=\"text\"],\nselect.error-input-validate {\n border: 1px solid #c00;\n}\n\nselect.error-input-validate:focus {\n outline-color: #c00;\n}\n\np.error-p-validate {\n width: 100%;\n color: #c00;\n}\n\n#modalVCItemForm #textarea_label_ifr {\n background-color: #c9cfcd;\n}\n\n/* Styles for the solid icons */\n\n.fa {\n display: inline-block;\n margin: 0;\n}\n\n.fa,\n.fa > svg,\n.fa.medium,\n.fa.medium > svg {\n width: 28px;\n height: 28px;\n}\n\n.fa.fa-small,\n.fa.fa-small > svg {\n width: 14px;\n height: 14px;\n}\n\n.fa.fa-large,\n.fa.fa-large > svg {\n width: 44px;\n height: 44px;\n}\n\n.fa-spin {\n animation: fa-spin 2s infinite linear;\n}\n\n.fa-pulse {\n animation: fa-spin 1s infinite steps(8);\n}\n\n@keyframes fa-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n\n.autocomplete {\n /*the container must be positioned relative:*/\n position: relative;\n display: inline-block;\n}\n.autocomplete input {\n /*background: pink;*/\n}\n.autocomplete-items {\n border: 1px solid #d4d4d4;\n border-bottom: none;\n border-top: none;\n /*position the autocomplete items to be the same width as the container:*/\n position: absolute;\n z-index: 1;\n overflow: auto;\n max-height: 150px;\n max-width: 250px;\n}\n.autocomplete-items div {\n width: 100%;\n padding: 10px;\n cursor: pointer;\n background-color: #fff;\n border-bottom: 1px solid #d4d4d4;\n border-top: 1px solid #d4d4d4;\n}\n.autocomplete-items div:hover {\n width: 100%;\n background-color: #e9e9e9;\n}\n.autocomplete-active {\n /*when navigating through the items using the arrow keys:*/\n background-color: DodgerBlue !important;\n color: #ffffff;\n}\n\n/* Digital clock */\n\n.visual-console-item .digital-clock {\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n flex-direction: column;\n justify-content: center;\n justify-items: center;\n align-content: center;\n align-items: center;\n}\n\n.visual-console-item .digital-clock > span {\n /* To improve legibility */\n text-rendering: optimizeLegibility;\n text-shadow: rgba(0, 0, 0, 0.01) 0 0 1px;\n}\n\n.visual-console-item .digital-clock > span.time {\n font-size: 50px;\n}\n\n.visual-console-item .digital-clock > span.date {\n font-size: 25px;\n}\n\n.visual-console-item .digital-clock > span.timezone {\n font-size: 25px;\n}\n\n/* Analog clock */\n\n.visual-console-item .analogic-clock {\n text-align: center;\n}\n\n.visual-console-item .analogic-clock .hour-hand {\n animation: rotate-hour 43200s infinite linear;\n}\n\n.visual-console-item .analogic-clock .minute-hand {\n animation: rotate-minute 3600s infinite linear;\n}\n\n.visual-console-item .analogic-clock .second-hand {\n animation: rotate-second 60s infinite linear;\n}\n\n#html-tabs .ui-widget-header {\n background-color: #ffffff;\n border: 0px;\n}\n\n#html-tabs .ui-tabs-anchor {\n float: none;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: space-between;\n}\n\n#html-tabs .ui-tabs-anchor img {\n margin-right: 10px;\n}\n\n#html-tabs .ui-tabs-nav li {\n border-radius: 5px 5px 0px 0px;\n}\n\nli.interval-color-ranges > label,\nli#li-default-ranges > label {\n margin-right: 15px;\n}\n\nli.interval-color-ranges > input[type=\"number\"],\nli#li-default-ranges > input[type=\"number\"] {\n width: 80px;\n}\n\nli.interval-color-ranges > label:not(:first-child),\nli#li-default-ranges > label:not(:first-child),\nli#li-size-item > label:not(:first-child),\nli#li-position-item > label:not(:first-child) {\n width: initial;\n margin-left: 15px;\n}\n\nli#li-image-item label {\n display: flex;\n flex-direction: row;\n justify-content: flex-end;\n}\n\nli#li-image-item label img {\n flex: initial;\n}\n\n.discovery.modal * {\n font-weight: normal;\n color: #343434;\n}\n\n.discovery.modal select {\n width: 100px;\n}\n\n.discovery.modal div#period_manual select,\n.discovery.modal div#period_manual input,\n.discovery.modal div#period_default select,\n.discovery.modal div#cacheExpiration_manual select,\n.discovery.modal div#cacheExpiration_manual input,\n.discovery.modal div#cacheExpiration_default select {\n font-size: inherit !important;\n}\n.discovery.modal div#period_default select#period_select,\n.discovery.modal div#cacheExpiration_default select#cacheExpiration_select {\n max-width: 230px;\n width: inherit;\n}\n\nli#li-timeZone-item > label:not(:first-child),\n.discovery.modal li#div-textarea-label > label {\n flex: inherit;\n}\n\nli#li-timeZone-item > select:not(:first-child) {\n margin-left: 10px;\n}\n\n.discovery.modal li#div-textarea-label table tbody td.mceIframeContainer {\n background-color: #ededed;\n}\n\n/*style item group show statistic*/\n.group-container {\n display: flex;\n flex-direction: column;\n width: 100%;\n height: 100%;\n}\n.group-container .group-item-title {\n width: 100%;\n height: 30%;\n background-color: #9d9ea0;\n color: black;\n font-weight: bold;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n}\n.group-container .group-item-info {\n width: 100%;\n height: 70%;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n padding: 2%;\n align-items: center;\n}\n\n.group-container .group-item-info .group-item-info-container {\n flex: 1 1 20%;\n display: flex;\n flex-direction: row;\n border-radius: 2px;\n max-height: 50px;\n min-height: 35px;\n margin: 1%;\n}\n\n.group-container .group-item-info .group-item-info-container .value-style {\n flex: 1;\n color: #fff;\n font-size: 100%;\n padding: 0%;\n width: 100%;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n}\n\n.group-container .group-item-info .group-item-info-container .name-style {\n flex: 1;\n background-color: white;\n color: black;\n font-size: 100%;\n padding: 0%;\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: row;\n align-items: center;\n justify-content: center;\n}\n\ndiv.label,\ndiv.simple-value {\n min-width: fit-content;\n min-height: fit-content;\n display: flex;\n flex-direction: column;\n justify-content: center;\n}\n\ndiv.simple-value > div {\n max-height: -webkit-fill-available;\n}\n\ndiv.module-graph .parent_graph p table tr {\n height: 25px;\n}\n\ndiv.module-graph {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: center;\n justify-content: center;\n}\n\ndiv.basic-chart {\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: row;\n flex-wrap: wrap;\n align-items: flex-end;\n justify-content: center;\n}\n\n.basic-chart-header {\n height: 40%;\n width: 100%;\n display: flex;\n}\n\n.basic-chart-header-name {\n margin: 0;\n padding: 0;\n height: 100%;\n width: 80%;\n display: flex;\n align-items: center;\n font-size: 2.5vmin;\n margin-left: 3%;\n}\n\n.basic-chart-header-value {\n margin: 0;\n padding: 0;\n height: 100%;\n width: 20%;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 2.5vmin;\n}\n\ndiv.module-graph .gauge_d3_class {\n flex: 1 1 100px;\n float: none !important;\n overflow: inherit !important;\n text-align: center;\n}\n\n.textDecorationNone:hover {\n text-decoration: none;\n}\n\n.vc-item-nl-label {\n border-radius: 5px;\n background-color: #fff;\n padding: 5px;\n padding-left: 1em;\n font-size: 14px;\n}\n\n.odometer {\n overflow: hidden !important;\n}\n\n.odometer-container {\n width: 100%;\n height: 100%;\n overflow: hidden;\n text-align: center;\n display: flex;\n align-items: flex-end;\n}\n\n.odometer-a {\n z-index: 5;\n position: absolute;\n width: 65%;\n height: 65%;\n left: calc(17.5%);\n border-radius: 1000px 1000px 0px 0px;\n display: flex;\n align-items: center;\n justify-content: flex-end;\n flex-direction: column;\n line-height: 0px;\n}\n\n.odometer-b {\n z-index: 4;\n position: relative;\n width: 95%;\n height: 95%;\n border-radius: 0px 0px 1000px 1000px;\n transform-origin: center top;\n transition: all 1.3s ease-in-out;\n top: calc(95%);\n left: calc(2.5%);\n}\n\n.odometer-c {\n z-index: 3;\n position: absolute;\n width: 96%;\n height: 96%;\n left: calc(2%);\n background-color: #202226;\n margin-left: auto;\n margin-right: auto;\n border-radius: 1000px 1000px 0px 0px;\n transform-origin: center top;\n transition: all 1.3s ease-in-out;\n}\n\n.odometer-d {\n z-index: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n background-color: #82b92e;\n margin-left: auto;\n margin-right: auto;\n border-radius: 1000px 1000px 0px 0px;\n transform-origin: center top;\n transition: all 1.3s ease-in-out;\n}\n\n.gauge-data {\n z-index: 4;\n color: #fff;\n font-size: 1.5em;\n width: 100%;\n height: 100%;\n transition: all 1s ease-out;\n position: absolute;\n display: flex;\n justify-content: center;\n align-items: flex-end;\n}\n\n.svg_warning {\n fill: #f3b200;\n}\n\n.svg_warning_hide {\n fill: #fff !important;\n}\n\n.gauge-data #percent {\n color: #000;\n}\n\n.orange_background {\n background: #ffa631;\n}\n.red_background {\n background: #e63c52;\n}\n.yellow_background {\n background: #f3b200;\n}\n.grey_background {\n background: #b2b2b2;\n}\n.blue_background {\n background: #4a83f3;\n}\n.green_background {\n background: #82b92e;\n}\n\n#box-rectangle-selection {\n position: absolute;\n width: 0px;\n height: 0px;\n border: 2px solid #002f33;\n}\n\np {\n margin-block-start: 1em;\n margin-block-end: 1em;\n}\n\nstrong {\n font-size: inherit;\n}","/* Styles for the solid icons */\n\n.fa {\n display: inline-block;\n margin: 0;\n}\n\n.fa,\n.fa > svg,\n.fa.medium,\n.fa.medium > svg {\n width: 28px;\n height: 28px;\n}\n\n.fa.fa-small,\n.fa.fa-small > svg {\n width: 14px;\n height: 14px;\n}\n\n.fa.fa-large,\n.fa.fa-large > svg {\n width: 44px;\n height: 44px;\n}\n\n.fa-spin {\n animation: fa-spin 2s infinite linear;\n}\n\n.fa-pulse {\n animation: fa-spin 1s infinite steps(8);\n}\n\n@keyframes fa-spin {\n 0% {\n transform: rotate(0deg);\n }\n 100% {\n transform: rotate(360deg);\n }\n}\n",".autocomplete {\n /*the container must be positioned relative:*/\n position: relative;\n display: inline-block;\n}\n.autocomplete input {\n /*background: pink;*/\n}\n.autocomplete-items {\n border: 1px solid #d4d4d4;\n border-bottom: none;\n border-top: none;\n /*position the autocomplete items to be the same width as the container:*/\n position: absolute;\n z-index: 1;\n overflow: auto;\n max-height: 150px;\n max-width: 250px;\n}\n.autocomplete-items div {\n width: 100%;\n padding: 10px;\n cursor: pointer;\n background-color: #fff;\n border-bottom: 1px solid #d4d4d4;\n border-top: 1px solid #d4d4d4;\n}\n.autocomplete-items div:hover {\n width: 100%;\n background-color: #e9e9e9;\n}\n.autocomplete-active {\n /*when navigating through the items using the arrow keys:*/\n background-color: DodgerBlue !important;\n color: #ffffff;\n}\n","/* Digital clock */\n\n.visual-console-item .digital-clock {\n display: flex;\n flex-direction: column;\n justify-content: space-evenly;\n justify-items: center;\n align-content: center;\n align-items: center;\n}\n\n.visual-console-item .digital-clock > span {\n /* To improve legibility */\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n text-rendering: optimizeLegibility;\n text-shadow: rgba(0, 0, 0, 0.01) 0 0 1px;\n}\n\n.visual-console-item .digital-clock > span.time {\n font-size: 50px;\n}\n\n.visual-console-item .digital-clock > span.date {\n font-size: 25px;\n}\n\n.visual-console-item .digital-clock > span.timezone {\n font-size: 25px;\n}\n\n/* Analog clock */\n\n.visual-console-item .analogic-clock {\n text-align: center;\n}\n\n.visual-console-item .analogic-clock .hour-hand {\n animation: rotate-hour 43200s infinite linear;\n}\n\n.visual-console-item .analogic-clock .minute-hand {\n animation: rotate-minute 3600s infinite linear;\n}\n\n.visual-console-item .analogic-clock .second-hand {\n animation: rotate-second 60s infinite linear;\n}\n"],"names":[],"sourceRoot":""} \ No newline at end of file diff --git a/visual_console_client/src/main.css b/visual_console_client/src/main.css index cd8b00e93f..c77bf658c8 100644 --- a/visual_console_client/src/main.css +++ b/visual_console_client/src/main.css @@ -742,3 +742,7 @@ p { margin-block-start: 1em; margin-block-end: 1em; } + +strong { + font-size: inherit; +} From 14fc8ef2b1958f10f9f13bbacd46c683d7f873fa Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Sun, 3 Dec 2023 21:30:17 +0100 Subject: [PATCH 145/397] Added new items to visual consoles and fixed unknown modules on creation --- .../include/ajax/demo_data.ajax.php | 270 ++++++++++++++++-- 1 file changed, 250 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 5a50eb4979..8a1c5b740a 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -295,10 +295,15 @@ if ($action === 'create_demo_data') { } } + $date_time = new DateTime(); + $current_date_time = $date_time->format('Y-m-d H:i:s'); + $values = [ - 'server_name' => $server_name, - 'id_os' => $id_os, - 'os_version' => $os_version, + 'server_name' => $server_name, + 'id_os' => $id_os, + 'os_version' => $os_version, + 'ultimo_contacto' => $current_date_time, + 'ultimo_contacto_remoto' => $current_date_time, ]; $create_alias = $agent_data['agent_alias'].'-'.($agents_created_count[$agent_data['agent_alias']] + 1); @@ -528,6 +533,7 @@ if ($action === 'create_demo_data') { 'utimestamp' => $utimestamp, 'last_status' => 0, 'last_known_status' => 0, + 'current_interval' => $agent_interval, ]; $status_id = db_get_value( @@ -2052,14 +2058,28 @@ if ($action === 'create_demo_data') { // Map used types. $types = [ - 'static_image' => 0, - 'module_graph' => 1, - 'custom_graph' => 1, - 'value' => 2, - 'label' => 4, - 'icon' => 5, + 'static_image' => 0, + 'module_graph' => 1, + 'custom_graph' => 1, + 'value' => 2, + 'percentile' => 3, + 'label' => 4, + 'icon' => 5, + 'bubble' => 9, + 'event_history' => 14, + 'circular_progress_bar' => 15, + 'circular_progress_bar_int' => 16, + 'color_cloud' => 20, + 'odometer' => 22, + 'basic_chart' => 23, ]; + $value_process_types = [ + 'max' => 6, + 'min' => 7, + 'avg' => 8, + ] + // Get ID of item type. Skip if it does not exist. if (isset($types[$items_array['type']]) === false) { register_error( @@ -2072,6 +2092,16 @@ if ($action === 'create_demo_data') { $element_values = []; $element_values['type'] = $types[$items_array['type']]; + if ($items_array['type'] == 'value') { + if (isset($items_array['process']) === true && isset($value_process_types[$items_array['process']])) { + $element_values['type'] = $value_process_types[$items_array['process']] + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + } + } + $element_values['id_layout'] = $created_id; if ($items_array['type'] === 'static_image') { @@ -2136,17 +2166,6 @@ if ($action === 'create_demo_data') { } if ($items_array['type'] === 'module_graph') { - if (isset($items_array['image']) === false - || is_string($items_array['image']) === false - ) { - // The above fields are required for this item. - register_error( - DEMO_VISUAL_CONSOLE, - __('Error in %s: image field must be specified for module_graph item type. Skipping creation of item with index %d', $filename, ($item_access_idx - 1)) - ); - continue; - } - if (isset($items_array['agent_name']) === true) { $matched_agents = agents_get_agents( ['nombre' => $items_array['agent_name']], @@ -2219,6 +2238,166 @@ if ($action === 'create_demo_data') { } } + if ($items_array['type'] === 'basic_chart') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + } + + if ($items_array['type'] === 'event_history') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + if (isset($items_array['interval']) === true) { + $element_values['period'] = $items_array['interval']; + } + } + + if ($items_array['type'] === 'odometer') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + } + + if ($items_array['type'] === 'color_cloud') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + } + if ($items_array['type'] === 'icon') { if (isset($items_array['image']) === false || is_string($items_array['image']) === false @@ -2306,6 +2485,57 @@ if ($action === 'create_demo_data') { $element_values['height'] = $items_array['height']; } + // Check here percentile items as height is used for max value + if ($items_array['type'] === 'percentile' || $items_array['type'] === 'bubble' || $items_array['type'] === 'circular_progress_bar' || $items_array['type'] === 'circular_progress_bar_int') { + if (isset($items_array['agent_name']) === true) { + $matched_agents = agents_get_agents( + ['nombre' => $items_array['agent_name']], + ['id_agente'], + 'AR', + [ + 'field' => 'nombre', + 'order' => 'ASC', + ], + false, + 0, + false, + false, + false + ); + $agent_id = $matched_agents[0]['id_agente']; + + if (!($agent_id > 0)) { + continue; + } + + $element_values['id_agent'] = $agent_id; + + if (isset($items_array['module']) === true) { + $module_row = modules_get_agentmodule_id(io_safe_input($items_array['module']), $agent_id); + + $module_id = $module_row['id_agente_modulo']; + + if (!($module_id > 0)) { + continue; + } + + $element_values['id_agente_modulo'] = $module_id; + } + } + + $element_values['border_width'] = 0; + if (isset($items_array['min']) === true) { + $element_values['border_width'] = $items_array['min']; + } + + $element_values['height'] = 100; + if (isset($items_array['max']) === true) { + $element_values['height'] = $items_array['max']; + } + + $element_values['image'] = 'percent'; + } + $id = db_process_sql_insert('tlayout_data', $element_values); if ($id > 0) { From b14c77862e6ad5f283fac1f81c5a8f903ff96b8d Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Sun, 3 Dec 2023 21:43:00 +0100 Subject: [PATCH 146/397] Added new items to visual consoles --- pandora_console/include/ajax/demo_data.ajax.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 8a1c5b740a..af6a2af628 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -2066,6 +2066,7 @@ if ($action === 'create_demo_data') { 'label' => 4, 'icon' => 5, 'bubble' => 9, + 'box' => 12, 'event_history' => 14, 'circular_progress_bar' => 15, 'circular_progress_bar_int' => 16, @@ -2398,6 +2399,16 @@ if ($action === 'create_demo_data') { } } + if ($items_array['type'] === 'box') { + if (isset($items_array['border_color']) === true) { + $element_values['border_color'] = $items_array['border_color']; + } + + if (isset($items_array['fill_color']) === true) { + $element_values['fill_color'] = $items_array['fill_color']; + } + } + if ($items_array['type'] === 'icon') { if (isset($items_array['image']) === false || is_string($items_array['image']) === false @@ -2485,6 +2496,8 @@ if ($action === 'create_demo_data') { $element_values['height'] = $items_array['height']; } + $element_values['show_on_top'] = (isset($items_array['show_on_top']) === true && $items_array['show_on_top'] === true) ? 1 : 0; + // Check here percentile items as height is used for max value if ($items_array['type'] === 'percentile' || $items_array['type'] === 'bubble' || $items_array['type'] === 'circular_progress_bar' || $items_array['type'] === 'circular_progress_bar_int') { if (isset($items_array['agent_name']) === true) { From 55aee67df3aabf01adca549e3f6d66cd82b7632e Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Sun, 3 Dec 2023 23:23:57 +0100 Subject: [PATCH 147/397] Added GIS maps creation --- .../extras/demodata/gis_maps/1-gismap.prd | 16 ++ pandora_console/godmode/setup/demo.php | 36 +++- .../include/ajax/demo_data.ajax.php | 176 +++++++++++++++++- pandora_console/include/constants.php | 13 +- 4 files changed, 223 insertions(+), 18 deletions(-) create mode 100644 pandora_console/extras/demodata/gis_maps/1-gismap.prd diff --git a/pandora_console/extras/demodata/gis_maps/1-gismap.prd b/pandora_console/extras/demodata/gis_maps/1-gismap.prd new file mode 100644 index 0000000000..84016c5279 --- /dev/null +++ b/pandora_console/extras/demodata/gis_maps/1-gismap.prd @@ -0,0 +1,16 @@ +[gis_data] + +name="Demo GIS map" +group="Demo servers" +zoom_level="6" +initial_latitude="40" +initial_longitude="-3" +initial_altitude="0" +default_latitude="40" +default_longitude="-3" +default_altitude="0" + +[gis_layers] + +name[1]="Demo servers" +group[1]="Demo servers" \ No newline at end of file diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index 3707dbe8ca..3cd5f6274f 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -56,6 +56,7 @@ $service_agent_name = get_parameter('service_agent_name', 'demo-global-agent-1') $dir_item_id_map = [ DEMO_CUSTOM_GRAPH => 'graphs', DEMO_NETWORK_MAP => 'network_maps', + DEMO_GIS_MAP => 'gis_maps', DEMO_SERVICE => 'services', DEMO_REPORT => 'reports', DEMO_DASHBOARD => 'dashboards', @@ -65,6 +66,7 @@ $dir_item_id_map = [ $enabled_items = [ 'graphs' => (int) get_parameter('enable_cg', $def_value), 'network_maps' => (int) get_parameter('enable_nm', $def_value), + 'gis_maps' => (int) get_parameter('enable_gis', $def_value), 'services' => (int) get_parameter('enable_services', $def_value), 'reports' => (int) get_parameter('enable_rep', $def_value), 'dashboards' => (int) get_parameter('enable_dashboards', $def_value), @@ -135,6 +137,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { DEMO_AGENT => 'agents', DEMO_SERVICE => 'services', DEMO_NETWORK_MAP => 'network maps', + DEMO_GIS_MAP => 'GIS maps', DEMO_CUSTOM_GRAPH => 'custom graphs', DEMO_REPORT => 'custom reports', DEMO_VISUAL_CONSOLE => 'visual consoles', @@ -233,7 +236,6 @@ if ($display_loading === true || $running_create === true || $running_delete) { $table_aux->size[1] = '50%'; $agent_sel_values = [ - 10 => '10', 30 => '30', 50 => '50', 500 => '500', @@ -370,6 +372,16 @@ if ($display_loading === true || $running_create === true || $running_delete) { ); $table_adv->data['row6'][] = html_print_label_input_block( + __('Create GIS maps'), + html_print_checkbox_switch( + 'enable_gis', + 1, + $enabled_items['gis_maps'], + true + ) + ); + + $table_adv->data['row7'][] = html_print_label_input_block( __('Create custom graphs'), html_print_checkbox_switch( 'enable_cg', @@ -379,7 +391,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row7'][] = html_print_label_input_block( + $table_adv->data['row8'][] = html_print_label_input_block( __('Create reports'), html_print_checkbox_switch( 'enable_rep', @@ -389,7 +401,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row8'][] = html_print_label_input_block( + $table_adv->data['row9'][] = html_print_label_input_block( __('Create visual consoles'), html_print_checkbox_switch( 'enable_vc', @@ -399,7 +411,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row9'][] = html_print_label_input_block( + $table_adv->data['row10'][] = html_print_label_input_block( __('Create dashboards'), html_print_checkbox_switch( 'enable_dashboards', @@ -409,7 +421,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row10'][] = html_print_label_input_block( + $table_adv->data['row11'][] = html_print_label_input_block( __('Demo data plugin agent'), html_print_input_text( 'plugin_agent', @@ -425,7 +437,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row11'][] = html_print_label_input_block( + $table_adv->data['row12'][] = html_print_label_input_block( __('Traps target IP').ui_print_help_tip(__('All demo traps are generated using version 1'), true), html_print_input_text( 'traps_target_ip', @@ -441,7 +453,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row12'][] = html_print_label_input_block( + $table_adv->data['row13'][] = html_print_label_input_block( __('Traps community'), html_print_input_text( 'traps_community', @@ -457,7 +469,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row13'][] = html_print_label_input_block( + $table_adv->data['row14'][] = html_print_label_input_block( __('Tentacle target IP'), html_print_input_text( 'tentacle_target_ip', @@ -473,7 +485,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row14'][] = html_print_label_input_block( + $table_adv->data['row15'][] = html_print_label_input_block( __('Tentacle port'), html_print_input_text( 'tentacle_port', @@ -489,7 +501,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - $table_adv->data['row15'][] = html_print_label_input_block( + $table_adv->data['row16'][] = html_print_label_input_block( __('Tentacle extra options'), html_print_input_text( 'tentacle_extra_options', @@ -593,6 +605,7 @@ if ($display_loading === true || $running_create === true || $running_delete) { $demo_agents_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tagente'); $demo_services_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tservice'); $demo_nm_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tmap'); + $demo_gis_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tgis_map'); $demo_cg_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tgraph'); $demo_rep_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'treport'); $demo_vc_count = (int) db_get_value('count(*)', 'tdemo_data', 'table_name', 'tlayout'); @@ -622,6 +635,9 @@ if ($display_loading === true || $running_create === true || $running_delete) { $table_summary->data[$i][0] = __('Network maps'); $table_summary->data[$i][1] = ($demo_nm_count > 0) ? $demo_nm_count : '-'; $i++; + $table_summary->data[$i][0] = __('GIS maps'); + $table_summary->data[$i][1] = ($demo_gis_count > 0) ? $demo_gis_count : '-'; + $i++; $table_summary->data[$i][0] = __('Custom graphs'); $table_summary->data[$i][1] = ($demo_cg_count > 0) ? $demo_cg_count : '-'; $i++; diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index af6a2af628..50cc0ad6a5 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -58,6 +58,7 @@ if ($action === 'create_demo_data') { 'reports', 'dashboards', 'visual_consoles', + 'gis_maps', ]; $demodata_directory = $config['homedir'].'/extras/demodata/'; @@ -1524,6 +1525,174 @@ if ($action === 'create_demo_data') { register_error(DEMO_NETWORK_MAP, __('No configuration files found or failed to parse files')); } + $gis_count = count($parsed_ini['gis_maps'] ?? []); + if ($gis_count > 0) { + // Enable GIS features + $token = 'activate_gis'; + $activate_gis = db_get_value_filter('value', 'tconfig', ['token' => $token]); + if ($activate_gis === false) { + config_create_value($token, 1); + } else { + config_update_value($token, 1); + } + + // Create GIS maps. + foreach ($parsed_ini['gis_maps'] as $ini_gis_data) { + $filename = $ini_gis_data['filename']; + $gis_data = $ini_gis_data['gis_data']; + $gis_layers = $ini_gis_data['gis_layers']; + + if (isset($gis_data['name']) === false + || is_string($gis_data['name']) === false + || isset($gis_data['group']) === false + || is_string($gis_data['group']) === false + ) { + register_error( + DEMO_GIS_MAP, + __('Error in %s: name and/or group is not specified or does not have a valid format. Skipping GIS map creation', $filename) + ); + continue; + } + + $gis_name = $gis_data['name']; + $gis_group = $gis_data['group']; + $gis_zoom_level = (isset($gis_data['zoom_level']) === true) ? $gis_data['zoom_level'] : '6'; + $gis_initial_latitude = (isset($gis_data['initial_latitude']) === true) ? $gis_data['initial_latitude'] : '0'; + $gis_initial_longitude = (isset($gis_data['initial_longitude']) === true) ? $gis_data['initial_longitude'] : '0'; + $gis_initial_altitude = (isset($gis_data['initial_altitude']) === true) ? $gis_data['initial_altitude'] : '0'; + $gis_default_latitude = (isset($gis_data['default_latitude']) === true) ? $gis_data['default_latitude'] : '0'; + $gis_default_longitude = (isset($gis_data['default_longitude']) === true) ? $gis_data['default_longitude'] : '0'; + $gis_default_altitude = (isset($gis_data['default_altitude']) === true) ? $gis_data['default_altitude'] : '0'; + + $gis_id_group = get_group_or_create_demo_group($gis_group); + + if ($gis_id_group === false) { + // Group could not be created. Skip GIS map creation. + register_error( + DEMO_GIS_MAP, + __('Error in %s: the specified group does not exist in the system and could not be created. Skipping GIS map creation', $filename) + ); + continue; + } + + $values = []; + $values['map_name'] = io_safe_input($gis_name); + $values['group_id'] = $gis_id_group; + $values['zoom_level'] = $gis_zoom_level; + $values['initial_latitude'] = $gis_initial_latitude; + $values['initial_longitude'] = $gis_initial_longitude; + $values['initial_altitude'] = $gis_initial_altitude; + $values['default_latitude'] = $gis_default_latitude; + $values['default_longitude'] = $gis_default_longitude; + $values['default_altitude'] = $gis_default_altitude; + + $id_map = db_process_sql_insert('tgis_map', $values); + + if ($id_map > 0) { + // Register created map in tdemo_data. + $values = [ + 'item_id' => $id_map, + 'table_name' => 'tgis_map', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item creation if could not be registered in tdemo_data. + db_process_sql_delete('tgis_map', ['id_tgis_map' => $id_map]); + + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map %s', $filename, $gis_name) + ); + + continue; + } + } else { + // Network map group could not be created. Skip creation of map. + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map %s', $filename, $gis_name) + ); + continue; + } + + $values = []; + $values['tgis_map_id_tgis_map'] = $id_map; + $values['tgis_map_con_id_tmap_con'] = 1; + + db_process_sql_insert('tgis_map_has_tgis_map_con', $values); + + if (count($gis_layers) > 0) { + $item_access_idx = 1; + + while (1) { + $items_array = []; + foreach ($gis_layers as $key => $value) { + $items_array[$key] = ($value[$item_access_idx] ?? null); + } + + $item_access_idx++; + + $test_empty_array = array_filter($items_array); + + if (empty($test_empty_array) === true) { + break; + } + + $item_values = []; + + $layer_order = $item_access_idx - 2; + + $item_values['tgis_map_id_tgis_map'] = $id_map; + $item_values['layer_stack_order'] = $layer_order; + $item_values['tgrupo_id_grupo'] = -1; + $item_values['view_layer'] = 1; + $item_values['layer_name'] = io_safe_input((isset($items_array['name']) === true) ? $items_array['name'] : 'layer-'-$layer_order); + + if (isset($items_array['group']) === true) { + $layer_id_group = get_group_or_create_demo_group($items_array['group']); + if ($layer_id_group !== false) { + $item_values['tgrupo_id_grupo'] = $layer_id_group; + } + } + + $created_gis_layer_id = db_process_sql_insert('tgis_map_layer', $item_values); + + if ($created_gis_layer_id > 0) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $created_gis_layer_id, + 'table_name' => 'tgis_map_layer', + ]; + $result = (bool) db_process_sql_insert('tdemo_data', $values); + + if ($result === false) { + // Rollback demo item if could not be registered in tdemo_data. + db_process_sql_delete('tgis_map_layer', ['id_tmap_layer' => $created_gis_layer_id]); + + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map item with index %d', $filename, ($item_access_idx - 1)) + ); + + continue; + } + } else { + register_error( + DEMO_GIS_MAP, + __('Uncaught error (source %s): could not create GIS map item with index %d', $filename, ($item_access_idx - 1)) + ); + } + } + } + } + + update_progress($total_items_count, $gis_count, $gis_count); + update_item_checked(DEMO_GIS_MAP); + } else { + register_error(DEMO_GIS_MAP, __('No configuration files found or failed to parse files')); + } + $cg_count = count($parsed_ini['graphs'] ?? []); if ($cg_count > 0) { // Create graphs. @@ -2079,7 +2248,7 @@ if ($action === 'create_demo_data') { 'max' => 6, 'min' => 7, 'avg' => 8, - ] + ]; // Get ID of item type. Skip if it does not exist. if (isset($types[$items_array['type']]) === false) { @@ -2095,7 +2264,7 @@ if ($action === 'create_demo_data') { $element_values['type'] = $types[$items_array['type']]; if ($items_array['type'] == 'value') { if (isset($items_array['process']) === true && isset($value_process_types[$items_array['process']])) { - $element_values['type'] = $value_process_types[$items_array['process']] + $element_values['type'] = $value_process_types[$items_array['process']]; if (isset($items_array['interval']) === true) { $element_values['period'] = $items_array['interval']; @@ -3056,6 +3225,9 @@ if ($action === 'cleanup_demo_data') { 'tagente_estado' => 'id_agente_estado', 'trel_item' => 'id', 'tplugin' => 'id', + 'tgis_data_status' => 'tagente_id_agente', + 'tgis_map' => 'id_tgis_map', + 'tgis_map_layer' => 'id_tmap_layer', ]; $table_id_field = $table_id_field_dict[$item['table_name']]; diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index ff39542202..4a5063ccbf 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -897,9 +897,10 @@ define('LOG_ALERTS', 2); // Demo items IDs. define('DEMO_AGENT', 1); define('DEMO_NETWORK_MAP', 2); -define('DEMO_CUSTOM_GRAPH', 3); -define('DEMO_REPORT', 4); -define('DEMO_SERVICE', 5); -define('DEMO_DASHBOARD', 6); -define('DEMO_VISUAL_CONSOLE', 7); -define('DEMO_PLUGIN', 8); +define('DEMO_GIS_MAP', 3); +define('DEMO_CUSTOM_GRAPH', 4); +define('DEMO_REPORT', 5); +define('DEMO_SERVICE', 6); +define('DEMO_DASHBOARD', 7); +define('DEMO_VISUAL_CONSOLE', 8); +define('DEMO_PLUGIN', 9); From 7892eb5c0c03cc45e6952570e0d95d49a1aeee52 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Sun, 3 Dec 2023 23:52:55 +0100 Subject: [PATCH 148/397] Added log modules --- .../extras/demodata/agents/1-linux.prd | 64 ++++++++++++++++++- .../util/plugin/pandora_demo_agents.pl | 39 +++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/pandora_console/extras/demodata/agents/1-linux.prd b/pandora_console/extras/demodata/agents/1-linux.prd index 35d76f3f79..aaec5cd6ad 100644 --- a/pandora_console/extras/demodata/agents/1-linux.prd +++ b/pandora_console/extras/demodata/agents/1-linux.prd @@ -146,4 +146,66 @@ total_size[3]="819M" mount_point[1]="/home" mount_point[2]="/" -mount_point[3]="/tmp" \ No newline at end of file +mount_point[3]="/tmp" + +[log_modules] + +source[1]="httpd" +data[1]='127.0.0.1 - "GET /index.html HTTP/1.1" 200 3456 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[2]="httpd" +data[2]='192.168.1.1 - "POST /submit.php HTTP/1.1" 302 0 "https://example.com/form" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[3]="httpd" +data[3]='10.0.0.2 - "GET /images/logo.png HTTP/1.1" 304 0 "-" "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.1 Mobile/15E148 Safari/604.1"' + +source[4]="httpd" +data[4]='172.16.0.1 - "GET /page/about-us HTTP/1.1" 404 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[5]="httpd" +data[5]='192.168.0.10 - "GET /css/style.css HTTP/1.1" 200 768 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[6]="httpd" +data[6]='203.0.113.45 - "GET /blog/post-123 HTTP/1.1" 200 5432 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[7]="httpd" +data[7]='54.78.90.12 - "GET /category/api-reference HTTP/1.1" 200 6543 "-" "Mozilla/5.0 (Linux; Android 10; SM-G960U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.181 Mobile Safari/537.36"' + +source[8]="httpd" +data[8]='88.77.66.55 - "GET /contact-us HTTP/1.1" 301 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[9]="httpd" +data[9]='198.51.100.23 - "GET /images/photo.jpg HTTP/1.1" 200 4567 "https://example.com/gallery" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[10]="httpd" +data[10]='128.0.0.1 - "GET /downloads/file.zip HTTP/1.1" 200 12345 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36"' + +source[11]="mysqld" +data[11]="[Warning] Aborted connection 123 to db: 'your_database' user: 'your_user' host: '192.168.1.100' (Got an error reading communication packets)" + +source[12]="mysqld" +data[12]="[ERROR] Table 'your_database.your_table' doesn't exist" + +source[13]="mysqld" +data[13]="[Note] Starting crash recovery..." + +source[14]="mysqld" +data[14]="[Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. Statement is unsafe because it uses a LIMIT clause. Use a different log bin event type." + +source[15]="mysqld" +data[15]="[ERROR] Out of memory; check if mysqld or some other process uses all available memory; if not, you may have to use 'ulimit' to allow mysqld to use more memory or you can add more swap space" + +source[16]="mysqld" +data[16]="[Note] Aborted connection 456 to db: 'another_database' user: 'another_user' host: 'localhost' (Got timeout reading communication packets)" + +source[17]="mysqld" +data[17]="[ERROR] Can't create a new thread (errno 11); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug" + +source[18]="mysqld" +data[18]="[Warning] 'user' entry 'your_user@localhost' ignored in --skip-name-resolve mode." + +source[19]="mysqld" +data[19]="[Note] InnoDB: Starting rollback of uncommitted transactions" + +source[20]="mysqld" +data[20]="[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed." \ No newline at end of file diff --git a/pandora_server/util/plugin/pandora_demo_agents.pl b/pandora_server/util/plugin/pandora_demo_agents.pl index d58472aa66..88ec91bf2c 100644 --- a/pandora_server/util/plugin/pandora_demo_agents.pl +++ b/pandora_server/util/plugin/pandora_demo_agents.pl @@ -197,6 +197,19 @@ sub parse_ini_file { $ini_data{'inventory_values'} = {}; } + # Initialize log modules keys + if(!defined($ini_data{'log_modules'})) { + $ini_data{'log_modules'} = {}; + } + + if(!defined($ini_data{'log_modules'}{'source'})) { + $ini_data{'log_modules'}{'source'} = {}; + } + + if(!defined($ini_data{'log_modules'}{'data'})) { + $ini_data{'log_modules'}{'data'} = {}; + } + # Initialize traps keys if(!defined($ini_data{'traps'})) { $ini_data{'traps'} = {}; @@ -518,6 +531,32 @@ sub generate_agent($) { $xml .= "\n"; } + # Append log module data to XML (only once a day at 00:00) + if (!empty($sorted_ini[$current_ini]->{'log_modules'}->{'source'}) && !empty($sorted_ini[$current_ini]->{'log_modules'}->{'data'})) { + + # Remove agent_data closing tag + $xml =~ s/<\/agent_data>//i; + + # Add log modules for each source + foreach my $log_source (sort keys %{$sorted_ini[$current_ini]->{'log_modules'}->{'source'}}) { + # Only if data is defined + if(defined($sorted_ini[$current_ini]->{'log_modules'}->{'data'}->{$log_source})) { + # Add log module 50% of times + if(get_bool(50)) { + my $log_data = $sorted_ini[$current_ini]->{'log_modules'}->{'data'}->{$log_source}; + + $xml .= "\n"; + $xml .= "\t\n"; + $xml .= "\t\n"; + $xml .= "\n"; + } + } + } + + # Close agent_data tag again + $xml .= "\n"; + } + # Get file name MD5 my $file_md5 = md5_hex($agent->{'agent_name'}); From 988841084c0a1a0d5eae40dd15956ba066a125f3 Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Mon, 4 Dec 2023 00:00:41 +0100 Subject: [PATCH 149/397] Fixed log modules generation --- pandora_server/util/plugin/pandora_demo_agents.pl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandora_server/util/plugin/pandora_demo_agents.pl b/pandora_server/util/plugin/pandora_demo_agents.pl index 88ec91bf2c..a746d6969f 100644 --- a/pandora_server/util/plugin/pandora_demo_agents.pl +++ b/pandora_server/util/plugin/pandora_demo_agents.pl @@ -538,12 +538,13 @@ sub generate_agent($) { $xml =~ s/<\/agent_data>//i; # Add log modules for each source - foreach my $log_source (sort keys %{$sorted_ini[$current_ini]->{'log_modules'}->{'source'}}) { + foreach my $log_key (sort keys %{$sorted_ini[$current_ini]->{'log_modules'}->{'source'}}) { # Only if data is defined - if(defined($sorted_ini[$current_ini]->{'log_modules'}->{'data'}->{$log_source})) { + if(defined($sorted_ini[$current_ini]->{'log_modules'}->{'data'}->{$log_key})) { # Add log module 50% of times if(get_bool(50)) { - my $log_data = $sorted_ini[$current_ini]->{'log_modules'}->{'data'}->{$log_source}; + my $log_source = $sorted_ini[$current_ini]->{'log_modules'}->{'source'}->{$log_key}; + my $log_data = $sorted_ini[$current_ini]->{'log_modules'}->{'data'}->{$log_key}; $xml .= "\n"; $xml .= "\t\n"; From cc1c138552271abbcf2804f6bce13e46dc19df73 Mon Sep 17 00:00:00 2001 From: Jorge Rincon Date: Mon, 4 Dec 2023 11:23:43 +0100 Subject: [PATCH 150/397] #12518 Fixed up custom field type link --- pandora_console/operation/agentes/estado_generalagente.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index dd4effe693..6e6615df51 100755 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -298,8 +298,9 @@ foreach ($fields as $field) { if ($custom_value[0]['is_password_type']) { $data[1] = '••••••••'; } else if ($field['is_link_enabled'] === '1') { - list($link_text, $link_url) = json_decode($custom_value[0]['description'], true); - + $custom_link_type = io_safe_output($custom_value[0]['description']); + $custom_link_type = json_decode($custom_link_type); + list($link_text, $link_url) = $custom_link_type; if (json_last_error() !== JSON_ERROR_NONE) { $link_text = ''; $link_url = ''; @@ -309,7 +310,7 @@ foreach ($fields as $field) { $link_text = $link_url; } - $data[1] = ''.$link_text.''; + $data[1] = ''.$link_text.''; } else { $custom_value[0]['description'] = ui_bbcode_to_html($custom_value[0]['description']); $data[1] = $custom_value[0]['description']; From 7125fd9a8fb0e8fd6f4e2d53c251109ca21eece2 Mon Sep 17 00:00:00 2001 From: rafael Date: Mon, 4 Dec 2023 11:26:50 +0100 Subject: [PATCH 151/397] change package links --- .../pandora_deploy_community_ubuntu_2204.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh index 5f240b0a41..c5c8edbb34 100644 --- a/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh +++ b/extras/deploy-scripts/pandora_deploy_community_ubuntu_2204.sh @@ -520,18 +520,18 @@ execute_cmd "systemctl restart mysql" "Configuring and restarting database engin #Define packages if [ "$PANDORA_LTS" -eq '1' ] ; then - [ "$PANDORA_SERVER_PACKAGE" ] || PANDORA_SERVER_PACKAGE="http://firefly.pandorafms.com/pandorafms/latest/Tarball/LTS/pandorafms_server-7.0NG.tar.gz" - [ "$PANDORA_CONSOLE_PACKAGE" ] || PANDORA_CONSOLE_PACKAGE="http://firefly.pandorafms.com/pandorafms/latest/Tarball/LTS/pandorafms_console-7.0NG.tar.gz" + [ "$PANDORA_SERVER_PACKAGE" ] || PANDORA_SERVER_PACKAGE="https://firefly.pandorafms.com/pandorafms/latest/Tarball/LTS/pandorafms_server-7.0NG.tar.gz" + [ "$PANDORA_CONSOLE_PACKAGE" ] || PANDORA_CONSOLE_PACKAGE="https://firefly.pandorafms.com/pandorafms/latest/Tarball/LTS/pandorafms_console-7.0NG.tar.gz" [ "$PANDORA_AGENT_PACKAGE" ] || PANDORA_AGENT_PACKAGE="https://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_agent_linux-7.0NG.x86_64.tar.gz" elif [ "$PANDORA_LTS" -ne '1' ] ; then - [ "$PANDORA_SERVER_PACKAGE" ] || PANDORA_SERVER_PACKAGE="http://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_server-7.0NG.tar.gz" - [ "$PANDORA_CONSOLE_PACKAGE" ] || PANDORA_CONSOLE_PACKAGE="http://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_console-7.0NG.tar.gz" + [ "$PANDORA_SERVER_PACKAGE" ] || PANDORA_SERVER_PACKAGE="https://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_server-7.0NG.tar.gz" + [ "$PANDORA_CONSOLE_PACKAGE" ] || PANDORA_CONSOLE_PACKAGE="https://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_console-7.0NG.tar.gz" [ "$PANDORA_AGENT_PACKAGE" ] || PANDORA_AGENT_PACKAGE=" https://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_agent_linux-7.0NG.x86_64.tar.gz" fi if [ "$PANDORA_BETA" -eq '1' ] ; then - PANDORA_SERVER_PACKAGE="http://firefly.pandorafms.com/pandora_enterprise_nightlies/pandorafms_server-latest.tar.gz" - PANDORA_CONSOLE_PACKAGE="http://firefly.pandorafms.com/pandora_enterprise_nightlies/pandorafms_console-latest.tar.gz" + PANDORA_SERVER_PACKAGE="https://firefly.pandorafms.com/pandora_enterprise_nightlies/pandorafms_server-latest.tar.gz" + PANDORA_CONSOLE_PACKAGE="https://firefly.pandorafms.com/pandora_enterprise_nightlies/pandorafms_console-latest.tar.gz" PANDORA_AGENT_PACKAGE="https://firefly.pandorafms.com/pandorafms/latest/Tarball/pandorafms_agent_linux-7.0NG.x86_64.tar.gz" fi @@ -837,7 +837,7 @@ echo "@hourly root bash -c /etc/cron.hourly/pandora_db" >> /etc/cront ## Enabling agent adn configuring Agente sed -i "s/^remote_config.*$/remote_config 1/g" $PANDORA_AGENT_CONF &>> "$LOGFILE" -execute_cmd "/etc/init.d/pandora_agent_daemon start" "Starting PandoraFSM Agent" +execute_cmd "/etc/init.d/pandora_agent_daemon restart" "Starting PandoraFSM Agent" systemctl enable pandora_agent_daemon &>> "$LOGFILE" #fix path phantomjs From 75ddb3b934d4c656344895b5d03324ce371a776d Mon Sep 17 00:00:00 2001 From: "alejandro.campos@artica.es" Date: Mon, 4 Dec 2023 11:37:12 +0100 Subject: [PATCH 152/397] minor changes in demo data functionality --- pandora_console/godmode/setup/demo.php | 47 ----------- .../include/ajax/demo_data.ajax.php | 83 ++++++++++++------- .../include/class/WelcomeWindow.class.php | 63 ++++++++++++-- 3 files changed, 109 insertions(+), 84 deletions(-) diff --git a/pandora_console/godmode/setup/demo.php b/pandora_console/godmode/setup/demo.php index 3707dbe8ca..90f7281db7 100644 --- a/pandora_console/godmode/setup/demo.php +++ b/pandora_console/godmode/setup/demo.php @@ -233,7 +233,6 @@ if ($display_loading === true || $running_create === true || $running_delete) { $table_aux->size[1] = '50%'; $agent_sel_values = [ - 10 => '10', 30 => '30', 50 => '50', 500 => '500', @@ -505,52 +504,6 @@ if ($display_loading === true || $running_create === true || $running_delete) { ) ); - /* $table_adv->data['row8'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['dashboards'], - true - ) - ); - $table_adv->data['row8'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['dashboards'], - true - ) - ); - $table_adv->data['row8'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['dashboards'], - true - ) - ); - $table_adv->data['row8'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['dashboards'], - true - ) - ); - $table_adv->data['row8'][] = html_print_label_input_block( - __('Create dashboards'), - html_print_checkbox_switch( - 'enable_dashboards', - 1, - $enabled_items['dashboards'], - true - ) - );*/ - echo ''; echo '
    '; echo ''.__('Configure demo data').''; diff --git a/pandora_console/include/ajax/demo_data.ajax.php b/pandora_console/include/ajax/demo_data.ajax.php index 5a50eb4979..3054f72d35 100644 --- a/pandora_console/include/ajax/demo_data.ajax.php +++ b/pandora_console/include/ajax/demo_data.ajax.php @@ -134,6 +134,7 @@ if ($action === 'create_demo_data') { $agent_created_total = 0; $agent_data_values_buffer = []; + $agent_traps_values_buffer = []; if ($total_agents_to_create > 0 && $agents_to_create > 0) { while ($agent_created_total < ($total_agents_to_create - 1)) { @@ -798,35 +799,8 @@ if ($action === 'create_demo_data') { 'utimestamp' => $utimestamp, ]; - $created_trap_id = db_process_sql_insert('ttrap', $values); - - if ($created_trap_id > 0) { - // Register created demo item in tdemo_data. - $values = [ - 'item_id' => $created_trap_id, - 'table_name' => 'ttrap', - ]; - $result = (bool) db_process_sql_insert('tdemo_data', $values); - - if ($result === false) { - // Rollback inventory module if could not be registered in tdemo_data. - db_process_sql_delete('ttrap', ['id_module_inventory' => $created_trap_id]); - - register_error( - DEMO_AGENT, - __('Uncaught error (source %s): could not create trap with index %d', $filename, ($trap_access_idx - 1)), - true - ); - - continue; - } - } else { - register_error( - DEMO_AGENT, - __('Uncaught error (source %s): could not create trap with index %d', $filename, ($trap_access_idx - 1)), - true - ); - } + // Buffer history traps for later bulk insertion (performance reasons). + $agent_traps_values_buffer[] = $values; } if ($adv_options_is_enabled === false @@ -850,10 +824,11 @@ if ($action === 'create_demo_data') { } } - $agent_data_values_buffer_chunks = array_chunk($agent_data_values_buffer, 1000); + $agent_data_values_buffer_chunks = array_chunk($agent_data_values_buffer, 100000); + $agent_traps_values_buffer_chunks = array_chunk($agent_traps_values_buffer, 100000); foreach ($agent_data_values_buffer_chunks as $chunk) { - // Bulk inserts. + // Bulk inserts (insert batches of up to 100,000 as a performance limit). mysql_db_process_sql_insert_multiple( 'tagente_datos', $chunk, @@ -861,6 +836,52 @@ if ($action === 'create_demo_data') { ); } + // Get last trap in database. + $id_trap_begin = db_get_value( + 'MAX(id_trap)', + 'ttrap', + 1, + 1, + false, + false + ); + + if ($id_trap_begin === false) { + $id_trap_begin = 0; + } + + foreach ($agent_traps_values_buffer_chunks as $chunk) { + // Bulk inserts (insert batches of up to 100,000 as a performance limit). + mysql_db_process_sql_insert_multiple( + 'ttrap', + $chunk, + false + ); + } + + // Get last trap in database after insertion. + $id_trap_end = db_get_value( + 'MAX(id_trap)', + 'ttrap', + 1, + 1, + false, + false + ); + + if ($id_trap_end === false) { + $id_trap_end = 0; + } + + for ($i = ($id_trap_begin + 1); $i <= $id_trap_end; $i++) { + // Register created demo item in tdemo_data. + $values = [ + 'item_id' => $i, + 'table_name' => 'ttrap', + ]; + db_process_sql_insert('tdemo_data', $values); + } + update_item_checked(DEMO_AGENT); } } diff --git a/pandora_console/include/class/WelcomeWindow.class.php b/pandora_console/include/class/WelcomeWindow.class.php index b51e753048..638ecf78b4 100644 --- a/pandora_console/include/class/WelcomeWindow.class.php +++ b/pandora_console/include/class/WelcomeWindow.class.php @@ -699,6 +699,45 @@ class WelcomeWindow extends Wizard echo html_print_submit_button(__('Create'), 'create_goliat', false, ['icon' => 'next', 'style' => 'margin-top:15px; float:right;']); ?> +