Plugins 0.1 - ONCE execution support

This commit is contained in:
Jokob-sk
2023-02-06 21:47:58 +11:00
parent 5ed142a6b8
commit 887c2d0f42
7 changed files with 528 additions and 240 deletions

View File

@@ -12,7 +12,7 @@ If you wish to develop a plugin, please check the existing plugin structure.
| `script.py` | yes | The Python script itself |
| `last_result.log` | yes | The file used to interface between PiAlert and the plugin (script). |
| `script.log` | no | Logging output (recommended) |
| `README.md` | no | Amy setup considerations or overview |
| `README.md` | no | Any setup considerations or overview (recommended) |
More on specific files below.
@@ -21,7 +21,7 @@ More on specific files below.
Used to interface between PiAlert and the plugin (script). After every scan it should contain only the results from the latest scan/execution.
- The format is a `csv`-like file with the pipe `|` separator. 8 (eight) values need to be supplied, so every line needs to contain 7 pipe separators. Empty values arerepresented by `null`
- The format is a `csv`-like file with the pipe `|` separator. 8 (eight) values need to be supplied, so every line needs to contain 7 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 in the script results and if the value is required below.
@@ -66,14 +66,37 @@ https://www.google.com|null|2023-01-02 15:56:30|200|0.7898|
### config.json
#### Supported settings types
##### Setting object struncture
- `RUN`
- `RUN_SCHD`
- `API_SQL`
- `TIMEOUT`
- `NOTIFY_ON`
- `ARGS`
```json
{
"type": "RUN",
"default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"],
"name" :[{
"language_code":"en_us",
"string" : "Run condition"
},
{
"language_code":"de_de",
"string" : "Ausführungsbedingung"
}],
"description": [{
"language_code":"en_us",
"string" : "Enable a regular scan of your services. If you select <code>schedule</code> the scheduling settings from below are applied. If you select <code>once</code> the scan is run only once on start of the application (container) for the time specified in <a href=\"#WEBMON_TIMEOUT\"><code>WEBMON_TIMEOUT</code> setting</a>."
}]
}
```
###### Supported settings types
- `RUN` - (required) Specifies when the service is executed
- Supported Options: "disabled", "once", "schedule" (if included then a `RUN_SCHD` setting needs to be specified), "always_after_scan", "on_new_device"
- `RUN_SCHD` - (required if you include the `RUN`) Cron-like scheduling used if the `RUN` setting set to `schedule`
- `CMD` - (required) What command should be executed.
- `API_SQL` - (optional) Generates a `table_` + code_name + `.json` file as per (API docs)[https://github.com/jokob-sk/Pi.Alert/blob/main/docs/API.md].
- `TIMEOUT` - (optional) Max execution time of the script. If not specified a default value of 10 seconds is used to prevent hanging.
- `WATCH` - (optional) Which database columns are watched for changes. If not specified no notifications are sent.
#### Example
@@ -82,102 +105,157 @@ https://www.google.com|null|2023-01-02 15:56:30|200|0.7898|
{
"code_name": "website_monitor",
"settings_short_prefix": "WEBMON",
"display_name" : "Website monitor",
"font_awesome_icon_classses": "fa-solid fa-globe",
"description": {
"en_us" : "This plugin is to monitor status changes of different services or websites."
},
"localized": ["display_name", "description", "icon"],
"display_name" : [{
"language_code":"en_us",
"string" : "Website monitor"
}],
"icon":[{
"language_code":"en_us",
"string" : "<i class=\"fa-solid fa-globe\"></i>"
}],
"argument" : "urls",
"description": [{
"language_code":"en_us",
"string" : "This plugin is to monitor status changes of different services or websites."
}],
"database_column_aliases":{
"Plugins_Events":{
"Index":{
"en_us" : "Index"
},
"Object_PrimaryID":{
"en_us" : "Monitored URL"
},
"DateTime":{
"en_us" : "Checked on"
},
"Watched_Value1":{
"en_us" : "Status code"
},
"Watched_Value2":{
"en_us" : "Latency"
}
"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"
}]
}
},
"settings":[
{
"type": "ENABLE",
"default_value":"False",
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Enable plugin"
}],
"description": [{
"language_code":"en_us",
"string" : "Enable a regular scan of your services. You need to enable this setting for anything to be executed regarding this plugin."
}]
},
{
"type": "RUN",
"default_value":"none",
"options": ["none","once","schedule"],
"name" : {
"en_us" : "Schedule"
},
"description":
{
"en_us" : "Enable a regular scan of your services. If you select <code>schedule</code> the scheduling settings from below are applied. If you select <code>once</code> the scan is run only once on start of the application (container) for the time specified in <a href=\"#WEBMON_TIMEOUT\"><code>WEBMON_TIMEOUT</code> setting</a>."
}
"localized": ["name", "description"],
"name" :[{
"language_code":"en_us",
"string" : "Schedule"
}],
"description": [{
"language_code":"en_us",
"string" : "Enable a regular scan of your services. If you select <code>schedule</code> the scheduling settings from below are applied. If you select <code>once</code> the scan is run only once on start of the application (container) for the time specified in <a href=\"#WEBMON_TIMEOUT\"><code>WEBMON_TIMEOUT</code> setting</a>."
}]
},
{
"type": "FORCE_REPORT",
"default_value": false,
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Force report"
}],
"description": [{
"language_code":"en_us",
"string" : "Force a notification message even if there are nochanges detected."
}]
},
{
"type": "RUN_SCHD",
"default_value":"0 2 * * *",
"name" : {
"en_us" : "Schedule"
},
"description":
{
"en_us" : "Only enabled if you select <code>schedule</code> in the <a href=\"#WEBMON_RUN\"><code>WEBMON_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes."
}
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Schedule"
}],
"description": [{
"language_code":"en_us",
"string" : "Only enabled if you select <code>schedule</code> in the <a href=\"#WEBMON_RUN\"><code>WEBMON_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes."
}]
},
{
"type": "API_SQL",
"default_value":"SELECT * FROM plugin_website_monitor",
"name" : {
"en_us" : "API endpoint"
},
"description":
{
"en_us" : "You can specify a custom SQL query which will generate a JSON file and then expose it via the <a href=\"/api/plugin_website_monitor.json\" target=\"_blank\"><code>plugin_website_monitor.json</code> file endpoint</a>."
}
"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 <a href=\"/api/plugin_website_monitor.json\" target=\"_blank\"><code>plugin_website_monitor.json</code> file endpoint</a>."
}]
},
{
"type": "TIMEOUT",
"type": "RUN_TIMEOUT",
"default_value":5,
"name" : {
"en_us" : "Run timeout"
},
"description":
{
"en_us" : "Maximum time in seconds to wait for a Website monitor check to finish for any url."
}
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Run timeout"
}],
"description": [{
"language_code":"en_us",
"string" : "Maximum time in seconds to wait for a Website monitor check to finish for any url."
}]
},
{
"type": "NOTIFY_ON",
"type": "WATCH",
"default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"name" : {
"en_us" : "Notify on"
},
"description":
{
"en_us" : "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is response status code (e.g.: 200, 404)</li><li><code>Watched_Value2</code> is Latency (not recommended)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>"
}
"localized": ["name", "description"],
"name" :[{
"language_code":"en_us",
"string" : "Notify on"
}] ,
"description":[{
"language_code":"en_us",
"string" : "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is response status code (e.g.: 200, 404)</li><li><code>Watched_Value2</code> is Latency (not recommended)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>"
}]
},
{
"type": "ARGS",
"default_value":"",
"name" : {
"en_us" : "Run timeout"
},
"description":
{
"en_us" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
}
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Arguments"
}],
"description": [{
"language_code":"en_us",
"string" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
}]
}
]
@@ -185,4 +263,5 @@ https://www.google.com|null|2023-01-02 15:56:30|200|0.7898|
```

View File

@@ -1,132 +1,170 @@
{
"code_name": "website_monitor",
"settings_short_prefix": "WEBMON",
"display_name" : "Website monitor",
"font_awesome_icon_classses": "fa-solid fa-globe",
"description": {
"en_us" : "This plugin is to monitor status changes of different services or websites."
"localized": ["display_name", "description", "icon"],
"display_name" : [{
"language_code":"en_us",
"string" : "Website monitor"
}],
"icon":[{
"language_code":"en_us",
"string" : "<i class=\"fa-solid fa-globe\"></i>"
}],
"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" : "sites",
"type" : "setting",
"value" : "WEBMON_LIST"
}],
"database_column_aliases":{
"Plugins_Events":{
"Index":{
"en_us" : "Index"
},
"Object_PrimaryID":{
"en_us" : "Monitored URL"
},
"DateTime":{
"en_us" : "Checked on"
},
"Watched_Value1":{
"en_us" : "Status code"
},
"Watched_Value2":{
"en_us" : "Latency"
}
"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"
}]
}
},
"settings":[
{
"type": "ENABLE",
"default_value":"False",
"options": [],
"name" : {
"en_us" : "Enable plugin"
},
"description":
{
"en_us" : "Enable a regular scan of your services. You need to enable this setting for anything to be executed regarding this plugin."
}
},
{
"type": "RUN",
"default_value":"none",
"options": ["none","once","schedule"],
"name" : {
"en_us" : "Schedule"
},
"description":
{
"en_us" : "Enable a regular scan of your services. If you select <code>schedule</code> the scheduling settings from below are applied. If you select <code>once</code> the scan is run only once on start of the application (container) for the time specified in <a href=\"#WEBMON_TIMEOUT\"><code>WEBMON_TIMEOUT</code> setting</a>."
}
"type": "RUN",
"default_value":"disabled",
"options": ["disabled", "once", "schedule", "always_after_scan", "on_new_device"],
"localized": ["name", "description"],
"name" :[{
"language_code":"en_us",
"string" : "Run condition"
}],
"description": [{
"language_code":"en_us",
"string" : "Enable a regular scan of your services. If you select <code>schedule</code> the scheduling settings from below are applied. If you select <code>once</code> the scan is run only once on start of the application (container) for the time specified in <a href=\"#WEBMON_TIMEOUT\"><code>WEBMON_TIMEOUT</code> setting</a>."
}]
},
{
"type": "FORCE_REPORT",
"default_value": false,
"options": [],
"name" : {
"en_us" : "Schedule"
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Force report"
},
"description":
{
"en_us" : "Enable a regular scan of your services. If you select <code>schedule</code> the scheduling settings from below are applied. If you select <code>once</code> the scan is run only once on start of the application (container) for the time specified in <a href=\"#WEBMON_TIMEOUT\"><code>WEBMON_TIMEOUT</code> setting</a>."
}
{
"language_code":"de_de",
"string" : "Zwing Bericht"
}],
"description": [{
"language_code":"en_us",
"string" : "Force a notification message even if there are no changes detected."
}]
},
{
"type": "RUN_SCHD",
"default_value":"0 2 * * *",
"options": [],
"name" : {
"en_us" : "Schedule"
},
"description":
{
"en_us" : "Only enabled if you select <code>schedule</code> in the <a href=\"#WEBMON_RUN\"><code>WEBMON_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes."
}
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Schedule"
}],
"description": [{
"language_code":"en_us",
"string" : "Only enabled if you select <code>schedule</code> in the <a href=\"#WEBMON_RUN\"><code>WEBMON_RUN</code> setting</a>. Make sure you enter the schedule in the correct cron-like format (e.g. validate at <a href=\"https://crontab.guru/\" target=\"_blank\">crontab.guru</a>). For example entering <code>0 4 * * *</code> will run the scan after 4 am in the <a onclick=\"toggleAllSettings()\" href=\"#TIMEZONE\"><code>TIMEZONE</code> you set above</a>. Will be run NEXT time the time passes."
}]
},
{
"type": "API_SQL",
"default_value":"SELECT * FROM plugin_website_monitor",
"options": [],
"name" : {
"en_us" : "API endpoint"
},
"description":
{
"en_us" : "You can specify a custom SQL query which will generate a JSON file and then expose it via the <a href=\"/api/plugin_website_monitor.json\" target=\"_blank\"><code>plugin_website_monitor.json</code> file endpoint</a>."
}
"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 <a href=\"/api/plugin_website_monitor.json\" target=\"_blank\"><code>plugin_website_monitor.json</code> file endpoint</a>."
}]
},
{
"type": "RUN_TIMEOUT",
"default_value":5,
"options": [],
"name" : {
"en_us" : "Run timeout"
},
"description":
{
"en_us" : "Maximum time in seconds to wait for a Website monitor check to finish for any url."
}
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Run timeout"
}],
"description": [{
"language_code":"en_us",
"string" : "Maximum time in seconds to wait for a Website monitor check to finish for any url."
}]
},
{
"type": "NOTIFY_ON",
"type": "WATCH",
"default_value":["Watched_Value1"],
"options": ["Watched_Value1","Watched_Value2","Watched_Value3","Watched_Value4"],
"name" : {
"en_us" : "Notify on"
},
"description":
{
"en_us" : "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is response status code (e.g.: 200, 404)</li><li><code>Watched_Value2</code> is Latency (not recommended)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>"
}
"localized": ["name", "description"],
"name" :[{
"language_code":"en_us",
"string" : "Notify on"
}] ,
"description":[{
"language_code":"en_us",
"string" : "Send a notification if selected values change. Use <code>CTRL + Click</code> to select/deselect. <ul> <li><code>Watched_Value1</code> is response status code (e.g.: 200, 404)</li><li><code>Watched_Value2</code> is Latency (not recommended)</li><li><code>Watched_Value3</code> unused </li><li><code>Watched_Value4</code> unused </li></ul>"
}]
},
{
"type": "ARGS",
"type": "CMD",
"default_value":"python3 script.py",
"options": [],
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Command"
}],
"description": [{
"language_code":"en_us",
"string" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
}]
},
{
"type": "LIST",
"default_value":"",
"options": [],
"name" : {
"en_us" : "Run timeout"
},
"description":
{
"en_us" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
}
"localized": ["name", "description"],
"name" : [{
"language_code":"en_us",
"string" : "Arguments"
}],
"description": [{
"language_code":"en_us",
"string" : "Change the <a href=\"https://linux.die.net/man/1/dig\" target=\"_blank\">dig utility</a> arguments if you have issues resolving your Internet IP. Arguments are added at the end of the following command: <code>dig +short </code>."
}]
}
]