From 13884a44d6e74482924494044ee298387353d108 Mon Sep 17 00:00:00 2001 From: danielmaya Date: Mon, 29 Jan 2018 16:48:21 +0100 Subject: [PATCH] Added clustermap --- .../godmode/reporting/cluster_view.php | 534 +++++++++++++++++- .../godmode/reporting/cluster_view_2.php | 462 --------------- .../include/functions_clusters.php | 9 +- pandora_console/include/functions_os.php | 4 + 4 files changed, 518 insertions(+), 491 deletions(-) delete mode 100644 pandora_console/godmode/reporting/cluster_view_2.php diff --git a/pandora_console/godmode/reporting/cluster_view.php b/pandora_console/godmode/reporting/cluster_view.php index 363a5a0c9f..47b33cb3ef 100644 --- a/pandora_console/godmode/reporting/cluster_view.php +++ b/pandora_console/godmode/reporting/cluster_view.php @@ -12,7 +12,9 @@ if (! check_acl ($config['id_user'], 0, "AR")) { } require_once ('include/functions_agents.php'); -require_once('include/functions_clusters.php'); +require_once ('include/functions_modules.php'); +require_once ('include/functions_clusters.php'); +require_once ('enterprise/include/functions_clustermap.php'); $id_cluster = get_parameter('id',0); @@ -28,49 +30,525 @@ $buttons['editor'] = array('active' => false, ui_print_page_header ( __("Cluster detail").' » '.clusters_get_name($id_cluster), "images/agent_mc.png", false, "agent_status", false, $buttons); - +$font_size = 10; +$width = "100%"; +$height = "600"; +$node_radius = 40; +$baseurl = ui_get_full_url(false, false, false, false); echo ""; echo ""; - echo ""; - echo ""; echo ""; echo ""; - echo ""; + echo ""; echo ""; echo "
"; - echo "
"; + $cluster_type = clusters_get_cluster_id_type($id_cluster); + + + if($cluster_type[$id_cluster] == 'AP'){ + + echo "
"; + + } + else{ + + echo ""; + + } + + echo "
"; + echo ''; + + echo '
'; echo "
"; - - echo "
"; - // - // echo "
".__('CLUSTER STATUS')."
"; - // echo "
"; - // - // echo "
"; - + echo "
"; + + echo "
"; + + echo "
".__('CLUSTER STATUS')."
"; + + $cluster_module = db_process_sql('select id_agente_modulo from tagente_modulo where id_agente = (select id_agent from tcluster where id = '.$id_cluster.') and nombre = "Cluster status"'); + + $cluster_module_status = modules_get_agentmodule_last_status($cluster_module[0]['id_agente_modulo']); + + switch ($cluster_module_status) { + case 1: + + echo "
+ +
+ +
"; + + break; + case 2: + + echo "
+ +
+ +
"; + + break; + case 4: + + echo "
+ +
+ +
"; + + break; + case 3: + + echo "
+ +
+ +
"; + + break; + case 5: + + echo "
+ +
+ +
"; + + break; + case 0: + + echo "
+ +
+ +
"; + + break; + + default: + + break; + } + + + + + if($cluster_type[$id_cluster] == 'AP'){ + + + echo "
"; + + echo "
".__('Balanced modules')."
"; + + echo "
"; + + $balanced_modules_in = items_get_cluster_items_id_name($id_cluster,'AP'); + + foreach ($balanced_modules_in as $key => $value) { + $cluster_module = db_process_sql('select id_agente_modulo from tagente_modulo where custom_integer_2 = '.$key); + + $cluster_module_status = modules_get_agentmodule_last_status($cluster_module[0]['id_agente_modulo']); + + echo "
"; + + if($cluster_module_status == 5){ + echo '
'.ui_print_truncate_text($value, 40,false).'
'; + } + else{ + echo '
'.ui_print_truncate_text($value, 40,false).'
'; + } + + echo '
'; + + } + + echo "
"; + + echo "
"; + echo "
"; - - echo "
"; - // - // echo "
".__('LAST UPDATE')."
"; - // echo "
88 Hours 88 Min 88 sec ago
"; - - echo "
"; - - - + + } + + echo "
"; + + $last_update = db_process_sql('select timestamp from tagente_estado where id_agente_modulo = '.$cluster_module[0]['id_agente_modulo']); + + $last_update_value = $last_update[0]['timestamp']; + + echo "
".__('LAST UPDATE')."
"; + echo "
".$last_update_value."
"; + + echo "
"; + + echo "
".__('Common modules')."
"; + + echo "
"; + + $modules_in = items_get_cluster_items_id_name($id_cluster,'AA'); + + foreach ($modules_in as $key => $value) { + $cluster_module = db_process_sql('select id_agente_modulo from tagente_modulo where custom_integer_2 = '.$key); + + $cluster_module_status = modules_get_agentmodule_last_status($cluster_module[0]['id_agente_modulo']); + + echo "
"; + + if($cluster_module_status == 5){ + echo '
'.ui_print_truncate_text($value, 40,false).'
'; + } + else{ + echo '
'.ui_print_truncate_text($value, 40,false).'
'; + } + + echo '
'; + + } + + echo "
"; + + echo "
"; + + echo "
"; + + + echo "
"; + + $id_agent = db_process_sql('select id_agent from tcluster where id = '.$id_cluster); + + $id_agent_value = $id_agent[0]['id_agent']; + + $table = new stdClass(); + $table->id = 'agent_details'; + $table->width = '100%'; + $table->cellspacing = 0; + $table->cellpadding = 0; + $table->class = 'agents'; + $table->style = array_fill(0, 3, 'vertical-align: top;'); + + $data = array(); + $data[0][0] = html_print_table($table_agent, true); + $data[0][0] .= + '
+ ' . + '' . + '
' . + __('Events (24h)') . + '

' . + graph_graphic_agentevents ($id_agent_value, 450, 40, SECONDS_1DAY, '', true, true) . + '
'; + + $table->style[0] = 'width:100%; vertical-align:top;'; + $data[0][1] = html_print_table($table_contact, true); + $data[0][1] .= empty($table_data->data) ? + '' : + '
' . html_print_table($table_data, true); + $data[0][1] .= !isset($table_incident) ? + '' : + '
' . html_print_table($table_incident, true); + + $table->rowspan[1][0] = 0; + + $table->data = $data; + $table->rowclass[] = ''; + + $table->cellstyle[1][0] = 'text-align:center;'; + + html_print_table($table); + $data2[1][0] = !isset($table_interface) ? + '' : + html_print_table($table_interface, true); + $table->data = $data2; + $table->styleTable = ''; + html_print_table($table); + + unset($table); + + echo "
"; + echo "
-
-
"; + echo "
"; + echo "
"; + echo "
"; +$id_agent = db_process_sql('select id_agent from tcluster where id = '.$id_cluster); -echo 'El estado del modulo del cluster '.clusters_get_name($id_cluster).' es '.agents_get_status(40); +$id_agent_value = $id_agent[0]['id_agent']; -?> \ No newline at end of file + +ui_require_css_file ('cluetip'); +ui_require_jquery_file ('cluetip'); + +echo ""; + +ui_include_time_picker(); +ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); + + +$layout = "fdp"; + +$graph = cluster_create_map($layout, $font_size, $zoom , $id_cluster); + +if ($graph === false) { + ui_print_error_message (__('Map could not be generated')); + echo '
' . __('No agents found') . '
'; + return; +} + +// Generate image and map +// If image was generated just a few minutes ago, then don't regenerate (it takes long) unless regen checkbox is set +$filename_map = safe_url_extraclean ($config["attachment_store"])."/vmware_map_" . $config['id_user']; +$filename_img = "attachment/vmware_map_" . $config['id_user']; +$filename_dot = safe_url_extraclean ($config["attachment_store"])."/vmware_map_" . $config['id_user']; + +$filename_map .= ".map"; +$filename_img .= ".png"; +$filename_dot .= ".dot"; + +$filename_plain = sys_get_temp_dir() . "/plain.txt"; + +file_put_contents($filename_dot, $graph); + +$cmd = "$layout -Tcmapx -o".$filename_map." -Tplain -o".$filename_plain." ".$filename_dot; + +system ($cmd); + +unlink($filename_dot); + +$nodes = cluster_loadfile($filename_plain, $graph); + + +foreach ($nodes['nodes'] as $key => $node) { + if ($node['id'] !== '1') { + $sql_AP = "SELECT am.nombre, am.id_agente_modulo, am.post_process, ae.datos, ae.estado FROM tagente_modulo am + INNER JOIN tagente_estado ae ON am.id_agente_modulo = ae.id_agente_modulo + WHERE nombre IN (SELECT name FROM tcluster_item WHERE id_cluster = $id_cluster AND item_type like 'AP') AND am.id_agente = $node[id_agent]"; + + $modules_AP = db_get_all_rows_sql ($sql_AP); + + if ($modules_AP) { + $nodes['nodes'][$key]['passive'] = 1; + } + } +} + +?> + +" . "\n"; +} + +echo '' . "\n"; + +?> + + \ No newline at end of file diff --git a/pandora_console/godmode/reporting/cluster_view_2.php b/pandora_console/godmode/reporting/cluster_view_2.php deleted file mode 100644 index fe6f595f36..0000000000 --- a/pandora_console/godmode/reporting/cluster_view_2.php +++ /dev/null @@ -1,462 +0,0 @@ - false, - 'text' => '' . - html_print_image("images/list.png", true, array ("title" => __('Clusters list'))) .''); - - -$buttons['editor'] = array('active' => false, - 'text' => '' . - html_print_image("images/gm_setup.png", true, array ("title" => __('Cluster editor'))) .''); - - -ui_print_page_header ( __("Cluster detail").' » '.clusters_get_name($id_cluster), "images/agent_mc.png", false, "agent_status", false, $buttons); - - - -echo ""; - echo ""; - - $cluster_type = clusters_get_cluster_id_type($id_cluster); - - - if($cluster_type[$id_cluster] == 'AP'){ - - echo ""; - - echo ""; - - echo ""; - - echo ""; - echo ""; - echo ""; -echo "
"; - - } - else{ - - echo ""; - - } - - echo "
"; - echo "
"; - - echo "
"; - - echo "
".__('CLUSTER STATUS')."
"; - - $cluster_module = db_process_sql('select id_agente_modulo from tagente_modulo where id_agente = (select id_agent from tcluster where id = '.$id_cluster.') and nombre = "Cluster status"'); - - $cluster_module_status = modules_get_agentmodule_last_status($cluster_module[0]['id_agente_modulo']); - - switch ($cluster_module_status) { - case 1: - - echo "
- -
- -
"; - - break; - case 2: - - echo "
- -
- -
"; - - break; - case 4: - - echo "
- -
- -
"; - - break; - case 3: - - echo "
- -
- -
"; - - break; - case 5: - - echo "
- -
- -
"; - - break; - case 0: - - echo "
- -
- -
"; - - break; - - default: - - break; - } - - - - - if($cluster_type[$id_cluster] == 'AP'){ - - - echo "
"; - - echo "
".__('Balanced modules')."
"; - - echo "
"; - - $balanced_modules_in = items_get_cluster_items_id_name($id_cluster,'AP'); - - foreach ($balanced_modules_in as $key => $value) { - $cluster_module = db_process_sql('select id_agente_modulo from tagente_modulo where custom_integer_2 = '.$key); - - $cluster_module_status = modules_get_agentmodule_last_status($cluster_module[0]['id_agente_modulo']); - - echo "
"; - - if($cluster_module_status == 5){ - echo '
'.ui_print_truncate_text($value, 40,false).'
'; - } - else{ - echo '
'.ui_print_truncate_text($value, 40,false).'
'; - } - - echo '
'; - - } - - echo "
"; - - echo "
"; - - echo "
"; - - } - - - echo "
"; - - $last_update = db_process_sql('select timestamp from tagente_estado where id_agente_modulo = '.$cluster_module[0]['id_agente_modulo']); - - $last_update_value = $last_update[0]['timestamp']; - - echo "
".__('LAST UPDATE')."
"; - echo "
".$last_update_value."
"; - - echo "
"; - - echo "
".__('Common modules')."
"; - - echo "
"; - - $modules_in = items_get_cluster_items_id_name($id_cluster,'AA'); - - foreach ($modules_in as $key => $value) { - $cluster_module = db_process_sql('select id_agente_modulo from tagente_modulo where custom_integer_2 = '.$key); - - $cluster_module_status = modules_get_agentmodule_last_status($cluster_module[0]['id_agente_modulo']); - - echo "
"; - - if($cluster_module_status == 5){ - echo '
'.ui_print_truncate_text($value, 40,false).'
'; - } - else{ - echo '
'.ui_print_truncate_text($value, 40,false).'
'; - } - - echo '
'; - - } - - echo "
"; - - echo "
"; - - echo "
"; - - - echo "
"; - - $id_agent = db_process_sql('select id_agent from tcluster where id = '.$id_cluster); - - $id_agent_value = $id_agent[0]['id_agent']; - - $table = new stdClass(); - $table->id = 'agent_details'; - $table->width = '100%'; - $table->cellspacing = 0; - $table->cellpadding = 0; - $table->class = 'agents'; - $table->style = array_fill(0, 3, 'vertical-align: top;'); - - $data = array(); - $data[0][0] = html_print_table($table_agent, true); - $data[0][0] .= - '
- ' . - '' . - '
' . - __('Events (24h)') . - '

' . - graph_graphic_agentevents ($id_agent_value, 450, 40, SECONDS_1DAY, '', true, true) . - '
'; - - $table->style[0] = 'width:100%; vertical-align:top;'; - $data[0][1] = html_print_table($table_contact, true); - $data[0][1] .= empty($table_data->data) ? - '' : - '
' . html_print_table($table_data, true); - $data[0][1] .= !isset($table_incident) ? - '' : - '
' . html_print_table($table_incident, true); - - $table->rowspan[1][0] = 0; - - $table->data = $data; - $table->rowclass[] = ''; - - $table->cellstyle[1][0] = 'text-align:center;'; - - html_print_table($table); - $data2[1][0] = !isset($table_interface) ? - '' : - html_print_table($table_interface, true); - $table->data = $data2; - $table->styleTable = ''; - html_print_table($table); - - unset($table); - - echo "
"; - - - echo "
"; - echo "
"; - echo "
"; - echo "
"; - -$id_agent = db_process_sql('select id_agent from tcluster where id = '.$id_cluster); - -$id_agent_value = $id_agent[0]['id_agent']; - -ui_require_css_file ('cluetip'); -ui_require_jquery_file ('cluetip'); - -echo ""; - -ui_include_time_picker(); -ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); - -?> - - \ No newline at end of file diff --git a/pandora_console/include/functions_clusters.php b/pandora_console/include/functions_clusters.php index 6f009dc553..b59607b377 100644 --- a/pandora_console/include/functions_clusters.php +++ b/pandora_console/include/functions_clusters.php @@ -204,7 +204,14 @@ function clusters_get_user ($id_user = 0, $only_names = false, $returnAllGroup = return $clusters; } - +function cluster_get_status ($id_agente){ + $sql = sprintf("SELECT known_status FROM tagente_estado ae + INNER JOIN tagente_modulo am ON ae.id_agente_modulo = am.id_agente_modulo + WHERE am.nombre = 'Cluster status' AND am.id_agente = %d",$id_agente); + + $status = db_get_all_rows_sql($sql); + return $status; +} ?> \ No newline at end of file diff --git a/pandora_console/include/functions_os.php b/pandora_console/include/functions_os.php index 8862b87db7..f9f7e407ec 100755 --- a/pandora_console/include/functions_os.php +++ b/pandora_console/include/functions_os.php @@ -74,4 +74,8 @@ function os_get_os() { return $op_systems; } + +function os_get_icon($id_os) { + return db_get_value ('icon_name', 'tconfig_os', 'id_os', (int) $id_os); +} ?>