From 76327c6d737be80d2c7411b66d61ca2e5fc7cf9a Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 30 Nov 2023 08:54:21 +0100 Subject: [PATCH 1/2] 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 3807baa8ef46ac4ea4a8a146e3a0419360ffd87f Mon Sep 17 00:00:00 2001 From: Enrique Martin Date: Thu, 30 Nov 2023 17:41:01 +0100 Subject: [PATCH 2/2] 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++;