2011-09-14 Miguel de Dios <miguel.dedios@artica.es>

* 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
This commit is contained in:
mdtrooper 2011-09-15 13:19:11 +00:00
parent 159c96b971
commit f8b3bba7aa
4 changed files with 190 additions and 64 deletions

View File

@ -1,4 +1,13 @@
2011-09-08 Miguel de Dios <miguel.dedios@artica.es> 2011-09-14 Miguel de Dios <miguel.dedios@artica.es>
* 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 <miguel.dedios@artica.es>
* include/functions_api.php: added in the output of get events the agent * include/functions_api.php: added in the output of get events the agent
name and group name. name and group name.

View File

@ -902,16 +902,22 @@ function get_priority_name ($priority) {
switch ($priority) { switch ($priority) {
case 0: case 0:
return __('Maintenance'); return __('Maintenance');
break;
case 1: case 1:
return __('Informational'); return __('Informational');
break;
case 2: case 2:
return __('Normal'); return __('Normal');
break;
case 3: case 3:
return __('Warning'); return __('Warning');
break;
case 4: case 4:
return __('Critical'); return __('Critical');
break;
default: default:
return __('All'); return __('All');
break;
} }
} }

View File

@ -20,6 +20,7 @@ require_once('functions_agents.php');
require_once('functions_modules.php'); require_once('functions_modules.php');
include_once($config['homedir'] . "/include/functions_profile.php"); include_once($config['homedir'] . "/include/functions_profile.php");
include_once($config['homedir'] . "/include/functions.php"); include_once($config['homedir'] . "/include/functions.php");
include_once($config['homedir'] . "/include/functions_events.php");
/** /**
* Parse the "other" parameter. * Parse the "other" parameter.
@ -1574,14 +1575,16 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
case "mysql": case "mysql":
$sql = "SELECT *, $sql = "SELECT *,
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, (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 FROM tevento
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination; WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$offset.",".$pagination;
break; break;
case "postgresql": case "postgresql":
$sql = "SELECT *, $sql = "SELECT *,
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, (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 FROM tevento
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset; WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC LIMIT ".$pagination." OFFSET ".$offset;
break; break;
@ -1591,7 +1594,8 @@ function get_events__with_user($trash1, $trash2, $other, $returnType, $user_in_d
$set['offset'] = $offset; $set['offset'] = $offset;
$sql = "SELECT *, $sql = "SELECT *,
(SELECT t1.nombre FROM tagente AS t1 WHERE t1.id_agente = tevento.id_agente) AS agent_name, (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 FROM tevento
WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC"; WHERE 1=1 ".$sql_post." ORDER BY utimestamp DESC";
$sql = oracle_recode_query ($sql, $set); $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); $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['type'] = 'array';
$data['data'] = $result; $data['data'] = $result;

View File

@ -452,59 +452,126 @@ function events_print_event_table ($filter = "", $limit = 10, $width = 440, $ret
* *
* @param string $type Event type from SQL * @param string $type Event type from SQL
* @param bool $return Whether to return or print * @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 * @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 = ''; $output = '';
if ($config['https']) {
$urlImage = 'https://';
}
else {
$urlImage = "http://";
}
$urlImage = $urlImage.$_SERVER['HTTP_HOST'].$config["homeurl"];
switch ($type) { switch ($type) {
case "alert_recovered": case "alert_recovered":
if ($only_url) {
$output = $urlImage . "/" . "images/error.png";
}
else {
$output .= html_print_image ("images/error.png", true, $output .= html_print_image ("images/error.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "alert_manual_validation": case "alert_manual_validation":
if ($only_url) {
$output = $urlImage . "/" . "images/eye.png";
}
else {
$output .= html_print_image ("images/eye.png", true, $output .= html_print_image ("images/eye.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "going_up_warning": case "going_up_warning":
if ($only_url) {
$output = $urlImage . "/" . "images/b_yellow.png";
}
else {
$output .= html_print_image ("images/b_yellow.png", true, $output .= html_print_image ("images/b_yellow.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "going_down_critical": case "going_down_critical":
case "going_up_critical": //This is to be backwards compatible 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, $output .= html_print_image ("images/b_red.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "going_up_normal": case "going_up_normal":
case "going_down_normal": //This is to be backwards compatible 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, $output .= html_print_image ("images/b_green.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "going_down_warning": case "going_down_warning":
if ($only_url) {
$output = $urlImage . "/" . "images/b_yellow.png";
}
else {
$output .= html_print_image ("images/b_yellow.png", true, $output .= html_print_image ("images/b_yellow.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "alert_fired": case "alert_fired":
if ($only_url) {
$output = $urlImage . "/" . "images/bell.png";
}
else {
$output .= html_print_image ("images/bell.png", true, $output .= html_print_image ("images/bell.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "system"; case "system":
if ($only_url) {
$output = $urlImage . "/" . "images/cog.png";
}
else {
$output .= html_print_image ("images/cog.png", true, $output .= html_print_image ("images/cog.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "recon_host_detected"; case "recon_host_detected":
if ($only_url) {
$output = $urlImage . "/" . "images/network.png";
}
else {
$output .= html_print_image ("images/network.png", true, $output .= html_print_image ("images/network.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "new_agent"; case "new_agent":
if ($only_url) {
$output = $urlImage . "/" . "images/wand.png";
}
else {
$output .= html_print_image ("images/wand.png", true, $output .= html_print_image ("images/wand.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
case "unknown": case "unknown":
default: default:
if ($only_url) {
$output = $urlImage . "/" . "images/err.png";
}
else {
$output .= html_print_image ("images/err.png", true, $output .= html_print_image ("images/err.png", true,
array ("title" => events_print_type_description($type, true))); array ("title" => events_print_type_description($type, true)));
}
break; break;
} }