diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 34e33cd06b..a63f23145b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,23 @@ +2012-07-06 Miguel de Dios + + * godmode/reporting/visual_console_builder.editor.js, + godmode/reporting/visual_console_builder.elements.php, + include/functions_visual_map.php, + include/ajax/visual_console_builder.ajax.php, + include/functions_visual_map_editor.php: uploaded some fixes and + changes for the visualmap, for example refactored some part of + print the visualmap in operation. + + * include/functions_html.php: fixed when included from standarlone + file from enterprise structure directory. + + * include/constants.php: added constants for avoid magic numbers + into the code of Visualmaps. + + * include/graphs/functions_gd.php, include/functions.php, + include/functions_io.php, include/functions_modules.php, + include/functions_ui.php: cleaned source code style. + 2012-07-06 Sergio Martin * pandoradb.sql diff --git a/pandora_console/godmode/reporting/visual_console_builder.editor.js b/pandora_console/godmode/reporting/visual_console_builder.editor.js index b809ab2b84..1c6dbcfc55 100644 --- a/pandora_console/godmode/reporting/visual_console_builder.editor.js +++ b/pandora_console/godmode/reporting/visual_console_builder.editor.js @@ -49,7 +49,6 @@ function visual_map_main() { draw_lines(lines, 'background', true); } ); - } function eventsTextAgent() { @@ -681,6 +680,10 @@ function hiddenFields(item) { $("#module_graph_size_row").css('display', 'none'); $("#module_graph_size_row." + item).css('display', ''); + + if (typeof(enterprise_hiddenFields) == 'function') { + enterprise_hiddenFields(item); + } } function cleanFields() { diff --git a/pandora_console/godmode/reporting/visual_console_builder.elements.php b/pandora_console/godmode/reporting/visual_console_builder.elements.php index d2abd6a8b8..df6559042c 100644 --- a/pandora_console/godmode/reporting/visual_console_builder.elements.php +++ b/pandora_console/godmode/reporting/visual_console_builder.elements.php @@ -45,9 +45,6 @@ foreach ($all_images as $image_file) { $images_list[$image_file] = $image_file; } -$layoutDataTypes = visual_map_get_layout_data_types(); - - $table->width = '100%'; $table->head = array (); $table->head['icon'] = ''; diff --git a/pandora_console/include/ajax/visual_console_builder.ajax.php b/pandora_console/include/ajax/visual_console_builder.ajax.php index 6b50f1e9b8..ba00cfd6cc 100644 --- a/pandora_console/include/ajax/visual_console_builder.ajax.php +++ b/pandora_console/include/ajax/visual_console_builder.ajax.php @@ -499,6 +499,9 @@ switch ($action) { echo json_encode($size); break; + default: + enterprise_hook("enterprise_visualmap_ajax"); + break; } /* visual map element status check */ diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index 05671d3a65..3881829752 100644 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -131,4 +131,19 @@ define('PROCESS_VALUE_NONE', 0); define('PROCESS_VALUE_MIN', 1); define('PROCESS_VALUE_MAX', 2); define('PROCESS_VALUE_AVG', 3); +//Status +define('VISUAL_MAP_STATUS_CRITICAL_BAD', 1); +define('VISUAL_MAP_STATUS_CRITICAL_ALERT', 4); +define('VISUAL_MAP_STATUS_NORMAL', 0); +define('VISUAL_MAP_STATUS_WARNING', 2); +define('VISUAL_MAP_STATUS_UNKNOW', 3); + + + +/* Service constants */ +//Status +define('SERVICE_STATUS_UNKNOW', -1); +define('SERVICE_STATUS_NORMAL', 0); +define('SERVICE_STATUS_CRITICAL', 1); +define('SERVICE_STATUS_WARNING', 2); ?> \ No newline at end of file diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index d06728f2dd..57dfa02c63 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -42,7 +42,7 @@ function check_refererer() { // This is done due to problems with HTTP_REFERER var when metarefresh is performed if ($config["refr"] > 0) return true; - + //Check if the referer have a port (for example when apache run in other port to 80) if (preg_match('/http(s?):\/\/.*:[0-9]*/', $referer) == 1) { $url = $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $config["homeurl"]; @@ -50,7 +50,7 @@ function check_refererer() { else { $url = $_SERVER['SERVER_NAME'] . $config["homeurl"]; } - + // Remove protocol from referer $referer = preg_replace('/http(s?):\/\//','',$referer); @@ -118,15 +118,15 @@ function output_clean_strict ($string) { * @return string Cleaned string */ function safe_url_extraclean ($string, $default_string = '') { - + /* Strip the string to 125 characters */ $string = substr ($string, 0, 125); - + /* Search for unwanted characters */ if (preg_match ('/[^a-zA-Z0-9_\/\.\-]|(\/\/)|(\.\.)/', $string)) { return $default_string; } - + return $string; } @@ -136,6 +136,7 @@ function safe_url_extraclean ($string, $default_string = '') { */ function no_permission () { require ("config.php"); + echo "

".__('You don\'t have access')."

"; echo html_print_image('images/noaccess.png', true, array("alt" => 'No access', "width" => '120')) . "

"; echo ""; @@ -144,6 +145,7 @@ function no_permission () { echo "
"; echo ""; include "general/footer.php"; + exit; } @@ -155,6 +157,7 @@ function no_permission () { */ function unmanaged_error ($error = "") { require_once ("config.php"); + echo "

".__('Unmanaged error')."

"; echo html_print_image('images/error.png', true, array("alt" => 'error')) . "

"; echo ""; @@ -165,6 +168,7 @@ function unmanaged_error ($error = "") { echo "
"; echo ""; include "general/footer.php"; + exit; } @@ -310,7 +314,7 @@ function human_time_comparation ($timestamp, $units = 'large') { } $seconds = get_system_time () - $timestamp; - + return human_time_description_raw($seconds, false, $units); } @@ -344,16 +348,16 @@ function get_system_time () { */ function get_user_language ($id_user = false) { global $config; - + $quick_language = get_parameter('quick_language_change', 0); - + if($quick_language) { $language = get_parameter('language', 0); if($language === 'default') { return $config['language']; } - + if($language !== 0) { return $language; } @@ -379,10 +383,10 @@ function get_user_language ($id_user = false) { function set_user_language() { global $config; global $l10n; - + $l10n = NULL; $user_language = get_user_language (); - + if (file_exists ('./include/languages/'.$user_language.'.mo')) { $l10n = new gettext_reader (new CachedFileReader ('./include/languages/'.$user_language.'.mo')); $l10n->load_tables(); @@ -421,7 +425,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large $nowString = __('N'); break; } - + if (empty ($seconds)) { return $nowString; // slerena 25/03/09 @@ -447,7 +451,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large $returnDate .= "$months $monthsString "; } - + $days = floor($seconds / 86400); if($days != 0) { @@ -457,7 +461,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large } $returnTime = ''; - + $hours = floor($seconds / 3600); if($hours != 0) { @@ -610,10 +614,10 @@ function get_parameter ($name, $default = '') { // POST has precedence if (isset($_POST[$name])) return get_parameter_post ($name, $default); - + if (isset($_GET[$name])) return get_parameter_get ($name, $default); - + return $default; } @@ -628,7 +632,7 @@ function get_parameter ($name, $default = '') { function get_parameter_get ($name, $default = "") { if ((isset ($_GET[$name])) && ($_GET[$name] != "")) return io_safe_input ($_GET[$name]); - + return $default; } @@ -643,7 +647,7 @@ function get_parameter_get ($name, $default = "") { function get_parameter_post ($name, $default = "") { if ((isset ($_POST[$name])) && ($_POST[$name] != "")) return io_safe_input ($_POST[$name]); - + return $default; } @@ -656,29 +660,31 @@ function get_parameter_post ($name, $default = "") { */ function get_alert_priority ($priority = 0) { global $config; + switch ($priority) { - case 0: - return __('Maintenance'); - break; - case 1: - return __('Informational'); - break; - case 2: - return __('Normal'); - break; - case 3: - return __('Warning'); - break; - case 4: - return __('Critical'); - break; - case 5: - return __('Minor'); - break; - case 6: - return __('Major'); - break; + case 0: + return __('Maintenance'); + break; + case 1: + return __('Informational'); + break; + case 2: + return __('Normal'); + break; + case 3: + return __('Warning'); + break; + case 4: + return __('Critical'); + break; + case 5: + return __('Minor'); + break; + case 6: + return __('Major'); + break; } + return ''; } @@ -692,12 +698,13 @@ function get_alert_priority ($priority = 0) { function get_alert_days ($row) { global $config; $days_output = ""; - + $check = $row["monday"] + $row["tuesday"] + $row["wednesday"] + $row["thursday"] + $row["friday"] + $row["saturday"] + $row["sunday"]; if ($check == 7) { return __('All'); - } elseif ($check == 0) { + } + elseif ($check == 0) { return __('None'); } @@ -716,7 +723,7 @@ function get_alert_days ($row) { if ($row["sunday"] != 0) $days_output .= __('Sun'); - if ($check > 1) { + if ($check > 1) { return str_replace (" ",", ",$days_output); } @@ -731,19 +738,21 @@ function get_alert_days ($row) { * @return string A string with the concatenated values */ function get_alert_times ($row2) { - if ($row2["time_from"]){ + if ($row2["time_from"]) { $time_from_table = $row2["time_from"]; - } else { + } + else { $time_from_table = __('N/A'); } - if ($row2["time_to"]){ + if ($row2["time_to"]) { $time_to_table = $row2["time_to"]; - } else { + } + else { $time_to_table = __('N/A'); } if ($time_to_table == $time_from_table) return __('N/A'); - + return substr ($time_from_table, 0, 5)." - ".substr ($time_to_table, 0, 5); } @@ -960,12 +969,12 @@ function enterprise_include ($filename) { global $config; // Load enterprise extensions - $filepath = realpath ($config["homedir"].'/'.ENTERPRISE_DIR.'/'.$filename); + $filepath = realpath ($config["homedir"] . '/' . ENTERPRISE_DIR . '/' . $filename); if ($filepath === false) return ENTERPRISE_NOT_HOOK; - if (strncmp ($config["homedir"], $filepath, strlen ($config["homedir"])) != 0){ + if (strncmp ($config["homedir"], $filepath, strlen ($config["homedir"])) != 0) { return ENTERPRISE_NOT_HOOK; } @@ -1188,9 +1197,9 @@ function array_key_to_offset($array, $key) { * @return array SNMP result. */ function get_snmpwalk($ip_target, $snmp_version, $snmp_community = '', $snmp3_auth_user = '', - $snmp3_security_level = '', $snmp3_auth_method = '', $snmp3_auth_pass = '', - $snmp3_privacy_method = '', $snmp3_privacy_pass = '', $quick_print = 0, $base_oid = "", $snmp_port = '') { - + $snmp3_security_level = '', $snmp3_auth_method = '', $snmp3_auth_pass = '', + $snmp3_privacy_method = '', $snmp3_privacy_pass = '', $quick_print = 0, $base_oid = "", $snmp_port = '') { + snmp_set_quick_print ($quick_print); // Fix for snmp port @@ -1250,9 +1259,9 @@ function string2image($string, $width, $height, $fontsize = 3, $padding_left = 4, $padding_top = 1, $home_url = '') { global $config; - + $string = str_replace('#','',$string); - + //Set the size of image from the size of text if ($width === false) { $size = calculateTextBox($fontsize, 0, $config['fontpath'], $string); @@ -1301,7 +1310,7 @@ function string2image($string, $width, $height, $fontsize = 3, function check_sql ($sql) { // We remove "*" to avoid things like SELECT * FROM tusuario - + //Check that it not delete_ as "delete_pending" (this is a common field in pandora tables). if (preg_match("/\*|delete[^_]|drop|alter|modify|union|password|pass|insert|update/i", $sql)) { @@ -1401,7 +1410,7 @@ function check_acl($id_user, $id_group, $access, $id_agent = 0) { if ($id_group != 0) { $group = db_get_row_filter('tgrupo', array('id_grupo' => $id_group)); $parents = groups_get_parents($group['parent'], true); - + foreach ($parents as $parent) { $parents_id[] = $parent['id_grupo']; } @@ -1435,12 +1444,12 @@ function check_acl($id_user, $id_group, $access, $id_agent = 0) { AND (tusuario_perfil.id_grupo IN (%s) OR tusuario_perfil.id_grupo = 0)", $id_user, implode(', ', $parents_id)); } - + $rowdup = db_get_all_rows_sql ($query); if (empty ($rowdup)) return 0; - + $result = 0; foreach ($rowdup as $row) { // For each profile for this pair of group and user do... @@ -1481,7 +1490,7 @@ function check_acl($id_user, $id_group, $access, $id_agent = 0) { if ($result >= 1) { return 1; } - + return 0; } diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 6157e1b2a4..780a31a1e0 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -28,6 +28,11 @@ if (!isset($config)) { require_once(str_repeat("../", $i) . "config.php"); break; // Skip config.php loading after load the first one } + else if(file_exists(str_repeat("../", $i) . 'include/config.php')) { + //For path from the enterprise structure dirs. + require_once(str_repeat("../", $i) . "include/config.php"); + break; // Skip config.php loading after load the first one + } } } diff --git a/pandora_console/include/functions_io.php b/pandora_console/include/functions_io.php index 12a3b4fd9a..0550b82c8c 100755 --- a/pandora_console/include/functions_io.php +++ b/pandora_console/include/functions_io.php @@ -153,7 +153,8 @@ function io_ascii_to_html($num) { if ($num <= 15) { return "�".dechex($num).";"; - } else { + } + else { return "&#x".dechex($num).";"; } } diff --git a/pandora_console/include/functions_modules.php b/pandora_console/include/functions_modules.php index 1749675117..c0d5866087 100644 --- a/pandora_console/include/functions_modules.php +++ b/pandora_console/include/functions_modules.php @@ -1002,16 +1002,16 @@ function modules_give_agent_id_from_module_id ($id_agent_module) { */ function modules_get_agentmodule_status($id_agentmodule = 0, $without_alerts = false) { $current_timestamp = get_system_time (); - + if (!$without_alerts) { $times_fired = db_get_value ('SUM(times_fired)', 'talert_template_modules', 'id_agent_module', $id_agentmodule); if ($times_fired > 0) { return 4; // Alert fired } } - + $status_row = db_get_row ("tagente_estado", "id_agente_modulo", $id_agentmodule); - + return $status_row['estado']; } @@ -1024,7 +1024,7 @@ function modules_get_agentmodule_status($id_agentmodule = 0, $without_alerts = f */ function modules_get_agentmodule_last_status($id_agentmodule = 0) { $status_row = db_get_row ("tagente_estado", "id_agente_modulo", $id_agentmodule); - + return $status_row['last_status']; } diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php index e775ac89a0..21b7be3ba6 100644 --- a/pandora_console/include/functions_ui.php +++ b/pandora_console/include/functions_ui.php @@ -19,7 +19,7 @@ * @subpackage UI */ -require_once($config['homedir'].'/include/functions_agents.php'); +require_once($config['homedir'] . '/include/functions_agents.php'); require_once($config['homedir'] . '/include/functions_modules.php'); require_once($config['homedir'] . '/include/functions.php'); require_once($config['homedir'] . '/include/functions_groups.php'); @@ -1101,7 +1101,7 @@ function ui_process_page_head ($string, $bitfield) { } $output = ''; - + // If user is logged or displayed view is the public view of visual console if ($config["refr"] > 0 && (isset($config['id_user']) || $vc_public_view == 1)) { $query = ui_get_url_refresh (false); diff --git a/pandora_console/include/functions_visual_map.php b/pandora_console/include/functions_visual_map.php index 71d3c72067..39f1912e3d 100644 --- a/pandora_console/include/functions_visual_map.php +++ b/pandora_console/include/functions_visual_map.php @@ -71,23 +71,23 @@ function visual_map_print_item($layoutData) { $status = visual_map_get_status_element($layoutData); switch ($status) { - case 1: + case VISUAL_MAP_STATUS_CRITICAL_BAD: //Critical (BAD) $colorStatus = "#ff0000"; break; - case 4: + case VISUAL_MAP_STATUS_CRITICAL_ALERT: //Critical (ALERT) $colorStatus = "#ff8800"; break; - case 0: + case VISUAL_MAP_STATUS_NORMAL: //Normal (OK) $colorStatus = "#00ff00"; break; - case 2: + case VISUAL_MAP_STATUS_WARNING: //Warning $colorStatus = "#ffff00"; break; - case 3: + case VISUAL_MAP_STATUS_UNKNOW: default: //Unknown // Default is Blue (Other) @@ -716,17 +716,17 @@ function visual_map_get_status_element($layoutData) { else if ($layoutData['id_agent'] != 0) { $status = agents_get_status ($layoutData["id_agent"]); if ($status == -1) // agents_get_status return -1 for unknown! - $status = 3; + $status = VISUAL_MAP_STATUS_UNKNOW; } else { - $status = 3; + $status = VISUAL_MAP_STATUS_UNKNOW; $id_agent = 0; } break; default: //If it's a graph, a progress bar or a data tag, ALWAYS report status OK //(=0) to avoid confussions here. - $status = 0; + $status = VISUAL_MAP_STATUS_NORMAL; break; } } @@ -742,6 +742,8 @@ function visual_map_get_status_element($layoutData) { * @param bool $draw_lines */ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_lines = true, $width = null, $height = null, $home_url = '') { + enterprise_include_once('include/functions_visual_map.php'); + //TODO: USE THE SAME CODE THAT THE VISUAL MAP EDITOR global $config; @@ -773,104 +775,99 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line style="z-index: 0; position:relative; width:'.$mapWidth.'px; height:'.$mapHeight.'px;">'; echo ""; $layout_datas = db_get_all_rows_field_filter ('tlayout_data', 'id_layout', $id_layout); + if (empty($layout_datas)) + $layout_datas = array(); $lines = array (); - if ($layout_datas !== false) { - foreach ($layout_datas as $layout_data) { - $id_agent = 0; - $layout_data['label'] = io_safe_output($layout_data['label']); - // **************************************************************** - // Get parent status (Could be an agent, module, map, others doesnt have parent info) - // **************************************************************** - - // Pending delete and disable modules must be ignored - $delete_pending_module = db_get_value ("delete_pending", "tagente_modulo", "id_agente_modulo", $layout_data["id_agente_modulo"]); - $disabled_module = db_get_value ("disabled", "tagente_modulo", "id_agente_modulo", $layout_data["id_agente_modulo"]); - - if($delete_pending_module == 1 || $disabled_module == 1) - continue; + foreach ($layout_datas as $layout_data) { + switch ($layout_data['type']) { + case STATIC_GRAPH: + case PERCENTILE_BAR: + case MODULE_GRAPH: + case SIMPLE_VALUE: + case SIMPLE_VALUE_MAX: + case SIMPLE_VALUE_MIN: + case SIMPLE_VALUE_AVG: + case PERCENTILE_BUBBLE: + // Pending delete and disable modules must be ignored + $delete_pending_module = db_get_value ("delete_pending", + "tagente_modulo", "id_agente_modulo", + $layout_data["id_agente_modulo"]); + $disabled_module = db_get_value ("disabled", "tagente_modulo", + "id_agente_modulo", $layout_data["id_agente_modulo"]); - if ($layout_data["parent_item"] != 0){ - $id_agent_module_parent = db_get_value ("id_agente_modulo", "tlayout_data", "id", $layout_data["parent_item"]); - $id_agent_parent = db_get_value ("id_agent", "tlayout_data", "id", $layout_data["parent_item"]); - $id_layout_linked = db_get_value ("id_layout_linked", "tlayout_data", "id", $layout_data["parent_item"]); - - // Module - if ($id_agent_module_parent != 0) { - $status_parent = modules_get_agentmodule_status ($id_agent_module_parent); - // Agent - } - elseif ($id_agent_parent != 0) { - $status_parent = agents_get_status ($id_agent_parent); - } - // Another layout/map - elseif ($id_layout_linked != 0) { - $status_parent = visual_map_get_layout_status ($id_layout_linked); - } - - else { - $status_parent = 3; - } - - } - else { - $id_agent_module_parent = 0; - $status_parent = 3; - } + if ($delete_pending_module == 1 || $disabled_module == 1) + continue; + break; + case SERVICE: + break; + default: + break; + } + + $id_agent = 0; + $layout_data['label'] = io_safe_output($layout_data['label']); + + // ************************************************************* + // Get parent status (Could be an agent, module, map, + // others doesnt have parent info) + // ************************************************************** + + if ($layout_data["parent_item"] != 0) { + $id_agent_module_parent = db_get_value ("id_agente_modulo", "tlayout_data", "id", $layout_data["parent_item"]); + $layout_data_parent = db_get_row_filter('tlayout_data', + array('id' => $layout_data["parent_item"])); - // **************************************************************** - // Get STATUS of current object - // **************************************************************** - - // Linked to other layout ?? - Only if not module defined - if ($layout_data['id_layout_linked'] != 0) { - $status = visual_map_get_layout_status ($layout_data['id_layout_linked']); - - // Single object - } - elseif (($layout_data["type"] == 0) - || ($layout_data["type"] == 3) - || ($layout_data["type"] == 9) - || ($layout_data["type"] == 4)) { - // Status for a simple module - if ($layout_data['id_agente_modulo'] != 0) { - $status = modules_get_agentmodule_status ($layout_data['id_agente_modulo']); - $id_agent = db_get_value ("id_agente", "tagente_estado", "id_agente_modulo", $layout_data['id_agente_modulo']); - - // Status for a whole agent, if agente_modulo was == 0 - } - elseif ($layout_data['id_agent'] != 0) { - $status = agents_get_status ($layout_data["id_agent"]); - if ($status == -1) // agents_get_status return -1 for unknown! - $status = 3; - $id_agent = $layout_data["id_agent"]; - } - else { - $status = 3; - $id_agent = 0; - } - } - else { - // If it's a graph, a progress bar or a data tag, ALWAYS report - // status OK (=0) to avoid confussions here. - $status = 0; - } - - // **************************************************************** - // STATIC IMAGE (type = 0) - // **************************************************************** - if ($layout_data['type'] == 0) { - // Link image - //index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=1 - if ($status == 0) // Bad monitor + $status_parent = visual_map_get_status_element($layout_data_parent); + } + else { + $id_agent_module_parent = 0; + $status_parent = 3; + } + + + // **************************************************************** + // Get STATUS of current object + // **************************************************************** + $status = visual_map_get_status_element($layout_data); + + + switch ($status) { + case VISUAL_MAP_STATUS_CRITICAL_BAD: + //Critical (BAD) + $colorStatus = "#ff0000"; + break; + case VISUAL_MAP_STATUS_CRITICAL_ALERT: + //Critical (ALERT) + $colorStatus = "#ff8800"; + break; + case VISUAL_MAP_STATUS_NORMAL: + //Normal (OK) + $colorStatus = "#00ff00"; + break; + case VISUAL_MAP_STATUS_WARNING: + //Warning + $colorStatus = "#ffff00"; + break; + case VISUAL_MAP_STATUS_UNKNOW: + default: + //Unknown + $colorStatus = "#5A5AFF"; + // Default is Grey (Other) + break; + } + + switch ($layout_data['type']) { + case STATIC_GRAPH: + if ($status == VISUAL_MAP_STATUS_CRITICAL_BAD) $z_index = 3; - elseif ($status == 2) // Warning + elseif ($status == VISUAL_MAP_STATUS_WARNING) $z_index = 2; - elseif ($status == 4) // Alert + elseif ($status == VISUAL_MAP_STATUS_CRITICAL_ALERT) $z_index = 4; else - $z_index = 1; // Print BAD over good + $z_index = 1; // Draw image if ($resizedMap) @@ -878,10 +875,8 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line else echo '
'; - if (!isset ($id_agent)) - $id_agent = 0; - if ($show_links) { + if (!isset($id_agent)) $id_agent = 0; if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { //Extract id service if it is a prediction module. @@ -915,7 +910,6 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line echo ''; } } - $img_style = array (); $img_style["title"] = $layout_data["label"]; @@ -927,30 +921,27 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line } $img = "images/console/icons/".$layout_data["image"]; + switch ($status) { - case 1: - //Critical (BAD) + case VISUAL_MAP_STATUS_CRITICAL_BAD: $img .= "_bad.png"; break; - case 4: - //Critical (ALERT) + case VISUAL_MAP_STATUS_CRITICAL_ALERT: $img = "4".$img."_bad.png"; break; - case 0: - //Normal (OK) + case VISUAL_MAP_STATUS_NORMAL: $img .= "_ok.png"; break; - case 2: - //Warning + case VISUAL_MAP_STATUS_WARNING: $img .= "_warning.png"; break; - case 3: - //Unknown + case VISUAL_MAP_STATUS_UNKNOW: default: - $img .= ".png"; // Default is Grey (Other) + $img .= ".png"; break; } + $borderStyle = ''; if(substr($img,0,1) == '4') { $img_style['border'] ='2px solid #ffa300;'; @@ -980,135 +971,314 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line html_print_image ($img, false, $img_style); - echo ""; - // Print label if valid label_color (only testing for starting with #) otherwise print nothing if ($layout_data['label_color'][0] == '#') { echo "
"; - echo $layout_data['label']; + echo $layout_data['label']; } echo "
"; - } - - switch ($layout_data['type']) { - case 4: - // **************************************************************** - // LABEL (type = 4) - // **************************************************************** - $z_index = 4; - if ($resizedMap) - echo '
'; - else - echo '
'; - - $endTagA = false; - if ($show_links) { - if (!isset($id_agent)) $id_agent = 0; - if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { - // Link to an agent - echo ''; - $endTagA = true; - } - elseif ($layout_data['id_layout_linked'] > 0) { - // Link to a map - echo ''; - $endTagA = true; - } - } - if ($layout_data['label_color'][0] == '#') { - echo "
"; - echo $layout_data['label']; - } - if ($endTagA) echo "
"; - echo "
"; - break; - case 5: - // **************************************************************** - // ICON (type = 5) - // **************************************************************** - $z_index = 4; - if ($resizedMap) - echo '
'; - else - echo '
'; - - $endTagA = false; - if ($show_links) { - if (!isset($id_agent)) $id_agent = 0; - if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { - // Link to an agent - echo ''; - $endTagA = true; - } - elseif ($layout_data['id_layout_linked'] > 0) { - // Link to a map - echo ''; - $endTagA = true; - } - elseif (preg_match('/^(http:\/\/)((.)+)$/i', $layout_data['label'])){ - // Link to an URL - echo ''; - $endTagA = true; - } - } - - $img_style = array (); - $img_style["title"] = $layout_data["label"]; - - if (!empty ($layout_data["width"])) { - $img_style["width"] = $layout_data["width"]; + + echo ""; + break; + case PERCENTILE_BAR: + break; + case MODULE_GRAPH: + break; + case SIMPLE_VALUE: + break; + case LABEL: + $z_index = 4; + if ($resizedMap) + echo '
'; + else + echo '
'; + + $endTagA = false; + if ($show_links) { + if (!isset($id_agent)) $id_agent = 0; + if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { + // Link to an agent + echo ''; + $endTagA = true; } - if (!empty ($layout_data["height"])) { + elseif ($layout_data['id_layout_linked'] > 0) { + // Link to a map + echo ''; + $endTagA = true; + } + } + if ($layout_data['label_color'][0] == '#') { + echo "
"; + echo $layout_data['label']; + } + if ($endTagA) echo "
"; + echo "
"; + break; + case ICON: + $z_index = 4; + if ($resizedMap) + echo '
'; + else + echo '"; + break; + case SIMPLE_VALUE: + case SIMPLE_VALUE_MAX: + case SIMPLE_VALUE_MIN: + case SIMPLE_VALUE_AVG: + $unit_text = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $layout_data['id_agente_modulo']); + $unit_text = trim(io_safe_output($unit_text)); + + if ($resizedMap) + echo '
'; + else + echo '
'; + + $endTagA = false; + + if ($show_links) { + //Extract id service if it is a prediction module. + $id_service = db_get_value_filter('custom_integer_1', + 'tagente_modulo', + array('id_agente_modulo' => $layout_data['id_agente_modulo'], + 'prediction_module' => 1)); + + if ($id_service === false) { + $id_service = 0; } - $img = "images/console/icons/".$layout_data["image"] . ".png"; - - if (is_file($img)) - $infoImage = getimagesize($img); - - if (!empty ($layout_data["width"])) { - if ($resizedMap) - $img_style["width"] = (integer)($proportion * $layout_data["width"]); - else - $img_style["width"] = $layout_data["width"]; + if ($id_service != 0) { + //Link to an service page + echo ''; + $endTagA = true; } - else - $img_style["width"] = (integer)($proportion * $infoImage[0]); + elseif ($layout_data['id_layout_linked'] > 0) { - if (!empty ($layout_data["height"])) { - if ($resizedMap) - $img_style["height"] = (integer)($proportion * $img_style["height"]); - else - $img_style["height"] = $layout_data["height"]; + // Link to a map + echo ''; + $endTagA = true; } - else - $img_style["height"] = (integer)($proportion * $infoImage[1]); + } + + echo ''.$layout_data['label']. ' '; + //TODO: change interface to add a period parameter, now is set to 1 day + switch ($layout_data['type']) { + case SIMPLE_VALUE: + $value = db_get_value ('datos', 'tagente_estado', 'id_agente_modulo', $layout_data['id_agente_modulo']); + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + echo $value; + break; + case SIMPLE_VALUE_MAX: + $value = reporting_get_agentmodule_data_max ($layout_data['id_agente_modulo'], $layout_data['period'], 0); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + } + echo $value; + break; + case SIMPLE_VALUE_MIN: + $value = reporting_get_agentmodule_data_min ($layout_data['id_agente_modulo'], $layout_data['period'], 0); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + } + echo $value; + break; + case SIMPLE_VALUE_AVG: + $value = reporting_get_agentmodule_data_average($layout_data['id_agente_modulo'], $layout_data['period'], 0); + if ($value === false) { + $value = __('Unknown'); + } + else { + $value = format_for_graph($value, 2); + if (!empty($unit_text)) + $value .= " " . $unit_text; + } + echo $value; + break; + } + echo ''; + + if ($endTagA) echo ''; + + echo '
'; + break; + case PERCENTILE_BAR: + case PERCENTILE_BUBBLE: + if ($resizedMap) + echo '
'; + else + echo '
'; + $valor = db_get_sql ('SELECT datos FROM tagente_estado WHERE id_agente_modulo = '.$layout_data['id_agente_modulo']); + $width = $layout_data['width']; + if ( $layout_data['height'] > 0) + $percentile = $valor / $layout_data['height'] * 100; + else + $percentile = 100; + + $percentile = round($percentile); + + $endTagA = false; + + echo $layout_data['label']; + echo "
"; + + if ($show_links) { + if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { + + //Extract id service if it is a prediction module. + $id_service = db_get_value_filter('custom_integer_1', + 'tagente_modulo', + array('id_agente_modulo' => $layout_data['id_agente_modulo'], + 'prediction_module' => 1)); + + if ($id_service === false) { + $id_service = 0; + } + + if ($id_service != 0) { + //Link to an service page + echo ''; + $endTagA = true; + } + else { + // Link to an agent + echo ''; + $endTagA = true; + } + } + elseif ($layout_data['id_layout_linked'] > 0) { - html_print_image ($img, false, $img_style); + // Link to a map + echo ''; + $endTagA = true; - if ($endTagA) echo ""; - - echo "
"; - break; - case 2: - case 6: - case 7: - case 8: - // **************************************************************** - // SIMPLE DATA VALUE (type = 2) - // **************************************************************** + } + else { + // A void object + echo ''; + $endTagA = true; + } + } + + $value_text = false; + if ($layout_data['image'] == 'percent') { + $value_text = false; + } + elseif ($layout_data['image'] == 'value') { $unit_text = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $layout_data['id_agente_modulo']); $unit_text = trim(io_safe_output($unit_text)); + $value_text = format_for_graph($valor, 2); + if (!empty($unit_text)) + $value_text .= " " . $unit_text; + } + + if ($layout_data['type'] == 9) { if ($resizedMap) - echo '
'; + echo progress_bubble($percentile, ((integer)($proportion * $width)), $width, '', 1, $value_text, $colorStatus); else - echo ''; + break; + case MODULE_GRAPH: + if ($resizedMap) { + $layout_data['width'] = ((integer)($proportion * $layout_data['width'])); + $layout_data['height'] = ((integer)($proportion * $layout_data['height'])); + $layout_data['pos_x'] = ((integer)($proportion * $layout_data['pos_x'])); + $layout_data['pos_y'] = ((integer)($proportion * $layout_data['pos_y'])); + } + + echo '
'; + + echo $layout_data['label']; + echo "
"; + + $endTagA = false; + + if ($show_links) { + if (($layout_data['id_layout_linked'] == "") || ($layout_data['id_layout_linked'] == 0)) { + //Extract id service if it is a prediction module. $id_service = db_get_value_filter('custom_integer_1', 'tagente_modulo', @@ -1123,274 +1293,56 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line //Link to an service page echo ''; - $endTagA = true; - } - elseif ($layout_data['id_layout_linked'] > 0) { - - // Link to a map - echo ''; - $endTagA = true; - } - } - - echo ''.$layout_data['label']. ' '; - //TODO: change interface to add a period parameter, now is set to 1 day - switch ($layout_data['type']) { - case 2: - $value = db_get_value ('datos', 'tagente_estado', 'id_agente_modulo', $layout_data['id_agente_modulo']); - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - echo $value; - break; - case 6: - $value = reporting_get_agentmodule_data_max ($layout_data['id_agente_modulo'], $layout_data['period'], 0); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - } - echo $value; - break; - case 7: - $value = reporting_get_agentmodule_data_min ($layout_data['id_agente_modulo'], $layout_data['period'], 0); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - } - echo $value; - break; - case 8: - $value = reporting_get_agentmodule_data_average($layout_data['id_agente_modulo'], $layout_data['period'], 0); - if ($value === false) { - $value = __('Unknown'); - } - else { - $value = format_for_graph($value, 2); - if (!empty($unit_text)) - $value .= " " . $unit_text; - } - echo $value; - break; - } - echo ''; - - if ($endTagA) echo ''; - - echo '
'; - break; - case 3: - // **************************************************************** - // Progress bar - // **************************************************************** - case 9: - // **************************************************************** - // Progress bubble - // **************************************************************** - - switch ($status) { - case 1: - //Critical (BAD) - $colorStatus = "#ff0000"; - break; - case 4: - //Critical (ALERT) - $colorStatus = "#ff8800"; - break; - case 0: - //Normal (OK) - $colorStatus = "#00ff00"; - break; - case 2: - //Warning - $colorStatus = "#ffff00"; - break; - case 3: - //Unknown - default: - $colorStatus = "#5A5AFF"; - // Default is Grey (Other) - break; - } - - if ($resizedMap) - echo '
'; - else - echo '
'; - $valor = db_get_sql ('SELECT datos FROM tagente_estado WHERE id_agente_modulo = '.$layout_data['id_agente_modulo']); - $width = $layout_data['width']; - if ( $layout_data['height'] > 0) - $percentile = $valor / $layout_data['height'] * 100; - else - $percentile = 100; - - $percentile = round($percentile); - - $endTagA = false; - - echo $layout_data['label']; - echo "
"; - - if ($show_links) { - if (($id_agent > 0) && ($layout_data['id_layout_linked'] == "" || $layout_data['id_layout_linked'] == 0)) { - - //Extract id service if it is a prediction module. - $id_service = db_get_value_filter('custom_integer_1', - 'tagente_modulo', - array('id_agente_modulo' => $layout_data['id_agente_modulo'], - 'prediction_module' => 1)); - - if ($id_service === false) { - $id_service = 0; - } - - if ($id_service != 0) { - //Link to an service page - echo ''; - $endTagA = true; - } - else { - // Link to an agent - echo ''; - $endTagA = true; - } - } - elseif ($layout_data['id_layout_linked'] > 0) { - - // Link to a map - echo ''; - $endTagA = true; - } else { - // A void object - echo ''; - $endTagA = true; + echo ''; } } - - $value_text = false; - if ($layout_data['image'] == 'percent') { - $value_text = false; - } - elseif ($layout_data['image'] == 'value') { - $unit_text = db_get_sql ('SELECT unit FROM tagente_modulo WHERE id_agente_modulo = ' . $layout_data['id_agente_modulo']); - $unit_text = trim(io_safe_output($unit_text)); - - $value_text = format_for_graph($valor, 2); - if (!empty($unit_text)) - $value_text .= " " . $unit_text; - } - - if ($layout_data['type'] == 9) { - if ($resizedMap) - echo progress_bubble($percentile, ((integer)($proportion * $width)), $width, '', 1, $value_text, $colorStatus); - else - echo progress_bubble($percentile, $width, $width, '', 1, $value_text, $colorStatus); - } else { - if ($resizedMap) - echo progress_bar($percentile, ((integer)($proportion * $width)), 15, '', 1, $value_text, $colorStatus); - else - echo progress_bar($percentile, $width, 15, '', 1, $value_text, $colorStatus); + echo ''; } - - if ($endTagA) echo ''; - - echo '
'; - break; - case 1; - // **************************************************************** - // Single module graph - // **************************************************************** - // SINGLE GRAPH (type = 1) - - if ($resizedMap) { - $layout_data['width'] = ((integer)($proportion * $layout_data['width'])); - $layout_data['height'] = ((integer)($proportion * $layout_data['height'])); - $layout_data['pos_x'] = ((integer)($proportion * $layout_data['pos_x'])); - $layout_data['pos_y'] = ((integer)($proportion * $layout_data['pos_y'])); - } - - echo '
'; - - echo $layout_data['label']; - echo "
"; - - $endTagA = false; - - if ($show_links) { - if (($layout_data['id_layout_linked'] == "") || ($layout_data['id_layout_linked'] == 0)) { - - //Extract id service if it is a prediction module. - $id_service = db_get_value_filter('custom_integer_1', - 'tagente_modulo', - array('id_agente_modulo' => $layout_data['id_agente_modulo'], - 'prediction_module' => 1)); - - if ($id_service === false) { - $id_service = 0; - } - - if ($id_service != 0) { - //Link to an service page - echo ''; - } - else { - echo ''; - } - } - else { - echo ''; - } - } - - // ATTENTION: DO NOT USE & here because is bad-translated and doesnt work - // resulting fault image links :( - echo grafico_modulo_sparse ($layout_data['id_agente_modulo'], $layout_data['period'], - false, $layout_data['width'], $layout_data['height'], - '', null, false, 1, false, 0, '', 0, 0, true, true, $home_url, 2); - - echo ""; - echo "
"; - break; - } - - // **************************************************************** - // Lines joining objects - // **************************************************************** - // Get parent relationship - Create line data - if ($layout_data["parent_item"] != "" && $layout_data["parent_item"] != 0) { - $line['id'] = $layout_data['id']; - $line['node_begin'] = 'layout-data-'.$layout_data["parent_item"]; - $line['node_end'] = 'layout-data-'.$layout_data["id"]; - switch ($status_parent) { - default: - case 3: - $line["color"] = "#ccc"; // Gray - break; - case 2: - $line["color"] = "#20f6f6"; // Yellow - break; - case 0: - $line["color"] = "#00ff00"; // Green - break; - case 4: - case 1: - $line["color"] = "#ff0000"; // Red - break; } - array_push ($lines, $line); + + // ATTENTION: DO NOT USE & here because is bad-translated and doesnt work + // resulting fault image links :( + echo grafico_modulo_sparse ($layout_data['id_agente_modulo'], $layout_data['period'], + false, $layout_data['width'], $layout_data['height'], + '', null, false, 1, false, 0, '', 0, 0, true, true, $home_url, 2); + + echo ""; + echo "
"; + break; + default: + enterprise_hook("enterprise_visual_map_print_item", + array($layout_data, $status, $colorStatus)); + break; + } + + // **************************************************************** + // Lines joining objects + // **************************************************************** + // Get parent relationship - Create line data + if ($layout_data["parent_item"] != "" && $layout_data["parent_item"] != 0) { + $line['id'] = $layout_data['id']; + $line['node_begin'] = 'layout-data-'.$layout_data["parent_item"]; + $line['node_end'] = 'layout-data-'.$layout_data["id"]; + switch ($status_parent) { + default: + case VISUAL_MAP_STATUS_UNKNOW: + $line["color"] = "#ccc"; // Gray + break; + case VISUAL_MAP_STATUS_WARNING: + $line["color"] = "#20f6f6"; // Yellow + break; + case VISUAL_MAP_STATUS_NORMAL: + $line["color"] = "#00ff00"; // Green + break; + case VISUAL_MAP_STATUS_CRITICAL_ALERT: + case VISUAL_MAP_STATUS_CRITICAL_BAD: + $line["color"] = "#ff0000"; // Red + break; } + array_push ($lines, $line); } } @@ -1411,19 +1363,6 @@ function visual_map_print_visual_map ($id_layout, $show_links = true, $draw_line echo "
"; } -/** - * @return array Layout data types - */ -function visual_map_get_layout_data_types () { - $types = array (); - $types[0] = __('Static graph'); - $types[1] = __('Module graph'); - $types[2] = __('Simple value'); - $types[3] = __('Percentile bar'); - - return $types; -} - /** * Get a list with the layouts for a user. * @@ -1473,7 +1412,6 @@ function visual_map_get_user_layouts ($id_user = 0, $only_names = false, $filter return $retval; } - /** * Get the status of a layout. * @@ -1487,13 +1425,13 @@ function visual_map_get_user_layouts ($id_user = 0, $only_names = false, $filter * @return bool The status of the given layout. True if it's OK, false if not. */ function visual_map_get_layout_status ($id_layout = 0, $depth = 0) { - $temp_status = 0; - $temp_total = 0; + $temp_status = VISUAL_MAP_STATUS_NORMAL; + $temp_total = VISUAL_MAP_STATUS_NORMAL; $depth++; // For recursion depth checking // TODO: Implement this limit as a configurable item in setup if ($depth > 10) { - return 3; // No status data if we need to exit by a excesive recursion + return VISUAL_MAP_STATUS_UNKNOW; // No status data if we need to exit by a excesive recursion } $id_layout = (int) $id_layout; @@ -1501,7 +1439,7 @@ function visual_map_get_layout_status ($id_layout = 0, $depth = 0) { $result = db_get_all_rows_filter ('tlayout_data', array ('id_layout' => $id_layout), array ('id_agente_modulo', 'parent_item', 'id_layout_linked', 'id_agent', 'type')); if ($result === false) - return 0; + return VISUAL_MAP_STATUS_NORMAL; foreach ($result as $rownum => $data) { if (($data["id_layout_linked"] == 0 && $data["id_agente_modulo"] == 0 && $data["id_agent"] == 0) || $data['type'] != 0) @@ -1519,8 +1457,8 @@ function visual_map_get_layout_status ($id_layout = 0, $depth = 0) { else { $status = agents_get_status ($data["id_agent"]); } - if ($status == 1) - return 1; + if ($status == VISUAL_MAP_STATUS_CRITICAL_BAD) + return VISUAL_MAP_STATUS_CRITICAL_BAD; if ($status > $temp_total) $temp_total = $status; } diff --git a/pandora_console/include/functions_visual_map_editor.php b/pandora_console/include/functions_visual_map_editor.php index 43972e644d..b3b9713c22 100644 --- a/pandora_console/include/functions_visual_map_editor.php +++ b/pandora_console/include/functions_visual_map_editor.php @@ -43,7 +43,7 @@ function visual_map_editor_print_item_palette($visualConsole_id, $background) { echo '