diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f67c496824..3adeb1ddf3 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,17 @@ +2013-09-09 Ramon Novoa + + * 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 * extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql, diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql index 27d77448ff..48c37f0dd9 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.mysql.sql @@ -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` diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql index badb0d7f7d..5825a4b37b 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.oracle.sql @@ -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 diff --git a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql index c9e14994a6..4fb53b1585 100644 --- a/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql +++ b/pandora_console/extras/pandoradb_migrate_4.0.x_to_5.0.postgreSQL.sql @@ -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" diff --git a/pandora_console/include/ajax/events.php b/pandora_console/include/ajax/events.php index d6a1a864be..8c584096ca 100644 --- a/pandora_console/include/ajax/events.php +++ b/pandora_console/include/ajax/events.php @@ -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 .= "
  • ".html_print_image('images/event_responses_col.png',true).__('Responses')."
  • "; } + if ($event['custom_data'] != '') { + $tabs .= "
  • ".html_print_image('images/custom_field_col.png',true).__('Custom data')."
  • "; + } $tabs .= ""; // 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']). ''; @@ -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 .= ' diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index d6ccb2463f..8435cc5d2b 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -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 diff --git a/pandora_console/include/functions_events.php b/pandora_console/include/functions_events.php index 5495f2f0e2..84ace49135 100644 --- a/pandora_console/include/functions_events.php +++ b/pandora_console/include/functions_events.php @@ -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 '
    '.__('Invalid custom data: %s', $json_custom_data).'
    '; + } + + $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 = '
    '.html_print_table($table, true).'
    '; + + return $custom_data; +} + function events_page_general ($event) { global $img_sev; global $config; diff --git a/pandora_console/include/javascript/pandora_events.js b/pandora_console/include/javascript/pandora_events.js index f0f99e18f0..6d6fc9caa1 100644 --- a/pandora_console/include/javascript/pandora_events.js +++ b/pandora_console/include/javascript/pandora_events.js @@ -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 (); diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index e6fece988d..923975a996 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -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); diff --git a/pandora_console/pandoradb.postgreSQL.sql b/pandora_console/pandoradb.postgreSQL.sql index 8ddc790431..9870fbcb33 100644 --- a/pandora_console/pandoradb.postgreSQL.sql +++ b/pandora_console/pandoradb.postgreSQL.sql @@ -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"); diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index f4df405d55..7e434320d3 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -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`),