2012-07-18 Miguel de Dios <miguel.dedios@artica.es>

* general/logon_ok.php, godmode/db/db_event.php,
	godmode/db/db_purge.php, include/functions_config.php,
	include/functions_ui.php, include/functions_netflow.php,
	include/functions.php, include/constants.php,
	include/functions_graph.php,
	operation/agentes/estado_ultimopaquete.php: clean source code style
	and kill some unicorns and magical numbers.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@6788 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2012-07-18 13:25:51 +00:00
parent 8c3d85b507
commit ed1c79730c
11 changed files with 789 additions and 754 deletions

View File

@ -1,3 +1,13 @@
2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* general/logon_ok.php, godmode/db/db_event.php,
godmode/db/db_purge.php, include/functions_config.php,
include/functions_ui.php, include/functions_netflow.php,
include/functions.php, include/constants.php,
include/functions_graph.php,
operation/agentes/estado_ultimopaquete.php: clean source code style
and kill some unicorns and magical numbers.
2012-07-18 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/pandora.js, include/functions_agents.php,

View File

@ -180,19 +180,19 @@ switch ($config["dbtype"]) {
case "mysql":
$sql = sprintf ("SELECT id_usuario,accion,fecha,ip_origen,descripcion
FROM tsesion
WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - 604800)
WHERE (`utimestamp` > UNIX_TIMESTAMP(NOW()) - " . SECONDS_1WEEK . ")
AND `id_usuario` = '%s' ORDER BY `utimestamp` DESC LIMIT 10", $config["id_user"]);
break;
case "postgresql":
$sql = sprintf ("SELECT \"id_usuario\", accion, fecha, \"ip_origen\", descripcion
FROM tsesion
WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - 604800)
WHERE (\"utimestamp\" > ceil(date_part('epoch', CURRENT_TIMESTAMP)) - " . SECONDS_1WEEK . ")
AND \"id_usuario\" = '%s' ORDER BY \"utimestamp\" DESC LIMIT 10", $config["id_user"]);
break;
case "oracle":
$sql = sprintf ("SELECT id_usuario, accion, fecha, ip_origen, descripcion
FROM tsesion
WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (86400)) - 604800)
WHERE ((utimestamp > ceil((sysdate - to_date('19700101000000','YYYYMMDDHH24MISS')) * (" . SECONDS_1DAY . ")) - " . SECONDS_1WEEK . ")
AND id_usuario = '%s') AND rownum <= 10 ORDER BY utimestamp DESC", $config["id_user"]);
break;
}

View File

@ -71,12 +71,12 @@ echo '<table width="98%" cellpadding="4" cellspacing="4" class="databox">
$time = get_system_time ();
$fields = array ();
$fields[$time - 7776000] = __('Purge event data over 90 days');
$fields[$time - 2592000] = __('Purge event data over 30 days');
$fields[$time - 1209600] = __('Purge event data over 14 days');
$fields[$time - 604800] = __('Purge event data over 7 days');
$fields[$time - 259200] = __('Purge event data over 3 days');
$fields[$time - 86400] = __('Purge event data over 1 day');
$fields[$time - SECONDS_3MONTHS] = __('Purge event data over 90 days');
$fields[$time - SECONDS_1MONTH] = __('Purge event data over 30 days');
$fields[$time - SECONDS_2WEEK] = __('Purge event data over 14 days');
$fields[$time - SECONDS_1WEEK] = __('Purge event data over 7 days');
$fields[$time - (SECONDS_1WEEK * 3)] = __('Purge event data over 3 days');
$fields[$time - SECONDS_1DAY] = __('Purge event data over 1 day');
$fields[$time] = __('Purge all event data');
html_print_select ($fields, "date_purge", '', '', '', '0', false, false, false, "w255");

View File

@ -43,24 +43,18 @@ echo '<h4>'.__('Get data from agent').'</h4>';
// All data (now)
$time["all"] = get_system_time ();
// 1 day ago
$time["1day"] = $time["all"]-86400;
$time["1day"] = $time["all"] - SECONDS_1DAY;
// 3 days ago
$time["3day"] = $time["all"] - 259200;
$time["3day"] = $time["all"] - SECONDS_1DAY * 3;
// 1 week ago
$time["1week"] = $time["all"] - 604800;
$time["1week"] = $time["all"] - SECONDS_1WEEK;
// 2 weeks ago
$time["2week"] = $time["all"] - 1209600;
$time["2week"] = $time["all"] - SECONDS_1WEEK * 2;
// 1 month ago
$time["1month"] = $time["all"] - 2592000;
$time["1month"] = $time["all"] - SECONDS_1MONTH;
// Three months ago
$time["3month"] = $time["all"] - 7776000;
$time["3month"] = $time["all"] - SECONDS_3MONTHS;
//Init data
$data["1day"] = 0;
@ -137,7 +131,8 @@ if (isset($_POST["purgedb"])) {
echo __('Total records deleted: ') . $affected;
}
} else {
}
else {
//All agents
echo __('Deleting records for all agents');
flush ();
@ -166,7 +161,8 @@ echo '</noscript><br />';
if ($id_agent > 0) {
$title = __('Information on agent %s in the database', agents_get_name ($id_agent));
} else {
}
else {
$title = __('Information on all agents in the database');
}
@ -182,13 +178,13 @@ else {
$query = "";
}
$data["1day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3day"], $query));
$data["1week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query));
$data["2week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["2week"], $query));
$data["1month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query));
$data["3month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query));
$data["total"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE 1=1 %s", $query));
$data["1day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3day"], $query));
$data["1week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query));
$data["2week"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["2week"], $query));
$data["1month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query));
$data["3month"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query));
$data["total"] = db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos WHERE 1=1 %s", $query));
$data["1day"] += db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_inc WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] += db_get_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_inc WHERE utimestamp > %d %s", $time["3day"], $query));

View File

@ -167,6 +167,12 @@ define('SERVICE_STATUS_UNKNOW', -1);
define('SERVICE_STATUS_NORMAL', 0);
define('SERVICE_STATUS_CRITICAL', 1);
define('SERVICE_STATUS_WARNING', 2);
//Default weights
define('SERVICE_WEIGHT_CRITICAL', 1);
define('SERVICE_WEIGHT_WARNING', 0.5);
define('SERVICE_ELEMENT_WEIGHT_CRITICAL', 1);
define('SERVICE_ELEMENT_WEIGHT_WARNING', 0.5);
define('SERVICE_ELEMENT_WEIGHT_OK', 0);

View File

@ -405,6 +405,10 @@ function set_user_language() {
*/
function human_time_description_raw ($seconds, $exactly = false, $units = 'large') {
//Miguel: I think that I can kill this unicorns and magical numbers
// because this function may call without loaded the
// constants.php file.
switch ($units) {
case 'large':
$secondsString = __('seconds');

View File

@ -295,7 +295,7 @@ function config_process_config () {
}
if (!isset ($config["sla_period"]) || empty ($config["sla_period"])) {
config_update_value ('sla_period', 604800);
config_update_value ('sla_period', SECONDS_1WEEK);
}
if (!isset ($config["prominent_time"])) {

File diff suppressed because it is too large Load Diff

View File

@ -35,6 +35,7 @@ function netflow_get_filters ($filter = false) {
else {
$filters = db_get_all_rows_filter ("tnetflow_filter", $filter);
}
$return = array ();
if ($filters === false) {
return $return;
@ -60,6 +61,7 @@ function netflow_get_reports ($filter = false) {
else {
$filters = db_get_all_rows_filter ("tnetflow_report", $filter);
}
$return = array ();
if ($filters === false) {
return $return;
@ -126,12 +128,12 @@ function netflow_check_report_group ($id_report, $mode=false) {
* @return array A netflow filter matching id and filter.
*/
function netflow_filter_get_filter ($id_sg, $filter = false, $fields = false) {
if (! is_array ($filter))
$filter = array ();
if (! is_array ($filter))
$filter = array ();
$filter['id_sg'] = (int) $id_sg;
$filter['id_sg'] = (int) $id_sg;
return db_get_row_filter ('tnetflow_filter', $filter, $fields);
return db_get_row_filter ('tnetflow_filter', $filter, $fields);
}
/**
@ -238,16 +240,16 @@ function netflow_data_table ($data, $start_date, $end_date, $aggregate) {
$end_date = date ($nfdump_date_format, $end_date);
// Set the format
if ($period <= 21600) {
if ($period <= SECONDS_6HOURS) {
$time_format = 'H:i:s';
}
elseif ($period < 86400) {
elseif ($period < SECONDS_1DAY) {
$time_format = 'H:i';
}
elseif ($period < 1296000) {
elseif ($period < SECONDS_15DAYS) {
$time_format = 'M d H:i';
}
elseif ($period < 2592000) {
elseif ($period < SECONDS_1MONTH) {
$time_format = 'M d H\h';
}
else {
@ -338,7 +340,8 @@ function netflow_get_data ($start_date, $end_date, $command, $unique_id, $aggreg
$val = explode(' ',$line);
$values['sources'][$val[4]] = 1;
}
} else {
}
else {
$values = array ();
}
@ -427,6 +430,7 @@ function netflow_get_stats ($start_date, $end_date, $command, $aggregate, $max,
}
sort_netflow_data ($values);
return $values;
}
@ -483,7 +487,8 @@ function netflow_get_filter_arguments ($filter) {
if (netflow_is_net ($val_ipdst[$i]) == 0) {
$filter_args .= 'dst ip '.$val_ipdst[$i];
} else {
}
else {
$filter_args .= 'dst net '.$val_ipdst[$i];
}
}
@ -492,7 +497,8 @@ function netflow_get_filter_arguments ($filter) {
if ($filter['ip_src'] != ''){
if ($filter_args == '') {
$filter_args .= ' "(';
} else {
}
else {
$filter_args .= ' and (';
}
$val_ipsrc = explode(',', $filter['ip_src']);
@ -503,7 +509,8 @@ function netflow_get_filter_arguments ($filter) {
if (netflow_is_net ($val_ipsrc[$i]) == 0) {
$filter_args .= 'src ip '.$val_ipsrc[$i];
} else {
}
else {
$filter_args .= 'src net '.$val_ipsrc[$i];
}
}
@ -512,7 +519,8 @@ function netflow_get_filter_arguments ($filter) {
if ($filter['dst_port'] != 0) {
if ($filter_args == '') {
$filter_args .= ' "(';
} else {
}
else {
$filter_args .= ' and (';
}
$val_dstport = explode(',', $filter['dst_port']);
@ -527,7 +535,8 @@ function netflow_get_filter_arguments ($filter) {
if ($filter['src_port'] != 0) {
if ($filter_args == '') {
$filter_args .= ' "(';
} else {
}
else {
$filter_args .= ' and (';
}
$val_srcport = explode(',', $filter['src_port']);
@ -586,7 +595,8 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
if ($aggregate != 'none') {
$interval_total = array ();
$interval_count = array ();
} else {
}
else {
$interval_total = 0;
$interval_count = 0;
}
@ -610,7 +620,7 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
$flow['date'] = $val[0];
$flow['time'] = $val[1];
switch ($aggregate){
switch ($aggregate) {
case "proto":
$flow['agg'] = $val[3];
break;
@ -657,12 +667,14 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
$interval_total[$flow['agg']] += $flow['data'];
$interval_count[$flow['agg']] += 1;
}
} else {
}
else {
$interval_total += $flow['data'];
$interval_count += 1;
}
}
} while ($read_flag == 1);
}
while ($read_flag == 1);
if ($aggregate != 'none') {
foreach ($interval_total as $agg => $val) {
@ -675,7 +687,8 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
// Read previous data for this interval
if (isset ($values['data'][$timestamp][$agg])) {
$previous_value = $values['data'][$timestamp][$agg];
} else {
}
else {
$previous_value = 0;
}
@ -687,7 +700,8 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
$values['data'][$timestamp][$agg] = (int) (($values['data'][$timestamp][$agg] + $previous_data) / 2);
}
}
} else {
}
else {
// No data for this interval
if ($interval_count == 0) {
@ -697,7 +711,8 @@ function netflow_parse_file ($start_date, $end_date, $file, &$values, $aggregate
// Read previous data for this interval
if (isset ($values[$timestamp]['data'])) {
$previous_value = $values[$timestamp]['data'];
} else {
}
else {
$previous_value = 0;
}
@ -892,5 +907,4 @@ function netflow_draw_item ($start_date, $end_date, $type, $filter, $command, $f
break;
}
}
?>

View File

@ -270,7 +270,8 @@ function ui_print_message ($message, $class = '', $attributes = '', $return = fa
if ($return)
return $output;
echo $output;
else
echo $output;
}
/**
@ -342,7 +343,9 @@ function ui_print_result_message ($result, $good = '', $bad = '', $attributes =
if (empty ($result)) {
return ui_print_error_message ($bad, $attributes, $return, $tag);
}
return ui_print_success_message ($good, $attributes, $return, $tag);
else {
return ui_print_success_message ($good, $attributes, $return, $tag);
}
}
/**
@ -823,7 +826,8 @@ function ui_print_string_substr ($string, $cutoff = 16, $return = false, $fontsi
$string2 = io_safe_output ($string);
if (mb_strlen($string2, "UTF-8") > $cutoff){
$string3 = "...";
} else {
}
else {
$string3 = "";
}
@ -1298,7 +1302,8 @@ function ui_process_page_head ($string, $bitfield) {
$output .= $string;
if (!empty ($config["compact_header"])) {
$output = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $output);
$output = str_replace(array("\r\n", "\r", "\n", "\t", ' ',
' ', ' '), '', $output);
}
return $output;
@ -1315,7 +1320,8 @@ function ui_process_page_head ($string, $bitfield) {
function ui_process_page_body ($string, $bitfield) {
global $config;
if (isset ($config['ignore_callback']) && $config['ignore_callback'] == true) {
if (isset ($config['ignore_callback']) &&
$config['ignore_callback'] == true) {
return;
}
@ -1326,7 +1332,8 @@ function ui_process_page_body ($string, $bitfield) {
require_once ($config["homedir"]."/include/htmlawed.php");
$htmLawedconfig = array ("valid_xhtml" => 1, "tidy" => -1);
$output .= htmLawed ($string, $htmLawedconfig);
} else {
}
else {
$output .= $string;
}
@ -1433,7 +1440,8 @@ function ui_pagination ($count, $url = false, $offset = 0, $pagination = 0, $ret
$output .= '<a class="pagination" href="'.$url.'&amp;'.$offset_name.'='.$inicio_bloque.'">';
if ($inicio_bloque == $offset) {
$output .= "<b>[ $i ]</b>";
} else {
}
else {
$output .= "[ $i ]";
}
$output .= '</a></span>';
@ -1527,7 +1535,8 @@ function ui_debug ($var, $backtrace = true) {
echo ' - <span class="filename">';
echo str_replace ($config['homedir'].'/', '', $trace['file']);
echo ':'.$trace['line'].'</span>';
} else {
}
else {
echo ' - <span class="filename"><em>Unknown file</em></span>';
}
echo '<pre id="args-'.$trace_id.'" class="invisible">';
@ -1550,6 +1559,7 @@ function ui_debug ($var, $backtrace = true) {
echo '<pre class="debug">';
print_r ($var);
echo '</pre>';
return true;
}
@ -1576,14 +1586,14 @@ function ui_print_moduletype_icon ($id_moduletype, $return = false, $relative =
if (! file_exists ($config['homedir'].'/'.$imagepath))
$imagepath = ENTERPRISE_DIR.'/'.$imagepath;
if ($options){
if ($options) {
return html_print_image ($imagepath, $return,
array ("border" => 0,
"title" => $type["descripcion"]), false, $relative);
}
else{
return html_print_image ($imagepath, $return,
false, false, $relative);
else {
return html_print_image ($imagepath, $return,
false, false, $relative);
}
}
@ -1672,7 +1682,7 @@ function ui_get_status_images_path () {
function ui_print_status_image ($type, $title = "", $return = false, $options = false) {
list ($imagepath) = ui_get_status_images_path ();
$imagepath .= "/".$type;
$imagepath .= "/" . $type;
if($options === false) {
$options = array();

View File

@ -479,11 +479,11 @@ foreach ($modules as $module) {
if ($module['history_data'] == 1) {
// RAW Table data
// RAW Table data
echo "<td class=".$tdcolor." width=70>";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=2592000&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_m.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=604800&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_w.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=86400&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_d.png', true, array("border" => '0', "alt" => '')) . "</a>";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=" . SECONDS_1MONTH . "&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_m.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=" . SECONDS_1WEEK . "&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_w.png', true, array("border" => '0', "alt" => '')) . "</a>&nbsp;&nbsp;";
echo "<a href='index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente=$id_agente&amp;tab=data_view&amp;period=" . SECONDS_1DAY ."&amp;id=".$module["id_agente_modulo"]."'>" . html_print_image('images/data_d.png', true, array("border" => '0', "alt" => '')) . "</a>";
}
else {
echo "<td class=".$tdcolor."></td>";
@ -494,7 +494,8 @@ foreach ($modules as $module) {
$seconds = get_system_time () - $module["utimestamp"];
if ($module['id_tipo_modulo'] < 21 && $module["module_interval"] > 0 && $module["utimestamp"] > 0 && $seconds >= ($module["module_interval"] * 2)) {
echo '<span class="redb">';
} else {
}
else {
echo '<span>';
}
}
@ -503,5 +504,4 @@ foreach ($modules as $module) {
echo "</td></tr>";
}
echo '</table>';
?>