From d2b6e75483a3f0a7aa62f73764fc225139ccb066 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Thu, 10 Aug 2023 08:01:16 +1000 Subject: [PATCH] Docs + before_config_save run option --- docker-compose.yml | 9 ++++----- front/plugins/README.md | 17 +++++++++++++++-- front/plugins/set_password/config.json | 4 ++-- pialert/__main__.py | 3 +-- pialert/conf.py | 1 - pialert/initialise.py | 9 +++++---- pialert/reporting.py | 2 -- 7 files changed, 27 insertions(+), 18 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b950913a..4031c4d9 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,12 +20,11 @@ services: # --------------------------------------------------------------------------- # DELETE START anyone trying to use this file: comment out / delete BELOW lines, they are only for development purposes - ${APP_DATA_LOCATION}/pialert/dhcp_samples/dhcp1.leases:/mnt/dhcp1.leases - - ${APP_DATA_LOCATION}/pialert/dhcp_samples/dhcp2.leases:/mnt/dhcp2.leases - # - ${DEV_LOCATION}/back/pialert.py:/home/pi/pialert/back/pialert.py + - ${APP_DATA_LOCATION}/pialert/dhcp_samples/dhcp2.leases:/mnt/dhcp2.leases - ${DEV_LOCATION}/pialert:/home/pi/pialert/pialert - # - ${DEV_LOCATION}/back/report_template.html:/home/pi/pialert/back/report_template.html - # - ${DEV_LOCATION}/back/report_template_new_version.html:/home/pi/pialert/back/report_template_new_version.html - # - ${DEV_LOCATION}/back/report_template.txt:/home/pi/pialert/back/report_template.txt + - ${DEV_LOCATION}/back/report_template.html:/home/pi/pialert/back/report_template.html + - ${DEV_LOCATION}/back/report_template_new_version.html:/home/pi/pialert/back/report_template_new_version.html + - ${DEV_LOCATION}/back/report_template.txt:/home/pi/pialert/back/report_template.txt - ${DEV_LOCATION}/pholus:/home/pi/pialert/pholus - ${DEV_LOCATION}/dockerfiles:/home/pi/pialert/dockerfiles - ${APP_DATA_LOCATION}/pialert/php.ini:/etc/php/7.4/fpm/php.ini diff --git a/front/plugins/README.md b/front/plugins/README.md index 27d8b5ab..5d0fd4e2 100755 --- a/front/plugins/README.md +++ b/front/plugins/README.md @@ -8,6 +8,7 @@ - [unifi_import (UNFIMP)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/unifi_import/) - [snmp_discovery (SNMPDSC)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/snmp_discovery/) - [undiscoverables (UNDIS)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/undiscoverables/) +- [arp_scan (ARPSCAN)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/arp_scan/) ### SQL query based plugins - [nmap_services (NMAPSERV)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/nmap_services/) @@ -15,6 +16,9 @@ ### template based plugins - [newdev_template (NEWDEV)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/newdev_template/) +### External SQLite based plugins +- [pihole_scan (PIHOLE)](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/newdev_template/) + ## 🌟 Create a custom plugin: Overview | ![Screen 1][screen1] | ![Screen 2][screen2] | ![Screen 3][screen3] | @@ -296,6 +300,9 @@ PiAlert will take the results of the plugin execution and insert these results i This approach is used to implement the `DHCPLSS` plugin. The script parses all supplied "dhcp.leases" files, get's the results in the generic table format outlined in the "Column order and values" section above and takes individual values and inserts them into the `"DHCP_Leases"` database table in the PiAlert database. All this is achieved by: +> [!NOTE] +> If results are mapped to the `CurrentScan` table, the data is then included into the regular scan loop, so for example notification for devices are sent out. + 1) Specifying the database table into which the results are inserted by defining `"mapped_to_table": "DHCP_Leases"` in the root of the `config.json` file as shown below: ```json @@ -440,8 +447,14 @@ Required attributes are: You can have any `"function": "my_custom_name"` custom name, however, the ones listed below have a specific functionality attached to them. If you use a custom name, then the setting is mostly used as an input parameter for the `params` section. - `RUN` - (required) Specifies when the service is executed - - Supported Options: "disabled", "once", "schedule" (if included then a `RUN_SCHD` setting needs to be specified), "always_after_scan", "on_new_device" -- `RUN_SCHD` - (required if you include the above `RUN` function) Cron-like scheduling used if the `RUN` setting set to `schedule` + - Supported Options: + - "disabled" - not run + - "once" - run on app start or on settings saved + - "schedule" - if included then a `RUN_SCHD` setting needs to be specified to determine what's the schedule, + - "always_after_scan" - run always after a scan is finished + - "on_new_device" - run when a new device is detected + - "before_config_save" - run before the config is marked as saved. Useful if your plugin needs to modify the `pialert.conf` file. +- `RUN_SCHD` - (required if you include the above `RUN` function) Cron-like scheduling is used if the `RUN` setting set to `schedule` - `CMD` - (required) What command should be executed. - `API_SQL` - (optional) Generates a `table_` + code_name + `.json` file as per [API docs](https://github.com/jokob-sk/Pi.Alert/blob/main/docs/API.md). - `RUN_TIMEOUT` - (optional) Max execution time of the script. If not specified a default value of 10 seconds is used to prevent hanging. diff --git a/front/plugins/set_password/config.json b/front/plugins/set_password/config.json index 655d2c93..b0bd46e1 100755 --- a/front/plugins/set_password/config.json +++ b/front/plugins/set_password/config.json @@ -7,7 +7,7 @@ "localized": ["display_name", "description", "icon"], "display_name": [{ "language_code": "en_us", - "string": "UI password" + "string": "Set password" }], "description": [{ "language_code": "en_us", @@ -31,7 +31,7 @@ "function": "RUN", "type": "text.select", "default_value":"disabled", - "options": ["disabled", "once"], + "options": ["disabled", "before_config_save"], "localized": ["name", "description"], "name" :[{ "language_code":"en_us", diff --git a/pialert/__main__.py b/pialert/__main__.py index abb08b53..0413d0a1 100755 --- a/pialert/__main__.py +++ b/pialert/__main__.py @@ -107,8 +107,7 @@ def main (): # TODO fix these loop_start_time = conf.loop_start_time # TODO fix - last_update_vendors = conf.last_update_vendors - last_network_scan = conf.last_network_scan + last_update_vendors = conf.last_update_vendors last_cleanup = conf.last_cleanup last_version_check = conf.last_version_check diff --git a/pialert/conf.py b/pialert/conf.py index 4f670c70..4a5f3288 100755 --- a/pialert/conf.py +++ b/pialert/conf.py @@ -19,7 +19,6 @@ plugins_once_run = False newVersionAvailable = False time_started = '' startTime = '' -last_network_scan = '' last_internet_IP_scan = '' last_scan_run = '' last_cleanup = '' diff --git a/pialert/initialise.py b/pialert/initialise.py index 875db542..cc1d12b3 100755 --- a/pialert/initialise.py +++ b/pialert/initialise.py @@ -13,7 +13,7 @@ from helper import collect_lang_strings, updateSubnets, initOrSetParam, isJsonOb from logger import mylog from api import update_api from scheduler import schedule_class -from plugin import get_plugins_configs, print_plugin_info +from plugin import get_plugins_configs, print_plugin_info, run_plugin_scripts #=============================================================================== # Initialise user defined values @@ -189,8 +189,7 @@ def importConfigs (db): conf.startTime = conf.time_started now_minus_24h = conf.time_started - datetime.timedelta(hours = 24) - # set these times to the past to force the first run - conf.last_network_scan = now_minus_24h + # set these times to the past to force the first run conf.last_internet_IP_scan = now_minus_24h conf.last_scan_run = now_minus_24h conf.last_cleanup = now_minus_24h @@ -199,7 +198,6 @@ def importConfigs (db): # TODO cleanup later ---------------------------------------------------------------------------------- - # global mySchedules # reset schedules conf.mySchedules = [] @@ -283,6 +281,9 @@ def importConfigs (db): # update only the settings datasource update_api(db, False, ["settings"]) + # run plugins that are modifying the config + run_plugin_scripts(db, 'before_config_save') + # Used to determine the next import conf.lastTimeImported = time.time() diff --git a/pialert/reporting.py b/pialert/reporting.py index 5fce7b39..1aedc111 100755 --- a/pialert/reporting.py +++ b/pialert/reporting.py @@ -25,8 +25,6 @@ import const from const import pialertPath, logPath, apiPath from helper import noti_struc, generate_mac_links, removeDuplicateNewLines, timeNowTZ, hide_email, updateState, get_file_content, write_file from logger import logResult, mylog, print_log -# from plugin import execute_plugin - from publishers.email import (check_config as email_check_config, send as send_email )