From 7b15efa9131548e793c6d47c0319d61424cdcaf4 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Fri, 13 Dec 2024 10:18:35 +1100 Subject: [PATCH] last_result.log -> /log/plugins/last_result.PLUGPREF.log --- docs/DEVICE_MANAGEMENT.md | 2 +- docs/PLUGINS_DEV.md | 14 +- front/css/app.css | 5 + front/devices.php | 6 +- .../lib/AdminLTE/dist/js/pages/dashboard3.js | 147 ++++++++++++++++++ front/php/server/query_logs.php | 0 front/plugins/__template/rename_me.py | 12 +- front/plugins/__test/test.py | 9 +- front/plugins/_publisher_apprise/apprise.py | 12 +- front/plugins/_publisher_email/email_smtp.py | 12 +- front/plugins/_publisher_mqtt/mqtt.py | 10 +- front/plugins/_publisher_ntfy/ntfy.py | 12 +- front/plugins/_publisher_pushover/pushover.py | 10 +- .../plugins/_publisher_pushsafer/pushsafer.py | 12 +- front/plugins/_publisher_telegram/tg.py | 12 +- front/plugins/_publisher_webhook/webhook.py | 10 +- front/plugins/arp_scan/script.py | 10 +- front/plugins/avahi_scan/avahi_scan.py | 12 +- front/plugins/csv_backup/script.py | 8 +- front/plugins/db_cleanup/script.py | 10 +- front/plugins/ddns_update/script.py | 10 +- front/plugins/dhcp_leases/script.py | 13 +- front/plugins/freebox/freebox.py | 12 +- front/plugins/icmp_scan/icmp.py | 10 +- front/plugins/internet_ip/script.py | 11 +- front/plugins/internet_speedtest/script.py | 7 +- front/plugins/ipneigh/ipneigh.py | 12 +- front/plugins/maintenance/maintenance.py | 11 +- front/plugins/mikrotik_scan/mikrotik.py | 10 +- front/plugins/nbtscan_scan/nbtscan.py | 12 +- front/plugins/nmap_dev_scan/nmap_dev.py | 12 +- front/plugins/nmap_scan/script.py | 32 ++-- front/plugins/nslookup_scan/nslookup.py | 10 +- front/plugins/omada_sdn_imp/omada_sdn.py | 15 +- front/plugins/snmp_discovery/script.py | 6 +- front/plugins/sync/hub.php | 29 ++-- front/plugins/sync/sync.py | 30 ++-- front/plugins/undiscoverables/script.py | 10 +- front/plugins/unifi_import/script.py | 13 +- front/plugins/vendor_update/script.py | 8 +- front/plugins/website_monitor/script.py | 6 +- front/report.php | 2 +- server/plugin.py | 10 +- 43 files changed, 419 insertions(+), 197 deletions(-) create mode 100755 front/lib/AdminLTE/dist/js/pages/dashboard3.js mode change 100644 => 100755 front/php/server/query_logs.php diff --git a/docs/DEVICE_MANAGEMENT.md b/docs/DEVICE_MANAGEMENT.md index ab099b1e..289fb418 100755 --- a/docs/DEVICE_MANAGEMENT.md +++ b/docs/DEVICE_MANAGEMENT.md @@ -1,6 +1,6 @@ # NetAlertX - Device Management -The Main Info section is where most of the device identifyiable information is stored and edited. Some of the information is autodetected via various plugins. Initial values for most of the fields can be specified in the `NEWDEV` plugin. +The Main Info section is where most of the device identifiable information is stored and edited. Some of the information is autodetected via various plugins. Initial values for most of the fields can be specified in the `NEWDEV` plugin. > [!NOTE] diff --git a/docs/PLUGINS_DEV.md b/docs/PLUGINS_DEV.md index 96ae41e2..cd2ec0be 100755 --- a/docs/PLUGINS_DEV.md +++ b/docs/PLUGINS_DEV.md @@ -46,7 +46,7 @@ Please read the below carefully if you'd like to contribute with a plugin yourse |----------------------|----------------------|----------------------| | `config.json` | yes | Contains the plugin configuration (manifest) including the settings available to the user. | | `script.py` | no | The Python script itself. You may call any valid linux command. | - | `last_result.log` | no | The file used to interface between NetAlertX and the plugin. Required for a script plugin if you want to feed data into the app. | + | `last_result..log` | no | The file used to interface between NetAlertX and the plugin. Required for a script plugin if you want to feed data into the app. Stored in the `/api/log/plugins/` | | `script.log` | no | Logging output (recommended) | | `README.md` | yes | Any setup considerations or overview | @@ -103,7 +103,7 @@ Currently, these data sources are supported (valid `data_source` value). | External SQLite DB query | `sqlite-db-query` | yes | Executes a SQL query from the `CMD` setting on an external SQLite database mapped in the `DB_PATH` setting. | | Plugin type | `plugin_type` | no | Specifies the type of the plugin and in which section the Plugin settings are displayed ( one of `general/system/scanner/other/publisher` ). | -> * "Needs to return a "table" means that the application expects a `last_result.log` file with some results. It's not a blocker, however warnings in the `app.log` might be logged. +> * "Needs to return a "table" means that the application expects a `last_result..log` file with some results. It's not a blocker, however warnings in the `app.log` might be logged. > ๐Ÿ”ŽExample >```json @@ -120,21 +120,21 @@ You can show or hide the UI on the "Plugins" page and "Plugins" tab for a plugin ### "data_source": "script" - If the `data_source` is set to `script` the `CMD` setting (that you specify in the `settings` array section in the `config.json`) contains an executable Linux command, that usually generates a `last_result.log` file (not required if you don't import any data into the app). The `last_result.log` file needs to be saved in the same folder as the plugin. + If the `data_source` is set to `script` the `CMD` setting (that you specify in the `settings` array section in the `config.json`) contains an executable Linux command, that usually generates a `last_result..log` file (not required if you don't import any data into the app). The `last_result..log` file needs to be saved in `/api/log/plugins`. > [!IMPORTANT] -> A lot of the work is taken care of by the [`plugin_helper.py` library](/front/plugins/plugin_helper.py). You don't need to manage the `last_result.log` file if using the helper objects. Check other `script.py` of other plugins for details (The [Undicoverables plugins `script.py` file](/front/plugins/undiscoverables/script.py) is a good example). +> A lot of the work is taken care of by the [`plugin_helper.py` library](/front/plugins/plugin_helper.py). You don't need to manage the `last_result..log` file if using the helper objects. Check other `script.py` of other plugins for details (The [Undicoverables plugins `script.py` file](/front/plugins/undiscoverables/script.py) is a good example). - The content of the `last_result.log` file needs to contain the columns as defined in the "Column order and values" section above. The order of columns can't be changed. After every scan it should contain only the results from the latest scan/execution. + The content of the `last_result..log` file needs to contain the columns as defined in the "Column order and values" section above. The order of columns can't be changed. After every scan it should contain only the results from the latest scan/execution. -- The format of the `last_result.log` is a `csv`-like file with the pipe `|` as a separator. +- The format of the `last_result..log` is a `csv`-like file with the pipe `|` as a separator. - 9 (nine) values need to be supplied, so every line needs to contain 8 pipe separators. Empty values are represented by `null`. - Don't render "headers" for these "columns". Every scan result/event entry needs to be on a new line. - You can find which "columns" need to be present, and if the value is required or optional, in the "Column order and values" section. - The order of these "columns" can't be changed. -#### ๐Ÿ”Ž last_result.log examples +#### ๐Ÿ”Ž last_result.prefix.log examples Valid CSV: diff --git a/front/css/app.css b/front/css/app.css index 23b50a7e..e9b1c51b 100755 --- a/front/css/app.css +++ b/front/css/app.css @@ -1282,6 +1282,11 @@ input[readonly] { } +.dummyDevice +{ + text-align: end; +} + #tableDevices .fab { font-size: 1.5em; diff --git a/front/devices.php b/front/devices.php index b2f036a8..145b76c2 100755 --- a/front/devices.php +++ b/front/devices.php @@ -75,7 +75,11 @@

- +
+ + + +
diff --git a/front/lib/AdminLTE/dist/js/pages/dashboard3.js b/front/lib/AdminLTE/dist/js/pages/dashboard3.js new file mode 100755 index 00000000..c4895eb5 --- /dev/null +++ b/front/lib/AdminLTE/dist/js/pages/dashboard3.js @@ -0,0 +1,147 @@ +/* global Chart:false */ + +$(function () { + 'use strict' + + var ticksStyle = { + fontColor: '#495057', + fontStyle: 'bold' + } + + var mode = 'index' + var intersect = true + + var $salesChart = $('#sales-chart') + // eslint-disable-next-line no-unused-vars + var salesChart = new Chart($salesChart, { + type: 'bar', + data: { + labels: ['JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'], + datasets: [ + { + backgroundColor: '#007bff', + borderColor: '#007bff', + data: [1000, 2000, 3000, 2500, 2700, 2500, 3000] + }, + { + backgroundColor: '#ced4da', + borderColor: '#ced4da', + data: [700, 1700, 2700, 2000, 1800, 1500, 2000] + } + ] + }, + options: { + maintainAspectRatio: false, + tooltips: { + mode: mode, + intersect: intersect + }, + hover: { + mode: mode, + intersect: intersect + }, + legend: { + display: false + }, + scales: { + yAxes: [{ + // display: false, + gridLines: { + display: true, + lineWidth: '4px', + color: 'rgba(0, 0, 0, .2)', + zeroLineColor: 'transparent' + }, + ticks: $.extend({ + beginAtZero: true, + + // Include a dollar sign in the ticks + callback: function (value) { + if (value >= 1000) { + value /= 1000 + value += 'k' + } + + return '$' + value + } + }, ticksStyle) + }], + xAxes: [{ + display: true, + gridLines: { + display: false + }, + ticks: ticksStyle + }] + } + } + }) + + var $visitorsChart = $('#visitors-chart') + // eslint-disable-next-line no-unused-vars + var visitorsChart = new Chart($visitorsChart, { + data: { + labels: ['18th', '20th', '22nd', '24th', '26th', '28th', '30th'], + datasets: [{ + type: 'line', + data: [100, 120, 170, 167, 180, 177, 160], + backgroundColor: 'transparent', + borderColor: '#007bff', + pointBorderColor: '#007bff', + pointBackgroundColor: '#007bff', + fill: false + // pointHoverBackgroundColor: '#007bff', + // pointHoverBorderColor : '#007bff' + }, + { + type: 'line', + data: [60, 80, 70, 67, 80, 77, 100], + backgroundColor: 'tansparent', + borderColor: '#ced4da', + pointBorderColor: '#ced4da', + pointBackgroundColor: '#ced4da', + fill: false + // pointHoverBackgroundColor: '#ced4da', + // pointHoverBorderColor : '#ced4da' + }] + }, + options: { + maintainAspectRatio: false, + tooltips: { + mode: mode, + intersect: intersect + }, + hover: { + mode: mode, + intersect: intersect + }, + legend: { + display: false + }, + scales: { + yAxes: [{ + // display: false, + gridLines: { + display: true, + lineWidth: '4px', + color: 'rgba(0, 0, 0, .2)', + zeroLineColor: 'transparent' + }, + ticks: $.extend({ + beginAtZero: true, + suggestedMax: 200 + }, ticksStyle) + }], + xAxes: [{ + display: true, + gridLines: { + display: false + }, + ticks: ticksStyle + }] + } + } + }) +}) + +// lgtm [js/unused-local-variable] diff --git a/front/php/server/query_logs.php b/front/php/server/query_logs.php old mode 100644 new mode 100755 diff --git a/front/plugins/__template/rename_me.py b/front/plugins/__template/rename_me.py index c0401176..b744c4ca 100755 --- a/front/plugins/__template/rename_me.py +++ b/front/plugins/__template/rename_me.py @@ -14,7 +14,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from notification import write_notification import conf @@ -22,15 +22,17 @@ import conf # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) +pluginName = '' + # Define the current path and log file paths -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) -pluginName = '' + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/__test/test.py b/front/plugins/__test/test.py index 69b2f9ca..5db091e0 100755 --- a/front/plugins/__test/test.py +++ b/front/plugins/__test/test.py @@ -19,7 +19,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) # NetAlertX modules import conf -from const import apiPath, confFileName +from const import apiPath, confFileName, logPath from plugin_utils import getPluginObject from plugin_helper import Plugin_Objects from logger import mylog, append_line_to_file @@ -27,9 +27,10 @@ from helper import timeNowTZ, get_setting_value, bytes_to_string, sanitize_strin from notification import Notification_obj from database import DB, get_device_stats +pluginName = 'TESTONLY' -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file @@ -37,7 +38,7 @@ plugin_objects = Plugin_Objects(RESULT_FILE) # Create an MD5 hash object md5_hash = hashlib.md5() -pluginName = 'TESTONLY' + # globals diff --git a/front/plugins/_publisher_apprise/apprise.py b/front/plugins/_publisher_apprise/apprise.py index 1a360ce0..6adef06b 100755 --- a/front/plugins/_publisher_apprise/apprise.py +++ b/front/plugins/_publisher_apprise/apprise.py @@ -13,7 +13,7 @@ INSTALL_PATH="/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) import conf -from const import confFileName +from const import confFileName, logPath from plugin_helper import Plugin_Objects from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value @@ -24,11 +24,13 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'APPRISE' +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}](publisher) In script']) @@ -51,7 +53,7 @@ def main(): # Retrieve new notifications new_notifications = notifications.getNew() - # Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint) + # Process the new notifications (see the Notifications DB table for structure or check the /php/server/query_json.php?file=table_notifications.json endpoint) for notification in new_notifications: # Send notification diff --git a/front/plugins/_publisher_email/email_smtp.py b/front/plugins/_publisher_email/email_smtp.py index 16c74947..8f0c7768 100755 --- a/front/plugins/_publisher_email/email_smtp.py +++ b/front/plugins/_publisher_email/email_smtp.py @@ -22,7 +22,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) # NetAlertX modules import conf -from const import confFileName +from const import confFileName, logPath from plugin_helper import Plugin_Objects from logger import mylog, append_line_to_file, print_log from helper import timeNowTZ, get_setting_value, hide_email @@ -33,11 +33,13 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'SMTP' +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}](publisher) In script']) @@ -73,7 +75,7 @@ def main(): # mylog('verbose', [f'[{pluginName}] SMTP_REPORT_FROM: ', get_setting_value("SMTP_REPORT_FROM")]) - # Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint) + # Process the new notifications (see the Notifications DB table for structure or check the /php/server/query_json.php?file=table_notifications.json endpoint) for notification in new_notifications: # Send notification diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py index c08b8334..1f20cc9a 100755 --- a/front/plugins/_publisher_mqtt/mqtt.py +++ b/front/plugins/_publisher_mqtt/mqtt.py @@ -23,7 +23,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) # NetAlertX modules import conf -from const import apiPath, confFileName +from const import apiPath, confFileName, logPath from plugin_utils import getPluginObject from plugin_helper import Plugin_Objects from logger import mylog, append_line_to_file @@ -35,15 +35,17 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +pluginName = 'MQTT' + +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) # Create an MD5 hash object md5_hash = hashlib.md5() -pluginName = 'MQTT' + # globals mqtt_sensors = [] diff --git a/front/plugins/_publisher_ntfy/ntfy.py b/front/plugins/_publisher_ntfy/ntfy.py index b20f594a..a1d7514f 100755 --- a/front/plugins/_publisher_ntfy/ntfy.py +++ b/front/plugins/_publisher_ntfy/ntfy.py @@ -16,7 +16,7 @@ INSTALL_PATH="/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) import conf -from const import confFileName +from const import confFileName, logPath from plugin_helper import Plugin_Objects, handleEmpty from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value @@ -27,11 +27,13 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'NTFY' +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}](publisher) In script']) @@ -54,7 +56,7 @@ def main(): # Retrieve new notifications new_notifications = notifications.getNew() - # Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint) + # Process the new notifications (see the Notifications DB table for structure or check the /php/server/query_json.php?file=table_notifications.json endpoint) for notification in new_notifications: # Send notification diff --git a/front/plugins/_publisher_pushover/pushover.py b/front/plugins/_publisher_pushover/pushover.py index 21898d73..66fa26ab 100755 --- a/front/plugins/_publisher_pushover/pushover.py +++ b/front/plugins/_publisher_pushover/pushover.py @@ -15,17 +15,19 @@ from helper import timeNowTZ, get_setting_value, hide_string # noqa: E402 from notification import Notification_obj # noqa: E402 from database import DB # noqa: E402 import conf -from const import confFileName +from const import confFileName, logPath from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, "last_result.log") - pluginName = "PUSHOVER" +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, "last_result.log") + + + def main(): mylog("verbose", f"[{pluginName}](publisher) In script") diff --git a/front/plugins/_publisher_pushsafer/pushsafer.py b/front/plugins/_publisher_pushsafer/pushsafer.py index e55a9beb..39ae6a60 100755 --- a/front/plugins/_publisher_pushsafer/pushsafer.py +++ b/front/plugins/_publisher_pushsafer/pushsafer.py @@ -16,7 +16,7 @@ INSTALL_PATH="/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) import conf -from const import confFileName +from const import confFileName, logPath from plugin_helper import Plugin_Objects, handleEmpty from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value, hide_string @@ -27,11 +27,13 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'PUSHSAFER' +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}](publisher) In script']) @@ -54,7 +56,7 @@ def main(): # Retrieve new notifications new_notifications = notifications.getNew() - # Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint) + # Process the new notifications (see the Notifications DB table for structure or check the /php/server/query_json.php?file=table_notifications.json endpoint) for notification in new_notifications: # Send notification diff --git a/front/plugins/_publisher_telegram/tg.py b/front/plugins/_publisher_telegram/tg.py index 9b8e3308..03a8bebc 100755 --- a/front/plugins/_publisher_telegram/tg.py +++ b/front/plugins/_publisher_telegram/tg.py @@ -13,7 +13,7 @@ INSTALL_PATH = "/app" sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) import conf -from const import confFileName +from const import confFileName, logPath from plugin_helper import Plugin_Objects from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value @@ -24,11 +24,13 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'TELEGRAM' +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}](publisher) In script']) @@ -52,7 +54,7 @@ def main(): # Retrieve new notifications new_notifications = notifications.getNew() - # Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint) + # Process the new notifications (see the Notifications DB table for structure or check the /php/server/query_json.php?file=table_notifications.json endpoint) for notification in new_notifications: # Send notification result = send(notification["Text"]) diff --git a/front/plugins/_publisher_webhook/webhook.py b/front/plugins/_publisher_webhook/webhook.py index bc298e15..83d271cd 100755 --- a/front/plugins/_publisher_webhook/webhook.py +++ b/front/plugins/_publisher_webhook/webhook.py @@ -30,11 +30,13 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'WEBHOOK' +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}](publisher) In script']) @@ -57,7 +59,7 @@ def main(): # Retrieve new notifications new_notifications = notifications.getNew() - # Process the new notifications (see the Notifications DB table for structure or check the /api/table_notifications.json endpoint) + # Process the new notifications (see the Notifications DB table for structure or check the /php/server/query_json.php?file=table_notifications.json endpoint) for notification in new_notifications: # Send notification diff --git a/front/plugins/arp_scan/script.py b/front/plugins/arp_scan/script.py index deb7806e..7e889da2 100755 --- a/front/plugins/arp_scan/script.py +++ b/front/plugins/arp_scan/script.py @@ -24,12 +24,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'ARPSCAN' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): parser = argparse.ArgumentParser(description='Import devices from settings') diff --git a/front/plugins/avahi_scan/avahi_scan.py b/front/plugins/avahi_scan/avahi_scan.py index 498f440c..15a2c508 100755 --- a/front/plugins/avahi_scan/avahi_scan.py +++ b/front/plugins/avahi_scan/avahi_scan.py @@ -14,7 +14,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from notification import write_notification from database import DB @@ -25,15 +25,17 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) +pluginName = 'AVAHISCAN' + # Define the current path and log file paths -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) -pluginName = 'AVAHISCAN' + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/csv_backup/script.py b/front/plugins/csv_backup/script.py index 8cc9ec9f..f9837abb 100755 --- a/front/plugins/csv_backup/script.py +++ b/front/plugins/csv_backup/script.py @@ -24,9 +24,11 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +pluginName = 'CSVBCKP' + +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') def main(): diff --git a/front/plugins/db_cleanup/script.py b/front/plugins/db_cleanup/script.py index ea7c8817..d979cacf 100755 --- a/front/plugins/db_cleanup/script.py +++ b/front/plugins/db_cleanup/script.py @@ -24,12 +24,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'DBCLNP' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): PLUGINS_KEEP_HIST = int(get_setting_value("PLUGINS_KEEP_HIST")) diff --git a/front/plugins/ddns_update/script.py b/front/plugins/ddns_update/script.py index ea869801..e39bd79c 100755 --- a/front/plugins/ddns_update/script.py +++ b/front/plugins/ddns_update/script.py @@ -27,12 +27,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'DDNS' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/dhcp_leases/script.py b/front/plugins/dhcp_leases/script.py index 1353aad5..7253e034 100755 --- a/front/plugins/dhcp_leases/script.py +++ b/front/plugins/dhcp_leases/script.py @@ -17,18 +17,21 @@ from logger import mylog from dhcp_leases import DhcpLeases from helper import timeNowTZ, get_setting_value import conf +from const import logPath from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - - pluginName= 'DHCPLSS' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + + # ------------------------------------------------------------- def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/freebox/freebox.py b/front/plugins/freebox/freebox.py index 593345be..6f1b9652 100755 --- a/front/plugins/freebox/freebox.py +++ b/front/plugins/freebox/freebox.py @@ -23,7 +23,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from notification import write_notification import conf @@ -31,16 +31,16 @@ import conf # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value("TIMEZONE")) +pluginName = 'FREEBOX' + # Define the current path and log file paths -CUR_PATH = str(Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, "script.log") -RESULT_FILE = os.path.join(CUR_PATH, "last_result.log") +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) -pluginName = "FREEBOX" - device_type_map = { "workstation": "PC", "laptop": "Laptop", diff --git a/front/plugins/icmp_scan/icmp.py b/front/plugins/icmp_scan/icmp.py index 7eb72881..ae6d3134 100755 --- a/front/plugins/icmp_scan/icmp.py +++ b/front/plugins/icmp_scan/icmp.py @@ -30,12 +30,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'ICMP' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/internet_ip/script.py b/front/plugins/internet_ip/script.py index 285bdef2..fe4a5a29 100755 --- a/front/plugins/internet_ip/script.py +++ b/front/plugins/internet_ip/script.py @@ -28,13 +28,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) - -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'INTRNT' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + no_internet_ip = '0.0.0.0' def main(): diff --git a/front/plugins/internet_speedtest/script.py b/front/plugins/internet_speedtest/script.py index 54282693..aa4e768f 100755 --- a/front/plugins/internet_speedtest/script.py +++ b/front/plugins/internet_speedtest/script.py @@ -16,12 +16,15 @@ from logger import mylog, append_line_to_file from helper import timeNowTZ, get_setting_value import conf from pytz import timezone +from const import logPath # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +pluginName = 'INTRSPD' + +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') def main(): diff --git a/front/plugins/ipneigh/ipneigh.py b/front/plugins/ipneigh/ipneigh.py index fa3da775..486739e3 100755 --- a/front/plugins/ipneigh/ipneigh.py +++ b/front/plugins/ipneigh/ipneigh.py @@ -17,7 +17,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty from plugin_utils import get_plugins_configs from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from notification import write_notification import conf @@ -25,15 +25,17 @@ import conf # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) +pluginName = 'IPNEIGH' + # Define the current path and log file paths -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) -pluginName = 'IPNEIGH' + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/maintenance/maintenance.py b/front/plugins/maintenance/maintenance.py index 3fe6d3e4..86b94d6e 100755 --- a/front/plugins/maintenance/maintenance.py +++ b/front/plugins/maintenance/maintenance.py @@ -25,13 +25,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) - -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'MAINT' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/mikrotik_scan/mikrotik.py b/front/plugins/mikrotik_scan/mikrotik.py index b779f3d9..d754b99f 100755 --- a/front/plugins/mikrotik_scan/mikrotik.py +++ b/front/plugins/mikrotik_scan/mikrotik.py @@ -30,12 +30,14 @@ from librouteros.exceptions import TrapError # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'MTSCAN' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/nbtscan_scan/nbtscan.py b/front/plugins/nbtscan_scan/nbtscan.py index ca09ac45..ffb8f13f 100755 --- a/front/plugins/nbtscan_scan/nbtscan.py +++ b/front/plugins/nbtscan_scan/nbtscan.py @@ -14,7 +14,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from notification import write_notification from database import DB @@ -25,15 +25,17 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) +pluginName = 'NBTSCAN' + # Define the current path and log file paths -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) -pluginName = 'NBTSCAN' + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/nmap_dev_scan/nmap_dev.py b/front/plugins/nmap_dev_scan/nmap_dev.py index a2e2c6e6..a09c9e46 100755 --- a/front/plugins/nmap_dev_scan/nmap_dev.py +++ b/front/plugins/nmap_dev_scan/nmap_dev.py @@ -31,13 +31,15 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) - -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'NMAPDEV' + +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/nmap_scan/script.py b/front/plugins/nmap_scan/script.py index 1dcffbd9..4cf1ce95 100755 --- a/front/plugins/nmap_scan/script.py +++ b/front/plugins/nmap_scan/script.py @@ -23,9 +23,11 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +pluginName = 'NMAP' + +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') #------------------------------------------------------------------------------- def main(): @@ -41,21 +43,21 @@ def main(): plugin_objects = Plugin_Objects(RESULT_FILE) # Print a message to indicate that the script is starting. - mylog('debug', ['[NMAP Scan] In script ']) + mylog('debug', [f'[{pluginName}] In script ']) # Printing the params list to check its content. - mylog('debug', ['[NMAP Scan] values.ips: ', values.ips]) - mylog('debug', ['[NMAP Scan] values.macs: ', values.macs]) - mylog('debug', ['[NMAP Scan] values.timeout: ', values.timeout]) - mylog('debug', ['[NMAP Scan] values.args: ', values.args]) + mylog('debug', [f'[{pluginName}] values.ips: ', values.ips]) + mylog('debug', [f'[{pluginName}] values.macs: ', values.macs]) + mylog('debug', [f'[{pluginName}] values.timeout: ', values.timeout]) + mylog('debug', [f'[{pluginName}] values.args: ', values.args]) argsDecoded = decodeBase64(values.args[0].split('=b')[1]) - mylog('debug', ['[NMAP Scan] argsDecoded: ', argsDecoded]) + mylog('debug', [f'[{pluginName}] argsDecoded: ', argsDecoded]) entries = performNmapScan(values.ips[0].split('=')[1].split(','), values.macs[0].split('=')[1].split(',') , values.timeout[0].split('=')[1], argsDecoded) - mylog('verbose', ['[NMAP Scan] Total number of ports found by NMAP: ', len(entries)]) + mylog('verbose', [f'[{pluginName}] Total number of ports found by NMAP: ', len(entries)]) for entry in entries: @@ -104,7 +106,7 @@ def performNmapScan(deviceIPs, deviceMACs, timeoutSec, args): devTotal = len(deviceIPs) - mylog('verbose', ['[NMAP Scan] Scan: Nmap for max ', str(timeoutSec), 's ('+ str(round(int(timeoutSec) / 60, 1)) +'min) per device']) + mylog('verbose', [f'[{pluginName}] Scan: Nmap for max ', str(timeoutSec), 's ('+ str(round(int(timeoutSec) / 60, 1)) +'min) per device']) mylog('verbose', ["[NMAP Scan] Estimated max delay: ", (devTotal * int(timeoutSec)), 's ', '(', round((devTotal * int(timeoutSec))/60,1) , 'min)' ]) @@ -125,12 +127,12 @@ def performNmapScan(deviceIPs, deviceMACs, timeoutSec, args): mylog('none', ["[NMAP Scan] " ,e.output]) mylog('none', ["[NMAP Scan] โš  ERROR - Nmap Scan - check logs", progress]) except subprocess.TimeoutExpired as timeErr: - mylog('verbose', ['[NMAP Scan] Nmap TIMEOUT - the process forcefully terminated as timeout reached for ', ip, progress]) + mylog('verbose', [f'[{pluginName}] Nmap TIMEOUT - the process forcefully terminated as timeout reached for ', ip, progress]) if output == "": # check if the subprocess failed - mylog('minimal', ['[NMAP Scan] Nmap FAIL for ', ip, progress ,' check logs for details']) + mylog('minimal', [f'[{pluginName}] Nmap FAIL for ', ip, progress ,' check logs for details']) else: - mylog('verbose', ['[NMAP Scan] Nmap SUCCESS for ', ip, progress]) + mylog('verbose', [f'[{pluginName}] Nmap SUCCESS for ', ip, progress]) @@ -160,7 +162,7 @@ def performNmapScan(deviceIPs, deviceMACs, timeoutSec, args): elif 'Nmap done' in line: duration = line.split('scanned in ')[1] - mylog('verbose', [f'[NMAP Scan] {newPortsPerDevice} ports found on {deviceMACs[devIndex]}']) + mylog('verbose', [ff'[{pluginName}] {newPortsPerDevice} ports found on {deviceMACs[devIndex]}']) index += 1 devIndex += 1 diff --git a/front/plugins/nslookup_scan/nslookup.py b/front/plugins/nslookup_scan/nslookup.py index d4baa3ee..050cac17 100755 --- a/front/plugins/nslookup_scan/nslookup.py +++ b/front/plugins/nslookup_scan/nslookup.py @@ -30,12 +30,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'NSLOOKUP' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): mylog('verbose', [f'[{pluginName}] In script']) diff --git a/front/plugins/omada_sdn_imp/omada_sdn.py b/front/plugins/omada_sdn_imp/omada_sdn.py index e786208d..c59c22fe 100755 --- a/front/plugins/omada_sdn_imp/omada_sdn.py +++ b/front/plugins/omada_sdn_imp/omada_sdn.py @@ -45,7 +45,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from notification import write_notification from pytz import timezone @@ -54,11 +54,14 @@ import conf conf.tz = timezone(get_setting_value("TIMEZONE")) PARALLELISM = 4 +pluginName = "OMDSDN" + # Define the current path and log file paths -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, "script.log") -RESULT_FILE = os.path.join(CUR_PATH, "last_result.log") -OMADA_API_RETURN_FILE = os.path.join(CUR_PATH, "omada_api_return") +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + +OMADA_API_RETURN_FILE = os.path.join(LOG_PATH, "omada_api_return") # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) @@ -86,7 +89,7 @@ dMAC, dIP, dTYPE, dSTATUS, dNAME, dMODEL = range(6) cMAC, cIP, cNAME, cSWITCH_AP, cPORT_SSID = range(5) OMDLOGLEVEL = "debug" -pluginName = "OMDSDN" + # diff --git a/front/plugins/snmp_discovery/script.py b/front/plugins/snmp_discovery/script.py index 0fcb1ea6..543a56f0 100755 --- a/front/plugins/snmp_discovery/script.py +++ b/front/plugins/snmp_discovery/script.py @@ -21,8 +21,10 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +pluginName = "SNMPDSC" + +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Workflow diff --git a/front/plugins/sync/hub.php b/front/plugins/sync/hub.php index 2352ca88..e0fc2b49 100755 --- a/front/plugins/sync/hub.php +++ b/front/plugins/sync/hub.php @@ -64,33 +64,34 @@ else if ($method === 'POST') { // Retrieve and decode the data from the POST request $data = $_POST['data'] ?? ''; - $plugin_folder = $_POST['plugin_folder'] ?? ''; + $file_path = $_POST['file_path'] ?? ''; $node_name = $_POST['node_name'] ?? ''; + $plugin = $_POST['plugin'] ?? ''; - $storage_path = "/app/front/plugins/{$plugin_folder}"; + $storage_path = "/app/log/plugins/"; - // Create the storage directory if it doesn't exist - if (!is_dir($storage_path)) { - echo "Could not open folder: {$storage_path}"; - write_notification("[Plugin: SYNC] Could not open folder: {$storage_path}", "alert"); - http_response_code(500); - exit; - } + // // check location + // if (!is_dir($storage_path)) { + // echo "Could not open folder: {$storage_path}"; + // write_notification("[Plugin: SYNC] Could not open folder: {$storage_path}", "alert"); + // http_response_code(500); + // exit; + // } // Generate a unique file path to avoid overwriting existing files - $encoded_files = glob("{$storage_path}/last_result.encoded.{$node_name}.*.log"); - $decoded_files = glob("{$storage_path}/last_result.decoded.{$node_name}.*.log"); + $encoded_files = glob("{$storage_path}/last_result.{$plugin}.encoded.{$node_name}.*.log"); + $decoded_files = glob("{$storage_path}/last_result.{$plugin}.decoded.{$node_name}.*.log"); $files = array_merge($encoded_files, $decoded_files); $file_count = count($files) + 1; - $file_path = "{$storage_path}/last_result.encoded.{$node_name}.{$file_count}.log"; + $file_path_new = "{$storage_path}/last_result.{$plugin}.encoded.{$node_name}.{$file_count}.log"; // Save the decoded data to the file - file_put_contents($file_path, $data); + file_put_contents($file_path_new, $data); http_response_code(200); echo 'Data received and stored successfully'; - write_notification("[Plugin: SYNC] Data received ({$plugin_folder})", "info"); + write_notification("[Plugin: SYNC] Data received ({$file_path_new})", "info"); } else { http_response_code(405); diff --git a/front/plugins/sync/sync.py b/front/plugins/sync/sync.py index b0884596..13504ccb 100755 --- a/front/plugins/sync/sync.py +++ b/front/plugins/sync/sync.py @@ -17,7 +17,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64 from plugin_utils import get_plugins_configs, decode_and_rename_files from logger import mylog -from const import pluginsPath, fullDbPath +from const import pluginsPath, fullDbPath, logPath from helper import timeNowTZ, get_setting_value from crypto_utils import encrypt_data from notification import write_notification @@ -27,15 +27,16 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) +pluginName = 'SYNC' + # Define the current path and log file paths -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') # Initialize the Plugin obj output file plugin_objects = Plugin_Objects(RESULT_FILE) -pluginName = 'SYNC' def main(): mylog('verbose', [f'[{pluginName}] In script']) @@ -84,8 +85,7 @@ def main(): mylog('verbose', [f'[{pluginName}] synching "{pref}" ({index}/{len(plugins_to_sync)})']) # Construct the file path for the plugin's last_result.log file - plugin_folder = plugin["code_name"] - file_path = f"{INSTALL_PATH}/front/plugins/{plugin_folder}/last_result.log" + file_path = f"{LOG_PATH}/last_result.{pref}.log" if os.path.exists(file_path): # Read the content of the log file @@ -95,17 +95,16 @@ def main(): mylog('verbose', [f'[{pluginName}] Sending file_content: "{file_content}"']) # encrypt and send data to the hub - send_data(api_token, file_content, encryption_key, plugin_folder, node_name, pref, hub_url) + send_data(api_token, file_content, encryption_key, file_path, node_name, pref, hub_url) else: - mylog('verbose', [f'[{pluginName}] {plugin_folder}/last_result.log not found']) + mylog('verbose', [f'[{pluginName}] {file_path} not found']) # PUSHING/SENDING devices if send_devices: file_path = f"{INSTALL_PATH}/api/table_devices.json" - plugin_folder = 'sync' pref = 'SYNC' if os.path.exists(file_path): @@ -114,7 +113,7 @@ def main(): file_content = f.read() mylog('verbose', [f'[{pluginName}] Sending file_content: "{file_content}"']) - send_data(api_token, file_content, encryption_key, plugin_folder, node_name, pref, hub_url) + send_data(api_token, file_content, encryption_key, file_path, node_name, pref, hub_url) else: mylog('verbose', [f'[{pluginName}] SYNC_hub_url not defined, skipping posting "Devices" data']) else: @@ -267,7 +266,7 @@ def main(): # send data to the HUB -def send_data(api_token, file_content, encryption_key, plugin_folder, node_name, pref, hub_url): +def send_data(api_token, file_content, encryption_key, file_path, node_name, pref, hub_url): # Encrypt the log data using the encryption_key encrypted_data = encrypt_data(file_content, encryption_key) @@ -276,7 +275,8 @@ def send_data(api_token, file_content, encryption_key, plugin_folder, node_name, # Prepare the data payload for the POST request data = { 'data': encrypted_data, - 'plugin_folder': plugin_folder, + 'file_path': file_path, + 'plugin': pref, 'node_name': node_name } # Set the authorization header with the API token @@ -287,11 +287,11 @@ def send_data(api_token, file_content, encryption_key, plugin_folder, node_name, mylog('verbose', [f'[{pluginName}] response: "{response}"']) if response.status_code == 200: - message = f'[{pluginName}] Data for "{plugin_folder}" sent successfully' + message = f'[{pluginName}] Data for "{file_path}" sent successfully' mylog('verbose', [message]) write_notification(message, 'info', timeNowTZ()) else: - message = f'[{pluginName}] Failed to send data for "{plugin_folder}" (Status code: {response.status_code})' + message = f'[{pluginName}] Failed to send data for "{file_path}" (Status code: {response.status_code})' mylog('verbose', [message]) write_notification(message, 'alert', timeNowTZ()) diff --git a/front/plugins/undiscoverables/script.py b/front/plugins/undiscoverables/script.py index 36dda12f..fe2b00ca 100755 --- a/front/plugins/undiscoverables/script.py +++ b/front/plugins/undiscoverables/script.py @@ -21,12 +21,14 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') - pluginName = 'UNDIS' +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') + + + def main(): # the script expects a parameter in the format of devices=device1,device2,... diff --git a/front/plugins/unifi_import/script.py b/front/plugins/unifi_import/script.py index cbb1016c..cf6d80be 100755 --- a/front/plugins/unifi_import/script.py +++ b/front/plugins/unifi_import/script.py @@ -24,19 +24,22 @@ from logger import mylog from helper import timeNowTZ, get_setting_value, normalize_string import conf from pytz import timezone +from const import logPath # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') -LOCK_FILE = os.path.join(CUR_PATH, 'full_run.lock') +pluginName = 'UNFIMP' + +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') +LOCK_FILE = os.path.join(LOG_PATH, f'full_run.{pluginName}.lock') requests.packages.urllib3.disable_warnings(InsecureRequestWarning) -pluginName = 'UNFIMP' + # Workflow diff --git a/front/plugins/vendor_update/script.py b/front/plugins/vendor_update/script.py index 842a4b84..070a1432 100755 --- a/front/plugins/vendor_update/script.py +++ b/front/plugins/vendor_update/script.py @@ -26,10 +26,12 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) +pluginName = 'VNDRPDT' -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -LOG_FILE = os.path.join(CUR_PATH, 'script.log') -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') + +LOG_PATH = logPath + '/plugins' +LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log') +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') def main(): diff --git a/front/plugins/website_monitor/script.py b/front/plugins/website_monitor/script.py index d9a32d07..f437a47b 100755 --- a/front/plugins/website_monitor/script.py +++ b/front/plugins/website_monitor/script.py @@ -22,8 +22,10 @@ from pytz import timezone # Make sure the TIMEZONE for logging is correct conf.tz = timezone(get_setting_value('TIMEZONE')) -CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) -RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') +pluginName = 'WEBMON' + +LOG_PATH = logPath + '/plugins' +RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log') def main(): parser = argparse.ArgumentParser(description='Simple URL monitoring tool') diff --git a/front/report.php b/front/report.php index f08aa088..e565ea37 100755 --- a/front/report.php +++ b/front/report.php @@ -163,7 +163,7 @@ const urlParams = new URLSearchParams(window.location.search); if (urlParams.has('guid')) { const guid = urlParams.get('guid'); - fetch('api/table_notifications.json') + fetch('php/server/query_json.php?file=table_notifications.json') .then(response => response.json()) .then(data => { const index = findIndexByGUID(data.data, guid); diff --git a/server/plugin.py b/server/plugin.py index d90bdf40..d050c7d1 100755 --- a/server/plugin.py +++ b/server/plugin.py @@ -147,7 +147,7 @@ def run_plugin_scripts(db, all_plugins, runType, pluginsState = plugins_state()) # Function to run a plugin command -def run_plugin(command, set_RUN_TIMEOUT): +def run_plugin(command, set_RUN_TIMEOUT, plugin): try: return subprocess.check_output(command, universal_newlines=True, stderr=subprocess.STDOUT, timeout=set_RUN_TIMEOUT) except subprocess.CalledProcessError as e: @@ -224,7 +224,7 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ): # Using ThreadPoolExecutor to handle concurrent subprocesses with ThreadPoolExecutor(max_workers=5) as executor: - futures = [executor.submit(run_plugin, command, set_RUN_TIMEOUT)] # Submit the command as a future + futures = [executor.submit(run_plugin, command, set_RUN_TIMEOUT, plugin)] # Submit the command as a future for future in as_completed(futures): output = future.result() # Get the output or error @@ -235,8 +235,8 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ): newLines = [] # Create the file path - file_dir = os.path.join(pluginsPath, plugin["code_name"]) - file_prefix = 'last_result' + file_dir = logPath + '/plugins' + file_prefix = f'last_result.{plugin["unique_prefix"]}' # Decode files, rename them, and get the list of files, this will return all files starting with the prefix, even if they are not encoded files_to_process = decode_and_rename_files(file_dir, file_prefix) @@ -255,7 +255,7 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ): # cleanup - select only lines containing a separator to filter out unnecessary data newLines = list(filter(lambda x: '|' in x, newLines)) - # Store e.g. Node_1 from last_result.encoded.Node_1.1.log + # Store e.g. Node_1 from last_result..encoded.Node_1.1.log tmp_SyncHubNodeName = '' if len(filename.split('.')) > 3: tmp_SyncHubNodeName = filename.split('.')[2]