mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Docs + before_config_save run option
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 = ''
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user