mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-11-06 23:43:07 -05:00
With PIHOLEAPI_GET_OFFLINE enabled, PIHOLEAPI imports devices it considers offline, but every row still counted as a live sighting. The plugin computed the online state, yet never passed it on, and its config.json mapped nothing to CurrentScan.scanPresence, so each row got the column default 1. An offline device imported only for its name, vendor and IP was marked online. ADGUARDIMP had the same problem in #1813 and fixed it the same way. Changes: - main() passes the online state as helpVal4 '1' or '0' to add_object() (server/plugins/pihole_api_scan/pihole_api_scan.py). - config.json maps helpVal4 to scanPresence, the same column definition adguard_import uses. The GET_OFFLINE description says offline devices are imported without being marked online; the README says the same. - test/db_test_helpers.py: make_plugin_event_row() takes an optional help_val4, and CREATE_CURRENT_SCAN gets the CHECK (scanPresence IN (0, 1)) of the real schema (db_upgrade.py), so a test sees the same constraint as production. - New test/scan/test_piholeapi_scan_presence_mapping.py runs the real PIHOLEAPI config.json through process_plugin_events() and checks that a helpVal4 '0' row lands in CurrentScan with scanPresence 0. - test/plugins/test_pihole_api_scan.py: main() writes helpVal4 '0' for an offline device and '1' for every IP row of an online device. Both new tests fail without this change. Impact: Devices imported only because of PIHOLEAPI_GET_OFFLINE keep their name, vendor and IP data but no longer mark the device as online. Live check against Pi-hole v6.8: 28 rows with helpVal4 '0', 5 with '1'; the absent phone got devPresentLastScan 0 and only a New Device event. With GET_OFFLINE disabled (the default) every imported row is online, so nothing changes there.
NetAlertX modules
The original pilaert.py code is now moved to this new folder and split into different modules.
| Module | Description |
|---|---|
__main__.py |
The MAIN program of NetAlertX |
__init__.py |
an empty init file |
README.md |
this readme file |
../server/plugins |
a folder containing all plugins that publish notifications or scan for devices |
api.py |
updating the API endpoints with the relevant data. |
appevent.py |
TBC |
const.py |
A place to define the constants for NetAlertX like log path or config path. |
conf.py |
conf.py holds the configuration variables and makes them available for all modules. It is also the workaround for global variables that need to be resolved at some point |
database.py |
This module connects to the DB, makes sure the DB is up to date and defines some standard queries and interfaces. |
device.py |
The device module looks after the devices and saves the scan results into the devices |
flows.py |
TBC |
helper.py |
Helper as the name suggest contains multiple little functions and methods used in many of the other modules and helps keep things clean |
initialise.py |
Initiatlise sets up the environment and makes everything ready to go |
logger.py |
Logger is there the keep all the logs organised and looking identical. |
networscan.py |
Networkscan collects the scan results (maybe to merge with reporting.py) |
notification.py |
Creates and handles the notification object and generates ther HTML and text variants of the message |
plugin.py |
This is where the plugins get integrated into the backend of NetAlertX |
plugin_utils.py |
Helper utilities for plugin.py |
reporting.py |
Reporting collects the data for the notification reports |
scheduler.py |
All things scheduling |