/c/pr/1 · v1
NetSignal Mini
You are an expert Python developer. Write a complete, working program called "NetSignal Mini":
a colorful web dashboard for Cisco syslog messages.
RULES
- One file only: netsignal_mini.py. Python 3.12, standard library only (no pip packages).
- The web page (HTML, CSS, JavaScript) is embedded in the Python file as a string.
No CDN, no external fonts, no external scripts. Charts are drawn with inline SVG.
- Read-only: never write, move or delete anything in the log folder.
- Give me the whole file in one answer. No placeholders, no "TODO", no shortened parts.
SETTINGS (constants at the top of the file)
LOG_DIR = "/opt/netsignal-demo/logs"
LIVE_FILE = "demo-syslog.log" # the file that grows all day
PORT = 8090
HOST = "0.0.0.0"
START_READ_MB = 50 # at start, read only the last 50 MB of the live file
MAX_EVENTS = 200000 # keep the newest events in memory (collections.deque)
LOG FORMAT (synthetic examples, not from any real network)
Jan 07 09:41:05 demo-core-01.example.com 1001: Jan 07 09:41:04.250 UTC: %OSPF-5-ADJCHG: Process 1, Nbr 192.0.2.20 on TenGigabitEthernet0/0/1 from FULL to DOWN, Neighbor Down: Dead timer expired
Jan 07 09:41:12 demo-access-02 %LINK-3-UPDOWN: Interface GigabitEthernet0/0/5, changed state to down
Jan 07 09:41:30 demo-access-02 %SEC_LOGIN-4-LOGIN_FAILED: Login failed [user: demo-user] [Source: 198.51.100.7]
From each line extract: time (first timestamp, add the current year), device (host name without
the domain), code (FACILITY-SEVERITY-MNEMONIC), severity (the digit 0-7), message (text after
the code). Lines that do not match are skipped and counted as "unparsed".
BACKGROUND READER (one thread)
- At start read the last START_READ_MB of the live file, then every 1 second read only the new bytes.
- If the file becomes smaller (rotated), start again from the beginning of the new file.
- Handle a half-written last line (keep it until the newline arrives).
- Protect the shared event list with a lock.
WEB SERVER (http.server.ThreadingHTTPServer)
- GET / the dashboard page
- GET /api/data JSON for the page. Query parameters: minutes (default 60), q (text filter,
matches device, code or message, case-insensitive), sev (maximum severity number)
JSON content: totals, count per severity, count per 5-minute bucket per severity,
top 10 devices, top 10 codes, newest 200 matching events, unparsed count, last update time.
DASHBOARD PAGE
- Dark background, modern look, colorful. Severity colors: 0-2 red, 3 orange, 4 yellow,
5 blue, 6-7 grey.
- Top row: 5 big tiles: Total messages, Critical (0-2), Errors (3), Warnings (4), Devices reporting.
- Stacked bar chart: messages per 5 minutes, colored by severity (SVG).
- Two horizontal bar charts side by side: Top 10 devices, Top 10 message codes.
Clicking a bar puts that device or code in the filter box.
- Table of the newest 200 messages: time, device, colored severity badge, code, message.
Message text must be HTML-escaped.
- Controls: time range buttons (15 min, 1 h, 6 h, 24 h), a filter text box,
a severity selector, and a Pause button.
- The page refreshes its data every 5 seconds with fetch() without reloading.
- Works on a 1920 px monitor and on a laptop screen.
AFTER THE CODE
Give the command to start it and the address to open in the browser. Nothing else.