2013-05-16 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_incidents.php, include/api.php,
	include/functions.php, include/functions_modules.php,
	include/graphs/flot/pandora.flot.js, include/functions_cron.php,
	include/functions_graph.php: improved the source code style.




git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8140 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2013-05-16 09:19:16 +00:00
parent 24ef862f58
commit 0853d84dcd
8 changed files with 115 additions and 67 deletions

View File

@ -1,3 +1,10 @@
2013-05-16 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_incidents.php, include/api.php,
include/functions.php, include/functions_modules.php,
include/graphs/flot/pandora.flot.js, include/functions_cron.php,
include/functions_graph.php: improved the source code style.
2013-05-16 Miguel de Dios <miguel.dedios@artica.es>
* operation/agentes/stat_win.php: disabled show events when the

View File

@ -49,7 +49,7 @@ $user_in_db = null;
$no_login_msg = "";
if (isInACL($ipOrigin)) {
if(empty($apiPassword) || (!empty($apiPassword) && $api_password === $apiPassword)) {
if (empty($apiPassword) || (!empty($apiPassword) && $api_password === $apiPassword)) {
$user_in_db = process_user_login($user, $password, true);
if ($user_in_db !== false) {
@ -78,7 +78,7 @@ if ($correctLogin) {
if ($op2 == 'extension') {
$extension_api_url = $config["homedir"]."/".EXTENSIONS_DIR."/$ext_name/$ext_name.api.php";
// The extension API file must exist and the extension must be enabled
if(file_exists($extension_api_url) && !in_array($ext_name,extensions_get_disabled_extensions())) {
if (file_exists($extension_api_url) && !in_array($ext_name,extensions_get_disabled_extensions())) {
include_once($extension_api_url);
$function_name = 'apiextension_'.$op.'_'.$ext_function;
}
@ -107,7 +107,7 @@ if ($correctLogin) {
else {
db_pandora_audit("API access Failed", $no_login_msg, $user, $ipOrigin);
sleep (15);
//Protection on DoS attacks
echo 'auth error';
}

View File

@ -203,8 +203,8 @@ function list_files ($directory, $stringSearch, $searchHandler, $return = false)
}
}
if ($searchHandler == 1) {
while(false !== ($fileName = @readdir ($directoryHandler))) {
if(@substr_count ($fileName, $stringSearch) > 0) {
while (false !== ($fileName = @readdir ($directoryHandler))) {
if (@substr_count ($fileName, $stringSearch) > 0) {
$result[$fileName] = $fileName;
}
}
@ -322,7 +322,7 @@ function human_time_comparation ($timestamp, $units = 'large') {
}
$seconds = get_system_time () - $timestamp;
// $seconds could be negative, because get_system_time() could return cached value
// (that might be the time a session begins at).
// So negative values are to be rounded off to 'NOW'.
@ -366,7 +366,7 @@ function get_user_language ($id_user = null) {
$quick_language = get_parameter('quick_language_change', 0);
if($quick_language) {
if ($quick_language) {
$language = get_parameter('language', 0);
if($language === 'default') {
@ -378,7 +378,7 @@ function get_user_language ($id_user = null) {
}
}
if($id_user === null && isset($config['id_user'])) {
if ($id_user === null && isset($config['id_user'])) {
$id_user = $config['id_user'];
}
@ -457,7 +457,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
$years = floor($seconds / 31104000);
if($years != 0) {
if ($years != 0) {
$seconds = $seconds - ($years * 31104000);
$returnDate .= "$years $yearsString ";
@ -465,7 +465,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
$months = floor($seconds / 2592000);
if($months != 0) {
if ($months != 0) {
$seconds = $seconds - ($months * 2592000);
$returnDate .= "$months $monthsString ";
@ -473,7 +473,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
$days = floor($seconds / 86400);
if($days != 0) {
if ($days != 0) {
$seconds = $seconds - ($days * 86400);
$returnDate .= "$days $daysString ";
@ -483,7 +483,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
$hours = floor($seconds / 3600);
if($hours != 0) {
if ($hours != 0) {
$seconds = $seconds - ($hours * 3600);
$returnTime .= "$hours $hoursString ";
@ -491,7 +491,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
$mins = floor($seconds / 60);
if($mins != 0) {
if ($mins != 0) {
$seconds = $seconds - ($mins * 60);
if($hours == 0) {
@ -502,7 +502,7 @@ function human_time_description_raw ($seconds, $exactly = false, $units = 'large
}
}
if($seconds != 0) {
if ($seconds != 0) {
if($hours == 0) {
$returnTime .= "$seconds $secondsString ";
}

View File

@ -32,19 +32,19 @@ function cron_update_module_interval ($module_id, $cron) {
// Get the number of seconds left to the next execution of the given cron entry.
function cron_next_execution ($cron) {
// Get day of the week and month from cron config
list ($minute, $hour, $mday, $month, $wday) = explode (" ", $cron);
// Get current time
$cur_time = time();
// Any day of the way
if ($wday == '*') {
$nex_time = cron_next_execution_date ($cron, $cur_time);
return $nex_time - $cur_time;
}
// A specific day of the week
$count = 0;
$nex_time = $cur_time;
@ -52,6 +52,7 @@ function cron_next_execution ($cron) {
$nex_time = cron_next_execution_date ($cron, $nex_time);
$nex_time_wd = $nex_time;
list ($nex_mon, $nex_wday) = explode (" ", date ("m w", $nex_time_wd));
do {
// Check the day of the week
if ($nex_wday == $wday) {
@ -61,25 +62,28 @@ function cron_next_execution ($cron) {
// Move to the next day of the month
$nex_time_wd += 86400;
list ($nex_mon_wd, $nex_wday) = explode (" ", date ("m w", $nex_time_wd));
} while ($mday == '*' && $nex_mon_wd == $nex_mon);
}
while ($mday == '*' && $nex_mon_wd == $nex_mon);
$count++;
} while ($count < 60);
}
while ($count < 60);
// Something went wrong, default to 5 minutes
return 300;
}
// Get the next execution date for the given cron entry in seconds since epoch.
function cron_next_execution_date ($cron, $cur_time = false) {
// Get cron configuration
list ($min, $hour, $mday, $mon, $wday) = explode (" ", $cron);
// Months start from 0
if($mon != '*') {
if ($mon != '*') {
$mon -= 1;
}
// Get current time
if ($cur_time === false) {
$cur_time = time();
@ -92,7 +96,7 @@ function cron_next_execution_date ($cron, $cur_time = false) {
$nex_mday = $mday;
$nex_mon = $mon;
$nex_year = $cur_year;
// Replace wildcards
if ($min == '*') {
if ($hour != '*' || $mday != '*' || $wday != '*' || $mon != '*') {
@ -121,7 +125,7 @@ function cron_next_execution_date ($cron, $cur_time = false) {
if ($mon == '*') {
$nex_mon = $cur_mon;
}
// Find the next execution date
$count = 0;
do {
@ -130,7 +134,7 @@ function cron_next_execution_date ($cron, $cur_time = false) {
return $next_time;
}
if ($min == '*' && $hour == '*' && $wday == '*' && $mday == '*' && $mon == '*') {
list ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = explode (" ", date ("i H d m Y", $next_time + 60));
list ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = explode (" ", date ("i H d m Y", $next_time + 60));
}
else if ($hour == '*' && $wday == '*' && $mday == '*' && $mon == '*') {
list ($nex_min, $nex_hour, $nex_mday, $nex_mon, $nex_year) = explode (" ", date ("i H d m Y", $next_time + 3600));
@ -149,7 +153,8 @@ function cron_next_execution_date ($cron, $cur_time = false) {
$nex_year++;
}
$count++;
} while ($count < 86400);
}
while ($count < 86400);
// Something went wrong, default to 5 minutes
return $cur_time + 300;

View File

@ -1332,7 +1332,7 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0, $return =
$config['fontpath'], $config['font_size'], "", 1, array(), array(), 0, 0, '', false, '', false);
}
if($return) {
if ($return) {
return $out;
}
else {
@ -2747,10 +2747,10 @@ function grafico_modulo_boolean_data ($agent_module_id, $period, $show_events,
$chart[$timestamp]['min'.$series_suffix] = 0;
}*/
if(!empty($event_ids)) {
if (!empty($event_ids)) {
$chart_extra_data[count($chart)-1]['events'] = implode(',',$event_ids);
}
if(!empty($alert_ids)) {
if (!empty($alert_ids)) {
$chart_extra_data[count($chart)-1]['alerts'] = implode(',',$alert_ids);
}

View File

@ -73,9 +73,10 @@ function incidents_print_priority_img ($id_priority, $return = false) {
if ($return === false) {
echo $img;
}
return $img;
}
/**
* Gets all the possible status for incidents in an array
@ -122,6 +123,7 @@ function incidents_print_status_img ($id_status, $return = false) {
if ($return === false) {
echo $img;
}
return $img;
}
@ -160,16 +162,17 @@ function incidents_process_chown ($id_incident, $owner = false) {
global $config;
$owner = $config["id_user"];
}
$id_incident = (array) safe_int ($id_incident, 1); //Make sure we have all positive int's
if (empty ($id_incident)) {
return false;
}
$id_incident = implode (",", $id_incident);
$sql = sprintf ("UPDATE tincidencia SET id_usuario = '%s' WHERE id_incidencia IN (%s)", $owner, $id_incident);
return db_process_sql ($sql);
}
/**
* Get the author of an incident.
@ -182,6 +185,7 @@ function incidents_get_author ($id_incident) {
if ($id_incident < 1) {
return "";
}
return (string) db_get_value ('id_creator', 'tincidencia', 'id_incidencia', (int) $id_incident);
}
@ -196,6 +200,7 @@ function incidents_get_owner ($id_incident) {
if ($id_incident < 1) {
return "";
}
return (string) db_get_value ('id_usuario', 'tincidencia', 'id_incidencia', (int) $id_incident);
}
@ -210,9 +215,10 @@ function incidents_get_lastupdate ($id_incident) {
if ($id_incident < 1) {
return "";
}
return (string) db_get_value ('id_lastupdate', 'tincidencia', 'id_incidencia', (int) $id_incident);
}
/**
* Get the group id of an incident.
@ -225,6 +231,7 @@ function incidents_get_group ($id_incident) {
if ($id_incident < 1) {
return 0;
}
return (int) db_get_value ('id_grupo', 'tincidencia', 'id_incidencia', (int) $id_incident);
}
@ -376,7 +383,7 @@ function incidents_get_attach ($id_incident) {
return $attach;
}
/**
* Get user id of a note.
*
@ -397,7 +404,7 @@ function incidents_get_notes_author ($id_note) {
* @return variant The function result called in the API.
*/
function incidents_call_api($url, $postparameters = false) {
$curlObj = curl_init();
curl_setopt($curlObj, CURLOPT_URL, $url);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
@ -406,7 +413,7 @@ function incidents_call_api($url, $postparameters = false) {
}
$result = curl_exec($curlObj);
curl_close($curlObj);
return $result;
}
@ -419,6 +426,7 @@ function incidents_call_api($url, $postparameters = false) {
*/
function incidents_xml_to_array($xml) {
$xmlObj = simplexml_load_string($xml,'SimpleXMLElement',LIBXML_NOCDATA);
return json_decode(json_encode($xmlObj), true);
}

View File

@ -155,25 +155,25 @@ function modules_change_disabled($id_agent_module, $new_value = 1) {
$id_agent_module_changed = array();
foreach($id_agent_module as $id_module) {
foreach ($id_agent_module as $id_module) {
// If the module is already disabled/enabled ignore
$current_disabled = db_get_value('disabled', 'tagente_modulo', 'id_agente_modulo', $id_module);
if($current_disabled == $new_value) {
if ($current_disabled == $new_value) {
continue;
}
$id_agent_changed[] = modules_get_agentmodule_agent($id_module);
$id_agent_module_changed[] = $id_module;
}
if(empty($id_agent_module_changed)) {
if (empty($id_agent_module_changed)) {
$result = false;
}
else {
$result = db_process_sql_update('tagente_modulo', array('disabled' => (int) $new_value), array('id_agente_modulo' => $id_agent_module_changed));
}
if($result) {
if ($result) {
// Change the agent flag to update modules count
db_process_sql_update('tagente', array('update_module_count' => 1), array('id_agente' => $id_agent_changed));
return NOERR;
@ -264,7 +264,7 @@ function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false
}
if (isset ($values['nombre'])) {
if(empty ($values['nombre'])) {
if (empty ($values['nombre'])) {
return ERR_INCOMPLETE;
}
@ -272,7 +272,7 @@ function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false
$exists = (bool)db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('nombre' => $values['nombre'], 'id_agente' => $id_agent, 'id_agente_modulo' => "<>$id"));
if($exists) {
if ($exists) {
return ERR_EXIST;
}
}
@ -343,7 +343,7 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
$exists = (bool)db_get_value_filter('id_agente_modulo', 'tagente_modulo', array('nombre' => $name, 'id_agente' => (int)$id_agent));
if($exists) {
if ($exists) {
return ERR_EXIST;
}
@ -421,7 +421,7 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
}
// Update module status count if the module is not created disabled
if(!isset ($values['disabled']) || $values['disabled'] == 0) {
if (!isset ($values['disabled']) || $values['disabled'] == 0) {
if ($status == 0) {
db_process_sql ('UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente=' . (int)$id_agent);
}
@ -1374,7 +1374,7 @@ function modules_get_modulegroups () {
* @return string The modulegroup name
*/
function modules_get_modulegroup_name ($modulegroup_id) {
if($modulegroup_id == 0)
if ($modulegroup_id == 0)
return false;
else
return (string) db_get_value ('name', 'tmodule_group', 'id_mg', (int) $modulegroup_id);
@ -1449,14 +1449,21 @@ function modules_get_status($id_agent_module, $db_status, $data, &$status, &$tit
function modules_agents_unknown ($module_name) {
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT( DISTINCT tagente.id_agente) FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_estado.estado = 3 AND tagente_modulo.nombre = '$module_name'");
return db_get_sql ("SELECT COUNT( DISTINCT tagente.id_agente)
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.disabled = 0
AND tagente_estado.utimestamp != 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.disabled = 0
AND tagente_estado.id_agente = tagente.id_agente
AND tagente_estado.estado = 3
AND tagente_modulo.nombre = '$module_name'");
}
// Get ok agents by using the status code in modules.
function modules_agents_ok ($module_name) {
//!!!Query explanation!!!
//An agent is OK if all its modules are OK
//The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown
@ -1465,14 +1472,23 @@ function modules_agents_ok ($module_name) {
//Then we count the agents of the group selected to know how many agents are in OK status
//TODO REVIEW ORACLE AND POSTGRES
return db_get_sql ("SELECT COUNT(max_estado) FROM (SELECT MAX(tagente_estado.estado) as max_estado FROM tagente_estado, tagente, tagente_modulo WHERE tagente.disabled = 0 AND tagente_estado.utimestamp != 0 AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo AND tagente_modulo.disabled = 0 AND tagente_estado.id_agente = tagente.id_agente AND tagente_modulo.nombre = '$module_name' GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1");
return db_get_sql ("SELECT COUNT(max_estado)
FROM (
SELECT MAX(tagente_estado.estado) as max_estado
FROM tagente_estado, tagente, tagente_modulo
WHERE tagente.disabled = 0
AND tagente_estado.utimestamp != 0
AND tagente_modulo.id_agente_modulo = tagente_estado.id_agente_modulo
AND tagente_modulo.disabled = 0
AND tagente_estado.id_agente = tagente.id_agente
AND tagente_modulo.nombre = '$module_name'
GROUP BY tagente.id_agente HAVING max_estado = 0) AS S1");
}
// Get critical agents by using the status code in modules.
function modules_agents_critical ($module_name) {
//!!!Query explanation!!!
//An agent is Warning when has at least one module in warning status and nothing more in critical status
//The status values are: 0 OK; 1 Critical; 2 Warning; 3 Unkown
@ -1489,7 +1505,6 @@ function modules_agents_critical ($module_name) {
AND estado = 1
AND tagente_estado.id_agente = tagente.id_agente
AND tagente_modulo.nombre = '$module_name'");
}
// Get warning agents by using the status code in modules.
@ -1515,35 +1530,48 @@ function modules_agents_warning ($module_name) {
AND tagente_modulo.nombre = '$module_name'
GROUP BY tagente.id_agente
HAVING min_estado = 2) AS S1");
}
// Get unknown agents by using the status code in modules
function modules_group_agent_unknown ($module_group) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND critical_count=0 AND warning_count=0 AND unknown_count>0 AND id_module_group = $module_group");
return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo
WHERE tagente.id_agente=tagente_modulo.id_agente
AND critical_count=0 AND warning_count=0
AND unknown_count>0 AND id_module_group = $module_group");
}
// Get ok agents by using the status code in modules.
function modules_group_agent_ok ($module_group) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND normal_count=total_count AND id_module_group = $module_group");
return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo
WHERE tagente.id_agente=tagente_modulo.id_agente
AND normal_count = total_count
AND id_module_group = $module_group");
}
// Get critical agents by using the status code in modules.
function modules_group_agent_critical ($module_group) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND critical_count>0 AND id_module_group = $module_group");
return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo
WHERE tagente.id_agente=tagente_modulo.id_agente
AND critical_count > 0 AND id_module_group = $module_group");
}
// Get warning agents by using the status code in modules.
function modules_group_agent_warning ($module_group) {
return db_get_sql ("SELECT COUNT(*) FROM tagente, tagente_modulo WHERE tagente.id_agente=tagente_modulo.id_agente AND critical_count=0 AND warning_count>0 AND id_module_group = $module_group");
return db_get_sql ("SELECT COUNT(*)
FROM tagente, tagente_modulo
WHERE tagente.id_agente=tagente_modulo.id_agente
AND critical_count = 0 AND warning_count > 0
AND id_module_group = $module_group");
}
?>
?>

View File

@ -43,7 +43,7 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat
}
var show_legend = true;
if(legend_position == 'hidden') {
if (legend_position == 'hidden') {
show_legend = false;
}