From f795e611ac3184a5b41e0f592deb662bd3335d16 Mon Sep 17 00:00:00 2001 From: guruevi Date: Wed, 29 Oct 2008 20:03:42 +0000 Subject: [PATCH] git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1201 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 + pandora_console/include/functions.php | 8 +- .../operation/agentes/status_monitor.php | 339 ++++++++---------- 3 files changed, 172 insertions(+), 183 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index fe08ef4d83..4f17a25065 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2008-10-29 Evi Vanoost + + * operation/agentes/status_monitor.php: Made it a bit faster and fixed + some issues I had with it (flag). Uses new html functions now. + + * include/functions.php: Made human_time_comparation accept both + Unixtime as well as other system timestamps + 2008-10-28 Esteban Sanchez * godmode/modules/manage_network_components.php: Replaced parameters diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index 6a710b6327..7b62dd522b 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -475,8 +475,11 @@ function human_time_comparation ($timestamp) { return "0 ".__('minutes'); } - $ahora = date ("Y/m/d H:i:s"); - $seconds = strtotime ($ahora) - strtotime ($timestamp); + if (!is_numeric ($timestamp)) { + $timestamp = strtotime ($timestamp); + } + + $seconds = time () - $timestamp; if ($seconds < 60) return format_numeric ($seconds, 0)." ".__('seconds'); @@ -497,6 +500,7 @@ function human_time_comparation ($timestamp) { if ($seconds < 15552000) return format_numeric ($seconds / 2592000, 0)." ".__('months'); + return " +6 ".__('months'); } diff --git a/pandora_console/operation/agentes/status_monitor.php b/pandora_console/operation/agentes/status_monitor.php index 71533519cd..55e0a256a9 100644 --- a/pandora_console/operation/agentes/status_monitor.php +++ b/pandora_console/operation/agentes/status_monitor.php @@ -19,7 +19,7 @@ // Load global vars -require ("include/config.php"); +require_once ("include/config.php"); check_login(); @@ -30,8 +30,7 @@ if (! give_acl ($config['id_user'], 0, "AR") && ! give_acl ($config['id_user'], exit; } -echo "

".__('Pandora Agents')." > "; -echo __('Full list of Monitors')."

"; +echo "

".__('Pandora Agents')." > ".__('Full list of Monitors')."

"; $ag_freestring = get_parameter ("ag_freestring", ""); $ag_modulename = get_parameter ("ag_modulename", ""); @@ -39,218 +38,196 @@ $ag_group = get_parameter ("ag_group", -1); $offset = get_parameter ("offset", 0); $status = get_parameter ("status", 0); -$URL = "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60"; -echo "
0) { + $url .= "&ag_group=".$ag_group; +} +if ($ag_modulename != "") { + $url .= "&ag_modulename=".$ag_modulename; +} +if ($ag_freestring != "") { + $url .= "&ag_freestring=".$ag_freestring; +} +if ($status != 0) { + $url .= "&status=".$status; +} -// Module name selector -// This code thanks for an idea from Nikum, nikun_h@hotmail.com -if ($ag_modulename != "") - $URL .= "&ag_modulename=".$ag_modulename; +echo ''; -// Freestring selector -if ($ag_freestring != "") - $URL .= "&ag_freestring=".$ag_freestring ; +echo ''; +echo ''; +echo '
'.__('Group').''; -// Status selector -$URL .= "&status=$status"; +print_select (get_user_groups (), "ag_group", $ag_group, 'this.form.submit();', '', '0', false, false, false, 'w130'); -echo $URL; - -// End FORM TAG -echo "'>"; - -echo ""; -echo ""; -echo ""; +echo ""; -echo ""; -echo ""; -echo "'; +echo ''; + +echo '
".__('Group').""; -echo ""; echo "".__('Monitor status').""; -echo ""; -echo __('Monitor status'); -echo ""; -echo ""; +$fields = array (); +$fields[0] = __('Monitors down'); //default +$fields[1] = __('Monitors up'); +$fields[2] = __('Monitors unknown'); -echo "
".__('Module name')." -
'.__('Module name').''; + +$result = get_db_all_rows_sql ("SELECT DISTINCT(nombre) FROM tagente_modulo WHERE id_tipo_modulo IN (2, 6, 9, 18, 21, 100) ORDER BY nombre"); +if ($result === false) { + $result = array (); } -echo ""; -echo ""; -echo __('Free text'); -echo ""; -echo ""; -echo ""; -echo "'.__('Free text').''; +print_input_text ("ag_freestring", $ag_freestring, '', 15); +echo ''; +print_submit_button (__('Show'), "uptbutton", false, 'class="sub"'); + echo ""; echo "
"; // Begin Build SQL sentences - -$SQL_pre = "SELECT tagente_modulo.id_agente_modulo, tagente.nombre, tagente_modulo.nombre, tagente_modulo.descripcion, tagente.id_grupo, tagente.id_agente, tagente_modulo.id_tipo_modulo, tagente_modulo.module_interval, tagente_estado.datos, tagente_estado.utimestamp, tagente_estado.timestamp "; - -$SQL_pre_count = "SELECT count(tagente_modulo.id_agente_modulo) "; - -$SQL = " FROM tagente, tagente_modulo, tagente_estado WHERE tagente.id_agente = tagente_modulo.id_agente AND tagente_modulo.disabled = 0 AND tagente.disabled = 0 AND tagente_modulo.id_tipo_modulo in (2, 9, 12, 18, 6, 100) AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo "; +$sql = " FROM tagente, tagente_modulo, tagente_estado + WHERE tagente.id_agente = tagente_modulo.id_agente + AND tagente_modulo.disabled = 0 + AND tagente.disabled = 0 + AND tagente_modulo.id_tipo_modulo IN (2, 9, 12, 18, 6, 100) + AND tagente_estado.id_agente_modulo = tagente_modulo.id_agente_modulo"; // Agent group selector -if ($ag_group > 1) - $SQL .=" AND tagente.id_grupo = ".$ag_group; -else { +if ($ag_group > 1 && give_acl ($config["id_user"], $ag_group, "AR")) { + $sql .= sprintf (" AND tagente.id_grupo = %d", $ag_group); +} else { // User has explicit permission on group 1 ? - $sql = sprintf ("SELECT COUNT(id_grupo) FROM tusuario_perfil WHERE id_usuario='%s' AND id_grupo = 1", $config['id_user']); - $all_group = get_db_sql ($sql); - if ($all_group == 0) - $SQL .= sprintf (" AND tagente.id_grupo IN (SELECT id_grupo FROM tusuario_perfil WHERE id_usuario='%s') ", $config['id_user']); + $sql .= " AND tagente.id_grupo IN (".implode (",", array_keys (get_user_groups ())).")"; } // Module name selector -// This code thanks for an idea from Nikum, nikun_h@hotmail.com -if ($ag_modulename != "") - $SQL .= " AND tagente_modulo.nombre = '$ag_modulename'"; +if ($ag_modulename != "") { + $sql .= sprintf (" AND tagente_modulo.nombre = '%s'", $ag_modulename); +} // Freestring selector -if ($ag_freestring != "") - $SQL .= " AND ( tagente.nombre LIKE '%".$ag_freestring."%' OR tagente_modulo.nombre LIKE '%".$ag_freestring."%' OR tagente_modulo.descripcion LIKE '%".$ag_freestring."%') "; +if ($ag_freestring != "") { + $sql .= sprintf (" AND (tagente.nombre LIKE '%%%s%%' OR tagente_modulo.nombre LIKE '%%%s%%' OR tagente_modulo.descripcion LIKE '%%%s%%')", $ag_freestring, $ag_freestring, $ag_freestring); +} // Status selector -if ($status == 1) - $SQL .= " AND tagente_estado.estado = 0 "; -elseif ($status == 0) - $SQL .= " AND tagente_estado.estado = 1 "; -elseif ($status == 2) - $SQL .= " AND (UNIX_TIMESTAMP()-tagente_estado.utimestamp ) > (tagente_estado.current_interval * 2)"; +if ($status == 1) { //Up + $sql .= " AND tagente_estado.estado = 0 AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) < (tagente_estado.current_interval * 2)"; +} elseif ($status == 0) { //Down + $sql .= " AND tagente_estado.estado = 1"; +} elseif ($status == 2) { //Unknown + $sql .= " AND (UNIX_TIMESTAMP(NOW()) - tagente_estado.utimestamp) >= (tagente_estado.current_interval * 2)"; +} -// Final order -$SQL .= " ORDER BY tagente.id_grupo, tagente.nombre"; +$sql .= " ORDER BY tagente.id_grupo, tagente.nombre"; // Build final SQL sentences -$SQL_FINAL = $SQL_pre . $SQL; -$SQL_COUNT = $SQL_pre_count . $SQL; +$count = get_db_sql ("SELECT COUNT(tagente_modulo.id_agente_modulo)".$sql); +$sql = "SELECT tagente_modulo.id_agente_modulo, + tagente.intervalo AS agent_interval, + tagente.nombre AS agent_name, + tagente_modulo.nombre AS module_name, + tagente_modulo.flag AS flag, + tagente.id_grupo AS id_group, + tagente.id_agente AS id_agent, + tagente_modulo.id_tipo_modulo AS module_type, + tagente_modulo.module_interval, + tagente_estado.datos, + tagente_estado.utimestamp AS utimestamp".$sql." LIMIT ".$offset.",".$config["block_size"]; +$result = get_db_all_rows_sql ($sql); -$counter = get_db_sql ($SQL_COUNT); -if ( $counter > $config["block_size"]) { - pagination ($counter, $URL, $offset); - $SQL_FINAL .= " LIMIT $offset , ".$config["block_size"]; +if ($count > $config["block_size"]) { + pagination ($count, "index.php?sec=estado&sec2=operation/agentes/status_monitor&refr=60".$url, $offset); } +if ($result === false) { + $result = array (); +} -if ($counter > 0) { - echo " - - - - - - - - "; - $color =1; - $result=mysql_query($SQL_FINAL); +$table->cellpadding = 4; +$table->cellspacing = 4; +$table->width = 750; +$table->class = "databox"; - while ($data=mysql_fetch_array($result)){ //while there are agents - if ($color == 1){ - $tdcolor="datos"; - $color =0; - } else { - $tdcolor="datos2"; - $color =1; - } - if ($data[7] == 0){ - $my_interval = give_agentinterval($data[5]); - } else { - $my_interval = $data[7]; - } - - if ($status == 2) { - $seconds = time() - $data[9]; - - if ($seconds < ($my_interval*2)) - continue; - } +$table->head = array (); +$table->data = array (); +$table->size = array (); +$table->align = array (); - echo ""; - echo ""; - echo ""; - echo ""; +$table->head[3] = __('Module Name'); + +$table->head[4] = __('Interval'); +$table->align[4] = "center"; + +$table->head[5] = __('Status'); +$table->align[5] = "center"; + +$table->head[6] = __('Timestamp'); +$table->algin[6] = "center"; + +foreach ($result as $row) { + $data = array (); + //This should be processed locally. Don't rely on other URL's to do our dirty work. Maybe a process_agentmodule_flag function + $data[0] = ''; + if ($row["flag"] == 0) { + $data[0] .= ''; + } else { + $data[0] .= ''; + } + $data[0] .= ''; + + $data[1] = ''; + $data[1] .= strtoupper (substr ($row["agent_name"], 0, 25)); + $data[1] .= ''; + + $data[2] = ''; + + $data[3] = substr ($row["module_name"], 0, 30); + + $data[4] = $row["agent_interval"]; + + if ($row["datos"] > 0) { + $data[5] = ''; + } else { + $data[5] = ''; } - echo "
- ".__('Agent')."".__('Type')."".__('Name')."".__('Description')."".__('Interval')."".__('Status')."".__('Timestamp')."
"; - echo ""; - echo ""; - echo ""; - echo "".strtoupper(substr($data[1],0,21)).""; - echo ""; - echo "". substr($data[2],0,21). "".substr($data[3],0,30).""; - echo $my_interval; +$table->head[0] = ""; +$table->align[0] = "center"; - echo ""; - if ($data[8] > 0){ - echo ""; - } else { - echo ""; - } +$table->head[1] = __('Agent'); - echo ""; - $seconds = time() - $data[9]; - if ($seconds >= ($my_interval*2)) - echo ""; - else - echo ""; +$table->head[2] = __('Type'); +$table->align[2] = "center"; - echo human_time_comparation ($data[10]); - echo "
"; - echo ""; - echo ""; - echo ""; - echo ""; - echo "
"; - echo "  ".__('Monitor up')."  ".__('Monitor down')."
"; -} else { - echo "
".__('This group doesn\'t have any monitor')."
"; -} + $seconds = time () - $row["utimestamp"]; + + if ($seconds >= ($row["agent_interval"] * 2)) { + $data[6] = ''; + } else { + $data[6] = ''; + } + + $data[6] .= human_time_comparation ($row["utimestamp"]); + $data[6] .= ""; + + array_push ($table->data, $data); +} +if (!empty ($table->data)) { + print_table ($table); + echo '
  '.__('Monitor up').'        '.__('Monitor down').'
'; +} else { + echo '
'.__('This group doesn\'t have any monitor').'
'; +} ?>