From ee1a3fc6831ec04aa41a9db7dbac13ad328d1bb1 Mon Sep 17 00:00:00 2001 From: Jokob-sk Date: Mon, 13 Feb 2023 22:20:48 +1100 Subject: [PATCH] Plugins 0.2 - Show unprocessed events in UI --- back/pialert.py | 8 ++ docs/API.md | 1 + front/js/pialert_common.js | 1 + front/php/templates/language/en_us.php | 9 ++ front/plugins.php | 162 +++++++++++++++++++++++-- front/plugins/README.md | 39 +++++- 6 files changed, 207 insertions(+), 13 deletions(-) diff --git a/back/pialert.py b/back/pialert.py index 88a25b89..09e38c57 100755 --- a/back/pialert.py +++ b/back/pialert.py @@ -52,6 +52,7 @@ sql_pholus_scan_all = "SELECT * FROM Pholus_Scan" sql_events_pending_alert = "SELECT * FROM Events where eve_PendingAlertEmail is not 0" sql_settings = "SELECT * FROM Settings" sql_plugins_entries = "SELECT * FROM Plugins_Entries" +sql_language_strings = "SELECT * FROM Language_Strings" sql_plugins_unprocessed_entries = "SELECT * FROM Plugins_Unprocessed_Entries" sql_new_devices = """SELECT * FROM ( SELECT eve_IP as dev_LastIP, eve_MAC as dev_MAC FROM Events_Devices WHERE eve_PendingAlertEmail = 1 @@ -3237,6 +3238,9 @@ def update_api(isNotification = False, updateOnlyDataSources = []): write_file(folder + 'notification_text.html' , mail_html) write_file(folder + 'notification_json_final.json' , json.dumps(json_final)) + # Save plugins + write_file(folder + 'plugins.json' , json.dumps({"data" : plugins.list})) + # prepare databse tables we want to expose dataSourcesSQLs = [ ["devices", sql_devices_all], @@ -3246,6 +3250,7 @@ def update_api(isNotification = False, updateOnlyDataSources = []): ["settings", sql_settings], ["plugins_unprocessed_entries", sql_plugins_unprocessed_entries], ["plugins_entries", sql_plugins_entries], + ["language_strings", sql_language_strings], ["custom_endpoint", API_CUSTOM_SQL], ] @@ -3649,6 +3654,9 @@ def run_plugin_scripts(runType): global plugins, tz, mySchedules + # Header + updateState("Run: Plugins") + mylog('debug', [' [Plugins] Check if any plugins need to be executed on run type: ', runType]) for plugin in plugins.list: diff --git a/docs/API.md b/docs/API.md index 4aba177e..5a982976 100755 --- a/docs/API.md +++ b/docs/API.md @@ -31,6 +31,7 @@ You can access the following files: | `table_events_pending_alert.json` | The list of the unprocessed (pending) notification events. | | `table_settings.json` | The content of the settings table. | | `table_plugins_entries.json` | The content of the plugins_entries table. Find more info on the [Plugin system here](https://github.com/jokob-sk/Pi.Alert/tree/main/front/plugins)| + | `language_strings.json` | The content of the language_strings table, which in turn is loaded from the plugins `config.json` definitions. | | `table_plugins_unprocessed_entries.json` | The content of the plugins_unprocessed_entries table. | | `table_custom_endpoint.json` | A custom endpoint generated by the SQL query specified by the `API_CUSTOM_SQL` setting. | diff --git a/front/js/pialert_common.js b/front/js/pialert_common.js index 2226e9fc..d0318169 100755 --- a/front/js/pialert_common.js +++ b/front/js/pialert_common.js @@ -346,3 +346,4 @@ function openInNewTab (url) { + diff --git a/front/php/templates/language/en_us.php b/front/php/templates/language/en_us.php index 05687618..a289fb2f 100755 --- a/front/php/templates/language/en_us.php +++ b/front/php/templates/language/en_us.php @@ -24,6 +24,7 @@ $lang['en_us'] = array( 'Gen_AreYouSure' => 'Are you sure?', 'Gen_Upd' => 'Updated successfully', 'Gen_Upd_Fail' => 'Update failed', +'Gen_Help' => 'Need help?', ////////////////////////////////////////////////////////////////// // Login Page - Update by @TeroRERO 03ago2022 @@ -471,6 +472,12 @@ $lang['en_us'] = array( +////////////////////////////////////////////////////////////////// +// Plugins +////////////////////////////////////////////////////////////////// + +'Plugins_Unprocessed_Events' => 'Unprocessed events', + ////////////////////////////////////////////////////////////////// // Settings ////////////////////////////////////////////////////////////////// @@ -673,6 +680,8 @@ The arp-scan time itself depends on the number of IP addresses to check so set t + + ); ?> diff --git a/front/plugins.php b/front/plugins.php index 51e72323..7db45753 100755 --- a/front/plugins.php +++ b/front/plugins.php @@ -2,6 +2,9 @@ require 'php/templates/header.php'; ?> + + +
@@ -16,19 +19,158 @@
-
-
- -
- aaa -
-
- - + - \ No newline at end of file + + + + diff --git a/front/plugins/README.md b/front/plugins/README.md index ce86abfd..07171e03 100755 --- a/front/plugins/README.md +++ b/front/plugins/README.md @@ -6,10 +6,13 @@ Highly experimental feature. Follow the below very carefully and check example p PiAlert comes with a simple plugin system to feed events from third-party scripts into the UI and then send notifications if desired. -If you wish to develop a plugin, please check the existing plugin structure. +If you wish to develop a plugin, please check the existing plugin structure. Once the settings are saved by the user they need to be removed from the `pialert.conf` file manually if you want to re-initialize them from the `config.json` of teh plugin. ## Plugin file structure overview +> Folder name must be the same as the code name value in: `"code_name": ""` +> Unique prefix needs to be unique compared to the other settings prefixes, e.g.: the prefix `APPRISE` is already in use. + | File | Required | Description | |----------------------|----------------------|----------------------| | `config.json` | yes | Contains the plugin configuration (manifest) including the settings available to the user. | @@ -142,7 +145,8 @@ Example: ##### Localized strings -- `"language_code":""` - code name of the language string. Only these three currently supported. + +- `"language_code":""` - code name of the language string. Only these three currently supported. At least the `"language_code":"en_us"` variant has to be defined. - `"string"` - The string to be displayed in the given language. Example: @@ -155,13 +159,40 @@ Example: } ``` +##### database_column_aliases +- Only columns specified in the `"localized"` parameter and also with at least an english translation will be shown in the UI. + +```json +{ + "localized": ["Index", "Object_PrimaryID", "DateTime", "Watched_Value1", "Watched_Value2"], + "Index":[{ + "language_code":"en_us", + "string" : "Index" + }], + "Object_PrimaryID":[{ + "language_code":"en_us", + "string" : "Monitored URL" + }], + "DateTime":[{ + "language_code":"en_us", + "string" : "Checked on" + }], + "Watched_Value1":[{ + "language_code":"en_us", + "string" : "Status code" + }], + "Watched_Value2":[{ + "language_code":"en_us", + "string" : "Latency" + }] + } +``` ## Full Example ```json { - { "code_name": "website_monitor", "unique_prefix": "WEBMON", "localized": ["display_name", "description", "icon"], @@ -360,4 +391,6 @@ Example: ] } + + ```