last_result.log -> /log/plugins/last_result.PLUGPREF.log

This commit is contained in:
jokob-sk
2024-12-13 10:18:35 +11:00
parent a7e35c4697
commit 7b15efa913
43 changed files with 419 additions and 197 deletions

View File

@@ -1,6 +1,6 @@
# NetAlertX - Device Management # 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] > [!NOTE]

View File

@@ -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. | | `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. | | `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.<prefix>.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) | | `script.log` | no | Logging output (recommended) |
| `README.md` | yes | Any setup considerations or overview | | `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. | | 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` ). | | 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.<prefix>.log` file with some results. It's not a blocker, however warnings in the `app.log` might be logged.
> 🔎Example > 🔎Example
>```json >```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" ### "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.<prefix>.log` file (not required if you don't import any data into the app). The `last_result.<prefix>.log` file needs to be saved in `/api/log/plugins`.
> [!IMPORTANT] > [!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.<prefix>.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.<prefix>.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.<prefix>.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`. - 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". - Don't render "headers" for these "columns".
Every scan result/event entry needs to be on a new line. 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. - 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. - The order of these "columns" can't be changed.
#### 🔎 last_result.log examples #### 🔎 last_result.prefix.log examples
Valid CSV: Valid CSV:

View File

@@ -1282,6 +1282,11 @@ input[readonly] {
} }
.dummyDevice
{
text-align: end;
}
#tableDevices .fab #tableDevices .fab
{ {
font-size: 1.5em; font-size: 1.5em;

View File

@@ -75,7 +75,11 @@
<div class=" col-md-9 "> <div class=" col-md-9 ">
<h3 id="tableDevicesTitle" class="box-title text-gray "></h3> <h3 id="tableDevicesTitle" class="box-title text-gray "></h3>
</div> </div>
<div class=" col-md-3 "><a href="deviceDetails.php?mac=new"><i title="<?= lang('Gen_create_new_device');?>" class="fa fa-square-plus"></i> <?= lang('Gen_create_new_device');?></a></div> <div class="dummyDevice col-md-3 ">
<span>
<a href="deviceDetails.php?mac=new"><i title="<?= lang('Gen_create_new_device');?>" class="fa fa-square-plus"></i> <?= lang('Gen_create_new_device');?></a>
</span>
</div>
</div> </div>
<!-- table --> <!-- table -->

147
front/lib/AdminLTE/dist/js/pages/dashboard3.js vendored Executable file
View File

@@ -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]

0
front/php/server/query_logs.php Normal file → Executable file
View File

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64
from plugin_utils import get_plugins_configs from plugin_utils import get_plugins_configs
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from notification import write_notification from notification import write_notification
import conf import conf
@@ -22,15 +22,17 @@ import conf
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
pluginName = '<unique_prefix>'
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, 'script.log') LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
pluginName = '<unique_prefix>'
def main(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -19,7 +19,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
# NetAlertX modules # NetAlertX modules
import conf import conf
from const import apiPath, confFileName from const import apiPath, confFileName, logPath
from plugin_utils import getPluginObject from plugin_utils import getPluginObject
from plugin_helper import Plugin_Objects from plugin_helper import Plugin_Objects
from logger import mylog, append_line_to_file 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 notification import Notification_obj
from database import DB, get_device_stats from database import DB, get_device_stats
pluginName = 'TESTONLY'
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
@@ -37,7 +38,7 @@ plugin_objects = Plugin_Objects(RESULT_FILE)
# Create an MD5 hash object # Create an MD5 hash object
md5_hash = hashlib.md5() md5_hash = hashlib.md5()
pluginName = 'TESTONLY'
# globals # globals

View File

@@ -13,7 +13,7 @@ INSTALL_PATH="/app"
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
import conf import conf
from const import confFileName from const import confFileName, logPath
from plugin_helper import Plugin_Objects from plugin_helper import Plugin_Objects
from logger import mylog, append_line_to_file from logger import mylog, append_line_to_file
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
@@ -24,11 +24,13 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' pluginName = 'APPRISE'
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
def main(): def main():
mylog('verbose', [f'[{pluginName}](publisher) In script']) mylog('verbose', [f'[{pluginName}](publisher) In script'])
@@ -51,7 +53,7 @@ def main():
# Retrieve new notifications # Retrieve new notifications
new_notifications = notifications.getNew() 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: for notification in new_notifications:
# Send notification # Send notification

View File

@@ -22,7 +22,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
# NetAlertX modules # NetAlertX modules
import conf import conf
from const import confFileName from const import confFileName, logPath
from plugin_helper import Plugin_Objects from plugin_helper import Plugin_Objects
from logger import mylog, append_line_to_file, print_log from logger import mylog, append_line_to_file, print_log
from helper import timeNowTZ, get_setting_value, hide_email 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 # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' pluginName = 'SMTP'
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
def main(): def main():
mylog('verbose', [f'[{pluginName}](publisher) In script']) 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")]) # 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: for notification in new_notifications:
# Send notification # Send notification

View File

@@ -23,7 +23,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
# NetAlertX modules # NetAlertX modules
import conf import conf
from const import apiPath, confFileName from const import apiPath, confFileName, logPath
from plugin_utils import getPluginObject from plugin_utils import getPluginObject
from plugin_helper import Plugin_Objects from plugin_helper import Plugin_Objects
from logger import mylog, append_line_to_file from logger import mylog, append_line_to_file
@@ -35,15 +35,17 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = 'MQTT'
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 # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
# Create an MD5 hash object # Create an MD5 hash object
md5_hash = hashlib.md5() md5_hash = hashlib.md5()
pluginName = 'MQTT'
# globals # globals
mqtt_sensors = [] mqtt_sensors = []

View File

@@ -16,7 +16,7 @@ INSTALL_PATH="/app"
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
import conf import conf
from const import confFileName from const import confFileName, logPath
from plugin_helper import Plugin_Objects, handleEmpty from plugin_helper import Plugin_Objects, handleEmpty
from logger import mylog, append_line_to_file from logger import mylog, append_line_to_file
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
@@ -27,11 +27,13 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' pluginName = 'NTFY'
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
def main(): def main():
mylog('verbose', [f'[{pluginName}](publisher) In script']) mylog('verbose', [f'[{pluginName}](publisher) In script'])
@@ -54,7 +56,7 @@ def main():
# Retrieve new notifications # Retrieve new notifications
new_notifications = notifications.getNew() 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: for notification in new_notifications:
# Send notification # Send notification

View File

@@ -15,17 +15,19 @@ from helper import timeNowTZ, get_setting_value, hide_string # noqa: E402
from notification import Notification_obj # noqa: E402 from notification import Notification_obj # noqa: E402
from database import DB # noqa: E402 from database import DB # noqa: E402
import conf import conf
from const import confFileName from const import confFileName, logPath
from pytz import timezone from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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" pluginName = "PUSHOVER"
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, "last_result.log")
def main(): def main():
mylog("verbose", f"[{pluginName}](publisher) In script") mylog("verbose", f"[{pluginName}](publisher) In script")

View File

@@ -16,7 +16,7 @@ INSTALL_PATH="/app"
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
import conf import conf
from const import confFileName from const import confFileName, logPath
from plugin_helper import Plugin_Objects, handleEmpty from plugin_helper import Plugin_Objects, handleEmpty
from logger import mylog, append_line_to_file from logger import mylog, append_line_to_file
from helper import timeNowTZ, get_setting_value, hide_string 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 # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' pluginName = 'PUSHSAFER'
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
def main(): def main():
mylog('verbose', [f'[{pluginName}](publisher) In script']) mylog('verbose', [f'[{pluginName}](publisher) In script'])
@@ -54,7 +56,7 @@ def main():
# Retrieve new notifications # Retrieve new notifications
new_notifications = notifications.getNew() 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: for notification in new_notifications:
# Send notification # Send notification

View File

@@ -13,7 +13,7 @@ INSTALL_PATH = "/app"
sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"]) sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
import conf import conf
from const import confFileName from const import confFileName, logPath
from plugin_helper import Plugin_Objects from plugin_helper import Plugin_Objects
from logger import mylog, append_line_to_file from logger import mylog, append_line_to_file
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
@@ -24,11 +24,13 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' pluginName = 'TELEGRAM'
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
def main(): def main():
mylog('verbose', [f'[{pluginName}](publisher) In script']) mylog('verbose', [f'[{pluginName}](publisher) In script'])
@@ -52,7 +54,7 @@ def main():
# Retrieve new notifications # Retrieve new notifications
new_notifications = notifications.getNew() 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: for notification in new_notifications:
# Send notification # Send notification
result = send(notification["Text"]) result = send(notification["Text"])

View File

@@ -30,11 +30,13 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' pluginName = 'WEBHOOK'
LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
def main(): def main():
mylog('verbose', [f'[{pluginName}](publisher) In script']) mylog('verbose', [f'[{pluginName}](publisher) In script'])
@@ -57,7 +59,7 @@ def main():
# Retrieve new notifications # Retrieve new notifications
new_notifications = notifications.getNew() 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: for notification in new_notifications:
# Send notification # Send notification

View File

@@ -24,12 +24,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
parser = argparse.ArgumentParser(description='Import devices from settings') parser = argparse.ArgumentParser(description='Import devices from settings')

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64
from plugin_utils import get_plugins_configs from plugin_utils import get_plugins_configs
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from notification import write_notification from notification import write_notification
from database import DB from database import DB
@@ -25,15 +25,17 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
pluginName = 'AVAHISCAN'
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, 'script.log') LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
pluginName = 'AVAHISCAN'
def main(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -24,9 +24,11 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = 'CSVBCKP'
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(): def main():

View File

@@ -24,12 +24,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
PLUGINS_KEEP_HIST = int(get_setting_value("PLUGINS_KEEP_HIST")) PLUGINS_KEEP_HIST = int(get_setting_value("PLUGINS_KEEP_HIST"))

View File

@@ -27,12 +27,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -17,18 +17,21 @@ from logger import mylog
from dhcp_leases import DhcpLeases from dhcp_leases import DhcpLeases
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
import conf import conf
from const import logPath
from pytz import timezone from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64
from plugin_utils import get_plugins_configs from plugin_utils import get_plugins_configs
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from notification import write_notification from notification import write_notification
import conf import conf
@@ -31,16 +31,16 @@ import conf
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value("TIMEZONE")) conf.tz = timezone(get_setting_value("TIMEZONE"))
pluginName = 'FREEBOX'
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, "script.log") LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, "last_result.log") RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
pluginName = "FREEBOX"
device_type_map = { device_type_map = {
"workstation": "PC", "workstation": "PC",
"laptop": "Laptop", "laptop": "Laptop",

View File

@@ -30,12 +30,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -28,13 +28,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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' no_internet_ip = '0.0.0.0'
def main(): def main():

View File

@@ -16,12 +16,15 @@ from logger import mylog, append_line_to_file
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
import conf import conf
from pytz import timezone from pytz import timezone
from const import logPath
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = 'INTRSPD'
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')
def main(): def main():

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64, handleEmpty
from plugin_utils import get_plugins_configs from plugin_utils import get_plugins_configs
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from notification import write_notification from notification import write_notification
import conf import conf
@@ -25,15 +25,17 @@ import conf
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
pluginName = 'IPNEIGH'
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, 'script.log') LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
pluginName = 'IPNEIGH'
def main(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -25,13 +25,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -30,12 +30,14 @@ from librouteros.exceptions import TrapError
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64
from plugin_utils import get_plugins_configs from plugin_utils import get_plugins_configs
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from notification import write_notification from notification import write_notification
from database import DB from database import DB
@@ -25,15 +25,17 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
pluginName = 'NBTSCAN'
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, 'script.log') LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
pluginName = 'NBTSCAN'
def main(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -31,13 +31,15 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -23,9 +23,11 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = 'NMAP'
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(): def main():
@@ -41,21 +43,21 @@ def main():
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
# Print a message to indicate that the script is starting. # 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. # Printing the params list to check its content.
mylog('debug', ['[NMAP Scan] values.ips: ', values.ips]) mylog('debug', [f'[{pluginName}] values.ips: ', values.ips])
mylog('debug', ['[NMAP Scan] values.macs: ', values.macs]) mylog('debug', [f'[{pluginName}] values.macs: ', values.macs])
mylog('debug', ['[NMAP Scan] values.timeout: ', values.timeout]) mylog('debug', [f'[{pluginName}] values.timeout: ', values.timeout])
mylog('debug', ['[NMAP Scan] values.args: ', values.args]) mylog('debug', [f'[{pluginName}] values.args: ', values.args])
argsDecoded = decodeBase64(values.args[0].split('=b')[1]) 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) 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: for entry in entries:
@@ -104,7 +106,7 @@ def performNmapScan(deviceIPs, deviceMACs, timeoutSec, args):
devTotal = len(deviceIPs) 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)' ]) 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] " ,e.output])
mylog('none', ["[NMAP Scan] ⚠ ERROR - Nmap Scan - check logs", progress]) mylog('none', ["[NMAP Scan] ⚠ ERROR - Nmap Scan - check logs", progress])
except subprocess.TimeoutExpired as timeErr: 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 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: 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: elif 'Nmap done' in line:
duration = line.split('scanned in ')[1] 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 index += 1
devIndex += 1 devIndex += 1

View File

@@ -30,12 +30,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64
from plugin_utils import get_plugins_configs from plugin_utils import get_plugins_configs
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from notification import write_notification from notification import write_notification
from pytz import timezone from pytz import timezone
@@ -54,11 +54,14 @@ import conf
conf.tz = timezone(get_setting_value("TIMEZONE")) conf.tz = timezone(get_setting_value("TIMEZONE"))
PARALLELISM = 4 PARALLELISM = 4
pluginName = "OMDSDN"
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, "script.log") LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, "last_result.log") RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
OMADA_API_RETURN_FILE = os.path.join(CUR_PATH, "omada_api_return")
OMADA_API_RETURN_FILE = os.path.join(LOG_PATH, "omada_api_return")
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_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) cMAC, cIP, cNAME, cSWITCH_AP, cPORT_SSID = range(5)
OMDLOGLEVEL = "debug" OMDLOGLEVEL = "debug"
pluginName = "OMDSDN"
# #

View File

@@ -21,8 +21,10 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = "SNMPDSC"
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')
# Workflow # Workflow

View File

@@ -64,33 +64,34 @@ else if ($method === 'POST') {
// Retrieve and decode the data from the POST request // Retrieve and decode the data from the POST request
$data = $_POST['data'] ?? ''; $data = $_POST['data'] ?? '';
$plugin_folder = $_POST['plugin_folder'] ?? ''; $file_path = $_POST['file_path'] ?? '';
$node_name = $_POST['node_name'] ?? ''; $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 // // check location
if (!is_dir($storage_path)) { // if (!is_dir($storage_path)) {
echo "Could not open folder: {$storage_path}"; // echo "Could not open folder: {$storage_path}";
write_notification("[Plugin: SYNC] Could not open folder: {$storage_path}", "alert"); // write_notification("[Plugin: SYNC] Could not open folder: {$storage_path}", "alert");
http_response_code(500); // http_response_code(500);
exit; // exit;
} // }
// Generate a unique file path to avoid overwriting existing files // Generate a unique file path to avoid overwriting existing files
$encoded_files = glob("{$storage_path}/last_result.encoded.{$node_name}.*.log"); $encoded_files = glob("{$storage_path}/last_result.{$plugin}.encoded.{$node_name}.*.log");
$decoded_files = glob("{$storage_path}/last_result.decoded.{$node_name}.*.log"); $decoded_files = glob("{$storage_path}/last_result.{$plugin}.decoded.{$node_name}.*.log");
$files = array_merge($encoded_files, $decoded_files); $files = array_merge($encoded_files, $decoded_files);
$file_count = count($files) + 1; $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 // Save the decoded data to the file
file_put_contents($file_path, $data); file_put_contents($file_path_new, $data);
http_response_code(200); http_response_code(200);
echo 'Data received and stored successfully'; 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 { } else {
http_response_code(405); http_response_code(405);

View File

@@ -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_helper import Plugin_Object, Plugin_Objects, decodeBase64
from plugin_utils import get_plugins_configs, decode_and_rename_files from plugin_utils import get_plugins_configs, decode_and_rename_files
from logger import mylog from logger import mylog
from const import pluginsPath, fullDbPath from const import pluginsPath, fullDbPath, logPath
from helper import timeNowTZ, get_setting_value from helper import timeNowTZ, get_setting_value
from crypto_utils import encrypt_data from crypto_utils import encrypt_data
from notification import write_notification from notification import write_notification
@@ -27,15 +27,16 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
pluginName = 'SYNC'
# Define the current path and log file paths # Define the current path and log file paths
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) LOG_PATH = logPath + '/plugins'
LOG_FILE = os.path.join(CUR_PATH, 'script.log') LOG_FILE = os.path.join(LOG_PATH, f'script.{pluginName}.log')
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') RESULT_FILE = os.path.join(LOG_PATH, f'last_result.{pluginName}.log')
# Initialize the Plugin obj output file # Initialize the Plugin obj output file
plugin_objects = Plugin_Objects(RESULT_FILE) plugin_objects = Plugin_Objects(RESULT_FILE)
pluginName = 'SYNC'
def main(): def main():
mylog('verbose', [f'[{pluginName}] In script']) mylog('verbose', [f'[{pluginName}] In script'])
@@ -84,8 +85,7 @@ def main():
mylog('verbose', [f'[{pluginName}] synching "{pref}" ({index}/{len(plugins_to_sync)})']) mylog('verbose', [f'[{pluginName}] synching "{pref}" ({index}/{len(plugins_to_sync)})'])
# Construct the file path for the plugin's last_result.log file # Construct the file path for the plugin's last_result.log file
plugin_folder = plugin["code_name"] file_path = f"{LOG_PATH}/last_result.{pref}.log"
file_path = f"{INSTALL_PATH}/front/plugins/{plugin_folder}/last_result.log"
if os.path.exists(file_path): if os.path.exists(file_path):
# Read the content of the log file # Read the content of the log file
@@ -95,17 +95,16 @@ def main():
mylog('verbose', [f'[{pluginName}] Sending file_content: "{file_content}"']) mylog('verbose', [f'[{pluginName}] Sending file_content: "{file_content}"'])
# encrypt and send data to the hub # 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: else:
mylog('verbose', [f'[{pluginName}] {plugin_folder}/last_result.log not found']) mylog('verbose', [f'[{pluginName}] {file_path} not found'])
# PUSHING/SENDING devices # PUSHING/SENDING devices
if send_devices: if send_devices:
file_path = f"{INSTALL_PATH}/api/table_devices.json" file_path = f"{INSTALL_PATH}/api/table_devices.json"
plugin_folder = 'sync'
pref = 'SYNC' pref = 'SYNC'
if os.path.exists(file_path): if os.path.exists(file_path):
@@ -114,7 +113,7 @@ def main():
file_content = f.read() file_content = f.read()
mylog('verbose', [f'[{pluginName}] Sending file_content: "{file_content}"']) 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: else:
mylog('verbose', [f'[{pluginName}] SYNC_hub_url not defined, skipping posting "Devices" data']) mylog('verbose', [f'[{pluginName}] SYNC_hub_url not defined, skipping posting "Devices" data'])
else: else:
@@ -267,7 +266,7 @@ def main():
# send data to the HUB # 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 # Encrypt the log data using the encryption_key
encrypted_data = encrypt_data(file_content, 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 # Prepare the data payload for the POST request
data = { data = {
'data': encrypted_data, 'data': encrypted_data,
'plugin_folder': plugin_folder, 'file_path': file_path,
'plugin': pref,
'node_name': node_name 'node_name': node_name
} }
# Set the authorization header with the API token # 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}"']) mylog('verbose', [f'[{pluginName}] response: "{response}"'])
if response.status_code == 200: 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]) mylog('verbose', [message])
write_notification(message, 'info', timeNowTZ()) write_notification(message, 'info', timeNowTZ())
else: 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]) mylog('verbose', [message])
write_notification(message, 'alert', timeNowTZ()) write_notification(message, 'alert', timeNowTZ())

View File

@@ -21,12 +21,14 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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' 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(): def main():
# the script expects a parameter in the format of devices=device1,device2,... # the script expects a parameter in the format of devices=device1,device2,...

View File

@@ -24,19 +24,22 @@ from logger import mylog
from helper import timeNowTZ, get_setting_value, normalize_string from helper import timeNowTZ, get_setting_value, normalize_string
import conf import conf
from pytz import timezone from pytz import timezone
from const import logPath
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = 'UNFIMP'
LOG_FILE = os.path.join(CUR_PATH, 'script.log')
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') LOG_PATH = logPath + '/plugins'
LOCK_FILE = os.path.join(CUR_PATH, 'full_run.lock') 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) requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
pluginName = 'UNFIMP'
# Workflow # Workflow

View File

@@ -26,10 +26,12 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) 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') LOG_PATH = logPath + '/plugins'
RESULT_FILE = os.path.join(CUR_PATH, 'last_result.log') 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(): def main():

View File

@@ -22,8 +22,10 @@ from pytz import timezone
# Make sure the TIMEZONE for logging is correct # Make sure the TIMEZONE for logging is correct
conf.tz = timezone(get_setting_value('TIMEZONE')) conf.tz = timezone(get_setting_value('TIMEZONE'))
CUR_PATH = str(pathlib.Path(__file__).parent.resolve()) pluginName = 'WEBMON'
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')
def main(): def main():
parser = argparse.ArgumentParser(description='Simple URL monitoring tool') parser = argparse.ArgumentParser(description='Simple URL monitoring tool')

View File

@@ -163,7 +163,7 @@
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('guid')) { if (urlParams.has('guid')) {
const guid = urlParams.get('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(response => response.json())
.then(data => { .then(data => {
const index = findIndexByGUID(data.data, guid); const index = findIndexByGUID(data.data, guid);

View File

@@ -147,7 +147,7 @@ def run_plugin_scripts(db, all_plugins, runType, pluginsState = plugins_state())
# Function to run a plugin command # Function to run a plugin command
def run_plugin(command, set_RUN_TIMEOUT): def run_plugin(command, set_RUN_TIMEOUT, plugin):
try: try:
return subprocess.check_output(command, universal_newlines=True, stderr=subprocess.STDOUT, timeout=set_RUN_TIMEOUT) return subprocess.check_output(command, universal_newlines=True, stderr=subprocess.STDOUT, timeout=set_RUN_TIMEOUT)
except subprocess.CalledProcessError as e: 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 # Using ThreadPoolExecutor to handle concurrent subprocesses
with ThreadPoolExecutor(max_workers=5) as executor: 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): for future in as_completed(futures):
output = future.result() # Get the output or error output = future.result() # Get the output or error
@@ -235,8 +235,8 @@ def execute_plugin(db, all_plugins, plugin, pluginsState = plugins_state() ):
newLines = [] newLines = []
# Create the file path # Create the file path
file_dir = os.path.join(pluginsPath, plugin["code_name"]) file_dir = logPath + '/plugins'
file_prefix = 'last_result' 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 # 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) 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 # cleanup - select only lines containing a separator to filter out unnecessary data
newLines = list(filter(lambda x: '|' in x, newLines)) 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.<prefix>.encoded.Node_1.1.log
tmp_SyncHubNodeName = '' tmp_SyncHubNodeName = ''
if len(filename.split('.')) > 3: if len(filename.split('.')) > 3:
tmp_SyncHubNodeName = filename.split('.')[2] tmp_SyncHubNodeName = filename.split('.')[2]