From d0d9a1a65de3e2b9fc096af0c870026a4139e377 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Sat, 25 Feb 2023 12:56:40 +1100 Subject: [PATCH] Plugins 0.3 - SQL call fix and additional UI controls --- back/pialert.py | 8 +- front/plugins.php | 15 +- front/plugins/README.md | 341 +--------------------- front/plugins/website_monitor/config.json | 2 +- front/settings.php | 2 +- 5 files changed, 17 insertions(+), 351 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index 9a4619df..cd99d404 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -3906,8 +3906,6 @@ def process_plugin_events(plugin): # ---------------------------- # Update the Plugin_Objects - - sql.execute ("DELETE FROM Plugins_Objects") for plugObj in pluginObjects: @@ -3915,8 +3913,10 @@ def process_plugin_events(plugin): if plugObj.status == 'new': createdTime = plugObj.changed + + q = f"UPDATE Plugins_Objects set Plugin = '{plugObj.pluginPref}', DateTimeChanged = '{plugObj.changed}', Watched_Value1 = '{plugObj.watched1}', Watched_Value2 = '{plugObj.watched2}', Watched_Value3 = '{plugObj.watched3}', Watched_Value4 = '{plugObj.watched4}', Status = '{plugObj.status}', Extra = '{plugObj.extra}' WHERE 'Index' = {plugObj.index}" - sql.execute ("INSERT INTO Plugins_Objects (Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData )) + sql.execute (q) # Update the Plugins_Events with the new statuses @@ -3929,7 +3929,7 @@ def process_plugin_events(plugin): if plugObj.status == 'new': createdTime = plugObj.changed - sql.execute ("INSERT INTO Plugins_Events (Index, Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.index, plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData )) + sql.execute ("INSERT INTO Plugins_Events (Plugin, Object_PrimaryID, Object_SecondaryID, DateTimeCreated, DateTimeChanged, Watched_Value1, Watched_Value2, Watched_Value3, Watched_Value4, Status, Extra, UserData) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)", (plugObj.pluginPref, plugObj.primaryId , plugObj.secondaryId , createdTime, plugObj.changed , plugObj.watched1 , plugObj.watched2 , plugObj.watched3 , plugObj.watched4 , plugObj.status , plugObj.extra, plugObj.userData )) commitDB() diff --git a/front/plugins.php b/front/plugins.php index f2244b8b..25e926c9 100755 --- a/front/plugins.php +++ b/front/plugins.php @@ -38,7 +38,7 @@ // ----------------------------------------------------------------------------- // Get form control according to the column definition from config.json > database_column_definitions -function getFormControl(index, dbColumnDef, value) { +function getFormControl(dbColumnDef, value, index) { result = '' @@ -47,8 +47,13 @@ function getFormControl(index, dbColumnDef, value) { case 'label': result = `${value}`; break; - case 'text': - result = ``; + case 'textboxsave': + result = ` +
+ + +
+ `; break; case 'url': result = `${value}`; @@ -66,7 +71,7 @@ function getFormControl(index, dbColumnDef, value) { $.each(dbColumnDef.options, function(index, obj) { if(value == obj.equals) { - result = `${obj.replacement}` + result = `${obj.replacement}` } }); break; @@ -203,7 +208,7 @@ function generateTabs() for(j=0;j' + clm += ''+ getFormControl(colDefinitions[j], pluginObjects[i][colDefinitions[j].column], pluginObjects[i]["Index"]) +'' } obRows += '' + clm + '' } diff --git a/front/plugins/README.md b/front/plugins/README.md index d241633b..f401fcbf 100755 --- a/front/plugins/README.md +++ b/front/plugins/README.md @@ -234,343 +234,4 @@ Example: ## Full Example -```json -{ - "code_name": "website_monitor", - "unique_prefix": "WEBMON", - "localized": ["display_name", "description", "icon"], - "display_name" : [{ - "language_code":"en_us", - "string" : "Website monitor" - }], - "icon":[{ - "language_code":"en_us", - "string" : "" - }], - "description": [{ - "language_code":"en_us", - "string" : "This plugin is to monitor status changes of different services or websites." - }], - "params" : [{ - "name" : "macs", - "type" : "sql", - "value" : "SELECT dev_MAC from DEVICES" - }, - { - "name" : "urls", - "type" : "setting", - "value" : "WEBMON_urls_to_check" - }, - { - "name" : "internet_ip", - "type" : "setting", - "value" : "WEBMON_SQL_internet_ip" - }], - "database_column_definitions": - [ - { - "column": "Index", - "show": false, - "type": "label", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "N/A" - }] - } , - { - "column": "Plugin", - "show": false, - "type": "label", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "N/A" - }] - }, - { - "column": "Object_PrimaryID", - "show": true, - "type": "text", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Monitored URL" - }] - }, - { - "column": "Object_SecondaryD", - "show": false, - "type": "label", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "N/A" - }] - } , - { - "column": "DateTimeCreated", - "show": true, - "type": "text", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Created" - }] - }, - { - "column": "DateTimeChanged", - "show": true, - "type": "text", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Changed" - }] - }, - { - "column": "Watched_Value1", - "show": true, - "type": "text", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Status code" - }] - }, - { - "column": "Watched_Value2", - "show": true, - "type": "text", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Latency" - }] - }, - { - "column": "Watched_Value3", - "show": false, - "type": "label", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "N/A" - }] - } , - { - "column": "Watched_Value4", - "show": false, - "type": "label", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "N/A" - }] - } , - { - "column": "UserData", - "show": true, - "type": "text", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Comments" - }] - }, - { - "column": "Status", - "show": true, - "type": "equals", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Status" - }] - }, - { - "column": "Extra", - "show": false, - "type": "label", - "default_value":"", - "options": [], - "localized": ["name"], - "name":[{ - "language_code":"en_us", - "string" : "Extra" - }] - } - ], - "settings":[ - { - "function": "RUN", - "type": "selecttext", - "default_value":"disabled", - "options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"], - "localized": ["name", "description"], - "name" :[{ - "language_code":"en_us", - "string" : "When to run" - }], - "description": [{ - "language_code":"en_us", - "string" : "Enable a regular scan of your services. If you select schedule the scheduling settings from below are applied. If you select once the scan is run only once on start of the application (container) for the time specified in WEBMON_RUN_TIMEOUT setting." - }] - }, - { - "function": "CMD", - "type": "text", - "default_value":"python3 /home/pi/pialert/front/plugins/website_monitor/script.py urls={urls}", - "options": [], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "Command" - }], - "description": [{ - "language_code":"en_us", - "string" : "Command to run" - }] - }, - { - "function": "RUN_SCHD", - "type": "text", - "default_value":"0 2 * * *", - "options": [], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "Schedule" - }], - "description": [{ - "language_code":"en_us", - "string" : "Only enabled if you select schedule in the WEBMON_RUN setting. Make sure you enter the schedule in the correct cron-like format (e.g. validate at crontab.guru). For example entering 0 4 * * * will run the scan after 4 am in the TIMEZONE you set above. Will be run NEXT time the time passes." - }] - }, - { - "function": "API_SQL", - "type": "text", - "default_value":"SELECT * FROM plugin_website_monitor", - "options": [], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "API endpoint" - }], - "description": [{ - "language_code":"en_us", - "string" : "You can specify a custom SQL query which will generate a JSON file and then expose it via the plugin_website_monitor.json file endpoint." - }] - }, - { - "function": "RUN_TIMEOUT", - "type": "integer", - "default_value":5, - "options": [], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "Run timeout" - }, - { - "language_code":"de_de", - "string" : "Wartezeit" - }], - "description": [{ - "language_code":"en_us", - "string" : "Maximum time in seconds to wait for a Website monitor check to finish for any url." - }] - }, - { - "function": "WATCH", - "type": "multiselect", - "default_value":["Watched_Value1"], - "options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"], - "localized": ["name", "description"], - "name" :[{ - "language_code":"en_us", - "string" : "Watched" - }] , - "description":[{ - "language_code":"en_us", - "string" : "Send a notification if selected values change. Use CTRL + Click to select/deselect.
  • Watched_Value1 is response status code (e.g.: 200, 404)
  • Watched_Value2 is Latency (not recommended)
  • Watched_Value3 unused
  • Watched_Value4 unused
" - }] - }, - { - "function": "REPORT_ON", - "type": "multiselect", - "default_value":["new","watched-changed"], - "options": ["new","watched-changed","watched-not-changed"], - "localized": ["name", "description"], - "name" :[{ - "language_code":"en_us", - "string" : "Report on" - }] , - "description":[{ - "language_code":"en_us", - "string" : "Send a notification only on these statuses. new means a new unique (unique combination of PrimaryId and SecondaryId) object was discovered. watched-changed means that selected Watched_ValueN columns changed." - }] - }, - { - "function": "urls_to_check", - "type": "list", - "default_value":[], - "options": [], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "Arguments" - }], - "description": [{ - "language_code":"en_us", - "string" : "Services to watch. Enter full URL, e.g. https://google.com." - }] - }, - { - "function": "SQL_internet_ip", - "type": "readonly", - "default_value":"SELECT dev_LastIP FROM Devices WHERE dev_MAC = 'Internet'", - "options": [], - "localized": ["name", "description"], - "name" : [{ - "language_code":"en_us", - "string" : "Helper variable" - }], - "description": [{ - "language_code":"en_us", - "string" : "Unused setting - for demonstration only. Getting the IP address of the Router / Internet. " - }] - } - - ] -} - - - - - -``` +Check the [website_monitor WEBMON) config.json](https://github.com/jokob-sk/Pi.Alert/blob/main/front/plugins/website_monitor/config.json) file for details. diff --git a/front/plugins/website_monitor/config.json b/front/plugins/website_monitor/config.json index 036366f3..6109cc7e 100755 --- a/front/plugins/website_monitor/config.json +++ b/front/plugins/website_monitor/config.json @@ -175,7 +175,7 @@ { "column": "UserData", "show": true, - "type": "text", + "type": "textboxsave", "default_value":"", "options": [], "localized": ["name"], diff --git a/front/settings.php b/front/settings.php index 418ca92e..6a1ca49c 100755 --- a/front/settings.php +++ b/front/settings.php @@ -121,7 +121,7 @@ while ($row = $result -> fetchArray (SQLITE3_ASSOC)) { // text - textbox if($set['Type'] == 'text' ) { - $input = ''; + $input = ''; } // password - hidden text elseif ($set['Type'] == 'password')