Skip to content

Commit d434cc5

Browse files
authored
Merge pull request #1499 from netalertx/main
sync
2 parents 4991b05 + cedbd59 commit d434cc5

File tree

258 files changed

+8301
-4894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

258 files changed

+8301
-4894
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ ENV LANG=C.UTF-8
137137
RUN apk add --no-cache bash mtr libbsd zip lsblk tzdata curl arp-scan iproute2 iproute2-ss nmap fping \
138138
nmap-scripts traceroute nbtscan net-tools net-snmp-tools bind-tools awake ca-certificates \
139139
sqlite php83 php83-fpm php83-cgi php83-curl php83-sqlite3 php83-session python3 envsubst \
140-
nginx supercronic shadow su-exec && \
140+
nginx supercronic shadow su-exec jq && \
141141
rm -Rf /var/cache/apk/* && \
142142
rm -Rf /etc/nginx && \
143143
addgroup -g ${NETALERTX_GID} ${NETALERTX_GROUP} && \

.devcontainer/scripts/generate-configs.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,17 @@ cat "${DEVCONTAINER_DIR}/resources/devcontainer-Dockerfile"
3131

3232
echo "Generated $OUT_FILE using root dir $ROOT_DIR"
3333

34+
# Passive Gemini MCP config
35+
TOKEN=$(grep '^API_TOKEN=' /data/config/app.conf 2>/dev/null | cut -d"'" -f2)
36+
if [ -n "${TOKEN}" ]; then
37+
mkdir -p "${ROOT_DIR}/.gemini"
38+
[ -f "${ROOT_DIR}/.gemini/settings.json" ] || echo "{}" > "${ROOT_DIR}/.gemini/settings.json"
39+
jq --arg t "$TOKEN" '.mcpServers["netalertx-devcontainer"] = {url: "http://127.0.0.1:20212/mcp/sse", headers: {Authorization: ("Bearer " + $t)}}' "${ROOT_DIR}/.gemini/settings.json" > "${ROOT_DIR}/.gemini/settings.json.tmp" && mv "${ROOT_DIR}/.gemini/settings.json.tmp" "${ROOT_DIR}/.gemini/settings.json"
40+
41+
# VS Code MCP config
42+
mkdir -p "${ROOT_DIR}/.vscode"
43+
[ -f "${ROOT_DIR}/.vscode/mcp.json" ] || echo "{}" > "${ROOT_DIR}/.vscode/mcp.json"
44+
jq --arg t "$TOKEN" '.servers["netalertx-devcontainer"] = {type: "sse", url: "http://127.0.0.1:20212/mcp/sse", headers: {Authorization: ("Bearer " + $t)}}' "${ROOT_DIR}/.vscode/mcp.json" > "${ROOT_DIR}/.vscode/mcp.json.tmp" && mv "${ROOT_DIR}/.vscode/mcp.json.tmp" "${ROOT_DIR}/.vscode/mcp.json"
45+
fi
46+
3447
echo "Done."

.devcontainer/scripts/run-tests.sh

Lines changed: 0 additions & 13 deletions
This file was deleted.

.devcontainer/scripts/setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ LOG_FILES=(
3232
LOG_DB_IS_LOCKED
3333
LOG_NGINX_ERROR
3434
)
35-
3635
sudo chmod 666 /var/run/docker.sock 2>/dev/null || true
3736
sudo chown "$(id -u)":"$(id -g)" /workspaces
3837
sudo chmod 755 /workspaces
@@ -55,6 +54,9 @@ sudo install -d -m 777 /tmp/log/plugins
5554
sudo rm -rf /entrypoint.d
5655
sudo ln -s "${SOURCE_DIR}/install/production-filesystem/entrypoint.d" /entrypoint.d
5756

57+
sudo rm -rf /services
58+
sudo ln -s "${SOURCE_DIR}/install/production-filesystem/services" /services
59+
5860
sudo rm -rf "${NETALERTX_APP}"
5961
sudo ln -s "${SOURCE_DIR}/" "${NETALERTX_APP}"
6062

@@ -88,8 +90,6 @@ sudo chmod 777 "${LOG_DB_IS_LOCKED}"
8890

8991
sudo pkill -f python3 2>/dev/null || true
9092

91-
sudo chmod -R 777 "${PY_SITE_PACKAGES}" "${NETALERTX_DATA}" 2>/dev/null || true
92-
9393
sudo chown -R "${NETALERTX_USER}:${NETALERTX_GROUP}" "${NETALERTX_APP}"
9494
date +%s | sudo tee "${NETALERTX_FRONT}/buildtimestamp.txt" >/dev/null
9595

.gemini/GEMINI.md

Lines changed: 0 additions & 59 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: devcontainer-management
3+
description: Guide for identifying, managing, and running commands within the NetAlertX development container. Use this when asked to run commands, testing, setup scripts, or troubleshoot container issues.
4+
---
5+
6+
# Devcontainer Management
7+
8+
When starting a session or performing tasks requiring the runtime environment, you must identify and use the active development container.
9+
10+
## Finding the Container
11+
12+
Run `docker ps` to list running containers. Look for an image name containing `vsc-netalertx` or similar.
13+
14+
```bash
15+
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Status}}\t{{.Names}}" | grep netalertx
16+
```
17+
18+
- **If no container is found:** Inform the user. You cannot run integration tests or backend logic without it.
19+
- **If multiple containers are found:** Ask the user to clarify which one to use (e.g., provide the Container ID).
20+
21+
## Running Commands in the Container
22+
23+
Prefix commands with `docker exec <CONTAINER_ID>` to run them inside the environment. Use the scripts in `/services/` to control backend and other processes.
24+
25+
```bash
26+
docker exec <CONTAINER_ID> bash /workspaces/NetAlertX/.devcontainer/scripts/setup.sh
27+
```
28+
29+
*Note: This script wipes `/tmp` ramdisks, resets DBs, and restarts services (python server, cron,php-fpm, nginx).*
30+
31+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
name: mcp-activation
3+
description: Enables live interaction with the NetAlertX runtime. This skill configures the Model Context Protocol (MCP) connection, granting full API access for debugging, troubleshooting, and real-time operations including database queries, network scans, and device management.
4+
---
5+
6+
# MCP Activation Skill
7+
8+
This skill configures the NetAlertX development environment to expose the Model Context Protocol (MCP) server to AI agents.
9+
10+
## Why use this?
11+
12+
By default, agents only have access to the static codebase (files). To perform dynamic actions—such as:
13+
- **Querying the database** (e.g., getting device lists, events)
14+
- **Triggering actions** (e.g., network scans, Wake-on-LAN)
15+
- **Validating runtime state** (e.g., checking if a fix actually works)
16+
17+
...you need access to the **MCP Server** running inside the container. This skill sets up the necessary authentication tokens and connection configs to bridge your agent to that live server.
18+
19+
## Prerequisites
20+
21+
1. **Devcontainer:** You must be connected to the NetAlertX devcontainer.
22+
2. **Server Running:** The backend server must be running (to generate `app.conf` with the API token).
23+
24+
## Activation Steps
25+
26+
1. **Activate Devcontainer Skill:**
27+
If you are not already inside the container, activate the management skill:
28+
```text
29+
activate_skill("devcontainer-management")
30+
```
31+
32+
2. **Generate Configurations:**
33+
Run the configuration generation script *inside* the container. This script extracts the API Token and creates the necessary settings files (`.gemini/settings.json` and `.vscode/mcp.json`).
34+
35+
```bash
36+
# Run inside the container
37+
/workspaces/NetAlertX/.devcontainer/scripts/generate-configs.sh
38+
```
39+
40+
3. **Apply Changes:**
41+
42+
* **For Gemini CLI:**
43+
The agent session must be **restarted** to load the new `.gemini/settings.json`.
44+
> "I have generated the MCP configuration. Please **restart this session** to activate the `netalertx-devcontainer` tools."
45+
46+
* **For VS Code (GitHub Copilot / Cline):**
47+
The VS Code window must be **reloaded** to pick up the new `.vscode/mcp.json`.
48+
> "I have generated the MCP configuration. Please run **'Developer: Reload Window'** in VS Code to activate the MCP server."
49+
50+
## Verification
51+
52+
After restarting, you should see new tools available (e.g., `netalertx-devcontainer__get_devices`).
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: project-navigation
3+
description: Reference for the NetAlertX codebase structure, key file paths, and configuration locations. Use this when exploring the codebase or looking for specific components like the backend entry point, frontend files, or database location.
4+
---
5+
6+
# Project Navigation & Structure
7+
8+
## Codebase Structure & Key Paths
9+
10+
- **Source Code:** `/workspaces/NetAlertX` (mapped to `/app` in container via symlink).
11+
- **Backend Entry:** `server/api_server/api_server_start.py` (Flask) and `server/__main__.py`.
12+
- **Frontend:** `front/` (PHP/JS).
13+
- **Plugins:** `front/plugins/`.
14+
- **Config:** `/data/config/app.conf` (runtime) or `back/app.conf` (default).
15+
- **Database:** `/data/db/app.db` (SQLite).
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: testing-workflow
3+
description: Read before running tests. Detailed instructions for single, standard unit tests (fast), full suites (slow), handling authentication, and obtaining the API Token. Tests must be run when a job is complete.
4+
---
5+
6+
# Testing Workflow
7+
After code is developed, tests must be run to ensure the integrity of the final result.
8+
9+
**Crucial:** Tests MUST be run inside the container to access the correct runtime environment (DB, Config, Dependencies).
10+
11+
## 0. Pre-requisites: Environment Check
12+
13+
Before running any tests, verify you are inside the development container:
14+
15+
```bash
16+
ls -d /workspaces/NetAlertX
17+
```
18+
19+
**IF** this directory does not exist, you are likely on the host machine. You **MUST** immediately activate the `devcontainer-management` skill to enter the container or run commands inside it.
20+
21+
```text
22+
activate_skill("devcontainer-management")
23+
```
24+
25+
## 1. Full Test Suite (MANDATORY DEFAULT)
26+
27+
Unless the user **explicitly** requests "fast" or "quick" tests, you **MUST** run the full test suite. **Do not** optimize for time. Comprehensive coverage is the priority over speed.
28+
29+
```bash
30+
cd /workspaces/NetAlertX; pytest test/
31+
```
32+
33+
## 2. Fast Unit Tests (Conditional)
34+
35+
**ONLY** use this if the user explicitly asks for "fast tests", "quick tests", or "unit tests only". This **excludes** slow tests marked with `docker` or `feature_complete`.
36+
37+
```bash
38+
cd /workspaces/NetAlertX; pytest test/ -m 'not docker and not feature_complete'
39+
```
40+
41+
## 3. Running Specific Tests
42+
43+
To run a specific file or folder:
44+
45+
```bash
46+
cd /workspaces/NetAlertX; pytest test/<path_to_test>
47+
```
48+
49+
*Example:*
50+
```bash
51+
cd /workspaces/NetAlertX; pytest test/api_endpoints/test_mcp_extended_endpoints.py
52+
```
53+
54+
## Authentication & Environment Reset
55+
56+
Authentication tokens are required to perform certain operations such as manual testing or crafting expressions to work with the web APIs. After making code changes, you MUST reset the environment to ensure the new code is running and verify you have the latest `API_TOKEN`.
57+
58+
1. **Reset Environment:** Run the setup script inside the container.
59+
```bash
60+
bash /workspaces/NetAlertX/.devcontainer/scripts/setup.sh
61+
```
62+
2. **Wait for Stabilization:** Wait at least 5 seconds for services (nginx, python server, etc.) to start.
63+
```bash
64+
sleep 5
65+
```
66+
3. **Obtain Token:** Retrieve the current token from the container.
67+
```bash
68+
python3 -c "from helper import get_setting_value; print(get_setting_value('API_TOKEN'))"
69+
```
70+
71+
The retrieved token MUST be used in all subsequent API or test calls requiring authentication.
72+
73+
### Troubleshooting
74+
75+
If tests fail with 403 Forbidden or empty tokens:
76+
1. Verify server is running and use the setup script (`/workspaces/NetAlertX/.devcontainer/scripts/setup.sh`) if required.
77+
2. Verify `app.conf` inside the container: `cat /data/config/app.conf`
78+
3. Verify Python can read it: `python3 -c "from helper import get_setting_value; print(get_setting_value('API_TOKEN'))"`

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
github: jokob-sk
2-
patreon: netalertx
32
buy_me_a_coffee: jokobsk

0 commit comments

Comments
 (0)