Docs + show_ui

This commit is contained in:
Jokob-sk
2023-08-12 07:24:42 +10:00
parent 56d6190fa3
commit b3159d683c
15 changed files with 76 additions and 26 deletions

View File

@@ -102,10 +102,13 @@ More on specifics below.
Currently, these data sources are supported (valid `data_source` value).
- Script (`script`)
- SQL query on the PiAlert database (`pialert-db-query`)
- Template (`template`)
- External SQLite database (`sqlite-db-query`)
| Name | `data_source` value | Needs to return a "table" | Overview (more details on this page below) |
|----------------------|----------------------|----------------------|----------------------|
| Script | `script` | no | Executes any linux command in the `CMD` setting. |
| Pialert DB query | `pialert-db-query` | yes | Executes a SQL query on the PiAlert database in the `CMD` setting. |
| Template | `template` | no | Used to generate internal settings, such a sdefault values. |
| 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. |
> 🔎Example
>```json
@@ -113,6 +116,13 @@ Currently, these data sources are supported (valid `data_source` value).
>```
Any of the above data sources have to return a "table" of the exact structure as outlined above.
You can show or hide the UI on the "Plugins" page and "Plugins" tab on devices via the `show_ui` property:
> 🔎Example
>```json
> "show_ui": true,
> ```
### "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`) needs to contain an executable Linux command, that generates a `last_result.log` file. This file needs to be stored in the same folder as the plugin.
@@ -208,17 +218,29 @@ Used to initialize internal settings. Check the `newdev_template` plugin for det
### "data_source": "sqlite-db-query"
You can execute a SQL query on an external database connected to the current PiALert database via a temporary `EXTERNAL.` prefix. The external SQLite database file has to be mapped in the container to the path specified in the `db_path` property:
You can execute a SQL query on an external database connected to the current PiALert database via a temporary `EXTERNAL.` prefix. The external SQLite database file has to be mapped in the container to the path specified in the `DB_PATH` setting:
```json
...
"data_source": "sqlite-db-query",
"data_source_settings":
{
"db_path":"/etc/pihole/pihole-FTL.db"
},
...
```
> 🔎Example
>
>```json
> ...
>{
> "function": "DB_PATH",
> "type": "readonly",
> "default_value":"/etc/pihole/pihole-FTL.db",
> "options": [],
> "localized": ["name", "description"],
> "name" : [{
> "language_code":"en_us",
> "string" : "DB Path"
> }],
> "description": [{
> "language_code":"en_us",
> "string" : "Required setting for the <code>sqlite-db-query</code> plugin type. Is used to mount an external SQLite database and execute the SQL query stored in the <code>CMD</code> setting."
> }]
> }
> ...
>```
The actual SQL query you want to execute is then stored as a `CMD` setting, similar to the `pialert-db-query` plugin type.

View File

@@ -13,6 +13,7 @@
"compare_use_quotes": true
}
],
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name": [

View File

@@ -12,6 +12,7 @@
"compare_use_quotes": true
}
],
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"mapped_to_table": "DHCP_Leases",
"display_name" : [{

View File

@@ -3,6 +3,7 @@
"unique_prefix": "DHCPSRVS",
"enabled": true,
"data_source": "script",
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name" : [{
"language_code":"en_us",

View File

@@ -3,7 +3,8 @@
"template_type": "database-entry",
"unique_prefix": "KNWN",
"enabled": true,
"data_source": "template",
"data_source": "template",
"show_ui": false,
"localized": ["display_name", "description", "icon"],
"display_name": [{
"language_code": "en_us",

View File

@@ -4,6 +4,7 @@
"unique_prefix": "NEWDEV",
"enabled": true,
"data_source": "template",
"show_ui": false,
"localized": ["display_name", "description", "icon"],
"display_name": [{
"language_code": "en_us",

View File

@@ -12,6 +12,7 @@
"compare_use_quotes": true
}
],
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name" : [{
"language_code":"en_us",

View File

@@ -3,10 +3,6 @@
"unique_prefix": "PIHOLE",
"enabled": true,
"data_source": "sqlite-db-query",
"data_source_settings":
{
"db_path":"/etc/pihole/pihole-FTL.db"
},
"mapped_to_table": "CurrentScan",
"data_filters": [
{
@@ -17,6 +13,7 @@
"compare_use_quotes": true
}
],
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name": [
@@ -57,7 +54,7 @@
}],
"description": [{
"language_code":"en_us",
"string" : "Specify when your PiHole device import from the PiHole databse will run. The typical setting would be <code>schedule</code> and then you specify a cron-like schedule in the <a href=\"#PIHOLE_RUN_SCHD\"><code>PIHOLE_RUN_SCHD</code>setting</a>. If enabled, you must map the pihole db into your container to the <code>:/etc/pihole/pihole-FTL.db</code> mount path."
"string" : "Specify when your PiHole device import from the PiHole databse will run. The typical setting would be <code>schedule</code> and then you specify a cron-like schedule in the <a href=\"#PIHOLE_RUN_SCHD\"><code>PIHOLE_RUN_SCHD</code>setting</a>. If enabled, you must map the pihole db into your container to the <code>:/etc/pihole/pihole-FTL.db</code> mount path as specified in the <code>DB_PATH</code> setting."
}]
},
{
@@ -94,6 +91,21 @@
}
]
},
{
"function": "DB_PATH",
"type": "readonly",
"default_value":"/etc/pihole/pihole-FTL.db",
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "DB Path"
}],
"description": [{
"language_code":"en_us",
"string" : "Required setting for the <code>sqlite-db-query</code> plugin type. Is used to mount an external SQLite database and execute the SQL query stored in the <code>CMD</code> setting."
}]
},
{
"function": "RUN_SCHD",
"type": "text",

View File

@@ -1,9 +1,10 @@
{
"code_name": "set_webui_password",
"code_name": "set_password",
"template_type": "database-entry",
"unique_prefix": "SETPWD",
"enabled": true,
"data_source": "script",
"show_ui": false,
"localized": ["display_name", "description", "icon"],
"display_name": [{
"language_code": "en_us",

View File

@@ -12,6 +12,7 @@
"compare_use_quotes": true
}
],
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"mapped_to_table": "DHCP_Leases",
"display_name" : [{

View File

@@ -4,7 +4,7 @@
"enabled": true,
"data_source": "script",
"mapped_to_table": "DHCP_Leases",
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name": [

View File

@@ -3,6 +3,7 @@
"unique_prefix": "UNFIMP",
"enabled": true,
"data_source": "script",
"show_ui": true,
"data_filters": [
{
"compare_column" : "Object_PrimaryID",

View File

@@ -3,6 +3,7 @@
"unique_prefix": "WEBMON",
"enabled": true,
"data_source": "python-script",
"show_ui": true,
"localized": ["display_name", "description", "icon"],
"display_name" : [{
"language_code": "en_us",

View File

@@ -216,7 +216,7 @@ function generateTabs()
// console.log(pluginObj)
if(pluginObj.data_source != "template") // hiding template-based plugins as they don't produce any output
if(pluginObj.show_ui) // hiding plugins where specified
{
$('#tabs-location').append(
`<li class=" left-nav ${activetab}">

View File

@@ -32,8 +32,6 @@ def run_plugin_scripts(db, runType):
shouldRun = True
elif runType == "schedule":
# run if overdue scheduled time
# check schedules if any contains a unique plugin prefix matching the current plugin
for schd in conf.mySchedules:
if schd.service == prefix:
@@ -250,8 +248,16 @@ def execute_plugin(db, plugin):
# Execute command
mylog('verbose', ['[Plugins] Executing: ', q])
# ------- necessary settings check --------
set = get_plugin_setting(plugin, "DB_PATH")
# handle missing "function":"DB_PATH" setting
if set == None:
mylog('none', ['[Plugins] Error: DB_PATH setting for plugin type sqlite-db-query missing.'])
return
fullSqlitePath = plugin['data_source_settings']['db_path']
fullSqlitePath = set["value"]
# try attaching the sqlite DB
try: