2013-08-20 Miguel de Dios <miguel.dedios@artica.es>

* 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
This commit is contained in:
mdtrooper 2013-08-21 12:37:37 +00:00
parent 00c554f0b4
commit 04afb4615d
6 changed files with 115 additions and 55 deletions

View File

@ -1,3 +1,11 @@
2013-08-20 Miguel de Dios <miguel.dedios@artica.es>
* 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 <miguel.dedios@artica.es>
* include/functions_api.php: added calls to set gis data for agent

View File

@ -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 "<div class='nf'>".__('There are no servers configured into the database')."</div>";
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] = '<span style="white-space:nowrap;">'.$server["lag_txt"].'</span>';
$data[5] = '<span style="white-space:nowrap;">' .
$server["lag_txt"] . '</span>';
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] .= '<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=0&server_reset_counts='.$server["id_server"].'">';
$data[8] .= html_print_image ('images/target.png', true,
array('title' => __('Reset module status and fired alert counts')));
$data[8] .= '</a>&nbsp;&nbsp;';
} else if ($server['type'] == 'enterprise snmp') {
$data[8] .= '<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=0&server_reset_snmp_enterprise='.$server["id_server"].'">';
$data[8] .= html_print_image ('images/target.png', true,
array('title' => __('Claim back SNMP modules')));
$data[8] .= '</a>&nbsp;&nbsp;';
}
$data[8] .= '<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&server='.$server["id_server"].'">';
$data[8] .= html_print_image ('images/config.png', true,
array('title' => __('Edit')));
$data[8] .= '</a>';
$data[8] .= '&nbsp;&nbsp;<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_del='.$server["id_server"].'&amp;delete=1">';
$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] .= '</a>';
//Only Pandora Administrator can delete servers
if (check_acl ($config["id_user"], 0, "PM")) {
$data[8] = '';
if ($server['type'] == 'data') {
$data[8] .= '<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=0&server_reset_counts='.$server["id_server"].'">';
$data[8] .= html_print_image ('images/target.png', true,
array('title' => __('Reset module status and fired alert counts')));
$data[8] .= '</a>&nbsp;&nbsp;';
}
else if ($server['type'] == 'enterprise snmp') {
$data[8] .= '<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&refr=0&server_reset_snmp_enterprise='.$server["id_server"].'">';
$data[8] .= html_print_image ('images/target.png', true,
array('title' => __('Claim back SNMP modules')));
$data[8] .= '</a>&nbsp;&nbsp;';
}
$data[8] .= '<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&server='.$server["id_server"].'">';
$data[8] .= html_print_image ('images/config.png', true,
array('title' => __('Edit')));
$data[8] .= '</a>';
$data[8] .= '&nbsp;&nbsp;<a href="index.php?sec=gservers&sec2=godmode/servers/modificar_server&server_del='.$server["id_server"].'&amp;delete=1">';
$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] .= '</a>';
}
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]);

View File

@ -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

View File

@ -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);

View File

@ -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"] = "";

View File

@ -570,10 +570,9 @@ require('include/php_to_js_values.php');
?>
<script type="text/javascript" language="javascript">
//Initial load of page
$(document).ready(adjustFooter);
//Every resize of window
$(window).resize(adjustFooter);