$datelimit"; $resq1=mysql_query($query1); $last_data = ""; $total_badtime = 0; $interval_begin = 0; $interval_last = 0; if ($resq1 != 0){ while ($row=mysql_fetch_array($resq1)){ if ( ($row["datos"] > $max_value) OR ($row["datos"] < $min_value)){ if ($interval_begin == 0){ $interval_begin = $row["utimestamp"]; } } elseif ($interval_begin != 0){ // Here ends interval with data outside valid values, // Need to add this time to counter $interval_last = $row["utimestamp"]; $temp_time = $interval_last - $interval_begin; $total_badtime = $total_badtime + $temp_time; $interval_begin = 0; $interval_last = 0; } } } else return 100; $result = 100 - ($total_badtime / $period ) * 100; return $result; } function general_stats ( $id_user, $id_group = 0) { if ($id_group <= 0) // Get group list that user has access $mis_grupos = list_group2 ($id_user); else $mis_grupos[0] = $id_group; $contador_grupo = 0; $contador_agente = 0; $array_index = 0; $monitor_checks = 0; $monitor_ok = 0; $monitor_bad = 0; $monitor_unknown =0; $monitor_alert = 0; $monitor_not_init=0; $total_agents = 0; $data_checks = 0; $data_unknown =0; $data_not_init = 0; $data_alert = 0; $data_alert_total = 0; $monitor_alert_total = 0; $ahora=date("Y/m/d H:i:s"); $ahora_sec = strtotime($ahora); // Prepare data to show // For each valid group for this user, take data from agent and modules foreach ($mis_grupos as $migrupo) { if ($migrupo != "") { $existen_agentes = 0; $sql0 = "SELECT COUNT(id_agente) FROM tagente WHERE id_grupo = $migrupo AND disabled = 0"; $result0 = mysql_query ($sql0); $row0 = mysql_fetch_array ($result0); $total_agents = $total_agents + $row0[0]; if ($row0[0] > 0) $existen_agentes = 1; // SQL Join to get monitor status for agents belong this group $sql1 = "SELECT tagente.id_agente, tagente_estado.estado, tagente_estado.datos, tagente_estado.current_interval, tagente_estado.utimestamp, tagente_estado.id_agente_modulo FROM tagente, tagente_estado WHERE tagente.disabled = 0 AND tagente.id_grupo = $migrupo AND tagente.id_agente = tagente_estado.id_agente "; if ($result1 = mysql_query ($sql1)){ while ($row1 = mysql_fetch_array ($result1)) { $id_agente = $row1[0]; $estado = $row1[1]; $datos = $row1[2]; $module_interval = $row1[3]; $utimestamp = $row1[4]; $seconds = $ahora_sec - $utimestamp; $id_agente_modulo = $row1[5]; if ($estado != 100){ // Monitor check $monitor_checks++; if ($utimestamp == 0) $monitor_not_init++; elseif ($seconds >= ($module_interval*2)) $monitor_unknown++; elseif ($datos != 0) { $monitor_ok++; } else { $monitor_bad++; } // Alert if ($utimestamp != 0){ $sql2 = "SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = $id_agente_modulo"; if ($result2 = mysql_query ($sql2)){ if ($row2 = mysql_fetch_array ($result2)){ $monitor_alert_total++; if ($row2[0] > 0) $monitor_alert++; } } } } else { // Data check if ($utimestamp == 0) $data_not_init++; elseif ($seconds >= ($module_interval*2)) $data_unknown++; $data_checks++; // Alert if ($utimestamp != 0){ $sql2 = "SELECT times_fired FROM talerta_agente_modulo WHERE id_agente_modulo = $id_agente_modulo"; if ($result2 = mysql_query ($sql2)){ if ($row2 = mysql_fetch_array ($result2)) { $data_alert_total++; if ($row2[0] > 0) $data_alert++; } } } } } } } } $data = array(); $data[0] = $monitor_checks; $data[1] = $monitor_ok; $data[2] = $monitor_bad; $data[3] = $monitor_unknown; $data[4] = $monitor_alert; $data[5] = $total_agents; $data[6] = $data_checks; $data[7] = $data_unknown; $data[8] = $data_alert; $data[9] = $data_alert_total; $data[10] = $monitor_alert_total; $data[11] = $data_not_init; $data[12] = $monitor_not_init; return $data; } function event_reporting ($id_agent, $period){ require("config.php"); require ("include/languages/language_".$language_code.".php"); $id_user=$_SESSION["id_usuario"]; global $REMOTE_ADDR; $ahora = date("U"); $mytimestamp = $ahora - $period; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; $color = 1; $id_evento = 0; $sql2="SELECT * FROM tevento WHERE id_agente = $id_agent AND utimestamp > '$mytimestamp'"; // Make query for data (all data, not only distinct). $result2=mysql_query($sql2); while ($row2=mysql_fetch_array($result2)){ $id_grupo = $row2["id_grupo"]; if (give_acl($id_user, $id_grupo, "IR") == 1){ // Only incident read access to view data ! $id_group = $row2["id_grupo"]; if ($color == 1){ $tdcolor = "datos"; $color = 0; } else { $tdcolor = "datos2"; $color = 1; } echo ""; } } echo "
".$lang_label["status"]."".$lang_label["event_name"]."".$lang_label["id_user"]."".$lang_label["timestamp"]."
"; if ($row2["estado"] == 0) echo ""; else echo ""; echo "".$row2["evento"]; echo ""; if ($row2["estado"] <> 0) echo substr($row2["id_usuario"],0,8)." ".dame_nombre_real($row2["id_usuario"]).""; echo "".$row2["timestamp"]; echo "
"; } function alert_reporting ($id_agent_module){ require("config.php"); require ("include/languages/language_".$language_code.".php"); $query_gen='SELECT talerta_agente_modulo.alert_text, talerta_agente_modulo.id_alerta, talerta_agente_modulo.descripcion, talerta_agente_modulo.last_fired, talerta_agente_modulo.times_fired, tagente_modulo.nombre, talerta_agente_modulo.dis_max, talerta_agente_modulo.dis_min, talerta_agente_modulo.max_alerts, talerta_agente_modulo.time_threshold, talerta_agente_modulo.min_alerts, talerta_agente_modulo.id_agente_modulo, tagente_modulo.id_agente_modulo FROM tagente_modulo, talerta_agente_modulo WHERE tagente_modulo.id_agente_modulo = talerta_agente_modulo.id_agente_modulo and talerta_agente_modulo.id_agente_modulo = '.$id_agent_module.' ORDER BY tagente_modulo.nombre'; $result_gen=mysql_query($query_gen); if (mysql_num_rows ($result_gen)) { echo ""; echo ""; $color=1; while ($data=mysql_fetch_array($result_gen)){ if ($color == 1){ $tdcolor = "datos"; $color = 0; } else { $tdcolor = "datos2"; $color = 1; } echo ""; if ($data["times_fired"] <> 0) echo ""; else echo ""; echo ""; echo ""; } else { echo ""; } echo ""; } echo '
".$lang_label["status"]." ".$lang_label["description"]." ".$lang_label["time_threshold"]." ".$lang_label["last_fired"]." ".$lang_label["times_fired"]."
".$data["descripcion"]."".human_time_description($data["time_threshold"]); if ($data["last_fired"] == "0000-00-00 00:00:00") { echo "".$lang_label["never"]."".human_time_comparation ($data["last_fired"])."".$data["times_fired"]."
'; } } ?>