From eeec94d61e30d08167c6eace4471fba9834fe183 Mon Sep 17 00:00:00 2001 From: juanmanuelr Date: Fri, 20 May 2011 10:47:42 +0000 Subject: [PATCH] 2011-05-20 Juan Manuel Ramon * include/db/oracle.php include/functions_agents.php include/functions_db.php include/functions_alerts.php pandoradb.oracle.sql pandoradb.data.oracle.sql godmode/alerts/configure_alert_compound.php godmode/alerts/configure_alert_template.php godmode/snmpconsole/snmp_alert.php godmode/users/configure_user.php godmode/reporting/reporting_builder.list_items.php godmode/reporting/reporting_builder.php: Several corrections over Console code for Oracle support. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4371 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 16 +++ .../alerts/configure_alert_compound.php | 64 ++++++++--- .../alerts/configure_alert_template.php | 103 +++++++++++++----- .../reporting_builder.list_items.php | 75 +++++++++---- .../godmode/reporting/reporting_builder.php | 39 +++++-- .../godmode/snmpconsole/snmp_alert.php | 13 ++- .../godmode/users/configure_user.php | 19 +++- pandora_console/include/db/oracle.php | 20 ++-- pandora_console/include/functions_agents.php | 47 +++++++- pandora_console/include/functions_alerts.php | 44 +++++++- pandora_console/include/functions_db.php | 26 +++-- pandora_console/pandoradb.data.oracle.sql | 18 +-- pandora_console/pandoradb.oracle.sql | 4 +- 13 files changed, 374 insertions(+), 114 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index f048a77ca3..b63c459a48 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,19 @@ +2011-05-20 Juan Manuel Ramon + + * include/db/oracle.php + include/functions_agents.php + include/functions_db.php + include/functions_alerts.php + pandoradb.oracle.sql + pandoradb.data.oracle.sql + godmode/alerts/configure_alert_compound.php + godmode/alerts/configure_alert_template.php + godmode/snmpconsole/snmp_alert.php + godmode/users/configure_user.php + godmode/reporting/reporting_builder.list_items.php + godmode/reporting/reporting_builder.php: Several corrections + over Console code for Oracle support. + 2011-05-19 Vanessa Gil * operation/agentes/alerts_status.php diff --git a/pandora_console/godmode/alerts/configure_alert_compound.php b/pandora_console/godmode/alerts/configure_alert_compound.php index 8597abbbf8..04f012c513 100644 --- a/pandora_console/godmode/alerts/configure_alert_compound.php +++ b/pandora_console/godmode/alerts/configure_alert_compound.php @@ -95,6 +95,8 @@ function print_alert_compound_steps ($step, $id) { } function update_compound ($step) { + global $config; + $id = (int) get_parameter ('id'); if (empty ($id)) @@ -138,20 +140,40 @@ function update_compound ($step) { $min_alerts = (int) get_parameter ('min_alerts'); if ($threshold == -1) $threshold = (int) get_parameter ('other_threshold'); - - $values = array ('monday' => $monday, - 'tuesday' => $tuesday, - 'wednesday' => $wednesday, - 'thursday' => $thursday, - 'friday' => $friday, - 'saturday' => $saturday, - 'sunday' => $sunday, - 'time_from' => $time_from, - 'time_to' => $time_to, - 'time_threshold' => $threshold, - 'max_alerts' => $max_alerts, - 'min_alerts' => $min_alerts - ); + + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $values = array ('monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'time_from' => $time_from, + 'time_to' => $time_to, + 'time_threshold' => $threshold, + 'max_alerts' => $max_alerts, + 'min_alerts' => $min_alerts + ); + break; + case "oracle": + $values = array ('monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'time_from' => "#to_date('" . $time_from . "', 'hh24:mi:ss')", + 'time_to' => "#to_date('" . $time_to . "', 'hh24:mi:ss')", + 'time_threshold' => $threshold, + 'max_alerts' => $max_alerts, + 'min_alerts' => $min_alerts + ); + break; + } $result = alerts_update_alert_compound ($id, $values); @@ -355,8 +377,18 @@ if ($step == 2) { 5, 7, true); $table->data[4][0] = __('Actions'); - $table->data[4][1] = html_print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', - 'action', '', '', __('Select'), 0, true, false, false).' '; + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $table->data[4][1] = html_print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', + 'action', '', '', __('Select'), 0, true, false, false).' '; + break; + case "oracle": + $table->data[4][1] = html_print_select_from_sql ('SELECT id, dbms_lob.substr(name,4000,1) as name FROM talert_actions ORDER BY dbms_lob.substr(name,4000,1)', + 'action', '', '', __('Select'), 0, true, false, false).' '; + break; + } + $table->data[4][1] .= html_print_button (__('Add'), 'add_action', false, '', 'class="sub next"', true); $table->data[4][1] .= '
'; diff --git a/pandora_console/godmode/alerts/configure_alert_template.php b/pandora_console/godmode/alerts/configure_alert_template.php index b5e6248b7d..9ffdaea90b 100644 --- a/pandora_console/godmode/alerts/configure_alert_template.php +++ b/pandora_console/godmode/alerts/configure_alert_template.php @@ -161,6 +161,8 @@ function print_alert_template_steps ($step, $id) { } function update_template ($step) { + global $config; + $id = (int) get_parameter ('id'); if (empty ($id)) @@ -213,25 +215,47 @@ function update_template ($step) { if (empty ($default_action)) { $default_action = NULL; } - - $values = array ('monday' => $monday, - 'tuesday' => $tuesday, - 'wednesday' => $wednesday, - 'thursday' => $thursday, - 'friday' => $friday, - 'saturday' => $saturday, - 'sunday' => $sunday, - 'time_from' => $time_from, - 'time_to' => $time_to, - 'time_threshold' => $threshold, - 'id_alert_action' => $default_action, - 'field1' => $field1, - 'field2' => $field2, - 'field3' => $field3, - 'max_alerts' => $max_alerts, - 'min_alerts' => $min_alerts - ); - + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $values = array ('monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'time_from' => $time_from, + 'time_to' => $time_to, + 'time_threshold' => $threshold, + 'id_alert_action' => $default_action, + 'field1' => $field1, + 'field2' => $field2, + 'field3' => $field3, + 'max_alerts' => $max_alerts, + 'min_alerts' => $min_alerts + ); + break; + case "oracle": + $values = array ('monday' => $monday, + 'tuesday' => $tuesday, + 'wednesday' => $wednesday, + 'thursday' => $thursday, + 'friday' => $friday, + 'saturday' => $saturday, + 'sunday' => $sunday, + 'time_from' => "#to_date('" . $time_from . "','hh24:mi:ss')", + 'time_to' => "#to_date('" . $time_to . "','hh24:mi:ss')", + 'time_threshold' => $threshold, + 'id_alert_action' => $default_action, + 'field1' => $field1, + 'field2' => $field2, + 'field3' => $field3, + 'max_alerts' => $max_alerts, + 'min_alerts' => $min_alerts + ); + break; + } $result = alerts_update_alert_template ($id, $values); } elseif ($step == 3) { @@ -307,14 +331,29 @@ if ($create_template) { $priority = (int) get_parameter ('priority'); $id_group = get_parameter ("id_group"); - $values = array ('description' => $description, - 'value' => $value, - 'max_value' => $max, - 'min_value' => $min, - 'id_group' => $id_group, - 'matches_value' => $matches, - 'priority' => $priority); - + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $values = array ('description' => $description, + 'value' => $value, + 'max_value' => $max, + 'min_value' => $min, + 'id_group' => $id_group, + 'matches_value' => $matches, + 'priority' => $priority); + break; + case "oracle": + $values = array ('description' => $description, + 'value' => $value, + 'max_value' => $max, + 'min_value' => $min, + 'id_group' => $id_group, + 'matches_value' => $matches, + 'priority' => $priority, + 'field3' => ' ', + 'field3_recovery' => ' '); + break; + } $result = alerts_create_alert_template ($name, $type, $values); if ($result) { @@ -457,7 +496,15 @@ if ($step == 2) { $table->data[4][0] = __('Default action'); $usr_groups = implode(',', array_keys(users_get_groups($config['id_user'], 'LM', true))); - $sql_query = sprintf('SELECT id, name FROM talert_actions WHERE id_group IN (%s) ORDER BY name', $usr_groups); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $sql_query = sprintf('SELECT id, name FROM talert_actions WHERE id_group IN (%s) ORDER BY name', $usr_groups); + break; + case "oracle": + $sql_query = sprintf('SELECT id, dbms_lob.substr(name,4000,1) as nombre FROM talert_actions WHERE id_group IN (%s) ORDER BY dbms_lob.substr(name,4000,1)', $usr_groups); + break; + } $table->data[4][1] = html_print_select_from_sql ($sql_query, 'default_action', $default_action, '', __('None'), 0, true, false, false).ui_print_help_tip (__('In case you fill any Field 1, Field 2 or Field 3 above, those will replace the corresponding fields of this associated "Default action".'), true); diff --git a/pandora_console/godmode/reporting/reporting_builder.list_items.php b/pandora_console/godmode/reporting/reporting_builder.list_items.php index cf01331ad5..070f914507 100644 --- a/pandora_console/godmode/reporting/reporting_builder.list_items.php +++ b/pandora_console/godmode/reporting/reporting_builder.list_items.php @@ -26,19 +26,37 @@ if (! check_acl ($config['id_user'], 0, "IW")) { include_once($config['homedir'] . "/include/functions_agents.php"); //FORM FILTER -$rows = db_get_all_rows_sql(' - SELECT t5.nombre, t5.id_agente - FROM - ( - SELECT t1.*, id_agente - FROM treport_content AS t1 - LEFT JOIN tagente_modulo AS t2 - ON t1.id_agent_module = id_agente_modulo - ) AS t4 - INNER JOIN tagente AS t5 - ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente) - WHERE t4.id_report = ' . $idReport); - +switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $rows = db_get_all_rows_sql(' + SELECT t5.nombre, t5.id_agente + FROM + ( + SELECT t1.*, id_agente + FROM treport_content AS t1 + LEFT JOIN tagente_modulo AS t2 + ON t1.id_agent_module = id_agente_modulo + ) AS t4 + INNER JOIN tagente AS t5 + ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente) + WHERE t4.id_report = ' . $idReport); + break; + case "oracle": + $rows = db_get_all_rows_sql(' + SELECT t5.nombre, t5.id_agente + FROM + ( + SELECT t1.*, id_agente + FROM treport_content t1 + LEFT JOIN tagente_modulo t2 + ON t1.id_agent_module = id_agente_modulo + ) t4 + INNER JOIN tagente t5 + ON (t4.id_agent = t5.id_agente OR t4.id_agente = t5.id_agente) + WHERE t4.id_report = ' . $idReport); + break; +} if ($rows === false) { $rows = array(); } @@ -48,12 +66,25 @@ foreach ($rows as $row) { $agents[$row['id_agente']] = $row['nombre']; } -$rows = db_get_all_rows_sql(' - SELECT t1.id_agent_module, t2.nombre - FROM treport_content AS t1 - INNER JOIN tagente_modulo AS t2 - ON t1.id_agent_module = t2.id_agente_modulo - WHERE t1.id_report = ' . $idReport); +switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $rows = db_get_all_rows_sql(' + SELECT t1.id_agent_module, t2.nombre + FROM treport_content AS t1 + INNER JOIN tagente_modulo AS t2 + ON t1.id_agent_module = t2.id_agente_modulo + WHERE t1.id_report = ' . $idReport); + break; + case "oracle": + $rows = db_get_all_rows_sql(' + SELECT t1.id_agent_module, t2.nombre + FROM treport_content t1 + INNER JOIN tagente_modulo t2 + ON t1.id_agent_module = t2.id_agente_modulo + WHERE t1.id_report = ' . $idReport); + break; +} if ($rows === false) { $rows = array(); } @@ -143,8 +174,10 @@ switch ($config["dbtype"]) { $set['offset'] = $offset; $items = oracle_recode_query ('SELECT * FROM treport_content WHERE ' . $where . ' AND id_report = ' . $idReport . ' ORDER BY "order"', $set, 'AND', false); // Delete rnum row generated by oracle_recode_query() function - for ($i=0; $i < count($items); $i++) { - unset($items[$i]['rnum']); + if ($items !== false){ + for ($i=0; $i < count($items); $i++) { + unset($items[$i]['rnum']); + } } break; } diff --git a/pandora_console/godmode/reporting/reporting_builder.php b/pandora_console/godmode/reporting/reporting_builder.php index 92dfceee0e..fff5601e43 100644 --- a/pandora_console/godmode/reporting/reporting_builder.php +++ b/pandora_console/godmode/reporting/reporting_builder.php @@ -232,7 +232,21 @@ switch ($action) { $values['id_gs'] = get_parameter('id_custom_graph'); $values['text'] = get_parameter('text'); $values['id_agent_module'] = get_parameter('id_agent_module'); - $values['only_display_wrong'] = get_parameter('checkbox_only_display_wrong'); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $values['only_display_wrong'] = get_parameter('checkbox_only_display_wrong'); + break; + case "oracle": + $only_display_wrong_tmp = get_parameter('checkbox_only_display_wrong'); + if (empty($only_display_wrong_tmp)){ + $values['only_display_wrong'] = 0; + } + else{ + $values['only_display_wrong'] = $only_display_wrong_tmp; + } + break; + } $values['monday'] = get_parameter('monday', 0); $values['tuesday'] = get_parameter('tuesday', 0); $values['wednesday'] = get_parameter('wednesday', 0); @@ -240,12 +254,21 @@ switch ($action) { $values['friday'] = get_parameter('friday', 0); $values['saturday'] = get_parameter('saturday', 0); $values['sunday'] = get_parameter('sunday', 0); - $values['time_from'] = get_parameter('time_from'); - $values['time_to'] = get_parameter('time_to'); - $values['group_by_agent'] = get_parameter ('checkbox_row_group_by_agent'); - $values['show_resume'] = get_parameter ('checkbox_show_resume'); - $values['order_uptodown'] = get_parameter ('radiobutton_order_uptodown'); - $values['top_n'] = get_parameter('radiobutton_max_min_avg'); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $values['time_from'] = get_parameter('time_from'); + $values['time_to'] = get_parameter('time_to'); + break; + case "oracle": + $values['time_from'] = '#to_date(\'' . get_parameter('time_from') . '\',\'hh24:mi\')'; + $values['time_to'] = '#to_date(\'' . get_parameter('time_to') . '\', \'hh24:mi\')'; + break; + } + $values['group_by_agent'] = get_parameter ('checkbox_row_group_by_agent',0); + $values['show_resume'] = get_parameter ('checkbox_show_resume',0); + $values['order_uptodown'] = get_parameter ('radiobutton_order_uptodown',0); + $values['top_n'] = get_parameter('radiobutton_max_min_avg',0); $values['top_n_value'] = get_parameter('quantity'); $values['exception_condition'] = get_parameter('radiobutton_exception_condition'); $values['exception_condition_value'] = get_parameter('exception_condition_value'); @@ -292,7 +315,7 @@ switch ($action) { case "postgresql": case "oracle": $max = db_get_all_rows_sql('SELECT max("order") AS max - FROM treport_content WHERE id_report = ' . $idReport . ';'); + FROM treport_content WHERE id_report = ' . $idReport); break; } if ($max === false) { diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 013a8df40c..231542d0d7 100644 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -164,8 +164,17 @@ if (isset ($_GET["update_alert"])) { $fields[$row["id"]] = $row["name"]; } - html_print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', - "alert_type", $alert_type, '', '', 0, false, false, false); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + html_print_select_from_sql ('SELECT id, name FROM talert_actions ORDER BY name', + "alert_type", $alert_type, '', '', 0, false, false, false); + break; + case "oracle": + html_print_select_from_sql ('SELECT id, dbms_lob.substr(name,4000,1) as name FROM talert_actions ORDER BY dbms_lob.substr(name,4000,1)', + "alert_type", $alert_type, '', '', 0, false, false, false); + break; + } echo ''; // Description diff --git a/pandora_console/godmode/users/configure_user.php b/pandora_console/godmode/users/configure_user.php index 73eba708f3..635e460d56 100644 --- a/pandora_console/godmode/users/configure_user.php +++ b/pandora_console/godmode/users/configure_user.php @@ -98,13 +98,13 @@ if ($create_user) { $values['email'] = (string) get_parameter ('email'); $values['phone'] = (string) get_parameter ('phone'); $values['comments'] = (string) get_parameter ('comments'); - $values['is_admin'] = get_parameter ('is_admin', 0); + $values['is_admin'] = (int) get_parameter ('is_admin', 0); $values['language'] = get_parameter ('language', $config["language"]); if ($isFunctionSkins !== ENTERPRISE_NOT_HOOK) { - $values['id_skin'] = get_parameter ('skin', 0); + $values['id_skin'] = (int) get_parameter ('skin', 0); } - $values['block_size'] = get_parameter ('block_size', $config["block_size"]); - $values['flash_chart'] = get_parameter ('flash_charts', $config["flash_charts"]); + $values['block_size'] = (int) get_parameter ('block_size', $config["block_size"]); + $values['flash_chart'] = (int) get_parameter ('flash_charts', $config["flash_charts"]); if ($id == '') { ui_print_error_message (__('User ID cannot be empty')); @@ -139,7 +139,16 @@ if ($create_user) { $info .= ' Skin: ' . $values['id_skin']; } - $result = create_user($id, $password_new, $values); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $result = create_user($id, $password_new, $values); + break; + case "oracle": + $result = db_process_sql('/INSERT INTO tusuario (fullname, firstname, lastname, email, phone, comments, is_admin, language, id_skin, block_size, flash_chart, id_user, password, last_connect, registered) VALUES (\'' . $values['fullname'] . '\',\'\',\'\',\'\',\'\',\'\',' . $values['is_admin'] . ',\'' . $values['language'] .'\',' . $values['id_skin'] . ',' . $values['block_size'] . ',' . $values['flash_chart'] . ',\'' . $id . '\',\'' . $password_new . '\',0,\'' . get_system_time () . '\')'); + break; + } + db_pandora_audit("User management", "Created user ".io_safe_input($id), false, false, $info); diff --git a/pandora_console/include/db/oracle.php b/pandora_console/include/db/oracle.php index 2f5ce6fc65..b1752c09b7 100644 --- a/pandora_console/include/db/oracle.php +++ b/pandora_console/include/db/oracle.php @@ -237,7 +237,7 @@ function oracle_db_process_sql($sql, $rettype = "affected_rows", $dbconnection = } // Prevent execution of insert_id stored procedure else if ($type[0] == '/INSERT'){ - $query = oci_parse($dbconnection, substr($sql,1)); + $query = oci_parse($config['dbconnection'], substr($sql,1)); } else{ $query = oci_parse($config['dbconnection'], $sql); @@ -812,8 +812,10 @@ function oracle_recode_query ($sql, $values, $join = 'AND', $return = true) { } else{ $result = oracle_db_process_sql($result); - for ($i=0; $i < count($result); $i++) { - unset($result[$i]['RNUM']); + if ($result !== false){ + for ($i=0; $i < count($result); $i++) { + unset($result[$i]['RNUM']); + } } return $result; } @@ -1080,10 +1082,14 @@ function oracle_db_format_array_to_update_sql ($values) { else { /* String */ if (isset ($value[0]) && $value[0] == '`') - /* Don't round with quotes if it references a field */ - $sql = sprintf ("%s = %s", $field, str_replace('`', '', $value)); - else - $sql = sprintf ("%s = '%s'", $field, $value); + /* Don't round with quotes if it references a field */ + $sql = sprintf ("%s = %s", $field, str_replace('`', '', $value)); + else if (substr($value, 0,1) == '#'){ + $sql = sprintf ("%s = %s", $field, substr($value,1)); + } + else{ + $sql = sprintf ("%s = '%s'", $field, $value); + } } array_push ($fields, $sql); } diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index b75e09e6e4..faad62cb46 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -807,7 +807,7 @@ function agents_get_group_agents ($id_group = 0, $search = false, $case = "lower $search_sql .= ' AND nombre COLLATE utf8_general_ci LIKE \'' . $name . '\' '; break; case "oracle": - $search_sql .= ' AND nombre LIKE UPPER("' . $name . '") '; + $search_sql .= ' AND UPPER(nombre) LIKE UPPER(\'' . $name . '\') '; break; } @@ -962,13 +962,29 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false } if ($value[0] == '%') { - array_push ($fields, $field.' LIKE "'.$value.'"'); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + array_push ($fields, $field.' LIKE "'.$value.'"'); + break; + case "oracle": + array_push ($fields, $field.' LIKE \''.$value.'\''); + break; + } } else if ($operatorDistin) { array_push($fields, $field.' <> ' . substr($value, 2)); } else if (substr($value, -1) == '%') { - array_push ($fields, $field.' LIKE "'.$value.'"'); + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + array_push ($fields, $field.' LIKE "'.$value.'"'); + break; + case "oracle": + array_push ($fields, $field.' LIKE \''.$value.'\''); + break; + } } else { switch ($config["dbtype"]) { @@ -995,10 +1011,29 @@ function agents_get_modules ($id_agent = null, $details = false, $filter = false } if (empty ($details)) { - $details = "nombre"; + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $details = "nombre"; + break; + case "oracle": + $details = "dbms_lob.substr(nombre,4000,1) as nombre"; + } } - else { - $details = io_safe_input ($details); + else { + if ($config['dbtype'] == 'oracle'){ + $details_new = array(); + foreach ($details as $detail){ + if ($detail == 'nombre') + $details_new[] = 'dbms_lob.substr(nombre,4000,1) as nombre'; + else + $details_new[] = $detail; + } + html_debug_print($details_new,"/tmp/prueba.txt"); + $details = io_safe_input ($details_new); + } + else + $details = io_safe_input ($details); } switch ($config["dbtype"]) { diff --git a/pandora_console/include/functions_alerts.php b/pandora_console/include/functions_alerts.php index 551f43e018..92c6caa1e6 100644 --- a/pandora_console/include/functions_alerts.php +++ b/pandora_console/include/functions_alerts.php @@ -552,11 +552,26 @@ function alerts_get_alert_templates ($filter = false, $fields = false) { * @return mixed Selected alert template or false if something goes wrong. */ function alerts_get_alert_template ($id_alert_template) { + global $config; + $id_alert_template = safe_int ($id_alert_template, 1); if (empty ($id_alert_template)) return false; - - return db_get_row ('talert_templates', 'id', $id_alert_template); + + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + return db_get_row ('talert_templates', 'id', $id_alert_template); + break; + case "oracle": + $fields_select = db_get_all_rows_sql('SELECT column_name FROM user_tab_columns WHERE table_name = \'TALERT_TEMPLATES\' AND column_name NOT IN (\'TIME_FROM\',\'TIME_TO\')'); + foreach ($fields_select as $field_select){ + $select_field[] = $field_select['column_name']; + } + $select_stmt = implode(',', $select_field); + return db_get_row_sql("SELECT $select_stmt, to_char(time_from, 'hh24:mi:ss') as time_from, to_char(time_to, 'hh24:mi:ss') as time_to FROM talert_templates"); + break; + } } /** @@ -1234,6 +1249,8 @@ function alerts_compound_operations () { * @return Id of the alert compound of false is something goes wrong. */ function alerts_create_alert_compound ($name, $id_agent, $values = false) { + global $config; + if (empty ($name)) return false; if (! is_array ($values)) @@ -1241,6 +1258,12 @@ function alerts_create_alert_compound ($name, $id_agent, $values = false) { $values['name'] = $name; $values['id_agent'] = (int) $id_agent; + switch($config['dbtype']){ + case "oracle": + $values['field3_recovery'] = ' '; + break; + } + return @db_process_sql_insert ('talert_compound', $values); } @@ -1325,7 +1348,22 @@ function alerts_get_alert_compounds ($filter = false, $fields = false) { * @return Result set of the selected alert compound or false is something goes wrong. */ function alerts_get_alert_compound ($id_alert_compound) { - return db_get_row ('talert_compound', 'id', $id_alert_compound); + global $config; + + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + return db_get_row ('talert_compound', 'id', $id_alert_compound); + break; + case "oracle": + $fields_select = db_get_all_rows_sql('SELECT column_name FROM user_tab_columns WHERE table_name = \'TALERT_COMPOUND\' AND column_name NOT IN (\'TIME_FROM\',\'TIME_TO\')'); + foreach ($fields_select as $field_select){ + $select_field[] = $field_select['column_name']; + } + $select_stmt = implode(',', $select_field); + return db_get_row_sql("SELECT $select_stmt, to_char(time_from, 'hh24:mi:ss') as time_from, to_char(time_to, 'hh24:mi:ss') as time_to FROM talert_compound"); + break; + } } /** diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 537e846282..577f5a81b6 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -127,13 +127,25 @@ function db_pandora_audit($accion, $descripcion, $user_id = false, $ip = false, $accion = io_safe_input($accion); $descripcion = io_safe_input($descripcion); - $values = array('id_usuario' => $id, - 'accion' => $accion, - 'ip_origen' => $ip, - 'descripcion' => $descripcion, - 'fecha' => date('Y-m-d H:i:s'), - 'utimestamp' => time()); - + switch ($config['dbtype']){ + case "mysql": + case "postgresql": + $values = array('id_usuario' => $id, + 'accion' => $accion, + 'ip_origen' => $ip, + 'descripcion' => $descripcion, + 'fecha' => date('Y-m-d H:i:s'), + 'utimestamp' => time()); + break; + case "oracle": + $values = array('id_usuario' => $id, + 'accion' => $accion, + 'ip_origen' => $ip, + 'descripcion' => $descripcion, + 'fecha' => '#to_date(\'' . date('Y-m-d H:i:s') . '\',\'YYYY-MM-DD HH24:MI:SS\')', + 'utimestamp' => time()); + break; + } $id_audit = db_process_sql_insert('tsesion', $values); enterprise_include_once('include/functions_audit.php'); diff --git a/pandora_console/pandoradb.data.oracle.sql b/pandora_console/pandoradb.data.oracle.sql index 41c18bc911..87c43bf095 100644 --- a/pandora_console/pandoradb.data.oracle.sql +++ b/pandora_console/pandoradb.data.oracle.sql @@ -512,15 +512,15 @@ END;; CREATE OR REPLACE PROCEDURE treport_custom_sql_insert (IDX IN NUMBER, NAME IN VARCHAR2, SQL_TXT IN VARCHAR2, FLAG IN NUMBER) AS g_nclob CLOB; BEGIN if FLAG = 0 then insert into treport_custom_sql values (IDX, NAME, empty_clob()) returning SQL into g_nclob; dbms_lob.write(g_nclob, length (SQL_TXT), 1, SQL_TXT); else select SQL into g_nclob from treport_custom_sql where ID = IDX for update; dbms_lob.writeappend( g_nclob, length(SQL_TXT), SQL_TXT); end if; END;; BEGIN -treport_custom_sql_insert(4, 'Group view', 'select t1.nombre, (select count(t3.id_agente) from tagente as t3 where t1.id_grupo =',0); +treport_custom_sql_insert(4, 'Group view', 'select t1.nombre, (select count(t3.id_agente) from tagente t3 where t1.id_grupo =',0); -treport_custom_sql_insert(4, 'Group view',' t3.id_grupo) as agents, (SELECT COUNT(t4.id_agente) FROM tagente as ',1); +treport_custom_sql_insert(4, 'Group view',' t3.id_grupo) agents, (SELECT COUNT(t4.id_agente) FROM tagente ',1); treport_custom_sql_insert(4, 'Group view','t4 WHERE t4.id_grupo = t1.id_grupo AND t4.disabled = 0 AND t4.ultimo_contacto ',1); treport_custom_sql_insert(4, 'Group view','< NOW() - (intervalo /',1); -treport_custom_sql_insert(4, 'Group view',' (1/2))) as agent_unknown, (SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado,',1); +treport_custom_sql_insert(4, 'Group view',' (1/2))) agent_unknown, (SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado,',1); treport_custom_sql_insert(4,'Group view',' tagente, tagente_modulo WHERE tagente.id_grupo = t1.id_grupo AND tagente.disabled = 0 ',1); @@ -532,13 +532,13 @@ treport_custom_sql_insert(4, 'Group view','AND (UNIX_TIMESTAMP( treport_custom_sql_insert(4, 'Group view',' tagente_estado.utimestamp) >= (tagente_estado.current_interval /',1); -treport_custom_sql_insert(4,'Group view',' (1/2))) as monitor_unknow, (SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente,',1); +treport_custom_sql_insert(4,'Group view',' (1/2))) monitor_unknow, (SELECT COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente,',1); treport_custom_sql_insert(4, 'Group view',' tagente_modulo WHERE tagente.id_grupo = t1.id_grupo AND tagente.disabled = 0 AND tagente.id_agente = ',1); treport_custom_sql_insert(4, 'Group view','tagente_estado.id_agente AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 ',1); -treport_custom_sql_insert(4, 'Group view','AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0) as monitor_no_init, (SELECT ',1); +treport_custom_sql_insert(4, 'Group view','AND tagente_modulo.id_tipo_modulo NOT IN (21,22,23,24) AND utimestamp = 0) monitor_no_init, (SELECT ',1); treport_custom_sql_insert(4, 'Group view','COUNT(tagente_estado.id_agente_estado) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = t1.id_grupo ',1); @@ -550,7 +550,7 @@ treport_custom_sql_insert(4, 'Group view',' tagente_estado.utimestamp& treport_custom_sql_insert(4,'Group view',' (1/2)) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND (utimestamp > 0 OR ',1); -treport_custom_sql_insert(4, 'Group view','(tagente_modulo.id_tipo_modulo IN(21,22,23,24)))) as monitor_ok, (SELECT COUNT(tagente_estado.id_agente_estado) ',1); +treport_custom_sql_insert(4, 'Group view','(tagente_modulo.id_tipo_modulo IN(21,22,23,24)))) monitor_ok, (SELECT COUNT(tagente_estado.id_agente_estado) ',1); treport_custom_sql_insert(4, 'Group view','FROM tagente_estado, tagente, tagente_modulo WHERE tagente.id_grupo = t1.id_grupo AND tagente.disabled = 0 AND ',1); @@ -560,7 +560,7 @@ treport_custom_sql_insert(4, 'Group view','#x20;= 0 AND esta treport_custom_sql_insert(4, 'Group view',' tagente_estado.utimestamp) < (tagente_estado.current_interval /',1); -treport_custom_sql_insert(4, 'Group view',' (1/2)) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0) as ',1); +treport_custom_sql_insert(4, 'Group view',' (1/2)) OR (tagente_modulo.id_tipo_modulo IN(21,22,23,24,100))) AND utimestamp > 0) ',1); treport_custom_sql_insert(4, 'Group view','monitor_critical, (SELECT COUNT(talert_template_modules.id) FROM talert_template_modules, tagente_modulo, tagente_estado, tagente ',1); @@ -568,8 +568,8 @@ treport_custom_sql_insert(4, 'Group view','WHERE tagente.id_grupo treport_custom_sql_insert(4, 'Group view','tagente_modulo.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 AND talert_template_modules.id_agent_module ',1); -treport_custom_sql_insert(4, 'Group view','= tagente_modulo.id_agente_modulo AND times_fired > 0) as monitor_alert_fired from tgrupo as t1 where 0 ',1); +treport_custom_sql_insert(4, 'Group view','= tagente_modulo.id_agente_modulo AND times_fired > 0) monitor_alert_fired from tgrupo t1 where 0 ',1); -treport_custom_sql_insert(4, 'Group view','< (select count(t2.id_agente) from tagente as t2 where t1.id_grupo = t2.id_grupo)',1); +treport_custom_sql_insert(4, 'Group view','< (select count(t2.id_agente) from tagente t2 where t1.id_grupo = t2.id_grupo)',1); COMMIT; END;; diff --git a/pandora_console/pandoradb.oracle.sql b/pandora_console/pandoradb.oracle.sql index 197bb87bbc..12b1cbcfa8 100644 --- a/pandora_console/pandoradb.oracle.sql +++ b/pandora_console/pandoradb.oracle.sql @@ -812,8 +812,8 @@ CREATE OR REPLACE TRIGGER ttrap_inc BEFORE INSERT ON ttrap REFERENCING NEW AS NE CREATE TABLE tusuario ( id_user VARCHAR2(60) NOT NULL PRIMARY KEY, fullname VARCHAR2(255) NOT NULL, - firstname VARCHAR2(255) NOT NULL, - lastname VARCHAR2(255) NOT NULL, + firstname VARCHAR2(255), + lastname VARCHAR2(255), middlename VARCHAR2(255) default '', password VARCHAR2(45) default NULL, comments VARCHAR2(200) default NULL,