2610.3
This commit is contained in:
1 parent
c2180fcc8f
commit
e16320124b
1 file changed
+19
-3
+19
-3
@@ -408,7 +408,8 @@ shell_access() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ── log helpers ───────────────────────────────────────────────────────────────
|
# ── log helpers ───────────────────────────────────────────────────────────────
|
||||||
# Prints the last 5 log events (always exactly 5 lines): timestamp, src_ip, dst_port.
|
# Prints the last 5 events from the past hour (always exactly 5 lines):
|
||||||
|
# timestamp (local time), src_ip, dst_port.
|
||||||
|
|
||||||
log_last5() {
|
log_last5() {
|
||||||
if [ ! -f "$LOG_FILE" ]; then
|
if [ ! -f "$LOG_FILE" ]; then
|
||||||
@@ -417,7 +418,9 @@ log_last5() {
|
|||||||
fi
|
fi
|
||||||
tail -n 5 "$LOG_FILE" | python3 -c '
|
tail -n 5 "$LOG_FILE" | python3 -c '
|
||||||
import sys, json
|
import sys, json
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
out = []
|
out = []
|
||||||
|
cutoff = datetime.now(timezone.utc) - timedelta(hours=1)
|
||||||
for line in sys.stdin:
|
for line in sys.stdin:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line:
|
if not line:
|
||||||
@@ -426,10 +429,23 @@ for line in sys.stdin:
|
|||||||
e = json.loads(line)
|
e = json.loads(line)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
ts = str(e.get("timestamp", "?"))
|
raw_ts = str(e.get("timestamp", ""))
|
||||||
|
if raw_ts.endswith("Z"):
|
||||||
|
raw_ts = raw_ts[:-1] + "+00:00"
|
||||||
|
try:
|
||||||
|
ts = datetime.fromisoformat(raw_ts)
|
||||||
|
except ValueError:
|
||||||
|
continue
|
||||||
|
if ts.tzinfo is None:
|
||||||
|
ts = ts.replace(tzinfo=timezone.utc)
|
||||||
|
if ts < cutoff:
|
||||||
|
continue
|
||||||
src = str(e.get("src_ip", "?"))
|
src = str(e.get("src_ip", "?"))
|
||||||
dst = str(e.get("dst_port", "?"))
|
dst = str(e.get("dst_port", "?"))
|
||||||
out.append(f" {ts:<34} {src:<18} {dst}")
|
local_ts = ts.astimezone().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
out.append(f" {local_ts:<34} {src:<18} {dst}")
|
||||||
|
if not out:
|
||||||
|
out.append(" (no events in the last hour)")
|
||||||
while len(out) < 5:
|
while len(out) < 5:
|
||||||
out.append("")
|
out.append("")
|
||||||
print("\n".join(out))
|
print("\n".join(out))
|
||||||
|
|||||||
Reference in new issue
Block a user