Spaces:
Runtime error
Runtime error
Update pages/Omnilog.py
Browse files- pages/Omnilog.py +87 -46
pages/Omnilog.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import re, hashlib
|
| 3 |
from utils.file_utils import normalize_log_line, keyword_search
|
| 4 |
from utils.summarizer import summarize_text
|
| 5 |
|
| 6 |
st.title("📜 Omnilog")
|
| 7 |
-
st.write("Log analyzer with normalization, search, and
|
| 8 |
|
| 9 |
# Init counters
|
| 10 |
if "uploaded_files" not in st.session_state:
|
|
@@ -12,47 +12,88 @@ if "uploaded_files" not in st.session_state:
|
|
| 12 |
if "errors" not in st.session_state:
|
| 13 |
st.session_state.errors = []
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
st.
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import re, hashlib, time, os
|
| 3 |
from utils.file_utils import normalize_log_line, keyword_search
|
| 4 |
from utils.summarizer import summarize_text
|
| 5 |
|
| 6 |
st.title("📜 Omnilog")
|
| 7 |
+
st.write("Log analyzer with normalization, search, AI summaries, and real-time tailing")
|
| 8 |
|
| 9 |
# Init counters
|
| 10 |
if "uploaded_files" not in st.session_state:
|
|
|
|
| 12 |
if "errors" not in st.session_state:
|
| 13 |
st.session_state.errors = []
|
| 14 |
|
| 15 |
+
mode = st.radio("Mode", ["Upload Log File", "Live Syslog Tail"])
|
| 16 |
+
|
| 17 |
+
# ─── Upload Mode ──────────────────────────────────────────────
|
| 18 |
+
if mode == "Upload Log File":
|
| 19 |
+
uploaded = st.file_uploader("Upload a log file", type=["log", "txt"])
|
| 20 |
+
if uploaded:
|
| 21 |
+
try:
|
| 22 |
+
content = uploaded.read().decode("utf-8", errors="ignore")
|
| 23 |
+
|
| 24 |
+
# Track upload
|
| 25 |
+
st.session_state.uploaded_files.append(uploaded.name)
|
| 26 |
+
|
| 27 |
+
# Normalize
|
| 28 |
+
normalized = [normalize_log_line(line) for line in content.splitlines()]
|
| 29 |
+
|
| 30 |
+
# Display normalized preview
|
| 31 |
+
st.subheader("🧹 Normalized Logs")
|
| 32 |
+
st.code("\n".join(normalized[:50]))
|
| 33 |
+
|
| 34 |
+
# Stats
|
| 35 |
+
st.subheader("📊 Stats")
|
| 36 |
+
st.metric("Total Lines", len(normalized))
|
| 37 |
+
st.metric("Unique Entries", len(set(normalized)))
|
| 38 |
+
st.write("SHA1 Digest:", hashlib.sha1(content.encode()).hexdigest())
|
| 39 |
+
|
| 40 |
+
# Keyword search
|
| 41 |
+
query = st.text_input("🔍 Search logs")
|
| 42 |
+
matches = []
|
| 43 |
+
if query:
|
| 44 |
+
matches = keyword_search("\n".join(normalized), query)
|
| 45 |
+
st.success(f"Found {len(matches)} matches")
|
| 46 |
+
st.code("\n".join(matches[:50]))
|
| 47 |
+
|
| 48 |
+
# AI summarization
|
| 49 |
+
st.subheader("🧠 AI Summary")
|
| 50 |
+
summary = summarize_text("\n".join(normalized))
|
| 51 |
+
st.write(summary)
|
| 52 |
+
|
| 53 |
+
# Save for Chatbot
|
| 54 |
+
st.session_state.omnilog_output = {
|
| 55 |
+
"normalized_preview": "\n".join(normalized[:50]),
|
| 56 |
+
"matches": matches[:50],
|
| 57 |
+
"summary": summary,
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
except Exception as e:
|
| 61 |
+
st.error(f"⚠️ Error processing log: {e}")
|
| 62 |
+
st.session_state.errors.append(str(e))
|
| 63 |
+
|
| 64 |
+
# ─── Live Tailing Mode ────────────────────────────────────────
|
| 65 |
+
elif mode == "Live Syslog Tail":
|
| 66 |
+
logfile = "/var/log/syslog"
|
| 67 |
+
if not os.path.exists(logfile):
|
| 68 |
+
st.error("⚠️ Syslog not found. This mode only works locally.")
|
| 69 |
+
else:
|
| 70 |
+
st.info(f"Streaming last 50 lines from {logfile} (auto-refreshing)")
|
| 71 |
+
|
| 72 |
+
# Read last 50 lines
|
| 73 |
+
def tail_file(path, n=50):
|
| 74 |
+
with open(path, "r", errors="ignore") as f:
|
| 75 |
+
lines = f.readlines()
|
| 76 |
+
return lines[-n:]
|
| 77 |
+
|
| 78 |
+
# Placeholder container
|
| 79 |
+
placeholder = st.empty()
|
| 80 |
+
|
| 81 |
+
# Live loop
|
| 82 |
+
for _ in range(200): # ~200 refreshes (stop after)
|
| 83 |
+
lines = tail_file(logfile, 50)
|
| 84 |
+
normalized = [normalize_log_line(l) for l in lines]
|
| 85 |
+
|
| 86 |
+
# Highlight critical warnings
|
| 87 |
+
highlighted = []
|
| 88 |
+
for line in normalized:
|
| 89 |
+
if re.search(r"(CRITICAL|FAILED|WARNING)", line, re.IGNORECASE):
|
| 90 |
+
highlighted.append("⚠️ " + line)
|
| 91 |
+
st.session_state.errors.append(line)
|
| 92 |
+
else:
|
| 93 |
+
highlighted.append(line)
|
| 94 |
+
|
| 95 |
+
# Update live view
|
| 96 |
+
with placeholder.container():
|
| 97 |
+
st.code("\n".join(highlighted))
|
| 98 |
+
|
| 99 |
+
time.sleep(2) # refresh every 2s
|