From 04afb4615db33ab6f59ae706887cde5ab4d143fe Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 21 Aug 2013 12:37:37 +0000 Subject: [PATCH] 2013-08-20 Miguel de Dios * godmode/servers/servers.build_table.php, include/functions_db.php, include/functions_servers.php, index.php: improved the source code style. * include/functions_api.php: added the call to update the agent. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8682 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 +++ .../godmode/servers/servers.build_table.php | 60 ++++++++-------- pandora_console/include/functions_api.php | 69 ++++++++++++++++--- pandora_console/include/functions_db.php | 22 +++--- pandora_console/include/functions_servers.php | 8 ++- pandora_console/index.php | 3 +- 6 files changed, 115 insertions(+), 55 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a16279fd56..27182ba2c7 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2013-08-20 Miguel de Dios + + * godmode/servers/servers.build_table.php, include/functions_db.php, + include/functions_servers.php, index.php: improved the source code + style. + + * include/functions_api.php: added the call to update the agent. + 2013-08-20 Miguel de Dios * include/functions_api.php: added calls to set gis data for agent diff --git a/pandora_console/godmode/servers/servers.build_table.php b/pandora_console/godmode/servers/servers.build_table.php index 3962ba38e7..a88ca41a73 100644 --- a/pandora_console/godmode/servers/servers.build_table.php +++ b/pandora_console/godmode/servers/servers.build_table.php @@ -27,7 +27,7 @@ if (! check_acl ($config["id_user"], 0, "AW")) { global $tiny; -$servers = servers_get_info (); +$servers = servers_get_info(); if ($servers === false) { echo "
".__('There are no servers configured into the database')."
"; return; @@ -101,41 +101,43 @@ foreach ($servers as $server) { default: $data[3] = progress_bar($server["load"], 60, 20, $server["lag_txt"], 0); $data[4] = $server["modules"] . " ".__('of')." ". $server["modules_total"]; - $data[5] = ''.$server["lag_txt"].''; + $data[5] = '' . + $server["lag_txt"] . ''; break; } $data[6] = $server['threads'].' : '.$server['queued_modules']; $data[7] = ui_print_timestamp ($server['keepalive'], true); - //Only Pandora Administrator can delete servers - if (check_acl ($config["id_user"], 0, "PM")) { - $data[8] = ''; - if ($server['type'] == 'data') { - $data[8] .= ''; - $data[8] .= html_print_image ('images/target.png', true, - array('title' => __('Reset module status and fired alert counts'))); - $data[8] .= '  '; - } else if ($server['type'] == 'enterprise snmp') { - $data[8] .= ''; - $data[8] .= html_print_image ('images/target.png', true, - array('title' => __('Claim back SNMP modules'))); - $data[8] .= '  '; - } - - $data[8] .= ''; - $data[8] .= html_print_image ('images/config.png', true, - array('title' => __('Edit'))); - $data[8] .= ''; - - $data[8] .= '  '; - $data[8] .= html_print_image ('images/cross.png', true, - array('title' => __('Delete'), - 'onclick' => "if (! confirm ('" . __('Modules run by this server will stop working. Do you want to continue?') ."')) return false")); - $data[8] .= ''; + //Only Pandora Administrator can delete servers + if (check_acl ($config["id_user"], 0, "PM")) { + $data[8] = ''; + if ($server['type'] == 'data') { + $data[8] .= ''; + $data[8] .= html_print_image ('images/target.png', true, + array('title' => __('Reset module status and fired alert counts'))); + $data[8] .= '  '; + } + else if ($server['type'] == 'enterprise snmp') { + $data[8] .= ''; + $data[8] .= html_print_image ('images/target.png', true, + array('title' => __('Claim back SNMP modules'))); + $data[8] .= '  '; + } + + $data[8] .= ''; + $data[8] .= html_print_image ('images/config.png', true, + array('title' => __('Edit'))); + $data[8] .= ''; + + $data[8] .= '  '; + $data[8] .= html_print_image ('images/cross.png', true, + array('title' => __('Delete'), + 'onclick' => "if (! confirm ('" . __('Modules run by this server will stop working. Do you want to continue?') ."')) return false")); + $data[8] .= ''; } - if($tiny) { + if ($tiny) { unset($data[4]); unset($data[6]); unset($data[7]); @@ -144,7 +146,7 @@ foreach ($servers as $server) { array_push ($table->data, $data); } -if($tiny) { +if ($tiny) { unset($table->head[4]); unset($table->head[6]); unset($table->head[7]); diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index d277e92823..a6e4197c9a 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -722,6 +722,41 @@ function api_get_tree_agents($trash1, $trahs2, $other, $returnType) returnData($returnType, $data, $separator); } +function api_set_update_agent($id_agent, $thrash2, $other, $thrash3) { + global $config; + //html_debug_print($other); + $name = $other['data'][0]; + $ip = $other['data'][1]; + $idParent = $other['data'][2]; + $idGroup = $other['data'][3]; + $cascadeProtection = $other['data'][4]; + $intervalSeconds = $other['data'][5]; + $idOS = $other['data'][6]; + $idServer = $other['data'][7]; + $customId = $other['data'][8]; + $learningMode = $other['data'][9]; + $disabled = $other['data'][10]; + $description = $other['data'][11]; + + $return = db_process_sql_update('tagente', + array('nombre' => $name, + 'direccion' => $ip, + 'id_grupo' => $idGroup, + 'intervalo' => $intervalSeconds, + 'comentarios' => $description, + 'modo' => $learningMode, + 'id_os' => $idOS, + 'disabled' => $disabled, + 'cascade_protection' => $cascadeProtection, + 'server_name' => $nameServer, + 'id_parent' => $idParent, + 'custom_id' => $customId), + array('id_agente' => $id_agent)); + + returnData('string', + array('type' => 'string', 'data' => (int)((bool)$return))); +} + /** * Create a new agent, and print the id for new agent. * @@ -754,11 +789,13 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) { switch ($config["dbtype"]) { case "mysql": - $sql1 = 'SELECT name FROM tserver WHERE id_server ='. $idServer; + $sql1 = 'SELECT name + FROM tserver WHERE id_server =' . $idServer; break; case "postgresql": case "oracle": - $sql1 = 'SELECT name FROM tserver WHERE id_server ='. $idServer; + $sql1 = 'SELECT name + FROM tserver WHERE id_server =' . $idServer; break; } @@ -768,13 +805,22 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) { returnError('agent_name_exist', 'The name of agent yet exist in DB.'); } else if (($idParent != 0) && - (db_get_value_sql('SELECT id_agente FROM tagente WHERE id_agente = ' . $idParent) === false)) { - returnError('parent_agent_not_exist', 'The agent parent don`t exist.'); + (db_get_value_sql('SELECT id_agente + FROM tagente + WHERE id_agente = ' . $idParent) === false)) { + + returnError('parent_agent_not_exist', 'The agent parent don`t exist.'); } - else if (db_get_value_sql('SELECT id_grupo FROM tgrupo WHERE id_grupo = ' . $idGroup) === false) { + else if (db_get_value_sql('SELECT id_grupo + FROM tgrupo + WHERE id_grupo = ' . $idGroup) === false) { + returnError('id_grupo_not_exist', 'The group don`t exist.'); } - else if (db_get_value_sql('SELECT id_os FROM tconfig_os WHERE id_os = ' . $idOS) === false) { + else if (db_get_value_sql('SELECT id_os + FROM tconfig_os + WHERE id_os = ' . $idOS) === false) { + returnError('id_os_not_exist', 'The OS don`t exist.'); } else if (db_get_value_sql($sql1) === false) { @@ -796,7 +842,7 @@ function api_set_new_agent($thrash1, $thrash2, $other, $thrash3) { 'custom_id' => $customId)); returnData('string', - array('type' => 'string', 'data' => $idAgente)); + array('type' => 'string', 'data' => $idAgente)); } } @@ -840,6 +886,7 @@ function api_set_create_custom_field($t1, $t2, $other, $returnType) { $data['type'] = "string"; $data["data"] = $result; + returnData("string", $data); } } @@ -851,10 +898,10 @@ function api_set_create_custom_field($t1, $t2, $other, $returnType) { * @param string $name Custom field name */ function api_get_custom_field_id($t1, $t2, $other, $returnType) { - + $name = $other["data"][0]; $id = db_get_value ('id_field', 'tagent_custom_fields', 'name', $name); - + $data['type'] = "string"; $data["data"] = $id; returnData("string", $data); @@ -893,7 +940,7 @@ function api_set_delete_agent($id, $thrash1, $thrast2, $thrash3) { function api_get_all_agents($thrash1, $thrash2, $other, $thrash3) { $where = ''; - + if (isset($other['data'][0])) { // Filter by SO if ($other['data'][0] != "") { @@ -926,7 +973,7 @@ function api_get_all_agents($thrash1, $thrash2, $other, $thrash3) { $separator = ';'; //by default else $separator = $other['data'][5]; - + // Initialization of array $result_agents = array(); // Filter by state diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 6ccc75e400..56ad126f6b 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -560,25 +560,25 @@ function db_sql_error_handler ($errno, $errstr) { */ function db_add_database_debug_trace ($sql, $result = false, $affected = false, $extra = false) { global $config; - + if (! isset ($config['debug'])) return false; - + if (! isset ($config['db_debug'])) $config['db_debug'] = array (); - + if (isset ($config['db_debug'][$sql])) { $config['db_debug'][$sql]['saved']++; return; } - + $var = array (); $var['sql'] = $sql; $var['result'] = $result; $var['affected'] = $affected; $var['saved'] = 0; $var['extra'] = $extra; - + $config['db_debug'][$sql] = $var; } @@ -590,7 +590,7 @@ function db_add_database_debug_trace ($sql, $result = false, $affected = false, */ function db_clean_cache() { global $sql_cache; - + $sql_cache = array ('saved' => 0); } @@ -615,7 +615,7 @@ function db_clean_cache() { */ function db_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $cache = true, &$status = null, $autocommit = true) { global $config; - + switch ($config["dbtype"]) { case "mysql": return @mysql_db_process_sql($sql, $rettype, $dbconnection, $cache); @@ -625,7 +625,7 @@ function db_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $c break; case "oracle": return @oracle_db_process_sql($sql, $rettype, $dbconnection, $cache, $status, $autocommit); - break; + break; } } @@ -640,7 +640,7 @@ function db_process_sql($sql, $rettype = "affected_rows", $dbconnection = '', $c */ function db_get_all_rows_in_table ($table, $order_field = "", $order = 'ASC') { global $config; - + switch ($config["dbtype"]) { case "mysql": return mysql_db_get_all_rows_in_table($table, $order_field, $order); @@ -666,7 +666,7 @@ function db_get_all_rows_in_table ($table, $order_field = "", $order = 'ASC') { */ function db_get_all_rows_field_filter($table, $field, $condition, $order_field = "") { global $config; - + switch ($config["dbtype"]) { case "mysql": return mysql_db_get_all_rows_field_filter($table, $field, $condition, $order_field); @@ -690,7 +690,7 @@ function db_get_all_rows_field_filter($table, $field, $condition, $order_field = */ function db_get_all_fields_in_table($table, $field = '', $condition = '', $order_field = '') { global $config; - + switch ($config["dbtype"]) { case "mysql": return mysql_db_get_all_fields_in_table($table, $field, $condition, $order_field); diff --git a/pandora_console/include/functions_servers.php b/pandora_console/include/functions_servers.php index 85f9899c89..0b77499639 100644 --- a/pandora_console/include/functions_servers.php +++ b/pandora_console/include/functions_servers.php @@ -300,7 +300,7 @@ function servers_get_rate($avg_interval, $num_modules) { */ function servers_get_info ($id_server = -1) { global $config; - + if (is_array ($id_server)) { $select_id = " WHERE id_server IN (".implode (",", $id_server).")"; } @@ -600,7 +600,11 @@ function servers_get_info ($id_server = -1) { } // Take data for realtime mode if (isset($server["module_lag"])) - $server["lag_txt"] = ($server["lag"] == 0 ? '-' : human_time_description_raw ($server["lag"])) . " / ". $server["module_lag"]; + $server["lag_txt"] = + ($server["lag"] == 0 ? + '-' + : + human_time_description_raw($server["lag"])) . " / " . $server["module_lag"]; else $server["lag_txt"] = ""; diff --git a/pandora_console/index.php b/pandora_console/index.php index 25d83bbaeb..1026f1566c 100644 --- a/pandora_console/index.php +++ b/pandora_console/index.php @@ -570,10 +570,9 @@ require('include/php_to_js_values.php'); ?>