From 7221b4ba96b90c96a7817e9c76c4f7421b4231cc Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Sun, 15 Mar 2026 01:19:34 +0000 Subject: [PATCH 1/9] Keep all local changes while resolving conflicts --- docs/NOTIFICATION_TEMPLATES.md | 100 ++++++ .../notification_processing/config.json | 147 +++++++++ server/messaging/notification_sections.py | 133 ++++++++ server/messaging/reporting.py | 51 +-- server/models/notification_instance.py | 56 +--- test/backend/test_notification_templates.py | 299 ++++++++++++++++++ test/integration/integration_test.py | 14 +- 7 files changed, 723 insertions(+), 77 deletions(-) create mode 100644 docs/NOTIFICATION_TEMPLATES.md create mode 100644 server/messaging/notification_sections.py create mode 100644 test/backend/test_notification_templates.py diff --git a/docs/NOTIFICATION_TEMPLATES.md b/docs/NOTIFICATION_TEMPLATES.md new file mode 100644 index 00000000..2956bd32 --- /dev/null +++ b/docs/NOTIFICATION_TEMPLATES.md @@ -0,0 +1,100 @@ +# Notification Text Templates + +> Customize how devices and events appear in **text** notifications (email previews, push notifications, Apprise messages). + +By default, NetAlertX formats each device as a vertical list of `Header: Value` pairs. Text templates let you define a **single-line format per device** using `{FieldName}` placeholders — ideal for mobile notification previews and high-volume alerts. + +HTML email tables are **not affected** by these templates. + +## Quick Start + +1. Go to **Settings → Notification Processing**. +2. Set a template string for the section you want to customize, e.g.: + - **Text Template: New Devices** → `{devName} ({eve_MAC}) - {eve_IP}` +3. Save. The next notification will use your format. + +**Before (default):** +``` +🆕 New devices +--------- +devName: MyPhone +eve_MAC: aa:bb:cc:dd:ee:ff +devVendor: Apple +eve_IP: 192.168.1.42 +eve_DateTime: 2025-01-15 10:30:00 +eve_EventType: New Device +devComments: +``` + +**After (with template `{devName} ({eve_MAC}) - {eve_IP}`):** +``` +🆕 New devices +--------- +MyPhone (aa:bb:cc:dd:ee:ff) - 192.168.1.42 +``` + +## Settings Reference + +| Setting | Type | Default | Description | +|---------|------|---------|-------------| +| `NTFPRCS_TEXT_SECTION_HEADERS` | Boolean | `true` | Show/hide section titles (e.g. `🆕 New devices \n---------`). | +| `NTFPRCS_TEXT_TEMPLATE_new_devices` | String | *(empty)* | Template for new device rows. | +| `NTFPRCS_TEXT_TEMPLATE_down_devices` | String | *(empty)* | Template for down device rows. | +| `NTFPRCS_TEXT_TEMPLATE_down_reconnected` | String | *(empty)* | Template for reconnected device rows. | +| `NTFPRCS_TEXT_TEMPLATE_events` | String | *(empty)* | Template for event rows. | +| `NTFPRCS_TEXT_TEMPLATE_plugins` | String | *(empty)* | Template for plugin event rows. | + +When a template is **empty**, the section uses the original vertical `Header: Value` format (full backward compatibility). + +## Template Syntax + +Use `{FieldName}` to insert a value from the notification data. Field names are **case-sensitive** and must match the column names exactly. + +``` +{devName} ({eve_MAC}) connected at {eve_DateTime} +``` + +- No loops, conditionals, or nesting — just simple string replacement. +- If a `{FieldName}` does not exist in the data, it is left as-is in the output (safe failure). For example, `{NonExistent}` renders literally as `{NonExistent}`. + +## Variable Availability by Section + +All four device sections (`new_devices`, `down_devices`, `down_reconnected`, `events`) share the same unified field names. + +### `new_devices`, `down_devices`, `down_reconnected`, and `events` + +| Variable | Description | +|----------|-------------| +| `{devName}` | Device display name | +| `{eve_MAC}` | Device MAC address | +| `{devVendor}` | Device vendor/manufacturer | +| `{eve_IP}` | Device IP address | +| `{eve_DateTime}` | Event timestamp | +| `{eve_EventType}` | Type of event (e.g. `New Device`, `Connected`, `Device Down`) | +| `{devComments}` | Device comments | + +**Example (new_devices/events):** `{devName} ({eve_MAC}) - {eve_IP} [{eve_EventType}]` + +**Example (down_devices):** `{devName} ({eve_MAC}) {devVendor} - went down at {eve_DateTime}` + +**Example (down_reconnected):** `{devName} ({eve_MAC}) reconnected at {eve_DateTime}` + +### `plugins` + +| Variable | Description | +|----------|-------------| +| `{Plugin}` | Plugin code name | +| `{Object_PrimaryId}` | Primary identifier of the object | +| `{Object_SecondaryId}` | Secondary identifier | +| `{DateTimeChanged}` | Timestamp of change | +| `{Watched_Value1}` | First watched value | +| `{Watched_Value2}` | Second watched value | +| `{Watched_Value3}` | Third watched value | +| `{Watched_Value4}` | Fourth watched value | +| `{Status}` | Plugin event status | + +**Example:** `{Plugin}: {Object_PrimaryId} - {Status}` + +## Section Headers Toggle + +Set **Text Section Headers** (`NTFPRCS_TEXT_SECTION_HEADERS`) to `false` to remove the section title separators from text notifications. This is useful when you want compact output without the `🆕 New devices \n---------` banners. diff --git a/front/plugins/notification_processing/config.json b/front/plugins/notification_processing/config.json index acb4fbbf..bf2c9e2a 100755 --- a/front/plugins/notification_processing/config.json +++ b/front/plugins/notification_processing/config.json @@ -152,6 +152,153 @@ "string": "You can specify a SQL where condition to filter out Events from notifications. For example AND devLastIP NOT LIKE '192.168.3.%' will always exclude any Event notifications for all devices with the IP starting with 192.168.3.%." } ] +<<<<<<< Updated upstream +======= + }, + { + "function": "TEXT_SECTION_HEADERS", + "type": { + "dataType": "boolean", + "elements": [ + { "elementType": "input", "elementOptions": [{ "type": "checkbox" }], "transformers": [] } + ] + }, + "default_value": true, + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Text Section Headers" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Enable or disable section titles (e.g. 🆕 New devices \\n---------) in text notifications. Enabled by default for backward compatibility." + } + ] + }, + { + "function": "TEXT_TEMPLATE_new_devices", + "type": { + "dataType": "string", + "elements": [ + { "elementType": "input", "elementOptions": [], "transformers": [] } + ] + }, + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Text Template: New Devices" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Custom text template for new device notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) - {eve_IP}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + } + ] + }, + { + "function": "TEXT_TEMPLATE_down_devices", + "type": { + "dataType": "string", + "elements": [ + { "elementType": "input", "elementOptions": [], "transformers": [] } + ] + }, + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Text Template: Down Devices" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Custom text template for down device notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) - {eve_IP}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + } + ] + }, + { + "function": "TEXT_TEMPLATE_down_reconnected", + "type": { + "dataType": "string", + "elements": [ + { "elementType": "input", "elementOptions": [], "transformers": [] } + ] + }, + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Text Template: Reconnected" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Custom text template for reconnected device notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) reconnected at {eve_DateTime}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + } + ] + }, + { + "function": "TEXT_TEMPLATE_events", + "type": { + "dataType": "string", + "elements": [ + { "elementType": "input", "elementOptions": [], "transformers": [] } + ] + }, + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Text Template: Events" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Custom text template for event notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) {eve_EventType} at {eve_DateTime}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + } + ] + }, + { + "function": "TEXT_TEMPLATE_plugins", + "type": { + "dataType": "string", + "elements": [ + { "elementType": "input", "elementOptions": [], "transformers": [] } + ] + }, + "default_value": "", + "options": [], + "localized": ["name", "description"], + "name": [ + { + "language_code": "en_us", + "string": "Text Template: Plugins" + } + ], + "description": [ + { + "language_code": "en_us", + "string": "Custom text template for plugin event notifications. Use {FieldName} placeholders, e.g. {Plugin}: {Object_PrimaryId} - {Status}. Leave empty for default formatting. Available fields: {Plugin}, {Object_PrimaryId}, {Object_SecondaryId}, {DateTimeChanged}, {Watched_Value1}, {Watched_Value2}, {Watched_Value3}, {Watched_Value4}, {Status}." + } + ] +>>>>>>> Stashed changes } ], diff --git a/server/messaging/notification_sections.py b/server/messaging/notification_sections.py new file mode 100644 index 00000000..a31fb204 --- /dev/null +++ b/server/messaging/notification_sections.py @@ -0,0 +1,133 @@ +# ------------------------------------------------------------------------------- +# notification_sections.py — Single source of truth for notification section +# metadata: titles, SQL templates, datetime fields, and section ordering. +# +# Both reporting.py and notification_instance.py import from here. +# ------------------------------------------------------------------------------- + +# Canonical processing order +SECTION_ORDER = [ + "new_devices", + "down_devices", + "down_reconnected", + "events", + "plugins", +] + +# Section display titles (used in text + HTML notifications) +SECTION_TITLES = { + "new_devices": "🆕 New devices", + "down_devices": "🔴 Down devices", + "down_reconnected": "🔁 Reconnected down devices", + "events": "⚡ Events", + "plugins": "🔌 Plugins", +} + +# Which column(s) contain datetime values per section (for timezone conversion) +DATETIME_FIELDS = { + "new_devices": ["eve_DateTime"], + "down_devices": ["eve_DateTime"], + "down_reconnected": ["eve_DateTime"], + "events": ["eve_DateTime"], + "plugins": ["DateTimeChanged"], +} + +# --------------------------------------------------------------------------- +# SQL templates +# +# All device sections use unified DB column names so the JSON output +# has consistent field names across new_devices, down_devices, +# down_reconnected, and events. +# +# Placeholders: +# {condition} — optional WHERE clause appended by condition builder +# {alert_down_minutes} — runtime value, only used by down_devices +# --------------------------------------------------------------------------- +SQL_TEMPLATES = { + "new_devices": """ + SELECT + devName, + eve_MAC, + devVendor, + devLastIP as eve_IP, + eve_DateTime, + eve_EventType, + devComments + FROM Events_Devices + WHERE eve_PendingAlertEmail = 1 + AND eve_EventType = 'New Device' {condition} + ORDER BY eve_DateTime + """, + "down_devices": """ + SELECT + devName, + eve_MAC, + devVendor, + eve_IP, + eve_DateTime, + eve_EventType, + devComments + FROM Events_Devices AS down_events + WHERE eve_PendingAlertEmail = 1 + AND down_events.eve_EventType = 'Device Down' + AND eve_DateTime < datetime('now', '-{alert_down_minutes} minutes') + AND NOT EXISTS ( + SELECT 1 + FROM Events AS connected_events + WHERE connected_events.eve_MAC = down_events.eve_MAC + AND connected_events.eve_EventType = 'Connected' + AND connected_events.eve_DateTime > down_events.eve_DateTime + ) + ORDER BY down_events.eve_DateTime + """, + "down_reconnected": """ + SELECT + devName, + eve_MAC, + devVendor, + eve_IP, + eve_DateTime, + eve_EventType, + devComments + FROM Events_Devices AS reconnected_devices + WHERE reconnected_devices.eve_EventType = 'Down Reconnected' + AND reconnected_devices.eve_PendingAlertEmail = 1 + ORDER BY reconnected_devices.eve_DateTime + """, + "events": """ + SELECT + devName, + eve_MAC, + devVendor, + devLastIP as eve_IP, + eve_DateTime, + eve_EventType, + devComments + FROM Events_Devices + WHERE eve_PendingAlertEmail = 1 + AND eve_EventType IN ('Connected', 'Down Reconnected', 'Disconnected','IP Changed') {condition} + ORDER BY eve_DateTime + """, + "plugins": """ + SELECT + Plugin, + Object_PrimaryId, + Object_SecondaryId, + DateTimeChanged, + Watched_Value1, + Watched_Value2, + Watched_Value3, + Watched_Value4, + Status + FROM Plugins_Events + """, +} + +# Sections that support user-defined condition filters +SECTIONS_WITH_CONDITIONS = {"new_devices", "events"} + +# Legacy setting key mapping for condition filters +SECTION_CONDITION_MAP = { + "new_devices": "NTFPRCS_new_dev_condition", + "events": "NTFPRCS_event_condition", +} diff --git a/server/messaging/reporting.py b/server/messaging/reporting.py index 21c0d19e..d222529d 100755 --- a/server/messaging/reporting.py +++ b/server/messaging/reporting.py @@ -25,20 +25,20 @@ from helper import ( # noqa: E402 [flake8 lint suppression] from logger import mylog # noqa: E402 [flake8 lint suppression] from db.sql_safe_builder import create_safe_condition_builder # noqa: E402 [flake8 lint suppression] from utils.datetime_utils import format_date_iso # noqa: E402 [flake8 lint suppression] +from messaging.notification_sections import ( # noqa: E402 [flake8 lint suppression] + SECTION_ORDER, + SECTION_TITLES, + DATETIME_FIELDS, + SQL_TEMPLATES, + SECTIONS_WITH_CONDITIONS, + SECTION_CONDITION_MAP, +) import conf # noqa: E402 [flake8 lint suppression] # =============================================================================== # Timezone conversion # =============================================================================== -DATETIME_FIELDS = { - "new_devices": ["Datetime"], - "down_devices": ["eve_DateTime"], - "down_reconnected": ["eve_DateTime"], - "events": ["Datetime"], - "plugins": ["DateTimeChanged"], -} - def get_datetime_fields_from_columns(column_names): return [ @@ -155,6 +155,7 @@ def get_notifications(db): return "" +<<<<<<< Updated upstream # ------------------------- # SQL templates # ------------------------- @@ -245,13 +246,17 @@ def get_notifications(db): # Sections that support dynamic conditions sections_with_conditions = {"new_devices", "events"} +======= + # SQL templates with placeholders for runtime values + # {condition} and {alert_down_minutes} are formatted at query time +>>>>>>> Stashed changes # Initialize final structure final_json = {} - for section in ["new_devices", "down_devices", "down_reconnected", "events", "plugins"]: + for section in SECTION_ORDER: final_json[section] = [] final_json[f"{section}_meta"] = { - "title": section_titles.get(section, section), + "title": SECTION_TITLES.get(section, section), "columnNames": [] } @@ -260,17 +265,8 @@ def get_notifications(db): # ------------------------- # Main loop # ------------------------- - condition_builder = create_safe_condition_builder() - - SECTION_CONDITION_MAP = { - "new_devices": "NTFPRCS_new_dev_condition", - "events": "NTFPRCS_event_condition", - } - - sections_with_conditions = set(SECTION_CONDITION_MAP.keys()) - for section in sections: - template = sql_templates.get(section) + template = SQL_TEMPLATES.get(section) if not template: mylog("verbose", ["[Notification] Unknown section: ", section]) @@ -280,7 +276,7 @@ def get_notifications(db): parameters = {} try: - if section in sections_with_conditions: + if section in SECTIONS_WITH_CONDITIONS: condition_key = SECTION_CONDITION_MAP.get(section) condition_setting = get_setting_value(condition_key) @@ -289,11 +285,18 @@ def get_notifications(db): condition_setting ) - sqlQuery = template.format(condition=safe_condition) + # Format template with runtime placeholders + format_vars = {"condition": safe_condition} + if section == "down_devices": + format_vars["alert_down_minutes"] = alert_down_minutes + sqlQuery = template.format(**format_vars) except Exception as e: mylog("verbose", [f"[Notification] Error building condition for {section}: ", e]) - sqlQuery = template.format(condition="") + fallback_vars = {"condition": ""} + if section == "down_devices": + fallback_vars["alert_down_minutes"] = alert_down_minutes + sqlQuery = template.format(**fallback_vars) parameters = {} mylog("debug", [f"[Notification] {section} SQL query: ", sqlQuery]) @@ -307,7 +310,7 @@ def get_notifications(db): final_json[section] = json_obj.json.get("data", []) final_json[f"{section}_meta"] = { - "title": section_titles.get(section, section), + "title": SECTION_TITLES.get(section, section), "columnNames": getattr(json_obj, "columnNames", []) } diff --git a/server/models/notification_instance.py b/server/models/notification_instance.py index e45f97d3..686685d2 100755 --- a/server/models/notification_instance.py +++ b/server/models/notification_instance.py @@ -16,6 +16,7 @@ from helper import ( getBuildTimeStampAndVersion, ) from messaging.in_app import write_notification +from messaging.notification_sections import SECTION_ORDER from utils.datetime_utils import timeNowUTC, timeNowTZ, get_timezone_offset @@ -60,12 +61,7 @@ class NotificationInstance: write_file(logPath + "/report_output.json", json.dumps(JSON)) # Check if nothing to report, end - if ( - JSON["new_devices"] == [] and JSON["down_devices"] == [] and JSON["events"] == [] and JSON["plugins"] == [] and JSON["down_reconnected"] == [] - ): - self.HasNotifications = False - else: - self.HasNotifications = True + self.HasNotifications = any(JSON.get(s, []) for s in SECTION_ORDER) self.GUID = str(uuid.uuid4()) self.DateTimeCreated = timeNowUTC() @@ -129,47 +125,13 @@ class NotificationInstance: mail_text = mail_text.replace("REPORT_DASHBOARD_URL", self.serverUrl) mail_html = mail_html.replace("REPORT_DASHBOARD_URL", self.serverUrl) - # Start generating the TEXT & HTML notification messages - # new_devices - # --- - html, text = construct_notifications(self.JSON, "new_devices") - - mail_text = mail_text.replace("NEW_DEVICES_TABLE", text + "\n") - mail_html = mail_html.replace("NEW_DEVICES_TABLE", html) - mylog("verbose", ["[Notification] New Devices sections done."]) - - # down_devices - # --- - html, text = construct_notifications(self.JSON, "down_devices") - - mail_text = mail_text.replace("DOWN_DEVICES_TABLE", text + "\n") - mail_html = mail_html.replace("DOWN_DEVICES_TABLE", html) - mylog("verbose", ["[Notification] Down Devices sections done."]) - - # down_reconnected - # --- - html, text = construct_notifications(self.JSON, "down_reconnected") - - mail_text = mail_text.replace("DOWN_RECONNECTED_TABLE", text + "\n") - mail_html = mail_html.replace("DOWN_RECONNECTED_TABLE", html) - mylog("verbose", ["[Notification] Reconnected Down Devices sections done."]) - - # events - # --- - html, text = construct_notifications(self.JSON, "events") - - mail_text = mail_text.replace("EVENTS_TABLE", text + "\n") - mail_html = mail_html.replace("EVENTS_TABLE", html) - mylog("verbose", ["[Notification] Events sections done."]) - - # plugins - # --- - html, text = construct_notifications(self.JSON, "plugins") - - mail_text = mail_text.replace("PLUGINS_TABLE", text + "\n") - mail_html = mail_html.replace("PLUGINS_TABLE", html) - - mylog("verbose", ["[Notification] Plugins sections done."]) + # Generate TEXT & HTML for each notification section + for section in SECTION_ORDER: + html, text = construct_notifications(self.JSON, section) + placeholder = f"{section.upper()}_TABLE" + mail_text = mail_text.replace(placeholder, text + "\n") + mail_html = mail_html.replace(placeholder, html) + mylog("verbose", [f"[Notification] {section} section done."]) final_text = removeDuplicateNewLines(mail_text) diff --git a/test/backend/test_notification_templates.py b/test/backend/test_notification_templates.py new file mode 100644 index 00000000..0653493d --- /dev/null +++ b/test/backend/test_notification_templates.py @@ -0,0 +1,299 @@ +""" +NetAlertX Notification Text Template Tests + +Tests the template substitution and section header toggle in +construct_notifications(). All tests mock get_setting_value to avoid +database/config dependencies. + +License: GNU GPLv3 +""" + +import sys +import os +import unittest +from unittest.mock import patch + +# Add the server directory to the path for imports +INSTALL_PATH = os.getenv("NETALERTX_APP", "/app") +sys.path.extend([f"{INSTALL_PATH}/server"]) + + +def _make_json(section, devices, column_names, title="Test Section"): + """Helper to build the JSON structure expected by construct_notifications.""" + return { + section: devices, + f"{section}_meta": { + "title": title, + "columnNames": column_names, + }, + } + + +SAMPLE_NEW_DEVICES = [ + { + "devName": "MyPhone", + "eve_MAC": "aa:bb:cc:dd:ee:ff", + "devVendor": "", + "eve_IP": "192.168.1.42", + "eve_DateTime": "2025-01-15 10:30:00", + "eve_EventType": "New Device", + "devComments": "", + }, + { + "devName": "Laptop", + "eve_MAC": "11:22:33:44:55:66", + "devVendor": "Dell", + "eve_IP": "192.168.1.99", + "eve_DateTime": "2025-01-15 11:00:00", + "eve_EventType": "New Device", + "devComments": "Office", + }, +] + +NEW_DEVICE_COLUMNS = ["devName", "eve_MAC", "devVendor", "eve_IP", "eve_DateTime", "eve_EventType", "devComments"] + + +class TestConstructNotificationsTemplates(unittest.TestCase): + """Tests for template substitution in construct_notifications.""" + + def _setting_factory(self, overrides=None): + """Return a mock get_setting_value that resolves from overrides dict.""" + settings = overrides or {} + + def mock_get(key): + return settings.get(key, "") + + return mock_get + + # ----------------------------------------------------------------- + # Empty section should always return ("", "") regardless of settings + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_empty_section_returns_empty(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.return_value = "" + json_data = _make_json("new_devices", [], []) + html, text = construct_notifications(json_data, "new_devices") + self.assertEqual(html, "") + self.assertEqual(text, "") + + # ----------------------------------------------------------------- + # Legacy fallback: no template → vertical Header: Value per device + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_legacy_fallback_no_template(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "", + }) + + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + html, text = construct_notifications(json_data, "new_devices") + + # Section header must be present + self.assertIn("🆕 New devices", text) + self.assertIn("---------", text) + + # Legacy format: each header appears as "Header: \tValue" + self.assertIn("eve_MAC:", text) + self.assertIn("aa:bb:cc:dd:ee:ff", text) + self.assertIn("devName:", text) + self.assertIn("MyPhone", text) + + # HTML must still be generated + self.assertNotEqual(html, "") + + # ----------------------------------------------------------------- + # Template substitution: single-line format per device + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_template_substitution(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eve_MAC}) - {eve_IP}", + }) + + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + _, text = construct_notifications(json_data, "new_devices") + + self.assertIn("MyPhone (aa:bb:cc:dd:ee:ff) - 192.168.1.42", text) + self.assertIn("Laptop (11:22:33:44:55:66) - 192.168.1.99", text) + + # ----------------------------------------------------------------- + # Missing field: {NonExistent} left as-is (safe failure) + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_missing_field_safe_failure(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} - {NonExistent}", + }) + + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + _, text = construct_notifications(json_data, "new_devices") + + self.assertIn("MyPhone - {NonExistent}", text) + self.assertIn("Laptop - {NonExistent}", text) + + # ----------------------------------------------------------------- + # Section headers disabled: no title/separator in text output + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_section_headers_disabled(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": False, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eve_MAC})", + }) + + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + _, text = construct_notifications(json_data, "new_devices") + + self.assertNotIn("🆕 New devices", text) + self.assertNotIn("---------", text) + # Template output still present + self.assertIn("MyPhone (aa:bb:cc:dd:ee:ff)", text) + + # ----------------------------------------------------------------- + # Section headers enabled (default when setting absent/empty) + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_section_headers_default_enabled(self, mock_setting): + from models.notification_instance import construct_notifications + + # Simulate setting not configured (returns empty string) + mock_setting.side_effect = self._setting_factory({}) + + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + _, text = construct_notifications(json_data, "new_devices") + + # Headers should be shown by default + self.assertIn("🆕 New devices", text) + self.assertIn("---------", text) + + # ----------------------------------------------------------------- + # Mixed valid and invalid fields in same template + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_mixed_valid_and_invalid_fields(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({BadField}) - {eve_IP}", + }) + + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + _, text = construct_notifications(json_data, "new_devices") + + self.assertIn("MyPhone ({BadField}) - 192.168.1.42", text) + + # ----------------------------------------------------------------- + # Down devices section uses same column names as all other sections + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_down_devices_template(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_down_devices": "{devName} ({eve_MAC}) down since {eve_DateTime}", + }) + + down_devices = [ + { + "devName": "Router", + "eve_MAC": "ff:ee:dd:cc:bb:aa", + "devVendor": "Cisco", + "eve_IP": "10.0.0.1", + "eve_DateTime": "2025-01-15 08:00:00", + "eve_EventType": "Device Down", + "devComments": "", + } + ] + columns = ["devName", "eve_MAC", "devVendor", "eve_IP", "eve_DateTime", "eve_EventType", "devComments"] + + json_data = _make_json("down_devices", down_devices, columns, "🔴 Down devices") + _, text = construct_notifications(json_data, "down_devices") + + self.assertIn("Router (ff:ee:dd:cc:bb:aa) down since 2025-01-15 08:00:00", text) + + # ----------------------------------------------------------------- + # Down reconnected section uses same unified column names + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_down_reconnected_template(self, mock_setting): + from models.notification_instance import construct_notifications + + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_down_reconnected": "{devName} ({eve_MAC}) reconnected at {eve_DateTime}", + }) + + reconnected = [ + { + "devName": "Switch", + "eve_MAC": "aa:11:bb:22:cc:33", + "devVendor": "Netgear", + "eve_IP": "10.0.0.2", + "eve_DateTime": "2025-01-15 09:30:00", + "eve_EventType": "Down Reconnected", + "devComments": "", + } + ] + columns = ["devName", "eve_MAC", "devVendor", "eve_IP", "eve_DateTime", "eve_EventType", "devComments"] + + json_data = _make_json("down_reconnected", reconnected, columns, "🔁 Reconnected down devices") + _, text = construct_notifications(json_data, "down_reconnected") + + self.assertIn("Switch (aa:11:bb:22:cc:33) reconnected at 2025-01-15 09:30:00", text) + + # ----------------------------------------------------------------- + # HTML output is unchanged regardless of template config + # ----------------------------------------------------------------- + @patch("models.notification_instance.get_setting_value") + def test_html_unchanged_with_template(self, mock_setting): + from models.notification_instance import construct_notifications + + # Get HTML without template + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "", + }) + json_data = _make_json( + "new_devices", SAMPLE_NEW_DEVICES, NEW_DEVICE_COLUMNS, "🆕 New devices" + ) + html_without, _ = construct_notifications(json_data, "new_devices") + + # Get HTML with template + mock_setting.side_effect = self._setting_factory({ + "NTFPRCS_TEXT_SECTION_HEADERS": True, + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eve_MAC})", + }) + html_with, _ = construct_notifications(json_data, "new_devices") + + self.assertEqual(html_without, html_with) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/integration/integration_test.py b/test/integration/integration_test.py index 200e0f49..b4e28f06 100755 --- a/test/integration/integration_test.py +++ b/test/integration/integration_test.py @@ -42,8 +42,10 @@ def test_db(test_db_path): eve_MAC TEXT, eve_DateTime TEXT, devLastIP TEXT, + eve_IP TEXT, eve_EventType TEXT, devName TEXT, + devVendor TEXT, devComments TEXT, eve_PendingAlertEmail INTEGER ) @@ -84,13 +86,13 @@ def test_db(test_db_path): # Insert test data test_data = [ - ('aa:bb:cc:dd:ee:ff', '2024-01-01 12:00:00', '192.168.1.100', 'New Device', 'Test Device', 'Test Comment', 1), - ('11:22:33:44:55:66', '2024-01-01 12:01:00', '192.168.1.101', 'Connected', 'Test Device 2', 'Another Comment', 1), - ('77:88:99:aa:bb:cc', '2024-01-01 12:02:00', '192.168.1.102', 'Disconnected', 'Test Device 3', 'Third Comment', 1), + ('aa:bb:cc:dd:ee:ff', '2024-01-01 12:00:00', '192.168.1.100', '192.168.1.100', 'New Device', 'Test Device', 'Apple', 'Test Comment', 1), + ('11:22:33:44:55:66', '2024-01-01 12:01:00', '192.168.1.101', '192.168.1.101', 'Connected', 'Test Device 2', 'Dell', 'Another Comment', 1), + ('77:88:99:aa:bb:cc', '2024-01-01 12:02:00', '192.168.1.102', '192.168.1.102', 'Disconnected', 'Test Device 3', 'Cisco', 'Third Comment', 1), ] cur.executemany(''' - INSERT INTO Events_Devices (eve_MAC, eve_DateTime, devLastIP, eve_EventType, devName, devComments, eve_PendingAlertEmail) - VALUES (?, ?, ?, ?, ?, ?, ?) + INSERT INTO Events_Devices (eve_MAC, eve_DateTime, devLastIP, eve_IP, eve_EventType, devName, devVendor, devComments, eve_PendingAlertEmail) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ''', test_data) conn.commit() @@ -115,7 +117,7 @@ def test_fresh_install_compatibility(builder): def test_existing_db_compatibility(): mock_db = Mock() mock_result = Mock() - mock_result.columnNames = ['MAC', 'Datetime', 'IP', 'Event Type', 'Device name', 'Comments'] + mock_result.columnNames = ['devName', 'eve_MAC', 'devVendor', 'eve_IP', 'eve_DateTime', 'eve_EventType', 'devComments'] mock_result.json = {'data': []} mock_db.get_table_as_json.return_value = mock_result From c7399215ecd76126156b4c35f7e16262bdea5598 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Mon, 16 Mar 2026 10:11:22 +0000 Subject: [PATCH 2/9] Refactor event and session column names to camelCase - Updated test cases to reflect new column names (eve_MAC -> eveMac, eve_DateTime -> eveDateTime, etc.) across various test files. - Modified SQL table definitions in the database cleanup and migration tests to use camelCase naming conventions. - Implemented migration tests to ensure legacy column names are correctly renamed to camelCase equivalents. - Ensured that existing data is preserved during the migration process and that views referencing old column names are dropped before renaming. - Verified that the migration function is idempotent, allowing for safe re-execution without data loss. --- .github/skills/code-standards/SKILL.md | 1 + docs/API_EVENTS.md | 36 +- docs/API_SESSIONS.md | 24 +- docs/DEBUG_PLUGINS.md | 4 +- docs/NOTIFICATIONS.md | 2 +- docs/NOTIFICATION_TEMPLATES.md | 48 +- docs/PLUGINS_DEV.md | 18 +- docs/PLUGINS_DEV_CONFIG.md | 8 +- docs/PLUGINS_DEV_DATASOURCES.md | 16 +- docs/PLUGINS_DEV_DATA_CONTRACT.md | 62 +-- docs/PLUGINS_DEV_QUICK_START.md | 12 +- docs/PLUGINS_DEV_UI_COMPONENTS.md | 44 +- front/appEventsCore.php | 40 +- front/deviceDetailsEvents.php | 18 +- front/deviceDetailsSessions.php | 12 +- front/js/app-init.js | 2 +- front/js/cache.js | 6 +- front/multiEditCore.php | 1 + front/php/components/graph_online_history.php | 10 +- front/php/templates/language/lang.php | 2 +- front/plugins/__template/config.json | 22 +- front/plugins/__template/rename_me.py | 2 +- front/plugins/_publisher_apprise/config.json | 26 +- front/plugins/_publisher_email/config.json | 26 +- front/plugins/_publisher_mqtt/config.json | 28 +- front/plugins/_publisher_mqtt/mqtt.py | 4 +- front/plugins/_publisher_ntfy/config.json | 22 +- front/plugins/_publisher_pushover/config.json | 22 +- .../plugins/_publisher_pushsafer/config.json | 22 +- front/plugins/_publisher_telegram/config.json | 26 +- front/plugins/_publisher_webhook/config.json | 22 +- front/plugins/adguard_import/config.json | 22 +- front/plugins/arp_scan/config.json | 32 +- front/plugins/asuswrt_import/config.json | 18 +- front/plugins/avahi_scan/config.json | 18 +- front/plugins/db_cleanup/script.py | 24 +- front/plugins/ddns_update/config.json | 36 +- front/plugins/dhcp_leases/ASUS_ROUTERS.md | 6 +- front/plugins/dhcp_leases/config.json | 50 +- front/plugins/dhcp_servers/config.json | 44 +- front/plugins/dig_scan/config.json | 18 +- front/plugins/freebox/config.json | 22 +- front/plugins/icmp_scan/config.json | 22 +- front/plugins/internet_ip/config.json | 42 +- front/plugins/internet_speedtest/README.md | 8 +- front/plugins/internet_speedtest/config.json | 46 +- front/plugins/ipneigh/config.json | 22 +- front/plugins/luci_import/config.json | 18 +- front/plugins/mikrotik_scan/config.json | 20 +- front/plugins/nbtscan_scan/config.json | 18 +- front/plugins/nmap_dev_scan/config.json | 34 +- front/plugins/nmap_scan/config.json | 44 +- .../plugins/notification_processing/README.md | 4 +- .../notification_processing/config.json | 10 +- front/plugins/nslookup_scan/config.json | 18 +- front/plugins/omada_sdn_imp/config.json | 36 +- front/plugins/omada_sdn_imp/omada_sdn.py | 2 +- front/plugins/omada_sdn_openapi/config.json | 40 +- front/plugins/pihole_api_scan/config.json | 22 +- front/plugins/pihole_scan/config.json | 36 +- front/plugins/snmp_discovery/config.json | 44 +- front/plugins/sync/config.json | 22 +- front/plugins/unifi_api_import/config.json | 22 +- front/plugins/unifi_import/config.json | 50 +- front/plugins/vendor_update/config.json | 46 +- front/plugins/wake_on_lan/config.json | 22 +- front/plugins/website_monitor/config.json | 44 +- front/pluginsCore.php | 16 +- front/report.php | 18 +- .../report_templates/webhook_json_sample.json | 60 +-- scripts/db_cleanup/db_cleanup.py | 32 +- server/api_server/graphql_endpoint.py | 70 +-- server/api_server/sessions_endpoint.py | 196 +++---- server/const.py | 28 +- server/database.py | 5 + server/db/db_upgrade.py | 446 +++++++++++----- server/db/schema/app.sql | 494 ++++++------------ server/db/sql_safe_builder.py | 30 +- server/initialise.py | 82 ++- server/messaging/notification_sections.py | 92 ++-- server/messaging/reporting.py | 22 +- server/models/device_instance.py | 42 +- server/models/event_instance.py | 60 +-- server/models/notification_instance.py | 50 +- server/models/plugin_object_instance.py | 20 +- server/plugin.py | 204 ++++---- server/scan/device_handling.py | 18 +- server/scan/name_resolution.py | 8 +- server/scan/session_events.py | 66 +-- server/utils/plugin_utils.py | 2 +- server/workflows/actions.py | 8 +- server/workflows/app_events.py | 132 ++--- server/workflows/manager.py | 12 +- server/workflows/triggers.py | 6 +- test/api_endpoints/test_events_endpoints.py | 10 +- .../api_endpoints/test_mcp_tools_endpoints.py | 6 +- test/api_endpoints/test_sessions_endpoints.py | 6 +- test/backend/sql_safe_builder.py | 30 +- test/backend/test_compound_conditions.py | 2 +- test/backend/test_notification_templates.py | 38 +- test/backend/test_safe_builder_unit.py | 2 +- test/backend/test_sql_injection_prevention.py | 4 +- test/backend/test_sql_security.py | 14 +- test/db/test_camelcase_migration.py | 307 +++++++++++ test/db/test_db_cleanup.py | 52 +- test/db_test_helpers.py | 20 +- test/integration/integration_test.py | 56 +- test/scan/test_down_sleep_events.py | 6 +- test/scan/test_field_lock_scan_integration.py | 28 +- 109 files changed, 2403 insertions(+), 1967 deletions(-) create mode 100644 test/db/test_camelcase_migration.py diff --git a/.github/skills/code-standards/SKILL.md b/.github/skills/code-standards/SKILL.md index 98c7516b..00128188 100644 --- a/.github/skills/code-standards/SKILL.md +++ b/.github/skills/code-standards/SKILL.md @@ -12,6 +12,7 @@ description: NetAlertX coding standards and conventions. Use this when writing c - code has to be maintainable, no duplicate code - follow DRY principle - maintainability of code is more important than speed of implementation - code files should be less than 500 LOC for better maintainability +- DB columns must not contain underscores, use camelCase instead (e.g., deviceInstanceId, not device_instance_id) ## File Length diff --git a/docs/API_EVENTS.md b/docs/API_EVENTS.md index ff423c4f..d933658b 100755 --- a/docs/API_EVENTS.md +++ b/docs/API_EVENTS.md @@ -58,12 +58,12 @@ The Events API provides access to **device event logs**, allowing creation, retr "success": true, "events": [ { - "eve_MAC": "00:11:22:33:44:55", - "eve_IP": "192.168.1.10", - "eve_DateTime": "2025-08-24T12:00:00Z", - "eve_EventType": "Device Down", - "eve_AdditionalInfo": "", - "eve_PendingAlertEmail": 1 + "eveMac": "00:11:22:33:44:55", + "eveIp": "192.168.1.10", + "eveDateTime": "2025-08-24T12:00:00Z", + "eveEventType": "Device Down", + "eveAdditionalInfo": "", + "evePendingAlertEmail": 1 } ] } @@ -102,11 +102,11 @@ The Events API provides access to **device event logs**, allowing creation, retr "count": 5, "events": [ { - "eve_DateTime": "2025-12-07 12:00:00", - "eve_EventType": "New Device", - "eve_MAC": "AA:BB:CC:DD:EE:FF", - "eve_IP": "192.168.1.100", - "eve_AdditionalInfo": "Device detected" + "eveDateTime": "2025-12-07 12:00:00", + "eveEventType": "New Device", + "eveMac": "AA:BB:CC:DD:EE:FF", + "eveIp": "192.168.1.100", + "eveAdditionalInfo": "Device detected" } ] } @@ -127,9 +127,9 @@ The Events API provides access to **device event logs**, allowing creation, retr "count": 10, "events": [ { - "eve_DateTime": "2025-12-07 12:00:00", - "eve_EventType": "Device Down", - "eve_MAC": "AA:BB:CC:DD:EE:FF" + "eveDateTime": "2025-12-07 12:00:00", + "eveEventType": "Device Down", + "eveMac": "AA:BB:CC:DD:EE:FF" } ] } @@ -159,9 +159,9 @@ The Events API provides access to **device event logs**, allowing creation, retr 1. Total events in the period 2. Total sessions 3. Missing sessions -4. Voided events (`eve_EventType LIKE 'VOIDED%'`) -5. New device events (`eve_EventType LIKE 'New Device'`) -6. Device down events (`eve_EventType LIKE 'Device Down'`) +4. Voided events (`eveEventType LIKE 'VOIDED%'`) +5. New device events (`eveEventType LIKE 'New Device'`) +6. Device down events (`eveEventType LIKE 'Device Down'`) --- @@ -187,7 +187,7 @@ Event endpoints are available as **MCP Tools** for AI assistant integration: ``` * Events are stored in the **Events table** with the following fields: - `eve_MAC`, `eve_IP`, `eve_DateTime`, `eve_EventType`, `eve_AdditionalInfo`, `eve_PendingAlertEmail`. + `eveMac`, `eveIp`, `eveDateTime`, `eveEventType`, `eveAdditionalInfo`, `evePendingAlertEmail`. * Event creation automatically logs activity for debugging. diff --git a/docs/API_SESSIONS.md b/docs/API_SESSIONS.md index 94224aa4..d5d19eed 100755 --- a/docs/API_SESSIONS.md +++ b/docs/API_SESSIONS.md @@ -106,12 +106,12 @@ curl -X DELETE "http://:/sessions/delete" \ "success": true, "sessions": [ { - "ses_MAC": "AA:BB:CC:DD:EE:FF", - "ses_Connection": "2025-08-01 10:00", - "ses_Disconnection": "2025-08-01 12:00", - "ses_Duration": "2h 0m", - "ses_IP": "192.168.1.10", - "ses_Info": "" + "sesMac": "AA:BB:CC:DD:EE:FF", + "sesDateTimeConnection": "2025-08-01 10:00", + "sesDateTimeDisconnection": "2025-08-01 12:00", + "sesDuration": "2h 0m", + "sesIp": "192.168.1.10", + "sesAdditionalInfo": "" } ] } @@ -194,12 +194,12 @@ curl -X GET "http://:/sessions/calendar?start=2025-08-0 "success": true, "sessions": [ { - "ses_MAC": "AA:BB:CC:DD:EE:FF", - "ses_Connection": "2025-08-01 10:00", - "ses_Disconnection": "2025-08-01 12:00", - "ses_Duration": "2h 0m", - "ses_IP": "192.168.1.10", - "ses_Info": "" + "sesMac": "AA:BB:CC:DD:EE:FF", + "sesDateTimeConnection": "2025-08-01 10:00", + "sesDateTimeDisconnection": "2025-08-01 12:00", + "sesDuration": "2h 0m", + "sesIp": "192.168.1.10", + "sesAdditionalInfo": "" } ] } diff --git a/docs/DEBUG_PLUGINS.md b/docs/DEBUG_PLUGINS.md index 947eee0d..f84e752d 100755 --- a/docs/DEBUG_PLUGINS.md +++ b/docs/DEBUG_PLUGINS.md @@ -43,7 +43,7 @@ Input data from the plugin might cause mapping issues in specific edge cases. Lo 17:31:05 [Scheduler] run for PIHOLE: YES 17:31:05 [Plugin utils] --------------------------------------------- 17:31:05 [Plugin utils] display_name: PiHole (Device sync) -17:31:05 [Plugins] CMD: SELECT n.hwaddr AS Object_PrimaryID, {s-quote}null{s-quote} AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr is not {s-quote}00:00:00:00:00:00{s-quote} AND na.ip is not null +17:31:05 [Plugins] CMD: SELECT n.hwaddr AS objectPrimaryId, {s-quote}null{s-quote} AS objectSecondaryId, datetime() AS DateTime, na.ip AS watchedValue1, n.lastQuery AS watchedValue2, na.name AS watchedValue3, n.macVendor AS watchedValue4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr is not {s-quote}00:00:00:00:00:00{s-quote} AND na.ip is not null 17:31:05 [Plugins] setTyp: subnets 17:31:05 [Plugin utils] Flattening the below array 17:31:05 ['192.168.1.0/24 --interface=eth1'] @@ -52,7 +52,7 @@ Input data from the plugin might cause mapping issues in specific edge cases. Lo 17:31:05 [Plugins] Convert to Base64: True 17:31:05 [Plugins] base64 value: b'MTkyLjE2OC4xLjAvMjQgLS1pbnRlcmZhY2U9ZXRoMQ==' 17:31:05 [Plugins] Timeout: 10 -17:31:05 [Plugins] Executing: SELECT n.hwaddr AS Object_PrimaryID, 'null' AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, 'null' AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE 'ip-%' AND n.hwaddr is not '00:00:00:00:00:00' AND na.ip is not null +17:31:05 [Plugins] Executing: SELECT n.hwaddr AS objectPrimaryId, 'null' AS objectSecondaryId, datetime() AS DateTime, na.ip AS watchedValue1, n.lastQuery AS watchedValue2, na.name AS watchedValue3, n.macVendor AS watchedValue4, 'null' AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE 'ip-%' AND n.hwaddr is not '00:00:00:00:00:00' AND na.ip is not null 🔻 17:31:05 [Plugins] SUCCESS, received 2 entries 17:31:05 [Plugins] sqlParam entries: [(0, 'PIHOLE', '01:01:01:01:01:01', 'null', 'null', '2023-12-25 06:31:05', '172.30.0.1', 0, 'aaaa', 'vvvvvvvvv', 'not-processed', 'null', 'null', '01:01:01:01:01:01'), (0, 'PIHOLE', '02:42:ac:1e:00:02', 'null', 'null', '2023-12-25 06:31:05', '172.30.0.2', 0, 'dddd', 'vvvvv2222', 'not-processed', 'null', 'null', '02:42:ac:1e:00:02')] diff --git a/docs/NOTIFICATIONS.md b/docs/NOTIFICATIONS.md index 3bd12d5a..eb29b1a2 100755 --- a/docs/NOTIFICATIONS.md +++ b/docs/NOTIFICATIONS.md @@ -36,7 +36,7 @@ The following device properties influence notifications. You can: On almost all plugins there are 2 core settings, `_WATCH` and `_REPORT_ON`. 1. `_WATCH` specifies the columns which the app should watch. If watched columns change the device state is considered changed. This changed status is then used to decide to send out notifications based on the `_REPORT_ON` setting. -2. `_REPORT_ON` let's you specify on which events the app should notify you. This is related to the `_WATCH` setting. So if you select `watched-changed` and in `_WATCH` you only select `Watched_Value1`, then a notification is triggered if `Watched_Value1` is changed from the previous value, but no notification is send if `Watched_Value2` changes. +2. `_REPORT_ON` let's you specify on which events the app should notify you. This is related to the `_WATCH` setting. So if you select `watched-changed` and in `_WATCH` you only select `watchedValue1`, then a notification is triggered if `watchedValue1` is changed from the previous value, but no notification is send if `watchedValue2` changes. Click the **Read more in the docs.** Link at the top of each plugin to get more details on how the given plugin works. diff --git a/docs/NOTIFICATION_TEMPLATES.md b/docs/NOTIFICATION_TEMPLATES.md index 2956bd32..63828703 100644 --- a/docs/NOTIFICATION_TEMPLATES.md +++ b/docs/NOTIFICATION_TEMPLATES.md @@ -10,7 +10,7 @@ HTML email tables are **not affected** by these templates. 1. Go to **Settings → Notification Processing**. 2. Set a template string for the section you want to customize, e.g.: - - **Text Template: New Devices** → `{devName} ({eve_MAC}) - {eve_IP}` + - **Text Template: New Devices** → `{devName} ({eveMac}) - {eveIp}` 3. Save. The next notification will use your format. **Before (default):** @@ -18,15 +18,15 @@ HTML email tables are **not affected** by these templates. 🆕 New devices --------- devName: MyPhone -eve_MAC: aa:bb:cc:dd:ee:ff +eveMac: aa:bb:cc:dd:ee:ff devVendor: Apple -eve_IP: 192.168.1.42 -eve_DateTime: 2025-01-15 10:30:00 -eve_EventType: New Device +eveIp: 192.168.1.42 +eveDateTime: 2025-01-15 10:30:00 +eveEventType: New Device devComments: ``` -**After (with template `{devName} ({eve_MAC}) - {eve_IP}`):** +**After (with template `{devName} ({eveMac}) - {eveIp}`):** ``` 🆕 New devices --------- @@ -51,7 +51,7 @@ When a template is **empty**, the section uses the original vertical `Header: Va Use `{FieldName}` to insert a value from the notification data. Field names are **case-sensitive** and must match the column names exactly. ``` -{devName} ({eve_MAC}) connected at {eve_DateTime} +{devName} ({eveMac}) connected at {eveDateTime} ``` - No loops, conditionals, or nesting — just simple string replacement. @@ -66,34 +66,34 @@ All four device sections (`new_devices`, `down_devices`, `down_reconnected`, `ev | Variable | Description | |----------|-------------| | `{devName}` | Device display name | -| `{eve_MAC}` | Device MAC address | +| `{eveMac}` | Device MAC address | | `{devVendor}` | Device vendor/manufacturer | -| `{eve_IP}` | Device IP address | -| `{eve_DateTime}` | Event timestamp | -| `{eve_EventType}` | Type of event (e.g. `New Device`, `Connected`, `Device Down`) | +| `{eveIp}` | Device IP address | +| `{eveDateTime}` | Event timestamp | +| `{eveEventType}` | Type of event (e.g. `New Device`, `Connected`, `Device Down`) | | `{devComments}` | Device comments | -**Example (new_devices/events):** `{devName} ({eve_MAC}) - {eve_IP} [{eve_EventType}]` +**Example (new_devices/events):** `{devName} ({eveMac}) - {eveIp} [{eveEventType}]` -**Example (down_devices):** `{devName} ({eve_MAC}) {devVendor} - went down at {eve_DateTime}` +**Example (down_devices):** `{devName} ({eveMac}) {devVendor} - went down at {eveDateTime}` -**Example (down_reconnected):** `{devName} ({eve_MAC}) reconnected at {eve_DateTime}` +**Example (down_reconnected):** `{devName} ({eveMac}) reconnected at {eveDateTime}` ### `plugins` | Variable | Description | |----------|-------------| -| `{Plugin}` | Plugin code name | -| `{Object_PrimaryId}` | Primary identifier of the object | -| `{Object_SecondaryId}` | Secondary identifier | -| `{DateTimeChanged}` | Timestamp of change | -| `{Watched_Value1}` | First watched value | -| `{Watched_Value2}` | Second watched value | -| `{Watched_Value3}` | Third watched value | -| `{Watched_Value4}` | Fourth watched value | -| `{Status}` | Plugin event status | +| `{plugin}` | Plugin code name | +| `{objectPrimaryId}` | Primary identifier of the object | +| `{objectSecondaryId}` | Secondary identifier | +| `{dateTimeChanged}` | Timestamp of change | +| `{watchedValue1}` | First watched value | +| `{watchedValue2}` | Second watched value | +| `{watchedValue3}` | Third watched value | +| `{watchedValue4}` | Fourth watched value | +| `{status}` | Plugin event status | -**Example:** `{Plugin}: {Object_PrimaryId} - {Status}` +**Example:** `{plugin}: {objectPrimaryId} - {status}` ## Section Headers Toggle diff --git a/docs/PLUGINS_DEV.md b/docs/PLUGINS_DEV.md index 1bfaf854..04780588 100755 --- a/docs/PLUGINS_DEV.md +++ b/docs/PLUGINS_DEV.md @@ -179,13 +179,13 @@ Quick reference: | Column | Name | Required | Example | |--------|------|----------|---------| -| 0 | Object_PrimaryID | **YES** | `"device_name"` or `"192.168.1.1"` | -| 1 | Object_SecondaryID | no | `"secondary_id"` or `null` | +| 0 | objectPrimaryId | **YES** | `"device_name"` or `"192.168.1.1"` | +| 1 | objectSecondaryId | no | `"secondary_id"` or `null` | | 2 | DateTime | **YES** | `"2023-01-02 15:56:30"` | -| 3 | Watched_Value1 | **YES** | `"online"` or `"200"` | -| 4 | Watched_Value2 | no | `"ip_address"` or `null` | -| 5 | Watched_Value3 | no | `null` | -| 6 | Watched_Value4 | no | `null` | +| 3 | watchedValue1 | **YES** | `"online"` or `"200"` | +| 4 | watchedValue2 | no | `"ip_address"` or `null` | +| 5 | watchedValue3 | no | `null` | +| 6 | watchedValue4 | no | `null` | | 7 | Extra | no | `"additional data"` or `null` | | 8 | ForeignKey | no | `"aa:bb:cc:dd:ee:ff"` or `null` | @@ -243,7 +243,7 @@ Control which rows display in the UI: { "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -267,7 +267,7 @@ To import plugin data into NetAlertX tables for device discovery or notification "mapped_to_table": "CurrentScan", "database_column_definitions": [ { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "show": true, "type": "device_mac", @@ -345,7 +345,7 @@ See [PLUGINS_DEV_SETTINGS.md](PLUGINS_DEV_SETTINGS.md) for complete settings doc ### Plugin Output Format ``` -Object_PrimaryID|Object_SecondaryID|DateTime|Watched_Value1|Watched_Value2|Watched_Value3|Watched_Value4|Extra|ForeignKey +objectPrimaryId|objectSecondaryId|DateTime|watchedValue1|watchedValue2|watchedValue3|watchedValue4|Extra|ForeignKey ``` 9 required columns, 4 optional helpers = 13 max diff --git a/docs/PLUGINS_DEV_CONFIG.md b/docs/PLUGINS_DEV_CONFIG.md index bdc7efcc..69e95bdb 100755 --- a/docs/PLUGINS_DEV_CONFIG.md +++ b/docs/PLUGINS_DEV_CONFIG.md @@ -77,7 +77,7 @@ It also describes plugin output expectations and the main plugin categories. * `database_column_definitions` * `mapped_to_table` -**Example:** `Object_PrimaryID → devMAC` +**Example:** `objectPrimaryId → devMAC` --- @@ -88,9 +88,9 @@ Output values are pipe-delimited in a fixed order. #### Identifiers -* `Object_PrimaryID` and `Object_SecondaryID` uniquely identify records (for example, `MAC|IP`). +* `objectPrimaryId` and `objectSecondaryId` uniquely identify records (for example, `MAC|IP`). -#### Watched Values (`Watched_Value1–4`) +#### Watched Values (`watchedValue1–4`) * Used by the core to detect changes between runs. * Changes in these fields can trigger notifications. @@ -114,7 +114,7 @@ Output values are pipe-delimited in a fixed order. ### 7. Persistence * Parsed data is **upserted** into the database. -* Conflicts are resolved using the combined key: `Object_PrimaryID + Object_SecondaryID`. +* Conflicts are resolved using the combined key: `objectPrimaryId + objectSecondaryId`. --- diff --git a/docs/PLUGINS_DEV_DATASOURCES.md b/docs/PLUGINS_DEV_DATASOURCES.md index f6d547cd..cc3b7700 100644 --- a/docs/PLUGINS_DEV_DATASOURCES.md +++ b/docs/PLUGINS_DEV_DATASOURCES.md @@ -107,7 +107,7 @@ Query the NetAlertX SQLite database and display results. { "function": "CMD", "type": {"dataType": "string", "elements": [{"elementType": "input", "elementOptions": [], "transformers": []}]}, - "default_value": "SELECT dv.devName as Object_PrimaryID, cast(dv.devLastIP as VARCHAR(100)) || ':' || cast(SUBSTR(ns.Port, 0, INSTR(ns.Port, '/')) as VARCHAR(100)) as Object_SecondaryID, datetime() as DateTime, ns.Service as Watched_Value1, ns.State as Watched_Value2, null as Watched_Value3, null as Watched_Value4, ns.Extra as Extra, dv.devMac as ForeignKey FROM (SELECT * FROM Nmap_Scan) ns LEFT JOIN (SELECT devName, devMac, devLastIP FROM Devices) dv ON ns.MAC = dv.devMac", + "default_value": "SELECT dv.devName as objectPrimaryId, cast(dv.devLastIP as VARCHAR(100)) || ':' || cast(SUBSTR(ns.Port, 0, INSTR(ns.Port, '/')) as VARCHAR(100)) as objectSecondaryId, datetime() as DateTime, ns.Service as watchedValue1, ns.State as watchedValue2, null as watchedValue3, null as watchedValue4, ns.Extra as Extra, dv.devMac as ForeignKey FROM (SELECT * FROM Nmap_Scan) ns LEFT JOIN (SELECT devName, devMac, devLastIP FROM Devices) dv ON ns.MAC = dv.devMac", "localized": ["name"], "name": [{"language_code": "en_us", "string": "SQL to run"}], "description": [{"language_code": "en_us", "string": "This SQL query populates the plugin table"}] @@ -118,13 +118,13 @@ Query the NetAlertX SQLite database and display results. ```sql SELECT - e.EventValue as Object_PrimaryID, - d.devName as Object_SecondaryID, + e.EventValue as objectPrimaryId, + d.devName as objectSecondaryId, e.EventDateTime as DateTime, - e.EventType as Watched_Value1, - d.devLastIP as Watched_Value2, - null as Watched_Value3, - null as Watched_Value4, + e.EventType as watchedValue1, + d.devLastIP as watchedValue2, + null as watchedValue3, + null as watchedValue4, e.EventDetails as Extra, d.devMac as ForeignKey FROM @@ -181,7 +181,7 @@ Then set data source and query: ```json { "function": "CMD", - "default_value": "SELECT hwaddr as Object_PrimaryID, cast('http://' || (SELECT ip FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1) as VARCHAR(100)) || ':' || cast(SUBSTR((SELECT name FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1), 0, INSTR((SELECT name FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1), '/')) as VARCHAR(100)) as Object_SecondaryID, datetime() as DateTime, macVendor as Watched_Value1, lastQuery as Watched_Value2, (SELECT name FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1) as Watched_Value3, null as Watched_Value4, '' as Extra, hwaddr as ForeignKey FROM EXTERNAL_PIHOLE.network WHERE hwaddr NOT LIKE 'ip-%' AND hwaddr <> '00:00:00:00:00:00'", + "default_value": "SELECT hwaddr as objectPrimaryId, cast('http://' || (SELECT ip FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1) as VARCHAR(100)) || ':' || cast(SUBSTR((SELECT name FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1), 0, INSTR((SELECT name FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1), '/')) as VARCHAR(100)) as objectSecondaryId, datetime() as DateTime, macVendor as watchedValue1, lastQuery as watchedValue2, (SELECT name FROM EXTERNAL_PIHOLE.network_addresses WHERE network_id = id ORDER BY lastseen DESC LIMIT 1) as watchedValue3, null as watchedValue4, '' as Extra, hwaddr as ForeignKey FROM EXTERNAL_PIHOLE.network WHERE hwaddr NOT LIKE 'ip-%' AND hwaddr <> '00:00:00:00:00:00'", "localized": ["name"], "name": [{"language_code": "en_us", "string": "SQL to run"}] } diff --git a/docs/PLUGINS_DEV_DATA_CONTRACT.md b/docs/PLUGINS_DEV_DATA_CONTRACT.md index f0c5390b..e0a0a469 100644 --- a/docs/PLUGINS_DEV_DATA_CONTRACT.md +++ b/docs/PLUGINS_DEV_DATA_CONTRACT.md @@ -18,19 +18,19 @@ Plugins communicate with NetAlertX by writing results to a **pipe-delimited log ## Column Specification > [!NOTE] -> The order of columns is **FIXED** and cannot be changed. All 9 mandatory columns must be provided. If you use any optional column (`HelpVal1`), you must supply all optional columns (`HelpVal1` through `HelpVal4`). +> The order of columns is **FIXED** and cannot be changed. All 9 mandatory columns must be provided. If you use any optional column (`helpVal1`), you must supply all optional columns (`helpVal1` through `helpVal4`). ### Mandatory Columns (0–8) | Order | Column Name | Type | Required | Description | |-------|-------------|------|----------|-------------| -| 0 | `Object_PrimaryID` | string | **YES** | The primary identifier for grouping. Examples: device MAC, hostname, service name, or any unique ID | -| 1 | `Object_SecondaryID` | string | no | Secondary identifier for relationships (e.g., IP address, port, sub-ID). Use `null` if not needed | +| 0 | `objectPrimaryId` | string | **YES** | The primary identifier for grouping. Examples: device MAC, hostname, service name, or any unique ID | +| 1 | `objectSecondaryId` | string | no | Secondary identifier for relationships (e.g., IP address, port, sub-ID). Use `null` if not needed | | 2 | `DateTime` | string | **YES** | Timestamp when the event/data was collected. Format: `YYYY-MM-DD HH:MM:SS` | -| 3 | `Watched_Value1` | string | **YES** | Primary watched value. Changes trigger notifications. Examples: IP address, status, version | -| 4 | `Watched_Value2` | string | no | Secondary watched value. Use `null` if not needed | -| 5 | `Watched_Value3` | string | no | Tertiary watched value. Use `null` if not needed | -| 6 | `Watched_Value4` | string | no | Quaternary watched value. Use `null` if not needed | +| 3 | `watchedValue1` | string | **YES** | Primary watched value. Changes trigger notifications. Examples: IP address, status, version | +| 4 | `watchedValue2` | string | no | Secondary watched value. Use `null` if not needed | +| 5 | `watchedValue3` | string | no | Tertiary watched value. Use `null` if not needed | +| 6 | `watchedValue4` | string | no | Quaternary watched value. Use `null` if not needed | | 7 | `Extra` | string | no | Any additional metadata to display in UI and notifications. Use `null` if not needed | | 8 | `ForeignKey` | string | no | Foreign key linking to parent object (usually MAC address for device relationship). Use `null` if not needed | @@ -38,10 +38,10 @@ Plugins communicate with NetAlertX by writing results to a **pipe-delimited log | Order | Column Name | Type | Required | Description | |-------|-------------|------|----------|-------------| -| 9 | `HelpVal1` | string | *conditional* | Helper value 1. If used, all help values must be supplied | -| 10 | `HelpVal2` | string | *conditional* | Helper value 2. If used, all help values must be supplied | -| 11 | `HelpVal3` | string | *conditional* | Helper value 3. If used, all help values must be supplied | -| 12 | `HelpVal4` | string | *conditional* | Helper value 4. If used, all help values must be supplied | +| 9 | `helpVal1` | string | *conditional* | Helper value 1. If used, all help values must be supplied | +| 10 | `helpVal2` | string | *conditional* | Helper value 2. If used, all help values must be supplied | +| 11 | `helpVal3` | string | *conditional* | Helper value 3. If used, all help values must be supplied | +| 12 | `helpVal4` | string | *conditional* | Helper value 4. If used, all help values must be supplied | ## Usage Guide @@ -58,15 +58,15 @@ Watched values are fields that the NetAlertX core monitors for **changes between **How to use them:** -- `Watched_Value1`: Always required; primary indicator of status/state -- `Watched_Value2–4`: Optional; use for secondary/tertiary state information +- `watchedValue1`: Always required; primary indicator of status/state +- `watchedValue2–4`: Optional; use for secondary/tertiary state information - Leave unused ones as `null` **Example:** -- Device scanner: `Watched_Value1 = "online"` or `"offline"` -- Port scanner: `Watched_Value1 = "80"` (port number), `Watched_Value2 = "open"` (state) -- Service monitor: `Watched_Value1 = "200"` (HTTP status), `Watched_Value2 = "0.45"` (response time) +- Device scanner: `watchedValue1 = "online"` or `"offline"` +- Port scanner: `watchedValue1 = "80"` (port number), `watchedValue2 = "open"` (state) +- Service monitor: `watchedValue1 = "200"` (HTTP status), `watchedValue2 = "0.45"` (response time) ### Foreign Key @@ -110,14 +110,14 @@ https://google.com|null|2023-01-02 15:56:30|200|0.7898||null|null Missing pipe ``` -❌ **Missing mandatory Watched_Value1** (column 3): +❌ **Missing mandatory watchedValue1** (column 3): ```csv https://duckduckgo.com|192.168.1.1|2023-01-02 15:56:30|null|0.9898|null|null|Best|null ↑ Must not be null ``` -❌ **Incomplete optional columns** (has HelpVal1 but missing HelpVal2–4): +❌ **Incomplete optional columns** (has helpVal1 but missing helpVal2–4): ```csv device|null|2023-01-02 15:56:30|status|null|null|null|null|null|helper1 ↑ @@ -146,19 +146,19 @@ plugin_objects = Plugin_Objects("YOURPREFIX") # Add objects plugin_objects.add_object( - Object_PrimaryID="device_id", - Object_SecondaryID="192.168.1.1", + objectPrimaryId="device_id", + objectSecondaryId="192.168.1.1", DateTime="2023-01-02 15:56:30", - Watched_Value1="online", - Watched_Value2=None, - Watched_Value3=None, - Watched_Value4=None, + watchedValue1="online", + watchedValue2=None, + watchedValue3=None, + watchedValue4=None, Extra="Additional data", ForeignKey="aa:bb:cc:dd:ee:ff", - HelpVal1=None, - HelpVal2=None, - HelpVal3=None, - HelpVal4=None + helpVal1=None, + helpVal2=None, + helpVal3=None, + helpVal4=None ) # Write results (handles formatting, sanitization, and file creation) @@ -177,7 +177,7 @@ The library automatically: The core runs **de-duplication once per hour** on the `Plugins_Objects` table: -- **Duplicate Detection Key:** Combination of `Object_PrimaryID`, `Object_SecondaryID`, `Plugin` (auto-filled from `unique_prefix`), and `UserData` +- **Duplicate Detection Key:** Combination of `objectPrimaryId`, `objectSecondaryId`, `Plugin` (auto-filled from `unique_prefix`), and `UserData` - **Resolution:** Oldest duplicate entries are removed, newest are kept - **Use Case:** Prevents duplicate notifications when the same object is detected multiple times @@ -213,9 +213,9 @@ Before writing your plugin's `script.py`, ensure: - [ ] **9 or 13 columns** in each output line (8 or 12 pipe separators) - [ ] **Mandatory columns filled:** - - Column 0: `Object_PrimaryID` (not null) + - Column 0: `objectPrimaryId` (not null) - Column 2: `DateTime` in `YYYY-MM-DD HH:MM:SS` format - - Column 3: `Watched_Value1` (not null) + - Column 3: `watchedValue1` (not null) - [ ] **Null values as literal string** `null` (not empty string or special chars) - [ ] **No extra pipes or misaligned columns** - [ ] **If using optional helpers** (columns 9–12), all 4 must be present diff --git a/docs/PLUGINS_DEV_QUICK_START.md b/docs/PLUGINS_DEV_QUICK_START.md index 933b6886..6bac4ae5 100644 --- a/docs/PLUGINS_DEV_QUICK_START.md +++ b/docs/PLUGINS_DEV_QUICK_START.md @@ -68,13 +68,13 @@ try: # Add an object to results plugin_objects.add_object( - Object_PrimaryID="example_id", - Object_SecondaryID=None, + objectPrimaryId="example_id", + objectSecondaryId=None, DateTime="2023-01-02 15:56:30", - Watched_Value1="value1", - Watched_Value2=None, - Watched_Value3=None, - Watched_Value4=None, + watchedValue1="value1", + watchedValue2=None, + watchedValue3=None, + watchedValue4=None, Extra="additional_data", ForeignKey=None ) diff --git a/docs/PLUGINS_DEV_UI_COMPONENTS.md b/docs/PLUGINS_DEV_UI_COMPONENTS.md index 776bd40e..663f52e0 100644 --- a/docs/PLUGINS_DEV_UI_COMPONENTS.md +++ b/docs/PLUGINS_DEV_UI_COMPONENTS.md @@ -16,7 +16,7 @@ Each column definition specifies: ```json { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "devMac", "mapped_to_column_data": null, "css_classes": "col-sm-2", @@ -39,7 +39,7 @@ Each column definition specifies: | Property | Type | Required | Description | |----------|------|----------|-------------| -| `column` | string | **YES** | Source column name from data contract (e.g., `Object_PrimaryID`, `Watched_Value1`) | +| `column` | string | **YES** | Source column name from data contract (e.g., `objectPrimaryId`, `watchedValue1`) | | `mapped_to_column` | string | no | Target database column if mapping to a table like `CurrentScan` | | `mapped_to_column_data` | object | no | Static value to map instead of using column data | | `css_classes` | string | no | Bootstrap CSS classes for width/spacing (e.g., `"col-sm-2"`, `"col-sm-6"`) | @@ -64,7 +64,7 @@ Plain text display (read-only). ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "label", "localized": ["name"], @@ -99,7 +99,7 @@ Resolves an IP address to a MAC address and creates a device link. ```json { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "show": true, "type": "device_ip", "localized": ["name"], @@ -117,7 +117,7 @@ Creates a device link with the target device's name as the link label. ```json { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "show": true, "type": "device_name_mac", "localized": ["name"], @@ -135,7 +135,7 @@ Renders as a clickable HTTP/HTTPS link. ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "url", "localized": ["name"], @@ -153,7 +153,7 @@ Creates two links (HTTP and HTTPS) as lock icons for the given IP/hostname. ```json { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "show": true, "type": "url_http_https", "localized": ["name"], @@ -207,7 +207,7 @@ Color-codes values based on ranges. Useful for status codes, latency, capacity p ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "threshold", "options": [ @@ -252,7 +252,7 @@ Replaces specific values with display strings or HTML. ```json { - "column": "Watched_Value2", + "column": "watchedValue2", "show": true, "type": "replace", "options": [ @@ -286,7 +286,7 @@ Applies a regular expression to extract/transform values. ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "regex", "options": [ @@ -310,7 +310,7 @@ Evaluates JavaScript code with access to the column value (use `${value}` or `{v ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "eval", "default_value": "", @@ -322,7 +322,7 @@ Evaluates JavaScript code with access to the column value (use `${value}` or `{v **Example with custom formatting:** ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "eval", "options": [ @@ -347,7 +347,7 @@ You can chain multiple transformations with dot notation: ```json { - "column": "Watched_Value3", + "column": "watchedValue3", "show": true, "type": "regex.url_http_https", "options": [ @@ -376,7 +376,7 @@ Use SQL query results to populate dropdown options: ```json { - "column": "Watched_Value2", + "column": "watchedValue2", "show": true, "type": "select", "options": ["{value}"], @@ -405,7 +405,7 @@ Use plugin settings to populate options: ```json { - "column": "Watched_Value1", + "column": "watchedValue1", "show": true, "type": "select", "options": ["{value}"], @@ -439,7 +439,7 @@ To import plugin data into the device scan pipeline (for notifications, heuristi "mapped_to_table": "CurrentScan", "database_column_definitions": [ { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "show": true, "type": "device_mac", @@ -447,7 +447,7 @@ To import plugin data into the device scan pipeline (for notifications, heuristi "name": [{"language_code": "en_us", "string": "MAC Address"}] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "show": true, "type": "device_ip", @@ -501,7 +501,7 @@ Control which rows are displayed based on filter conditions. Filters are applied { "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -545,7 +545,7 @@ When viewing a device detail page, the `txtMacFilter` field is populated with th { "database_column_definitions": [ { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, @@ -555,7 +555,7 @@ When viewing a device detail page, the `txtMacFilter` field is populated with th "name": [{"language_code": "en_us", "string": "MAC Address"}] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -574,7 +574,7 @@ When viewing a device detail page, the `txtMacFilter` field is populated with th "name": [{"language_code": "en_us", "string": "Last Seen"}] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "threshold", @@ -589,7 +589,7 @@ When viewing a device detail page, the `txtMacFilter` field is populated with th "name": [{"language_code": "en_us", "string": "HTTP Status"}] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-1", "show": true, "type": "label", diff --git a/front/appEventsCore.php b/front/appEventsCore.php index 22c4ca23..47febbbe 100755 --- a/front/appEventsCore.php +++ b/front/appEventsCore.php @@ -61,16 +61,16 @@ $(document).ready(function () { appEvents(options: $options) { count appEvents { - DateTimeCreated - AppEventProcessed - AppEventType - ObjectType - ObjectPrimaryID - ObjectSecondaryID - ObjectStatus - ObjectPlugin - ObjectGUID - GUID + dateTimeCreated + appEventProcessed + appEventType + objectType + objectPrimaryId + objectSecondaryId + objectStatus + objectPlugin + objectGuid + guid } } } @@ -128,16 +128,16 @@ $(document).ready(function () { }, columns: [ - { data: 'DateTimeCreated', title: getString('AppEvents_DateTimeCreated') }, - { data: 'AppEventProcessed', title: getString('AppEvents_AppEventProcessed') }, - { data: 'AppEventType', title: getString('AppEvents_Type') }, - { data: 'ObjectType', title: getString('AppEvents_ObjectType') }, - { data: 'ObjectPrimaryID', title: getString('AppEvents_ObjectPrimaryID') }, - { data: 'ObjectSecondaryID', title: getString('AppEvents_ObjectSecondaryID') }, - { data: 'ObjectStatus', title: getString('AppEvents_ObjectStatus') }, - { data: 'ObjectPlugin', title: getString('AppEvents_Plugin') }, - { data: 'ObjectGUID', title: 'Object GUID' }, - { data: 'GUID', title: 'Event GUID' } + { data: 'dateTimeCreated', title: getString('AppEvents_DateTimeCreated') }, + { data: 'appEventProcessed', title: getString('AppEvents_AppEventProcessed') }, + { data: 'appEventType', title: getString('AppEvents_Type') }, + { data: 'objectType', title: getString('AppEvents_ObjectType') }, + { data: 'objectPrimaryId', title: getString('AppEvents_ObjectPrimaryID') }, + { data: 'objectSecondaryId', title: getString('AppEvents_ObjectSecondaryID') }, + { data: 'objectStatus', title: getString('AppEvents_ObjectStatus') }, + { data: 'objectPlugin', title: getString('AppEvents_Plugin') }, + { data: 'objectGuid', title: 'Object GUID' }, + { data: 'guid', title: 'Event GUID' } ], columnDefs: [ diff --git a/front/deviceDetailsEvents.php b/front/deviceDetailsEvents.php index a592d8ce..c7b7fdfe 100755 --- a/front/deviceDetailsEvents.php +++ b/front/deviceDetailsEvents.php @@ -38,12 +38,12 @@ function loadEventsData() { let { start, end } = getPeriodStartEnd(period); const rawSql = ` - SELECT eve_DateTime, eve_EventType, eve_IP, eve_AdditionalInfo + SELECT eveDateTime, eveEventType, eveIp, eveAdditionalInfo FROM Events - WHERE eve_MAC = "${mac}" - AND eve_DateTime BETWEEN "${start}" AND "${end}" + WHERE eveMac = "${mac}" + AND eveDateTime BETWEEN "${start}" AND "${end}" AND ( - (eve_EventType NOT IN ("Connected", "Disconnected", "VOIDED - Connected", "VOIDED - Disconnected")) + (eveEventType NOT IN ("Connected", "Disconnected", "VOIDED - Connected", "VOIDED - Disconnected")) OR "${hideConnectionsStr}" = "false" ) `; @@ -66,15 +66,15 @@ function loadEventsData() { success: function (data) { // assuming read_query returns rows directly const rows = data["results"].map(row => { - const rawDate = row.eve_DateTime; + const rawDate = row.eveDateTime; const formattedDate = rawDate ? localizeTimestamp(rawDate) : '-'; return [ formattedDate, - row.eve_DateTime, - row.eve_EventType, - row.eve_IP, - row.eve_AdditionalInfo + row.eveDateTime, + row.eveEventType, + row.eveIp, + row.eveAdditionalInfo ]; }); diff --git a/front/deviceDetailsSessions.php b/front/deviceDetailsSessions.php index ed9a0487..837a8971 100755 --- a/front/deviceDetailsSessions.php +++ b/front/deviceDetailsSessions.php @@ -121,12 +121,12 @@ function loadSessionsData() { if (data.success && data.sessions.length) { data.sessions.forEach(session => { table.row.add([ - session.ses_DateTimeOrder, - session.ses_Connection, - session.ses_Disconnection, - session.ses_Duration, - session.ses_IP, - session.ses_Info + session.sesDateTimeOrder, + session.sesConnection, + session.sesDisconnection, + session.sesDuration, + session.sesIp, + session.sesInfo ]); }); } diff --git a/front/js/app-init.js b/front/js/app-init.js index 5da09560..96bd2f4e 100644 --- a/front/js/app-init.js +++ b/front/js/app-init.js @@ -16,7 +16,7 @@ // ----------------------------------------------------------------------------- var completedCalls = [] -var completedCalls_final = ['cacheApiConfig', 'cacheSettings', 'cacheStrings', 'cacheDevices']; +var completedCalls_final = ['cacheApiConfig', 'cacheSettings', 'cacheStrings_v2', 'cacheDevices']; var lang_completedCalls = 0; diff --git a/front/js/cache.js b/front/js/cache.js index f224f6f2..12c881d3 100644 --- a/front/js/cache.js +++ b/front/js/cache.js @@ -304,7 +304,7 @@ function cacheStrings() { .then((data) => { if (!Array.isArray(data)) { data = []; } data.forEach((langString) => { - setCache(CACHE_KEYS.langString(langString.String_Key, langString.Language_Code), langString.String_Value); + setCache(CACHE_KEYS.langString(langString.stringKey, langString.languageCode), langString.stringValue); }); resolve(); }); @@ -347,11 +347,11 @@ function cacheStrings() { if (!Array.isArray(data)) { data = []; } // Store plugin translations data.forEach((langString) => { - setCache(CACHE_KEYS.langString(langString.String_Key, langString.Language_Code), langString.String_Value); + setCache(CACHE_KEYS.langString(langString.stringKey, langString.languageCode), langString.stringValue); }); // Handle successful completion of language processing - handleSuccess('cacheStrings'); + handleSuccess('cacheStrings_v2'); resolveLang(); }); }) diff --git a/front/multiEditCore.php b/front/multiEditCore.php index accf5e2e..4995460f 100755 --- a/front/multiEditCore.php +++ b/front/multiEditCore.php @@ -2,6 +2,7 @@ //------------------------------------------------------------------------------ // check if authenticated require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/security.php'; + require_once $_SERVER['DOCUMENT_ROOT'] . '/php/server/db.php'; require_once $_SERVER['DOCUMENT_ROOT'] . '/php/templates/language/lang.php'; ?> diff --git a/front/php/components/graph_online_history.php b/front/php/components/graph_online_history.php index 46275870..752143dc 100755 --- a/front/php/components/graph_online_history.php +++ b/front/php/components/graph_online_history.php @@ -28,13 +28,13 @@ function initOnlineHistoryGraph() { res.data.forEach(function(entry) { - var formattedTime = localizeTimestamp(entry.Scan_Date).slice(11, 17); + var formattedTime = localizeTimestamp(entry.scanDate).slice(11, 17); timeStamps.push(formattedTime); - onlineCounts.push(entry.Online_Devices); - downCounts.push(entry.Down_Devices); - offlineCounts.push(entry.Offline_Devices); - archivedCounts.push(entry.Archived_Devices); + onlineCounts.push(entry.onlineDevices); + downCounts.push(entry.downDevices); + offlineCounts.push(entry.offlineDevices); + archivedCounts.push(entry.archivedDevices); }); // Call your presenceOverTime function after data is ready diff --git a/front/php/templates/language/lang.php b/front/php/templates/language/lang.php index 6c4c3dbc..62264c89 100755 --- a/front/php/templates/language/lang.php +++ b/front/php/templates/language/lang.php @@ -24,7 +24,7 @@ $pia_lang_selected = isset($_langMatch[1]) ? strtolower($_langMatch[1]) : $defau $result = $db->query("SELECT * FROM Plugins_Language_Strings"); $strings = array(); while ($row = $result->fetchArray(SQLITE3_ASSOC)) { - $strings[$row['String_Key']] = $row['String_Value']; + $strings[$row['stringKey']] = $row['stringValue']; } diff --git a/front/plugins/__template/config.json b/front/plugins/__template/config.json index 12617d70..620aa408 100755 --- a/front/plugins/__template/config.json +++ b/front/plugins/__template/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -403,7 +403,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -418,7 +418,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -434,7 +434,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -450,7 +450,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -466,7 +466,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -482,7 +482,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, @@ -498,7 +498,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -532,7 +532,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -547,7 +547,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -562,7 +562,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/__template/rename_me.py b/front/plugins/__template/rename_me.py index b9f43e56..95cd1f62 100755 --- a/front/plugins/__template/rename_me.py +++ b/front/plugins/__template/rename_me.py @@ -50,7 +50,7 @@ def main(): # make sure the below mapping is mapped in config.json, for example: # "database_column_definitions": [ # { - # "column": "Object_PrimaryID", <--------- the value I save into primaryId + # "column": "objectPrimaryId", <--------- the value I save into primaryId # "mapped_to_column": "scanMac", <--------- gets inserted into the CurrentScan DB # table column scanMac # diff --git a/front/plugins/_publisher_apprise/config.json b/front/plugins/_publisher_apprise/config.json index 8980cd86..2dfc1520 100755 --- a/front/plugins/_publisher_apprise/config.json +++ b/front/plugins/_publisher_apprise/config.json @@ -31,7 +31,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -46,7 +46,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -65,7 +65,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "url", @@ -80,7 +80,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -99,7 +99,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-3", "show": true, "type": "label", @@ -114,7 +114,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -133,7 +133,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -153,7 +153,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-8", "show": true, "type": "textarea_readonly", @@ -168,7 +168,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -187,7 +187,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -206,7 +206,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -225,7 +225,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -261,7 +261,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_email/config.json b/front/plugins/_publisher_email/config.json index f86c4ac5..a1b2de1b 100755 --- a/front/plugins/_publisher_email/config.json +++ b/front/plugins/_publisher_email/config.json @@ -31,7 +31,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -46,7 +46,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -65,7 +65,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "url", @@ -80,7 +80,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -99,7 +99,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -114,7 +114,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -133,7 +133,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -153,7 +153,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-8", "show": true, "type": "textarea_readonly", @@ -168,7 +168,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -187,7 +187,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -206,7 +206,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -225,7 +225,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -261,7 +261,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_mqtt/config.json b/front/plugins/_publisher_mqtt/config.json index 2b1316ea..105041f1 100755 --- a/front/plugins/_publisher_mqtt/config.json +++ b/front/plugins/_publisher_mqtt/config.json @@ -7,7 +7,7 @@ "show_ui": true, "data_filters": [ { - "compare_column": "Watched_Value4", + "compare_column": "watchedValue4", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -47,7 +47,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -62,7 +62,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -81,7 +81,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -96,7 +96,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -111,7 +111,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -126,7 +126,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -145,7 +145,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-3", "show": false, "type": "label", @@ -160,7 +160,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -175,7 +175,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -190,7 +190,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -205,7 +205,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -224,7 +224,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", @@ -260,7 +260,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py index 8f5e88b0..7727ca4f 100755 --- a/front/plugins/_publisher_mqtt/mqtt.py +++ b/front/plugins/_publisher_mqtt/mqtt.py @@ -212,14 +212,14 @@ class sensor_config: already known. If not, it marks the sensor as new and logs relevant information. """ # Retrieve the plugin object based on the sensor's hash - plugObj = getPluginObject({"Plugin": "MQTT", "Watched_Value3": self.hash}) + plugObj = getPluginObject({"plugin": "MQTT", "watchedValue3": self.hash}) # Check if the plugin object is new if not plugObj: self.isNew = True mylog('verbose', [f"[{pluginName}] New sensor entry (name|mac|hash) : ({self.deviceName}|{self.mac}|{self.hash}"]) else: - device_name = plugObj.get("Watched_Value1", "Unknown") + device_name = plugObj.get("watchedValue1", "Unknown") mylog('verbose', [f"[{pluginName}] Existing, skip Device Name: {device_name}"]) self.isNew = False diff --git a/front/plugins/_publisher_ntfy/config.json b/front/plugins/_publisher_ntfy/config.json index 7afb93e6..16a37048 100755 --- a/front/plugins/_publisher_ntfy/config.json +++ b/front/plugins/_publisher_ntfy/config.json @@ -31,7 +31,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -46,7 +46,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -65,7 +65,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -80,7 +80,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -95,7 +95,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -115,7 +115,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "textarea_readonly", @@ -130,7 +130,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -145,7 +145,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "device_mac", @@ -160,7 +160,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -179,7 +179,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -215,7 +215,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_pushover/config.json b/front/plugins/_publisher_pushover/config.json index 7fbc2b2a..aed7d530 100755 --- a/front/plugins/_publisher_pushover/config.json +++ b/front/plugins/_publisher_pushover/config.json @@ -31,7 +31,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -46,7 +46,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -65,7 +65,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -80,7 +80,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -95,7 +95,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -115,7 +115,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "textarea_readonly", @@ -130,7 +130,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -145,7 +145,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "device_mac", @@ -160,7 +160,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -179,7 +179,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -215,7 +215,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_pushsafer/config.json b/front/plugins/_publisher_pushsafer/config.json index a7826942..40b6541a 100755 --- a/front/plugins/_publisher_pushsafer/config.json +++ b/front/plugins/_publisher_pushsafer/config.json @@ -31,7 +31,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -46,7 +46,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -65,7 +65,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -80,7 +80,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -95,7 +95,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -115,7 +115,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "textarea_readonly", @@ -130,7 +130,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -145,7 +145,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "device_mac", @@ -160,7 +160,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -179,7 +179,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -215,7 +215,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_telegram/config.json b/front/plugins/_publisher_telegram/config.json index 9b6cbb65..7786acd1 100755 --- a/front/plugins/_publisher_telegram/config.json +++ b/front/plugins/_publisher_telegram/config.json @@ -27,7 +27,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -42,7 +42,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -61,7 +61,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "url", @@ -76,7 +76,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -95,7 +95,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -110,7 +110,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -129,7 +129,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -149,7 +149,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-8", "show": true, "type": "textarea_readonly", @@ -164,7 +164,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -183,7 +183,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -202,7 +202,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -221,7 +221,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -257,7 +257,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/_publisher_webhook/config.json b/front/plugins/_publisher_webhook/config.json index 65a3481c..069e39f6 100755 --- a/front/plugins/_publisher_webhook/config.json +++ b/front/plugins/_publisher_webhook/config.json @@ -31,7 +31,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -46,7 +46,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -65,7 +65,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -80,7 +80,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -95,7 +95,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "eval", @@ -115,7 +115,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-3", "show": true, "type": "textarea_readonly", @@ -130,7 +130,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-3", "show": true, "type": "textarea_readonly", @@ -145,7 +145,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "device_mac", @@ -160,7 +160,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -179,7 +179,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -215,7 +215,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", diff --git a/front/plugins/adguard_import/config.json b/front/plugins/adguard_import/config.json index f4df3377..411230e0 100644 --- a/front/plugins/adguard_import/config.json +++ b/front/plugins/adguard_import/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -378,7 +378,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -393,7 +393,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -409,7 +409,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -425,7 +425,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -441,7 +441,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, @@ -457,7 +457,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -472,7 +472,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -506,7 +506,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -521,7 +521,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -536,7 +536,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/arp_scan/config.json b/front/plugins/arp_scan/config.json index 98beb02e..973927c4 100755 --- a/front/plugins/arp_scan/config.json +++ b/front/plugins/arp_scan/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -343,12 +343,12 @@ } ] }, - "default_value": ["Watched_Value1", "Watched_Value2"], + "default_value": ["watchedValue1", "watchedValue2"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -368,15 +368,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is IP
  • Watched_Value2 is Vendor
  • Watched_Value3 is Interface
  • Watched_Value4 is N/A
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is IP
  • watchedValue2 is Vendor
  • watchedValue3 is Interface
  • watchedValue4 is N/A
" }, { "language_code": "es_es", - "string": "Envía una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Valor_observado1 es IP
  • Valor_observado2 es Proveedor
  • Valor_observado3 es Interfaz
  • Valor_observado4 es N/A
" + "string": "Envía una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es IP
  • watchedValue2 es Proveedor
  • watchedValue3 es Interfaz
  • watchedValue4 es N/A
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist die IP
  • Watched_Value2 ist der Hersteller
  • Watched_Value3 ist das Interface
  • Watched_Value4 ist nicht in Verwendung
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist die IP
  • watchedValue2 ist der Hersteller
  • watchedValue3 ist das Interface
  • watchedValue4 ist nicht in Verwendung
" } ] }, @@ -484,7 +484,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -499,7 +499,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -515,7 +515,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -531,7 +531,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -582,7 +582,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -605,7 +605,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -628,7 +628,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/asuswrt_import/config.json b/front/plugins/asuswrt_import/config.json index 0135ab20..eac84984 100755 --- a/front/plugins/asuswrt_import/config.json +++ b/front/plugins/asuswrt_import/config.json @@ -9,7 +9,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -431,7 +431,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -448,7 +448,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "default_value": "", "localized": [ @@ -474,7 +474,7 @@ "type": "device_mac" }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "default_value": "", "localized": [ @@ -500,7 +500,7 @@ "type": "device_ip" }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "default_value": "", "localized": [ @@ -526,7 +526,7 @@ "type": "label" }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "default_value": "", @@ -573,7 +573,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -590,7 +590,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -607,7 +607,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/avahi_scan/config.json b/front/plugins/avahi_scan/config.json index d588e64d..d6650b98 100755 --- a/front/plugins/avahi_scan/config.json +++ b/front/plugins/avahi_scan/config.json @@ -8,7 +8,7 @@ "show_ui": true, "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -291,7 +291,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -306,7 +306,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -325,7 +325,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -344,7 +344,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -359,7 +359,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -374,7 +374,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -389,7 +389,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -404,7 +404,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/db_cleanup/script.py b/front/plugins/db_cleanup/script.py index 4d1c74e2..a6966e2c 100755 --- a/front/plugins/db_cleanup/script.py +++ b/front/plugins/db_cleanup/script.py @@ -82,16 +82,16 @@ def cleanup_database( # Cleanup Online History mylog("verbose", [f"[{pluginName}] Online_History: Delete all but keep latest 150 entries"]) cursor.execute( - """DELETE from Online_History where "Index" not in ( - SELECT "Index" from Online_History - order by Scan_Date desc limit 150)""" + """DELETE from Online_History where "index" not in ( + SELECT "index" from Online_History + order by scanDate desc limit 150)""" ) mylog("verbose", [f"[{pluginName}] Online_History deleted rows: {cursor.rowcount}"]) # ----------------------------------------------------- # Cleanup Events mylog("verbose", f"[{pluginName}] Events: Delete all older than {str(DAYS_TO_KEEP_EVENTS)} days (DAYS_TO_KEEP_EVENTS setting)") - sql = f"""DELETE FROM Events WHERE eve_DateTime <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')""" + sql = f"""DELETE FROM Events WHERE eveDateTime <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')""" mylog("verbose", [f"[{pluginName}] SQL : {sql}"]) cursor.execute(sql) mylog("verbose", [f"[{pluginName}] Events deleted rows: {cursor.rowcount}"]) @@ -100,7 +100,7 @@ def cleanup_database( # Sessions (derived snapshot — trimmed to the same window as Events so the # two tables stay in sync without introducing a separate setting) mylog("verbose", f"[{pluginName}] Sessions: Delete all older than {str(DAYS_TO_KEEP_EVENTS)} days (reuses DAYS_TO_KEEP_EVENTS)") - sql = f"""DELETE FROM Sessions WHERE ses_DateTimeConnection <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')""" + sql = f"""DELETE FROM Sessions WHERE sesDateTimeConnection <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')""" mylog("verbose", [f"[{pluginName}] SQL : {sql}"]) cursor.execute(sql) mylog("verbose", [f"[{pluginName}] Sessions deleted rows: {cursor.rowcount}"]) @@ -113,7 +113,7 @@ def cleanup_database( SELECT "Index" FROM ( SELECT "Index", - ROW_NUMBER() OVER(PARTITION BY "Plugin" ORDER BY DateTimeChanged DESC) AS row_num + ROW_NUMBER() OVER(PARTITION BY plugin ORDER BY dateTimeChanged DESC) AS row_num FROM Plugins_History ) AS ranked_objects WHERE row_num <= {str(PLUGINS_KEEP_HIST)} @@ -130,7 +130,7 @@ def cleanup_database( SELECT "Index" FROM ( SELECT "Index", - ROW_NUMBER() OVER(PARTITION BY "Notifications" ORDER BY DateTimeCreated DESC) AS row_num + ROW_NUMBER() OVER(PARTITION BY "index" ORDER BY dateTimeCreated DESC) AS row_num FROM Notifications ) AS ranked_objects WHERE row_num <= {histCount} @@ -147,7 +147,7 @@ def cleanup_database( SELECT "Index" FROM ( SELECT "Index", - ROW_NUMBER() OVER(PARTITION BY "AppEvents" ORDER BY DateTimeCreated DESC) AS row_num + ROW_NUMBER() OVER(PARTITION BY "index" ORDER BY dateTimeCreated DESC) AS row_num FROM AppEvents ) AS ranked_objects WHERE row_num <= {histCount} @@ -192,10 +192,10 @@ def cleanup_database( DELETE FROM Plugins_Objects WHERE rowid > ( SELECT MIN(rowid) FROM Plugins_Objects p2 - WHERE Plugins_Objects.Plugin = p2.Plugin - AND Plugins_Objects.Object_PrimaryID = p2.Object_PrimaryID - AND Plugins_Objects.Object_SecondaryID = p2.Object_SecondaryID - AND Plugins_Objects.UserData = p2.UserData + WHERE Plugins_Objects.plugin = p2.plugin + AND Plugins_Objects.objectPrimaryId = p2.objectPrimaryId + AND Plugins_Objects.objectSecondaryId = p2.objectSecondaryId + AND Plugins_Objects.userData = p2.userData ) """ ) diff --git a/front/plugins/ddns_update/config.json b/front/plugins/ddns_update/config.json index eec75e92..2337f809 100755 --- a/front/plugins/ddns_update/config.json +++ b/front/plugins/ddns_update/config.json @@ -5,7 +5,7 @@ "enabled": true, "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -437,12 +437,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -462,11 +462,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Previous IP (not recommended)
  • Watched_Value2 unused
  • Watched_Value3 unused
  • Watched_Value4 unused
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Previous IP (not recommended)
  • watchedValue2 unused
  • watchedValue3 unused
  • watchedValue4 unused
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist die Vorige IP (nicht empfohlen)
  • Watched_Value2 ist nicht in Verwendung
  • Watched_Value3 ist nicht in Verwendung
  • Watched_Value4 ist nicht in Verwendung
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist die Vorige IP (nicht empfohlen)
  • watchedValue2 ist nicht in Verwendung
  • watchedValue3 ist nicht in Verwendung
  • watchedValue4 ist nicht in Verwendung
" } ] }, @@ -507,22 +507,22 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas Watched_ValueN seleccionadas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." }, { "language_code": "de_de", - "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte Watched_ValueN-Spalte hat sich geändert." + "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte watchedValueN-Spalte hat sich geändert." } ] } ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -537,7 +537,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -560,7 +560,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -583,7 +583,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -628,7 +628,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -651,7 +651,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -674,7 +674,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/dhcp_leases/ASUS_ROUTERS.md b/front/plugins/dhcp_leases/ASUS_ROUTERS.md index 6fc257aa..4ad0d7da 100755 --- a/front/plugins/dhcp_leases/ASUS_ROUTERS.md +++ b/front/plugins/dhcp_leases/ASUS_ROUTERS.md @@ -78,7 +78,7 @@ volumes: 10. Load the `DHCPLSS` plugin and add the search path: `/etc/dnsmasq/dnsmasq.leases` -Configure the plugin, and save everything. You can trigger a manual run. +Configure the plugin, and save everything. You can trigger a manual run. > [!NOTE] > DHCP leases don't allow for realtime tracking and the freshness of the data depends on the DHCP leasing time (usually set to 1 or 24h, or 3600 to 86400 seconds). @@ -93,8 +93,8 @@ DHCPLSS_CMD: 'python3 /app/front/plugins/dhcp_leases/script.py paths={paths}' DHCPLSS_paths_to_check: ['/etc/dnsmasq/dnsmasq.leases'] DHCPLSS_RUN_SCHD: '*/5 * * * *' DHCPLSS_TUN_TIMEOUT: 5 -DHCPLSS_WATCH: ['Watched_Value1', 'Watched_Value4'] -DHCPLSS_REPORT_ON: ['new', 'watched_changed'] +DHCPLSS_WATCH: ['watchedValue1', 'watchedValue4'] +DHCPLSS_REPORT_ON: ['new', 'watched-changed'] ``` You can check the the `dnsmasq.leases` file in the container by running `ls /etc/dnsmasq/`: diff --git a/front/plugins/dhcp_leases/config.json b/front/plugins/dhcp_leases/config.json index 70adb612..b760f8d3 100755 --- a/front/plugins/dhcp_leases/config.json +++ b/front/plugins/dhcp_leases/config.json @@ -7,7 +7,7 @@ "data_source": "script", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -64,7 +64,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -79,7 +79,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -102,7 +102,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, @@ -126,7 +126,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -150,7 +150,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -173,7 +173,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, @@ -197,7 +197,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -220,7 +220,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -244,7 +244,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -267,7 +267,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -290,7 +290,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -313,7 +313,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": true, "type": "label", @@ -363,7 +363,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", @@ -758,12 +758,12 @@ } ] }, - "default_value": ["Watched_Value1", "Watched_Value4"], + "default_value": ["watchedValue1", "watchedValue4"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -783,15 +783,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Active
  • Watched_Value2 is Hostname
  • Watched_Value3 is hardware
  • Watched_Value4 is State
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Active
  • watchedValue2 is Hostname
  • watchedValue3 is hardware
  • watchedValue4 is State
" }, { "language_code": "es_es", - "string": "Enviar una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Watched_Value1 está activo
  • Watched_Value2 es el nombre de host
  • Watched_Value3 es hardware
  • Watched_Value4 es Estado
" + "string": "Enviar una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 está activo
  • watchedValue2 es el nombre de host
  • watchedValue3 es hardware
  • watchedValue4 es Estado
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist der Aktivstatus
  • Watched_Value2 ist der Hostname
  • Watched_Value3 ist die Hardware
  • Watched_Value4 ist der Zustand
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist der Aktivstatus
  • watchedValue2 ist der Hostname
  • watchedValue3 ist die Hardware
  • watchedValue4 ist der Zustand
" } ] }, @@ -832,15 +832,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas Watched_ValueN seleccionadas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." }, { "language_code": "de_de", - "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte Watched_ValueN-Spalte hat sich geändert." + "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte watchedValueN-Spalte hat sich geändert." } ] } diff --git a/front/plugins/dhcp_servers/config.json b/front/plugins/dhcp_servers/config.json index 57169612..049ec58d 100755 --- a/front/plugins/dhcp_servers/config.json +++ b/front/plugins/dhcp_servers/config.json @@ -40,7 +40,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -55,7 +55,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -74,7 +74,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -93,7 +93,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -112,7 +112,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -131,7 +131,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -150,7 +150,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -169,7 +169,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -188,7 +188,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -207,7 +207,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -226,7 +226,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": true, "type": "textbox_save", @@ -245,7 +245,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", @@ -281,7 +281,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": true, "type": "label", @@ -483,12 +483,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -504,11 +504,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Domain Name Server
  • Watched_Value2 is IP Offered
  • Watched_Value3 is Interface
  • Watched_Value4 is Router
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Domain Name Server
  • watchedValue2 is IP Offered
  • watchedValue3 is Interface
  • watchedValue4 is Router
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Watched_Value1 es servidor de nombres de dominio
  • Watched_Value2 es IP ofrecida
  • Watched_Value3 es Interfaz
  • Watched_Value4 es enrutador
" + "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es servidor de nombres de dominio
  • watchedValue2 es IP ofrecida
  • watchedValue3 es Interfaz
  • watchedValue4 es enrutador
" } ] }, @@ -540,11 +540,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas Watched_ValueN seleccionadas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." } ] } diff --git a/front/plugins/dig_scan/config.json b/front/plugins/dig_scan/config.json index 8729f9a5..23c58237 100755 --- a/front/plugins/dig_scan/config.json +++ b/front/plugins/dig_scan/config.json @@ -8,7 +8,7 @@ "show_ui": true, "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -299,7 +299,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -314,7 +314,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -333,7 +333,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -352,7 +352,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -367,7 +367,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -382,7 +382,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -397,7 +397,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -412,7 +412,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/freebox/config.json b/front/plugins/freebox/config.json index 9ab39ec6..000b69d2 100755 --- a/front/plugins/freebox/config.json +++ b/front/plugins/freebox/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -376,7 +376,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -393,7 +393,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -411,7 +411,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -429,7 +429,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -447,7 +447,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -465,7 +465,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, @@ -483,7 +483,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -521,7 +521,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -538,7 +538,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -555,7 +555,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/icmp_scan/config.json b/front/plugins/icmp_scan/config.json index d3fac3db..e04f3ac0 100755 --- a/front/plugins/icmp_scan/config.json +++ b/front/plugins/icmp_scan/config.json @@ -9,7 +9,7 @@ "show_ui": true, "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -364,7 +364,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -381,7 +381,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -399,7 +399,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -417,7 +417,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -434,7 +434,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "textarea_readonly", @@ -451,7 +451,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -468,7 +468,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -506,7 +506,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -523,7 +523,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -540,7 +540,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/internet_ip/config.json b/front/plugins/internet_ip/config.json index 446f30d1..679913d5 100755 --- a/front/plugins/internet_ip/config.json +++ b/front/plugins/internet_ip/config.json @@ -7,7 +7,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -329,12 +329,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -354,11 +354,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Previous IP (not recommended)
  • Watched_Value2 unused
  • Watched_Value3 unused
  • Watched_Value4 type
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Previous IP (not recommended)
  • watchedValue2 unused
  • watchedValue3 unused
  • watchedValue4 type
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist die Vorige IP (nicht empfohlen)
  • Watched_Value2 ist nicht in Verwendung
  • Watched_Value3 ist nicht in Verwendung
  • Watched_Value4 ist nicht in Verwendung
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist die Vorige IP (nicht empfohlen)
  • watchedValue2 ist nicht in Verwendung
  • watchedValue3 ist nicht in Verwendung
  • watchedValue4 ist nicht in Verwendung
" } ] }, @@ -399,15 +399,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas Watched_ValueN seleccionadas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." }, { "language_code": "de_de", - "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte Watched_ValueN-Spalte hat sich geändert." + "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte watchedValueN-Spalte hat sich geändert." } ] }, @@ -478,7 +478,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -493,7 +493,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -517,7 +517,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -541,7 +541,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -560,7 +560,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "textarea_readonly", @@ -575,7 +575,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -590,7 +590,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": false, @@ -633,7 +633,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -656,7 +656,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, @@ -680,7 +680,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/internet_speedtest/README.md b/front/plugins/internet_speedtest/README.md index 898b2c67..17979043 100755 --- a/front/plugins/internet_speedtest/README.md +++ b/front/plugins/internet_speedtest/README.md @@ -1,6 +1,6 @@ ## Overview -A plugin allowing for executing regular internet speed tests. +A plugin allowing for executing regular internet speed tests. ### Usage @@ -43,9 +43,9 @@ Inside the container, a Python version of speedtest often exists in the virtual ### Data Mapping -- **Watched_Value1** — Download Speed (Mbps). -- **Watched_Value2** — Upload Speed (Mbps). -- **Watched_Value3** — Full JSON payload (useful for n8n or detailed webhooks). +- **watchedValue1** — Download Speed (Mbps). +- **watchedValue2** — Upload Speed (Mbps). +- **watchedValue3** — Full JSON payload (useful for n8n or detailed webhooks). ### Notes diff --git a/front/plugins/internet_speedtest/config.json b/front/plugins/internet_speedtest/config.json index 0d8a97f1..49df80eb 100755 --- a/front/plugins/internet_speedtest/config.json +++ b/front/plugins/internet_speedtest/config.json @@ -39,7 +39,7 @@ "params": [], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -54,7 +54,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -77,7 +77,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": false, "type": "url", @@ -96,7 +96,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -119,7 +119,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -138,7 +138,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -161,7 +161,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "threshold", @@ -197,7 +197,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "threshold", @@ -233,7 +233,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -256,7 +256,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -279,7 +279,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -302,7 +302,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": false, "type": "replace", @@ -342,7 +342,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", @@ -568,10 +568,10 @@ }, "default_value": [], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -591,15 +591,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Download speed (not recommended)
  • Watched_Value2 is Upload speed (not recommended)
  • Watched_Value3 is JSON payload for webhooks (schema varies by engine)
  • Watched_Value4 unused
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Download speed (not recommended)
  • watchedValue2 is Upload speed (not recommended)
  • watchedValue3 is JSON payload for webhooks (schema varies by engine)
  • watchedValue4 unused
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Use CTRL + Clic para seleccionar/deseleccionar.
  • Watched_Value1 es la velocidad de descarga (no recomendado)
  • Watched_Value2 es la velocidad de carga (no recomendado)
  • Watched_Value3 es la carga útil JSON para webhooks (el esquema varía según el motor)
  • Watched_Value4 no se usa
" + "string": "Envíe una notificación si los valores seleccionados cambian. Use CTRL + Clic para seleccionar/deseleccionar.
  • watchedValue1 es la velocidad de descarga (no recomendado)
  • watchedValue2 es la velocidad de carga (no recomendado)
  • watchedValue3 es la carga útil JSON para webhooks (el esquema varía según el motor)
  • watchedValue4 no se usa
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist die Download-Geschwindigkeit (nicht empfohlen)
  • Watched_Value2 ist die Upload-Geschwindigkeit (nicht empfohlen)
  • Watched_Value3 ist JSON-Payload für Webhooks (Schema variiert je nach Engine)
  • Watched_Value4 ist nicht in Verwendung
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist die Download-Geschwindigkeit (nicht empfohlen)
  • watchedValue2 ist die Upload-Geschwindigkeit (nicht empfohlen)
  • watchedValue3 ist JSON-Payload für Webhooks (Schema variiert je nach Engine)
  • watchedValue4 ist nicht in Verwendung
" } ] }, @@ -640,15 +640,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó Watched_ValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." }, { "language_code": "de_de", - "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte Watched_ValueN-Spalte hat sich geändert." + "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte watchedValueN-Spalte hat sich geändert." } ] } diff --git a/front/plugins/ipneigh/config.json b/front/plugins/ipneigh/config.json index 3ba4d08e..1ca114a9 100755 --- a/front/plugins/ipneigh/config.json +++ b/front/plugins/ipneigh/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -273,7 +273,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -290,7 +290,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -308,7 +308,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -326,7 +326,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -344,7 +344,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -362,7 +362,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, @@ -380,7 +380,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -418,7 +418,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -435,7 +435,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -452,7 +452,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/luci_import/config.json b/front/plugins/luci_import/config.json index e12eaeac..490e8932 100755 --- a/front/plugins/luci_import/config.json +++ b/front/plugins/luci_import/config.json @@ -9,7 +9,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -450,7 +450,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -469,7 +469,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -489,7 +489,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -509,7 +509,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -528,7 +528,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -571,7 +571,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -590,7 +590,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -609,7 +609,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/mikrotik_scan/config.json b/front/plugins/mikrotik_scan/config.json index f3cc3f58..b968d804 100755 --- a/front/plugins/mikrotik_scan/config.json +++ b/front/plugins/mikrotik_scan/config.json @@ -336,7 +336,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -351,7 +351,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -382,7 +382,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -398,7 +398,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -413,7 +413,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -429,7 +429,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -444,7 +444,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -459,7 +459,7 @@ ] }, { - "column": "HelpVal1", + "column": "helpVal1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -493,7 +493,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -512,7 +512,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", diff --git a/front/plugins/nbtscan_scan/config.json b/front/plugins/nbtscan_scan/config.json index 48b8a589..b64fad72 100755 --- a/front/plugins/nbtscan_scan/config.json +++ b/front/plugins/nbtscan_scan/config.json @@ -8,7 +8,7 @@ "show_ui": true, "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -299,7 +299,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -314,7 +314,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -333,7 +333,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -352,7 +352,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -367,7 +367,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -382,7 +382,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -397,7 +397,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -412,7 +412,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/nmap_dev_scan/config.json b/front/plugins/nmap_dev_scan/config.json index 55cf9c77..a5b3487c 100755 --- a/front/plugins/nmap_dev_scan/config.json +++ b/front/plugins/nmap_dev_scan/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -290,10 +290,10 @@ }, "default_value": [], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": [ "name", @@ -316,15 +316,15 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Name
  • Watched_Value2 is Vendor
  • Watched_Value3 is Interface
  • Watched_Value4 is N/A
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Name
  • watchedValue2 is Vendor
  • watchedValue3 is Interface
  • watchedValue4 is N/A
" }, { "language_code": "es_es", - "string": "Envía una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Valor_observado1 es Name
  • Valor_observado2 es Proveedor
  • Valor_observado3 es Interfaz
  • Valor_observado4 es N/A
" + "string": "Envía una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es Name
  • watchedValue2 es Proveedor
  • watchedValue3 es Interfaz
  • watchedValue4 es N/A
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist der Namen
  • Watched_Value2 ist der Hersteller
  • Watched_Value3 ist das Interface
  • Watched_Value4 ist nicht in Verwendung
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist der Namen
  • watchedValue2 ist der Hersteller
  • watchedValue3 ist das Interface
  • watchedValue4 ist nicht in Verwendung
" } ] }, @@ -522,7 +522,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -539,7 +539,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -557,7 +557,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -575,7 +575,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -593,7 +593,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -619,7 +619,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanLastQuery", "css_classes": "col-sm-2", "show": true, @@ -670,7 +670,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -695,7 +695,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -720,7 +720,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/nmap_scan/config.json b/front/plugins/nmap_scan/config.json index 34a6d561..b5326075 100755 --- a/front/plugins/nmap_scan/config.json +++ b/front/plugins/nmap_scan/config.json @@ -72,7 +72,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -87,7 +87,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -102,7 +102,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -121,7 +121,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -140,7 +140,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -159,7 +159,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -178,7 +178,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-1", "show": true, "type": "label", @@ -197,7 +197,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-1", "show": true, "type": "label", @@ -215,7 +215,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-1", "show": true, "type": "regex.url_http_https", @@ -239,7 +239,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -258,7 +258,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-1", "show": false, "type": "label", @@ -277,7 +277,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-3", "show": true, "type": "textbox_save", @@ -315,7 +315,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", @@ -558,12 +558,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -579,11 +579,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is service type (e.g.: http, ssh)
  • Watched_Value2 is Status (open or closed)
  • Watched_Value3 unused
  • Watched_Value4 unused
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is service type (e.g.: http, ssh)
  • watchedValue2 is Status (open or closed)
  • watchedValue3 unused
  • watchedValue4 unused
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Watched_Value1 es el tipo de servicio (p. ej., http, ssh)
  • Watched_Value2 es el estado (abierto o cerrado)
  • Watched_Value3 no utilizado
  • Watched_Value4 no utilizado
" + "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es el tipo de servicio (p. ej., http, ssh)
  • watchedValue2 es el estado (abierto o cerrado)
  • watchedValue3 no utilizado
  • watchedValue4 no utilizado
" } ] }, @@ -615,11 +615,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó Watched_ValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." } ] } diff --git a/front/plugins/notification_processing/README.md b/front/plugins/notification_processing/README.md index 9fad5a26..c1deabf0 100755 --- a/front/plugins/notification_processing/README.md +++ b/front/plugins/notification_processing/README.md @@ -33,12 +33,12 @@ The following notification types are available based on the `NTFPRCS_INCLUDED_SE - Notifies about specific events triggered by a device. - The device must have **Alert Events** enabled in its settings. - Includes events: - - `Connected`, `Down Reconnected`, `Disconnected`,`IP Changed` + - `Connected`, `Down Reconnected`, `Disconnected`,`IP Changed` - you can exclude devices with a custom where condition via the `NTFPRCS_event_condition` setting ### `plugins` - Notifies when an event is triggered by a plugin. -- These notifications depend on the plugin's configuration of the `Watched_Value1-4` values and the `_REPORT_ON` settings. +- These notifications depend on the plugin's configuration of the `watchedValue1-4` values and the `_REPORT_ON` settings. ## Device-Specific Overrides diff --git a/front/plugins/notification_processing/config.json b/front/plugins/notification_processing/config.json index 3333fd79..726c0382 100755 --- a/front/plugins/notification_processing/config.json +++ b/front/plugins/notification_processing/config.json @@ -225,7 +225,7 @@ "description": [ { "language_code": "en_us", - "string": "Custom text template for new device notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) - {eve_IP}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + "string": "Custom text template for new device notifications. Use {FieldName} placeholders, e.g. {devName} ({eveMac}) - {eveIp}. Leave empty for default formatting. Available fields: {devName}, {eveMac}, {devVendor}, {eveIp}, {eveDateTime}, {eveEventType}, {devComments}." } ] }, @@ -249,7 +249,7 @@ "description": [ { "language_code": "en_us", - "string": "Custom text template for down device notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) - {eve_IP}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + "string": "Custom text template for down device notifications. Use {FieldName} placeholders, e.g. {devName} ({eveMac}) - {eveIp}. Leave empty for default formatting. Available fields: {devName}, {eveMac}, {devVendor}, {eveIp}, {eveDateTime}, {eveEventType}, {devComments}." } ] }, @@ -273,7 +273,7 @@ "description": [ { "language_code": "en_us", - "string": "Custom text template for reconnected device notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) reconnected at {eve_DateTime}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + "string": "Custom text template for reconnected device notifications. Use {FieldName} placeholders, e.g. {devName} ({eveMac}) reconnected at {eveDateTime}. Leave empty for default formatting. Available fields: {devName}, {eveMac}, {devVendor}, {eveIp}, {eveDateTime}, {eveEventType}, {devComments}." } ] }, @@ -297,7 +297,7 @@ "description": [ { "language_code": "en_us", - "string": "Custom text template for event notifications. Use {FieldName} placeholders, e.g. {devName} ({eve_MAC}) {eve_EventType} at {eve_DateTime}. Leave empty for default formatting. Available fields: {devName}, {eve_MAC}, {devVendor}, {eve_IP}, {eve_DateTime}, {eve_EventType}, {devComments}." + "string": "Custom text template for event notifications. Use {FieldName} placeholders, e.g. {devName} ({eveMac}) {eveEventType} at {eveDateTime}. Leave empty for default formatting. Available fields: {devName}, {eveMac}, {devVendor}, {eveIp}, {eveDateTime}, {eveEventType}, {devComments}." } ] }, @@ -321,7 +321,7 @@ "description": [ { "language_code": "en_us", - "string": "Custom text template for plugin event notifications. Use {FieldName} placeholders, e.g. {Plugin}: {Object_PrimaryId} - {Status}. Leave empty for default formatting. Available fields: {Plugin}, {Object_PrimaryId}, {Object_SecondaryId}, {DateTimeChanged}, {Watched_Value1}, {Watched_Value2}, {Watched_Value3}, {Watched_Value4}, {Status}." + "string": "Custom text template for plugin event notifications. Use {FieldName} placeholders, e.g. {plugin}: {objectPrimaryId} - {status}. Leave empty for default formatting. Available fields: {plugin}, {objectPrimaryId}, {objectSecondaryId}, {dateTimeChanged}, {watchedValue1}, {watchedValue2}, {watchedValue3}, {watchedValue4}, {status}." } ] } diff --git a/front/plugins/nslookup_scan/config.json b/front/plugins/nslookup_scan/config.json index 6bf444d0..00449c2d 100755 --- a/front/plugins/nslookup_scan/config.json +++ b/front/plugins/nslookup_scan/config.json @@ -8,7 +8,7 @@ "show_ui": true, "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -299,7 +299,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -314,7 +314,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-3", "show": true, "type": "device_name_mac", @@ -329,7 +329,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -344,7 +344,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -359,7 +359,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -374,7 +374,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -393,7 +393,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -412,7 +412,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/omada_sdn_imp/config.json b/front/plugins/omada_sdn_imp/config.json index 394d3940..e4560f44 100755 --- a/front/plugins/omada_sdn_imp/config.json +++ b/front/plugins/omada_sdn_imp/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -403,7 +403,7 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Hostname
  • Watched_Value2 is Parent Node
  • Watched_Value3 is Port
  • Watched_Value4 is SSID
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Hostname
  • watchedValue2 is Parent Node
  • watchedValue3 is Port
  • watchedValue4 is SSID
" } ], "function": "WATCH", @@ -419,10 +419,10 @@ } ], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "type": { "dataType": "array", @@ -440,7 +440,7 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." } ], "function": "REPORT_ON", @@ -542,7 +542,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -557,7 +557,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -581,7 +581,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -605,7 +605,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -621,7 +621,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "show": true, @@ -637,7 +637,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanParentPort", "css_classes": "col-sm-2", "show": true, @@ -653,7 +653,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "mapped_to_column": "scanSSID", "css_classes": "col-sm-2", "show": true, @@ -669,7 +669,7 @@ ] }, { - "column": "Extra", + "column": "extra", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": false, @@ -712,7 +712,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -735,7 +735,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -758,7 +758,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/omada_sdn_imp/omada_sdn.py b/front/plugins/omada_sdn_imp/omada_sdn.py index 9447df69..922f7971 100755 --- a/front/plugins/omada_sdn_imp/omada_sdn.py +++ b/front/plugins/omada_sdn_imp/omada_sdn.py @@ -319,7 +319,7 @@ def main(): # make sure the below mapping is mapped in config.json, for example: # "database_column_definitions": [ # { - # "column": "Object_PrimaryID", <--------- the value I save into primaryId + # "column": "objectPrimaryId", <--------- the value I save into primaryId # "mapped_to_column": "scanMac", <--------- gets unserted into the CurrentScan DB table column scanMac # watched1 = 'null' , # figure a way to run my udpate script delayed diff --git a/front/plugins/omada_sdn_openapi/config.json b/front/plugins/omada_sdn_openapi/config.json index cc594202..b3737b78 100755 --- a/front/plugins/omada_sdn_openapi/config.json +++ b/front/plugins/omada_sdn_openapi/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -380,7 +380,7 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Device Name
  • Watched_Value2 is Parent Node MAC
  • Watched_Value3 is Parent Node Port
  • Watched_Value4 is Parent Node SSID
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Device Name
  • watchedValue2 is Parent Node MAC
  • watchedValue3 is Parent Node Port
  • watchedValue4 is Parent Node SSID
" } ], "function": "WATCH", @@ -392,10 +392,10 @@ } ], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "type": { "dataType": "array", @@ -413,7 +413,7 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." } ], "function": "REPORT_ON", @@ -517,7 +517,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -532,7 +532,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -548,7 +548,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -564,7 +564,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -580,7 +580,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "show": true, @@ -596,7 +596,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanParentPort", "css_classes": "col-sm-2", "show": true, @@ -612,7 +612,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "mapped_to_column": "scanSSID", "css_classes": "col-sm-2", "show": true, @@ -628,7 +628,7 @@ ] }, { - "column": "Extra", + "column": "extra", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": false, @@ -663,7 +663,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -678,7 +678,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -693,7 +693,7 @@ ] }, { - "column": "HelpVal1", + "column": "helpVal1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -708,7 +708,7 @@ ] }, { - "column": "HelpVal2", + "column": "helpVal2", "mapped_to_column": "scanSite", "css_classes": "col-sm-2", "show": true, @@ -724,7 +724,7 @@ ] }, { - "column": "HelpVal3", + "column": "helpVal3", "css_classes": "col-sm-2", "show": true, "type": "label", diff --git a/front/plugins/pihole_api_scan/config.json b/front/plugins/pihole_api_scan/config.json index 2ed11f33..f5605c17 100644 --- a/front/plugins/pihole_api_scan/config.json +++ b/front/plugins/pihole_api_scan/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -441,7 +441,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -456,7 +456,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -472,7 +472,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -488,7 +488,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -504,7 +504,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -520,7 +520,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -535,7 +535,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -569,7 +569,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -584,7 +584,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -599,7 +599,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/pihole_scan/config.json b/front/plugins/pihole_scan/config.json index 6d96f111..c8a371de 100755 --- a/front/plugins/pihole_scan/config.json +++ b/front/plugins/pihole_scan/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -105,7 +105,7 @@ { "elementType": "input", "elementOptions": [], "transformers": [] } ] }, - "default_value": "SELECT n.hwaddr AS Object_PrimaryID, {s-quote}null{s-quote} AS Object_SecondaryID, datetime() AS DateTime, na.ip AS Watched_Value1, n.lastQuery AS Watched_Value2, na.name AS Watched_Value3, n.macVendor AS Watched_Value4, {s-quote}null{s-quote} AS Extra, n.hwaddr AS ForeignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr is not {s-quote}00:00:00:00:00:00{s-quote} AND na.ip is not null", + "default_value": "SELECT n.hwaddr AS objectPrimaryId, {s-quote}null{s-quote} AS objectSecondaryId, datetime() AS dateTimeChanged, na.ip AS watchedValue1, n.lastQuery AS watchedValue2, na.name AS watchedValue3, n.macVendor AS watchedValue4, {s-quote}null{s-quote} AS extra, n.hwaddr AS foreignKey FROM EXTERNAL_PIHOLE.Network AS n LEFT JOIN EXTERNAL_PIHOLE.Network_Addresses AS na ON na.network_id = n.id WHERE n.hwaddr NOT LIKE {s-quote}ip-%{s-quote} AND n.hwaddr is not {s-quote}00:00:00:00:00:00{s-quote} AND na.ip is not null", "options": [], "localized": ["name", "description"], "name": [ @@ -295,12 +295,12 @@ } ] }, - "default_value": ["Watched_Value1", "Watched_Value2"], + "default_value": ["watchedValue1", "watchedValue2"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -316,11 +316,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is IP
  • Watched_Value2 is Last Query
  • Watched_Value3 is Name
  • Watched_Value4 is N/A
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is IP
  • watchedValue2 is Last Query
  • watchedValue3 is Name
  • watchedValue4 is N/A
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Watched_Value1 es IP
  • Watched_Value2 es Proveedor
  • Watched_Value3 is es Interfaz
  • Watched_Value4 es N/A
" + "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es IP
  • watchedValue2 es Proveedor
  • watchedValue3 is es Interfaz
  • watchedValue4 es N/A
" } ] }, @@ -369,7 +369,7 @@ "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -384,7 +384,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, @@ -404,7 +404,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -419,7 +419,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -439,7 +439,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanLastQuery", "css_classes": "col-sm-2", "show": true, @@ -455,7 +455,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -471,7 +471,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -510,7 +510,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -529,7 +529,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index b89ed4ad..1c2ea990 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -7,7 +7,7 @@ "data_source": "script", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -65,7 +65,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -80,7 +80,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -99,7 +99,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, @@ -119,7 +119,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -139,7 +139,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, @@ -159,7 +159,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -179,7 +179,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -198,7 +198,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -217,7 +217,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -236,7 +236,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -255,7 +255,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": true, "type": "label", @@ -297,7 +297,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", @@ -663,12 +663,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -684,11 +684,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Hostname (not discoverable)
  • Watched_Value2 is Router IP
  • Watched_Value3 is not used
  • Watched_Value4 is not used
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Hostname (not discoverable)
  • watchedValue2 is Router IP
  • watchedValue3 is not used
  • watchedValue4 is not used
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Watched_Value1 es el nombre de host (no detectable)
  • Watched_Value2 es la IP del enrutador
  • Watched_Value3< /code> no se utiliza
  • Watched_Value4 no se utiliza
" + "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es el nombre de host (no detectable)
  • watchedValue2 es la IP del enrutador
  • watchedValue3< /code> no se utiliza
  • watchedValue4 no se utiliza
" } ] }, @@ -725,11 +725,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas Watched_ValueN seleccionadas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." } ] } diff --git a/front/plugins/sync/config.json b/front/plugins/sync/config.json index bb98a239..1c5695d2 100755 --- a/front/plugins/sync/config.json +++ b/front/plugins/sync/config.json @@ -7,7 +7,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -667,7 +667,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -684,7 +684,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -710,7 +710,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -736,7 +736,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -754,7 +754,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -772,7 +772,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanSyncHubNode", "css_classes": "col-sm-2", "show": true, @@ -790,7 +790,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -836,7 +836,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -861,7 +861,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -886,7 +886,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/unifi_api_import/config.json b/front/plugins/unifi_api_import/config.json index 8ee8fba7..423e486b 100755 --- a/front/plugins/unifi_api_import/config.json +++ b/front/plugins/unifi_api_import/config.json @@ -8,7 +8,7 @@ "mapped_to_table": "CurrentScan", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -569,7 +569,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -586,7 +586,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-3", "show": true, @@ -604,7 +604,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -622,7 +622,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -640,7 +640,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "show": true, @@ -658,7 +658,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -675,7 +675,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "show": true, @@ -714,7 +714,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -731,7 +731,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -748,7 +748,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index ce215cc9..b5274514 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -72,7 +72,7 @@ ], "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", "compare_operator": "==", @@ -81,7 +81,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -96,7 +96,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -119,7 +119,7 @@ "type": "label" }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -143,7 +143,7 @@ "type": "device_mac" }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -167,7 +167,7 @@ "type": "device_ip" }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -190,7 +190,7 @@ "type": "label" }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -214,7 +214,7 @@ "type": "label" }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -238,7 +238,7 @@ "type": "label" }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "default_value": "", @@ -262,7 +262,7 @@ "type": "label" }, { - "column": "Watched_Value3", + "column": "watchedValue3", "mapped_to_column": "scanType", "css_classes": "col-sm-2", "default_value": "", @@ -286,7 +286,7 @@ "type": "label" }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -309,7 +309,7 @@ "type": "label" }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "default_value": "", "localized": ["name"], @@ -359,7 +359,7 @@ "type": "label" }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "default_value": "", "localized": ["name"], @@ -382,7 +382,7 @@ "type": "label" }, { - "column": "HelpVal1", + "column": "helpVal1", "mapped_to_column": "scanParentMAC", "css_classes": "col-sm-2", "default_value": "", @@ -398,7 +398,7 @@ "type": "label" }, { - "column": "HelpVal2", + "column": "helpVal2", "mapped_to_column": "scanParentPort", "css_classes": "col-sm-2", "default_value": "", @@ -414,7 +414,7 @@ "type": "label" }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "default_value": "", "localized": ["name"], @@ -992,15 +992,15 @@ ] }, { - "default_value": ["Watched_Value1", "Watched_Value4"], + "default_value": ["watchedValue1", "watchedValue4"], "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is Hostname
  • Watched_Value2 is Vendor
  • Watched_Value3 is Type
  • Watched_Value4 is Online
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is Hostname
  • watchedValue2 is Vendor
  • watchedValue3 is Type
  • watchedValue4 is Online
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • Watched_Value1 es el nombre de host
  • Watched_Value2 es el proveedor
  • Watched_Value3 es el tipo
  • Watched_Value4 es Online
" + "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es el nombre de host
  • watchedValue2 es el proveedor
  • watchedValue3 es el tipo
  • watchedValue4 es Online
" } ], "function": "WATCH", @@ -1016,10 +1016,10 @@ } ], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "type": { "dataType": "array", @@ -1037,11 +1037,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas Watched_ValueN seleccionadas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (una combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." } ], "function": "REPORT_ON", diff --git a/front/plugins/vendor_update/config.json b/front/plugins/vendor_update/config.json index 79f29f93..17f1f925 100755 --- a/front/plugins/vendor_update/config.json +++ b/front/plugins/vendor_update/config.json @@ -304,12 +304,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -329,11 +329,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is vendor name
  • Watched_Value2 is device name
  • Watched_Value3 unused
  • Watched_Value4 unused
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is vendor name
  • watchedValue2 is device name
  • watchedValue3 unused
  • watchedValue4 unused
" }, { "language_code": "de_de", - "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • Watched_Value1 ist der Herstellername
  • Watched_Value2 ist der Gerätename
  • Watched_Value3 ist nicht in Verwendung
  • Watched_Value4 ist nicht in Verwendung
" + "string": "Sende eine Benachrichtigung, wenn ein ausgwählter Wert sich ändert. STRG + klicken zum aus-/abwählen.
  • watchedValue1 ist der Herstellername
  • watchedValue2 ist der Gerätename
  • watchedValue3 ist nicht in Verwendung
  • watchedValue4 ist nicht in Verwendung
" } ] }, @@ -374,22 +374,22 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó Watched_ValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." }, { "language_code": "de_de", - "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte Watched_ValueN-Spalte hat sich geändert." + "string": "Benachrichtige nur bei diesen Status. new bedeutet ein neues eindeutiges (einzigartige Kombination aus PrimaryId und SecondaryId) Objekt wurde erkennt. watched-changed bedeutet eine ausgewählte watchedValueN-Spalte hat sich geändert." } ] } ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -404,7 +404,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -427,7 +427,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "mapped_to_column": "scanMac", "css_classes": "col-sm-2", "show": true, @@ -451,7 +451,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "mapped_to_column": "scanLastIP", "css_classes": "col-sm-2", "show": true, @@ -475,7 +475,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -498,7 +498,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "mapped_to_column": "scanLastConnection", "css_classes": "col-sm-2", "show": true, @@ -549,7 +549,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "mapped_to_column": "scanVendor", "css_classes": "col-sm-2", "show": true, @@ -569,7 +569,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "mapped_to_column": "scanName", "css_classes": "col-sm-2", "show": true, @@ -593,7 +593,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -612,7 +612,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -631,7 +631,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": false, "type": "textbox_save", @@ -654,7 +654,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", @@ -673,7 +673,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/wake_on_lan/config.json b/front/plugins/wake_on_lan/config.json index ed9233f2..38f7fc01 100755 --- a/front/plugins/wake_on_lan/config.json +++ b/front/plugins/wake_on_lan/config.json @@ -7,7 +7,7 @@ "data_source": "script", "data_filters": [ { - "compare_column": "Object_PrimaryID", + "compare_column": "objectPrimaryId", "compare_operator": "==", "compare_field_id": "txtMacFilter", "compare_js_template": "'{value}'.toString()", @@ -356,7 +356,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -371,7 +371,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "device_name_mac", @@ -386,7 +386,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": true, "type": "device_ip", @@ -401,7 +401,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -416,7 +416,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -431,7 +431,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -446,7 +446,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -476,7 +476,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -491,7 +491,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -506,7 +506,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", diff --git a/front/plugins/website_monitor/config.json b/front/plugins/website_monitor/config.json index 9aeb11f0..251605fe 100755 --- a/front/plugins/website_monitor/config.json +++ b/front/plugins/website_monitor/config.json @@ -51,7 +51,7 @@ ], "database_column_definitions": [ { - "column": "Index", + "column": "index", "css_classes": "col-sm-2", "show": true, "type": "none", @@ -66,7 +66,7 @@ ] }, { - "column": "Plugin", + "column": "plugin", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -85,7 +85,7 @@ ] }, { - "column": "Object_PrimaryID", + "column": "objectPrimaryId", "css_classes": "col-sm-2", "show": true, "type": "url", @@ -104,7 +104,7 @@ ] }, { - "column": "Object_SecondaryID", + "column": "objectSecondaryId", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -123,7 +123,7 @@ ] }, { - "column": "DateTimeCreated", + "column": "dateTimeCreated", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -142,7 +142,7 @@ ] }, { - "column": "DateTimeChanged", + "column": "dateTimeChanged", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -161,7 +161,7 @@ ] }, { - "column": "Watched_Value1", + "column": "watchedValue1", "css_classes": "col-sm-2", "show": true, "type": "threshold", @@ -201,7 +201,7 @@ ] }, { - "column": "Watched_Value2", + "column": "watchedValue2", "css_classes": "col-sm-2", "show": true, "type": "label", @@ -220,7 +220,7 @@ ] }, { - "column": "Watched_Value3", + "column": "watchedValue3", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -239,7 +239,7 @@ ] }, { - "column": "Watched_Value4", + "column": "watchedValue4", "css_classes": "col-sm-2", "show": false, "type": "label", @@ -258,7 +258,7 @@ ] }, { - "column": "UserData", + "column": "userData", "css_classes": "col-sm-2", "show": true, "type": "textbox_save", @@ -277,7 +277,7 @@ ] }, { - "column": "Status", + "column": "status", "css_classes": "col-sm-1", "show": true, "type": "replace", @@ -313,7 +313,7 @@ ] }, { - "column": "Extra", + "column": "extra", "css_classes": "col-sm-3", "show": false, "type": "label", @@ -543,12 +543,12 @@ } ] }, - "default_value": ["Watched_Value1"], + "default_value": ["watchedValue1"], "options": [ - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4" + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4" ], "localized": ["name", "description"], "name": [ @@ -564,11 +564,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is response status code (e.g.: 200, 404)
  • Watched_Value2 is Latency (not recommended)
  • Watched_Value3 unused
  • Watched_Value4 unused
" + "string": "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • watchedValue1 is response status code (e.g.: 200, 404)
  • watchedValue2 is Latency (not recommended)
  • watchedValue3 unused
  • watchedValue4 unused
" }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Use CTRL + Click para seleccionar/deseleccionar.
  • Watched_Value1 es un código de estado de respuesta (por ejemplo: 200, 404)
  • Valor_observado2 es Latencia (no recomendado)
  • Valor_observado3 no utilizado
  • Valor_observado4 sin usar
" + "string": "Envíe una notificación si los valores seleccionados cambian. Use CTRL + Click para seleccionar/deseleccionar.
  • watchedValue1 es un código de estado de respuesta (por ejemplo: 200, 404)
  • watchedValue2 es Latencia (no recomendado)
  • watchedValue3 no utilizado
  • watchedValue4 sin usar
" } ] }, @@ -605,11 +605,11 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó Watched_ValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." } ] }, diff --git a/front/pluginsCore.php b/front/pluginsCore.php index 32566603..1e19ff07 100755 --- a/front/pluginsCore.php +++ b/front/pluginsCore.php @@ -246,9 +246,9 @@ function genericSaveData (id) { headers: { "Authorization": `Bearer ${apiToken}` }, data: JSON.stringify({ dbtable: "Plugins_Objects", - columnName: "Index", + columnName: "index", id: index, - columns: "UserData", + columns: "userData", values: columnValue }), contentType: "application/json", @@ -413,26 +413,26 @@ function getColumnDefinitions(pluginObj) { function getEventData(prefix, colDefinitions, pluginObj) { // Extract event data specific to the plugin and format it for DataTables return pluginUnprocessedEvents - .filter(event => event.Plugin === prefix && shouldBeShown(event, pluginObj)) // Filter events for the specific plugin + .filter(event => event.plugin === prefix && shouldBeShown(event, pluginObj)) // Filter events for the specific plugin .map(event => colDefinitions.map(colDef => event[colDef.column] || '')); // Map to the defined columns } function getObjectData(prefix, colDefinitions, pluginObj) { // Extract object data specific to the plugin and format it for DataTables return pluginObjects - .filter(object => object.Plugin === prefix && shouldBeShown(object, pluginObj)) // Filter objects for the specific plugin - .map(object => colDefinitions.map(colDef => getFormControl(colDef, object[colDef.column], object["Index"], colDefinitions, object))); // Map to the defined columns + .filter(object => object.plugin === prefix && shouldBeShown(object, pluginObj)) // Filter objects for the specific plugin + .map(object => colDefinitions.map(colDef => getFormControl(colDef, object[colDef.column], object["index"], colDefinitions, object))); // Map to the defined columns } function getHistoryData(prefix, colDefinitions, pluginObj) { return pluginHistory - .filter(history => history.Plugin === prefix && shouldBeShown(history, pluginObj)) // First, filter based on the plugin prefix - .sort((a, b) => b.Index - a.Index) // Then, sort by the Index field in descending order + .filter(history => history.plugin === prefix && shouldBeShown(history, pluginObj)) // First, filter based on the plugin prefix + .sort((a, b) => b.index - a.index) // Then, sort by the Index field in descending order .slice(0, 50) // Limit the result to the first 50 entries .map(object => colDefinitions.map(colDef => - getFormControl(colDef, object[colDef.column], object["Index"], colDefinitions, object) + getFormControl(colDef, object[colDef.column], object["index"], colDefinitions, object) ) ); } diff --git a/front/report.php b/front/report.php index 498eb06b..d27efdc8 100755 --- a/front/report.php +++ b/front/report.php @@ -43,9 +43,9 @@ @@ -100,23 +100,23 @@ // Display the selected format data and update timestamp switch (format) { - case 'HTML': + case 'html': notificationData.innerHTML = formatData; break; - case 'JSON': + case 'json': notificationData.innerHTML = `
                                                       ${jsonSyntaxHighlight(JSON.stringify(JSON.parse(formatData), undefined, 4))}
                                                     
`; break; - case 'Text': + case 'text': notificationData.innerHTML = `
${formatData}
`; break; } // console.log(notification) - timestamp.textContent = localizeTimestamp(notification.DateTimeCreated); - notiGuid.textContent = notification.GUID; + timestamp.textContent = localizeTimestamp(notification.dateTimeCreated); + notiGuid.textContent = notification.guid; currentIndex = index; $("#notificationOutOff").html(`${currentIndex + 1}/${data.data.length}`); @@ -131,7 +131,7 @@ // Function to find the index of a notification by GUID function findIndexByGUID(data, guid) { - return data.findIndex(notification => notification.GUID == guid); + return data.findIndex(notification => notification.guid == guid); } // Listen for format selection changes diff --git a/front/report_templates/webhook_json_sample.json b/front/report_templates/webhook_json_sample.json index c252e4e6..f8201ab9 100755 --- a/front/report_templates/webhook_json_sample.json +++ b/front/report_templates/webhook_json_sample.json @@ -42,11 +42,11 @@ "title": "🔴 Down devices", "columnNames": [ "devName", - "eve_MAC", + "eveMac", "devVendor", - "eve_IP", - "eve_DateTime", - "eve_EventType" + "eveIp", + "eveDateTime", + "eveEventType" ] }, "down_devices": [], @@ -64,22 +64,22 @@ "down_reconnected": [ { "devName": "Phone - Moto 82", - "eve_MAC": "74:ac:74:ac:74:ac", + "eveMac": "74:ac:74:ac:74:ac", "devVendor": "Motorola Mobility LLC, a Lenovo Company", - "eve_IP": "192.168.1.167", - "eve_DateTime": "2025-01-11 10:05:01+11:00", - "eve_EventType": "Down Reconnected" + "eveIp": "192.168.1.167", + "eveDateTime": "2025-01-11 10:05:01+11:00", + "eveEventType": "Down Reconnected" } ], "down_reconnected_meta": { "title": "🔁 Reconnected down devices", "columnNames": [ "devName", - "eve_MAC", + "eveMac", "devVendor", - "eve_IP", - "eve_DateTime", - "eve_EventType" + "eveIp", + "eveDateTime", + "eveEventType" ] }, "events": [ @@ -103,28 +103,28 @@ "plugins_meta": { "title": "🔌 Plugins", "columnNames": [ - "Plugin", - "Object_PrimaryID", - "Object_SecondaryID", - "DateTimeChanged", - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4", - "Status" + "plugin", + "objectPrimaryId", + "objectSecondaryId", + "dateTimeChanged", + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4", + "status" ] }, "plugins": [ { - "Plugin": "ARPSCAN", - "Object_PrimaryID": "74:ac:74:ac:74:ac", - "Object_SecondaryID": "192.168.1.114", - "DateTimeChanged": "2025-01-11 12:21:00", - "Watched_Value1": "192.168.1.114", - "Watched_Value2": "Microsoft Corporation", - "Watched_Value3": "192.168.1.0/24 --interface=eth1", - "Watched_Value4": "", - "Status": "new" + "plugin": "ARPSCAN", + "objectPrimaryId": "74:ac:74:ac:74:ac", + "objectSecondaryId": "192.168.1.114", + "dateTimeChanged": "2025-01-11 12:21:00", + "watchedValue1": "192.168.1.114", + "watchedValue2": "Microsoft Corporation", + "watchedValue3": "192.168.1.0/24 --interface=eth1", + "watchedValue4": "", + "status": "new" } ] } diff --git a/scripts/db_cleanup/db_cleanup.py b/scripts/db_cleanup/db_cleanup.py index e55ee5e6..39e782af 100755 --- a/scripts/db_cleanup/db_cleanup.py +++ b/scripts/db_cleanup/db_cleanup.py @@ -34,12 +34,12 @@ def check_and_clean_device(): # Check all tables for MAC tables_checks = [ - f"SELECT 'Events' as source, * FROM Events WHERE eve_MAC='{mac}'", - f"SELECT 'Devices' as source, * FROM Devices WHERE dev_MAC='{mac}'", + f"SELECT 'Events' as source, * FROM Events WHERE eveMac='{mac}'", + f"SELECT 'Devices' as source, * FROM Devices WHERE devMac='{mac}'", f"SELECT 'CurrentScan' as source, * FROM CurrentScan WHERE scanMac='{mac}'", f"SELECT 'Notifications' as source, * FROM Notifications WHERE JSON LIKE '%{mac}%'", - f"SELECT 'AppEvents' as source, * FROM AppEvents WHERE ObjectPrimaryID LIKE '%{mac}%' OR ObjectSecondaryID LIKE '%{mac}%'", - f"SELECT 'Plugins_Objects' as source, * FROM Plugins_Objects WHERE Object_PrimaryID LIKE '%{mac}%'" + f"SELECT 'AppEvents' as source, * FROM AppEvents WHERE objectPrimaryId LIKE '%{mac}%' OR objectSecondaryId LIKE '%{mac}%'", + f"SELECT 'Plugins_Objects' as source, * FROM Plugins_Objects WHERE objectPrimaryId LIKE '%{mac}%'" ] found = False @@ -54,12 +54,12 @@ def check_and_clean_device(): if confirm.lower() == 'y': # Delete from all tables deletes = [ - f"DELETE FROM Events WHERE eve_MAC='{mac}'", - f"DELETE FROM Devices WHERE dev_MAC='{mac}'", + f"DELETE FROM Events WHERE eveMac='{mac}'", + f"DELETE FROM Devices WHERE devMac='{mac}'", f"DELETE FROM CurrentScan WHERE scanMac='{mac}'", f"DELETE FROM Notifications WHERE JSON LIKE '%{mac}%'", - f"DELETE FROM AppEvents WHERE ObjectPrimaryID LIKE '%{mac}%' OR ObjectSecondaryID LIKE '%{mac}%'", - f"DELETE FROM Plugins_Objects WHERE Object_PrimaryID LIKE '%{mac}%'" + f"DELETE FROM AppEvents WHERE objectPrimaryId LIKE '%{mac}%' OR objectSecondaryId LIKE '%{mac}%'", + f"DELETE FROM Plugins_Objects WHERE objectPrimaryId LIKE '%{mac}%'" ] for delete in deletes: @@ -73,12 +73,12 @@ def check_and_clean_device(): # Check all tables for IP tables_checks = [ - f"SELECT 'Events' as source, * FROM Events WHERE eve_IP='{ip}'", - f"SELECT 'Devices' as source, * FROM Devices WHERE dev_LastIP='{ip}'", + f"SELECT 'Events' as source, * FROM Events WHERE eveIp='{ip}'", + f"SELECT 'Devices' as source, * FROM Devices WHERE devLastIp='{ip}'", f"SELECT 'CurrentScan' as source, * FROM CurrentScan WHERE scanLastIP='{ip}'", f"SELECT 'Notifications' as source, * FROM Notifications WHERE JSON LIKE '%{ip}%'", - f"SELECT 'AppEvents' as source, * FROM AppEvents WHERE ObjectSecondaryID LIKE '%{ip}%'", - f"SELECT 'Plugins_Objects' as source, * FROM Plugins_Objects WHERE Object_SecondaryID LIKE '%{ip}%'" + f"SELECT 'AppEvents' as source, * FROM AppEvents WHERE objectSecondaryId LIKE '%{ip}%'", + f"SELECT 'Plugins_Objects' as source, * FROM Plugins_Objects WHERE objectSecondaryId LIKE '%{ip}%'" ] found = False @@ -93,12 +93,12 @@ def check_and_clean_device(): if confirm.lower() == 'y': # Delete from all tables deletes = [ - f"DELETE FROM Events WHERE eve_IP='{ip}'", - f"DELETE FROM Devices WHERE dev_LastIP='{ip}'", + f"DELETE FROM Events WHERE eveIp='{ip}'", + f"DELETE FROM Devices WHERE devLastIp='{ip}'", f"DELETE FROM CurrentScan WHERE scanLastIP='{ip}'", f"DELETE FROM Notifications WHERE JSON LIKE '%{ip}%'", - f"DELETE FROM AppEvents WHERE ObjectSecondaryID LIKE '%{ip}%'", - f"DELETE FROM Plugins_Objects WHERE Object_SecondaryID LIKE '%{ip}%'" + f"DELETE FROM AppEvents WHERE objectSecondaryId LIKE '%{ip}%'", + f"DELETE FROM Plugins_Objects WHERE objectSecondaryId LIKE '%{ip}%'" ] for delete in deletes: diff --git a/server/api_server/graphql_endpoint.py b/server/api_server/graphql_endpoint.py index ba417d84..99850800 100755 --- a/server/api_server/graphql_endpoint.py +++ b/server/api_server/graphql_endpoint.py @@ -154,30 +154,30 @@ class LangStringResult(ObjectType): # --- APP EVENTS --- class AppEvent(ObjectType): - Index = Int(description="Internal index") - GUID = String(description="Unique event GUID") - AppEventProcessed = Int(description="Processing status (0 or 1)") - DateTimeCreated = String(description="Event creation timestamp") + index = Int(description="Internal index") + guid = String(description="Unique event GUID") + appEventProcessed = Int(description="Processing status (0 or 1)") + dateTimeCreated = String(description="Event creation timestamp") - ObjectType = String(description="Type of the related object (Device, Setting, etc.)") - ObjectGUID = String(description="GUID of the related object") - ObjectPlugin = String(description="Plugin associated with the object") - ObjectPrimaryID = String(description="Primary identifier of the object") - ObjectSecondaryID = String(description="Secondary identifier of the object") - ObjectForeignKey = String(description="Foreign key reference") - ObjectIndex = Int(description="Object index") + objectType = String(description="Type of the related object (Device, Setting, etc.)") + objectGuid = String(description="GUID of the related object") + objectPlugin = String(description="Plugin associated with the object") + objectPrimaryId = String(description="Primary identifier of the object") + objectSecondaryId = String(description="Secondary identifier of the object") + objectForeignKey = String(description="Foreign key reference") + objectIndex = Int(description="Object index") - ObjectIsNew = Int(description="Is the object new? (0 or 1)") - ObjectIsArchived = Int(description="Is the object archived? (0 or 1)") - ObjectStatusColumn = String(description="Column used for status") - ObjectStatus = String(description="Object status value") + objectIsNew = Int(description="Is the object new? (0 or 1)") + objectIsArchived = Int(description="Is the object archived? (0 or 1)") + objectStatusColumn = String(description="Column used for status") + objectStatus = String(description="Object status value") - AppEventType = String(description="Type of application event") + appEventType = String(description="Type of application event") - Helper1 = String(description="Generic helper field 1") - Helper2 = String(description="Generic helper field 2") - Helper3 = String(description="Generic helper field 3") - Extra = String(description="Additional JSON data") + helper1 = String(description="Generic helper field 1") + helper2 = String(description="Generic helper field 2") + helper3 = String(description="Generic helper field 3") + extra = String(description="Additional JSON data") class AppEventResult(ObjectType): @@ -499,18 +499,18 @@ class Query(ObjectType): search_term = options.search.lower() searchable_fields = [ - "GUID", - "ObjectType", - "ObjectGUID", - "ObjectPlugin", - "ObjectPrimaryID", - "ObjectSecondaryID", - "ObjectStatus", - "AppEventType", - "Helper1", - "Helper2", - "Helper3", - "Extra", + "guid", + "objectType", + "objectGuid", + "objectPlugin", + "objectPrimaryId", + "objectSecondaryId", + "objectStatus", + "appEventType", + "helper1", + "helper2", + "helper3", + "extra", ] events_data = [ @@ -616,9 +616,9 @@ class Query(ObjectType): plugin_data = json.load(f).get("data", []) plugin_list = [ LangString( - langCode=entry.get("Language_Code"), - langStringKey=entry.get("String_Key"), - langStringText=entry.get("String_Value") + langCode=entry.get("languageCode"), + langStringKey=entry.get("stringKey"), + langStringText=entry.get("stringValue") ) for entry in plugin_data ] _langstrings_cache[cache_key] = plugin_list diff --git a/server/api_server/sessions_endpoint.py b/server/api_server/sessions_endpoint.py index f9435c84..dd6037d2 100755 --- a/server/api_server/sessions_endpoint.py +++ b/server/api_server/sessions_endpoint.py @@ -33,8 +33,8 @@ def create_session( cur.execute( """ - INSERT INTO Sessions (ses_MAC, ses_IP, ses_DateTimeConnection, ses_DateTimeDisconnection, - ses_EventTypeConnection, ses_EventTypeDisconnection) + INSERT INTO Sessions (sesMac, sesIp, sesDateTimeConnection, sesDateTimeDisconnection, + sesEventTypeConnection, sesEventTypeDisconnection) VALUES (?, ?, ?, ?, ?, ?) """, (mac, ip, start_time, end_time, event_type_conn, event_type_disc), @@ -52,7 +52,7 @@ def delete_session(mac): conn = get_temp_db_connection() cur = conn.cursor() - cur.execute("DELETE FROM Sessions WHERE ses_MAC = ?", (mac,)) + cur.execute("DELETE FROM Sessions WHERE sesMac = ?", (mac,)) conn.commit() conn.close() @@ -69,13 +69,13 @@ def get_sessions(mac=None, start_date=None, end_date=None): params = [] if mac: - sql += " AND ses_MAC = ?" + sql += " AND sesMac = ?" params.append(mac) if start_date: - sql += " AND ses_DateTimeConnection >= ?" + sql += " AND sesDateTimeConnection >= ?" params.append(start_date) if end_date: - sql += " AND ses_DateTimeDisconnection <= ?" + sql += " AND sesDateTimeDisconnection <= ?" params.append(end_date) cur.execute(sql, tuple(params)) @@ -106,49 +106,49 @@ def get_sessions_calendar(start_date, end_date, mac): sql = """ SELECT - SES1.ses_MAC, - SES1.ses_EventTypeConnection, - SES1.ses_DateTimeConnection, - SES1.ses_EventTypeDisconnection, - SES1.ses_DateTimeDisconnection, - SES1.ses_IP, - SES1.ses_AdditionalInfo, - SES1.ses_StillConnected, + SES1.sesMac, + SES1.sesEventTypeConnection, + SES1.sesDateTimeConnection, + SES1.sesEventTypeDisconnection, + SES1.sesDateTimeDisconnection, + SES1.sesIp, + SES1.sesAdditionalInfo, + SES1.sesStillConnected, CASE - WHEN SES1.ses_EventTypeConnection = '' THEN + WHEN SES1.sesEventTypeConnection = '' THEN IFNULL( ( - SELECT MAX(SES2.ses_DateTimeDisconnection) + SELECT MAX(SES2.sesDateTimeDisconnection) FROM Sessions AS SES2 - WHERE SES2.ses_MAC = SES1.ses_MAC - AND SES2.ses_DateTimeDisconnection < SES1.ses_DateTimeDisconnection - AND SES2.ses_DateTimeDisconnection BETWEEN Date(?) AND Date(?) + WHERE SES2.sesMac = SES1.sesMac + AND SES2.sesDateTimeDisconnection < SES1.sesDateTimeDisconnection + AND SES2.sesDateTimeDisconnection BETWEEN Date(?) AND Date(?) ), - DATETIME(SES1.ses_DateTimeDisconnection, '-1 hour') + DATETIME(SES1.sesDateTimeDisconnection, '-1 hour') ) - ELSE SES1.ses_DateTimeConnection - END AS ses_DateTimeConnectionCorrected, + ELSE SES1.sesDateTimeConnection + END AS sesDateTimeConnectionCorrected, CASE - WHEN SES1.ses_EventTypeDisconnection = '' THEN + WHEN SES1.sesEventTypeDisconnection = '' THEN ( - SELECT MIN(SES2.ses_DateTimeConnection) + SELECT MIN(SES2.sesDateTimeConnection) FROM Sessions AS SES2 - WHERE SES2.ses_MAC = SES1.ses_MAC - AND SES2.ses_DateTimeConnection > SES1.ses_DateTimeConnection - AND SES2.ses_DateTimeConnection BETWEEN Date(?) AND Date(?) + WHERE SES2.sesMac = SES1.sesMac + AND SES2.sesDateTimeConnection > SES1.sesDateTimeConnection + AND SES2.sesDateTimeConnection BETWEEN Date(?) AND Date(?) ) - ELSE SES1.ses_DateTimeDisconnection - END AS ses_DateTimeDisconnectionCorrected + ELSE SES1.sesDateTimeDisconnection + END AS sesDateTimeDisconnectionCorrected FROM Sessions AS SES1 WHERE ( - (SES1.ses_DateTimeConnection BETWEEN Date(?) AND Date(?)) - OR (SES1.ses_DateTimeDisconnection BETWEEN Date(?) AND Date(?)) - OR SES1.ses_StillConnected = 1 + (SES1.sesDateTimeConnection BETWEEN Date(?) AND Date(?)) + OR (SES1.sesDateTimeDisconnection BETWEEN Date(?) AND Date(?)) + OR SES1.sesStillConnected = 1 ) - AND (? IS NULL OR SES1.ses_MAC = ?) + AND (? IS NULL OR SES1.sesMac = ?) """ cur.execute( @@ -173,31 +173,31 @@ def get_sessions_calendar(start_date, end_date, mac): # Color logic (unchanged from PHP) if ( - row["ses_EventTypeConnection"] == "" or row["ses_EventTypeDisconnection"] == "" + row["sesEventTypeConnection"] == "" or row["sesEventTypeDisconnection"] == "" ): color = "#f39c12" - elif row["ses_StillConnected"] == 1: + elif row["sesStillConnected"] == 1: color = "#00a659" else: color = "#0073b7" # --- IMPORTANT FIX --- # FullCalendar v3 CANNOT handle end = null - end_dt = row["ses_DateTimeDisconnectionCorrected"] - if not end_dt and row["ses_StillConnected"] == 1: + end_dt = row["sesDateTimeDisconnectionCorrected"] + if not end_dt and row["sesStillConnected"] == 1: end_dt = now_iso tooltip = ( - f"Connection: {format_event_date(row['ses_DateTimeConnection'], row['ses_EventTypeConnection'])}\n" - f"Disconnection: {format_event_date(row['ses_DateTimeDisconnection'], row['ses_EventTypeDisconnection'])}\n" - f"IP: {row['ses_IP']}" + f"Connection: {format_event_date(row['sesDateTimeConnection'], row['sesEventTypeConnection'])}\n" + f"Disconnection: {format_event_date(row['sesDateTimeDisconnection'], row['sesEventTypeDisconnection'])}\n" + f"IP: {row['sesIp']}" ) events.append( { - "resourceId": row["ses_MAC"], + "resourceId": row["sesMac"], "title": "", - "start": format_date_iso(row["ses_DateTimeConnectionCorrected"]), + "start": format_date_iso(row["sesDateTimeConnectionCorrected"]), "end": format_date_iso(end_dt), "color": color, "tooltip": tooltip, @@ -219,20 +219,20 @@ def get_device_sessions(mac, period): sql = f""" SELECT - IFNULL(ses_DateTimeConnection, ses_DateTimeDisconnection) AS ses_DateTimeOrder, - ses_EventTypeConnection, - ses_DateTimeConnection, - ses_EventTypeDisconnection, - ses_DateTimeDisconnection, - ses_StillConnected, - ses_IP, - ses_AdditionalInfo + IFNULL(sesDateTimeConnection, sesDateTimeDisconnection) AS sesDateTimeOrder, + sesEventTypeConnection, + sesDateTimeConnection, + sesEventTypeDisconnection, + sesDateTimeDisconnection, + sesStillConnected, + sesIp, + sesAdditionalInfo FROM Sessions - WHERE ses_MAC = ? + WHERE sesMac = ? AND ( - ses_DateTimeConnection >= {period_date} - OR ses_DateTimeDisconnection >= {period_date} - OR ses_StillConnected = 1 + sesDateTimeConnection >= {period_date} + OR sesDateTimeDisconnection >= {period_date} + OR sesStillConnected = 1 ) """ @@ -245,44 +245,44 @@ def get_device_sessions(mac, period): for row in rows: # Connection DateTime - if row["ses_EventTypeConnection"] == "": - ini = row["ses_EventTypeConnection"] + if row["sesEventTypeConnection"] == "": + ini = row["sesEventTypeConnection"] else: - ini = format_date(row["ses_DateTimeConnection"]) + ini = format_date(row["sesDateTimeConnection"]) # Disconnection DateTime - if row["ses_StillConnected"]: + if row["sesStillConnected"]: end = "..." - elif row["ses_EventTypeDisconnection"] == "": - end = row["ses_EventTypeDisconnection"] + elif row["sesEventTypeDisconnection"] == "": + end = row["sesEventTypeDisconnection"] else: - end = format_date(row["ses_DateTimeDisconnection"]) + end = format_date(row["sesDateTimeDisconnection"]) # Duration - if row["ses_EventTypeConnection"] in ("", None) or row[ - "ses_EventTypeDisconnection" + if row["sesEventTypeConnection"] in ("", None) or row[ + "sesEventTypeDisconnection" ] in ("", None): dur = "..." - elif row["ses_StillConnected"]: - dur = format_date_diff(row["ses_DateTimeConnection"], None, tz_name)["text"] + elif row["sesStillConnected"]: + dur = format_date_diff(row["sesDateTimeConnection"], None, tz_name)["text"] else: - dur = format_date_diff(row["ses_DateTimeConnection"], row["ses_DateTimeDisconnection"], tz_name)["text"] + dur = format_date_diff(row["sesDateTimeConnection"], row["sesDateTimeDisconnection"], tz_name)["text"] # Additional Info - info = row["ses_AdditionalInfo"] - if row["ses_EventTypeConnection"] == "New Device": - info = f"{row['ses_EventTypeConnection']}: {info}" + info = row["sesAdditionalInfo"] + if row["sesEventTypeConnection"] == "New Device": + info = f"{row['sesEventTypeConnection']}: {info}" # Push row data table_data["data"].append( { - "ses_MAC": mac, - "ses_DateTimeOrder": row["ses_DateTimeOrder"], - "ses_Connection": ini, - "ses_Disconnection": end, - "ses_Duration": dur, - "ses_IP": row["ses_IP"], - "ses_Info": info, + "sesMac": mac, + "sesDateTimeOrder": row["sesDateTimeOrder"], + "sesConnection": ini, + "sesDisconnection": end, + "sesDuration": dur, + "sesIp": row["sesIp"], + "sesInfo": info, } ) @@ -307,42 +307,42 @@ def get_session_events(event_type, period_date): # Base SQLs sql_events = f""" SELECT - eve_DateTime AS eve_DateTimeOrder, + eveDateTime AS eveDateTimeOrder, devName, devOwner, - eve_DateTime, - eve_EventType, + eveDateTime, + eveEventType, NULL, NULL, NULL, NULL, - eve_IP, + eveIp, NULL, - eve_AdditionalInfo, + eveAdditionalInfo, NULL, devMac, - eve_PendingAlertEmail + evePendingAlertEmail FROM Events_Devices - WHERE eve_DateTime >= {period_date} + WHERE eveDateTime >= {period_date} """ sql_sessions = """ SELECT - IFNULL(ses_DateTimeConnection, ses_DateTimeDisconnection) AS ses_DateTimeOrder, + IFNULL(sesDateTimeConnection, sesDateTimeDisconnection) AS sesDateTimeOrder, devName, devOwner, NULL, NULL, - ses_DateTimeConnection, - ses_DateTimeDisconnection, + sesDateTimeConnection, + sesDateTimeDisconnection, NULL, NULL, - ses_IP, + sesIp, NULL, - ses_AdditionalInfo, - ses_StillConnected, + sesAdditionalInfo, + sesStillConnected, devMac, - 0 AS ses_PendingAlertEmail + 0 AS sesPendingAlertEmail FROM Sessions_Devices """ @@ -353,9 +353,9 @@ def get_session_events(event_type, period_date): sql = ( sql_sessions + f""" WHERE ( - ses_DateTimeConnection >= {period_date} - OR ses_DateTimeDisconnection >= {period_date} - OR ses_StillConnected = 1 + sesDateTimeConnection >= {period_date} + OR sesDateTimeDisconnection >= {period_date} + OR sesStillConnected = 1 ) """ ) @@ -363,17 +363,17 @@ def get_session_events(event_type, period_date): sql = ( sql_sessions + f""" WHERE ( - (ses_DateTimeConnection IS NULL AND ses_DateTimeDisconnection >= {period_date}) - OR (ses_DateTimeDisconnection IS NULL AND ses_StillConnected = 0 AND ses_DateTimeConnection >= {period_date}) + (sesDateTimeConnection IS NULL AND sesDateTimeDisconnection >= {period_date}) + OR (sesDateTimeDisconnection IS NULL AND sesStillConnected = 0 AND sesDateTimeConnection >= {period_date}) ) """ ) elif event_type == "voided": - sql = sql_events + ' AND eve_EventType LIKE "VOIDED%"' + sql = sql_events + ' AND eveEventType LIKE "VOIDED%"' elif event_type == "new": - sql = sql_events + ' AND eve_EventType = "New Device"' + sql = sql_events + ' AND eveEventType = "New Device"' elif event_type == "down": - sql = sql_events + ' AND eve_EventType = "Device Down"' + sql = sql_events + ' AND eveEventType = "Device Down"' else: sql = sql_events + " AND 1=0" diff --git a/server/const.py b/server/const.py index f8ea4782..135102ec 100755 --- a/server/const.py +++ b/server/const.py @@ -67,7 +67,7 @@ sql_devices_all = """ FROM DevicesView """ -sql_appevents = """select * from AppEvents order by DateTimeCreated desc""" +sql_appevents = """select * from AppEvents order by dateTimeCreated desc""" # The below query calculates counts of devices in various categories: # (connected/online, offline, down, new, archived), # as well as a combined count for devices that match any status listed in the UI_MY_DEVICES setting @@ -141,32 +141,32 @@ sql_devices_filters = """ sql_devices_stats = f""" SELECT - Online_Devices as online, - Down_Devices as down, - All_Devices as 'all', - Archived_Devices as archived, + onlineDevices as online, + downDevices as down, + allDevices as 'all', + archivedDevices as archived, (SELECT COUNT(*) FROM Devices a WHERE devIsNew = 1) as new, (SELECT COUNT(*) FROM Devices a WHERE devName IN ({NULL_EQUIVALENTS_SQL}) OR devName IS NULL) as unknown FROM Online_History - ORDER BY Scan_Date DESC + ORDER BY scanDate DESC LIMIT 1 """ -sql_events_pending_alert = "SELECT * FROM Events where eve_PendingAlertEmail is not 0" +sql_events_pending_alert = "SELECT * FROM Events where evePendingAlertEmail is not 0" sql_settings = "SELECT * FROM Settings" sql_plugins_objects = "SELECT * FROM Plugins_Objects" sql_language_strings = "SELECT * FROM Plugins_Language_Strings" sql_notifications_all = "SELECT * FROM Notifications" sql_online_history = "SELECT * FROM Online_History" sql_plugins_events = "SELECT * FROM Plugins_Events" -sql_plugins_history = "SELECT * FROM Plugins_History ORDER BY DateTimeChanged DESC" +sql_plugins_history = "SELECT * FROM Plugins_History ORDER BY dateTimeChanged DESC" sql_new_devices = """SELECT * FROM ( - SELECT eve_IP as devLastIP, - eve_MAC as devMac, - MAX(eve_DateTime) as lastEvent + SELECT eveIp as devLastIP, + eveMac as devMac, + MAX(eveDateTime) as lastEvent FROM Events_Devices - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType = 'New Device' - GROUP BY eve_MAC + WHERE evePendingAlertEmail = 1 + AND eveEventType = 'New Device' + GROUP BY eveMac ORDER BY lastEvent ) t1 LEFT JOIN diff --git a/server/database.py b/server/database.py index 521e865b..c0c16d1d 100755 --- a/server/database.py +++ b/server/database.py @@ -16,6 +16,7 @@ from db.db_upgrade import ( ensure_Settings, ensure_Indexes, ensure_mac_lowercase_triggers, + migrate_to_camelcase, migrate_timestamps_to_utc, ) @@ -194,6 +195,10 @@ class DB: if not ensure_column(self.sql, "Devices", "devCanSleep", "INTEGER"): raise RuntimeError("ensure_column(devCanSleep) failed") + # CamelCase column migration (must run before UTC migration and + # before ensure_plugins_tables which uses IF NOT EXISTS with new names) + migrate_to_camelcase(self.sql) + # Settings table setup ensure_Settings(self.sql) diff --git a/server/db/db_upgrade.py b/server/db/db_upgrade.py index 55cda251..83739315 100755 --- a/server/db/db_upgrade.py +++ b/server/db/db_upgrade.py @@ -157,7 +157,7 @@ def ensure_views(sql) -> bool: sql.execute(""" CREATE VIEW Events_Devices AS SELECT * FROM Events - LEFT JOIN Devices ON eve_MAC = devMac; + LEFT JOIN Devices ON eveMac = devMac; """) sql.execute(""" DROP VIEW IF EXISTS LatestEventsPerMAC;""") @@ -165,7 +165,7 @@ def ensure_views(sql) -> bool: WITH RankedEvents AS ( SELECT e.*, - ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num + ROW_NUMBER() OVER (PARTITION BY e.eveMac ORDER BY e.eveDateTime DESC) AS row_num FROM Events AS e ) SELECT @@ -173,43 +173,43 @@ def ensure_views(sql) -> bool: d.*, c.* FROM RankedEvents AS e - LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - INNER JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac + LEFT JOIN Devices AS d ON e.eveMac = d.devMac + INNER JOIN CurrentScan AS c ON e.eveMac = c.scanMac WHERE e.row_num = 1;""") sql.execute(""" DROP VIEW IF EXISTS Sessions_Devices;""") sql.execute( - """CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON ses_MAC = devMac;""" + """CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON sesMac = devMac;""" ) # handling the Convert_Events_to_Sessions / Sessions screens sql.execute("""DROP VIEW IF EXISTS Convert_Events_to_Sessions;""") - sql.execute("""CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC, - EVE1.eve_IP, - EVE1.eve_EventType AS eve_EventTypeConnection, - EVE1.eve_DateTime AS eve_DateTimeConnection, - CASE WHEN EVE2.eve_EventType IN ('Disconnected', 'Device Down') OR - EVE2.eve_EventType IS NULL THEN EVE2.eve_EventType ELSE '' END AS eve_EventTypeDisconnection, - CASE WHEN EVE2.eve_EventType IN ('Disconnected', 'Device Down') THEN EVE2.eve_DateTime ELSE NULL END AS eve_DateTimeDisconnection, - CASE WHEN EVE2.eve_EventType IS NULL THEN 1 ELSE 0 END AS eve_StillConnected, - EVE1.eve_AdditionalInfo + sql.execute("""CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eveMac, + EVE1.eveIp, + EVE1.eveEventType AS eveEventTypeConnection, + EVE1.eveDateTime AS eveDateTimeConnection, + CASE WHEN EVE2.eveEventType IN ('Disconnected', 'Device Down') OR + EVE2.eveEventType IS NULL THEN EVE2.eveEventType ELSE '' END AS eveEventTypeDisconnection, + CASE WHEN EVE2.eveEventType IN ('Disconnected', 'Device Down') THEN EVE2.eveDateTime ELSE NULL END AS eveDateTimeDisconnection, + CASE WHEN EVE2.eveEventType IS NULL THEN 1 ELSE 0 END AS eveStillConnected, + EVE1.eveAdditionalInfo FROM Events AS EVE1 LEFT JOIN - Events AS EVE2 ON EVE1.eve_PairEventRowID = EVE2.RowID - WHERE EVE1.eve_EventType IN ('New Device', 'Connected','Down Reconnected') + Events AS EVE2 ON EVE1.evePairEventRowid = EVE2.RowID + WHERE EVE1.eveEventType IN ('New Device', 'Connected','Down Reconnected') UNION - SELECT eve_MAC, - eve_IP, - '' AS eve_EventTypeConnection, - NULL AS eve_DateTimeConnection, - eve_EventType AS eve_EventTypeDisconnection, - eve_DateTime AS eve_DateTimeDisconnection, - 0 AS eve_StillConnected, - eve_AdditionalInfo + SELECT eveMac, + eveIp, + '' AS eveEventTypeConnection, + NULL AS eveDateTimeConnection, + eveEventType AS eveEventTypeDisconnection, + eveDateTime AS eveDateTimeDisconnection, + 0 AS eveStillConnected, + eveAdditionalInfo FROM Events AS EVE1 - WHERE (eve_EventType = 'Device Down' OR - eve_EventType = 'Disconnected') AND - EVE1.eve_PairEventRowID IS NULL; + WHERE (eveEventType = 'Device Down' OR + eveEventType = 'Disconnected') AND + EVE1.evePairEventRowid IS NULL; """) sql.execute(""" DROP VIEW IF EXISTS LatestDeviceScan;""") @@ -316,10 +316,10 @@ def ensure_views(sql) -> bool: WHEN EXISTS ( SELECT 1 FROM Events e - WHERE LOWER(e.eve_MAC) = LOWER(Devices.devMac) - AND e.eve_EventType IN ('Connected','Disconnected','Device Down','Down Reconnected') - AND e.eve_DateTime >= datetime('now', '-{FLAP_WINDOW_HOURS} hours') - GROUP BY e.eve_MAC + WHERE LOWER(e.eveMac) = LOWER(Devices.devMac) + AND e.eveEventType IN ('Connected','Disconnected','Device Down','Down Reconnected') + AND e.eveDateTime >= datetime('now', '-{FLAP_WINDOW_HOURS} hours') + GROUP BY e.eveMac HAVING COUNT(*) >= {FLAP_THRESHOLD} ) THEN 1 @@ -360,10 +360,10 @@ def ensure_Indexes(sql) -> bool: SELECT MIN(rowid) FROM Events GROUP BY - eve_MAC, - eve_IP, - eve_EventType, - eve_DateTime + eveMac, + eveIp, + eveEventType, + eveDateTime ); """ @@ -373,32 +373,32 @@ def ensure_Indexes(sql) -> bool: # Sessions ( "idx_ses_mac_date", - "CREATE INDEX idx_ses_mac_date ON Sessions(ses_MAC, ses_DateTimeConnection, ses_DateTimeDisconnection, ses_StillConnected)", + "CREATE INDEX idx_ses_mac_date ON Sessions(sesMac, sesDateTimeConnection, sesDateTimeDisconnection, sesStillConnected)", ), # Events ( "idx_eve_mac_date_type", - "CREATE INDEX idx_eve_mac_date_type ON Events(eve_MAC, eve_DateTime, eve_EventType)", + "CREATE INDEX idx_eve_mac_date_type ON Events(eveMac, eveDateTime, eveEventType)", ), ( "idx_eve_alert_pending", - "CREATE INDEX idx_eve_alert_pending ON Events(eve_PendingAlertEmail)", + "CREATE INDEX idx_eve_alert_pending ON Events(evePendingAlertEmail)", ), ( "idx_eve_mac_datetime_desc", - "CREATE INDEX idx_eve_mac_datetime_desc ON Events(eve_MAC, eve_DateTime DESC)", + "CREATE INDEX idx_eve_mac_datetime_desc ON Events(eveMac, eveDateTime DESC)", ), ( "idx_eve_pairevent", - "CREATE INDEX idx_eve_pairevent ON Events(eve_PairEventRowID)", + "CREATE INDEX idx_eve_pairevent ON Events(evePairEventRowid)", ), ( "idx_eve_type_date", - "CREATE INDEX idx_eve_type_date ON Events(eve_EventType, eve_DateTime)", + "CREATE INDEX idx_eve_type_date ON Events(eveEventType, eveDateTime)", ), ( "idx_events_unique", - "CREATE UNIQUE INDEX idx_events_unique ON Events (eve_MAC, eve_IP, eve_EventType, eve_DateTime)", + "CREATE UNIQUE INDEX idx_events_unique ON Events (eveMac, eveIp, eveEventType, eveDateTime)", ), # Devices ("idx_dev_mac", "CREATE INDEX idx_dev_mac ON Devices(devMac)"), @@ -436,15 +436,15 @@ def ensure_Indexes(sql) -> bool: # Plugins_Objects ( "idx_plugins_plugin_mac_ip", - "CREATE INDEX idx_plugins_plugin_mac_ip ON Plugins_Objects(Plugin, Object_PrimaryID, Object_SecondaryID)", + "CREATE INDEX idx_plugins_plugin_mac_ip ON Plugins_Objects(plugin, objectPrimaryId, objectSecondaryId)", ), # Issue #1251: Optimize name resolution lookup # Plugins_History: covers both the db_cleanup window function - # (PARTITION BY Plugin ORDER BY DateTimeChanged DESC) and the - # API query (SELECT * … ORDER BY DateTimeChanged DESC). + # (PARTITION BY plugin ORDER BY dateTimeChanged DESC) and the + # API query (SELECT * … ORDER BY dateTimeChanged DESC). # Without this, both ops do a full 48k-row table sort on every cycle. ( "idx_plugins_history_plugin_dt", - "CREATE INDEX idx_plugins_history_plugin_dt ON Plugins_History(Plugin, DateTimeChanged DESC)", + "CREATE INDEX idx_plugins_history_plugin_dt ON Plugins_History(plugin, dateTimeChanged DESC)", ), ] @@ -547,94 +547,295 @@ def ensure_plugins_tables(sql) -> bool: # Plugin state sql_Plugins_Objects = """ CREATE TABLE IF NOT EXISTS Plugins_Objects( - "Index" INTEGER, - Plugin TEXT NOT NULL, - Object_PrimaryID TEXT NOT NULL, - Object_SecondaryID TEXT NOT NULL, - DateTimeCreated TEXT NOT NULL, - DateTimeChanged TEXT NOT NULL, - Watched_Value1 TEXT NOT NULL, - Watched_Value2 TEXT NOT NULL, - Watched_Value3 TEXT NOT NULL, - Watched_Value4 TEXT NOT NULL, - Status TEXT NOT NULL, - Extra TEXT NOT NULL, - UserData TEXT NOT NULL, - ForeignKey TEXT NOT NULL, - SyncHubNodeName TEXT, - "HelpVal1" TEXT, - "HelpVal2" TEXT, - "HelpVal3" TEXT, - "HelpVal4" TEXT, - ObjectGUID TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + plugin TEXT NOT NULL, + objectPrimaryId TEXT NOT NULL, + objectSecondaryId TEXT NOT NULL, + dateTimeCreated TEXT NOT NULL, + dateTimeChanged TEXT NOT NULL, + watchedValue1 TEXT NOT NULL, + watchedValue2 TEXT NOT NULL, + watchedValue3 TEXT NOT NULL, + watchedValue4 TEXT NOT NULL, + "status" TEXT NOT NULL, + extra TEXT NOT NULL, + userData TEXT NOT NULL, + foreignKey TEXT NOT NULL, + syncHubNodeName TEXT, + helpVal1 TEXT, + helpVal2 TEXT, + helpVal3 TEXT, + helpVal4 TEXT, + objectGuid TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); """ sql.execute(sql_Plugins_Objects) # Plugin execution results sql_Plugins_Events = """ CREATE TABLE IF NOT EXISTS Plugins_Events( - "Index" INTEGER, - Plugin TEXT NOT NULL, - Object_PrimaryID TEXT NOT NULL, - Object_SecondaryID TEXT NOT NULL, - DateTimeCreated TEXT NOT NULL, - DateTimeChanged TEXT NOT NULL, - Watched_Value1 TEXT NOT NULL, - Watched_Value2 TEXT NOT NULL, - Watched_Value3 TEXT NOT NULL, - Watched_Value4 TEXT NOT NULL, - Status TEXT NOT NULL, - Extra TEXT NOT NULL, - UserData TEXT NOT NULL, - ForeignKey TEXT NOT NULL, - SyncHubNodeName TEXT, - "HelpVal1" TEXT, - "HelpVal2" TEXT, - "HelpVal3" TEXT, - "HelpVal4" TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + plugin TEXT NOT NULL, + objectPrimaryId TEXT NOT NULL, + objectSecondaryId TEXT NOT NULL, + dateTimeCreated TEXT NOT NULL, + dateTimeChanged TEXT NOT NULL, + watchedValue1 TEXT NOT NULL, + watchedValue2 TEXT NOT NULL, + watchedValue3 TEXT NOT NULL, + watchedValue4 TEXT NOT NULL, + "status" TEXT NOT NULL, + extra TEXT NOT NULL, + userData TEXT NOT NULL, + foreignKey TEXT NOT NULL, + syncHubNodeName TEXT, + helpVal1 TEXT, + helpVal2 TEXT, + helpVal3 TEXT, + helpVal4 TEXT, + objectGuid TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); """ sql.execute(sql_Plugins_Events) # Plugin execution history sql_Plugins_History = """ CREATE TABLE IF NOT EXISTS Plugins_History( - "Index" INTEGER, - Plugin TEXT NOT NULL, - Object_PrimaryID TEXT NOT NULL, - Object_SecondaryID TEXT NOT NULL, - DateTimeCreated TEXT NOT NULL, - DateTimeChanged TEXT NOT NULL, - Watched_Value1 TEXT NOT NULL, - Watched_Value2 TEXT NOT NULL, - Watched_Value3 TEXT NOT NULL, - Watched_Value4 TEXT NOT NULL, - Status TEXT NOT NULL, - Extra TEXT NOT NULL, - UserData TEXT NOT NULL, - ForeignKey TEXT NOT NULL, - SyncHubNodeName TEXT, - "HelpVal1" TEXT, - "HelpVal2" TEXT, - "HelpVal3" TEXT, - "HelpVal4" TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + plugin TEXT NOT NULL, + objectPrimaryId TEXT NOT NULL, + objectSecondaryId TEXT NOT NULL, + dateTimeCreated TEXT NOT NULL, + dateTimeChanged TEXT NOT NULL, + watchedValue1 TEXT NOT NULL, + watchedValue2 TEXT NOT NULL, + watchedValue3 TEXT NOT NULL, + watchedValue4 TEXT NOT NULL, + "status" TEXT NOT NULL, + extra TEXT NOT NULL, + userData TEXT NOT NULL, + foreignKey TEXT NOT NULL, + syncHubNodeName TEXT, + helpVal1 TEXT, + helpVal2 TEXT, + helpVal3 TEXT, + helpVal4 TEXT, + objectGuid TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); """ sql.execute(sql_Plugins_History) # Dynamically generated language strings sql.execute("DROP TABLE IF EXISTS Plugins_Language_Strings;") sql.execute(""" CREATE TABLE IF NOT EXISTS Plugins_Language_Strings( - "Index" INTEGER, - Language_Code TEXT NOT NULL, - String_Key TEXT NOT NULL, - String_Value TEXT NOT NULL, - Extra TEXT NOT NULL, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + languageCode TEXT NOT NULL, + stringKey TEXT NOT NULL, + stringValue TEXT NOT NULL, + extra TEXT NOT NULL, + PRIMARY KEY("index" AUTOINCREMENT) ); """) return True +# =============================================================================== +# CamelCase Column Migration +# =============================================================================== + +# Mapping of (table_name, old_column_name) → new_column_name. +# Only entries where the name actually changes are listed. +# Columns like "Index" → "index" are cosmetic case changes handled +# implicitly by SQLite's case-insensitive matching. +_CAMELCASE_COLUMN_MAP = { + "Events": { + "eve_MAC": "eveMac", + "eve_IP": "eveIp", + "eve_DateTime": "eveDateTime", + "eve_EventType": "eveEventType", + "eve_AdditionalInfo": "eveAdditionalInfo", + "eve_PendingAlertEmail": "evePendingAlertEmail", + "eve_PairEventRowid": "evePairEventRowid", + "eve_PairEventRowID": "evePairEventRowid", + }, + "Sessions": { + "ses_MAC": "sesMac", + "ses_IP": "sesIp", + "ses_EventTypeConnection": "sesEventTypeConnection", + "ses_DateTimeConnection": "sesDateTimeConnection", + "ses_EventTypeDisconnection": "sesEventTypeDisconnection", + "ses_DateTimeDisconnection": "sesDateTimeDisconnection", + "ses_StillConnected": "sesStillConnected", + "ses_AdditionalInfo": "sesAdditionalInfo", + }, + "Online_History": { + "Index": "index", + "Scan_Date": "scanDate", + "Online_Devices": "onlineDevices", + "Down_Devices": "downDevices", + "All_Devices": "allDevices", + "Archived_Devices": "archivedDevices", + "Offline_Devices": "offlineDevices", + }, + "Plugins_Objects": { + "Index": "index", + "Plugin": "plugin", + "Object_PrimaryID": "objectPrimaryId", + "Object_SecondaryID": "objectSecondaryId", + "DateTimeCreated": "dateTimeCreated", + "DateTimeChanged": "dateTimeChanged", + "Watched_Value1": "watchedValue1", + "Watched_Value2": "watchedValue2", + "Watched_Value3": "watchedValue3", + "Watched_Value4": "watchedValue4", + "Status": "status", + "Extra": "extra", + "UserData": "userData", + "ForeignKey": "foreignKey", + "SyncHubNodeName": "syncHubNodeName", + "HelpVal1": "helpVal1", + "HelpVal2": "helpVal2", + "HelpVal3": "helpVal3", + "HelpVal4": "helpVal4", + "ObjectGUID": "objectGuid", + }, + "Plugins_Events": { + "Index": "index", + "Plugin": "plugin", + "Object_PrimaryID": "objectPrimaryId", + "Object_SecondaryID": "objectSecondaryId", + "DateTimeCreated": "dateTimeCreated", + "DateTimeChanged": "dateTimeChanged", + "Watched_Value1": "watchedValue1", + "Watched_Value2": "watchedValue2", + "Watched_Value3": "watchedValue3", + "Watched_Value4": "watchedValue4", + "Status": "status", + "Extra": "extra", + "UserData": "userData", + "ForeignKey": "foreignKey", + "SyncHubNodeName": "syncHubNodeName", + "HelpVal1": "helpVal1", + "HelpVal2": "helpVal2", + "HelpVal3": "helpVal3", + "HelpVal4": "helpVal4", + "ObjectGUID": "objectGuid", + }, + "Plugins_History": { + "Index": "index", + "Plugin": "plugin", + "Object_PrimaryID": "objectPrimaryId", + "Object_SecondaryID": "objectSecondaryId", + "DateTimeCreated": "dateTimeCreated", + "DateTimeChanged": "dateTimeChanged", + "Watched_Value1": "watchedValue1", + "Watched_Value2": "watchedValue2", + "Watched_Value3": "watchedValue3", + "Watched_Value4": "watchedValue4", + "Status": "status", + "Extra": "extra", + "UserData": "userData", + "ForeignKey": "foreignKey", + "SyncHubNodeName": "syncHubNodeName", + "HelpVal1": "helpVal1", + "HelpVal2": "helpVal2", + "HelpVal3": "helpVal3", + "HelpVal4": "helpVal4", + "ObjectGUID": "objectGuid", + }, + "Plugins_Language_Strings": { + "Index": "index", + "Language_Code": "languageCode", + "String_Key": "stringKey", + "String_Value": "stringValue", + "Extra": "extra", + }, + "AppEvents": { + "Index": "index", + "GUID": "guid", + "AppEventProcessed": "appEventProcessed", + "DateTimeCreated": "dateTimeCreated", + "ObjectType": "objectType", + "ObjectGUID": "objectGuid", + "ObjectPlugin": "objectPlugin", + "ObjectPrimaryID": "objectPrimaryId", + "ObjectSecondaryID": "objectSecondaryId", + "ObjectForeignKey": "objectForeignKey", + "ObjectIndex": "objectIndex", + "ObjectIsNew": "objectIsNew", + "ObjectIsArchived": "objectIsArchived", + "ObjectStatusColumn": "objectStatusColumn", + "ObjectStatus": "objectStatus", + "AppEventType": "appEventType", + "Helper1": "helper1", + "Helper2": "helper2", + "Helper3": "helper3", + "Extra": "extra", + }, + "Notifications": { + "Index": "index", + "GUID": "guid", + "DateTimeCreated": "dateTimeCreated", + "DateTimePushed": "dateTimePushed", + "Status": "status", + "JSON": "json", + "Text": "text", + "HTML": "html", + "PublishedVia": "publishedVia", + "Extra": "extra", + }, +} + + +def migrate_to_camelcase(sql) -> bool: + """ + Detects legacy (underscore/PascalCase) column names and renames them + to camelCase using ALTER TABLE … RENAME COLUMN (SQLite ≥ 3.25.0). + + Idempotent: columns already matching the new name are silently skipped. + """ + + # Quick probe: if Events table has 'eveMac' we're already on the new schema + sql.execute('PRAGMA table_info("Events")') + events_cols = {row[1] for row in sql.fetchall()} + if "eveMac" in events_cols: + mylog("verbose", ["[db_upgrade] Schema already uses camelCase — skipping migration"]) + return True + + if "eve_MAC" not in events_cols: + # Events table doesn't exist or has unexpected schema — skip silently + mylog("verbose", ["[db_upgrade] Events table missing/unrecognised — skipping camelCase migration"]) + return True + + mylog("none", ["[db_upgrade] Starting camelCase column migration …"]) + + # Drop views first — ALTER TABLE RENAME COLUMN will fail if a view + # references the old column name and the view SQL cannot be rewritten. + for view_name in ("Events_Devices", "LatestEventsPerMAC", "Sessions_Devices", + "Convert_Events_to_Sessions", "LatestDeviceScan", "DevicesView"): + sql.execute(f"DROP VIEW IF EXISTS {view_name};") + + renamed_count = 0 + + for table, column_map in _CAMELCASE_COLUMN_MAP.items(): + # Check table exists + sql.execute(f"SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table,)) + if not sql.fetchone(): + mylog("verbose", [f"[db_upgrade] Table '{table}' does not exist — skipping"]) + continue + + # Get current column names (case-preserved) + sql.execute(f'PRAGMA table_info("{table}")') + current_cols = {row[1] for row in sql.fetchall()} + + for old_name, new_name in column_map.items(): + if old_name in current_cols and new_name not in current_cols: + sql.execute(f'ALTER TABLE "{table}" RENAME COLUMN "{old_name}" TO "{new_name}"') + renamed_count += 1 + mylog("verbose", [f"[db_upgrade] {table}.{old_name} → {new_name}"]) + + mylog("none", [f"[db_upgrade] ✓ camelCase migration complete — {renamed_count} columns renamed"]) + return True + + # =============================================================================== # UTC Timestamp Migration (added 2026-02-10) # =============================================================================== @@ -817,17 +1018,18 @@ def migrate_timestamps_to_utc(sql) -> bool: mylog("verbose", f"[db_upgrade] Starting UTC timestamp migration (offset: {offset_hours} hours)") - # List of tables and their datetime columns + # List of tables and their datetime columns (camelCase names — + # migrate_to_camelcase() runs before this function). timestamp_columns = { 'Devices': ['devFirstConnection', 'devLastConnection', 'devLastNotification'], - 'Events': ['eve_DateTime'], - 'Sessions': ['ses_DateTimeConnection', 'ses_DateTimeDisconnection'], - 'Notifications': ['DateTimeCreated', 'DateTimePushed'], - 'Online_History': ['Scan_Date'], - 'Plugins_Objects': ['DateTimeCreated', 'DateTimeChanged'], - 'Plugins_Events': ['DateTimeCreated', 'DateTimeChanged'], - 'Plugins_History': ['DateTimeCreated', 'DateTimeChanged'], - 'AppEvents': ['DateTimeCreated'], + 'Events': ['eveDateTime'], + 'Sessions': ['sesDateTimeConnection', 'sesDateTimeDisconnection'], + 'Notifications': ['dateTimeCreated', 'dateTimePushed'], + 'Online_History': ['scanDate'], + 'Plugins_Objects': ['dateTimeCreated', 'dateTimeChanged'], + 'Plugins_Events': ['dateTimeCreated', 'dateTimeChanged'], + 'Plugins_History': ['dateTimeCreated', 'dateTimeChanged'], + 'AppEvents': ['dateTimeCreated'], } for table, columns in timestamp_columns.items(): diff --git a/server/db/schema/app.sql b/server/db/schema/app.sql index e3b51763..dffd27b1 100644 --- a/server/db/schema/app.sql +++ b/server/db/schema/app.sql @@ -1,14 +1,14 @@ -CREATE TABLE Events (eve_MAC STRING (50) NOT NULL COLLATE NOCASE, eve_IP STRING (50) NOT NULL COLLATE NOCASE, eve_DateTime DATETIME NOT NULL, eve_EventType STRING (30) NOT NULL COLLATE NOCASE, eve_AdditionalInfo STRING (250) DEFAULT (''), eve_PendingAlertEmail BOOLEAN NOT NULL CHECK (eve_PendingAlertEmail IN (0, 1)) DEFAULT (1), eve_PairEventRowid INTEGER); -CREATE TABLE Sessions (ses_MAC STRING (50) COLLATE NOCASE, ses_IP STRING (50) COLLATE NOCASE, ses_EventTypeConnection STRING (30) COLLATE NOCASE, ses_DateTimeConnection DATETIME, ses_EventTypeDisconnection STRING (30) COLLATE NOCASE, ses_DateTimeDisconnection DATETIME, ses_StillConnected BOOLEAN, ses_AdditionalInfo STRING (250)); -CREATE TABLE IF NOT EXISTS "Online_History" ( - "Index" INTEGER, - "Scan_Date" TEXT, - "Online_Devices" INTEGER, - "Down_Devices" INTEGER, - "All_Devices" INTEGER, - "Archived_Devices" INTEGER, - "Offline_Devices" INTEGER, - PRIMARY KEY("Index" AUTOINCREMENT) +CREATE TABLE Events (eveMac STRING (50) NOT NULL COLLATE NOCASE, eveIp STRING (50) NOT NULL COLLATE NOCASE, eveDateTime DATETIME NOT NULL, eveEventType STRING (30) NOT NULL COLLATE NOCASE, eveAdditionalInfo STRING (250) DEFAULT (''), evePendingAlertEmail BOOLEAN NOT NULL CHECK (evePendingAlertEmail IN (0, 1)) DEFAULT (1), evePairEventRowid INTEGER); +CREATE TABLE Sessions (sesMac STRING (50) COLLATE NOCASE, sesIp STRING (50) COLLATE NOCASE, sesEventTypeConnection STRING (30) COLLATE NOCASE, sesDateTimeConnection DATETIME, sesEventTypeDisconnection STRING (30) COLLATE NOCASE, sesDateTimeDisconnection DATETIME, sesStillConnected BOOLEAN, sesAdditionalInfo STRING (250)); +CREATE TABLE IF NOT EXISTS Online_History ( + "index" INTEGER, + scanDate TEXT, + onlineDevices INTEGER, + downDevices INTEGER, + allDevices INTEGER, + archivedDevices INTEGER, + offlineDevices INTEGER, + PRIMARY KEY("index" AUTOINCREMENT) ); CREATE TABLE Devices ( devMac STRING (50) PRIMARY KEY NOT NULL COLLATE NOCASE, @@ -57,96 +57,98 @@ CREATE TABLE Devices ( devParentPortSource TEXT, devParentRelTypeSource TEXT, devVlanSource TEXT, - "devCustomProps" TEXT); -CREATE TABLE IF NOT EXISTS "Settings" ( - "setKey" TEXT, - "setName" TEXT, - "setDescription" TEXT, - "setType" TEXT, - "setOptions" TEXT, - "setGroup" TEXT, - "setValue" TEXT, - "setEvents" TEXT, - "setOverriddenByEnv" INTEGER + devCustomProps TEXT); +CREATE TABLE IF NOT EXISTS Settings ( + setKey TEXT, + setName TEXT, + setDescription TEXT, + setType TEXT, + setOptions TEXT, + setGroup TEXT, + setValue TEXT, + setEvents TEXT, + setOverriddenByEnv INTEGER ); -CREATE TABLE IF NOT EXISTS "Parameters" ( - "parID" TEXT PRIMARY KEY, - "parValue" TEXT +CREATE TABLE IF NOT EXISTS Parameters ( + parID TEXT PRIMARY KEY, + parValue TEXT ); CREATE TABLE Plugins_Objects( - "Index" INTEGER, - Plugin TEXT NOT NULL, - Object_PrimaryID TEXT NOT NULL, - Object_SecondaryID TEXT NOT NULL, - DateTimeCreated TEXT NOT NULL, - DateTimeChanged TEXT NOT NULL, - Watched_Value1 TEXT NOT NULL, - Watched_Value2 TEXT NOT NULL, - Watched_Value3 TEXT NOT NULL, - Watched_Value4 TEXT NOT NULL, - Status TEXT NOT NULL, - Extra TEXT NOT NULL, - UserData TEXT NOT NULL, - ForeignKey TEXT NOT NULL, - SyncHubNodeName TEXT, - "HelpVal1" TEXT, - "HelpVal2" TEXT, - "HelpVal3" TEXT, - "HelpVal4" TEXT, - ObjectGUID TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + plugin TEXT NOT NULL, + objectPrimaryId TEXT NOT NULL, + objectSecondaryId TEXT NOT NULL, + dateTimeCreated TEXT NOT NULL, + dateTimeChanged TEXT NOT NULL, + watchedValue1 TEXT NOT NULL, + watchedValue2 TEXT NOT NULL, + watchedValue3 TEXT NOT NULL, + watchedValue4 TEXT NOT NULL, + "status" TEXT NOT NULL, + extra TEXT NOT NULL, + userData TEXT NOT NULL, + foreignKey TEXT NOT NULL, + syncHubNodeName TEXT, + helpVal1 TEXT, + helpVal2 TEXT, + helpVal3 TEXT, + helpVal4 TEXT, + objectGuid TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); CREATE TABLE Plugins_Events( - "Index" INTEGER, - Plugin TEXT NOT NULL, - Object_PrimaryID TEXT NOT NULL, - Object_SecondaryID TEXT NOT NULL, - DateTimeCreated TEXT NOT NULL, - DateTimeChanged TEXT NOT NULL, - Watched_Value1 TEXT NOT NULL, - Watched_Value2 TEXT NOT NULL, - Watched_Value3 TEXT NOT NULL, - Watched_Value4 TEXT NOT NULL, - Status TEXT NOT NULL, - Extra TEXT NOT NULL, - UserData TEXT NOT NULL, - ForeignKey TEXT NOT NULL, - SyncHubNodeName TEXT, - "HelpVal1" TEXT, - "HelpVal2" TEXT, - "HelpVal3" TEXT, - "HelpVal4" TEXT, "ObjectGUID" TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + plugin TEXT NOT NULL, + objectPrimaryId TEXT NOT NULL, + objectSecondaryId TEXT NOT NULL, + dateTimeCreated TEXT NOT NULL, + dateTimeChanged TEXT NOT NULL, + watchedValue1 TEXT NOT NULL, + watchedValue2 TEXT NOT NULL, + watchedValue3 TEXT NOT NULL, + watchedValue4 TEXT NOT NULL, + "status" TEXT NOT NULL, + extra TEXT NOT NULL, + userData TEXT NOT NULL, + foreignKey TEXT NOT NULL, + syncHubNodeName TEXT, + helpVal1 TEXT, + helpVal2 TEXT, + helpVal3 TEXT, + helpVal4 TEXT, + objectGuid TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); CREATE TABLE Plugins_History( - "Index" INTEGER, - Plugin TEXT NOT NULL, - Object_PrimaryID TEXT NOT NULL, - Object_SecondaryID TEXT NOT NULL, - DateTimeCreated TEXT NOT NULL, - DateTimeChanged TEXT NOT NULL, - Watched_Value1 TEXT NOT NULL, - Watched_Value2 TEXT NOT NULL, - Watched_Value3 TEXT NOT NULL, - Watched_Value4 TEXT NOT NULL, - Status TEXT NOT NULL, - Extra TEXT NOT NULL, - UserData TEXT NOT NULL, - ForeignKey TEXT NOT NULL, - SyncHubNodeName TEXT, - "HelpVal1" TEXT, - "HelpVal2" TEXT, - "HelpVal3" TEXT, - "HelpVal4" TEXT, "ObjectGUID" TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + plugin TEXT NOT NULL, + objectPrimaryId TEXT NOT NULL, + objectSecondaryId TEXT NOT NULL, + dateTimeCreated TEXT NOT NULL, + dateTimeChanged TEXT NOT NULL, + watchedValue1 TEXT NOT NULL, + watchedValue2 TEXT NOT NULL, + watchedValue3 TEXT NOT NULL, + watchedValue4 TEXT NOT NULL, + "status" TEXT NOT NULL, + extra TEXT NOT NULL, + userData TEXT NOT NULL, + foreignKey TEXT NOT NULL, + syncHubNodeName TEXT, + helpVal1 TEXT, + helpVal2 TEXT, + helpVal3 TEXT, + helpVal4 TEXT, + objectGuid TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); CREATE TABLE Plugins_Language_Strings( - "Index" INTEGER, - Language_Code TEXT NOT NULL, - String_Key TEXT NOT NULL, - String_Value TEXT NOT NULL, - Extra TEXT NOT NULL, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + languageCode TEXT NOT NULL, + stringKey TEXT NOT NULL, + stringValue TEXT NOT NULL, + extra TEXT NOT NULL, + PRIMARY KEY("index" AUTOINCREMENT) ); CREATE TABLE CurrentScan ( scanMac STRING(50) NOT NULL COLLATE NOCASE, @@ -165,50 +167,50 @@ CREATE TABLE CurrentScan ( scanType STRING(250), UNIQUE(scanMac) ); -CREATE TABLE IF NOT EXISTS "AppEvents" ( - "Index" INTEGER PRIMARY KEY AUTOINCREMENT, - "GUID" TEXT UNIQUE, - "AppEventProcessed" BOOLEAN, - "DateTimeCreated" TEXT, - "ObjectType" TEXT, - "ObjectGUID" TEXT, - "ObjectPlugin" TEXT, - "ObjectPrimaryID" TEXT, - "ObjectSecondaryID" TEXT, - "ObjectForeignKey" TEXT, - "ObjectIndex" TEXT, - "ObjectIsNew" BOOLEAN, - "ObjectIsArchived" BOOLEAN, - "ObjectStatusColumn" TEXT, - "ObjectStatus" TEXT, - "AppEventType" TEXT, - "Helper1" TEXT, - "Helper2" TEXT, - "Helper3" TEXT, - "Extra" TEXT +CREATE TABLE IF NOT EXISTS AppEvents ( + "index" INTEGER PRIMARY KEY AUTOINCREMENT, + guid TEXT UNIQUE, + appEventProcessed BOOLEAN, + dateTimeCreated TEXT, + objectType TEXT, + objectGuid TEXT, + objectPlugin TEXT, + objectPrimaryId TEXT, + objectSecondaryId TEXT, + objectForeignKey TEXT, + objectIndex TEXT, + objectIsNew BOOLEAN, + objectIsArchived BOOLEAN, + objectStatusColumn TEXT, + objectStatus TEXT, + appEventType TEXT, + helper1 TEXT, + helper2 TEXT, + helper3 TEXT, + extra TEXT ); -CREATE TABLE IF NOT EXISTS "Notifications" ( - "Index" INTEGER, - "GUID" TEXT UNIQUE, - "DateTimeCreated" TEXT, - "DateTimePushed" TEXT, - "Status" TEXT, - "JSON" TEXT, - "Text" TEXT, - "HTML" TEXT, - "PublishedVia" TEXT, - "Extra" TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) +CREATE TABLE IF NOT EXISTS Notifications ( + "index" INTEGER, + guid TEXT UNIQUE, + dateTimeCreated TEXT, + dateTimePushed TEXT, + "status" TEXT, + "json" TEXT, + "text" TEXT, + html TEXT, + publishedVia TEXT, + extra TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); -CREATE INDEX IDX_eve_DateTime ON Events (eve_DateTime); -CREATE INDEX IDX_eve_EventType ON Events (eve_EventType COLLATE NOCASE); -CREATE INDEX IDX_eve_MAC ON Events (eve_MAC COLLATE NOCASE); -CREATE INDEX IDX_eve_PairEventRowid ON Events (eve_PairEventRowid); -CREATE INDEX IDX_ses_EventTypeDisconnection ON Sessions (ses_EventTypeDisconnection COLLATE NOCASE); -CREATE INDEX IDX_ses_EventTypeConnection ON Sessions (ses_EventTypeConnection COLLATE NOCASE); -CREATE INDEX IDX_ses_DateTimeDisconnection ON Sessions (ses_DateTimeDisconnection); -CREATE INDEX IDX_ses_MAC ON Sessions (ses_MAC COLLATE NOCASE); -CREATE INDEX IDX_ses_DateTimeConnection ON Sessions (ses_DateTimeConnection); +CREATE INDEX IDX_eve_DateTime ON Events (eveDateTime); +CREATE INDEX IDX_eve_EventType ON Events (eveEventType COLLATE NOCASE); +CREATE INDEX IDX_eve_MAC ON Events (eveMac COLLATE NOCASE); +CREATE INDEX IDX_eve_PairEventRowid ON Events (evePairEventRowid); +CREATE INDEX IDX_ses_EventTypeDisconnection ON Sessions (sesEventTypeDisconnection COLLATE NOCASE); +CREATE INDEX IDX_ses_EventTypeConnection ON Sessions (sesEventTypeConnection COLLATE NOCASE); +CREATE INDEX IDX_ses_DateTimeDisconnection ON Sessions (sesDateTimeDisconnection); +CREATE INDEX IDX_ses_MAC ON Sessions (sesMac COLLATE NOCASE); +CREATE INDEX IDX_ses_DateTimeConnection ON Sessions (sesDateTimeConnection); CREATE INDEX IDX_dev_PresentLastScan ON Devices (devPresentLastScan); CREATE INDEX IDX_dev_FirstConnection ON Devices (devFirstConnection); CREATE INDEX IDX_dev_AlertDeviceDown ON Devices (devAlertDown); @@ -220,21 +222,20 @@ CREATE INDEX IDX_dev_NewDevice ON Devices (devIsNew); CREATE INDEX IDX_dev_Archived ON Devices (devIsArchived); CREATE UNIQUE INDEX IF NOT EXISTS idx_events_unique ON Events ( - eve_MAC, - eve_IP, - eve_EventType, - eve_DateTime + eveMac, + eveIp, + eveEventType, + eveDateTime ); CREATE VIEW Events_Devices AS SELECT * FROM Events - LEFT JOIN Devices ON eve_MAC = devMac -/* Events_Devices(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps) */; + LEFT JOIN Devices ON eveMac = devMac; CREATE VIEW LatestEventsPerMAC AS WITH RankedEvents AS ( SELECT e.*, - ROW_NUMBER() OVER (PARTITION BY e.eve_MAC ORDER BY e.eve_DateTime DESC) AS row_num + ROW_NUMBER() OVER (PARTITION BY e.eveMac ORDER BY e.eveDateTime DESC) AS row_num FROM Events AS e ) SELECT @@ -242,192 +243,33 @@ CREATE VIEW LatestEventsPerMAC AS d.*, c.* FROM RankedEvents AS e - LEFT JOIN Devices AS d ON e.eve_MAC = d.devMac - INNER JOIN CurrentScan AS c ON e.eve_MAC = c.scanMac - WHERE e.row_num = 1 -/* LatestEventsPerMAC(eve_MAC,eve_IP,eve_DateTime,eve_EventType,eve_AdditionalInfo,eve_PendingAlertEmail,eve_PairEventRowid,row_num,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps,scanMac,scanLastIP,scanVendor,scanSourcePlugin,scanName,scanLastQuery,scanLastConnection,scanSyncHubNode,scanSite,scanSSID,scanParentMAC,scanParentPort,scanType) */; -CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN "Devices" ON ses_MAC = devMac -/* Sessions_Devices(ses_MAC,ses_IP,ses_EventTypeConnection,ses_DateTimeConnection,ses_EventTypeDisconnection,ses_DateTimeDisconnection,ses_StillConnected,ses_AdditionalInfo,devMac,devName,devOwner,devType,devVendor,devFavorite,devGroup,devComments,devFirstConnection,devLastConnection,devLastIP,devStaticIP,devScan,devLogEvents,devAlertEvents,devAlertDown,devSkipRepeated,devLastNotification,devPresentLastScan,devIsNew,devLocation,devIsArchived,devParentMAC,devParentPort,devIcon,devGUID,devSite,devSSID,devSyncHubNode,devSourcePlugin,devCustomProps) */; -CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eve_MAC, - EVE1.eve_IP, - EVE1.eve_EventType AS eve_EventTypeConnection, - EVE1.eve_DateTime AS eve_DateTimeConnection, - CASE WHEN EVE2.eve_EventType IN ('Disconnected', 'Device Down') OR - EVE2.eve_EventType IS NULL THEN EVE2.eve_EventType ELSE '' END AS eve_EventTypeDisconnection, - CASE WHEN EVE2.eve_EventType IN ('Disconnected', 'Device Down') THEN EVE2.eve_DateTime ELSE NULL END AS eve_DateTimeDisconnection, - CASE WHEN EVE2.eve_EventType IS NULL THEN 1 ELSE 0 END AS eve_StillConnected, - EVE1.eve_AdditionalInfo + LEFT JOIN Devices AS d ON e.eveMac = d.devMac + INNER JOIN CurrentScan AS c ON e.eveMac = c.scanMac + WHERE e.row_num = 1; +CREATE VIEW Sessions_Devices AS SELECT * FROM Sessions LEFT JOIN Devices ON sesMac = devMac; +CREATE VIEW Convert_Events_to_Sessions AS SELECT EVE1.eveMac, + EVE1.eveIp, + EVE1.eveEventType AS eveEventTypeConnection, + EVE1.eveDateTime AS eveDateTimeConnection, + CASE WHEN EVE2.eveEventType IN ('Disconnected', 'Device Down') OR + EVE2.eveEventType IS NULL THEN EVE2.eveEventType ELSE '' END AS eveEventTypeDisconnection, + CASE WHEN EVE2.eveEventType IN ('Disconnected', 'Device Down') THEN EVE2.eveDateTime ELSE NULL END AS eveDateTimeDisconnection, + CASE WHEN EVE2.eveEventType IS NULL THEN 1 ELSE 0 END AS eveStillConnected, + EVE1.eveAdditionalInfo FROM Events AS EVE1 LEFT JOIN - Events AS EVE2 ON EVE1.eve_PairEventRowID = EVE2.RowID - WHERE EVE1.eve_EventType IN ('New Device', 'Connected','Down Reconnected') + Events AS EVE2 ON EVE1.evePairEventRowid = EVE2.RowID + WHERE EVE1.eveEventType IN ('New Device', 'Connected','Down Reconnected') UNION - SELECT eve_MAC, - eve_IP, - '' AS eve_EventTypeConnection, - NULL AS eve_DateTimeConnection, - eve_EventType AS eve_EventTypeDisconnection, - eve_DateTime AS eve_DateTimeDisconnection, - 0 AS eve_StillConnected, - eve_AdditionalInfo + SELECT eveMac, + eveIp, + '' AS eveEventTypeConnection, + NULL AS eveDateTimeConnection, + eveEventType AS eveEventTypeDisconnection, + eveDateTime AS eveDateTimeDisconnection, + 0 AS eveStillConnected, + eveAdditionalInfo FROM Events AS EVE1 - WHERE (eve_EventType = 'Device Down' OR - eve_EventType = 'Disconnected') AND - EVE1.eve_PairEventRowID IS NULL -/* Convert_Events_to_Sessions(eve_MAC,eve_IP,eve_EventTypeConnection,eve_DateTimeConnection,eve_EventTypeDisconnection,eve_DateTimeDisconnection,eve_StillConnected,eve_AdditionalInfo) */; -CREATE TRIGGER "trg_insert_devices" - AFTER INSERT ON "Devices" - WHEN NOT EXISTS ( - SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 - AND ObjectType = 'Devices' - AND ObjectGUID = NEW.devGUID - AND ObjectStatus = CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END - AND AppEventType = 'insert' - ) - BEGIN - INSERT INTO "AppEvents" ( - "GUID", - "DateTimeCreated", - "AppEventProcessed", - "ObjectType", - "ObjectGUID", - "ObjectPrimaryID", - "ObjectSecondaryID", - "ObjectStatus", - "ObjectStatusColumn", - "ObjectIsNew", - "ObjectIsArchived", - "ObjectForeignKey", - "ObjectPlugin", - "AppEventType" - ) - VALUES ( - - lower( - hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || - substr(hex( randomblob(2)), 2) || '-' || - substr('AB89', 1 + (abs(random()) % 4) , 1) || - substr(hex(randomblob(2)), 2) || '-' || - hex(randomblob(6)) - ) - , - DATETIME('now'), - FALSE, - 'Devices', - NEW.devGUID, -- ObjectGUID - NEW.devMac, -- ObjectPrimaryID - NEW.devLastIP, -- ObjectSecondaryID - CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END, -- ObjectStatus - 'devPresentLastScan', -- ObjectStatusColumn - NEW.devIsNew, -- ObjectIsNew - NEW.devIsArchived, -- ObjectIsArchived - NEW.devGUID, -- ObjectForeignKey - 'DEVICES', -- ObjectForeignKey - 'insert' - ); - END; -CREATE TRIGGER "trg_update_devices" - AFTER UPDATE ON "Devices" - WHEN NOT EXISTS ( - SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 - AND ObjectType = 'Devices' - AND ObjectGUID = NEW.devGUID - AND ObjectStatus = CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END - AND AppEventType = 'update' - ) - BEGIN - INSERT INTO "AppEvents" ( - "GUID", - "DateTimeCreated", - "AppEventProcessed", - "ObjectType", - "ObjectGUID", - "ObjectPrimaryID", - "ObjectSecondaryID", - "ObjectStatus", - "ObjectStatusColumn", - "ObjectIsNew", - "ObjectIsArchived", - "ObjectForeignKey", - "ObjectPlugin", - "AppEventType" - ) - VALUES ( - - lower( - hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || - substr(hex( randomblob(2)), 2) || '-' || - substr('AB89', 1 + (abs(random()) % 4) , 1) || - substr(hex(randomblob(2)), 2) || '-' || - hex(randomblob(6)) - ) - , - DATETIME('now'), - FALSE, - 'Devices', - NEW.devGUID, -- ObjectGUID - NEW.devMac, -- ObjectPrimaryID - NEW.devLastIP, -- ObjectSecondaryID - CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END, -- ObjectStatus - 'devPresentLastScan', -- ObjectStatusColumn - NEW.devIsNew, -- ObjectIsNew - NEW.devIsArchived, -- ObjectIsArchived - NEW.devGUID, -- ObjectForeignKey - 'DEVICES', -- ObjectForeignKey - 'update' - ); - END; -CREATE TRIGGER "trg_delete_devices" - AFTER DELETE ON "Devices" - WHEN NOT EXISTS ( - SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 - AND ObjectType = 'Devices' - AND ObjectGUID = OLD.devGUID - AND ObjectStatus = CASE WHEN OLD.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END - AND AppEventType = 'delete' - ) - BEGIN - INSERT INTO "AppEvents" ( - "GUID", - "DateTimeCreated", - "AppEventProcessed", - "ObjectType", - "ObjectGUID", - "ObjectPrimaryID", - "ObjectSecondaryID", - "ObjectStatus", - "ObjectStatusColumn", - "ObjectIsNew", - "ObjectIsArchived", - "ObjectForeignKey", - "ObjectPlugin", - "AppEventType" - ) - VALUES ( - - lower( - hex(randomblob(4)) || '-' || hex(randomblob(2)) || '-' || '4' || - substr(hex( randomblob(2)), 2) || '-' || - substr('AB89', 1 + (abs(random()) % 4) , 1) || - substr(hex(randomblob(2)), 2) || '-' || - hex(randomblob(6)) - ) - , - DATETIME('now'), - FALSE, - 'Devices', - OLD.devGUID, -- ObjectGUID - OLD.devMac, -- ObjectPrimaryID - OLD.devLastIP, -- ObjectSecondaryID - CASE WHEN OLD.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END, -- ObjectStatus - 'devPresentLastScan', -- ObjectStatusColumn - OLD.devIsNew, -- ObjectIsNew - OLD.devIsArchived, -- ObjectIsArchived - OLD.devGUID, -- ObjectForeignKey - 'DEVICES', -- ObjectForeignKey - 'delete' - ); - END; + WHERE (eveEventType = 'Device Down' OR + eveEventType = 'Disconnected') AND + EVE1.evePairEventRowid IS NULL; diff --git a/server/db/sql_safe_builder.py b/server/db/sql_safe_builder.py index fc3e11e2..e5a8b480 100755 --- a/server/db/sql_safe_builder.py +++ b/server/db/sql_safe_builder.py @@ -29,10 +29,10 @@ class SafeConditionBuilder: # Whitelist of allowed column names for filtering ALLOWED_COLUMNS = { - "eve_MAC", - "eve_DateTime", - "eve_IP", - "eve_EventType", + "eveMac", + "eveDateTime", + "eveIp", + "eveEventType", "devName", "devComments", "devLastIP", @@ -43,15 +43,15 @@ class SafeConditionBuilder: "devPresentLastScan", "devFavorite", "devIsNew", - "Plugin", - "Object_PrimaryId", - "Object_SecondaryId", - "DateTimeChanged", - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4", - "Status", + "plugin", + "objectPrimaryId", + "objectSecondaryId", + "dateTimeChanged", + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4", + "status", } # Whitelist of allowed comparison operators @@ -413,7 +413,7 @@ class SafeConditionBuilder: This method handles basic patterns like: - devName = 'value' (with optional AND/OR prefix) - devComments LIKE '%value%' - - eve_EventType IN ('type1', 'type2') + - eveEventType IN ('type1', 'type2') Args: condition: Single condition string to parse @@ -648,7 +648,7 @@ class SafeConditionBuilder: self.parameters[param_name] = event_type param_names.append(f":{param_name}") - sql_snippet = f"AND eve_EventType IN ({', '.join(param_names)})" + sql_snippet = f"AND eveEventType IN ({', '.join(param_names)})" return sql_snippet, self.parameters def get_safe_condition_legacy( diff --git a/server/initialise.py b/server/initialise.py index 182b0c02..49e50b05 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -27,7 +27,7 @@ from messaging.in_app import write_notification # =============================================================================== _LANGUAGES_JSON = os.path.join( - applicationPath, "front", "php", "templates", "language", "language_definitions" ,"languages.json" + applicationPath, "front", "php", "templates", "language", "language_definitions", "languages.json" ) @@ -204,6 +204,9 @@ def importConfigs(pm, db, all_plugins): # rename settings that have changed names due to code cleanup and migration to plugins # renameSettings(config_file) + # rename legacy DB column references in user config values (e.g. templates, WATCH lists) + renameColumnReferences(config_file) + fileModifiedTime = os.path.getmtime(config_file) mylog("debug", ["[Import Config] checking config file "]) @@ -582,7 +585,7 @@ def importConfigs(pm, db, all_plugins): # bulk-import language strings sql.executemany( - """INSERT INTO Plugins_Language_Strings ("Language_Code", "String_Key", "String_Value", "Extra") VALUES (?, ?, ?, ?)""", + """INSERT INTO Plugins_Language_Strings (languageCode, stringKey, stringValue, extra) VALUES (?, ?, ?, ?)""", stringSqlParams, ) @@ -845,3 +848,78 @@ def renameSettings(config_file): else: mylog("debug", "[Config] No old setting names found in the file. No changes made.") + + +# ------------------------------------------------------------------------------- +# Rename legacy DB column names in user-persisted config values (templates, WATCH lists, etc.) +# Follows the same backup-and-replace pattern as renameSettings(). +_column_replacements = { + # Event columns + r"\beve_MAC\b": "eveMac", + r"\beve_IP\b": "eveIp", + r"\beve_DateTime\b": "eveDateTime", + r"\beve_EventType\b": "eveEventType", + r"\beve_AdditionalInfo\b": "eveAdditionalInfo", + r"\beve_PendingAlertEmail\b": "evePendingAlertEmail", + r"\beve_PairEventRowid\b": "evePairEventRowid", + # Session columns + r"\bses_MAC\b": "sesMac", + r"\bses_IP\b": "sesIp", + r"\bses_StillConnected\b": "sesStillConnected", + r"\bses_AdditionalInfo\b": "sesAdditionalInfo", + # Plugin columns (templates + WATCH values) + r"\bObject_PrimaryID\b": "objectPrimaryId", + r"\bObject_PrimaryId\b": "objectPrimaryId", + r"\bObject_SecondaryID\b": "objectSecondaryId", + r"\bObject_SecondaryId\b": "objectSecondaryId", + r"\bWatched_Value1\b": "watchedValue1", + r"\bWatched_Value2\b": "watchedValue2", + r"\bWatched_Value3\b": "watchedValue3", + r"\bWatched_Value4\b": "watchedValue4", + r"\bDateTimeChanged\b": "dateTimeChanged", + r"\bDateTimeCreated\b": "dateTimeCreated", + r"\bSyncHubNodeName\b": "syncHubNodeName", + # Online_History (in case of API_CUSTOM_SQL) + r"\bScan_Date\b": "scanDate", + r"\bOnline_Devices\b": "onlineDevices", + r"\bDown_Devices\b": "downDevices", + r"\bAll_Devices\b": "allDevices", + r"\bArchived_Devices\b": "archivedDevices", + r"\bOffline_Devices\b": "offlineDevices", + # Language strings (unlikely in user config but thorough) + r"\bLanguage_Code\b": "languageCode", + r"\bString_Key\b": "stringKey", + r"\bString_Value\b": "stringValue", +} + + +def renameColumnReferences(config_file): + """Rename legacy DB column references in the user's app.conf file.""" + contains_old_refs = False + + with open(str(config_file), "r") as f: + for line in f: + if any(re.search(key, line) for key in _column_replacements): + mylog("debug", f"[Config] Old column reference found: ({line.strip()})") + contains_old_refs = True + break + + if not contains_old_refs: + mylog("debug", "[Config] No old column references found in config. No changes made.") + return + + timestamp = timeNowUTC(as_string=False).strftime("%Y%m%d%H%M%S") + backup_file = f"{config_file}_old_column_names_{timestamp}.bak" + mylog("none", f"[Config] Renaming legacy column references — backup: {backup_file}") + shutil.copy(str(config_file), backup_file) + + with ( + open(str(config_file), "r") as original, + open(str(config_file) + "_temp", "w") as temp, + ): + for line in original: + for pattern, replacement in _column_replacements.items(): + line = re.sub(pattern, replacement, line) + temp.write(line) + + shutil.move(str(config_file) + "_temp", str(config_file)) diff --git a/server/messaging/notification_sections.py b/server/messaging/notification_sections.py index a31fb204..f88821b2 100644 --- a/server/messaging/notification_sections.py +++ b/server/messaging/notification_sections.py @@ -25,11 +25,11 @@ SECTION_TITLES = { # Which column(s) contain datetime values per section (for timezone conversion) DATETIME_FIELDS = { - "new_devices": ["eve_DateTime"], - "down_devices": ["eve_DateTime"], - "down_reconnected": ["eve_DateTime"], - "events": ["eve_DateTime"], - "plugins": ["DateTimeChanged"], + "new_devices": ["eveDateTime"], + "down_devices": ["eveDateTime"], + "down_reconnected": ["eveDateTime"], + "events": ["eveDateTime"], + "plugins": ["dateTimeChanged"], } # --------------------------------------------------------------------------- @@ -47,78 +47,78 @@ SQL_TEMPLATES = { "new_devices": """ SELECT devName, - eve_MAC, + eveMac, devVendor, - devLastIP as eve_IP, - eve_DateTime, - eve_EventType, + devLastIP as eveIp, + eveDateTime, + eveEventType, devComments FROM Events_Devices - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType = 'New Device' {condition} - ORDER BY eve_DateTime + WHERE evePendingAlertEmail = 1 + AND eveEventType = 'New Device' {condition} + ORDER BY eveDateTime """, "down_devices": """ SELECT devName, - eve_MAC, + eveMac, devVendor, - eve_IP, - eve_DateTime, - eve_EventType, + eveIp, + eveDateTime, + eveEventType, devComments FROM Events_Devices AS down_events - WHERE eve_PendingAlertEmail = 1 - AND down_events.eve_EventType = 'Device Down' - AND eve_DateTime < datetime('now', '-{alert_down_minutes} minutes') + WHERE evePendingAlertEmail = 1 + AND down_events.eveEventType = 'Device Down' + AND eveDateTime < datetime('now', '-{alert_down_minutes} minutes') AND NOT EXISTS ( SELECT 1 FROM Events AS connected_events - WHERE connected_events.eve_MAC = down_events.eve_MAC - AND connected_events.eve_EventType = 'Connected' - AND connected_events.eve_DateTime > down_events.eve_DateTime + WHERE connected_events.eveMac = down_events.eveMac + AND connected_events.eveEventType = 'Connected' + AND connected_events.eveDateTime > down_events.eveDateTime ) - ORDER BY down_events.eve_DateTime + ORDER BY down_events.eveDateTime """, "down_reconnected": """ SELECT devName, - eve_MAC, + eveMac, devVendor, - eve_IP, - eve_DateTime, - eve_EventType, + eveIp, + eveDateTime, + eveEventType, devComments FROM Events_Devices AS reconnected_devices - WHERE reconnected_devices.eve_EventType = 'Down Reconnected' - AND reconnected_devices.eve_PendingAlertEmail = 1 - ORDER BY reconnected_devices.eve_DateTime + WHERE reconnected_devices.eveEventType = 'Down Reconnected' + AND reconnected_devices.evePendingAlertEmail = 1 + ORDER BY reconnected_devices.eveDateTime """, "events": """ SELECT devName, - eve_MAC, + eveMac, devVendor, - devLastIP as eve_IP, - eve_DateTime, - eve_EventType, + devLastIP as eveIp, + eveDateTime, + eveEventType, devComments FROM Events_Devices - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType IN ('Connected', 'Down Reconnected', 'Disconnected','IP Changed') {condition} - ORDER BY eve_DateTime + WHERE evePendingAlertEmail = 1 + AND eveEventType IN ('Connected', 'Down Reconnected', 'Disconnected','IP Changed') {condition} + ORDER BY eveDateTime """, "plugins": """ SELECT - Plugin, - Object_PrimaryId, - Object_SecondaryId, - DateTimeChanged, - Watched_Value1, - Watched_Value2, - Watched_Value3, - Watched_Value4, - Status + plugin, + objectPrimaryId, + objectSecondaryId, + dateTimeChanged, + watchedValue1, + watchedValue2, + watchedValue3, + watchedValue4, + status FROM Plugins_Events """, } diff --git a/server/messaging/reporting.py b/server/messaging/reporting.py index df0406d5..45a37453 100755 --- a/server/messaging/reporting.py +++ b/server/messaging/reporting.py @@ -114,16 +114,16 @@ def get_notifications(db): # Disable events where reporting is disabled sql.execute(""" - UPDATE Events SET eve_PendingAlertEmail = 0 - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType NOT IN ('Device Down', 'Down Reconnected', 'New Device') - AND eve_MAC IN (SELECT devMac FROM Devices WHERE devAlertEvents = 0) + UPDATE Events SET evePendingAlertEmail = 0 + WHERE evePendingAlertEmail = 1 + AND eveEventType NOT IN ('Device Down', 'Down Reconnected', 'New Device') + AND eveMac IN (SELECT devMac FROM Devices WHERE devAlertEvents = 0) """) sql.execute(""" - UPDATE Events SET eve_PendingAlertEmail = 0 - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType IN ('Device Down', 'Down Reconnected') - AND eve_MAC IN (SELECT devMac FROM Devices WHERE devAlertDown = 0) + UPDATE Events SET evePendingAlertEmail = 0 + WHERE evePendingAlertEmail = 1 + AND eveEventType IN ('Device Down', 'Down Reconnected') + AND eveMac IN (SELECT devMac FROM Devices WHERE devAlertDown = 0) """) alert_down_minutes = int(get_setting_value("NTFPRCS_alert_down_time") or 0) @@ -233,7 +233,7 @@ def skip_repeated_notifications(db): """ Skips sending alerts for devices recently notified. - Clears `eve_PendingAlertEmail` for events linked to devices whose last + Clears `evePendingAlertEmail` for events linked to devices whose last notification time is within their `devSkipRepeated` interval. Args: @@ -244,8 +244,8 @@ def skip_repeated_notifications(db): # due strfime : Overflow --> use "strftime / 60" mylog("verbose", "[Skip Repeated Notifications] Skip Repeated") - db.sql.execute("""UPDATE Events SET eve_PendingAlertEmail = 0 - WHERE eve_PendingAlertEmail = 1 AND eve_MAC IN + db.sql.execute("""UPDATE Events SET evePendingAlertEmail = 0 + WHERE evePendingAlertEmail = 1 AND eveMac IN ( SELECT devMac FROM Devices WHERE devLastNotification IS NOT NULL diff --git a/server/models/device_instance.py b/server/models/device_instance.py index 266ec55a..1384a75f 100755 --- a/server/models/device_instance.py +++ b/server/models/device_instance.py @@ -142,17 +142,17 @@ class DeviceInstance: objs = PluginObjectInstance().getByField( plugPrefix='NMAP', - matchedColumn='Object_PrimaryID', + matchedColumn='objectPrimaryId', matchedKey=primary, - returnFields=['Object_SecondaryID', 'Watched_Value2'] + returnFields=['objectSecondaryId', 'watchedValue2'] ) ports = [] for o in objs: - port = int(o.get('Object_SecondaryID') or 0) + port = int(o.get('objectSecondaryId') or 0) - ports.append({"port": port, "service": o.get('Watched_Value2', '')}) + ports.append({"port": port, "service": o.get('watchedValue2', '')}) return ports @@ -471,31 +471,31 @@ class DeviceInstance: LOWER(d.devParentMAC) AS devParentMAC, (SELECT COUNT(*) FROM Sessions - WHERE LOWER(ses_MAC) = LOWER(d.devMac) AND ( - ses_DateTimeConnection >= {period_date_sql} OR - ses_DateTimeDisconnection >= {period_date_sql} OR - ses_StillConnected = 1 + WHERE LOWER(sesMac) = LOWER(d.devMac) AND ( + sesDateTimeConnection >= {period_date_sql} OR + sesDateTimeDisconnection >= {period_date_sql} OR + sesStillConnected = 1 )) AS devSessions, (SELECT COUNT(*) FROM Events - WHERE LOWER(eve_MAC) = LOWER(d.devMac) AND eve_DateTime >= {period_date_sql} - AND eve_EventType NOT IN ('Connected','Disconnected')) AS devEvents, + WHERE LOWER(eveMac) = LOWER(d.devMac) AND eveDateTime >= {period_date_sql} + AND eveEventType NOT IN ('Connected','Disconnected')) AS devEvents, (SELECT COUNT(*) FROM Events - WHERE LOWER(eve_MAC) = LOWER(d.devMac) AND eve_DateTime >= {period_date_sql} - AND eve_EventType = 'Device Down') AS devDownAlerts, + WHERE LOWER(eveMac) = LOWER(d.devMac) AND eveDateTime >= {period_date_sql} + AND eveEventType = 'Device Down') AS devDownAlerts, (SELECT CAST(MAX(0, SUM( - julianday(IFNULL(ses_DateTimeDisconnection,'{now}')) - - julianday(CASE WHEN ses_DateTimeConnection < {period_date_sql} - THEN {period_date_sql} ELSE ses_DateTimeConnection END) + julianday(IFNULL(sesDateTimeDisconnection,'{now}')) - + julianday(CASE WHEN sesDateTimeConnection < {period_date_sql} + THEN {period_date_sql} ELSE sesDateTimeConnection END) ) * 24) AS INT) FROM Sessions - WHERE LOWER(ses_MAC) = LOWER(d.devMac) - AND ses_DateTimeConnection IS NOT NULL - AND (ses_DateTimeDisconnection IS NOT NULL OR ses_StillConnected = 1) - AND (ses_DateTimeConnection >= {period_date_sql} - OR ses_DateTimeDisconnection >= {period_date_sql} OR ses_StillConnected = 1) + WHERE LOWER(sesMac) = LOWER(d.devMac) + AND sesDateTimeConnection IS NOT NULL + AND (sesDateTimeDisconnection IS NOT NULL OR sesStillConnected = 1) + AND (sesDateTimeConnection >= {period_date_sql} + OR sesDateTimeDisconnection >= {period_date_sql} OR sesStillConnected = 1) ) AS devPresenceHours FROM DevicesView d @@ -797,7 +797,7 @@ class DeviceInstance: """Delete all events for a device.""" conn = get_temp_db_connection() cur = conn.cursor() - cur.execute("DELETE FROM Events WHERE eve_MAC=?", (mac,)) + cur.execute("DELETE FROM Events WHERE eveMac=?", (mac,)) conn.commit() conn.close() return {"success": True} diff --git a/server/models/event_instance.py b/server/models/event_instance.py index 0b166ad6..6222fd3b 100644 --- a/server/models/event_instance.py +++ b/server/models/event_instance.py @@ -21,7 +21,7 @@ class EventInstance: def get_all(self): conn = self._conn() rows = conn.execute( - "SELECT * FROM Events ORDER BY eve_DateTime DESC" + "SELECT * FROM Events ORDER BY eveDateTime DESC" ).fetchall() conn.close() return self._rows_to_list(rows) @@ -31,7 +31,7 @@ class EventInstance: conn = self._conn() rows = conn.execute(""" SELECT * FROM Events - ORDER BY eve_DateTime DESC + ORDER BY eveDateTime DESC LIMIT ? """, (n,)).fetchall() conn.close() @@ -47,8 +47,8 @@ class EventInstance: conn = self._conn() rows = conn.execute(""" SELECT * FROM Events - WHERE eve_DateTime >= ? - ORDER BY eve_DateTime DESC + WHERE eveDateTime >= ? + ORDER BY eveDateTime DESC """, (since,)).fetchall() conn.close() return self._rows_to_list(rows) @@ -63,8 +63,8 @@ class EventInstance: conn = self._conn() rows = conn.execute(""" SELECT * FROM Events - WHERE eve_DateTime >= ? - ORDER BY eve_DateTime DESC + WHERE eveDateTime >= ? + ORDER BY eveDateTime DESC """, (since,)).fetchall() conn.close() return self._rows_to_list(rows) @@ -78,8 +78,8 @@ class EventInstance: conn = self._conn() rows = conn.execute(""" SELECT * FROM Events - WHERE eve_DateTime BETWEEN ? AND ? - ORDER BY eve_DateTime DESC + WHERE eveDateTime BETWEEN ? AND ? + ORDER BY eveDateTime DESC """, (start, end)).fetchall() conn.close() return self._rows_to_list(rows) @@ -89,9 +89,9 @@ class EventInstance: conn = self._conn() conn.execute(""" INSERT OR IGNORE INTO Events ( - eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail, eve_PairEventRowid + eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail, evePairEventRowid ) VALUES (?,?,?,?,?,?,?) """, (mac, ip, timeNowUTC(), eventType, info, 1 if pendingAlert else 0, pairRow)) @@ -102,7 +102,7 @@ class EventInstance: def delete_older_than(self, days: int): cutoff = timeNowUTC(as_string=False) - timedelta(days=days) conn = self._conn() - result = conn.execute("DELETE FROM Events WHERE eve_DateTime < ?", (cutoff,)) + result = conn.execute("DELETE FROM Events WHERE eveDateTime < ?", (cutoff,)) conn.commit() deleted_count = result.rowcount conn.close() @@ -124,7 +124,7 @@ class EventInstance: cur = conn.cursor() cur.execute( """ - INSERT OR IGNORE INTO Events (eve_MAC, eve_IP, eve_DateTime, eve_EventType, eve_AdditionalInfo, eve_PendingAlertEmail) + INSERT OR IGNORE INTO Events (eveMac, eveIp, eveDateTime, eveEventType, eveAdditionalInfo, evePendingAlertEmail) VALUES (?, ?, ?, ?, ?, ?) """, (mac, ip, start_time, event_type, additional_info, pending_alert), @@ -145,10 +145,10 @@ class EventInstance: cur = conn.cursor() if mac: - sql = "SELECT * FROM Events WHERE eve_MAC=? ORDER BY eve_DateTime DESC" + sql = "SELECT * FROM Events WHERE eveMac=? ORDER BY eveDateTime DESC" cur.execute(sql, (mac,)) else: - sql = "SELECT * FROM Events ORDER BY eve_DateTime DESC" + sql = "SELECT * FROM Events ORDER BY eveDateTime DESC" cur.execute(sql) rows = cur.fetchall() @@ -163,7 +163,7 @@ class EventInstance: cur = conn.cursor() # Use a parameterized query with sqlite date function - sql = "DELETE FROM Events WHERE eve_DateTime <= date('now', ?)" + sql = "DELETE FROM Events WHERE eveDateTime <= date('now', ?)" cur.execute(sql, [f"-{days} days"]) conn.commit() @@ -197,19 +197,19 @@ class EventInstance: sql = f""" SELECT - (SELECT COUNT(*) FROM Events WHERE eve_DateTime >= {period_date_sql}) AS all_events, + (SELECT COUNT(*) FROM Events WHERE eveDateTime >= {period_date_sql}) AS all_events, (SELECT COUNT(*) FROM Sessions WHERE - ses_DateTimeConnection >= {period_date_sql} - OR ses_DateTimeDisconnection >= {period_date_sql} - OR ses_StillConnected = 1 + sesDateTimeConnection >= {period_date_sql} + OR sesDateTimeDisconnection >= {period_date_sql} + OR sesStillConnected = 1 ) AS sessions, (SELECT COUNT(*) FROM Sessions WHERE - (ses_DateTimeConnection IS NULL AND ses_DateTimeDisconnection >= {period_date_sql}) - OR (ses_DateTimeDisconnection IS NULL AND ses_StillConnected = 0 AND ses_DateTimeConnection >= {period_date_sql}) + (sesDateTimeConnection IS NULL AND sesDateTimeDisconnection >= {period_date_sql}) + OR (sesDateTimeDisconnection IS NULL AND sesStillConnected = 0 AND sesDateTimeConnection >= {period_date_sql}) ) AS missing, - (SELECT COUNT(*) FROM Events WHERE eve_DateTime >= {period_date_sql} AND eve_EventType LIKE 'VOIDED%') AS voided, - (SELECT COUNT(*) FROM Events WHERE eve_DateTime >= {period_date_sql} AND eve_EventType LIKE 'New Device') AS new, - (SELECT COUNT(*) FROM Events WHERE eve_DateTime >= {period_date_sql} AND eve_EventType LIKE 'Device Down') AS down + (SELECT COUNT(*) FROM Events WHERE eveDateTime >= {period_date_sql} AND eveEventType LIKE 'VOIDED%') AS voided, + (SELECT COUNT(*) FROM Events WHERE eveDateTime >= {period_date_sql} AND eveEventType LIKE 'New Device') AS new, + (SELECT COUNT(*) FROM Events WHERE eveDateTime >= {period_date_sql} AND eveEventType LIKE 'Device Down') AS down """ cur.execute(sql) @@ -247,11 +247,11 @@ class EventInstance: conn = self._conn() sql = """ - SELECT eve_MAC, COUNT(*) as event_count + SELECT eveMac, COUNT(*) as event_count FROM Events - WHERE eve_EventType IN ('Connected','Disconnected','Device Down','Down Reconnected') - AND eve_DateTime >= datetime('now', ?) - GROUP BY eve_MAC + WHERE eveEventType IN ('Connected','Disconnected','Device Down','Down Reconnected') + AND eveDateTime >= datetime('now', ?) + GROUP BY eveMac HAVING COUNT(*) >= ? """ @@ -262,6 +262,6 @@ class EventInstance: conn.close() if macs_only: - return {row["eve_MAC"] for row in rows} + return {row["eveMac"] for row in rows} return [dict(row) for row in rows] diff --git a/server/models/notification_instance.py b/server/models/notification_instance.py index b75668fe..38095093 100755 --- a/server/models/notification_instance.py +++ b/server/models/notification_instance.py @@ -31,17 +31,17 @@ class NotificationInstance: # Create Notifications table if missing self.db.sql.execute("""CREATE TABLE IF NOT EXISTS "Notifications" ( - "Index" INTEGER, - "GUID" TEXT UNIQUE, - "DateTimeCreated" TEXT, - "DateTimePushed" TEXT, - "Status" TEXT, - "JSON" TEXT, - "Text" TEXT, - "HTML" TEXT, - "PublishedVia" TEXT, - "Extra" TEXT, - PRIMARY KEY("Index" AUTOINCREMENT) + "index" INTEGER, + "guid" TEXT UNIQUE, + "dateTimeCreated" TEXT, + "dateTimePushed" TEXT, + "status" TEXT, + "json" TEXT, + "text" TEXT, + "html" TEXT, + "publishedVia" TEXT, + "extra" TEXT, + PRIMARY KEY("index" AUTOINCREMENT) ); """) @@ -178,7 +178,7 @@ class NotificationInstance: def upsert(self): self.db.sql.execute( """ - INSERT OR REPLACE INTO Notifications (GUID, DateTimeCreated, DateTimePushed, Status, JSON, Text, HTML, PublishedVia, Extra) + INSERT OR REPLACE INTO Notifications (guid, dateTimeCreated, dateTimePushed, "status", "json", "text", html, publishedVia, extra) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) """, ( @@ -202,7 +202,7 @@ class NotificationInstance: self.db.sql.execute( """ DELETE FROM Notifications - WHERE GUID = ? + WHERE guid = ? """, (GUID,), ) @@ -212,7 +212,7 @@ class NotificationInstance: def getNew(self): self.db.sql.execute(""" SELECT * FROM Notifications - WHERE Status = "new" + WHERE "status" = 'new' """) return self.db.sql.fetchall() @@ -221,8 +221,8 @@ class NotificationInstance: # Execute an SQL query to update the status of all notifications self.db.sql.execute(""" UPDATE Notifications - SET Status = "processed" - WHERE Status = "new" + SET "status" = 'processed' + WHERE "status" = 'new' """) self.save() @@ -234,15 +234,15 @@ class NotificationInstance: self.db.sql.execute(""" UPDATE Devices SET devLastNotification = ? WHERE devMac IN ( - SELECT eve_MAC FROM Events - WHERE eve_PendingAlertEmail = 1 + SELECT eveMac FROM Events + WHERE evePendingAlertEmail = 1 ) """, (timeNowUTC(),)) self.db.sql.execute(""" - UPDATE Events SET eve_PendingAlertEmail = 0 - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType !='Device Down' """) + UPDATE Events SET evePendingAlertEmail = 0 + WHERE evePendingAlertEmail = 1 + AND eveEventType !='Device Down' """) # Clear down events flag after the reporting window passed minutes = int(get_setting_value("NTFPRCS_alert_down_time") or 0) @@ -250,10 +250,10 @@ class NotificationInstance: self.db.sql.execute( """ UPDATE Events - SET eve_PendingAlertEmail = 0 - WHERE eve_PendingAlertEmail = 1 - AND eve_EventType = 'Device Down' - AND eve_DateTime < datetime('now', ?, ?) + SET evePendingAlertEmail = 0 + WHERE evePendingAlertEmail = 1 + AND eveEventType = 'Device Down' + AND eveDateTime < datetime('now', ?, ?) """, (f"-{minutes} minutes", tz_offset), ) diff --git a/server/models/plugin_object_instance.py b/server/models/plugin_object_instance.py index 30b2bf45..5018b6d5 100755 --- a/server/models/plugin_object_instance.py +++ b/server/models/plugin_object_instance.py @@ -35,18 +35,18 @@ class PluginObjectInstance: def getByGUID(self, ObjectGUID): return self._fetchone( - "SELECT * FROM Plugins_Objects WHERE ObjectGUID = ?", (ObjectGUID,) + "SELECT * FROM Plugins_Objects WHERE objectGuid = ?", (ObjectGUID,) ) def exists(self, ObjectGUID): row = self._fetchone(""" - SELECT COUNT(*) AS count FROM Plugins_Objects WHERE ObjectGUID = ? + SELECT COUNT(*) AS count FROM Plugins_Objects WHERE objectGuid = ? """, (ObjectGUID,)) return row["count"] > 0 if row else False def getByPlugin(self, plugin): return self._fetchall( - "SELECT * FROM Plugins_Objects WHERE Plugin = ?", (plugin,) + "SELECT * FROM Plugins_Objects WHERE plugin = ?", (plugin,) ) def getLastNCreatedPerPlugin(self, plugin, entries=1): @@ -54,8 +54,8 @@ class PluginObjectInstance: """ SELECT * FROM Plugins_Objects - WHERE Plugin = ? - ORDER BY DateTimeCreated DESC + WHERE plugin = ? + ORDER BY dateTimeCreated DESC LIMIT ? """, (plugin, entries), @@ -63,7 +63,7 @@ class PluginObjectInstance: def getByField(self, plugPrefix, matchedColumn, matchedKey, returnFields=None): rows = self._fetchall( - f"SELECT * FROM Plugins_Objects WHERE Plugin = ? AND {matchedColumn} = ?", + f"SELECT * FROM Plugins_Objects WHERE plugin = ? AND {matchedColumn} = ?", (plugPrefix, matchedKey.lower()) ) @@ -75,12 +75,12 @@ class PluginObjectInstance: def getByPrimary(self, plugin, primary_id): return self._fetchall(""" SELECT * FROM Plugins_Objects - WHERE Plugin = ? AND Object_PrimaryID = ? + WHERE plugin = ? AND objectPrimaryId = ? """, (plugin, primary_id)) def getByStatus(self, status): return self._fetchall(""" - SELECT * FROM Plugins_Objects WHERE Status = ? + SELECT * FROM Plugins_Objects WHERE "status" = ? """, (status,)) def updateField(self, ObjectGUID, field, value): @@ -90,7 +90,7 @@ class PluginObjectInstance: raise ValueError(msg) self._execute( - f"UPDATE Plugins_Objects SET {field}=? WHERE ObjectGUID=?", + f"UPDATE Plugins_Objects SET {field}=? WHERE objectGuid=?", (value, ObjectGUID) ) @@ -100,4 +100,4 @@ class PluginObjectInstance: mylog("none", msg) raise ValueError(msg) - self._execute("DELETE FROM Plugins_Objects WHERE ObjectGUID=?", (ObjectGUID,)) + self._execute("DELETE FROM Plugins_Objects WHERE objectGuid=?", (ObjectGUID,)) diff --git a/server/plugin.py b/server/plugin.py index 4d5cf563..0705dcb1 100755 --- a/server/plugin.py +++ b/server/plugin.py @@ -238,11 +238,11 @@ class plugin_manager: if plugin_name: # Only compute for single plugin sql.execute( """ - SELECT MAX(DateTimeChanged) AS last_changed, + SELECT MAX(dateTimeChanged) AS last_changed, COUNT(*) AS total_objects, - SUM(CASE WHEN DateTimeCreated = DateTimeChanged THEN 1 ELSE 0 END) AS new_objects + SUM(CASE WHEN dateTimeCreated = dateTimeChanged THEN 1 ELSE 0 END) AS new_objects FROM Plugins_Objects - WHERE Plugin = ? + WHERE plugin = ? """, (plugin_name,), ) @@ -264,12 +264,12 @@ class plugin_manager: else: # Compute for all plugins (full refresh) sql.execute(""" - SELECT Plugin, - MAX(DateTimeChanged) AS last_changed, + SELECT plugin, + MAX(dateTimeChanged) AS last_changed, COUNT(*) AS total_objects, - SUM(CASE WHEN DateTimeCreated = DateTimeChanged THEN 1 ELSE 0 END) AS new_objects + SUM(CASE WHEN dateTimeCreated = dateTimeChanged THEN 1 ELSE 0 END) AS new_objects FROM Plugins_Objects - GROUP BY Plugin + GROUP BY plugin """) for plugin, last_changed, total_objects, new_objects in sql.fetchall(): new_objects = new_objects or 0 # ensure it's int @@ -496,22 +496,22 @@ def execute_plugin(db, all_plugins, plugin): # Common part of the SQL parameters base_params = [ - 0, # "Index" placeholder + 0, # "index" placeholder plugin[ "unique_prefix" - ], # "Plugin" column value from the plugin dictionary - columns[0], # "Object_PrimaryID" value from columns list - columns[1], # "Object_SecondaryID" value from columns list - "null", # Placeholder for "DateTimeCreated" column - columns[2], # "DateTimeChanged" value from columns list - columns[3], # "Watched_Value1" value from columns list - columns[4], # "Watched_Value2" value from columns list - columns[5], # "Watched_Value3" value from columns list - columns[6], # "Watched_Value4" value from columns list - "not-processed", # "Status" column (placeholder) - columns[7], # "Extra" value from columns list - "null", # Placeholder for "UserData" column - columns[8], # "ForeignKey" value from columns list + ], # "plugin" column value from the plugin dictionary + columns[0], # "objectPrimaryId" value from columns list + columns[1], # "objectSecondaryId" value from columns list + "null", # Placeholder for "dateTimeCreated" column + columns[2], # "dateTimeChanged" value from columns list + columns[3], # "watchedValue1" value from columns list + columns[4], # "watchedValue2" value from columns list + columns[5], # "watchedValue3" value from columns list + columns[6], # "watchedValue4" value from columns list + "not-processed", # "status" column (placeholder) + columns[7], # "extra" value from columns list + "null", # Placeholder for "userData" column + columns[8], # "foreignKey" value from columns list tmp_SyncHubNodeName, # Sync Hub Node name ] @@ -566,26 +566,26 @@ def execute_plugin(db, all_plugins, plugin): # Each value corresponds to a column in the table in the order of the columns. # Must match the Plugins_Objects and Plugins_Events database tables and can be used as input for the plugin_object_class. base_params = [ - 0, # "Index" placeholder - plugin["unique_prefix"], # "Plugin" plugin dictionary - row[0], # "Object_PrimaryID" row + 0, # "index" placeholder + plugin["unique_prefix"], # "plugin" plugin dictionary + row[0], # "objectPrimaryId" row handle_empty( row[1] - ), # "Object_SecondaryID" column after handling empty values - "null", # Placeholder "DateTimeCreated" column - row[2], # "DateTimeChanged" row - row[3], # "Watched_Value1" row - row[4], # "Watched_Value2" row + ), # "objectSecondaryId" column after handling empty values + "null", # Placeholder "dateTimeCreated" column + row[2], # "dateTimeChanged" row + row[3], # "watchedValue1" row + row[4], # "watchedValue2" row handle_empty( row[5] - ), # "Watched_Value3" column after handling empty values + ), # "watchedValue3" column after handling empty values handle_empty( row[6] - ), # "Watched_Value4" column after handling empty values - "not-processed", # "Status" column (placeholder) - row[7], # "Extra" row - "null", # Placeholder "UserData" column - row[8], # "ForeignKey" row + ), # "watchedValue4" column after handling empty values + "not-processed", # "status" column (placeholder) + row[7], # "extra" row + "null", # Placeholder "userData" column + row[8], # "foreignKey" row "null", # Sync Hub Node name - Only supported with scripts ] @@ -654,41 +654,41 @@ def execute_plugin(db, all_plugins, plugin): # Each value corresponds to a column in the table in the order of the columns. # Must match the Plugins_Objects and Plugins_Events database tables and can be used as input for the plugin_object_class. base_params = [ - 0, # "Index" placeholder - plugin["unique_prefix"], # "Plugin" - row[0], # "Object_PrimaryID" - handle_empty(row[1]), # "Object_SecondaryID" - "null", # "DateTimeCreated" column (null placeholder) - row[2], # "DateTimeChanged" - row[3], # "Watched_Value1" - row[4], # "Watched_Value2" - handle_empty(row[5]), # "Watched_Value3" - handle_empty(row[6]), # "Watched_Value4" - "not-processed", # "Status" column (placeholder) - row[7], # "Extra" - "null", # "UserData" column (null placeholder) - row[8], # "ForeignKey" - "null", # Sync Hub Node name - Only supported with scripts + 0, # "index" placeholder + plugin["unique_prefix"], # "plugin" + row[0], # "objectPrimaryId" + handle_empty(row[1]), # "objectSecondaryId" + "null", # "dateTimeCreated" column (null placeholder) + row[2], # "dateTimeChanged" + row[3], # "watchedValue1" + row[4], # "watchedValue2" + handle_empty(row[5]), # "watchedValue3" + handle_empty(row[6]), # "watchedValue4" + "not-processed", # "status" column (placeholder) + row[7], # "extra" + "null", # "userData" column (null placeholder) + row[8], # "foreignKey" + "null", # syncHubNodeName - Only supported with scripts ] # Extend the base tuple with additional values if there are 13 columns if len(row) == 13: base_params.extend( [ - row[9], # "HelpVal1" - row[10], # "HelpVal2" - row[11], # "HelpVal3" - row[12], # "HelpVal4" + row[9], # "helpVal1" + row[10], # "helpVal2" + row[11], # "helpVal3" + row[12], # "helpVal4" ] ) else: # add padding base_params.extend( [ - "null", # "HelpVal1" - "null", # "HelpVal2" - "null", # "HelpVal3" - "null", # "HelpVal4" + "null", # "helpVal1" + "null", # "helpVal2" + "null", # "helpVal3" + "null", # "helpVal4" ] ) @@ -749,7 +749,7 @@ def process_plugin_events(db, plugin, plugEventsArr): # Create plugin objects from existing database entries plugObjectsArr = db.get_sql_array( - "SELECT * FROM Plugins_Objects where Plugin = '" + str(pluginPref) + "'" + "SELECT * FROM Plugins_Objects where plugin = '" + str(pluginPref) + "'" ) for obj in plugObjectsArr: @@ -894,11 +894,11 @@ def process_plugin_events(db, plugin, plugEventsArr): sql.executemany( """ INSERT INTO Plugins_Objects - ("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTimeCreated", - "DateTimeChanged", "Watched_Value1", "Watched_Value2", "Watched_Value3", - "Watched_Value4", "Status", "Extra", "UserData", "ForeignKey", "SyncHubNodeName", - "HelpVal1", "HelpVal2", "HelpVal3", "HelpVal4", - "ObjectGUID") + ("plugin", "objectPrimaryId", "objectSecondaryId", "dateTimeCreated", + "dateTimeChanged", "watchedValue1", "watchedValue2", "watchedValue3", + "watchedValue4", "status", "extra", "userData", "foreignKey", "syncHubNodeName", + "helpVal1", "helpVal2", "helpVal3", "helpVal4", + "objectGuid") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, objects_to_insert, @@ -909,12 +909,12 @@ def process_plugin_events(db, plugin, plugEventsArr): sql.executemany( """ UPDATE Plugins_Objects - SET "Plugin" = ?, "Object_PrimaryID" = ?, "Object_SecondaryID" = ?, "DateTimeCreated" = ?, - "DateTimeChanged" = ?, "Watched_Value1" = ?, "Watched_Value2" = ?, "Watched_Value3" = ?, - "Watched_Value4" = ?, "Status" = ?, "Extra" = ?, "UserData" = ?, "ForeignKey" = ?, "SyncHubNodeName" = ?, - "HelpVal1" = ?, "HelpVal2" = ?, "HelpVal3" = ?, "HelpVal4" = ?, - "ObjectGUID" = ? - WHERE "Index" = ? + SET "plugin" = ?, "objectPrimaryId" = ?, "objectSecondaryId" = ?, "dateTimeCreated" = ?, + "dateTimeChanged" = ?, "watchedValue1" = ?, "watchedValue2" = ?, "watchedValue3" = ?, + "watchedValue4" = ?, "status" = ?, "extra" = ?, "userData" = ?, "foreignKey" = ?, "syncHubNodeName" = ?, + "helpVal1" = ?, "helpVal2" = ?, "helpVal3" = ?, "helpVal4" = ?, + "objectGuid" = ? + WHERE "index" = ? """, objects_to_update, ) @@ -924,11 +924,11 @@ def process_plugin_events(db, plugin, plugEventsArr): sql.executemany( """ INSERT INTO Plugins_Events - ("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTimeCreated", - "DateTimeChanged", "Watched_Value1", "Watched_Value2", "Watched_Value3", - "Watched_Value4", "Status", "Extra", "UserData", "ForeignKey", "SyncHubNodeName", - "HelpVal1", "HelpVal2", "HelpVal3", "HelpVal4", - "ObjectGUID") + ("plugin", "objectPrimaryId", "objectSecondaryId", "dateTimeCreated", + "dateTimeChanged", "watchedValue1", "watchedValue2", "watchedValue3", + "watchedValue4", "status", "extra", "userData", "foreignKey", "syncHubNodeName", + "helpVal1", "helpVal2", "helpVal3", "helpVal4", + "objectGuid") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, events_to_insert, @@ -939,11 +939,11 @@ def process_plugin_events(db, plugin, plugEventsArr): sql.executemany( """ INSERT INTO Plugins_History - ("Plugin", "Object_PrimaryID", "Object_SecondaryID", "DateTimeCreated", - "DateTimeChanged", "Watched_Value1", "Watched_Value2", "Watched_Value3", - "Watched_Value4", "Status", "Extra", "UserData", "ForeignKey", "SyncHubNodeName", - "HelpVal1", "HelpVal2", "HelpVal3", "HelpVal4", - "ObjectGUID") + ("plugin", "objectPrimaryId", "objectSecondaryId", "dateTimeCreated", + "dateTimeChanged", "watchedValue1", "watchedValue2", "watchedValue3", + "watchedValue4", "status", "extra", "userData", "foreignKey", "syncHubNodeName", + "helpVal1", "helpVal2", "helpVal3", "helpVal4", + "objectGuid") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) """, history_to_insert, @@ -993,41 +993,41 @@ def process_plugin_events(db, plugin, plugEventsArr): tmpList = [] for col in mappedCols: - if col["column"] == "Index": + if col["column"] == "index": tmpList.append(plgEv.index) - elif col["column"] == "Plugin": + elif col["column"] == "plugin": tmpList.append(plgEv.pluginPref) - elif col["column"] == "Object_PrimaryID": + elif col["column"] == "objectPrimaryId": tmpList.append(plgEv.primaryId) - elif col["column"] == "Object_SecondaryID": + elif col["column"] == "objectSecondaryId": tmpList.append(plgEv.secondaryId) - elif col["column"] == "DateTimeCreated": + elif col["column"] == "dateTimeCreated": tmpList.append(plgEv.created) - elif col["column"] == "DateTimeChanged": + elif col["column"] == "dateTimeChanged": tmpList.append(plgEv.changed) - elif col["column"] == "Watched_Value1": + elif col["column"] == "watchedValue1": tmpList.append(plgEv.watched1) - elif col["column"] == "Watched_Value2": + elif col["column"] == "watchedValue2": tmpList.append(plgEv.watched2) - elif col["column"] == "Watched_Value3": + elif col["column"] == "watchedValue3": tmpList.append(plgEv.watched3) - elif col["column"] == "Watched_Value4": + elif col["column"] == "watchedValue4": tmpList.append(plgEv.watched4) - elif col["column"] == "UserData": + elif col["column"] == "userData": tmpList.append(plgEv.userData) - elif col["column"] == "Extra": + elif col["column"] == "extra": tmpList.append(plgEv.extra) - elif col["column"] == "Status": + elif col["column"] == "status": tmpList.append(plgEv.status) - elif col["column"] == "SyncHubNodeName": + elif col["column"] == "syncHubNodeName": tmpList.append(plgEv.syncHubNodeName) - elif col["column"] == "HelpVal1": + elif col["column"] == "helpVal1": tmpList.append(plgEv.helpVal1) - elif col["column"] == "HelpVal2": + elif col["column"] == "helpVal2": tmpList.append(plgEv.helpVal2) - elif col["column"] == "HelpVal3": + elif col["column"] == "helpVal3": tmpList.append(plgEv.helpVal3) - elif col["column"] == "HelpVal4": + elif col["column"] == "helpVal4": tmpList.append(plgEv.helpVal4) # Check if there's a default value specified for this column in the JSON. @@ -1113,10 +1113,10 @@ class plugin_object_class: # hash for comapring watched value changes indexNameColumnMapping = [ - (6, "Watched_Value1"), - (7, "Watched_Value2"), - (8, "Watched_Value3"), - (9, "Watched_Value4"), + (6, "watchedValue1"), + (7, "watchedValue2"), + (8, "watchedValue3"), + (9, "watchedValue4"), ] if setObj is not None: diff --git a/server/scan/device_handling.py b/server/scan/device_handling.py index 7d60c13d..63673eda 100755 --- a/server/scan/device_handling.py +++ b/server/scan/device_handling.py @@ -581,8 +581,8 @@ def print_scan_stats(db): row_dict = dict(row) mylog("trace", f" {row_dict}") - mylog("trace", " ================ Events table content where eve_PendingAlertEmail = 1 ================",) - sql.execute("select * from Events where eve_PendingAlertEmail = 1") + mylog("trace", " ================ Events table content where evePendingAlertEmail = 1 ================",) + sql.execute("select * from Events where evePendingAlertEmail = 1") rows = sql.fetchall() for row in rows: row_dict = dict(row) @@ -611,9 +611,9 @@ def create_new_devices(db): mylog("debug", '[New Devices] Insert "New Device" Events') query_new_device_events = f""" INSERT OR IGNORE INTO Events ( - eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail + eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail ) SELECT DISTINCT scanMac, scanLastIP, '{startTime}', 'New Device', scanVendor, 1 FROM CurrentScan @@ -630,9 +630,9 @@ def create_new_devices(db): mylog("debug", "[New Devices] Insert Connection into session table") sql.execute(f"""INSERT INTO Sessions ( - ses_MAC, ses_IP, ses_EventTypeConnection, ses_DateTimeConnection, - ses_EventTypeDisconnection, ses_DateTimeDisconnection, - ses_StillConnected, ses_AdditionalInfo + sesMac, sesIp, sesEventTypeConnection, sesDateTimeConnection, + sesEventTypeDisconnection, sesDateTimeDisconnection, + sesStillConnected, sesAdditionalInfo ) SELECT scanMac, scanLastIP, 'Connected', '{startTime}', NULL, NULL, 1, scanVendor FROM CurrentScan @@ -642,7 +642,7 @@ def create_new_devices(db): ) AND NOT EXISTS ( SELECT 1 FROM Sessions - WHERE ses_MAC = scanMac AND ses_StillConnected = 1 + WHERE sesMac = scanMac AND sesStillConnected = 1 ) """) diff --git a/server/scan/name_resolution.py b/server/scan/name_resolution.py index 8a9e226c..e05b4a15 100755 --- a/server/scan/name_resolution.py +++ b/server/scan/name_resolution.py @@ -24,8 +24,8 @@ class NameResolver: # Check by MAC sql.execute(f""" - SELECT Watched_Value2 FROM Plugins_Objects - WHERE Plugin = '{plugin}' AND Object_PrimaryID = '{pMAC}' + SELECT watchedValue2 FROM Plugins_Objects + WHERE plugin = '{plugin}' AND objectPrimaryId = '{pMAC}' """) result = sql.fetchall() # self.db.commitDB() # Issue #1251: Optimize name resolution lookup @@ -37,8 +37,8 @@ class NameResolver: if get_setting_value('NEWDEV_IP_MATCH_NAME'): sql.execute(f""" - SELECT Watched_Value2 FROM Plugins_Objects - WHERE Plugin = '{plugin}' AND Object_SecondaryID = '{pIP}' + SELECT watchedValue2 FROM Plugins_Objects + WHERE plugin = '{plugin}' AND objectSecondaryId = '{pIP}' """) result = sql.fetchall() # self.db.commitDB() # Issue #1251: Optimize name resolution lookup diff --git a/server/scan/session_events.py b/server/scan/session_events.py index 6fe39ebf..4a0cf588 100755 --- a/server/scan/session_events.py +++ b/server/scan/session_events.py @@ -120,27 +120,27 @@ def pair_sessions_events(db): mylog("debug", "[Pair Session] - 1 Connections / New Devices") sql.execute("""UPDATE Events - SET eve_PairEventRowid = + SET evePairEventRowid = (SELECT ROWID FROM Events AS EVE2 - WHERE EVE2.eve_EventType IN ('New Device', 'Connected', 'Down Reconnected', + WHERE EVE2.eveEventType IN ('New Device', 'Connected', 'Down Reconnected', 'Device Down', 'Disconnected') - AND EVE2.eve_MAC = Events.eve_MAC - AND EVE2.eve_Datetime > Events.eve_DateTime - ORDER BY EVE2.eve_DateTime ASC LIMIT 1) - WHERE eve_EventType IN ('New Device', 'Connected', 'Down Reconnected') - AND eve_PairEventRowid IS NULL + AND EVE2.eveMac = Events.eveMac + AND EVE2.eveDateTime > Events.eveDateTime + ORDER BY EVE2.eveDateTime ASC LIMIT 1) + WHERE eveEventType IN ('New Device', 'Connected', 'Down Reconnected') + AND evePairEventRowid IS NULL """) # Pair Disconnection / Device Down mylog("debug", "[Pair Session] - 2 Disconnections") sql.execute("""UPDATE Events - SET eve_PairEventRowid = + SET evePairEventRowid = (SELECT ROWID FROM Events AS EVE2 - WHERE EVE2.eve_PairEventRowid = Events.ROWID) - WHERE eve_EventType IN ('Device Down', 'Disconnected') - AND eve_PairEventRowid IS NULL + WHERE EVE2.evePairEventRowid = Events.ROWID) + WHERE eveEventType IN ('Device Down', 'Disconnected') + AND evePairEventRowid IS NULL """) mylog("debug", "[Pair Session] Pair session end") @@ -171,9 +171,9 @@ def insert_events(db): # Check device down – non-sleeping devices (immediate on first absence) mylog("debug", "[Events] - 1a - Devices down (non-sleeping)") - sql.execute(f"""INSERT OR IGNORE INTO Events (eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail) + sql.execute(f"""INSERT OR IGNORE INTO Events (eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail) SELECT devMac, devLastIP, '{startTime}', 'Device Down', '', 1 FROM DevicesView WHERE devAlertDown != 0 @@ -185,9 +185,9 @@ def insert_events(db): # Check device down – sleeping devices whose sleep window has expired mylog("debug", "[Events] - 1b - Devices down (sleep expired)") - sql.execute(f"""INSERT OR IGNORE INTO Events (eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail) + sql.execute(f"""INSERT OR IGNORE INTO Events (eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail) SELECT devMac, devLastIP, '{startTime}', 'Device Down', '', 1 FROM DevicesView WHERE devAlertDown != 0 @@ -197,33 +197,33 @@ def insert_events(db): AND NOT EXISTS (SELECT 1 FROM CurrentScan WHERE devMac = scanMac) AND NOT EXISTS (SELECT 1 FROM Events - WHERE eve_MAC = devMac - AND eve_EventType = 'Device Down' - AND eve_DateTime >= devLastConnection + WHERE eveMac = devMac + AND eveEventType = 'Device Down' + AND eveDateTime >= devLastConnection ) """) # Check new Connections or Down Reconnections mylog("debug", "[Events] - 2 - New Connections") - sql.execute(f""" INSERT OR IGNORE INTO Events (eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail) + sql.execute(f""" INSERT OR IGNORE INTO Events (eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail) SELECT DISTINCT c.scanMac, c.scanLastIP, '{startTime}', CASE - WHEN last_event.eve_EventType = 'Device Down' and last_event.eve_PendingAlertEmail = 0 THEN 'Down Reconnected' + WHEN last_event.eveEventType = 'Device Down' and last_event.evePendingAlertEmail = 0 THEN 'Down Reconnected' ELSE 'Connected' END, '', 1 FROM CurrentScan AS c - LEFT JOIN LatestEventsPerMAC AS last_event ON c.scanMac = last_event.eve_MAC - WHERE last_event.devPresentLastScan = 0 OR last_event.eve_MAC IS NULL + LEFT JOIN LatestEventsPerMAC AS last_event ON c.scanMac = last_event.eveMac + WHERE last_event.devPresentLastScan = 0 OR last_event.eveMac IS NULL """) # Check disconnections mylog("debug", "[Events] - 3 - Disconnections") - sql.execute(f"""INSERT OR IGNORE INTO Events (eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail) + sql.execute(f"""INSERT OR IGNORE INTO Events (eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail) SELECT devMac, devLastIP, '{startTime}', 'Disconnected', '', devAlertEvents FROM Devices @@ -235,9 +235,9 @@ def insert_events(db): # Check IP Changed mylog("debug", "[Events] - 4 - IP Changes") - sql.execute(f"""INSERT OR IGNORE INTO Events (eve_MAC, eve_IP, eve_DateTime, - eve_EventType, eve_AdditionalInfo, - eve_PendingAlertEmail) + sql.execute(f"""INSERT OR IGNORE INTO Events (eveMac, eveIp, eveDateTime, + eveEventType, eveAdditionalInfo, + evePendingAlertEmail) SELECT scanMac, scanLastIP, '{startTime}', 'IP Changed', 'Previous IP: '|| devLastIP, devAlertEvents FROM Devices, CurrentScan @@ -279,7 +279,7 @@ def insertOnlineHistory(db): # Prepare the insert query using parameterized inputs insert_query = """ - INSERT INTO Online_History (Scan_Date, Online_Devices, Down_Devices, All_Devices, Archived_Devices, Offline_Devices) + INSERT INTO Online_History (scanDate, onlineDevices, downDevices, allDevices, archivedDevices, offlineDevices) VALUES (?, ?, ?, ?, ?, ?) """ diff --git a/server/utils/plugin_utils.py b/server/utils/plugin_utils.py index 8f28932f..0b50454e 100755 --- a/server/utils/plugin_utils.py +++ b/server/utils/plugin_utils.py @@ -245,7 +245,7 @@ def handle_empty(value): # ------------------------------------------------------------------------------- # Get and return a plugin object based on key-value pairs -# keyValues example: getPluginObject({"Plugin":"MQTT", "Watched_Value4":"someValue"}) +# keyValues example: getPluginObject({"plugin":"MQTT", "watchedValue4":"someValue"}) def getPluginObject(keyValues): plugins_objects = apiPath + "table_plugins_objects.json" diff --git a/server/workflows/actions.py b/server/workflows/actions.py index da90aced..429da0f5 100755 --- a/server/workflows/actions.py +++ b/server/workflows/actions.py @@ -40,10 +40,10 @@ class UpdateFieldAction(Action): processed = False # currently unused - if isinstance(obj, dict) and "ObjectGUID" in obj: + if isinstance(obj, dict) and "objectGuid" in obj: mylog("debug", f"[WF] Updating Object '{obj}' ") plugin_instance = PluginObjectInstance() - plugin_instance.updateField(obj["ObjectGUID"], self.field, self.value) + plugin_instance.updateField(obj["objectGuid"], self.field, self.value) processed = True elif isinstance(obj, dict) and "devGUID" in obj: @@ -77,10 +77,10 @@ class DeleteObjectAction(Action): processed = False # currently unused - if isinstance(obj, dict) and "ObjectGUID" in obj: + if isinstance(obj, dict) and "objectGuid" in obj: mylog("debug", f"[WF] Updating Object '{obj}' ") plugin_instance = PluginObjectInstance() - plugin_instance.delete(obj["ObjectGUID"]) + plugin_instance.delete(obj["objectGuid"]) processed = True elif isinstance(obj, dict) and "devGUID" in obj: diff --git a/server/workflows/app_events.py b/server/workflows/app_events.py index 6396e30a..236b1663 100755 --- a/server/workflows/app_events.py +++ b/server/workflows/app_events.py @@ -23,29 +23,29 @@ class AppEvent_obj: self.object_mapping = { "Devices": { "fields": { - "ObjectGUID": "NEW.devGUID", - "ObjectPrimaryID": "NEW.devMac", - "ObjectSecondaryID": "NEW.devLastIP", - "ObjectForeignKey": "NEW.devGUID", - "ObjectStatus": "CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END", - "ObjectStatusColumn": "'devPresentLastScan'", - "ObjectIsNew": "NEW.devIsNew", - "ObjectIsArchived": "NEW.devIsArchived", - "ObjectPlugin": "'DEVICES'", + "objectGuid": "NEW.devGUID", + "objectPrimaryId": "NEW.devMac", + "objectSecondaryId": "NEW.devLastIP", + "objectForeignKey": "NEW.devGUID", + "objectStatus": "CASE WHEN NEW.devPresentLastScan = 1 THEN 'online' ELSE 'offline' END", + "objectStatusColumn": "'devPresentLastScan'", + "objectIsNew": "NEW.devIsNew", + "objectIsArchived": "NEW.devIsArchived", + "objectPlugin": "'DEVICES'", } } # , # "Plugins_Objects": { # "fields": { - # "ObjectGUID": "NEW.ObjectGUID", - # "ObjectPrimaryID": "NEW.Plugin", - # "ObjectSecondaryID": "NEW.Object_PrimaryID", - # "ObjectForeignKey": "NEW.ForeignKey", - # "ObjectStatus": "NEW.Status", - # "ObjectStatusColumn": "'Status'", - # "ObjectIsNew": "CASE WHEN NEW.Status = 'new' THEN 1 ELSE 0 END", - # "ObjectIsArchived": "0", # Default value - # "ObjectPlugin": "NEW.Plugin" + # "objectGuid": "NEW.objectGuid", + # "objectPrimaryId": "NEW.plugin", + # "objectSecondaryId": "NEW.objectPrimaryId", + # "objectForeignKey": "NEW.foreignKey", + # "objectStatus": "NEW.status", + # "objectStatusColumn": "'status'", + # "objectIsNew": "CASE WHEN NEW.status = 'new' THEN 1 ELSE 0 END", + # "objectIsArchived": "0", # Default value + # "objectPlugin": "NEW.plugin" # } # } } @@ -79,26 +79,26 @@ class AppEvent_obj: """Creates the AppEvents table if it doesn't exist.""" self.db.sql.execute(""" CREATE TABLE IF NOT EXISTS "AppEvents" ( - "Index" INTEGER PRIMARY KEY AUTOINCREMENT, - "GUID" TEXT UNIQUE, - "AppEventProcessed" BOOLEAN, - "DateTimeCreated" TEXT, - "ObjectType" TEXT, - "ObjectGUID" TEXT, - "ObjectPlugin" TEXT, - "ObjectPrimaryID" TEXT, - "ObjectSecondaryID" TEXT, - "ObjectForeignKey" TEXT, - "ObjectIndex" TEXT, - "ObjectIsNew" BOOLEAN, - "ObjectIsArchived" BOOLEAN, - "ObjectStatusColumn" TEXT, - "ObjectStatus" TEXT, - "AppEventType" TEXT, - "Helper1" TEXT, - "Helper2" TEXT, - "Helper3" TEXT, - "Extra" TEXT + "index" INTEGER PRIMARY KEY AUTOINCREMENT, + "guid" TEXT UNIQUE, + "appEventProcessed" BOOLEAN, + "dateTimeCreated" TEXT, + "objectType" TEXT, + "objectGuid" TEXT, + "objectPlugin" TEXT, + "objectPrimaryId" TEXT, + "objectSecondaryId" TEXT, + "objectForeignKey" TEXT, + "objectIndex" TEXT, + "objectIsNew" BOOLEAN, + "objectIsArchived" BOOLEAN, + "objectStatusColumn" TEXT, + "objectStatus" TEXT, + "appEventType" TEXT, + "helper1" TEXT, + "helper2" TEXT, + "helper3" TEXT, + "extra" TEXT ); """) @@ -111,43 +111,43 @@ class AppEvent_obj: AFTER {event.upper()} ON "{table_name}" WHEN NOT EXISTS ( SELECT 1 FROM AppEvents - WHERE AppEventProcessed = 0 - AND ObjectType = '{table_name}' - AND ObjectGUID = {manage_prefix(config["fields"]["ObjectGUID"], event)} - AND ObjectStatus = {manage_prefix(config["fields"]["ObjectStatus"], event)} - AND AppEventType = '{event.lower()}' + WHERE appEventProcessed = 0 + AND objectType = '{table_name}' + AND objectGuid = {manage_prefix(config["fields"]["objectGuid"], event)} + AND objectStatus = {manage_prefix(config["fields"]["objectStatus"], event)} + AND appEventType = '{event.lower()}' ) BEGIN INSERT INTO "AppEvents" ( - "GUID", - "DateTimeCreated", - "AppEventProcessed", - "ObjectType", - "ObjectGUID", - "ObjectPrimaryID", - "ObjectSecondaryID", - "ObjectStatus", - "ObjectStatusColumn", - "ObjectIsNew", - "ObjectIsArchived", - "ObjectForeignKey", - "ObjectPlugin", - "AppEventType" + "guid", + "dateTimeCreated", + "appEventProcessed", + "objectType", + "objectGuid", + "objectPrimaryId", + "objectSecondaryId", + "objectStatus", + "objectStatusColumn", + "objectIsNew", + "objectIsArchived", + "objectForeignKey", + "objectPlugin", + "appEventType" ) VALUES ( {sql_generateGuid}, DATETIME('now'), FALSE, '{table_name}', - {manage_prefix(config["fields"]["ObjectGUID"], event)}, -- ObjectGUID - {manage_prefix(config["fields"]["ObjectPrimaryID"], event)}, -- ObjectPrimaryID - {manage_prefix(config["fields"]["ObjectSecondaryID"], event)}, -- ObjectSecondaryID - {manage_prefix(config["fields"]["ObjectStatus"], event)}, -- ObjectStatus - {manage_prefix(config["fields"]["ObjectStatusColumn"], event)}, -- ObjectStatusColumn - {manage_prefix(config["fields"]["ObjectIsNew"], event)}, -- ObjectIsNew - {manage_prefix(config["fields"]["ObjectIsArchived"], event)}, -- ObjectIsArchived - {manage_prefix(config["fields"]["ObjectForeignKey"], event)}, -- ObjectForeignKey - {manage_prefix(config["fields"]["ObjectPlugin"], event)}, -- ObjectForeignKey + {manage_prefix(config["fields"]["objectGuid"], event)}, -- objectGuid + {manage_prefix(config["fields"]["objectPrimaryId"], event)}, -- objectPrimaryId + {manage_prefix(config["fields"]["objectSecondaryId"], event)}, -- objectSecondaryId + {manage_prefix(config["fields"]["objectStatus"], event)}, -- objectStatus + {manage_prefix(config["fields"]["objectStatusColumn"], event)}, -- objectStatusColumn + {manage_prefix(config["fields"]["objectIsNew"], event)}, -- objectIsNew + {manage_prefix(config["fields"]["objectIsArchived"], event)}, -- objectIsArchived + {manage_prefix(config["fields"]["objectForeignKey"], event)}, -- objectForeignKey + {manage_prefix(config["fields"]["objectPlugin"], event)}, -- objectPlugin '{event.lower()}' ); END; diff --git a/server/workflows/manager.py b/server/workflows/manager.py index 52ede363..77ffa71c 100755 --- a/server/workflows/manager.py +++ b/server/workflows/manager.py @@ -33,8 +33,8 @@ class WorkflowManager: """Get new unprocessed events from the AppEvents table.""" result = self.db.sql.execute(""" SELECT * FROM AppEvents - WHERE AppEventProcessed = 0 - ORDER BY DateTimeCreated ASC + WHERE appEventProcessed = 0 + ORDER BY dateTimeCreated ASC """).fetchall() mylog("none", [f"[WF] get_new_app_events - new events count: {len(result)}"]) @@ -44,7 +44,7 @@ class WorkflowManager: def process_event(self, event): """Process the events. Check if events match a workflow trigger""" - evGuid = event["GUID"] + evGuid = event["guid"] mylog("verbose", [f"[WF] Processing event with GUID {evGuid}"]) @@ -67,10 +67,10 @@ class WorkflowManager: self.db.sql.execute( """ UPDATE AppEvents - SET AppEventProcessed = 1 - WHERE "Index" = ? + SET appEventProcessed = 1 + WHERE "index" = ? """, - (event["Index"],), + (event["index"],), ) # Pass the event's unique identifier self.db.commitDB() diff --git a/server/workflows/triggers.py b/server/workflows/triggers.py index 33e7ab2b..ed8ec4b9 100755 --- a/server/workflows/triggers.py +++ b/server/workflows/triggers.py @@ -21,7 +21,7 @@ class Trigger: self.event_type = triggerJson["event_type"] self.event = event # Store the triggered event context, if provided self.triggered = ( - self.object_type == event["ObjectType"] and self.event_type == event["AppEventType"] + self.object_type == event["objectType"] and self.event_type == event["appEventType"] ) mylog("debug", f"""[WF] self.triggered '{self.triggered}' for event '{get_array_from_sql_rows(event)} and trigger {json.dumps(triggerJson)}' """) @@ -33,7 +33,7 @@ class Trigger: if db_table == "Devices": refField = "devGUID" elif db_table == "Plugins_Objects": - refField = "ObjectGUID" + refField = "objectGuid" else: m = f"[WF] Unsupported object_type: {self.object_type}" mylog("none", [m]) @@ -42,7 +42,7 @@ class Trigger: query = f""" SELECT * FROM {db_table} - WHERE {refField} = '{event["ObjectGUID"]}' + WHERE {refField} = '{event["objectGuid"]}' """ mylog("debug", [query]) diff --git a/test/api_endpoints/test_events_endpoints.py b/test/api_endpoints/test_events_endpoints.py index 2c5978f8..8d97efee 100644 --- a/test/api_endpoints/test_events_endpoints.py +++ b/test/api_endpoints/test_events_endpoints.py @@ -61,7 +61,7 @@ def test_create_event(client, api_token, test_mac): resp = list_events(client, api_token, test_mac) assert resp.status_code == 200 events = resp.get_json().get("events", []) - assert any(ev.get("eve_MAC") == test_mac for ev in events) + assert any(ev.get("eveMac") == test_mac for ev in events) def test_delete_events_for_mac(client, api_token, test_mac): @@ -73,7 +73,7 @@ def test_delete_events_for_mac(client, api_token, test_mac): resp = list_events(client, api_token, test_mac) assert resp.status_code == 200 events = resp.json.get("events", []) - assert any(ev["eve_MAC"] == test_mac for ev in events) + assert any(ev["eveMac"] == test_mac for ev in events) # delete resp = client.delete(f"/events/{test_mac}", headers=auth_headers(api_token)) @@ -143,10 +143,10 @@ def test_delete_events_dynamic_days(client, api_token, test_mac): thirty_days_ago = timeNowUTC(as_string=False) - timedelta(days=30) initial_younger_count = 0 for ev in initial_events: - if ev.get("eve_MAC") == test_mac and ev.get("eve_DateTime"): + if ev.get("eveMac") == test_mac and ev.get("eveDateTime"): try: # Parse event datetime (handle ISO format) - ev_time_str = ev["eve_DateTime"] + ev_time_str = ev["eveDateTime"] # Try parsing with timezone info try: ev_time = datetime.fromisoformat(ev_time_str.replace("Z", "+00:00")) @@ -176,6 +176,6 @@ def test_delete_events_dynamic_days(client, api_token, test_mac): # confirm only recent events remain (pre-existing younger + newly created 5-day-old) resp = list_events(client, api_token, test_mac) events = resp.get_json().get("events", []) - mac_events = [ev for ev in events if ev.get("eve_MAC") == test_mac] + mac_events = [ev for ev in events if ev.get("eveMac") == test_mac] expected_remaining = initial_younger_count + 1 # 1 for the 5-day-old event we created assert len(mac_events) == expected_remaining diff --git a/test/api_endpoints/test_mcp_tools_endpoints.py b/test/api_endpoints/test_mcp_tools_endpoints.py index cdf2a94a..312f4549 100644 --- a/test/api_endpoints/test_mcp_tools_endpoints.py +++ b/test/api_endpoints/test_mcp_tools_endpoints.py @@ -116,7 +116,7 @@ def test_get_open_ports_ip(mock_device_db_conn, mock_plugin_db_conn, client, api mock_execute_result = MagicMock() # Mock for PluginObjectInstance.getByField (returns port data) - mock_execute_result.fetchall.return_value = [{"Object_SecondaryID": "22", "Watched_Value2": "ssh"}, {"Object_SecondaryID": "80", "Watched_Value2": "http"}] + mock_execute_result.fetchall.return_value = [{"objectSecondaryId": "22", "watchedValue2": "ssh"}, {"objectSecondaryId": "80", "watchedValue2": "http"}] # Mock for DeviceInstance.getByIP (returns device with MAC) mock_execute_result.fetchone.return_value = {"devMac": "aa:bb:cc:dd:ee:ff"} @@ -141,7 +141,7 @@ def test_get_open_ports_mac_resolve(mock_plugin_db_conn, client, api_token): # Mock database connection for MAC-based open ports query mock_conn = MagicMock() mock_execute_result = MagicMock() - mock_execute_result.fetchall.return_value = [{"Object_SecondaryID": "80", "Watched_Value2": "http"}] + mock_execute_result.fetchall.return_value = [{"objectSecondaryId": "80", "watchedValue2": "http"}] mock_conn.execute.return_value = mock_execute_result mock_plugin_db_conn.return_value = mock_conn @@ -189,7 +189,7 @@ def test_get_recent_alerts(mock_db_conn, client, api_token): mock_conn = MagicMock() mock_execute_result = MagicMock() now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - mock_execute_result.fetchall.return_value = [{"eve_DateTime": now, "eve_EventType": "New Device", "eve_MAC": "aa:bb:cc:dd:ee:ff"}] + mock_execute_result.fetchall.return_value = [{"eveDateTime": now, "eveEventType": "New Device", "eveMac": "aa:bb:cc:dd:ee:ff"}] mock_conn.execute.return_value = mock_execute_result mock_db_conn.return_value = mock_conn diff --git a/test/api_endpoints/test_sessions_endpoints.py b/test/api_endpoints/test_sessions_endpoints.py index 72fd47e5..50ed1fd2 100644 --- a/test/api_endpoints/test_sessions_endpoints.py +++ b/test/api_endpoints/test_sessions_endpoints.py @@ -74,7 +74,7 @@ def test_list_sessions(client, api_token, test_mac): assert resp.status_code == 200 assert resp.json.get("success") is True sessions = resp.json.get("sessions") - assert any(ses["ses_MAC"] == test_mac for ses in sessions) + assert any(ses["sesMac"] == test_mac for ses in sessions) def test_device_sessions_by_period(client, api_token, test_mac): @@ -105,7 +105,7 @@ def test_device_sessions_by_period(client, api_token, test_mac): print(test_mac) assert isinstance(sessions, list) - assert any(s["ses_MAC"] == test_mac for s in sessions) + assert any(s["sesMac"] == test_mac for s in sessions) def test_device_session_events(client, api_token, test_mac): @@ -178,7 +178,7 @@ def test_delete_session(client, api_token, test_mac): # Confirm deletion resp = client.get(f"/sessions/list?mac={test_mac}", headers=auth_headers(api_token)) sessions = resp.json.get("sessions") - assert not any(ses["ses_MAC"] == test_mac for ses in sessions) + assert not any(ses["sesMac"] == test_mac for ses in sessions) def test_get_sessions_calendar(client, api_token, test_mac): diff --git a/test/backend/sql_safe_builder.py b/test/backend/sql_safe_builder.py index a1bbc604..80690f5d 100644 --- a/test/backend/sql_safe_builder.py +++ b/test/backend/sql_safe_builder.py @@ -20,10 +20,10 @@ class SafeConditionBuilder: # Whitelist of allowed column names for filtering ALLOWED_COLUMNS = { - "eve_MAC", - "eve_DateTime", - "eve_IP", - "eve_EventType", + "eveMac", + "eveDateTime", + "eveIp", + "eveEventType", "devName", "devComments", "devLastIP", @@ -34,15 +34,15 @@ class SafeConditionBuilder: "devPresentLastScan", "devFavorite", "devIsNew", - "Plugin", - "Object_PrimaryId", - "Object_SecondaryId", - "DateTimeChanged", - "Watched_Value1", - "Watched_Value2", - "Watched_Value3", - "Watched_Value4", - "Status", + "plugin", + "objectPrimaryId", + "objectSecondaryId", + "dateTimeChanged", + "watchedValue1", + "watchedValue2", + "watchedValue3", + "watchedValue4", + "status", } # Whitelist of allowed comparison operators @@ -403,7 +403,7 @@ class SafeConditionBuilder: This method handles basic patterns like: - devName = 'value' (with optional AND/OR prefix) - devComments LIKE '%value%' - - eve_EventType IN ('type1', 'type2') + - eveEventType IN ('type1', 'type2') Args: condition: Single condition string to parse @@ -633,7 +633,7 @@ class SafeConditionBuilder: self.parameters[param_name] = event_type param_names.append(f":{param_name}") - sql_snippet = f"AND eve_EventType IN ({', '.join(param_names)})" + sql_snippet = f"AND eveEventType IN ({', '.join(param_names)})" return sql_snippet, self.parameters def get_safe_condition_legacy( diff --git a/test/backend/test_compound_conditions.py b/test/backend/test_compound_conditions.py index 06367b3a..bde2ca10 100644 --- a/test/backend/test_compound_conditions.py +++ b/test/backend/test_compound_conditions.py @@ -174,7 +174,7 @@ def test_compound_with_like_patterns(builder): def test_compound_with_inequality_operators(builder): """Test compound conditions with various inequality operators.""" - condition = "AND eve_DateTime > '2024-01-01' AND eve_DateTime < '2024-12-31'" + condition = "AND eveDateTime > '2024-01-01' AND eveDateTime < '2024-12-31'" sql, params = builder.build_safe_condition(condition) diff --git a/test/backend/test_notification_templates.py b/test/backend/test_notification_templates.py index 0653493d..f4448fd3 100644 --- a/test/backend/test_notification_templates.py +++ b/test/backend/test_notification_templates.py @@ -32,25 +32,25 @@ def _make_json(section, devices, column_names, title="Test Section"): SAMPLE_NEW_DEVICES = [ { "devName": "MyPhone", - "eve_MAC": "aa:bb:cc:dd:ee:ff", + "eveMac": "aa:bb:cc:dd:ee:ff", "devVendor": "", - "eve_IP": "192.168.1.42", - "eve_DateTime": "2025-01-15 10:30:00", - "eve_EventType": "New Device", + "eveIp": "192.168.1.42", + "eveDateTime": "2025-01-15 10:30:00", + "eveEventType": "New Device", "devComments": "", }, { "devName": "Laptop", - "eve_MAC": "11:22:33:44:55:66", + "eveMac": "11:22:33:44:55:66", "devVendor": "Dell", - "eve_IP": "192.168.1.99", - "eve_DateTime": "2025-01-15 11:00:00", - "eve_EventType": "New Device", + "eveIp": "192.168.1.99", + "eveDateTime": "2025-01-15 11:00:00", + "eveEventType": "New Device", "devComments": "Office", }, ] -NEW_DEVICE_COLUMNS = ["devName", "eve_MAC", "devVendor", "eve_IP", "eve_DateTime", "eve_EventType", "devComments"] +NEW_DEVICE_COLUMNS = ["devName", "eveMac", "devVendor", "eveIp", "eveDateTime", "eveEventType", "devComments"] class TestConstructNotificationsTemplates(unittest.TestCase): @@ -100,7 +100,7 @@ class TestConstructNotificationsTemplates(unittest.TestCase): self.assertIn("---------", text) # Legacy format: each header appears as "Header: \tValue" - self.assertIn("eve_MAC:", text) + self.assertIn("eveMac:", text) self.assertIn("aa:bb:cc:dd:ee:ff", text) self.assertIn("devName:", text) self.assertIn("MyPhone", text) @@ -117,7 +117,7 @@ class TestConstructNotificationsTemplates(unittest.TestCase): mock_setting.side_effect = self._setting_factory({ "NTFPRCS_TEXT_SECTION_HEADERS": True, - "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eve_MAC}) - {eve_IP}", + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eveMac}) - {eveIp}", }) json_data = _make_json( @@ -157,7 +157,7 @@ class TestConstructNotificationsTemplates(unittest.TestCase): mock_setting.side_effect = self._setting_factory({ "NTFPRCS_TEXT_SECTION_HEADERS": False, - "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eve_MAC})", + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eveMac})", }) json_data = _make_json( @@ -198,7 +198,7 @@ class TestConstructNotificationsTemplates(unittest.TestCase): mock_setting.side_effect = self._setting_factory({ "NTFPRCS_TEXT_SECTION_HEADERS": True, - "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({BadField}) - {eve_IP}", + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({BadField}) - {eveIp}", }) json_data = _make_json( @@ -217,21 +217,21 @@ class TestConstructNotificationsTemplates(unittest.TestCase): mock_setting.side_effect = self._setting_factory({ "NTFPRCS_TEXT_SECTION_HEADERS": True, - "NTFPRCS_TEXT_TEMPLATE_down_devices": "{devName} ({eve_MAC}) down since {eve_DateTime}", + "NTFPRCS_TEXT_TEMPLATE_down_devices": "{devName} ({eveMac}) down since {eveDateTime}", }) down_devices = [ { "devName": "Router", - "eve_MAC": "ff:ee:dd:cc:bb:aa", + "eveMac": "ff:ee:dd:cc:bb:aa", "devVendor": "Cisco", - "eve_IP": "10.0.0.1", - "eve_DateTime": "2025-01-15 08:00:00", - "eve_EventType": "Device Down", + "eveIp": "10.0.0.1", + "eveDateTime": "2025-01-15 08:00:00", + "eveEventType": "Device Down", "devComments": "", } ] - columns = ["devName", "eve_MAC", "devVendor", "eve_IP", "eve_DateTime", "eve_EventType", "devComments"] + columns = ["devName", "eveMac", "devVendor", "eveIp", "eveDateTime", "eveEventType", "devComments"] json_data = _make_json("down_devices", down_devices, columns, "🔴 Down devices") _, text = construct_notifications(json_data, "down_devices") diff --git a/test/backend/test_safe_builder_unit.py b/test/backend/test_safe_builder_unit.py index 38b7c2e2..f2775129 100644 --- a/test/backend/test_safe_builder_unit.py +++ b/test/backend/test_safe_builder_unit.py @@ -15,7 +15,7 @@ sys.modules['logger'] = Mock() class SafeConditionBuilderForTesting: """Minimal SafeConditionBuilder implementation for tests.""" - ALLOWED_COLUMNS = {'devName', 'eve_MAC', 'eve_EventType'} + ALLOWED_COLUMNS = {'devName', 'eveMac', 'eveEventType'} ALLOWED_OPERATORS = {'=', '!=', '<', '>', '<=', '>=', 'LIKE', 'NOT LIKE'} ALLOWED_LOGICAL_OPERATORS = {'AND', 'OR'} diff --git a/test/backend/test_sql_injection_prevention.py b/test/backend/test_sql_injection_prevention.py index 496003d3..6355c8ac 100644 --- a/test/backend/test_sql_injection_prevention.py +++ b/test/backend/test_sql_injection_prevention.py @@ -174,13 +174,13 @@ def test_null_byte_injection(builder): def test_build_condition_with_allowed_values(builder): """Test building condition with specific allowed values.""" conditions = [ - {"column": "eve_EventType", "operator": "=", "value": "Connected"}, + {"column": "eveEventType", "operator": "=", "value": "Connected"}, {"column": "devName", "operator": "LIKE", "value": "%test%"} ] condition, params = builder.build_condition(conditions, "AND") # Should create valid parameterized condition - assert "eve_EventType = :" in condition + assert "eveEventType = :" in condition assert "devName LIKE :" in condition assert len(params) == 2 diff --git a/test/backend/test_sql_security.py b/test/backend/test_sql_security.py index d3a3dc68..101ac3ff 100644 --- a/test/backend/test_sql_security.py +++ b/test/backend/test_sql_security.py @@ -58,9 +58,9 @@ class TestSafeConditionBuilder(unittest.TestCase): def test_validate_column_name(self): """Test column name validation against whitelist.""" # Valid columns - self.assertTrue(self.builder._validate_column_name('eve_MAC')) + self.assertTrue(self.builder._validate_column_name('eveMac')) self.assertTrue(self.builder._validate_column_name('devName')) - self.assertTrue(self.builder._validate_column_name('eve_EventType')) + self.assertTrue(self.builder._validate_column_name('eveEventType')) # Invalid columns self.assertFalse(self.builder._validate_column_name('malicious_column')) @@ -103,9 +103,9 @@ class TestSafeConditionBuilder(unittest.TestCase): def test_build_in_condition_valid(self): """Test building valid IN conditions.""" - sql, params = self.builder._build_in_condition('AND', 'eve_EventType', 'IN', "'Connected', 'Disconnected'") + sql, params = self.builder._build_in_condition('AND', 'eveEventType', 'IN', "'Connected', 'Disconnected'") - self.assertIn('AND eve_EventType IN', sql) + self.assertIn('AND eveEventType IN', sql) self.assertEqual(len(params), 2) self.assertIn('Connected', params.values()) self.assertIn('Disconnected', params.values()) @@ -162,7 +162,7 @@ class TestSafeConditionBuilder(unittest.TestCase): event_types = ['Connected', 'Disconnected'] sql, params = self.builder.build_event_type_filter(event_types) - self.assertIn('AND eve_EventType IN', sql) + self.assertIn('AND eveEventType IN', sql) self.assertEqual(len(params), 2) self.assertIn('Connected', params.values()) self.assertIn('Disconnected', params.values()) @@ -354,9 +354,9 @@ class TestSecurityBenchmarks(unittest.TestCase): """Test coverage of condition patterns.""" patterns_tested = [ "AND devName = 'value'", - "OR eve_EventType LIKE '%test%'", + "OR eveEventType LIKE '%test%'", "AND devComments IS NULL", - "AND eve_EventType IN ('Connected', 'Disconnected')", + "AND eveEventType IN ('Connected', 'Disconnected')", ] for pattern in patterns_tested: diff --git a/test/db/test_camelcase_migration.py b/test/db/test_camelcase_migration.py new file mode 100644 index 00000000..9e0a4ccb --- /dev/null +++ b/test/db/test_camelcase_migration.py @@ -0,0 +1,307 @@ +""" +Unit tests for migrate_to_camelcase() in db_upgrade. + +Covers: +- Already-migrated schema (eveMac present) → skip, return True +- Unrecognised schema (neither eveMac nor eve_MAC) → skip, return True +- Legacy Events columns renamed to camelCase equivalents +- Legacy Sessions columns renamed to camelCase equivalents +- Legacy Online_History columns renamed to camelCase equivalents +- Legacy Plugins_Objects columns renamed to camelCase equivalents +- Legacy Plugins_Language_Strings columns renamed to camelCase equivalents +- Missing tables are silently skipped without error +- Existing row data is preserved through the column rename +- Views referencing old column names are dropped before ALTER TABLE runs +- Migration is idempotent (second call detects eveMac and returns early) +""" + +import sys +import os +import sqlite3 + +INSTALL_PATH = os.getenv('NETALERTX_APP', '/app') +sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) + +from db.db_upgrade import migrate_to_camelcase # noqa: E402 + + +# --------------------------------------------------------------------------- +# Helpers +# --------------------------------------------------------------------------- + +def _make_cursor(): + """Return an in-memory SQLite cursor and its parent connection.""" + conn = sqlite3.connect(":memory:") + return conn.cursor(), conn + + +def _col_names(cursor, table): + """Return the set of column names for a given table.""" + cursor.execute(f'PRAGMA table_info("{table}")') + return {row[1] for row in cursor.fetchall()} + + +# --------------------------------------------------------------------------- +# Legacy DDL fixtures (pre-migration schema with old column names) +# --------------------------------------------------------------------------- + +_LEGACY_EVENTS_DDL = """ + CREATE TABLE Events ( + eve_MAC TEXT NOT NULL, + eve_IP TEXT NOT NULL, + eve_DateTime DATETIME NOT NULL, + eve_EventType TEXT NOT NULL, + eve_AdditionalInfo TEXT DEFAULT '', + eve_PendingAlertEmail INTEGER NOT NULL DEFAULT 1, + eve_PairEventRowid INTEGER + ) +""" + +_LEGACY_SESSIONS_DDL = """ + CREATE TABLE Sessions ( + ses_MAC TEXT, + ses_IP TEXT, + ses_EventTypeConnection TEXT, + ses_DateTimeConnection DATETIME, + ses_EventTypeDisconnection TEXT, + ses_DateTimeDisconnection DATETIME, + ses_StillConnected INTEGER, + ses_AdditionalInfo TEXT + ) +""" + +_LEGACY_ONLINE_HISTORY_DDL = """ + CREATE TABLE Online_History ( + "Index" INTEGER PRIMARY KEY AUTOINCREMENT, + "Scan_Date" TEXT, + "Online_Devices" INTEGER, + "Down_Devices" INTEGER, + "All_Devices" INTEGER, + "Archived_Devices" INTEGER, + "Offline_Devices" INTEGER + ) +""" + +_LEGACY_PLUGINS_OBJECTS_DDL = """ + CREATE TABLE Plugins_Objects ( + "Index" INTEGER PRIMARY KEY AUTOINCREMENT, + Plugin TEXT NOT NULL, + Object_PrimaryID TEXT NOT NULL, + Object_SecondaryID TEXT NOT NULL, + DateTimeCreated TEXT NOT NULL, + DateTimeChanged TEXT NOT NULL, + Watched_Value1 TEXT NOT NULL, + Watched_Value2 TEXT NOT NULL, + Watched_Value3 TEXT NOT NULL, + Watched_Value4 TEXT NOT NULL, + Status TEXT NOT NULL, + Extra TEXT NOT NULL, + UserData TEXT NOT NULL, + ForeignKey TEXT NOT NULL, + SyncHubNodeName TEXT, + HelpVal1 TEXT, + HelpVal2 TEXT, + HelpVal3 TEXT, + HelpVal4 TEXT, + ObjectGUID TEXT + ) +""" + +_LEGACY_PLUGINS_LANG_DDL = """ + CREATE TABLE Plugins_Language_Strings ( + "Index" INTEGER PRIMARY KEY AUTOINCREMENT, + Language_Code TEXT NOT NULL, + String_Key TEXT NOT NULL, + String_Value TEXT NOT NULL, + Extra TEXT NOT NULL + ) +""" + + +# --------------------------------------------------------------------------- +# Tests +# --------------------------------------------------------------------------- + +class TestMigrateToCamelCase: + + def test_returns_true_if_already_camelcase(self): + """DB already on camelCase schema → skip silently, return True.""" + cur, conn = _make_cursor() + cur.execute(""" + CREATE TABLE Events ( + eveMac TEXT NOT NULL, eveIp TEXT NOT NULL, + eveDateTime DATETIME NOT NULL, eveEventType TEXT NOT NULL, + eveAdditionalInfo TEXT, evePendingAlertEmail INTEGER, + evePairEventRowid INTEGER + ) + """) + conn.commit() + + result = migrate_to_camelcase(cur) + + assert result is True + assert "eveMac" in _col_names(cur, "Events") + + def test_returns_true_if_unknown_schema(self): + """Events exists but has neither eve_MAC nor eveMac → skip, return True.""" + cur, conn = _make_cursor() + cur.execute("CREATE TABLE Events (someOtherCol TEXT)") + conn.commit() + + result = migrate_to_camelcase(cur) + + assert result is True + + def test_events_legacy_columns_renamed(self): + """All legacy eve_* columns are renamed to their camelCase equivalents.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + conn.commit() + + result = migrate_to_camelcase(cur) + + assert result is True + cols = _col_names(cur, "Events") + expected_new = { + "eveMac", "eveIp", "eveDateTime", "eveEventType", + "eveAdditionalInfo", "evePendingAlertEmail", "evePairEventRowid", + } + old_names = { + "eve_MAC", "eve_IP", "eve_DateTime", "eve_EventType", + "eve_AdditionalInfo", "eve_PendingAlertEmail", "eve_PairEventRowid", + } + assert expected_new.issubset(cols), f"Missing new columns: {expected_new - cols}" + assert not old_names & cols, f"Old columns still present: {old_names & cols}" + + def test_sessions_legacy_columns_renamed(self): + """All legacy ses_* columns are renamed to their camelCase equivalents.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + cur.execute(_LEGACY_SESSIONS_DDL) + conn.commit() + + result = migrate_to_camelcase(cur) + + assert result is True + cols = _col_names(cur, "Sessions") + assert { + "sesMac", "sesIp", "sesEventTypeConnection", "sesDateTimeConnection", + "sesEventTypeDisconnection", "sesDateTimeDisconnection", + "sesStillConnected", "sesAdditionalInfo", + }.issubset(cols) + assert not {"ses_MAC", "ses_IP", "ses_DateTimeConnection"} & cols + + def test_online_history_legacy_columns_renamed(self): + """Quoted legacy Online_History column names are renamed to camelCase.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + cur.execute(_LEGACY_ONLINE_HISTORY_DDL) + conn.commit() + + migrate_to_camelcase(cur) + + cols = _col_names(cur, "Online_History") + assert { + "scanDate", "onlineDevices", "downDevices", + "allDevices", "archivedDevices", "offlineDevices", + }.issubset(cols) + assert not {"Scan_Date", "Online_Devices", "Down_Devices"} & cols + + def test_plugins_objects_legacy_columns_renamed(self): + """All renamed Plugins_Objects columns receive their camelCase names.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + cur.execute(_LEGACY_PLUGINS_OBJECTS_DDL) + conn.commit() + + migrate_to_camelcase(cur) + + cols = _col_names(cur, "Plugins_Objects") + assert { + "plugin", "objectPrimaryId", "objectSecondaryId", + "dateTimeCreated", "dateTimeChanged", + "watchedValue1", "watchedValue2", "watchedValue3", "watchedValue4", + "status", "extra", "userData", "foreignKey", "syncHubNodeName", + "helpVal1", "helpVal2", "helpVal3", "helpVal4", "objectGuid", + }.issubset(cols) + assert not { + "Object_PrimaryID", "Watched_Value1", "ObjectGUID", + "ForeignKey", "UserData", "Plugin", + } & cols + + def test_plugins_language_strings_renamed(self): + """Plugins_Language_Strings legacy column names are renamed to camelCase.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + cur.execute(_LEGACY_PLUGINS_LANG_DDL) + conn.commit() + + migrate_to_camelcase(cur) + + cols = _col_names(cur, "Plugins_Language_Strings") + assert {"languageCode", "stringKey", "stringValue", "extra"}.issubset(cols) + assert not {"Language_Code", "String_Key", "String_Value"} & cols + + def test_missing_table_silently_skipped(self): + """Tables in the migration map that don't exist are skipped without error.""" + cur, conn = _make_cursor() + # Only Events (legacy) exists — all other mapped tables are absent + cur.execute(_LEGACY_EVENTS_DDL) + conn.commit() + + result = migrate_to_camelcase(cur) + + assert result is True + assert "eveMac" in _col_names(cur, "Events") + + def test_data_preserved_after_rename(self): + """Existing rows remain accessible under the new camelCase column names.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + cur.execute( + "INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, eve_EventType) " + "VALUES ('aa:bb:cc:dd:ee:ff', '192.168.1.1', '2025-01-01 12:00:00', 'Connected')" + ) + conn.commit() + + migrate_to_camelcase(cur) + + cur.execute( + "SELECT eveMac, eveIp, eveEventType FROM Events WHERE eveMac = 'aa:bb:cc:dd:ee:ff'" + ) + row = cur.fetchone() + assert row is not None, "Row missing after camelCase migration" + assert row[0] == "aa:bb:cc:dd:ee:ff" + assert row[1] == "192.168.1.1" + assert row[2] == "Connected" + + def test_views_dropped_before_migration(self): + """Views referencing old column names do not block ALTER TABLE RENAME COLUMN.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + # A view that references old column names would normally block the rename + cur.execute("CREATE VIEW Events_Devices AS SELECT eve_MAC, eve_IP FROM Events") + conn.commit() + + result = migrate_to_camelcase(cur) + + assert result is True + assert "eveMac" in _col_names(cur, "Events") + # View is dropped (ensure_views() is responsible for recreation separately) + cur.execute("SELECT name FROM sqlite_master WHERE type='view' AND name='Events_Devices'") + assert cur.fetchone() is None + + def test_idempotent_second_run(self): + """Running migration twice is safe — second call detects eveMac and exits early.""" + cur, conn = _make_cursor() + cur.execute(_LEGACY_EVENTS_DDL) + conn.commit() + + first = migrate_to_camelcase(cur) + second = migrate_to_camelcase(cur) + + assert first is True + assert second is True + cols = _col_names(cur, "Events") + assert "eveMac" in cols + assert "eve_MAC" not in cols diff --git a/test/db/test_db_cleanup.py b/test/db/test_db_cleanup.py index 941161b3..6a915632 100644 --- a/test/db/test_db_cleanup.py +++ b/test/db/test_db_cleanup.py @@ -25,26 +25,26 @@ def _make_db(): cur.execute(""" CREATE TABLE Events ( - eve_MAC TEXT NOT NULL, - eve_IP TEXT NOT NULL, - eve_DateTime DATETIME NOT NULL, - eve_EventType TEXT NOT NULL, - eve_AdditionalInfo TEXT DEFAULT '', - eve_PendingAlertEmail INTEGER NOT NULL DEFAULT 1, - eve_PairEventRowid INTEGER + eveMac TEXT NOT NULL, + eveIp TEXT NOT NULL, + eveDateTime DATETIME NOT NULL, + eveEventType TEXT NOT NULL, + eveAdditionalInfo TEXT DEFAULT '', + evePendingAlertEmail INTEGER NOT NULL DEFAULT 1, + evePairEventRowid INTEGER ) """) cur.execute(""" CREATE TABLE Sessions ( - ses_MAC TEXT, - ses_IP TEXT, - ses_EventTypeConnection TEXT, - ses_DateTimeConnection DATETIME, - ses_EventTypeDisconnection TEXT, - ses_DateTimeDisconnection DATETIME, - ses_StillConnected INTEGER, - ses_AdditionalInfo TEXT + sesMac TEXT, + sesIp TEXT, + sesEventTypeConnection TEXT, + sesDateTimeConnection DATETIME, + sesEventTypeDisconnection TEXT, + sesDateTimeDisconnection DATETIME, + sesStillConnected INTEGER, + sesAdditionalInfo TEXT ) """) @@ -59,13 +59,13 @@ def _seed_sessions(cur, old_count: int, recent_count: int, days: int): """ for i in range(old_count): cur.execute( - "INSERT INTO Sessions (ses_MAC, ses_DateTimeConnection) " + "INSERT INTO Sessions (sesMac, sesDateTimeConnection) " "VALUES (?, date('now', ?))", (f"AA:BB:CC:DD:EE:{i:02X}", f"-{days + 1} day"), ) for i in range(recent_count): cur.execute( - "INSERT INTO Sessions (ses_MAC, ses_DateTimeConnection) " + "INSERT INTO Sessions (sesMac, sesDateTimeConnection) " "VALUES (?, date('now'))", (f"11:22:33:44:55:{i:02X}",), ) @@ -75,7 +75,7 @@ def _run_sessions_trim(cur, days: int) -> int: """Execute the exact DELETE used by db_cleanup and return rowcount.""" cur.execute( f"DELETE FROM Sessions " - f"WHERE ses_DateTimeConnection <= date('now', '-{days} day')" + f"WHERE sesDateTimeConnection <= date('now', '-{days} day')" ) return cur.rowcount @@ -126,20 +126,20 @@ class TestSessionsTrim: cur = conn.cursor() # Row exactly AT the boundary (date = 'now' - days exactly) cur.execute( - "INSERT INTO Sessions (ses_MAC, ses_DateTimeConnection) " + "INSERT INTO Sessions (sesMac, sesDateTimeConnection) " "VALUES (?, date('now', ?))", ("AA:BB:CC:00:00:01", "-30 day"), ) # Row just inside the window cur.execute( - "INSERT INTO Sessions (ses_MAC, ses_DateTimeConnection) " + "INSERT INTO Sessions (sesMac, sesDateTimeConnection) " "VALUES (?, date('now', '-29 day'))", ("AA:BB:CC:00:00:02",), ) _run_sessions_trim(cur, days=30) - cur.execute("SELECT ses_MAC FROM Sessions") + cur.execute("SELECT sesMac FROM Sessions") remaining_macs = {row[0] for row in cur.fetchall()} # Boundary row (== threshold) is deleted; inside row survives assert "AA:BB:CC:00:00:02" in remaining_macs, "Row inside window was wrongly deleted" @@ -157,8 +157,8 @@ class TestSessionsTrim: with open(script_path) as fh: source = fh.read() - events_expr = "DELETE FROM Events WHERE eve_DateTime <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')" - sessions_expr = "DELETE FROM Sessions WHERE ses_DateTimeConnection <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')" + events_expr = "DELETE FROM Events WHERE eveDateTime <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')" + sessions_expr = "DELETE FROM Sessions WHERE sesDateTimeConnection <= date('now', '-{str(DAYS_TO_KEEP_EVENTS)} day')" assert events_expr in source, "Events DELETE expression changed unexpectedly" assert sessions_expr in source, "Sessions DELETE is not aligned with Events DELETE" @@ -181,7 +181,7 @@ class TestAnalyze: # Seed some rows so ANALYZE has something to measure for i in range(20): cur.execute( - "INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, eve_EventType) " + "INSERT INTO Events (eveMac, eveIp, eveDateTime, eveEventType) " "VALUES (?, '1.2.3.4', date('now'), 'Connected')", (f"AA:BB:CC:DD:EE:{i:02X}",), ) @@ -238,7 +238,7 @@ class TestPragmaOptimize: for i in range(50): cur.execute( - "INSERT INTO Sessions (ses_MAC, ses_DateTimeConnection) " + "INSERT INTO Sessions (sesMac, sesDateTimeConnection) " "VALUES (?, date('now', '-60 day'))", (f"AA:BB:CC:DD:EE:{i:02X}",), ) @@ -247,7 +247,7 @@ class TestPragmaOptimize: # Mirror the tail sequence from cleanup_database. # WAL checkpoints are omitted: they require no open transaction and are # not supported on :memory: databases (SQLite raises OperationalError). - cur.execute("DELETE FROM Sessions WHERE ses_DateTimeConnection <= date('now', '-30 day')") + cur.execute("DELETE FROM Sessions WHERE sesDateTimeConnection <= date('now', '-30 day')") conn.commit() cur.execute("ANALYZE;") conn.execute("VACUUM;") diff --git a/test/db_test_helpers.py b/test/db_test_helpers.py index f27ee559..27bd9b7e 100644 --- a/test/db_test_helpers.py +++ b/test/db_test_helpers.py @@ -76,16 +76,16 @@ CREATE_DEVICES = """ ) """ -# Includes eve_PairEventRowid — required by insert_events(). +# Includes evePairEventRowid — required by insert_events(). CREATE_EVENTS = """ CREATE TABLE IF NOT EXISTS Events ( - eve_MAC TEXT, - eve_IP TEXT, - eve_DateTime TEXT, - eve_EventType TEXT, - eve_AdditionalInfo TEXT, - eve_PendingAlertEmail INTEGER, - eve_PairEventRowid INTEGER + eveMac TEXT, + eveIp TEXT, + eveDateTime TEXT, + eveEventType TEXT, + eveAdditionalInfo TEXT, + evePendingAlertEmail INTEGER, + evePairEventRowid INTEGER ) """ @@ -327,8 +327,8 @@ def sync_insert_devices( def down_event_macs(cur) -> set: """Return the set of MACs that have a 'Device Down' event row (lowercased).""" - cur.execute("SELECT eve_MAC FROM Events WHERE eve_EventType = 'Device Down'") - return {r["eve_MAC"].lower() for r in cur.fetchall()} + cur.execute("SELECT eveMac FROM Events WHERE eveEventType = 'Device Down'") + return {r["eveMac"].lower() for r in cur.fetchall()} # --------------------------------------------------------------------------- diff --git a/test/integration/integration_test.py b/test/integration/integration_test.py index b4e28f06..818add9d 100755 --- a/test/integration/integration_test.py +++ b/test/integration/integration_test.py @@ -39,15 +39,15 @@ def test_db(test_db_path): # Minimal schema for integration testing cur.execute(''' CREATE TABLE IF NOT EXISTS Events_Devices ( - eve_MAC TEXT, - eve_DateTime TEXT, + eveMac TEXT, + eveDateTime TEXT, devLastIP TEXT, - eve_IP TEXT, - eve_EventType TEXT, + eveIp TEXT, + eveEventType TEXT, devName TEXT, devVendor TEXT, devComments TEXT, - eve_PendingAlertEmail INTEGER + evePendingAlertEmail INTEGER ) ''') @@ -63,24 +63,24 @@ def test_db(test_db_path): cur.execute(''' CREATE TABLE IF NOT EXISTS Events ( - eve_MAC TEXT, - eve_DateTime TEXT, - eve_EventType TEXT, - eve_PendingAlertEmail INTEGER + eveMac TEXT, + eveDateTime TEXT, + eveEventType TEXT, + evePendingAlertEmail INTEGER ) ''') cur.execute(''' CREATE TABLE IF NOT EXISTS Plugins_Events ( - Plugin TEXT, - Object_PrimaryId TEXT, - Object_SecondaryId TEXT, - DateTimeChanged TEXT, - Watched_Value1 TEXT, - Watched_Value2 TEXT, - Watched_Value3 TEXT, - Watched_Value4 TEXT, - Status TEXT + plugin TEXT, + objectPrimaryId TEXT, + objectSecondaryId TEXT, + dateTimeChanged TEXT, + watchedValue1 TEXT, + watchedValue2 TEXT, + watchedValue3 TEXT, + watchedValue4 TEXT, + "status" TEXT ) ''') @@ -91,7 +91,7 @@ def test_db(test_db_path): ('77:88:99:aa:bb:cc', '2024-01-01 12:02:00', '192.168.1.102', '192.168.1.102', 'Disconnected', 'Test Device 3', 'Cisco', 'Third Comment', 1), ] cur.executemany(''' - INSERT INTO Events_Devices (eve_MAC, eve_DateTime, devLastIP, eve_IP, eve_EventType, devName, devVendor, devComments, eve_PendingAlertEmail) + INSERT INTO Events_Devices (eveMac, eveDateTime, devLastIP, eveIp, eveEventType, devName, devVendor, devComments, evePendingAlertEmail) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ''', test_data) @@ -117,7 +117,7 @@ def test_fresh_install_compatibility(builder): def test_existing_db_compatibility(): mock_db = Mock() mock_result = Mock() - mock_result.columnNames = ['devName', 'eve_MAC', 'devVendor', 'eve_IP', 'eve_DateTime', 'eve_EventType', 'devComments'] + mock_result.columnNames = ['devName', 'eveMac', 'devVendor', 'eveIp', 'eveDateTime', 'eveEventType', 'devComments'] mock_result.json = {'data': []} mock_db.get_table_as_json.return_value = mock_result @@ -145,9 +145,9 @@ def test_notification_system_integration(builder): assert "devName = :" in condition assert 'EmailTestDevice' in params.values() - apprise_condition = "AND eve_EventType = 'Connected'" + apprise_condition = "AND eveEventType = 'Connected'" condition, params = builder.get_safe_condition_legacy(apprise_condition) - assert "eve_EventType = :" in condition + assert "eveEventType = :" in condition assert 'Connected' in params.values() webhook_condition = "AND devComments LIKE '%webhook%'" @@ -155,9 +155,9 @@ def test_notification_system_integration(builder): assert "devComments LIKE :" in condition assert '%webhook%' in params.values() - mqtt_condition = "AND eve_MAC = 'aa:bb:cc:dd:ee:ff'" + mqtt_condition = "AND eveMac = 'aa:bb:cc:dd:ee:ff'" condition, params = builder.get_safe_condition_legacy(mqtt_condition) - assert "eve_MAC = :" in condition + assert "eveMac = :" in condition assert 'aa:bb:cc:dd:ee:ff' in params.values() @@ -165,7 +165,7 @@ def test_settings_persistence(builder): test_settings = [ "AND devName = 'Persistent Device'", "AND devComments = {s-quote}Legacy Quote{s-quote}", - "AND eve_EventType IN ('Connected', 'Disconnected')", + "AND eveEventType IN ('Connected', 'Disconnected')", "AND devLastIP = '192.168.1.1'", "" ] @@ -190,9 +190,9 @@ def test_device_operations(builder): def test_plugin_functionality(builder): plugin_conditions = [ - "AND Plugin = 'TestPlugin'", - "AND Object_PrimaryId = 'primary123'", - "AND Status = 'Active'" + "AND plugin = 'TestPlugin'", + "AND objectPrimaryId = 'primary123'", + "AND status = 'Active'" ] for cond in plugin_conditions: safe_condition, params = builder.get_safe_condition_legacy(cond) diff --git a/test/scan/test_down_sleep_events.py b/test/scan/test_down_sleep_events.py index 295f06b6..be43a8b7 100644 --- a/test/scan/test_down_sleep_events.py +++ b/test/scan/test_down_sleep_events.py @@ -258,8 +258,8 @@ class TestInsertEventsSleepSuppression: can_sleep=1, last_connection=last_conn) # Simulate: a Device Down event already exists for this absence cur.execute( - "INSERT INTO Events (eve_MAC, eve_IP, eve_DateTime, eve_EventType, " - "eve_AdditionalInfo, eve_PendingAlertEmail) " + "INSERT INTO Events (eveMac, eveIp, eveDateTime, eveEventType, " + "eveAdditionalInfo, evePendingAlertEmail) " "VALUES (?, '192.168.1.1', ?, 'Device Down', '', 1)", ("bb:00:00:00:00:04", _minutes_ago(15)), ) @@ -269,7 +269,7 @@ class TestInsertEventsSleepSuppression: cur.execute( "SELECT COUNT(*) as cnt FROM Events " - "WHERE eve_MAC = 'bb:00:00:00:00:04' AND eve_EventType = 'Device Down'" + "WHERE eveMac = 'bb:00:00:00:00:04' AND eveEventType = 'Device Down'" ) count = cur.fetchone()["cnt"] assert count == 1, ( diff --git a/test/scan/test_field_lock_scan_integration.py b/test/scan/test_field_lock_scan_integration.py index 01cbdbda..8036ad22 100644 --- a/test/scan/test_field_lock_scan_integration.py +++ b/test/scan/test_field_lock_scan_integration.py @@ -117,12 +117,12 @@ def scan_db_for_new_devices(): cur.execute( """ CREATE TABLE Events ( - eve_MAC TEXT, - eve_IP TEXT, - eve_DateTime TEXT, - eve_EventType TEXT, - eve_AdditionalInfo TEXT, - eve_PendingAlertEmail INTEGER + eveMac TEXT, + eveIp TEXT, + eveDateTime TEXT, + eveEventType TEXT, + eveAdditionalInfo TEXT, + evePendingAlertEmail INTEGER ) """ ) @@ -130,14 +130,14 @@ def scan_db_for_new_devices(): cur.execute( """ CREATE TABLE Sessions ( - ses_MAC TEXT, - ses_IP TEXT, - ses_EventTypeConnection TEXT, - ses_DateTimeConnection TEXT, - ses_EventTypeDisconnection TEXT, - ses_DateTimeDisconnection TEXT, - ses_StillConnected INTEGER, - ses_AdditionalInfo TEXT + sesMac TEXT, + sesIp TEXT, + sesEventTypeConnection TEXT, + sesDateTimeConnection TEXT, + sesEventTypeDisconnection TEXT, + sesDateTimeDisconnection TEXT, + sesStillConnected INTEGER, + sesAdditionalInfo TEXT ) """ ) From 0a7ecb5b7c2ff91fd5e3c2900b4e5359d48d26a4 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Tue, 17 Mar 2026 09:22:25 +0000 Subject: [PATCH 3/9] Update config.json files to add 'ordeable' option and refactor cacheStrings function for consistency --- front/js/cache.js | 4 ++-- front/plugins/arp_scan/config.json | 4 ++-- front/plugins/ddns_update/config.json | 4 ++-- front/plugins/dhcp_leases/config.json | 4 ++-- front/plugins/dhcp_servers/config.json | 4 ++-- front/plugins/internet_ip/config.json | 4 ++-- front/plugins/internet_speedtest/config.json | 4 ++-- front/plugins/nmap_scan/config.json | 4 ++-- front/plugins/omada_sdn_imp/config.json | 4 ++-- front/plugins/omada_sdn_openapi/config.json | 4 ++-- front/plugins/pihole_scan/config.json | 4 ++-- front/plugins/snmp_discovery/config.json | 4 ++-- front/plugins/unifi_import/config.json | 4 ++-- front/plugins/vendor_update/config.json | 4 ++-- front/plugins/website_monitor/config.json | 4 ++-- front/report.php | 2 +- server/db/db_upgrade.py | 2 +- server/initialise.py | 4 ++++ server/scan/name_resolution.py | 12 ++++++------ test/backend/test_notification_templates.py | 14 +++++++------- 20 files changed, 49 insertions(+), 45 deletions(-) diff --git a/front/js/cache.js b/front/js/cache.js index 12c881d3..575a40d4 100644 --- a/front/js/cache.js +++ b/front/js/cache.js @@ -290,7 +290,7 @@ function getSetting (key) { // ----------------------------------------------------------------------------- function cacheStrings() { return new Promise((resolve, reject) => { - if(getCache(CACHE_KEYS.initFlag('cacheStrings')) === "true") + if(getCache(CACHE_KEYS.initFlag('cacheStrings_v2')) === "true") { // Core strings are cached, but plugin strings may have failed silently on // the first load (non-fatal fetch). Always re-fetch them so that plugin @@ -370,7 +370,7 @@ function cacheStrings() { }) .catch((error) => { // Handle failure in any of the language processing - handleFailure('cacheStrings'); + handleFailure('cacheStrings_v2'); reject(error); }); diff --git a/front/plugins/arp_scan/config.json b/front/plugins/arp_scan/config.json index 973927c4..484144ab 100755 --- a/front/plugins/arp_scan/config.json +++ b/front/plugins/arp_scan/config.json @@ -338,7 +338,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -387,7 +387,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/ddns_update/config.json b/front/plugins/ddns_update/config.json index 2337f809..e0d267ed 100755 --- a/front/plugins/ddns_update/config.json +++ b/front/plugins/ddns_update/config.json @@ -432,7 +432,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -477,7 +477,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/dhcp_leases/config.json b/front/plugins/dhcp_leases/config.json index b760f8d3..5beab1e7 100755 --- a/front/plugins/dhcp_leases/config.json +++ b/front/plugins/dhcp_leases/config.json @@ -753,7 +753,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -802,7 +802,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/dhcp_servers/config.json b/front/plugins/dhcp_servers/config.json index 049ec58d..313aea76 100755 --- a/front/plugins/dhcp_servers/config.json +++ b/front/plugins/dhcp_servers/config.json @@ -478,7 +478,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -519,7 +519,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/internet_ip/config.json b/front/plugins/internet_ip/config.json index 679913d5..65a0c5c2 100755 --- a/front/plugins/internet_ip/config.json +++ b/front/plugins/internet_ip/config.json @@ -324,7 +324,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -369,7 +369,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/internet_speedtest/config.json b/front/plugins/internet_speedtest/config.json index 49df80eb..71a6e77d 100755 --- a/front/plugins/internet_speedtest/config.json +++ b/front/plugins/internet_speedtest/config.json @@ -561,7 +561,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -610,7 +610,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/nmap_scan/config.json b/front/plugins/nmap_scan/config.json index b5326075..301fc4d8 100755 --- a/front/plugins/nmap_scan/config.json +++ b/front/plugins/nmap_scan/config.json @@ -553,7 +553,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -594,7 +594,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/omada_sdn_imp/config.json b/front/plugins/omada_sdn_imp/config.json index e4560f44..a4cbd014 100755 --- a/front/plugins/omada_sdn_imp/config.json +++ b/front/plugins/omada_sdn_imp/config.json @@ -429,7 +429,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -462,7 +462,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/omada_sdn_openapi/config.json b/front/plugins/omada_sdn_openapi/config.json index b3737b78..c56eaded 100755 --- a/front/plugins/omada_sdn_openapi/config.json +++ b/front/plugins/omada_sdn_openapi/config.json @@ -402,7 +402,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -435,7 +435,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/pihole_scan/config.json b/front/plugins/pihole_scan/config.json index c8a371de..722723a0 100755 --- a/front/plugins/pihole_scan/config.json +++ b/front/plugins/pihole_scan/config.json @@ -290,7 +290,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -331,7 +331,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index 1c2ea990..95240621 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -658,7 +658,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -699,7 +699,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index b5274514..c9cf3c0a 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -1026,7 +1026,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -1067,7 +1067,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/vendor_update/config.json b/front/plugins/vendor_update/config.json index 17f1f925..6cba3f85 100755 --- a/front/plugins/vendor_update/config.json +++ b/front/plugins/vendor_update/config.json @@ -299,7 +299,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -344,7 +344,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/plugins/website_monitor/config.json b/front/plugins/website_monitor/config.json index 251605fe..26db306f 100755 --- a/front/plugins/website_monitor/config.json +++ b/front/plugins/website_monitor/config.json @@ -538,7 +538,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] @@ -579,7 +579,7 @@ "elements": [ { "elementType": "select", - "elementOptions": [{ "multiple": "true" }], + "elementOptions": [{ "multiple": "true", "ordeable": "true"}], "transformers": [] } ] diff --git a/front/report.php b/front/report.php index d27efdc8..6f6c5bf6 100755 --- a/front/report.php +++ b/front/report.php @@ -174,7 +174,7 @@ } else { // Initial data load - updateData('HTML', -1); // Default format to HTML and load the latest report + updateData('html', -1); // Default format to HTML and load the latest report } }); diff --git a/server/db/db_upgrade.py b/server/db/db_upgrade.py index 83739315..03ca83a4 100755 --- a/server/db/db_upgrade.py +++ b/server/db/db_upgrade.py @@ -817,7 +817,7 @@ def migrate_to_camelcase(sql) -> bool: for table, column_map in _CAMELCASE_COLUMN_MAP.items(): # Check table exists - sql.execute(f"SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table,)) + sql.execute("SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table,)) if not sql.fetchone(): mylog("verbose", [f"[db_upgrade] Table '{table}' does not exist — skipping"]) continue diff --git a/server/initialise.py b/server/initialise.py index 49e50b05..fcd48152 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -865,6 +865,10 @@ _column_replacements = { # Session columns r"\bses_MAC\b": "sesMac", r"\bses_IP\b": "sesIp", + r"\bses_DateTimeConnection\b": "sesDateTimeConnection", + r"\bses_DateTimeDisconnection\b": "sesDateTimeDisconnection", + r"\bses_EventTypeConnection\b": "sesEventTypeConnection", + r"\bses_EventTypeDisconnection\b": "sesEventTypeDisconnection", r"\bses_StillConnected\b": "sesStillConnected", r"\bses_AdditionalInfo\b": "sesAdditionalInfo", # Plugin columns (templates + WATCH values) diff --git a/server/scan/name_resolution.py b/server/scan/name_resolution.py index e05b4a15..d3cf654d 100755 --- a/server/scan/name_resolution.py +++ b/server/scan/name_resolution.py @@ -23,10 +23,10 @@ class NameResolver: nameNotFound = ResolvedName() # Check by MAC - sql.execute(f""" + sql.execute(""" SELECT watchedValue2 FROM Plugins_Objects - WHERE plugin = '{plugin}' AND objectPrimaryId = '{pMAC}' - """) + WHERE plugin = ? AND objectPrimaryId = ? + """, (plugin, pMAC)) result = sql.fetchall() # self.db.commitDB() # Issue #1251: Optimize name resolution lookup if result: @@ -36,10 +36,10 @@ class NameResolver: # Check name by IP if enabled if get_setting_value('NEWDEV_IP_MATCH_NAME'): - sql.execute(f""" + sql.execute(""" SELECT watchedValue2 FROM Plugins_Objects - WHERE plugin = '{plugin}' AND objectSecondaryId = '{pIP}' - """) + WHERE plugin = ? AND objectSecondaryId = ? + """, (plugin, pIP)) result = sql.fetchall() # self.db.commitDB() # Issue #1251: Optimize name resolution lookup if result: diff --git a/test/backend/test_notification_templates.py b/test/backend/test_notification_templates.py index f4448fd3..3a17237f 100644 --- a/test/backend/test_notification_templates.py +++ b/test/backend/test_notification_templates.py @@ -247,21 +247,21 @@ class TestConstructNotificationsTemplates(unittest.TestCase): mock_setting.side_effect = self._setting_factory({ "NTFPRCS_TEXT_SECTION_HEADERS": True, - "NTFPRCS_TEXT_TEMPLATE_down_reconnected": "{devName} ({eve_MAC}) reconnected at {eve_DateTime}", + "NTFPRCS_TEXT_TEMPLATE_down_reconnected": "{devName} ({eveMac}) reconnected at {eveDateTime}", }) reconnected = [ { "devName": "Switch", - "eve_MAC": "aa:11:bb:22:cc:33", + "eveMac": "aa:11:bb:22:cc:33", "devVendor": "Netgear", - "eve_IP": "10.0.0.2", - "eve_DateTime": "2025-01-15 09:30:00", - "eve_EventType": "Down Reconnected", + "eveIp": "10.0.0.2", + "eveDateTime": "2025-01-15 09:30:00", + "eveEventType": "Down Reconnected", "devComments": "", } ] - columns = ["devName", "eve_MAC", "devVendor", "eve_IP", "eve_DateTime", "eve_EventType", "devComments"] + columns = ["devName", "eveMac", "devVendor", "eveIp", "eveDateTime", "eveEventType", "devComments"] json_data = _make_json("down_reconnected", reconnected, columns, "🔁 Reconnected down devices") _, text = construct_notifications(json_data, "down_reconnected") @@ -288,7 +288,7 @@ class TestConstructNotificationsTemplates(unittest.TestCase): # Get HTML with template mock_setting.side_effect = self._setting_factory({ "NTFPRCS_TEXT_SECTION_HEADERS": True, - "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eve_MAC})", + "NTFPRCS_TEXT_TEMPLATE_new_devices": "{devName} ({eveMac})", }) html_with, _ = construct_notifications(json_data, "new_devices") From 43984132c49a065e4fff5378db27a255bc19dc0a Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Tue, 17 Mar 2026 09:46:27 +0000 Subject: [PATCH 4/9] Fix Spanish translations in config.json files for internet_speedtest, nmap_scan, and snmp_discovery plugins --- front/plugins/internet_speedtest/config.json | 2 +- front/plugins/nmap_scan/config.json | 2 +- front/plugins/snmp_discovery/config.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/front/plugins/internet_speedtest/config.json b/front/plugins/internet_speedtest/config.json index 71a6e77d..4aad632f 100755 --- a/front/plugins/internet_speedtest/config.json +++ b/front/plugins/internet_speedtest/config.json @@ -644,7 +644,7 @@ }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." }, { "language_code": "de_de", diff --git a/front/plugins/nmap_scan/config.json b/front/plugins/nmap_scan/config.json index 301fc4d8..5eb8e5f6 100755 --- a/front/plugins/nmap_scan/config.json +++ b/front/plugins/nmap_scan/config.json @@ -619,7 +619,7 @@ }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." } ] } diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index 95240621..ab71bc5e 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -688,7 +688,7 @@ }, { "language_code": "es_es", - "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es el nombre de host (no detectable)
  • watchedValue2 es la IP del enrutador
  • watchedValue3< /code> no se utiliza
  • watchedValue4 no se utiliza
" + "string": "Envíe una notificación si los valores seleccionados cambian. Utilice CTRL + clic para seleccionar/deseleccionar.
  • watchedValue1 es el nombre de host (no detectable)
  • watchedValue2 es la IP del enrutador
  • watchedValue3 no se utiliza
  • watchedValue4 no se utiliza
" } ] }, From b311113575fc62e1b0dbef9077953e99998fbf3f Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Tue, 17 Mar 2026 11:58:53 +0000 Subject: [PATCH 5/9] Fix Spanish translations and improve HTML attributes in config files and report --- front/plugins/vendor_update/config.json | 2 +- front/plugins/website_monitor/config.json | 2 +- front/report.php | 2 +- server/initialise.py | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/front/plugins/vendor_update/config.json b/front/plugins/vendor_update/config.json index 6cba3f85..3625550d 100755 --- a/front/plugins/vendor_update/config.json +++ b/front/plugins/vendor_update/config.json @@ -378,7 +378,7 @@ }, { "language_code": "es_es", - "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que seleccionó watchedValueN Las columnas cambiaron." + "string": "Envíe una notificación solo en estos estados. new significa que se descubrió un nuevo objeto único (combinación única de PrimaryId y SecondaryId). watched-changed significa que las columnas watchedValueN seleccionadas cambiaron." }, { "language_code": "de_de", diff --git a/front/plugins/website_monitor/config.json b/front/plugins/website_monitor/config.json index 26db306f..0e4c7e7f 100755 --- a/front/plugins/website_monitor/config.json +++ b/front/plugins/website_monitor/config.json @@ -605,7 +605,7 @@ "description": [ { "language_code": "en_us", - "string": "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." + "string": "Send a notification only on these statuses. new means a new unique (unique combination of objectPrimaryId and objectSecondaryId) object was discovered. watched-changed means that selected watchedValueN columns changed." }, { "language_code": "es_es", diff --git a/front/report.php b/front/report.php index 6f6c5bf6..33afb736 100755 --- a/front/report.php +++ b/front/report.php @@ -109,7 +109,7 @@ `; break; case 'text': - notificationData.innerHTML = `
${formatData}
`; + notificationData.innerHTML = `
${formatData}
`; break; } diff --git a/server/initialise.py b/server/initialise.py index fcd48152..740d7cef 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -862,6 +862,7 @@ _column_replacements = { r"\beve_AdditionalInfo\b": "eveAdditionalInfo", r"\beve_PendingAlertEmail\b": "evePendingAlertEmail", r"\beve_PairEventRowid\b": "evePairEventRowid", + r"\beve_PairEventRowID\b": "evePairEventRowid", # Session columns r"\bses_MAC\b": "sesMac", r"\bses_IP\b": "sesIp", From d7c7bd2cd2944188905ef8df5437ac0fef10a005 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Wed, 18 Mar 2026 09:57:20 +0000 Subject: [PATCH 6/9] Enhance SQL templates to prevent duplicate notifications for 'Down Reconnected' devices in event section --- server/messaging/notification_sections.py | 17 ++++++++++++----- server/messaging/reporting.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/server/messaging/notification_sections.py b/server/messaging/notification_sections.py index f88821b2..031d54b2 100644 --- a/server/messaging/notification_sections.py +++ b/server/messaging/notification_sections.py @@ -83,15 +83,22 @@ SQL_TEMPLATES = { "down_reconnected": """ SELECT devName, - eveMac, + reconnected_devices.eveMac, devVendor, - eveIp, - eveDateTime, - eveEventType, + reconnected_devices.eveIp, + reconnected_devices.eveDateTime, + reconnected_devices.eveEventType, devComments FROM Events_Devices AS reconnected_devices WHERE reconnected_devices.eveEventType = 'Down Reconnected' AND reconnected_devices.evePendingAlertEmail = 1 + AND NOT EXISTS ( + SELECT 1 FROM Events AS newer + WHERE newer.eveMac = reconnected_devices.eveMac + AND newer.eveEventType = 'Down Reconnected' + AND newer.evePendingAlertEmail = 1 + AND newer.eveDateTime > reconnected_devices.eveDateTime + ) ORDER BY reconnected_devices.eveDateTime """, "events": """ @@ -105,7 +112,7 @@ SQL_TEMPLATES = { devComments FROM Events_Devices WHERE evePendingAlertEmail = 1 - AND eveEventType IN ('Connected', 'Down Reconnected', 'Disconnected','IP Changed') {condition} + AND eveEventType IN ({event_types}) {condition} ORDER BY eveDateTime """, "plugins": """ diff --git a/server/messaging/reporting.py b/server/messaging/reporting.py index 45a37453..dfe9f087 100755 --- a/server/messaging/reporting.py +++ b/server/messaging/reporting.py @@ -198,6 +198,14 @@ def get_notifications(db): format_vars = {"condition": safe_condition} if section == "down_devices": format_vars["alert_down_minutes"] = alert_down_minutes + if section == "events": + # 'Down Reconnected' has its own dedicated section; exclude it + # from events when that section is also active to prevent the + # same device appearing twice with different IP sources. + if "down_reconnected" in sections: + format_vars["event_types"] = "'Connected', 'Disconnected','IP Changed'" + else: + format_vars["event_types"] = "'Connected', 'Down Reconnected', 'Disconnected','IP Changed'" sqlQuery = template.format(**format_vars) except Exception as e: @@ -205,6 +213,11 @@ def get_notifications(db): fallback_vars = {"condition": ""} if section == "down_devices": fallback_vars["alert_down_minutes"] = alert_down_minutes + if section == "events": + if "down_reconnected" in sections: + fallback_vars["event_types"] = "'Connected', 'Disconnected','IP Changed'" + else: + fallback_vars["event_types"] = "'Connected', 'Down Reconnected', 'Disconnected','IP Changed'" sqlQuery = template.format(**fallback_vars) parameters = {} From 7569923481aed30deaab513c428bdb36a8d82a3f Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Sat, 21 Mar 2026 20:55:24 +0000 Subject: [PATCH 7/9] Refactor column name replacements to include variations for ObjectPrimaryID and ObjectSecondaryID --- server/initialise.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/initialise.py b/server/initialise.py index 740d7cef..a7aa1883 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -875,8 +875,10 @@ _column_replacements = { # Plugin columns (templates + WATCH values) r"\bObject_PrimaryID\b": "objectPrimaryId", r"\bObject_PrimaryId\b": "objectPrimaryId", + r"\bObjectPrimaryID\b": "objectPrimaryId", r"\bObject_SecondaryID\b": "objectSecondaryId", r"\bObject_SecondaryId\b": "objectSecondaryId", + r"\bObjectSecondaryID\b": "objectSecondaryId", r"\bWatched_Value1\b": "watchedValue1", r"\bWatched_Value2\b": "watchedValue2", r"\bWatched_Value3\b": "watchedValue3", From fa22523a0bffd83cf1feeaaab22acef9d89292d7 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Sat, 21 Mar 2026 21:10:37 +0000 Subject: [PATCH 8/9] Refactor device tiles SQL logic to use get_sql_devices_tiles function for improved maintainability Feature Request - Flapping and Sleeping nuances Fixes #1567 --- server/api.py | 4 ++-- server/const.py | 35 ------------------------------ server/db/db_helper.py | 49 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 37 deletions(-) diff --git a/server/api.py b/server/api.py index 71d226ba..2ed27e37 100755 --- a/server/api.py +++ b/server/api.py @@ -18,9 +18,9 @@ from const import ( sql_language_strings, sql_notifications_all, sql_online_history, - sql_devices_tiles, sql_devices_filters, ) +from db.db_helper import get_sql_devices_tiles from logger import mylog from helper import write_file, get_setting_value from utils.datetime_utils import timeNowUTC @@ -67,7 +67,7 @@ def update_api( ["plugins_language_strings", sql_language_strings], ["notifications", sql_notifications_all], ["online_history", sql_online_history], - ["devices_tiles", sql_devices_tiles], + ["devices_tiles", get_sql_devices_tiles()], ["devices_filters", sql_devices_filters], ["custom_endpoint", conf.API_CUSTOM_SQL], ] diff --git a/server/const.py b/server/const.py index 135102ec..e07eda06 100755 --- a/server/const.py +++ b/server/const.py @@ -68,41 +68,6 @@ sql_devices_all = """ """ sql_appevents = """select * from AppEvents order by dateTimeCreated desc""" -# The below query calculates counts of devices in various categories: -# (connected/online, offline, down, new, archived), -# as well as a combined count for devices that match any status listed in the UI_MY_DEVICES setting -sql_devices_tiles = """ - WITH Statuses AS ( - SELECT setValue - FROM Settings - WHERE setKey = 'UI_MY_DEVICES' - ), - MyDevicesFilter AS ( - SELECT - -- Build a dynamic filter for devices matching any status in UI_MY_DEVICES - devPresentLastScan, devAlertDown, devIsNew, devIsArchived - FROM Devices - WHERE - (instr((SELECT setValue FROM Statuses), 'online') > 0 AND devPresentLastScan = 1) OR - (instr((SELECT setValue FROM Statuses), 'offline') > 0 AND devPresentLastScan = 0 AND devIsArchived = 0) OR - (instr((SELECT setValue FROM Statuses), 'down') > 0 AND devPresentLastScan = 0 AND devAlertDown = 1) OR - (instr((SELECT setValue FROM Statuses), 'new') > 0 AND devIsNew = 1) OR - (instr((SELECT setValue FROM Statuses), 'archived') > 0 AND devIsArchived = 1) - ) - SELECT - -- Counts for each individual status - (SELECT COUNT(*) FROM Devices WHERE devPresentLastScan = 1) AS connected, - (SELECT COUNT(*) FROM Devices WHERE devPresentLastScan = 0) AS offline, - (SELECT COUNT(*) FROM Devices WHERE devPresentLastScan = 0 AND devAlertDown = 1) AS down, - (SELECT COUNT(*) FROM Devices WHERE devIsNew = 1) AS new, - (SELECT COUNT(*) FROM Devices WHERE devIsArchived = 1) AS archived, - (SELECT COUNT(*) FROM Devices WHERE devFavorite = 1) AS favorites, - (SELECT COUNT(*) FROM Devices) AS "all", - (SELECT COUNT(*) FROM Devices) AS "all_devices", - -- My Devices count - (SELECT COUNT(*) FROM MyDevicesFilter) AS my_devices - FROM Statuses; - """ sql_devices_filters = """ SELECT DISTINCT 'devSite' AS columnName, devSite AS columnValue FROM Devices WHERE devSite NOT IN ('', 'null') AND devSite IS NOT NULL diff --git a/server/db/db_helper.py b/server/db/db_helper.py index a962ef2d..c828de00 100755 --- a/server/db/db_helper.py +++ b/server/db/db_helper.py @@ -66,6 +66,55 @@ def get_device_condition_by_status(device_status): return get_device_conditions().get(device_status, "WHERE 1=0") +# ------------------------------------------------------------------------------- +def get_sql_devices_tiles(): + """Build the device tiles count SQL using get_device_conditions() to avoid duplicating filter logic.""" + conds = get_device_conditions() + + def f(key): + """Strip 'WHERE ' prefix for use inside SELECT subqueries.""" + return conds[key][len("WHERE "):] + + # UI_MY_DEVICES setting values mapped to their device_conditions keys + my_devices_setting_map = [ + ("online", "connected"), + ("offline", "offline"), + ("down", "down"), + ("new", "new"), + ("archived", "archived"), + ] + + my_devices_clauses = "\n OR ".join( + f"(instr((SELECT setValue FROM Statuses), '{sk}') > 0 AND {f(ck)})" + for sk, ck in my_devices_setting_map + ) + + return f""" + WITH Statuses AS ( + SELECT setValue + FROM Settings + WHERE setKey = 'UI_MY_DEVICES' + ), + MyDevicesFilter AS ( + SELECT devMac + FROM Devices + WHERE + {my_devices_clauses} + ) + SELECT + (SELECT COUNT(*) FROM Devices WHERE {f('connected')}) AS connected, + (SELECT COUNT(*) FROM Devices WHERE {f('offline')}) AS offline, + (SELECT COUNT(*) FROM Devices WHERE {f('down')}) AS down, + (SELECT COUNT(*) FROM Devices WHERE {f('new')}) AS new, + (SELECT COUNT(*) FROM Devices WHERE {f('archived')}) AS archived, + (SELECT COUNT(*) FROM Devices WHERE {f('favorites')}) AS favorites, + (SELECT COUNT(*) FROM Devices WHERE {f('all')}) AS "all", + (SELECT COUNT(*) FROM Devices) AS "all_devices", + (SELECT COUNT(*) FROM MyDevicesFilter) AS my_devices + FROM Statuses; + """ + + # ------------------------------------------------------------------------------- # Creates a JSON-like dictionary from a database row def row_to_json(names, row): From 7278ee8cfa20e7c51f02361749eb771e6ee524a4 Mon Sep 17 00:00:00 2001 From: "Jokob @NetAlertX" <96159884+jokob-sk@users.noreply.github.com> Date: Sat, 21 Mar 2026 21:28:42 +0000 Subject: [PATCH 9/9] Refactor getTotals method to clarify API contract and ensure stable response structure #1569 #1561 --- server/models/device_instance.py | 28 +++++++++++++------- test/api_endpoints/test_devices_endpoints.py | 19 ++++++------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/server/models/device_instance.py b/server/models/device_instance.py index 1384a75f..cc8d9d89 100755 --- a/server/models/device_instance.py +++ b/server/models/device_instance.py @@ -327,20 +327,30 @@ class DeviceInstance: return {"success": True, "inserted": row_count, "skipped_lines": skipped} def getTotals(self): - """Get device totals by status.""" + """Get device totals by status. + + Returns a list of 6 counts in the documented positional order: + [all, connected, favorites, new, down, archived] + + IMPORTANT: This order is a public API contract consumed by: + - presence.php (reads indices 0-5) + - /devices/totals/named (maps indices 0-5 to named fields) + - homepage widget datav2 (reads /devices/totals indices) + DO NOT change the order or add/remove fields without a breaking-change release. + """ conn = get_temp_db_connection() sql = conn.cursor() - conditions = get_device_conditions() + all_conditions = get_device_conditions() - # Build sub-selects dynamically for all dictionary entries - sub_queries = [] - for key, condition in conditions.items(): - # Make sure the alias is SQL-safe (no spaces or special chars) - alias = key.replace(" ", "_").lower() - sub_queries.append(f'(SELECT COUNT(*) FROM DevicesView {condition}) AS "{alias}"') + # Only the 6 public fields, in documented positional order. + # DO NOT change this order — it is a stable API contract. + keys = ["all", "connected", "favorites", "new", "down", "archived"] + sub_queries = [ + f'(SELECT COUNT(*) FROM DevicesView {all_conditions[key]}) AS "{key}"' + for key in keys + ] - # Join all sub-selects with commas query = "SELECT\n " + ",\n ".join(sub_queries) sql.execute(query) row = sql.fetchone() diff --git a/test/api_endpoints/test_devices_endpoints.py b/test/api_endpoints/test_devices_endpoints.py index 62a3725c..6517feb6 100644 --- a/test/api_endpoints/test_devices_endpoints.py +++ b/test/api_endpoints/test_devices_endpoints.py @@ -8,7 +8,6 @@ import pytest from helper import get_setting_value from api_server.api_server_start import app -from db.db_helper import get_device_conditions @pytest.fixture(scope="session") @@ -163,17 +162,15 @@ def test_devices_totals(client, api_token, test_mac): data = resp.json assert isinstance(data, list) - # 3. Dynamically get expected length - conditions = get_device_conditions() - expected_length = len(conditions) - assert len(data) == expected_length + # 3. Verify the response has exactly 6 elements in documented order: + # [all, connected, favorites, new, down, archived] + expected_length = 6 + assert len(data) == expected_length, ( + f"Expected 6 totals (all, connected, favorites, new, down, archived), got {len(data)}" + ) - # 4. Check that at least 1 device exists when there are any conditions - if expected_length > 0: - assert data[0] >= 1 # 'devices' count includes the dummy device - else: - # no conditions defined; data should be an empty list - assert data == [] + # 4. Check that at least 1 device exists (all count includes the dummy device) + assert data[0] >= 1 # index 0 = 'all' finally: delete_dummy(client, api_token, test_mac)