/data and /tmp standarization

This commit is contained in:
Adam Outler
2025-11-04 22:26:35 +00:00
parent 90a07c61eb
commit 5b871865db
250 changed files with 7462 additions and 4940 deletions

View File

@@ -1,6 +1,6 @@
# NetAlertX-New-Devices-Checkmk-Script
This script retrieves the list of all devices from NetAlertX by reading the `/app/api/table_devices.json` file within the "NetAlertX" Docker container. It then checks if there are any new devices (`devIsNew == 1`).
This script retrieves the list of all devices from NetAlertX by reading the `table_devices.json` file from the API directory within the "NetAlertX" Docker container (default: `/tmp/api`, configurable via `NETALERTX_API` environment variable). It then checks if there are any new devices (`devIsNew == 1`).
- If new devices are found, a warning state is reported.
- Otherwise, an OK state is returned.

View File

@@ -1,13 +1,12 @@
YABin
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
NetAlertX-New-Devices-Checkmk-Script
Dieses Skript ruft die Liste aller Devices aus NetAlertX ab, indem es innerhalb
des Docker-Containers "NetAlertX" die Datei /app/api/table_devices.json ausliest.
des Docker-Containers "NetAlertX" die Datei table_devices.json aus dem API-Verzeichnis
ausliest (standardmäßig /tmp/api, konfigurierbar via NETALERTX_API).
Anschließend wird geprüft, ob neue Geräte vorhanden sind (devIsNew == 1).
Falls ja, wird ein Warning-Zustand gemeldet, sonst OK.
@@ -18,12 +17,17 @@ Siehe: https://docs.checkmk.com/latest/de/localchecks.html
import subprocess
import json
import os
def check_new_devices():
# Get API path from environment variable, fallback to /tmp/api
api_path = os.environ.get('NETALERTX_API', '/tmp/api')
table_devices_path = f'{api_path}/table_devices.json'
try:
# Rufe die JSON-Datei aus dem Docker-Container ab
result = subprocess.run(
['docker', 'exec', 'NetAlertX', 'cat', '/app/api/table_devices.json'],
['docker', 'exec', 'NetAlertX', 'cat', table_devices_path],
capture_output=True,
text=True,
check=True

View File

@@ -1,9 +1,15 @@
#!/usr/bin/env python3
import subprocess
import sys
import os
def run_sqlite_command(command):
full_command = f"sudo docker exec -i netalertx sqlite3 /app/db/app.db \"{command}\""
# Use environment variable with fallback
db_path = os.path.join(
os.getenv('NETALERTX_DB', '/data/db'),
'app.db'
)
full_command = f"sudo docker exec -i netalertx sqlite3 {db_path} \"{command}\""
try:
result = subprocess.run(full_command, shell=True, text=True, capture_output=True)
if result.stderr:

View File

@@ -1,7 +1,7 @@
#!/bin/sh
# This script recreates the database from schema code.
#Database location
NETALERTX_DB_FILE=/app/db/app.db
# Database location
NETALERTX_DB_FILE=${NETALERTX_DB:-/data/db}/app.db
#remove the old database
rm ${NETALERTX_DB_FILE}

View File

@@ -1,7 +1,12 @@
import sqlite3
import os
# Connect to the database
conn = sqlite3.connect("/app/db/app.db")
# Connect to the database using environment variable
db_path = os.path.join(
os.getenv('NETALERTX_DB', '/data/db'),
'app.db'
)
conn = sqlite3.connect(db_path)
cursor = conn.cursor()
# Get the names of all tables (excluding SQLite internal tables)