From f8b3bba7aa3dcc9ed1ce69d734bd2a840f9cda4b Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 15 Sep 2011 13:19:11 +0000 Subject: [PATCH] 2011-09-14 Miguel de Dios * include/functions.php: cleaned source code style. * include/functions_events.php: added the parameter to return only url in function "events_print_type_img". * include/functions_api.php: now the api in getevents return more data. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4954 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 11 +- pandora_console/include/functions.php | 30 ++-- pandora_console/include/functions_api.php | 50 +++++- pandora_console/include/functions_events.php | 163 +++++++++++++------ 4 files changed, 190 insertions(+), 64 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index ad8085407d..f24b39d224 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,4 +1,13 @@ -2011-09-08 Miguel de Dios +2011-09-14 Miguel de Dios + + * include/functions.php: cleaned source code style. + + * include/functions_events.php: added the parameter to return only url + in function "events_print_type_img". + + * include/functions_api.php: now the api in getevents return more data. + +2011-09-14 Miguel de Dios * include/functions_api.php: added in the output of get events the agent name and group name. diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 2151b4f193..33ac1cee9d 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -900,18 +900,24 @@ function get_priorities () { */ function get_priority_name ($priority) { switch ($priority) { - case 0: - return __('Maintenance'); - case 1: - return __('Informational'); - case 2: - return __('Normal'); - case 3: - return __('Warning'); - case 4: - return __('Critical'); - default: - return __('All'); + 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; + default: + return __('All'); + break; } } diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index b56f62f238..2f4890a1e5 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -20,6 +20,7 @@ require_once('functions_agents.php'); require_once('functions_modules.php'); include_once($config['homedir'] . "/include/functions_profile.php"); include_once($config['homedir'] . "/include/functions.php"); +include_once($config['homedir'] . "/include/functions_events.php"); /** * Parse the "other" parameter. @@ -1574,14 +1575,16 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d case "mysql": $sql = "SELECT *, (SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name + (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, + (SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon FROM tevento WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination; break; case "postgresql": $sql = "SELECT *, (SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name + (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, + (SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon FROM tevento WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset; break; @@ -1591,7 +1594,8 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d $set['offset'] = $offset; $sql = "SELECT *, (SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, - (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name + (SELECT t2.nombre FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_name, + (SELECT t2.icon FROM tgrupo AS t2 WHERE t2.id_grupo = tevento.id_grupo) AS group_icon FROM tevento WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC"; $sql = oracle_recode_query ($sql, $set); @@ -1654,6 +1658,46 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d $result = db_get_all_rows_sql ($sql); + if ($result !== false) { + //Add the description and image + foreach ($result as $key => $row) { + $row['description_event'] = events_print_type_description($row["event_type"], true); + $row['img_description'] = events_print_type_img ($row["event_type"], true, true); + $row['criticity_name'] = get_priority_name ($row["criticity"]); + if ($config['https']) { + $urlImage = 'https://'; + } + else { + $urlImage = "http://"; + } + + $urlImage = $urlImage.$_SERVER['HTTP_HOST'].$config["homeurl"]; + switch ($row["criticity"]) { + default: + case 0: + $img_sev = $urlImage . "/images/status_sets/default/severity_maintenance.png"; + break; + case 1: + $img_sev = $urlImage . "/images/status_sets/default/severity_informational.png"; + break; + case 2: + $img_sev = $urlImage . "/images/status_sets/default/severity_normal.png"; + break; + case 3: + $img_sev = $urlImage . "/images/status_sets/default/severity_warning.png"; + break; + case 4: + $img_sev = $urlImage . "/images/status_sets/default/severity_critical.png"; + break; + } + $row['img_criticy'] = $img_sev; + + $result[$key] = $row; + } + } + + //html_debug_print($result); + $data['type'] = 'array'; $data['data'] = $result; diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 773b75b0d1..e3bc1c0017 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -452,60 +452,127 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret * * @param string $type Event type from SQL * @param bool $return Whether to return or print + * @param bool $only_url Flag to return only url of image, by default false. * * @return string HTML with img */ -function events_print_type_img ($type, $return = false) { +function events_print_type_img ($type, $return = false, $only_url = false) { + global $config; + $output = ''; + if ($config['https']) { + $urlImage = 'https://'; + } + else { + $urlImage = "http://"; + } + + $urlImage = $urlImage.$_SERVER['HTTP_HOST'].$config["homeurl"]; + switch ($type) { - case "alert_recovered": - $output .= html_print_image ("images/error.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "alert_manual_validation": - $output .= html_print_image ("images/eye.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "going_up_warning": - $output .= html_print_image ("images/b_yellow.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "going_down_critical": - case "going_up_critical": //This is to be backwards compatible - $output .= html_print_image ("images/b_red.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "going_up_normal": - case "going_down_normal": //This is to be backwards compatible - $output .= html_print_image ("images/b_green.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "going_down_warning": - $output .= html_print_image ("images/b_yellow.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "alert_fired": - $output .= html_print_image ("images/bell.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "system"; - $output .= html_print_image ("images/cog.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "recon_host_detected"; - $output .= html_print_image ("images/network.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "new_agent"; - $output .= html_print_image ("images/wand.png", true, - array ("title" => events_print_type_description($type, true))); - break; - case "unknown": - default: - $output .= html_print_image ("images/err.png", true, - array ("title" => events_print_type_description($type, true))); - break; + case "alert_recovered": + if ($only_url) { + $output = $urlImage . "/" . "images/error.png"; + } + else { + $output .= html_print_image ("images/error.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "alert_manual_validation": + if ($only_url) { + $output = $urlImage . "/" . "images/eye.png"; + } + else { + $output .= html_print_image ("images/eye.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "going_up_warning": + if ($only_url) { + $output = $urlImage . "/" . "images/b_yellow.png"; + } + else { + $output .= html_print_image ("images/b_yellow.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "going_down_critical": + case "going_up_critical": //This is to be backwards compatible + if ($only_url) { + $output = $urlImage . "/" . "images/b_red.png"; + } + else { + $output .= html_print_image ("images/b_red.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "going_up_normal": + case "going_down_normal": //This is to be backwards compatible + if ($only_url) { + $output = $urlImage . "/" . "images/b_green.png"; + } + else { + $output .= html_print_image ("images/b_green.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "going_down_warning": + if ($only_url) { + $output = $urlImage . "/" . "images/b_yellow.png"; + } + else { + $output .= html_print_image ("images/b_yellow.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "alert_fired": + if ($only_url) { + $output = $urlImage . "/" . "images/bell.png"; + } + else { + $output .= html_print_image ("images/bell.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "system": + if ($only_url) { + $output = $urlImage . "/" . "images/cog.png"; + } + else { + $output .= html_print_image ("images/cog.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "recon_host_detected": + if ($only_url) { + $output = $urlImage . "/" . "images/network.png"; + } + else { + $output .= html_print_image ("images/network.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "new_agent": + if ($only_url) { + $output = $urlImage . "/" . "images/wand.png"; + } + else { + $output .= html_print_image ("images/wand.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; + case "unknown": + default: + if ($only_url) { + $output = $urlImage . "/" . "images/err.png"; + } + else { + $output .= html_print_image ("images/err.png", true, + array ("title" => events_print_type_description($type, true))); + } + break; } if ($return)