2013-02-27 Dario Rodriguez <dario@artica.es>

* include/functions_events.php: Added new fields to events_create_event 
	function: critical warning and unknown instructions, source and tags.
	* include/functions_api.php: Reimplemented api_create_event API function, 
	the behaviour was completly wrong from documented and events_create_event
	function.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7733 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
darode 2013-02-27 16:03:22 +00:00
parent b261b2dbf9
commit f6f7bbcaeb
3 changed files with 100 additions and 87 deletions

View File

@ -1,3 +1,11 @@
2013-02-27 Dario Rodriguez <dario@artica.es>
* include/functions_events.php: Added new fields to events_create_event
function: critical warning and unknown instructions, source and tags.
* include/functions_api.php: Reimplemented api_create_event API function,
the behaviour was completly wrong from documented and events_create_event
function.
2013-02-27 Miguel de Dios <miguel.dedios@artica.es> 2013-02-27 Miguel de Dios <miguel.dedios@artica.es>
* godmode/setup/setup_general.php, godmode/setup/setup_netflow.php, * godmode/setup/setup_general.php, godmode/setup/setup_netflow.php,

View File

@ -5589,97 +5589,102 @@ function api_set_create_event($id, $trash1, $other, $returnType) {
$values = array(); $values = array();
if ($other['data'][0] != '') if ($other['data'][0] != '') {
$values['id_grupo'] = $other['data'][0]; $values['event'] = $other['data'][0];
else { } else {
returnError('error_parameter', 'Id group required.'); returnError('error_parameter', 'Event text required.');
return;
}
if ($other['data'][1] != '') {
$values['id_grupo'] = $other['data'][1];
} else {
returnError('error_parameter', 'Group ID required.');
return; return;
} }
if ($other['data'][1] != '')
$values['event_type'] = $other['data'][1]; if ($other['data'][2] != '') {
else {
returnError('error_parameter', 'Event type required.');
return;
}
if ($other['data'][2] != '')
$values['id_agente'] = $other['data'][2]; $values['id_agente'] = $other['data'][2];
else { } else {
if ($other['data'][3] != '') { returnError('error_parameter', 'Agent ID required.');
$agent_name = $other['data'][3]; return;
$id_agent = agents_get_agent_id ($agent_name);
if ($id_agent !== false) {
$values['id_agente'] = $id_agent;
}
}
} }
if ($other['data'][4] != '')
$values['id_usuario'] = $other['data'][4];
if ($other['data'][5] != '') if ($other['data'][3] != '') {
$values['estado'] = $other['data'][5]; $values['status'] = $other['data'][3];
$values['timestamp'] = date("Y-m-d H:i:s", get_system_time()); } else {
$values['status'] = 0;
$values['evento'] = $id;
$values['utimestamp'] = get_system_time ();
if ($other['data'][6] != '')
$values['id_agentmodule'] = $other['data'][6];
else {
if ($other['data'][7] != '') {
$module_name = $other['data'][7];
$id_agent_module = modules_get_agentmodule_id ($module_name, $values['id_agente']);
if ($id_agent_module !== false) {
$values['id_agentmodule'] = $id_agent_module;
}
}
} }
if ($other['data'][8] != '')
$values['id_usuario'] = $other['data'][4];
if ($other['data'][5] != '') {
$values['event_type'] = $other['data'][5];
} else {
$values['event_type'] = "unknown";
}
if ($other['data'][6] != '') {
$values['priority'] = $other['data'][6];
} else {
$values['priority'] = 0;
}
if ($other['data'][7] != '') {
$values['id_agentmodule'] = $other['data'][7];
} else {
$value['id_agentemodule'] = 0;
}
if ($other['data'][8] != '') {
$values['id_alert_am'] = $other['data'][8]; $values['id_alert_am'] = $other['data'][8];
} else {
$values['id_alert_am'] = 0;
}
if ($other['data'][9] != '') if ($other['data'][9] != '') {
$values['criticity'] = $other['data'][9]; $values['critical_instructions'] = $other['data'][9];
} else {
$values['critical_instructions'] = '';
}
if ($other['data'][10] != '') {
$values['warning_instructions'] = $other['data'][10];
} else {
$values['warning_instructions'] = '';
}
if ($other['data'][11] != '') {
$values['unknown_instructions'] = $other['data'][11];
} else {
$values['unknown_instructions'] = '';
}
if ($other['data'][11] != '')
$values['tags'] = $other['data'][11];
if ($other['data'][12] != '')
$values['source'] = $other['data'][12];
else
$values['source'] = 'Pandora';
if ($other['data'][13] != '')
$values['id_extra'] = $other['data'][13];
if ($other['data'][14] != '') { if ($other['data'][14] != '') {
$values['critical_instructions'] = $other['data'][14]; $values['source'] = $other['data'][14];
} else {
$values['source'] = "Pandora";
} }
if ($other['data'][15] != '') { if ($other['data'][15] != '') {
$values['warning_instructions'] = $other['data'][15]; $values['tags'] = $other['data'][15];
} } else {
if ($other['data'][16] != '') { $values['tags'] = "";
$values['unknown_instructions'] = $other['data'][16];
}
$values ['ack_utimestamp'] = 0;
if (preg_match("/\w*alert\w*/", $values['event_type'])) {
if (($values['id_alert_am'] == '') || ($values['id_alert_am'] == 0)) {
returnError('error_parameter', 'Id alert required for this type of event.');
return;
}
}
if (preg_match("/\w*going\w*/", $values['event_type'])) {
if (($values['id_agentmodule'] == '') || ($values['id_agentmodule'] == 0)) {
returnError('error_parameter', 'Id agent module required for this type of event.');
return;
}
} }
$return = db_process_sql_insert('tevento', $values); $return = events_create_event($values['event'], $values['id_grupo'], $values['id_agente'],
$values['status'], $values['id_usuario'], $values['event_type'],
$values['priority'], $value['id_agentemodule'], $values['id_alert_am'],
$values['critical_instructions'], $values['warning_instructions'],
$values['unknown_instructions'], $values['source'], $values['tags']);
if ($other['data'][10] != '') { //user comments if ($other['data'][12] != '') { //user comments
if ($return !== false) { //event successfully created if ($return !== false) { //event successfully created
$user_comment = $other['data'][10]; $user_comment = $other['data'][12];
$res = events_comment ($return, $user_comment); $res = events_comment ($return, $user_comment);
if ($other['data'][17] != '') { //owner user if ($other['data'][13] != '') { //owner user
if ($res !== false) { //comment added if ($res !== false) { //comment added
$owner_user = $other['data'][17]; $owner_user = $other['data'][13];
events_change_owner ($return, $owner_user, true); events_change_owner ($return, $owner_user, true);
} }
} }

View File

@ -660,33 +660,33 @@ function events_get_description ($id_event) {
* *
* @return int event id * @return int event id
*/ */
function events_create_event ($event, $id_group, $id_agent, $status = 0, $id_user = "", $event_type = "unknown", $priority = 0, $id_agent_module = 0, $id_aam = 0, $critical_instructions = '', $warning_instructions = '', $unknown_instructions = '') { function events_create_event ($event, $id_group, $id_agent, $status = 0, $id_user = "", $event_type = "unknown", $priority = 0, $id_agent_module = 0, $id_aam = 0, $critical_instructions = '', $warning_instructions = '', $unknown_instructions = '', $source="Pandora", $tags="") {
global $config; global $config;
switch ($config["dbtype"]) { switch ($config["dbtype"]) {
case "mysql": case "mysql":
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, $sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
estado, utimestamp, id_usuario, event_type, criticity, estado, utimestamp, id_usuario, event_type, criticity,
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions) id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags)
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()), "%s", "%s", %d, %d, %d)', VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s")',
$id_agent, $id_group, $event, $status, $id_user, $event_type, $id_agent, $id_group, $event, $status, $id_user, $event_type,
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions); $priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags);
break; break;
case "postgresql": case "postgresql":
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, $sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
estado, utimestamp, id_usuario, event_type, criticity, estado, utimestamp, id_usuario, event_type, criticity,
id_agentmodule, id_alert_am) id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags)
VALUES (%d, %d, "%s", NOW(), %d, ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s", "%s", %d, %d, %d)', VALUES (%d, %d, "%s", NOW(), %d, ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s")',
$id_agent, $id_group, $event, $status, $id_user, $event_type, $id_agent, $id_group, $event, $status, $id_user, $event_type,
$priority, $id_agent_module, $id_aam); $priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags);
break; break;
case "oracle": case "oracle":
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp, $sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
estado, utimestamp, id_usuario, event_type, criticity, estado, utimestamp, id_usuario, event_type, criticity,
id_agentmodule, id_alert_am) id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags)
VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d, ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)), "%s", "%s", %d, %d, %d)', VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d, ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s")',
$id_agent, $id_group, $event, $status, $id_user, $event_type, $id_agent, $id_group, $event, $status, $id_user, $event_type,
$priority, $id_agent_module, $id_aam); $priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags);
break; break;
} }