2013-09-09 Ramon Novoa <rnovoa@artica.es>

* extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
	  extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
	  extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
	  include/ajax/events.php,
	  include/functions_api.php,
	  include/functions_events.php,
	  include/javascript/pandora_events.js,
	  pandoradb.sql,
	  pandoradb.postgreSQL.sql,
	  pandoradb.oracle.sql: Added support for event custom data (via CLI
	  and API).



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8754 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2013-09-09 16:21:45 +00:00
parent 9173d085b7
commit ebfb062743
11 changed files with 87 additions and 15 deletions

View File

@ -1,3 +1,17 @@
2013-09-09 Ramon Novoa <rnovoa@artica.es>
* extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql,
extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql,
include/ajax/events.php,
include/functions_api.php,
include/functions_events.php,
include/javascript/pandora_events.js,
pandoradb.sql,
pandoradb.postgreSQL.sql,
pandoradb.oracle.sql: Added support for event custom data (via CLI
and API).
2013-09-05 Ramon Novoa <rnovoa@artica.es>
* extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql,

View File

@ -139,6 +139,7 @@ ALTER TABLE `tevento` ADD COLUMN `warning_instructions` TEXT NOT NULL DEFAULT ''
ALTER TABLE `tevento` ADD COLUMN `unknown_instructions` TEXT NOT NULL DEFAULT '';
ALTER TABLE `tevento` ADD COLUMN `owner_user` VARCHAR(100) NOT NULL DEFAULT '';
ALTER TABLE `tevento` ADD COLUMN `ack_utimestamp` BIGINT(20) NOT NULL DEFAULT '0';
ALTER TABLE `tevento` ADD COLUMN `custom_data` TEXT NOT NULL DEFAULT '';
-- ----------------------------------------------------------------------
-- Table `tgrupo`

View File

@ -166,6 +166,7 @@ ALTER TABLE tevento ADD (unknown_instructions VARCHAR2(255) default '');
ALTER TABLE tevento MODIFY CONSTRAINT tevento_event_type_cons CHECK (event_type IN ('going_unknown','unknown','alert_fired','alert_recovered','alert_ceased','alert_manual_validation','recon_host_detected','system','error','new_agent','going_up_warning','going_up_critical','going_down_warning','going_down_normal','going_down_critical','going_up_normal', 'configuration_change'))
ALTER TABLE tevento ADD (owner_user VARCHAR2(100) NOT NULL default '0');
ALTER TABLE tevento ADD (ack_utimestamp NUMBER(19, 0) NOT NULL default 0);
ALTER TABLE tevento ADD (custom_data VARCHAR2(255) default '');
-- ---------------------------------------------------------------------
-- Table tgrupo

View File

@ -157,6 +157,7 @@ ALTER TABLE "tevento" ADD COLUMN "unknown_instructions" text default '';
ALTER TYPE type_tevento_event ADD VALUE 'going_unknown' BEFORE 'unknown';
ALTER TABLE "tevento" ADD COLUMN "owner_user" varchar(100) NOT NULL default '0';
ALTER TABLE "tevento" ADD COLUMN "ack_utimestamp" BIGINT NOT NULL default 0;
ALTER TABLE "tevento" ADD COLUMN "custom_data" text NULL default '';
-- -----------------------------------------------------
-- Table "tgrupo"

View File

@ -288,6 +288,9 @@ if ($get_extended_event) {
(tags_check_acl ($config['id_user'], $event['id_grupo'], "EW", $event['clean_tags']) || tags_check_acl ($config['id_user'], $event['id_grupo'], "EM", $event['clean_tags']))) {
$tabs .= "<li><a href='#extended_event_responses_page' id='link_responses'>".html_print_image('images/event_responses_col.png',true).__('Responses')."</a></li>";
}
if ($event['custom_data'] != '') {
$tabs .= "<li><a href='#extended_event_custom_data_page' id='link_custom_data'>".html_print_image('images/custom_field_col.png',true).__('Custom data')."</a></li>";
}
$tabs .= "</ul>";
// Get criticity image
@ -338,6 +341,8 @@ if ($get_extended_event) {
$custom_fields = events_page_custom_fields($event);
$custom_data = events_page_custom_data($event);
if ($meta) {
metaconsole_restore_db_force();
}
@ -364,6 +369,7 @@ if ($get_extended_event) {
$custom_fields.
$comments.
$responses.
$custom_data.
html_print_input_hidden('id_event',$event['id_evento']).
'</div>';
@ -390,6 +396,9 @@ if ($get_extended_event) {
case "responses":
$js .= '$tabs.tabs( "option", "active", 4);';
break;
case "custom_data":
$js .= '$tabs.tabs( "option", "active", 5);';
break;
}
$js .= '

View File

@ -6123,7 +6123,7 @@ function api_set_create_tag ($id, $trash1, $other, $returnType) {
}
//http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_event&id=name_event&other=2|system|3|admin|2|1|10|0|comments||Pandora||critical_inst|warning_inst|unknown_inst|other&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora
//http://127.0.0.1/pandora_console/include/api.php?op=set&op2=create_event&id=name_event&other=2|system|3|admin|2|1|10|0|comments||Pandora||critical_inst|warning_inst|unknown_inst|other||&other_mode=url_encode_separator_|&apipass=1234&user=admin&pass=pandora
function api_set_create_event($id, $trash1, $other, $returnType) {
if ($other['type'] == 'string') {
@ -6229,12 +6229,20 @@ function api_set_create_event($id, $trash1, $other, $returnType) {
else {
$values['tags'] = "";
}
if ($other['data'][16] != '') {
$values['custom_data'] = $other['data'][16];
}
else {
$values['custom_data'] = "";
}
$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']);
$values['unknown_instructions'], $values['source'], $values['tags'],
$values['custom_data']);
if ($other['data'][12] != '') { //user comments
if ($return !== false) { //event successfully created

View File

@ -734,33 +734,33 @@ function events_get_description ($id_event) {
*
* @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 = '', $source="Pandora", $tags="") {
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="", $custom_data="") {
global $config;
switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
estado, utimestamp, id_usuario, event_type, criticity,
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, "%s", "%s", "%s", "%s", "%s")',
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags, custom_data)
VALUES (%d, %d, "%s", NOW(), %d, UNIX_TIMESTAMP(NOW()), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
$id_agent, $id_group, $event, $status, $id_user, $event_type,
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags);
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags, $custom_data);
break;
case "postgresql":
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
estado, utimestamp, id_usuario, event_type, criticity,
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, "%s", "%s", "%s", "%s", "%s")',
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags, custom_data)
VALUES (%d, %d, "%s", NOW(), %d, ceil(date_part(\'epoch\', CURRENT_TIMESTAMP)), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
$id_agent, $id_group, $event, $status, $id_user, $event_type,
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags);
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags, $custom_data);
break;
case "oracle":
$sql = sprintf ('INSERT INTO tevento (id_agente, id_grupo, evento, timestamp,
estado, utimestamp, id_usuario, event_type, criticity,
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, "%s", "%s", "%s", "%s", "%s")',
id_agentmodule, id_alert_am, critical_instructions, warning_instructions, unknown_instructions, source, tags, custom_data)
VALUES (%d, %d, "%s", CURRENT_TIMESTAMP, %d, ceil((sysdate - to_date(\'19700101000000\',\'YYYYMMDDHH24MISS\')) * (86400)), "%s", "%s", %d, %d, %d, "%s", "%s", "%s", "%s", "%s", "%s")',
$id_agent, $id_group, $event, $status, $id_user, $event_type,
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags);
$priority, $id_agent_module, $id_aam, $critical_instructions, $warning_instructions, $unknown_instructions, $source, $tags, $custom_data);
break;
}
@ -2109,6 +2109,41 @@ function events_page_details ($event, $server = "") {
return $details;
}
function events_page_custom_data ($event) {
global $config;
////////////////////////////////////////////////////////////////////
// Custom data
////////////////////////////////////////////////////////////////////
if ($event['custom_data'] == '') {
return '';
}
$table->width = '100%';
$table->data = array ();
$table->head = array ();
$table->style[0] = 'width:35%; font-weight: bold; text-align: left;';
$table->style[1] = 'text-align: left;';
$table->class = "alternate rounded_cells";
$json_custom_data = base64_decode ($event['custom_data']);
$custom_data = json_decode ($json_custom_data);
if ($custom_data === NULL) {
return '<div id="extended_event_custom_data_page" class="extended_event_pages">'.__('Invalid custom data: %s', $json_custom_data).'</div>';
}
$i = 0;
foreach ($custom_data as $field => $value) {
$table->data[$i][0] = io_safe_output ($field);
$table->data[$i][1] = io_safe_output ($value);
$i++;
}
$custom_data = '<div id="extended_event_custom_data_page" class="extended_event_pages">'.html_print_table($table, true).'</div>';
return $custom_data;
}
function events_page_general ($event) {
global $img_sev;
global $config;

View File

@ -46,7 +46,7 @@ function show_event_dialog(event_id, group_rep, dialog_page, result) {
opacity: 0.5,
background: "black"
},
width: 700,
width: 725,
height: 510
})
.show ();

View File

@ -538,6 +538,7 @@ CREATE TABLE tevento (
unknown_instructions VARCHAR2(255) default '',
owner_user VARCHAR2(100) default '0' NOT NULL,
ack_utimestamp NUMBER(19, 0) default 0 NOT NULL,
custom_data CLOB,
CONSTRAINT tevento_event_type_cons CHECK (event_type IN ('going_unknown','unknown','alert_fired','alert_recovered','alert_ceased','alert_manual_validation','recon_host_detected','system','error','new_agent','going_up_warning','going_up_critical','going_down_warning','going_down_normal','going_down_critical','going_up_normal', 'configuration_change'))
);
CREATE INDEX tevento_id_1_idx ON tevento(id_agente, id_evento);

View File

@ -456,7 +456,8 @@ CREATE TABLE "tevento" (
"warning_instructions" TEXT default '',
"unknown_instructions" TEXT default '',
"owner_user" varchar(100) NOT NULL default '0',
"ack_utimestamp" BIGINT NOT NULL default 0
"ack_utimestamp" BIGINT NOT NULL default 0,
"custom_data" text NOT NULL
);
CREATE INDEX "tevento_id_1_idx" ON "tevento"("id_agente", "id_evento");
CREATE INDEX "tevento_id_2_idx" ON "tevento"("utimestamp", "id_evento");

View File

@ -507,6 +507,7 @@ CREATE TABLE IF NOT EXISTS `tevento` (
`unknown_instructions` text NOT NULL default '',
`owner_user` VARCHAR(100) NOT NULL DEFAULT '',
`ack_utimestamp` BIGINT(20) NOT NULL DEFAULT '0',
`custom_data` TEXT NOT NULL,
PRIMARY KEY (`id_evento`),
KEY `idx_agente` (`id_agente`),
KEY `idx_agentmodule` (`id_agentmodule`),